From d62dcfce76f2102174ae536a5ba52f91ad59e6bf Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 7 Dec 2011 05:03:42 +0200 Subject: started proxifier config loading implementation started proxifier process management implementation added "ProxifierPath=" config file variable --- server/server/config.cpp | 5 +++ server/server/config.h | 41 +++++++++++++++++++- server/server/headers.h | 1 + server/server/p_process.cpp | 13 +++++++ server/server/p_process.h | 2 +- server/server/p_xml.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++++ server/server/p_xml.h | 9 +++++ server/server/server.project | 11 +++++- server/server/xml.cpp | 1 - server/server/xml.h | 6 --- 10 files changed, 170 insertions(+), 10 deletions(-) mode change 100644 => 100755 server/server/config.h create mode 100755 server/server/p_xml.cpp create mode 100755 server/server/p_xml.h mode change 100644 => 100755 server/server/server.project delete mode 100755 server/server/xml.cpp delete mode 100755 server/server/xml.h (limited to 'server') 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::get_proxy_list() { return &proxy_list; diff --git a/server/server/config.h b/server/server/config.h old mode 100644 new mode 100755 index 1c68427..90b9d27 --- 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; + 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 *get_proxy_list(); std::list *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 *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(file)), std::istreambuf_iterator()); + 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 *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(file)), std::istreambuf_iterator()); + 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 *list, char *path) +{ +} + +bool p_save_proxy_chains(std::list *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 *list, char* path = NULL); +bool p_load_proxy_chains(std::list *list, char *path = NULL); +bool p_save_proxy_list(std::list *list, char *path = NULL); +bool p_save_proxy_chains(std::list *list, char *path = NULL); + +#endif \ No newline at end of file diff --git a/server/server/server.project b/server/server/server.project old mode 100644 new mode 100755 index 7412cb0..99e9406 --- a/server/server/server.project +++ b/server/server/server.project @@ -17,6 +17,10 @@ + + + + @@ -31,15 +35,19 @@ + + - + + + @@ -82,6 +90,7 @@ 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 -- cgit v1.2.3