diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index 67f244ff02..8a96588b02 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,11 @@ +2011-07-28 Dario Rodriguez + + * pandora_windows_service.h, pandora_windows_service.cc: Added proxy + mode feature. + * bin/PandoraAgent.exe: Created new compiled version with proxy mode + feature. + * bin/pandora_agent.conf: Added new parameters to configure proxy mode. + 2011-07-28 Sancho Lerena * bin/util/tentacle_server.exe: Tentacle server executable to use it diff --git a/pandora_agents/win32/bin/PandoraAgent.exe b/pandora_agents/win32/bin/PandoraAgent.exe index c0f2afa86f..f0c6afbc08 100755 Binary files a/pandora_agents/win32/bin/PandoraAgent.exe and b/pandora_agents/win32/bin/PandoraAgent.exe differ diff --git a/pandora_agents/win32/bin/pandora_agent.conf b/pandora_agents/win32/bin/pandora_agent.conf index a9d416b49c..a32f040723 100644 --- a/pandora_agents/win32/bin/pandora_agent.conf +++ b/pandora_agents/win32/bin/pandora_agent.conf @@ -64,6 +64,15 @@ server_port 41121 # Set XML encoding (ISO-8859-1 by default). #encoding ISO-8859-1 +# If set to 1 start Drone Agent's Proxy Mode +# proxy_mode 1 + +# Max number of simmultaneus connection for proxy (by default 10) +# proxy_max_connection 10 + +# Proxy timeout (by default 1s) +# proxy_timeout 1 + # Enable or disable XML buffer. xml_buffer 0 diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index 517deb1525..78165f3a56 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -38,6 +38,7 @@ #include #include #include +#include using namespace std; using namespace Pandora; @@ -81,6 +82,10 @@ Pandora_Windows_Service::setValues (const char * svc_name, * Destroys a Pandora_Windows_Service object. */ Pandora_Windows_Service::~Pandora_Windows_Service () { + + if(conf->getValue("proxy_mode") != "") { + killTentacleProxy(); + } if (this->conf != NULL) { delete this->conf; @@ -206,6 +211,7 @@ Pandora_Windows_Service::pandora_init () { string conf_file, interval, debug, transfer_interval, util_dir, path, env; string udp_server_enabled, udp_server_port, udp_server_addr, udp_server_auth_addr; string name_agent, name; + string proxy_mode, server_ip; int pos, num; setPandoraDebug (true); @@ -262,6 +268,13 @@ Pandora_Windows_Service::pandora_init () { srand ((unsigned) time (0)); this->setSleepTime (this->interval); + + /*Check if proxy mode is set*/ + proxy_mode = conf->getValue ("proxy_mode"); + + if (proxy_mode != "") { + lauchTentacleProxy(); + } pandoraLog ("Pandora agent started"); @@ -276,6 +289,70 @@ Pandora_Windows_Service::pandora_init () { } } +int +Pandora_Windows_Service::killTentacleProxy() { + PROCESS_INFORMATION pi; + STARTUPINFO si; + string kill_cmd; + + kill_cmd = "taskkill.exe /F /IM tentacle_server.exe"; + + ZeroMemory (&si, sizeof (si)); + ZeroMemory (&pi, sizeof (pi)); + if (CreateProcess (NULL , (CHAR *)kill_cmd.c_str (), NULL, NULL, FALSE, + CREATE_NO_WINDOW, NULL, NULL, &si, &pi) == 0) { + return -1; + } + + +} + +int +Pandora_Windows_Service::lauchTentacleProxy() { + string server_ip, server_port, proxy_max_connections, proxy_timeout; + string proxy_cmd; + PROCESS_INFORMATION pi; + STARTUPINFO si; + + /*Check if server proxy is localhost*/ + server_ip = conf->getValue("server_ip"); + + if (server_ip != "localhost") { + proxy_max_connections = conf->getValue("proxy_max_connection"); + + if (proxy_max_connections == "") { + proxy_max_connections = "10"; + } + + proxy_timeout = conf->getValue("proxy_timeout"); + + if (proxy_timeout == "") { + proxy_timeout = "1"; + } + + server_port = conf->getValue("server_port"); + + if (server_port == "") { + server_port = "41121"; + } + + proxy_cmd = "tentacle_server.exe -b " + server_ip + " -g " + server_port + " -c " + proxy_max_connections + " -t " + proxy_timeout + "-d"; + + pandoraLog("Proxy mode enabled"); + + ZeroMemory (&si, sizeof (si)); + ZeroMemory (&pi, sizeof (pi)); + if (CreateProcess (NULL , (CHAR *)proxy_cmd.c_str (), NULL, NULL, FALSE, + CREATE_NO_WINDOW, NULL, NULL, &si, &pi) == 0) { + return -1; + } + + } else { + pandoraLog ("[error] You can not proxy to localhost"); + } + +} + string Pandora_Windows_Service::getXmlHeader () { char timestamp[20]; diff --git a/pandora_agents/win32/pandora_windows_service.h b/pandora_agents/win32/pandora_windows_service.h index b07d829a1e..60980bb6d5 100644 --- a/pandora_agents/win32/pandora_windows_service.h +++ b/pandora_agents/win32/pandora_windows_service.h @@ -80,6 +80,8 @@ namespace Pandora { void pandora_run_broker (string config); int count_broker_agents(); void check_broker_agents(string *all_conf); + int lauchTentacleProxy(); + int killTentacleProxy(); Pandora_Windows_Service ();