mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-27 07:44:35 +02:00
2007-08-16 Esteban Sanchez <estebans@artica.es>
* ftp/pandora_ftp_test.[cc,h]: Added to repository. Implements a FTP test to be run on command line. * main.cc: Added --test-ftp option to perform a FTP test. * PandoraAgent.dev: Added new files. * bin/PandoraAgent.exe: Updated to last commit. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@599 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
50af40da9f
commit
2857fc9e84
@ -1,3 +1,14 @@
|
|||||||
|
2007-08-16 Esteban Sanchez <estebans@artica.es>
|
||||||
|
|
||||||
|
* ftp/pandora_ftp_test.[cc,h]: Added to repository. Implements a FTP
|
||||||
|
test to be run on command line.
|
||||||
|
|
||||||
|
* main.cc: Added --test-ftp option to perform a FTP test.
|
||||||
|
|
||||||
|
* PandoraAgent.dev: Added new files.
|
||||||
|
|
||||||
|
* bin/PandoraAgent.exe: Updated to last commit.
|
||||||
|
|
||||||
2007-08-16 Esteban Sanchez <estebans@artica.es>
|
2007-08-16 Esteban Sanchez <estebans@artica.es>
|
||||||
|
|
||||||
* pandora_windows_service.cc: Do not check debug flag if copying was
|
* pandora_windows_service.cc: Do not check debug flag if copying was
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[Project]
|
[Project]
|
||||||
FileName=PandoraAgent.dev
|
FileName=PandoraAgent.dev
|
||||||
Name=PandoraAgent
|
Name=PandoraAgent
|
||||||
UnitCount=67
|
UnitCount=69
|
||||||
Type=1
|
Type=1
|
||||||
Ver=1
|
Ver=1
|
||||||
ObjFiles=
|
ObjFiles=
|
||||||
@ -717,3 +717,23 @@ Priority=1000
|
|||||||
OverrideBuildCmd=0
|
OverrideBuildCmd=0
|
||||||
BuildCmd=
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit68]
|
||||||
|
FileName=ftp\pandora_ftp_test.cc
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=FTP
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit69]
|
||||||
|
FileName=ftp\pandora_ftp_test.h
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=FTP
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
Binary file not shown.
179
pandora_agents/win32/ftp/pandora_ftp_test.cc
Normal file
179
pandora_agents/win32/ftp/pandora_ftp_test.cc
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
/* Test module to prove FTP connection.
|
||||||
|
|
||||||
|
Copyright (C) 2006 Artica ST.
|
||||||
|
Written by Esteban Sanchez.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pandora_ftp_test.h"
|
||||||
|
#include "../tinyxml/tinyxml.h"
|
||||||
|
#include "../misc/pandora_file.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <dir.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace FTP;
|
||||||
|
using namespace Pandora;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Pandora_FTP_Test object.
|
||||||
|
*
|
||||||
|
* It will read the configuration file and prepares
|
||||||
|
* all the information to perform a FTP test.
|
||||||
|
*/
|
||||||
|
Pandora_FTP_Test::Pandora_FTP_Test () {
|
||||||
|
string conf_file;
|
||||||
|
|
||||||
|
conf_file = Pandora::getPandoraInstallDir ();
|
||||||
|
conf_file += "pandora_agent.conf";
|
||||||
|
conf = new Pandora_Agent_Conf (conf_file);
|
||||||
|
|
||||||
|
ftp_client = new FTP::Pandora_Ftp_Client ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a Pandora_FTP_Test object.
|
||||||
|
*/
|
||||||
|
Pandora_FTP_Test::~Pandora_FTP_Test () {
|
||||||
|
delete conf;
|
||||||
|
delete ftp_client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a FTP test.
|
||||||
|
*
|
||||||
|
* It will generate a lot of output to the stdout.
|
||||||
|
*
|
||||||
|
* @exception Authentication_Failed Throwed if the authentication process
|
||||||
|
* failed when connecting to the host.
|
||||||
|
* @exception Socket_Error Throwed when something goes bad with the sockets.
|
||||||
|
* @exception Resolv_Failed Throwed when the remote host could not be resolved
|
||||||
|
* to a valid IP.
|
||||||
|
* @exception Connection_Failed Throwed if the TCP/IP connection to the host
|
||||||
|
* failed or could not be done. It includes timeouts, route failures,
|
||||||
|
* etc
|
||||||
|
* @exception Session_Error Throwed if there was problem with the FTP session.
|
||||||
|
* @exception Pandora::Pandora_Exception Throwed if there was an unespecified
|
||||||
|
* error.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Pandora_FTP_Test::test () {
|
||||||
|
string password, tmp_filename;
|
||||||
|
string remote_host, remote_filepath, tmp_filepath;
|
||||||
|
TiXmlDocument *doc;
|
||||||
|
TiXmlDeclaration *decl;
|
||||||
|
bool saved;
|
||||||
|
char *err;
|
||||||
|
DIR *dir;
|
||||||
|
|
||||||
|
remote_host = this->conf->getValue ("server_ip");
|
||||||
|
cout << "Connecting with " << remote_host << "..." << endl;
|
||||||
|
password = this->conf->getValue ("ftp_password");
|
||||||
|
if (password == "") {
|
||||||
|
cout << "FTP password not found in configuration file." << endl;
|
||||||
|
cout << "Check that ftp_password variable is set." << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cout << "Username: pandora" << endl;
|
||||||
|
|
||||||
|
ftp_client = new FTP::Pandora_Ftp_Client ();
|
||||||
|
ftp_client->connect (remote_host,
|
||||||
|
22,
|
||||||
|
"pandora",
|
||||||
|
password);
|
||||||
|
|
||||||
|
dir = opendir (conf->getValue ("temporal").c_str ());
|
||||||
|
if (dir == NULL) {
|
||||||
|
cout << "Error when opening temporal directory." << endl;
|
||||||
|
cout << "Check that \"" << conf->getValue ("temporal")
|
||||||
|
<< "\" exists" << endl;
|
||||||
|
delete ftp_client;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
closedir (dir);
|
||||||
|
|
||||||
|
tmp_filename = "ftp.test";
|
||||||
|
tmp_filepath = conf->getValue ("temporal");
|
||||||
|
if (tmp_filepath[tmp_filepath.length () - 1] != '\\') {
|
||||||
|
tmp_filepath += "\\";
|
||||||
|
}
|
||||||
|
tmp_filepath += tmp_filename;
|
||||||
|
|
||||||
|
decl = new TiXmlDeclaration( "1.0", "ISO-8859-1", "" );
|
||||||
|
doc = new TiXmlDocument (tmp_filepath);
|
||||||
|
doc->InsertEndChild (*decl);
|
||||||
|
saved = doc->SaveFile();
|
||||||
|
if (!saved) {
|
||||||
|
Pandora_Exception e;
|
||||||
|
cout << "Error when saving the XML in " << tmp_filepath << endl;
|
||||||
|
if (doc->Error ()) {
|
||||||
|
cout << "Reason: " << doc->ErrorDesc () << endl;
|
||||||
|
}
|
||||||
|
cout << "Check the configuration file" << endl;
|
||||||
|
delete doc;
|
||||||
|
delete ftp_client;
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
delete doc;
|
||||||
|
|
||||||
|
cout << "Created a blank XML file in " << tmp_filepath<< endl;
|
||||||
|
|
||||||
|
remote_filepath = conf->getValue ("server_path");
|
||||||
|
if (remote_filepath[remote_filepath.length () - 1] != '/') {
|
||||||
|
remote_filepath += "/";
|
||||||
|
}
|
||||||
|
cout << "Remote copying " << tmp_filepath << "on server " << remote_host
|
||||||
|
<< " at " << remote_filepath << tmp_filename << endl;
|
||||||
|
|
||||||
|
try {
|
||||||
|
ftp_client->ftpFileFilename (remote_filepath + tmp_filename,
|
||||||
|
tmp_filepath);
|
||||||
|
} catch (FTP::Unknown_Host e) {
|
||||||
|
cout << "Failed when copying to " << remote_host << " (" <<
|
||||||
|
ftp_client->getError () << ")" << endl;
|
||||||
|
delete ftp_client;
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
} catch (FTP::Authentication_Failed e) {
|
||||||
|
cout << "Authentication Failed when connecting to " << remote_host << " ("
|
||||||
|
<< ftp_client->getError () << ")" << endl;
|
||||||
|
delete ftp_client;
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
} catch (FTP::FTP_Exception e) {
|
||||||
|
cout << "Failed when copying to " << remote_host <<
|
||||||
|
" (" << ftp_client->getError ()<< ")" << endl;
|
||||||
|
delete ftp_client;
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Successfuly file copied to remote host " << endl;
|
||||||
|
ftp_client->disconnect ();
|
||||||
|
delete ftp_client;
|
||||||
|
|
||||||
|
cout << "Successfuly disconnected from remote host " << endl;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Pandora_File::removeFile (tmp_filepath);
|
||||||
|
} catch (Pandora_File::Delete_Error e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "The FTP test was successful!" << endl;
|
||||||
|
}
|
42
pandora_agents/win32/ftp/pandora_ftp_test.h
Normal file
42
pandora_agents/win32/ftp/pandora_ftp_test.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* Test module to prove FTP connection.
|
||||||
|
|
||||||
|
Copyright (C) 2006 Artica ST.
|
||||||
|
Written by Esteban Sanchez.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pandora_ftp_client.h"
|
||||||
|
#include "../pandora_agent_conf.h"
|
||||||
|
|
||||||
|
using namespace Pandora;
|
||||||
|
|
||||||
|
namespace FTP {
|
||||||
|
/**
|
||||||
|
* Class to perform a test of the FTP configuration.
|
||||||
|
*
|
||||||
|
* An object of this class will read the configuration file
|
||||||
|
* and copy a blank xml file into remote server path.
|
||||||
|
*/
|
||||||
|
class Pandora_FTP_Test {
|
||||||
|
private:
|
||||||
|
Pandora_Ftp_Client *ftp_client;
|
||||||
|
Pandora_Agent_Conf *conf;
|
||||||
|
public:
|
||||||
|
Pandora_FTP_Test ();
|
||||||
|
~Pandora_FTP_Test ();
|
||||||
|
void test ();
|
||||||
|
};
|
||||||
|
}
|
@ -21,11 +21,13 @@
|
|||||||
#include "pandora.h"
|
#include "pandora.h"
|
||||||
#include "pandora_windows_service.h"
|
#include "pandora_windows_service.h"
|
||||||
#include "ssh/pandora_ssh_test.h"
|
#include "ssh/pandora_ssh_test.h"
|
||||||
|
#include "ftp/pandora_ftp_test.h"
|
||||||
|
|
||||||
#define PATH_SIZE _MAX_PATH+1
|
#define PATH_SIZE _MAX_PATH+1
|
||||||
#define SERVICE_INSTALL_CMDLINE_PARAM "--install"
|
#define SERVICE_INSTALL_CMDLINE_PARAM "--install"
|
||||||
#define SERVICE_UNINSTALL_CMDLINE_PARAM "--uninstall"
|
#define SERVICE_UNINSTALL_CMDLINE_PARAM "--uninstall"
|
||||||
#define SSH_TEST_CMDLINE_PARAM "--test-ssh"
|
#define SSH_TEST_CMDLINE_PARAM "--test-ssh"
|
||||||
|
#define FTP_TEST_CMDLINE_PARAM "--test-ftp"
|
||||||
#define HELP_CMDLINE_PARAM "--help"
|
#define HELP_CMDLINE_PARAM "--help"
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -72,8 +74,22 @@ main (int argc, char *argv[]) {
|
|||||||
} catch (Pandora_Exception e) {
|
} catch (Pandora_Exception e) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
} else if (_stricmp(argv[i], FTP_TEST_CMDLINE_PARAM) == 0) {
|
||||||
|
/* SSH test parameter */
|
||||||
|
FTP::Pandora_FTP_Test ftp_test;
|
||||||
|
|
||||||
|
delete service;
|
||||||
|
|
||||||
|
try {
|
||||||
|
ftp_test.test ();
|
||||||
|
} catch (Pandora_Exception e) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} else if (_stricmp(argv[i], HELP_CMDLINE_PARAM) == 0) {
|
} else if (_stricmp(argv[i], HELP_CMDLINE_PARAM) == 0) {
|
||||||
/* Help parameter */
|
/* Help parameter */
|
||||||
cout << "Usage: " << argv[0] << " [OPTION]" << endl << endl;
|
cout << "Usage: " << argv[0] << " [OPTION]" << endl << endl;
|
||||||
@ -84,12 +100,17 @@ main (int argc, char *argv[]) {
|
|||||||
cout << ": Uninstall the Pandora Agent service." << endl;
|
cout << ": Uninstall the Pandora Agent service." << endl;
|
||||||
cout << "\t" << SSH_TEST_CMDLINE_PARAM;
|
cout << "\t" << SSH_TEST_CMDLINE_PARAM;
|
||||||
cout << ": Test the SSH Pandora Agent configuration." << endl;
|
cout << ": Test the SSH Pandora Agent configuration." << endl;
|
||||||
|
cout << "\t" << FTP_TEST_CMDLINE_PARAM;
|
||||||
|
cout << ": Test the FTP Pandora Agent configuration." << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
/* No parameter recognized */
|
/* No parameter recognized */
|
||||||
cout << "Usage: " << argv[0] << " [" << SERVICE_INSTALL_CMDLINE_PARAM;
|
cout << "Usage: " << argv[0] << " [" << SERVICE_INSTALL_CMDLINE_PARAM;
|
||||||
cout << "] [" << SERVICE_UNINSTALL_CMDLINE_PARAM << "]" << endl;
|
cout << "] [" << SERVICE_UNINSTALL_CMDLINE_PARAM;
|
||||||
|
cout << "] [" << SSH_TEST_CMDLINE_PARAM;
|
||||||
|
cout << "] [" << FTP_TEST_CMDLINE_PARAM;
|
||||||
|
cout << endl;
|
||||||
cout << "Run " << argv[0] << "with " << HELP_CMDLINE_PARAM;
|
cout << "Run " << argv[0] << "with " << HELP_CMDLINE_PARAM;
|
||||||
cout << " parameter for more info." << endl;
|
cout << " parameter for more info." << endl;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user