bool ftpMisc::ftpDownload( string filename, string filepath,string localfile ) { stringstream ircOut; ftpConnection *ftp = ftpConnect(); bool result = false; if(!ftp || ftp->failed()) { if(ftp) _ftpConnections->ftpDone( ftp->ftpIDGet() ); return false; } ftp->directoryChange( filepath, true ); result = ftp->fileDownload( localfile, filename ); _ftpConnections->ftpDone( ftp->ftpIDGet() ); return result; }
FtpClientWindow::FtpClientWindow(QWidget *parent, Qt::WFlags flags) : QDialog(parent, flags) { setupUi(this); ftpClient = new FtpClient(this); connect(ftpServerLineEdit, SIGNAL(editingFinished ()), this, SLOT(changeServerName())); //connect(ftpServerPortLineEdit, SIGNAL(editingFinished ()), // this, SLOT(changeServerPort())); //connect(userNamelineEdit, SIGNAL(editingFinished ()), // this, SLOT(changeUserName())); //connect(passWordlineEdit, SIGNAL(editingFinished ()), // this, SLOT(changePWD())); connect(listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(processItem(QListWidgetItem *))); connect(listWidget, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(switchDownloadButton())); connect(connectPB, SIGNAL(clicked()), this, SLOT(ftpConnect())); //connect(cdUpDirPB, SIGNAL(clicked()), this, SLOT(cdParent())); connect(downLoadPB, SIGNAL(clicked()), this, SLOT(downloadFile())); connect(putLoadPB, SIGNAL(clicked()), this, SLOT(putloadFile())); connect(choosePB, SIGNAL(clicked()), this, SLOT(chooseFile())); connect(ftpClient, SIGNAL(cmdChangeList(const QUrlInfo &)), this, SLOT(changeList(const QUrlInfo &))); connect(ftpClient, SIGNAL(cmdConncted(bool)), this, SLOT(onConnect(bool))); connect(ftpClient, SIGNAL(cmdGot(bool)), this, SLOT(onGot(bool))); connect(ftpClient, SIGNAL(cmdPut(bool)), this, SLOT(onPut(bool))); connect(ftpClient, SIGNAL(cmdList(bool)), this, SLOT(onList(bool))); //connect(ftpClient, SIGNAL(cmdIsTopDir(bool)), // this, SLOT(onTopDir(bool))); connect(quitPB, SIGNAL(clicked()), this, SLOT(close())); }
error_t ftpClientTest(void) { error_t error; size_t length; IpAddr ipAddr; FtpClientContext ftpContext; static char_t buffer[256]; //Debug message TRACE_INFO("\r\n\r\nResolving server name...\r\n"); //Resolve FTP server name error = getHostByName(NULL, "ftp.gnu.org", &ipAddr, 0); //Any error to report? if(error) { //Debug message TRACE_INFO("Failed to resolve server name!\r\n"); //Exit immediately return error; } //Debug message TRACE_INFO("Connecting to FTP server %s\r\n", ipAddrToString(&ipAddr, NULL)); //Connect to the FTP server error = ftpConnect(&ftpContext, NULL, &ipAddr, 21, FTP_NO_SECURITY | FTP_PASSIVE_MODE); //Any error to report? if(error) { //Debug message TRACE_INFO("Failed to connect to FTP server!\r\n"); //Exit immediately return error; } //Debug message TRACE_INFO("Successful connection\r\n"); //Start of exception handling block do { //Login to the FTP server using the provided username and password error = ftpLogin(&ftpContext, "anonymous", "password", ""); //Any error to report? if(error) break; //Open the specified file for reading error = ftpOpenFile(&ftpContext, "welcome.msg", FTP_FOR_READING | FTP_BINARY_TYPE); //Any error to report? if(error) break; //Dump the contents of the file while(1) { //Read data error = ftpReadFile(&ftpContext, buffer, sizeof(buffer) - 1, &length, 0); //End of file? if(error) break; //Properly terminate the string with a NULL character buffer[length] = '\0'; //Dump current data TRACE_INFO("%s", buffer); } //End the string with a line feed TRACE_INFO("\r\n"); //Close the file error = ftpCloseFile(&ftpContext); //End of exception handling block } while(0); //Close the connection ftpClose(&ftpContext); //Debug message TRACE_INFO("Connection closed...\r\n"); //Return status code return error; }
int main(int argc, char *argv[]) { int status,poll_socket,drive_socket,end=0; int ftpSocket; char *gatheringData = "GROUP1.PHI.SetpointPosition;" "GROUP1.PHI.CurrentPosition;" "GROUP1.KAPPA.SetpointPosition;" "GROUP1.KAPPA.CurrentPosition;" "GROUP1.OMEGA.SetpointPosition;" "GROUP1.OMEGA.CurrentPosition;" "GROUP1.PSI.SetpointPosition;" "GROUP1.PSI.CurrentPosition;" "GROUP1.2THETA.SetpointPosition;" "GROUP1.2THETA.CurrentPosition;" "GROUP1.NU.SetpointPosition;" "GROUP1.NU.CurrentPosition"; char *positioner[NUM_AXES] = {"GROUP1.PHI", "GROUP1.KAPPA", "GROUP1.OMEGA", "GROUP1.PSI", "GROUP1.2THETA", "GROUP1.NU"}; char group[] = "GROUP1"; char outputfilename[500]; double maxp, minp, maxv, maxa; char buffer[BUFFER_SIZE]; int currentSamples, maxSamples; int i; int groupStatus; int eventID; time_t start_time, end_time; poll_socket = TCP_ConnectToServer(XPS_ADDRESS, 5001, POLL_TIMEOUT); drive_socket = TCP_ConnectToServer(XPS_ADDRESS, 5001, DRIVE_TIMEOUT); status = GroupStatusGet(poll_socket, group, &groupStatus); printf("Initial group status=%d\n", groupStatus); /* If group not initialized, then initialize it */ if (groupStatus >= 0 && groupStatus <= 9) { printf("Calling GroupInitialize ...\n"); status = GroupInitialize(drive_socket, group); if (status) { printf("Error calling GroupInitialize error=%d\n", status); return status; } printf("Calling GroupHomeSearch ...\n"); status = GroupHomeSearch(drive_socket, group); if (status) { printf("Error calling GroupHomeSearch error=%d\n", status); return status; } } printf("FTPing trajectory file to XPS ...\n"); /* FTP the trajectory file from the local directory to the XPS */ status = ftpConnect(XPS_ADDRESS, USERNAME, PASSWORD, &ftpSocket); if (status != 0) { printf("Error calling ftpConnect, status=%d\n", status); return status; } status = ftpChangeDir(ftpSocket, TRAJECTORY_DIRECTORY); if (status != 0) { printf("Error calling ftpChangeDir, status=%d\n", status); return status; } status = ftpStoreFile(ftpSocket, TRAJECTORY_FILE); if (status != 0) { printf("Error calling ftpStoreFile, status=%d\n", status); return status; } /* Define trajectory output pulses */ printf("Defining output pulses ...\n"); status = MultipleAxesPVTPulseOutputSet(poll_socket, group, 2, NUM_TRAJECTORY_ELEMENTS-1, PULSE_TIME); /*************************** Verify trajectory **********************/ printf("Verifying trajectory ...\n"); status = MultipleAxesPVTVerification(drive_socket, group, TRAJECTORY_FILE); if (status != 0) { printf("Error performing MultipleAxesPVTVerification, status=%d\n",status); end = 1; } printf("Reading verify results ...\n"); printf(" MultipleAxesPVTVerificationResultGet\n"); for (i=0; i<NUM_AXES; i++) { status = MultipleAxesPVTVerificationResultGet(poll_socket,positioner[i], outputfilename, &minp, &maxp, &maxv, &maxa); printf(" positioner %d, status %d, Max. pos. %g, Min. pos. %g, Max. vel. %g, Max. accel. %g\n", i, status, maxp, minp, maxv, maxa); } if (end == 1) return -1; /***********************Configure Gathering and Timer******************/ printf("Reseting gathering ...\n"); status = GatheringReset(poll_socket); if (status != 0) { printf("Error performing GatheringReset, status=%d\n",status); return status; } printf("Defining gathering ...\n"); status = GatheringConfigurationSet(poll_socket, NUM_AXES*NUM_GATHERING_ITEMS, gatheringData); if (status != 0) { printf("Error performing GatheringConfigurationSet, status=%d\n",status); return status; } printf("Defining trigger ...\n"); status = EventExtendedConfigurationTriggerSet(poll_socket, 2, "Always;GROUP1.PVT.TrajectoryPulse", "","","",""); if (status != 0) { printf("Error performing EventExtendedConfigurationTriggerSet, status=%d\n", status); return status; } printf("Defining action ...\n"); status = EventExtendedConfigurationActionSet(poll_socket, 1, "GatheringOneData", "", "", "", ""); if (status != 0) { printf("Error performing EventExtendedConfigurationActionSet, status=%d\n", status); return status; } printf("Starting gathering ...\n"); status= EventExtendedStart(poll_socket, &eventID); if (status != 0) { printf("Error performing EventExtendedStart, status=%d\n", status); return status; } /********************* Run trajectory ****************************/ status = GroupStatusGet(poll_socket, group, &groupStatus); if (status != 0) { printf("Error performing GroupStatusGet, status=%d\n", status); return status; } printf("Group status before executing trajectory=%d\n", groupStatus); printf("Executing trajectory ...\n"); start_time = time(NULL); status = MultipleAxesPVTExecution(drive_socket, group, TRAJECTORY_FILE, 1); end_time = time(NULL); printf("Time to execute trajectory=%f\n", difftime(end_time, start_time)); if (status != 0) { printf("Error performing MultipleAxesPVTExecution, status=%d\n", status); return status; } status = GroupStatusGet(poll_socket, group, &groupStatus); if (status != 0) { printf("Error performing GroupStatusGet, status=%d\n", status); return status; } printf("Group status after executing trajectory=%d\n", groupStatus); /* Remove the event */ printf("Removing event ...\n"); status = EventExtendedRemove(poll_socket, eventID); if (status != 0) { printf("Error performing ExtendedEventRemove, status=%d\n", status); return status; } /***********************Save the gathered data ***************/ printf("Stopping gathering ...\n"); start_time = time(NULL); status = GatheringStop(drive_socket); end_time = time(NULL); printf("Time to stop gathering=%f\n", difftime(end_time, start_time)); if (status != 0) { printf("Error performing GatheringExternalStop, status=%d\n", status); return status; } status = GroupStatusGet(poll_socket, group, &groupStatus); if (status != 0) { printf("Error performing GroupStatusGet, status=%d\n", status); return status; } printf("Group status after stopping gathering=%d\n", groupStatus); /* Read the number of lines of gathering */ status = GatheringCurrentNumberGet(drive_socket, ¤tSamples, &maxSamples); if (status != 0) { printf("Error calling GatherCurrentNumberGet, status=%d\n", status); return status; } if (currentSamples != NUM_GATHERING_POINTS) { printf("readGathering: warning, NUM_GATHERING_POINTS=%d, currentSamples=%d\n", NUM_GATHERING_POINTS, currentSamples); } status = GatheringDataMultipleLinesGet(drive_socket, 0, currentSamples, buffer); printf("GatheringDataMultipleLinesGet, status=%d, currentSamples=%d\n", status, currentSamples); printf("Buffer length=%d, buffer=\n%s\n", strlen(buffer), buffer); return 0; }
bool ftpMisc::ftpExecuteCommand( string command, vector<string> &responses ) { ftpConnection *ftp = 0; bool actResult = false; string argument; size_t pos; pos = command.find(" "); if( pos != string::npos ) { argument = command.substr( pos + 1 ); command = command.substr(0, pos); } transform( command.begin(), command.end(), command.begin(), ::tolower ); ftp = ftpConnect(); if(!ftp || ftp->failed()) { string fail = string( "Connection Failed. " ); if(ftp) { fail.append( ftp->errorGet() ); _ftpConnections->ftpDone( ftp->ftpIDGet() ); } responses.push_back( fail ); return false; } try { if(command == "list") { // No path? use root if(!argument.size()) argument = "/"; ftpEntry *entry = new ftpEntry(0, _serverConnection, argument, 0, (serverDetail()->_ftpType == ftpTypeRAIDEN) ? true : false ); if( ftp->directoryChange(argument, true) == false) responses = *ftp->ResponsesGet(); else { size_t count = 0; // Read/Process directorys responses = ftp->directoryRead( entry, true ); entry->entryProcess( responses, false ); actResult = !ftp->failed(); responses.clear(); // add all folders/files into responses vector<ftpEntry*>::iterator entryIT; for( entryIT = entry->entrysDirectorysGet()->begin(); entryIT != entry->entrysDirectorysGet()->end(); ++entryIT, count++ ) { responses.push_back( (*entryIT)->pathGet() ); if(count > 19) break; } for( entryIT = entry->entrysFilesGet()->begin(); entryIT != entry->entrysFilesGet()->end(); ++entryIT, count++ ) { responses.push_back( (*entryIT)->entryNameGet() ); if(count > 19) break; } } } else if(command == "site") { // Site Commands string argumentCmd, param; pos = argument.find(" "); if(pos != string::npos) { argumentCmd = argument.substr(0, pos); param = argument.substr(pos+1); } else argumentCmd = argument; if( argumentCmd.substr(0, 10) == "extractrar" ) { string target; if(param.substr( param.size()-1, 1 ) == "/") param.erase( param.size()-1, 1); pos = param.find_last_of("/" ); if(pos != string::npos) { target = param.substr( pos + 1 ); if(ftp->directoryChange(param)) ftp->siteCommand("extractrar", target); } vector<string> *str = ftp->ResponsesGet(); vector<string>::iterator strIT; for( strIT = str->begin(); strIT != str->end(); ++strIT) { responses.push_back( *strIT ); } } else { //actResult = ftp->command(command, argument); //responses = *ftp->ResponsesGet(); responses.push_back("all commands except list disabled"); } } } catch(...) { } _ftpConnections->ftpDone( ftp->ftpIDGet() ); return actResult; }
ftpTypes ftpMisc::ftpTypeTest(bool forceTalk) { serverDetails *server = _serverConnection->serverGet(); stringstream ircOut; bool result = false; ftpTypes ftpType = ftpTypeUNKNOWN; string response; size_t pos = 0; ftpConnection *ftp = 0; try { ftp = ftpConnect(); if(!ftp || ftp->failed()) { if(ftp) _ftpConnections->ftpDone( ftp->ftpIDGet() ); return ftpTypeUNKNOWN; } ircOut << Spidz->ircName( server ); // site vers check result = ftp->siteCommand("vers"); if(result) { //200 glFTPd 2.01 FreeBSD+TLS if( (response = responseFind( ftp, "glftpd", true )) != "" ) { ftpType = ftpTypeGLFTPD; ircOut << " glFTPd detected"; } } // site ver check if(!result) { result = ftp->siteCommand("ver"); if(result && ftpType == ftpTypeUNKNOWN) { //[15:50:28] [L] 220--------------------------------[ SITE VER ]------------------------------------ //[15:50:28] [L] 220-Running RaidenFTPD v2.4 build 3401 //[15:50:28] [L] 220 . if( (response = responseFind( ftp, "raidenftpd", true )) != "" ) { ftpType = ftpTypeRAIDEN; ircOut << " raidenFTPd detected"; } } } if(!result) { result = ftp->siteCommand("version"); //Running ioFTPD version 5-8-5r if(result && ftpType == ftpTypeUNKNOWN) { if( (response = responseFind( ftp, "ioftpd", true )) != "" ) { ftpType = ftpTypeIOFTPD; ircOut << " ioFTPd detected"; } } } if(!result) { response = ftp->ftpResponse(); ircOut << " unknown FTPd: " << response; } if(response.size() < 4) response = ftp->ftpResponse(); // Only talk to irc if the ftp type was previoausly unknown, or if it has changed if( server->_ftpType == ftpTypeUNKNOWN || server->_ftpType != ftpType || forceTalk) { if( response.size() > 4 ) ircOut << " " << response.substr(4); else ircOut << " No Response"; if(ircOut.str().size()) Spidz->IRCChat( ircOut, channelPUBLIC ); if(server->_ftpType != ftpType && ftpType != ftpTypeUNKNOWN) { Spidz->serverGet()->moduleGet< moduleSpidz >(modSPIDZ)->serverTypeSet( _serverID, ftpType ); server->_ftpType = ftpType; // Return the stored ftp type if we couldnt determine it, but its in the DB already } else if( server->_ftpType != ftpType && ftpType == ftpTypeUNKNOWN ) ftpType = server->_ftpType; } } catch(...) { } if( ftp ) _ftpConnections->ftpDone( ftp->ftpIDGet() ); return ftpType; }
bool ftpMisc::ftpFXP( pathFXP *Fxp, string &error ) { ftpMisc *miscDest = 0; ftpConnection *ftp = ftpConnect(); bool result = false; stringstream ircOut; size_t errorCode = 0; // Ensure source connects if(!ftp || ftp->failed()) { if(ftp) _ftpConnections->ftpDone( ftp->ftpIDGet() ); return false; } miscDest = new ftpMisc( Fxp->destID, this->_thread ); // Ensure destination connects ftpConnection *destFtp = miscDest->ftpConnect(); // Ensure destination connects if(!destFtp || destFtp->failed()) { if(ftp) _ftpConnections->ftpDone( ftp->ftpIDGet() ); delete miscDest; return false; } try { // Source: Change directory if(!ftp->directoryChange( Fxp->sourcePath ) ) { _ftpConnections->ftpDone( ftp->ftpIDGet() ); miscDest->ftpDone( destFtp->ftpIDGet() ); delete miscDest; return false; } // Dest: Change/Create directory if(!destFtp->directoryChange( Fxp->destPath )) { // Create the target folder destFtp->directoryCreate( Fxp->destPath ); // If it fails again, fail if(!destFtp->directoryChange( Fxp->destPath )) { _ftpConnections->ftpDone( ftp->ftpIDGet() ); miscDest->ftpDone( destFtp->ftpIDGet() ); delete miscDest; return false; } } string errorDest; // Do the fxp result = ftp->fileTransfer( destFtp, Fxp->filename, Fxp->filename, errorDest ); error = ftp->errorGet(); if(!result) { ircOut.str(""); ircOut << Spidz->ircName( _serverID, false ) << "->" << Spidz->ircName( Fxp->destID, false ) << " " << Fxp->filename << " Failed: "; ircOut << error; //errorCode = atoi(error.c_str()); // glftpd dupecheck fail //if(errorCode != 553) if( ircOut.str().find("dupe") != string::npos ) Spidz->IRCChat( ircOut, channelPUBLIC ); } } catch (... ) { } _ftpConnections->ftpDone( ftp->ftpIDGet() ); miscDest->ftpDone( destFtp->ftpIDGet() ); delete miscDest; return result; }
bool ftpMisc::ftpTest( bool silent, size_t flags, bool firstAttempt ) { serverDetails *serverMaster = 0; stringstream ircMessage; ftpConnection *ftp = 0; ftpEntry *ftpRoot = 0; try { // Test the Connection ircMessage << Spidz->ircName( serverDetail() ); ircMessage << " Connecting as "; if( serverDetail()->_serverMasterID) { serverMaster = _serverConnection->serverMasterGet(); ircMessage << ((_scanAccount) ? serverMaster->_scanUsername : serverMaster->_serverUsername); } else ircMessage << ((_scanAccount) ? serverDetail()->_scanUsername : serverDetail()->_serverUsername); if(!silent) Spidz->IRCChat( ircMessage, channelPUBLIC ); _ftpConnections->ftpNoClose( true ); ftp = ftpConnect(); // Check connection ircMessage.str(""); ircMessage << Spidz->ircName( serverDetail() ); if(!ftp || ftp->failed()) { ircMessage << " Connection Failed. "; ircMessage << _lastError; if(!firstAttempt) Spidz->IRCChat( ircMessage, channelPUBLIC ); if(ftp) _ftpConnections->ftpDone( ftp->ftpIDGet() ); _ftpConnections->ftpNoClose( false ); return false; } // Allow typetest to use our ftp connection _ftpConnections->ftpDone( ftp->ftpIDGet() ); ftpTypeTest( !silent ); if( serverDetail()->_serverMasterID ) { ircMessage << " Master Found, skipping password change"; if(!silent) Spidz->IRCChat( ircMessage, channelPUBLIC ); ircMessage.str(""); ircMessage << Spidz->ircName( serverDetail() ); } else { if( flags & ftpTestPasswordChange ) { if(!silent) { string pass = randomString(8); ircMessage << " Changing Password"; Spidz->IRCChat( ircMessage, channelPUBLIC ); ircMessage.str(""); ircMessage << Spidz->ircName( serverDetail() ); if( ftpPasswordChange( pass ) == false ) { ircMessage << " Password Change Failed: " << pass; Spidz->IRCChat( ircMessage, channelPUBLIC ); _ftpConnections->ftpNoClose( false ); return false; } } } } // Grab it back ftp = ftpConnect(); ftpRoot = new ftpEntry(0, _serverConnection, "/", 0, false ); // Lets do a directory test ircMessage << " Changing to " << ftpRoot->pathGet(); if(!silent) Spidz->IRCChat( ircMessage, channelPUBLIC ); ircMessage.str(""); ircMessage << Spidz->ircName( serverDetail() ); if( !ftp->directoryChange(ftpRoot->pathGet(), true) ) { ircMessage << " Directory Change Failed. "; if(!firstAttempt) Spidz->IRCChat( ircMessage, channelPUBLIC ); _ftpConnections->ftpDone( ftp->ftpIDGet() ); _ftpConnections->ftpNoClose( false ); delete ftpRoot; return false; } // Lets grab the directory listing ircMessage << " Reading Directory /"; if(!silent) Spidz->IRCChat( ircMessage, channelPUBLIC ); ircMessage.str(""); ircMessage << Spidz->ircName( serverDetail() ); // Read the ftp root, and process it vector<string> entrys = ftp->directoryRead( ftpRoot, true ); size_t directoryCount = 0; if(entrys.size()) ftpRoot->entryProcess( entrys, false ); if(entrys.size() > 1) directoryCount = entrys.size() - 2; // remove .. and . if( ftp->failed() || ! entrys.size() ) { ircMessage << " Directory Read Failed. "; ircMessage << ftp->errorGet(); if(!firstAttempt) Spidz->IRCChat( ircMessage, channelPUBLIC ); _ftpConnections->ftpDone( ftp->ftpIDGet() ); _ftpConnections->ftpNoClose( false ); delete ftpRoot; return false; } else { ircMessage << " Directory Entrys: "; ircMessage << directoryCount; if(!silent) Spidz->IRCChat( ircMessage, channelPUBLIC ); ircMessage.str(""); ircMessage << Spidz->ircName( serverDetail() ); } if(_scanAccount) { ircMessage << " Attempting IPList Upload"; if(!silent) Spidz->IRCChat( ircMessage, channelPUBLIC ); ircMessage.str(""); ircMessage << Spidz->ircName( serverDetail() ); _ftpConnections->ftpDone( ftp->ftpIDGet() ); if(!ftpIPUpdate()) { _ftpConnections->ftpNoClose( false ); delete ftpRoot; return false; } ftp = ftpConnect(); } else { // Not scan account, check for GENERALNAME folder vector<ftpEntry *>::iterator entryIT; string entry; string path = string(GENERALNAME); transform(path.begin(), path.end(), path.begin(), ::tolower); for( entryIT = ftpRoot->entrysDirectorysGet()->begin(); entryIT != ftpRoot->entrysDirectorysGet()->end(); ++entryIT ) { entry = (*entryIT)->entryNameGet(); transform(entry.begin(), entry.end(), entry.begin(), ::tolower); if( entry == path ) { if( ftp->directoryChange(generalNamePath(), true) ) { ircMessage << "Fatal: " << generalNamePath() << " Accessible by general account!"; if(!firstAttempt) Spidz->IRCChat( ircMessage, channelPUBLIC ); _ftpConnections->ftpDone( ftp->ftpIDGet() ); _ftpConnections->ftpNoClose( false ); delete ftpRoot; return false; } else { ircMessage << "Warning: " << generalNamePath() << " Visible from general account!"; if(!firstAttempt) Spidz->IRCChat( ircMessage, channelPUBLIC ); } break; } } } } catch(...) { } if(ftp) _ftpConnections->ftpDone( ftp->ftpIDGet() ); _ftpConnections->ftpNoClose( false ); if(ftpRoot) delete ftpRoot; // FTP is ok return true; }
bool ftpMisc::ftpPasswordChange( string newPassword ) { moduleKillarmy *modKillarmy = Spidz->serverGet()->moduleGet< moduleKillarmy >(modKILLARMY); stringstream ircOut; ftpConnection *ftp = 0; bool actResult, result = false; stringstream ircMessage; string response; string Command; vector<string>::iterator resIT; // Dont change password if we got a master if(serverDetail()->_serverMasterID) return true; if(!_serverID || ! newPassword.size() ) return false; if(!modKillarmy || !_ftpConnections || (serverDetail()->_ftpType == ftpTypeUNKNOWN)) return false; if( serverDetail()->_ftpType == ftpTypeRAIDEN ) { Command = "chpass "; if( _scanAccount ) Command.append( serverDetail()->_scanUsername); else Command.append( serverDetail()->_serverUsername); } else Command = "passwd"; ftp = ftpConnect(); // Failed connection? if(!ftp || ftp->failed()) response = "Connection Failed"; else { // Execute the command actResult = ftp->siteCommand(Command, newPassword); response = ftp->ftpResponse(); // Check for a response if( responseFind( ftp, "success" ) != "" || responseFind( ftp, "password changed") != "" || responseFind( ftp, "password is now") != "") { result = true; } } if(ftp) _ftpConnections->ftpDone( ftp->ftpIDGet() ); if(result) { if(_scanAccount) Spidz->serverGet()->moduleGet<moduleSpidz>(modSPIDZ)->serverScanPasswordChange( _serverID, newPassword); else Spidz->serverGet()->moduleGet<moduleSpidz>(modSPIDZ)->serverPasswordChange( _serverID, newPassword); ircMessage << "PW changed "; } else ircMessage << "PW change failed: " << newPassword << " "; if(_scanAccount) ircMessage << serverDetail()->_scanUsername << " - "; else ircMessage << serverDetail()->_serverUsername << " - "; ircMessage << serverDetail()->_serverName; ircMessage << " " << response; Spidz->IRCChat( ircMessage, channelADMIN ); return result; }
int main(int argc, char *argv[]){ int mySock; char cmd[1024], *param, *cp; char *par[3]; int connecte = 0; ctxClient* client = (ctxClient*)malloc(1*sizeof(ctxClient)); client->serverAddress = (char*)malloc(1*sizeof(char)); printf("Pour voir la liste des commandes supportées tappez 'help' :\n"); do{ printPrompt(); fgets(cmd, sizeof(cmd), stdin); param = strchr(cmd,' '); if (param) { strcpy(cp,param); par[0] = strtok (cp, " "); par[1] = strtok (cp, " "); printf("Par 1 : %s Par 2 %s", par[0], par[1]); } if(strcmp(cmd,"open\n\0")==0){ if(connecte){ printf("Vous êtes déja connecté à un serveur. \n"); } else{ printf("OK connect to server !\n"); mySock = ftpConnect(client,"127.0.0.1", 21); connecte=1; ftpReceiveCommand(client); ftpSendCommand(client,"PASV"); ftpReceiveCommand(client); } } else if(strcmp(cmd,"close\n\0")==0){ ftpSendCommand(client,"close"); } else if(strcmp(cmd,"cd\n\0")==0){ ftpSendCommand(client,"cd"); } else if(strcmp(cmd,"pwd\n\0")==0){ ftpSendCommand(client,"pwd"); } else if(strcmp(cmd,"get\n\0")==0){ ftpSendCommand(client,"get"); } else if(strcmp(cmd,"put\n\0")==0){ ftpSendCommand(client,"put"); } else if(strcmp(cmd,"del\n\0")==0){ ftpSendCommand(client,"del"); } else if(strcmp(cmd,"mkd\n\0")==0){ ftpSendCommand(client,"mkd"); } else if(strcmp(cmd,"rmd\n\0")==0){ ftpSendCommand(client,"rmd"); } else if(strcmp(cmd,"dir\n\0")==0){ ftpSendCommand(client,"dir"); } else if(strcmp(cmd,"help\n\0")==0){ printHelp(); } else if(strcmp(cmd,"exit\n\0")==0); else if(strcmp(cmd,"\n\0")==0); else{ printf("Commande non reconnue \n"); } }while(strcmp(cmd,"exit\n\0")); return 0; }