mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
2007-08-07 Esteban Sanchez <estebans@artica.es>
* pandora.cc: Updated agent version. * pandora.h, modules/pandora_module_exec.cc: Redefine WINVER, so CreateJobProject can be found without modifying windef.h. * pandora_agent_conf.cc: Rewritten a loop. * ftp/pandora_ftp_client.[cc,h]: Added to repository. Implemented FTP transfer protocol using libcurl. It adds a library dependency. * pandora_windows_service.cc: Added support for FTP transfers. Select between SSH (default) or FTP. Improved file structure to be cleaner. * pandora_windows_service.h: Added new private functions and removed unneccessary private attribute. * misc/pandora_file.[cc,h]: Added a function to get the filename of a path. * main.cc: Indentation fixed. * bin/libcurl.dll: Added to repository. New dependency. * bin/PandoraAgent.exe: Updated to last commit. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@594 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
0590bc5aee
commit
cee0fa4897
@ -1,3 +1,30 @@
|
||||
2007-08-07 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* pandora.cc: Updated agent version.
|
||||
|
||||
* pandora.h, modules/pandora_module_exec.cc: Redefine WINVER, so
|
||||
CreateJobProject can be found without modifying windef.h.
|
||||
|
||||
* pandora_agent_conf.cc: Rewritten a loop.
|
||||
|
||||
* ftp/pandora_ftp_client.[cc,h]: Added to repository. Implemented FTP
|
||||
transfer protocol using libcurl. It adds a library dependency.
|
||||
|
||||
* pandora_windows_service.cc: Added support for FTP transfers. Select
|
||||
between SSH (default) or FTP. Improved file structure to be cleaner.
|
||||
|
||||
* pandora_windows_service.h: Added new private functions and removed
|
||||
unneccessary private attribute.
|
||||
|
||||
* misc/pandora_file.[cc,h]: Added a function to get the filename of a
|
||||
path.
|
||||
|
||||
* main.cc: Indentation fixed.
|
||||
|
||||
* bin/libcurl.dll: Added to repository. New dependency.
|
||||
|
||||
* bin/PandoraAgent.exe: Updated to last commit.
|
||||
|
||||
2007-05-23 Raul Mateos <raulofpandora@gmail.com>
|
||||
|
||||
* installer/Pandora_Windows_Agent-1.2.1-Setup.exe: Updated installer.
|
||||
|
@ -1,7 +1,7 @@
|
||||
[Project]
|
||||
FileName=PandoraAgent.dev
|
||||
Name=PandoraAgent
|
||||
UnitCount=65
|
||||
UnitCount=67
|
||||
Type=1
|
||||
Ver=1
|
||||
ObjFiles=
|
||||
@ -12,7 +12,7 @@ ResourceIncludes=
|
||||
MakeIncludes=
|
||||
Compiler=
|
||||
CppCompiler=
|
||||
Linker=-lole32_@@_-loleaut32_@@_-luuid_@@_-lpsapi_@@_-lwsock32_@@_-lz_@@_-liphlpapi_@@_-lnetapi32_@@_-lws2_32_@@_-lcrypto_@@_-lgdi32_@@__@@_
|
||||
Linker=-lole32_@@_-loleaut32_@@_-luuid_@@_-lpsapi_@@_-lwsock32_@@_-lz_@@_-liphlpapi_@@_-lnetapi32_@@_-lws2_32_@@_-lcrypto_@@_-lgdi32_@@_-lcurldll_@@_
|
||||
IsCpp=1
|
||||
Icon=
|
||||
ExeOutput=
|
||||
@ -20,7 +20,7 @@ ObjectOutput=
|
||||
OverrideOutput=0
|
||||
OverrideOutputName=PandoraAgent.exe
|
||||
HostApplication=
|
||||
Folders=Misc,Modules,Modules/Utils,SSH,SSH/libssh2,Windows,Windows/WMI,XML
|
||||
Folders=FTP,Misc,Modules,Modules/Utils,SSH,SSH/libssh2,Windows,Windows/WMI,XML
|
||||
CommandLine=
|
||||
UseCustomMakefile=0
|
||||
CustomMakefile=
|
||||
@ -697,3 +697,23 @@ Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit66]
|
||||
FileName=ftp\pandora_ftp_client.cc
|
||||
CompileCpp=1
|
||||
Folder=FTP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit67]
|
||||
FileName=ftp\pandora_ftp_client.h
|
||||
CompileCpp=1
|
||||
Folder=FTP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
|
Binary file not shown.
BIN
pandora_agents/win32/bin/libcurl.dll
Normal file
BIN
pandora_agents/win32/bin/libcurl.dll
Normal file
Binary file not shown.
196
pandora_agents/win32/ftp/pandora_ftp_client.cc
Normal file
196
pandora_agents/win32/ftp/pandora_ftp_client.cc
Normal file
@ -0,0 +1,196 @@
|
||||
/* Class to abstract an FTP client. It uses libcurl.
|
||||
|
||||
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 <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include "pandora_ftp_client.h"
|
||||
#include "../misc/pandora_file.h"
|
||||
#include "../pandora_strutils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace FTP;
|
||||
using namespace Pandora;
|
||||
|
||||
/**
|
||||
* Creates a FTP client object and initialize its attributes.
|
||||
*/
|
||||
Pandora_Ftp_Client::Pandora_Ftp_Client ()
|
||||
{
|
||||
curl = NULL;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a FTP client object.
|
||||
*
|
||||
* It also disconnect the client from the host if connected.
|
||||
*
|
||||
* @see disconnect
|
||||
*/
|
||||
Pandora_Ftp_Client::~Pandora_Ftp_Client ()
|
||||
{
|
||||
this->disconnect ();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects from remote host.
|
||||
*
|
||||
* It will close all open connections and channels.
|
||||
*/
|
||||
void
|
||||
Pandora_Ftp_Client::disconnect ()
|
||||
{
|
||||
if (curl != NULL) {
|
||||
curl_easy_cleanup (curl);
|
||||
curl = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to specified host and port using a username and a
|
||||
* password.
|
||||
*
|
||||
* @param host Host to connect to.
|
||||
* @param port Port of FTP server in host
|
||||
* @param username FTP username in server.
|
||||
* @param password Username's password in server
|
||||
*/
|
||||
void
|
||||
Pandora_Ftp_Client::connect (const string host,
|
||||
const int port,
|
||||
const string username,
|
||||
const string password)
|
||||
{
|
||||
this->username = username;
|
||||
this->password = password;
|
||||
this->host = host;
|
||||
}
|
||||
|
||||
size_t
|
||||
read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
{
|
||||
return fread (ptr, size, nmemb, stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a file using a FTP connection.
|
||||
*
|
||||
* The function receives a filename in the local filesystem and copies all
|
||||
* its content to the remote host. The remote filename will be the
|
||||
* basename of the local file and will be copied in the remote actual
|
||||
* directory.
|
||||
*
|
||||
* @param remote_filename Remote path to copy the local file in.
|
||||
* @param filename Path to the local file.
|
||||
*/
|
||||
void
|
||||
Pandora_Ftp_Client::ftpFileFilename (const string remote_filename,
|
||||
const string filepath)
|
||||
{
|
||||
FILE *fd;
|
||||
string operation1;
|
||||
string operation2;
|
||||
struct stat file_info;
|
||||
int file;
|
||||
struct curl_slist *headerlist = NULL;
|
||||
string filename;
|
||||
string url;
|
||||
|
||||
if (this->host == "")
|
||||
throw Unknown_Host ();
|
||||
|
||||
filename = Pandora_File::fileName (filepath);
|
||||
|
||||
url = "ftp://";
|
||||
url += username;
|
||||
url += ':';
|
||||
url += password;
|
||||
url += '@';
|
||||
url += host;
|
||||
url += '/';
|
||||
url += filename;
|
||||
|
||||
file = open (filepath.c_str (), O_RDONLY);
|
||||
fstat (file, &file_info);
|
||||
close (file);
|
||||
|
||||
fd = fopen (filepath.c_str (), "rb");
|
||||
|
||||
curl_global_init (CURL_GLOBAL_ALL);
|
||||
|
||||
this->curl = curl_easy_init ();
|
||||
if (this->curl) {
|
||||
|
||||
pandoraLog ("Copying %s to %s%s", filepath.c_str (), this->host.c_str (),
|
||||
remote_filename.c_str ());
|
||||
|
||||
operation1 = "RNFR " + filename;
|
||||
headerlist = curl_slist_append (headerlist, operation1.c_str ());
|
||||
|
||||
operation2 = "RNTO " + remote_filename;
|
||||
headerlist = curl_slist_append (headerlist, operation2.c_str ());
|
||||
|
||||
curl_easy_setopt (this->curl, CURLOPT_UPLOAD, 1) ;
|
||||
curl_easy_setopt (this->curl, CURLOPT_URL, url.c_str ());
|
||||
curl_easy_setopt (this->curl, CURLOPT_POSTQUOTE, headerlist);
|
||||
curl_easy_setopt (this->curl, CURLOPT_READFUNCTION, read_func);
|
||||
curl_easy_setopt (this->curl, CURLOPT_READDATA, fd);
|
||||
curl_easy_setopt (curl, CURLOPT_INFILESIZE_LARGE,
|
||||
(curl_off_t) file_info.st_size);
|
||||
|
||||
this->result = curl_easy_perform (this->curl);
|
||||
|
||||
curl_slist_free_all (headerlist);
|
||||
curl_easy_cleanup (this->curl);
|
||||
|
||||
this->curl = NULL;
|
||||
}
|
||||
|
||||
curl_global_cleanup ();
|
||||
fclose (fd);
|
||||
|
||||
switch (this->result) {
|
||||
case CURLE_OK:
|
||||
break;
|
||||
case CURLE_COULDNT_CONNECT:
|
||||
throw Unknown_Host ();
|
||||
|
||||
break;
|
||||
case CURLE_FTP_ACCESS_DENIED:
|
||||
throw Authentication_Failed ();
|
||||
|
||||
break;
|
||||
default:
|
||||
throw FTP_Exception ();
|
||||
}
|
||||
}
|
||||
|
||||
string
|
||||
Pandora_Ftp_Client::getError ()
|
||||
{
|
||||
string error (curl_easy_strerror (this->result));
|
||||
|
||||
return error;
|
||||
}
|
80
pandora_agents/win32/ftp/pandora_ftp_client.h
Normal file
80
pandora_agents/win32/ftp/pandora_ftp_client.h
Normal file
@ -0,0 +1,80 @@
|
||||
/* Class to abstract an FTP client. It uses libcurl.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __PANDORA_FTP_CLIENT__
|
||||
#define __PANDORA_FTP_CLIENT__
|
||||
|
||||
#include <string>
|
||||
#include "../pandora.h"
|
||||
#include <curl/curl.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* FTP connection classes.
|
||||
*/
|
||||
namespace FTP {
|
||||
/**
|
||||
* A FTP super-class exception.
|
||||
*/
|
||||
class FTP_Exception : public Pandora::Pandora_Exception {
|
||||
};
|
||||
|
||||
/**
|
||||
* The FTP authentication fails when connecting.
|
||||
*/
|
||||
class Authentication_Failed : public FTP::FTP_Exception {
|
||||
};
|
||||
|
||||
/**
|
||||
* The FTP host is unknown.
|
||||
*/
|
||||
class Unknown_Host : public FTP::FTP_Exception {
|
||||
};
|
||||
|
||||
/**
|
||||
* Client to perform a FTP connection to a host.
|
||||
*/
|
||||
class Pandora_Ftp_Client {
|
||||
private:
|
||||
string host;
|
||||
string username;
|
||||
string password;
|
||||
|
||||
CURL *curl;
|
||||
CURLcode result;
|
||||
public:
|
||||
Pandora_Ftp_Client ();
|
||||
~Pandora_Ftp_Client ();
|
||||
|
||||
void connect (const string host,
|
||||
const int port,
|
||||
const string username,
|
||||
const string password);
|
||||
|
||||
void disconnect ();
|
||||
|
||||
void ftpFileFilename (const string remote_filename,
|
||||
const string filepath);
|
||||
|
||||
string getError ();
|
||||
};
|
||||
}
|
||||
#endif
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "pandora_file.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
@ -106,3 +107,25 @@ Pandora_File::writeFile (const string filepath, const string data) {
|
||||
file.write (data.c_str (), data.length ());
|
||||
file.close ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename of a complete filepath.
|
||||
*
|
||||
* @param filepath
|
||||
*/
|
||||
string
|
||||
Pandora_File::fileName (const string filepath)
|
||||
{
|
||||
string filename;
|
||||
int pos;
|
||||
|
||||
pos = filepath.find_last_of ("\\");
|
||||
|
||||
if (pos != string::npos) {
|
||||
filename = filepath.substr (pos + 1);
|
||||
} else {
|
||||
filename = filepath;
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ namespace Pandora_File {
|
||||
string readFile (const string filename);
|
||||
void removeFile (const string filename);
|
||||
void writeFile (const string filename, const string data);
|
||||
string fileName (const string filepath);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -64,7 +64,9 @@ Pandora_Module_Exec::run () {
|
||||
|
||||
/* Create a job to kill the child tree if it become zombie */
|
||||
/* CAUTION: In order to work this, WINVER should be defined to 0x0500.
|
||||
It is defined in <windef.h> */
|
||||
This may need no change, since it was redefined by the
|
||||
program, but if needed, the macro is defined
|
||||
in <windef.h> */
|
||||
job = CreateJobObject (&attributes, this->module_name.c_str ());
|
||||
if (job == NULL) {
|
||||
pandoraLog ("CreateJobObject bad. Err: %d", GetLastError ());
|
||||
|
@ -30,7 +30,7 @@ using namespace Pandora;
|
||||
using namespace Pandora_Strutils;
|
||||
|
||||
#define PATH_SIZE _MAX_PATH+1
|
||||
#define PANDORA_VERSION ("1.2Beta")
|
||||
#define PANDORA_VERSION ("1.3(Build 070807)")
|
||||
|
||||
string pandora_path;
|
||||
string pandora_dir;
|
||||
|
@ -22,6 +22,9 @@
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#undef WINVER
|
||||
#define WINVER 0x0500
|
||||
#include <windows.h>
|
||||
#include "windows_service.h"
|
||||
|
||||
|
@ -87,14 +87,14 @@ Pandora::Pandora_Agent_Conf::~Pandora_Agent_Conf () {
|
||||
* If it could not be found then an empty string is returned.
|
||||
*/
|
||||
string
|
||||
Pandora::Pandora_Agent_Conf::getValue (const string key) {
|
||||
std::list<Key_Value>::iterator i = key_values->begin ();
|
||||
Pandora::Pandora_Agent_Conf::getValue (const string key)
|
||||
{
|
||||
std::list<Key_Value>::iterator i;
|
||||
|
||||
while (i != key_values->end ()) {
|
||||
for (i = key_values->begin (); i != key_values->end (); i++) {
|
||||
if ((*i).getKey () == key) {
|
||||
return (*i).getValue ();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return "";
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "windows_service.h"
|
||||
#include "modules/pandora_module_factory.h"
|
||||
#include "ssh/pandora_ssh_client.h"
|
||||
#include "ftp/pandora_ftp_client.h"
|
||||
#include "misc/pandora_file.h"
|
||||
#include "windows/pandora_windows_info.h"
|
||||
|
||||
@ -99,6 +100,7 @@ Pandora_Windows_Service::pandora_init () {
|
||||
|
||||
conf_file = Pandora::getPandoraInstallDir ();
|
||||
conf_file += "pandora_agent.conf";
|
||||
|
||||
this->conf = new Pandora::Pandora_Agent_Conf (conf_file);
|
||||
this->modules = new Pandora_Module_List (conf_file);
|
||||
|
||||
@ -156,11 +158,12 @@ Pandora_Windows_Service::getXmlHeader () {
|
||||
return agent;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Pandora_Windows_Service::copyDataFile (string filename)
|
||||
Pandora_Windows_Service::copyScpDataFile (string host,
|
||||
string remote_path,
|
||||
string filename)
|
||||
{
|
||||
string remote_host, remote_filepath;
|
||||
SSH::Pandora_Ssh_Client ssh_client;
|
||||
string tmp_dir, filepath;
|
||||
string pubkey_file, privkey_file;
|
||||
|
||||
@ -170,9 +173,7 @@ Pandora_Windows_Service::copyDataFile (string filename)
|
||||
}
|
||||
filepath = tmp_dir + filename;
|
||||
|
||||
remote_host = conf->getValue ("server_ip");
|
||||
ssh_client = new SSH::Pandora_Ssh_Client ();
|
||||
pandoraDebug ("Connecting with %s", remote_host.c_str ());
|
||||
pandoraDebug ("Connecting with %s", host.c_str ());
|
||||
|
||||
try {
|
||||
pubkey_file = Pandora::getPandoraInstallDir ();
|
||||
@ -180,59 +181,119 @@ Pandora_Windows_Service::copyDataFile (string filename)
|
||||
privkey_file = Pandora::getPandoraInstallDir ();
|
||||
privkey_file += "key\\id_dsa";
|
||||
|
||||
ssh_client->connectWithPublicKey (remote_host.c_str (), 22, "pandora",
|
||||
ssh_client.connectWithPublicKey (host.c_str (), 22, "pandora",
|
||||
pubkey_file, privkey_file, "");
|
||||
} catch (SSH::Authentication_Failed e) {
|
||||
delete ssh_client;
|
||||
pandoraLog ("Pandora Agent: Authentication Failed when connecting to %s",
|
||||
remote_host.c_str ());
|
||||
if (getPandoraDebug () == false) {
|
||||
try {
|
||||
Pandora_File::removeFile (filepath);
|
||||
} catch (Pandora_File::Delete_Error e) {
|
||||
}
|
||||
}
|
||||
return;
|
||||
pandoraLog ("Pandora Agent: Authentication Failed "
|
||||
"when connecting to %s",
|
||||
host.c_str ());
|
||||
throw e;
|
||||
} catch (Pandora_Exception e) {
|
||||
delete ssh_client;
|
||||
pandoraLog ("Pandora Agent: Failed when copying to %s",
|
||||
remote_host.c_str ());
|
||||
if (getPandoraDebug () == false) {
|
||||
try {
|
||||
Pandora_File::removeFile (filepath);
|
||||
} catch (Pandora_File::Delete_Error e) {
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
remote_filepath = conf->getValue ("server_path");
|
||||
if (remote_filepath[remote_filepath.length () - 1] != '/') {
|
||||
remote_filepath += "/";
|
||||
host.c_str ());
|
||||
throw e;
|
||||
}
|
||||
|
||||
pandoraDebug ("Remote copying XML %s on server %s at %s%s",
|
||||
filepath.c_str (), remote_host.c_str (),
|
||||
remote_filepath.c_str (), filename.c_str ());
|
||||
filepath.c_str (), host.c_str (),
|
||||
remote_path.c_str (), filename.c_str ());
|
||||
try {
|
||||
ssh_client->scpFileFilename (remote_filepath + filename,
|
||||
ssh_client.scpFileFilename (remote_path + filename,
|
||||
filepath);
|
||||
} catch (Pandora_Exception e) {
|
||||
pandoraLog ("Unable to copy at %s%s", remote_filepath.c_str (),
|
||||
pandoraLog ("Unable to copy at %s%s", remote_path.c_str (),
|
||||
filename.c_str ());
|
||||
ssh_client->disconnect();
|
||||
delete ssh_client;
|
||||
ssh_client.disconnect();
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
ssh_client.disconnect();
|
||||
}
|
||||
|
||||
void
|
||||
Pandora_Windows_Service::copyFtpDataFile (string host,
|
||||
string remote_path,
|
||||
string filename)
|
||||
{
|
||||
FTP::Pandora_Ftp_Client ftp_client;
|
||||
string filepath;
|
||||
string password;
|
||||
|
||||
filepath = conf->getValue ("temporal");
|
||||
if (filepath[filepath.length () - 1] != '\\') {
|
||||
filepath += "\\";
|
||||
}
|
||||
filepath += filename;
|
||||
|
||||
password = conf->getValue ("ftp_password");
|
||||
|
||||
ftp_client.connect (host,
|
||||
22,
|
||||
"pandora",
|
||||
password);
|
||||
|
||||
try {
|
||||
ftp_client.ftpFileFilename (remote_path + filename,
|
||||
filepath);
|
||||
} catch (FTP::Unknown_Host e) {
|
||||
pandoraLog ("Failed when copying to %s (%s)", host.c_str (),
|
||||
ftp_client.getError ().c_str ());
|
||||
throw e;
|
||||
} catch (FTP::Authentication_Failed e) {
|
||||
pandoraLog ("Pandora Agent: Authentication Failed "
|
||||
"when connecting to %s (%s)",
|
||||
host.c_str (), ftp_client.getError ().c_str ());
|
||||
throw e;
|
||||
} catch (FTP::FTP_Exception e) {
|
||||
pandoraLog ("Pandora Agent: Failed when copying to %s (%s)",
|
||||
host.c_str (), ftp_client.getError ().c_str ());
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
ftp_client.disconnect ();
|
||||
}
|
||||
|
||||
void
|
||||
Pandora_Windows_Service::copyDataFile (string filename)
|
||||
{
|
||||
string mode, host, remote_path;
|
||||
|
||||
mode = conf->getValue ("transfer_mode");
|
||||
host = conf->getValue ("server_ip");
|
||||
remote_path = conf->getValue ("server_path");
|
||||
if (remote_path[remote_path.length () - 1] != '/') {
|
||||
remote_path += "/";
|
||||
}
|
||||
|
||||
try {
|
||||
if (mode == "ftp") {
|
||||
copyFtpDataFile (host, remote_path, filename);
|
||||
} else if (mode == "ssh" || mode == "") {
|
||||
copyScpDataFile (host, remote_path, filename);
|
||||
} else {
|
||||
pandoraLog ("Invalid transfer mode: %s."
|
||||
"Please rechak transfer_mode option "
|
||||
"in configuration file.");
|
||||
}
|
||||
|
||||
pandoraLog ("Successfuly copied XML file to server.");
|
||||
} catch (Pandora_Exception e) {
|
||||
if (getPandoraDebug () == false) {
|
||||
string filepath;
|
||||
|
||||
filepath = conf->getValue ("temporal");
|
||||
if (filepath[filepath.length () - 1] != '\\') {
|
||||
filepath += "\\";
|
||||
}
|
||||
filepath += filename;
|
||||
try {
|
||||
Pandora_File::removeFile (filepath);
|
||||
} catch (Pandora_File::Delete_Error e) {
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ssh_client->disconnect();
|
||||
delete ssh_client;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -36,7 +36,6 @@ namespace Pandora {
|
||||
*/
|
||||
class Pandora_Windows_Service : public Windows_Service {
|
||||
private:
|
||||
SSH::Pandora_Ssh_Client *ssh_client;
|
||||
Pandora_Agent_Conf *conf;
|
||||
Pandora_Modules::Pandora_Module_List *modules;
|
||||
long execution_number;
|
||||
@ -44,6 +43,12 @@ namespace Pandora {
|
||||
|
||||
TiXmlElement *getXmlHeader ();
|
||||
void copyDataFile (string filename);
|
||||
void copyScpDataFile (string host,
|
||||
string remote_path,
|
||||
string filename);
|
||||
void copyFtpDataFile (string host,
|
||||
string remote_path,
|
||||
string filename);
|
||||
|
||||
void pandora_run ();
|
||||
void pandora_init ();
|
||||
|
Loading…
x
Reference in New Issue
Block a user