mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Use current IP address in PASV reply if localIP==0
This commit is contained in:
parent
ad236feca1
commit
5052186e4a
@ -434,9 +434,13 @@ bool FtpServer::processCommand()
|
|||||||
dataServer.begin();
|
dataServer.begin();
|
||||||
if((((uint32_t)NET_CLASS.localIP()) & ((uint32_t)NET_CLASS.subnetMask())) ==
|
if((((uint32_t)NET_CLASS.localIP()) & ((uint32_t)NET_CLASS.subnetMask())) ==
|
||||||
(((uint32_t)client.remoteIP()) & ((uint32_t)NET_CLASS.subnetMask()))) {
|
(((uint32_t)client.remoteIP()) & ((uint32_t)NET_CLASS.subnetMask()))) {
|
||||||
dataIp = NET_CLASS.localIP();
|
if((uint32_t)localIp > 0) {
|
||||||
|
dataIp = localIp; // same subnet with manual IP set
|
||||||
} else {
|
} else {
|
||||||
dataIp = localIp;
|
dataIp = NET_CLASS.localIP(); // same subnet without manual IP set
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
dataIp = NET_CLASS.localIP(); // other subnet, no NAT
|
||||||
}
|
}
|
||||||
dataPort = pasvPort;
|
dataPort = pasvPort;
|
||||||
DEBUG_PRINTLN(F(" Connection management set to passive"));
|
DEBUG_PRINTLN(F(" Connection management set to passive"));
|
||||||
@ -466,11 +470,12 @@ bool FtpServer::processCommand()
|
|||||||
client.print((dataPort & 255));
|
client.print((dataPort & 255));
|
||||||
client.println(F(")"));
|
client.println(F(")"));
|
||||||
dataConn = FTP_Pasive;
|
dataConn = FTP_Pasive;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// PORT - Data Port
|
// PORT - Data Port
|
||||||
//
|
//
|
||||||
else if(CommandIs("PORT")) {
|
else if(CommandIs("PORT"))
|
||||||
|
{
|
||||||
data.stop();
|
data.stop();
|
||||||
// get IP of data client
|
// get IP of data client
|
||||||
dataIp[0] = atoi(parameter);
|
dataIp[0] = atoi(parameter);
|
||||||
@ -500,11 +505,12 @@ bool FtpServer::processCommand()
|
|||||||
client.println(F("200 PORT command successful"));
|
client.println(F("200 PORT command successful"));
|
||||||
dataConn = FTP_Active;
|
dataConn = FTP_Active;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// STRU - File Structure
|
// STRU - File Structure
|
||||||
//
|
//
|
||||||
else if(CommandIs("STRU")) {
|
else if(CommandIs("STRU"))
|
||||||
|
{
|
||||||
if(ParameterIs("F")) {
|
if(ParameterIs("F")) {
|
||||||
client.println(F("200 F Ok"));
|
client.println(F("200 F Ok"));
|
||||||
// else if( ParameterIs( "R" ))
|
// else if( ParameterIs( "R" ))
|
||||||
@ -512,11 +518,12 @@ bool FtpServer::processCommand()
|
|||||||
} else {
|
} else {
|
||||||
client.println(F("504 Only F(ile) is suported"));
|
client.println(F("504 Only F(ile) is suported"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// TYPE - Data Type
|
// TYPE - Data Type
|
||||||
//
|
//
|
||||||
else if(CommandIs("TYPE")) {
|
else if(CommandIs("TYPE"))
|
||||||
|
{
|
||||||
if(ParameterIs("A")) {
|
if(ParameterIs("A")) {
|
||||||
client.println(F("200 TYPE is now ASCII"));
|
client.println(F("200 TYPE is now ASCII"));
|
||||||
} else if(ParameterIs("I")) {
|
} else if(ParameterIs("I")) {
|
||||||
@ -524,25 +531,27 @@ bool FtpServer::processCommand()
|
|||||||
} else {
|
} else {
|
||||||
client.println(F("504 Unknow TYPE"));
|
client.println(F("504 Unknow TYPE"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
// //
|
// //
|
||||||
// FTP SERVICE COMMANDS //
|
// FTP SERVICE COMMANDS //
|
||||||
// //
|
// //
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
|
||||||
//
|
//
|
||||||
// ABOR - Abort
|
// ABOR - Abort
|
||||||
//
|
//
|
||||||
else if(CommandIs("ABOR")) {
|
else if(CommandIs("ABOR"))
|
||||||
|
{
|
||||||
abortTransfer();
|
abortTransfer();
|
||||||
client.println(F("226 Data connection closed"));
|
client.println(F("226 Data connection closed"));
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// DELE - Delete a File
|
// DELE - Delete a File
|
||||||
//
|
//
|
||||||
else if(CommandIs("DELE")) {
|
else if(CommandIs("DELE"))
|
||||||
|
{
|
||||||
char path[FTP_CWD_SIZE];
|
char path[FTP_CWD_SIZE];
|
||||||
if(haveParameter() && makeExistsPath(path)) {
|
if(haveParameter() && makeExistsPath(path)) {
|
||||||
if(remove(path)) {
|
if(remove(path)) {
|
||||||
@ -557,13 +566,14 @@ bool FtpServer::processCommand()
|
|||||||
client.println(parameter);
|
client.println(parameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// LIST - List
|
// LIST - List
|
||||||
// NLST - Name List
|
// NLST - Name List
|
||||||
// MLSD - Listing for Machine Processing (see RFC 3659)
|
// MLSD - Listing for Machine Processing (see RFC 3659)
|
||||||
//
|
//
|
||||||
else if(CommandIs("LIST") || CommandIs("NLST") || CommandIs("MLSD")) {
|
else if(CommandIs("LIST") || CommandIs("NLST") || CommandIs("MLSD"))
|
||||||
|
{
|
||||||
DEBUG_PRINT("List of file!!");
|
DEBUG_PRINT("List of file!!");
|
||||||
|
|
||||||
if(dataConnect()) {
|
if(dataConnect()) {
|
||||||
@ -582,11 +592,12 @@ bool FtpServer::processCommand()
|
|||||||
data.stop();
|
data.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// MLST - Listing for Machine Processing (see RFC 3659)
|
// MLST - Listing for Machine Processing (see RFC 3659)
|
||||||
//
|
//
|
||||||
else if(CommandIs("MLST")) {
|
else if(CommandIs("MLST"))
|
||||||
|
{
|
||||||
char path[FTP_CWD_SIZE];
|
char path[FTP_CWD_SIZE];
|
||||||
uint16_t dat, tim;
|
uint16_t dat, tim;
|
||||||
char dtStr[15];
|
char dtStr[15];
|
||||||
@ -614,17 +625,19 @@ bool FtpServer::processCommand()
|
|||||||
client.println(F("250 End."));
|
client.println(F("250 End."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// NOOP
|
// NOOP
|
||||||
//
|
//
|
||||||
else if(CommandIs("NOOP")) {
|
else if(CommandIs("NOOP"))
|
||||||
|
{
|
||||||
client.println(F("200 Zzz..."));
|
client.println(F("200 Zzz..."));
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// RETR - Retrieve
|
// RETR - Retrieve
|
||||||
//
|
//
|
||||||
else if(CommandIs("RETR")) {
|
else if(CommandIs("RETR"))
|
||||||
|
{
|
||||||
char path[FTP_CWD_SIZE];
|
char path[FTP_CWD_SIZE];
|
||||||
if(haveParameter() && makeExistsPath(path)) {
|
if(haveParameter() && makeExistsPath(path)) {
|
||||||
if(!openFile(path, FTP_FILE_READ)) {
|
if(!openFile(path, FTP_FILE_READ)) {
|
||||||
@ -650,12 +663,13 @@ bool FtpServer::processCommand()
|
|||||||
transferStage = FTP_Retrieve;
|
transferStage = FTP_Retrieve;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// STOR - Store
|
// STOR - Store
|
||||||
// APPE - Append
|
// APPE - Append
|
||||||
//
|
//
|
||||||
else if(CommandIs("STOR") || CommandIs("APPE")) {
|
else if(CommandIs("STOR") || CommandIs("APPE"))
|
||||||
|
{
|
||||||
char path[FTP_CWD_SIZE];
|
char path[FTP_CWD_SIZE];
|
||||||
if(haveParameter() && makePath(path)) {
|
if(haveParameter() && makePath(path)) {
|
||||||
bool open;
|
bool open;
|
||||||
@ -692,11 +706,12 @@ bool FtpServer::processCommand()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// MKD - Make Directory
|
// MKD - Make Directory
|
||||||
//
|
//
|
||||||
else if(CommandIs("MKD")) {
|
else if(CommandIs("MKD"))
|
||||||
|
{
|
||||||
char path[FTP_CWD_SIZE];
|
char path[FTP_CWD_SIZE];
|
||||||
if(haveParameter() && makePath(path)) {
|
if(haveParameter() && makePath(path)) {
|
||||||
if(exists(path)) {
|
if(exists(path)) {
|
||||||
@ -723,11 +738,12 @@ bool FtpServer::processCommand()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// RMD - Remove a Directory
|
// RMD - Remove a Directory
|
||||||
//
|
//
|
||||||
else if(CommandIs("RMD")) {
|
else if(CommandIs("RMD"))
|
||||||
|
{
|
||||||
char path[FTP_CWD_SIZE];
|
char path[FTP_CWD_SIZE];
|
||||||
if(haveParameter() && makeExistsPath(path)) {
|
if(haveParameter() && makeExistsPath(path)) {
|
||||||
if(removeDir(path)) {
|
if(removeDir(path)) {
|
||||||
@ -743,11 +759,12 @@ bool FtpServer::processCommand()
|
|||||||
client.println(F("\". Directory not empty?"));
|
client.println(F("\". Directory not empty?"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// RNFR - Rename From
|
// RNFR - Rename From
|
||||||
//
|
//
|
||||||
else if(CommandIs("RNFR")) {
|
else if(CommandIs("RNFR"))
|
||||||
|
{
|
||||||
rnfrName[0] = 0;
|
rnfrName[0] = 0;
|
||||||
if(haveParameter() && makeExistsPath(rnfrName)) {
|
if(haveParameter() && makeExistsPath(rnfrName)) {
|
||||||
DEBUG_PRINT(F(" Ready for renaming "));
|
DEBUG_PRINT(F(" Ready for renaming "));
|
||||||
@ -756,11 +773,12 @@ bool FtpServer::processCommand()
|
|||||||
client.println(F("350 RNFR accepted - file exists, ready for destination"));
|
client.println(F("350 RNFR accepted - file exists, ready for destination"));
|
||||||
rnfrCmd = true;
|
rnfrCmd = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// RNTO - Rename To
|
// RNTO - Rename To
|
||||||
//
|
//
|
||||||
else if(CommandIs("RNTO")) {
|
else if(CommandIs("RNTO"))
|
||||||
|
{
|
||||||
char path[FTP_CWD_SIZE];
|
char path[FTP_CWD_SIZE];
|
||||||
char dirp[FTP_FIL_SIZE];
|
char dirp[FTP_FIL_SIZE];
|
||||||
if(strlen(rnfrName) == 0 || !rnfrCmd) {
|
if(strlen(rnfrName) == 0 || !rnfrCmd) {
|
||||||
@ -798,25 +816,26 @@ bool FtpServer::processCommand()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
rnfrCmd = false;
|
rnfrCmd = false;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
//
|
//
|
||||||
// SYST - System
|
// SYST - System
|
||||||
//
|
//
|
||||||
else if( CommandIs( "SYST" ))
|
else if( CommandIs( "SYST" ))
|
||||||
FtpOutCli << F("215 MSDOS") << endl;
|
FtpOutCli << F("215 MSDOS") << endl;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
// //
|
// //
|
||||||
// EXTENSIONS COMMANDS (RFC 3659) //
|
// EXTENSIONS COMMANDS (RFC 3659) //
|
||||||
// //
|
// //
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
|
||||||
//
|
//
|
||||||
// MDTM && MFMT - File Modification Time (see RFC 3659)
|
// MDTM && MFMT - File Modification Time (see RFC 3659)
|
||||||
//
|
//
|
||||||
else if(CommandIs("MDTM") || CommandIs("MFMT")) {
|
else if(CommandIs("MDTM") || CommandIs("MFMT"))
|
||||||
|
{
|
||||||
if(haveParameter()) {
|
if(haveParameter()) {
|
||||||
char path[FTP_CWD_SIZE];
|
char path[FTP_CWD_SIZE];
|
||||||
char* fname = parameter;
|
char* fname = parameter;
|
||||||
@ -852,11 +871,12 @@ bool FtpServer::processCommand()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// SIZE - Size of the file
|
// SIZE - Size of the file
|
||||||
//
|
//
|
||||||
else if(CommandIs("SIZE")) {
|
else if(CommandIs("SIZE"))
|
||||||
|
{
|
||||||
char path[FTP_CWD_SIZE];
|
char path[FTP_CWD_SIZE];
|
||||||
if(haveParameter() && makeExistsPath(path)) {
|
if(haveParameter() && makeExistsPath(path)) {
|
||||||
if(!openFile(path, FTP_FILE_READ)) {
|
if(!openFile(path, FTP_FILE_READ)) {
|
||||||
@ -868,11 +888,12 @@ bool FtpServer::processCommand()
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// SITE - System command
|
// SITE - System command
|
||||||
//
|
//
|
||||||
else if(CommandIs("SITE")) {
|
else if(CommandIs("SITE"))
|
||||||
|
{
|
||||||
if(ParameterIs("FREE")) {
|
if(ParameterIs("FREE")) {
|
||||||
uint32_t capa = capacity();
|
uint32_t capa = capacity();
|
||||||
if((capa >> 10) < 1000) { // less than 1 Giga
|
if((capa >> 10) < 1000) { // less than 1 Giga
|
||||||
@ -892,13 +913,12 @@ bool FtpServer::processCommand()
|
|||||||
client.print(F("500 Unknow SITE command "));
|
client.print(F("500 Unknow SITE command "));
|
||||||
client.println(parameter);
|
client.println(parameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// Unrecognized commands ...
|
// Unrecognized commands ...
|
||||||
//
|
//
|
||||||
else
|
else client.println(F("500 Unknow command"));
|
||||||
client.println(F("500 Unknow command"));
|
return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int FtpServer::dataConnect(bool out150)
|
int FtpServer::dataConnect(bool out150)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user