diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2011-12-07 05:03:42 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2011-12-07 05:03:42 +0200 |
commit | d62dcfce76f2102174ae536a5ba52f91ad59e6bf (patch) | |
tree | 4fe0bbaed0ceb5bb485192dbc4e81d57ca5ad66a | |
parent | a0758d029dab4a91a36dd654b90d3c0a3b2b0b44 (diff) |
started proxifier config loading implementation
started proxifier process management implementation
added "ProxifierPath=" config file variable
-rwxr-xr-x | server/server/config.cpp | 5 | ||||
-rwxr-xr-x[-rw-r--r--] | server/server/config.h | 41 | ||||
-rwxr-xr-x | server/server/headers.h | 1 | ||||
-rwxr-xr-x | server/server/p_process.cpp | 13 | ||||
-rwxr-xr-x | server/server/p_process.h | 2 | ||||
-rwxr-xr-x | server/server/p_xml.cpp | 91 | ||||
-rwxr-xr-x | server/server/p_xml.h | 9 | ||||
-rwxr-xr-x[-rw-r--r--] | server/server/server.project | 11 | ||||
-rwxr-xr-x | server/server/xml.cpp | 1 | ||||
-rwxr-xr-x | server/server/xml.h | 6 |
10 files changed, 170 insertions, 10 deletions
diff --git a/server/server/config.cpp b/server/server/config.cpp index 4eb215d..7a1c80b 100755 --- a/server/server/config.cpp +++ b/server/server/config.cpp @@ -25,6 +25,7 @@ config::config(const char *pth) vars.bind_ip = get_string(cfg_str, "BindAddress=", "0.0.0.0"); vars.log_path = get_string(cfg_str, "LogPath=", ""); vars.dos_log_path = get_string(cfg_str, "DosLogPath=", ""); + vars.proxifier_path = get_string(cfg_str, "ProxifierPath=", "c:/proxifier"); vars.ignore_ssl_errors = get_int(cfg_str, "IgnoreSslErrors=", 0); } } @@ -412,6 +413,10 @@ const std::string& config::dos_log_path() { return vars.dos_log_path; } +const std::string& config::proxifier_path() +{ + return vars.proxifier_path; +} std::list<config::proxy_entry> *config::get_proxy_list() { return &proxy_list; diff --git a/server/server/config.h b/server/server/config.h index 1c68427..90b9d27 100644..100755 --- a/server/server/config.h +++ b/server/server/config.h @@ -25,6 +25,43 @@ public: city = city_; } }; + enum p_proxy_type {UNKNOWN = -1, HTTPS, SOCKS4, SOCKS5}; + struct p_proxy_entry + { + std::string host, login, password; + int port, id, options; + bool enable_auth; + p_proxy_type type; + p_proxy_entry() + { + port = 3128; + id = 100; + options = 0; + type = UNKNOWN; + enable_auth = false; + } + }; + + struct p_proxy_chain + { + std::string name; + int id; + struct chain_entry + { + int id; + bool enabled; + chain_entry() + { + id = 100; + enabled = true; + } + }; + std::list<chain_entry> chain; + p_proxy_chain() + { + id = 100; + } + }; struct static_proxy_entry { @@ -117,6 +154,7 @@ public: bool ignore_ssl_errors(); const std::string& bind_ip(); const std::string& log_path(); + const std::string& proxifier_path(); const std::string& dos_log_path(); std::list<proxy_entry> *get_proxy_list(); std::list<static_proxy_entry> *get_static_proxy_list(); @@ -129,7 +167,7 @@ private: { int ban_time, conn_count, check_interval, debug, dos_conn_count, conn_time; bool ignore_ssl_errors; - std::string log_path, bind_ip, dos_log_path; + std::string log_path, bind_ip, dos_log_path, proxifier_path; cfg_data() { ignore_ssl_errors = false; @@ -139,6 +177,7 @@ private: debug = 0; dos_conn_count = 200; bind_ip = "0.0.0.0"; + proxifier_path = "c:/proxifier"; } }; struct cli_cfg_data diff --git a/server/server/headers.h b/server/server/headers.h index 97ecc1c..65f9b37 100755 --- a/server/server/headers.h +++ b/server/server/headers.h @@ -32,5 +32,6 @@ #include "log.h" #include "config.h" #include "p_process.h" +#include "p_xml.h" #endif diff --git a/server/server/p_process.cpp b/server/server/p_process.cpp index d45d948..b3e7d53 100755 --- a/server/server/p_process.cpp +++ b/server/server/p_process.cpp @@ -1,2 +1,15 @@ #include "headers.h"
+extern config *cfg;
+
+bool p_start(char *path)
+{
+ Poco::Process *p = new Poco::Process;
+ if(!path)
+ p->launch(cfg->proxifier_path()+"proxifier.exe", Poco::Process::Args());
+ else
+ p->launch(path, Poco::Process::Args());
+ if(p->id() > 0)
+ return true;
+ return false;
+}
\ No newline at end of file diff --git a/server/server/p_process.h b/server/server/p_process.h index 8f67615..46368bf 100755 --- a/server/server/p_process.h +++ b/server/server/p_process.h @@ -1,6 +1,6 @@ #ifndef P_PROCESS_H
#define P_PROCESS_H
-
+bool p_start(char *path = NULL);
#endif
\ No newline at end of file diff --git a/server/server/p_xml.cpp b/server/server/p_xml.cpp new file mode 100755 index 0000000..3fac837 --- /dev/null +++ b/server/server/p_xml.cpp @@ -0,0 +1,91 @@ +#include "headers.h"
+extern config *cfg;
+
+using namespace rapidxml;
+
+bool p_load_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
+{
+ std::ifstream file;
+ if(!path)
+ file.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str(), std::ios::in);
+ else
+ file.open(path, std::ios::in);
+ if(file.is_open())
+ {
+ std::string data((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
+ file.close();
+ xml_document<> doc;
+ xml_node<> *proxy_list = doc.first_node()->first_node("ProxyList");
+ if(!proxy_list)
+ return false;
+ for(xml_node<> *node = proxy_list->first_node("Proxy"); node; node = node->next_sibling("Proxy"))
+ {
+ config::p_proxy_entry e;
+ e.id = atoi(node->first_attribute("id")->value());
+ std::string type = node->first_attribute("type")->value();
+ if(type == "HTTPS")
+ e.type = config::HTTPS;
+ if(type == "SOCKS4")
+ e.type = config::SOCKS4;
+ if(type == "SOCKS5")
+ e.type = config::SOCKS5;
+ e.host = node->first_node("Address")->value();
+ e.port = atoi(node->first_node("Port")->value());
+ e.options = atoi(node->first_node("Options")->value());
+ xml_node<> *auth = node->first_node("Authentication");
+ if(auth)
+ {
+ e.enable_auth = atoi(auth->first_attribute("Enabled")->value());
+ e.login = auth->first_node("Username")->value();
+ e.password = auth->first_node("Password")->value(); //TODO: detect kind of hash, decrypt (needed for set auth settings in proxy list)
+ }
+ list->push_back(e);
+ }
+ if(!list->empty())
+ return true; // succesfully loaded some entries
+ }
+ return false;
+}
+
+bool p_load_proxy_chains(std::list<config::p_proxy_chain> *list, char *path)
+{
+ std::ifstream file;
+ if(!path)
+ file.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str(), std::ios::in);
+ else
+ file.open(path, std::ios::in);
+ if(file.is_open())
+ {
+ std::string data((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
+ file.close();
+ xml_document<> doc;
+ xml_node<> *chain_list = doc.first_node()->first_node("ChainList");
+ if(!chain_list)
+ return false;
+ for(xml_node<> *node = chain_list->first_node("Chain"); node; node = node->next_sibling("Chain"))
+ {
+ config::p_proxy_chain c;
+ c.id = atoi(node->first_attribute("id")->value());
+ c.name = node->first_node("Name")->value();
+ for(xml_node<> *proxy = node->first_node("Proxy"); proxy; proxy = proxy->next_sibling("Proxy"))
+ {
+ config::p_proxy_chain::chain_entry e;
+ e.enabled = atoi(proxy->first_attribute("enabled")->value());
+ e.id = atoi(proxy->value());
+ c.chain.push_back(e);
+ }
+ list->push_back(c);
+ }
+ if(!list->empty())
+ return true;
+ }
+ return false;
+}
+
+bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
+{
+}
+
+bool p_save_proxy_chains(std::list<config::p_proxy_chain> *list, char *path)
+{
+}
\ No newline at end of file diff --git a/server/server/p_xml.h b/server/server/p_xml.h new file mode 100755 index 0000000..08f1110 --- /dev/null +++ b/server/server/p_xml.h @@ -0,0 +1,9 @@ +#ifndef XML_H
+#define XML_H
+
+bool p_load_proxy_list(std::list<config::p_proxy_entry> *list, char* path = NULL);
+bool p_load_proxy_chains(std::list<config::p_proxy_chain> *list, char *path = NULL);
+bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, char *path = NULL);
+bool p_save_proxy_chains(std::list<config::p_proxy_chain> *list, char *path = NULL);
+
+#endif
\ No newline at end of file diff --git a/server/server/server.project b/server/server/server.project index 7412cb0..99e9406 100644..100755 --- a/server/server/server.project +++ b/server/server/server.project @@ -17,6 +17,10 @@ <File Name="main.h"/> <File Name="utilities.cpp"/> <File Name="utilities.h"/> + <File Name="p_process.cpp"/> + <File Name="p_process.h"/> + <File Name="p_xml.cpp"/> + <File Name="p_xml.h"/> </VirtualDirectory> <Settings Type="Executable"> <GlobalSettings> @@ -31,15 +35,19 @@ <Configuration Name="Debug" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> <Compiler Options="-g3 -ggdb" C_Options="-g3 -ggdb" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags=""> <IncludePath Value="."/> + <IncludePath Value="../../libs/rapidxml-1.13"/> </Compiler> <Linker Options="" Required="yes"> <Library Value="boost_system"/> <Library Value="pthread"/> <Library Value="ssl"/> + <Library Value="crypto"/> <Library Value="boost_random"/> - <Library Value="boost_thread"/> <Library Value="boost_date_time"/> + <Library Value="boost_thread"/> <Library Value="boost_filesystem"/> + <Library Value="z"/> + <Library Value="PocoFoundation"/> </Linker> <ResourceCompiler Options="" Required="no"/> <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/> @@ -82,6 +90,7 @@ <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"> <![CDATA[ + ]]> </Environment> <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath=""> diff --git a/server/server/xml.cpp b/server/server/xml.cpp deleted file mode 100755 index f58bee1..0000000 --- a/server/server/xml.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "headers.h"
diff --git a/server/server/xml.h b/server/server/xml.h deleted file mode 100755 index 5d2a0ea..0000000 --- a/server/server/xml.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef XML_H
-#define XML_H
-
-
-
-#endif
\ No newline at end of file |