From 19ebb674a5d6c5f5d3e0cd81e86c0a0d91436ded Mon Sep 17 00:00:00 2001 From: esanchezm Date: Mon, 9 Feb 2009 10:26:07 +0000 Subject: [PATCH] 2009-02-09 Esteban Sanchez * main.cc: Added a new parameter --process to run the agent as a single process instead of a service. * pandora_windows_service.h: Interval property is now public so it can be readed if it's running as a single process. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1432 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/win32/ChangeLog | 8 + pandora_agents/win32/main.cc | 22 ++- .../win32/pandora_windows_service.h | 181 +++++++++--------- 3 files changed, 116 insertions(+), 95 deletions(-) diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index 580ee402e5..17e5e990fd 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,11 @@ +2009-02-09 Esteban Sanchez + + * main.cc: Added a new parameter --process to run the agent as a + single process instead of a service. + + * pandora_windows_service.h: Interval property is now public so it can + be readed if it's running as a single process. + 2008-12-03 Esteban Sanchez * bin/PandoraAgent.exe: Updated to last commit. diff --git a/pandora_agents/win32/main.cc b/pandora_agents/win32/main.cc index 3bf8dc20c5..43be24cc6c 100644 --- a/pandora_agents/win32/main.cc +++ b/pandora_agents/win32/main.cc @@ -29,6 +29,7 @@ #define SSH_TEST_CMDLINE_PARAM "--test-ssh" #define FTP_TEST_CMDLINE_PARAM "--test-ftp" #define HELP_CMDLINE_PARAM "--help" +#define PROCESS_CMDLINE_PARAM "--process" int main (int argc, char *argv[]) { @@ -36,6 +37,7 @@ main (int argc, char *argv[]) { char buffer[PATH_SIZE]; string aux; unsigned int pos; + bool process = false; service = Pandora_Windows_Service::getInstance (); service->setValues (Pandora::name, Pandora::display_name, @@ -91,8 +93,7 @@ main (int argc, char *argv[]) { } return 0; - - } else if (_stricmp(argv[i], HELP_CMDLINE_PARAM) == 0) { + } else if (_stricmp(argv[i], HELP_CMDLINE_PARAM) == 0) { /* Help parameter */ cout << "Pandora agent for Windows. "; cout << "Version " << getPandoraAgentVersion () << endl; @@ -108,6 +109,8 @@ main (int argc, char *argv[]) { cout << ": Test the FTP Pandora Agent configuration." << endl; return 0; + } else if (_stricmp(argv[i], PROCESS_CMDLINE_PARAM) == 0) { + process = true; } else { /* No parameter recognized */ cout << "Pandora agent for Windows. "; @@ -123,9 +126,18 @@ main (int argc, char *argv[]) { return 1; } } - service->run (); - + if (process) { + cout << "Pandora agent is now running" << endl; + service->pandora_init (); + while (1) { + service->pandora_run (); + Sleep (service->interval / 1000); + } + } else { + service->run (); + } + delete service; - + return 0; } diff --git a/pandora_agents/win32/pandora_windows_service.h b/pandora_agents/win32/pandora_windows_service.h index 6c1d4b2821..8b10d8a5d5 100644 --- a/pandora_agents/win32/pandora_windows_service.h +++ b/pandora_agents/win32/pandora_windows_service.h @@ -1,90 +1,91 @@ -/* Pandora agent service for Win32. - - 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_WINDOWS_SERVICE_H__ -#define __PANDORA_WINDOWS_SERVICE_H__ - -#include -#include "windows_service.h" -#include "tinyxml/tinyxml.h" -#include "pandora_agent_conf.h" -#include "modules/pandora_module_list.h" -#include "ssh/pandora_ssh_client.h" - -using namespace std; -using namespace Pandora_Modules; - -namespace Pandora { - /** - * Class to implement the Pandora Windows service. - */ - class Pandora_Windows_Service : public Windows_Service { - private: - Pandora_Agent_Conf *conf; - Pandora_Module_List *modules; - long execution_number; - string agent_name; - long interval; - long elapsed_transfer_time; - long transfer_interval; - bool started; - - TiXmlElement *getXmlHeader (); - int copyDataFile (string filename); - int copyTentacleDataFile (string host, - string filename, - string port, - string ssl, - string pass, - string opts); - int copyScpDataFile (string host, - string remote_path, - string filename); - int copyFtpDataFile (string host, - string remote_path, - string filename, - string password); - int copyLocalDataFile (string remote_path, - string filename); - void recvDataFile (string filename); - void recvTentacleDataFile (string host, - string filename); - void checkConfig (); - - Pandora_Windows_Service (); - public: - void pandora_run (); - void pandora_init (); - public: - static Pandora_Windows_Service *getInstance (); - - ~Pandora_Windows_Service (); - - void setValues (const char *svc_name, - const char *svc_display_name, - const char *svc_description); - - void start (); - int sendXml (Pandora_Module_List *modules); - Pandora_Agent_Conf *getConf (); - }; -} - -#endif +/* Pandora agent service for Win32. + + 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_WINDOWS_SERVICE_H__ +#define __PANDORA_WINDOWS_SERVICE_H__ + +#include +#include "windows_service.h" +#include "tinyxml/tinyxml.h" +#include "pandora_agent_conf.h" +#include "modules/pandora_module_list.h" +#include "ssh/pandora_ssh_client.h" + +using namespace std; +using namespace Pandora_Modules; + +namespace Pandora { + /** + * Class to implement the Pandora Windows service. + */ + class Pandora_Windows_Service : public Windows_Service { + private: + Pandora_Agent_Conf *conf; + Pandora_Module_List *modules; + long execution_number; + string agent_name; + long elapsed_transfer_time; + long transfer_interval; + bool started; + + TiXmlElement *getXmlHeader (); + int copyDataFile (string filename); + int copyTentacleDataFile (string host, + string filename, + string port, + string ssl, + string pass, + string opts); + int copyScpDataFile (string host, + string remote_path, + string filename); + int copyFtpDataFile (string host, + string remote_path, + string filename, + string password); + int copyLocalDataFile (string remote_path, + string filename); + void recvDataFile (string filename); + void recvTentacleDataFile (string host, + string filename); + void checkConfig (); + + Pandora_Windows_Service (); + public: + void pandora_run (); + void pandora_init (); + + long interval; + public: + static Pandora_Windows_Service *getInstance (); + + ~Pandora_Windows_Service (); + + void setValues (const char *svc_name, + const char *svc_display_name, + const char *svc_description); + + void start (); + int sendXml (Pandora_Module_List *modules); + Pandora_Agent_Conf *getConf (); + }; +} + +#endif