diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2011-12-02 00:39:21 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2011-12-02 00:39:21 +0200 |
commit | 26cc6181de5356f9a84d0b5a74ad9dbf9a3402c0 (patch) | |
tree | 9ddc62ea4020c922f088d7dd17a40cb916093cdb /server | |
parent | 918defcaea2b570a927a2884ce0e720b03e32d8a (diff) |
server_list.cfg support (host interval timeout;)
cli_config.cfg support (var=val;)
0x01 request support
//untested
Diffstat (limited to 'server')
-rw-r--r-- | server/proxy_ui_server.workspace | 5 | ||||
-rw-r--r-- | server/server/config.cpp | 143 | ||||
-rw-r--r-- | server/server/config.h | 176 | ||||
-rw-r--r-- | server/server/main.cpp | 98 |
4 files changed, 329 insertions, 93 deletions
diff --git a/server/proxy_ui_server.workspace b/server/proxy_ui_server.workspace index 7eda2a4..fef20c5 100644 --- a/server/proxy_ui_server.workspace +++ b/server/proxy_ui_server.workspace @@ -15,6 +15,11 @@ + + + + + ]]> </Environment> </CodeLite_Workspace> diff --git a/server/server/config.cpp b/server/server/config.cpp index 33a8124..2b28ed0 100644 --- a/server/server/config.cpp +++ b/server/server/config.cpp @@ -2,32 +2,56 @@ config::config(const char *pth) { - std::ifstream config; - if(!pth) { + std::ifstream config; + if(!pth) + { + std::string cfg_path = boost::filesystem::initial_path().string(); + cfg_path += "/server.cfg"; + config.open(cfg_path.c_str(), std::fstream::in); + } + else + config.open(pth, std::fstream::in); + if(config.is_open()) + { + std::string cfg_str((std::istreambuf_iterator<char>(config)), std::istreambuf_iterator<char>()); + config.close(); + vars.ban_time = get_int(cfg_str, "BanTime=", 60); + vars.check_interval = get_int(cfg_str, "ConnListCheckInterval=", 30); + vars.conn_count = get_int(cfg_str, "ConnectionCount=", 30); + vars.conn_time = get_int(cfg_str, "ConnectionTimeOut=", 60); + vars.dos_conn_count = get_int(cfg_str, "DosConnectionCount=", 200); + vars.debug = get_int(cfg_str, "Debug=", 0); + vars.bind_ip = get_string(cfg_str, "BindAddress=", "0.0.0.0"); + vars.log_path = get_string(cfg_str, "LogPath=", "./server.log"); + vars.dos_log_path = get_string(cfg_str, "DosLogPath=", "./server_dos.log"); + vars.ignore_ssl_errors = get_int(cfg_str, "IgnoreSslErrors=", 0); + } + } + { + std::ifstream config; std::string cfg_path = boost::filesystem::initial_path().string(); - cfg_path += "/server.cfg"; + cfg_path += "/cli_config.cfg"; config.open(cfg_path.c_str(), std::fstream::in); + if(config.is_open()) + { + std::string cfg_str((std::istreambuf_iterator<char>(config)), std::istreambuf_iterator<char>()); + config.close(); + cvars.config_update_interval = get_int(cfg_str, "config_update_interval=", 300); + cvars.client_update_interval = get_int(cfg_str, "client_update_interval=", 60000); + cvars.welcome_msg = get_string(cfg_str, "welcome_msg=", ""); + cvars.cfg_downloaded_msg = get_string(cfg_str, "config_downloaded_msg=", ""); + cvars.top_text = get_string(cfg_str, "top_panel_text=", ""); + cvars.bottom_text = get_string(cfg_str, "bottom_panel_text=", ""); + cvars.speed_visibility = get_int(cfg_str, "speed_visibility=", 1); + } } - else - config.open(pth, std::fstream::in); - std::string cfg_str((std::istreambuf_iterator<char>(config)), std::istreambuf_iterator<char>()); - config.close(); - vars.ban_time = get_int(cfg_str, "BanTime=", 60); - vars.check_interval = get_int(cfg_str, "ConnListCheckInterval=", 30); - vars.conn_count = get_int(cfg_str, "ConnectionCount=", 30); - vars.conn_time = get_int(cfg_str, "ConnectionTimeOut=", 60); - vars.dos_conn_count = get_int(cfg_str, "DosConnectionCount=", 200); - vars.debug = get_int(cfg_str, "Debug=", 0); - vars.bind_ip = get_string(cfg_str, "BindAddress=", "0.0.0.0"); - vars.log_path = get_string(cfg_str, "LogPath=", "./server.log"); - vars.dos_log_path = get_string(cfg_str, "DosLogPath=", "./server_dos.log"); - vars.ignore_ssl_errors = get_int(cfg_str, "IgnoreSslErrors=", 0); load_proxy_list(); load_static_proxy_list(); load_firewall_list(); load_deleted_list(); load_upload_list(); + load_servers_list(); } const int config::get_int(const std::string& data, const char* var, int default_) { @@ -58,6 +82,45 @@ const std::string config::get_string(const std::string& data, const char* var, c return default_; } +void config::load_servers_list(char* pth) +{ + std::ifstream config; + if(!pth) + { + std::string cfg_path = boost::filesystem::initial_path().string(); + cfg_path += "/server_list.cfg"; + config.open(cfg_path.c_str(), std::fstream::in); + } + else + config.open(pth, std::fstream::in); + std::string cfg_str((std::istreambuf_iterator<char>(config)), std::istreambuf_iterator<char>()); + config.close(); + if(!cfg_str.empty()) + { + std::string::size_type p1 = 0, p2 = 0, l = 1; + if(cfg_str.find("\r\n") != std::string::npos) + l = 2; + p2 = cfg_str.find(';'); + while(p2 != std::string::npos) + { + std::string line = cfg_str.substr(p1, p2-p1); + p1 = p2+l+1; + std::string::size_type lp1 = 0, lp2 = 0; + std::string serv, interval, timeout; + lp1++; + lp2 = line.find(" ", lp1); + serv = line.substr(lp1, lp2-lp1); + lp1 = lp2+1; + lp2 = line.find(' ', lp1); + interval = line.substr(lp1, lp2-lp1); + lp2++; + timeout = line.substr(lp2); + servers_list.push_back(conn_server(serv, atoi(interval.c_str()), atoi(timeout.c_str()))); + p2 = cfg_str.find(';', p1); + } + } +} + void config::load_upload_list(char *pth) { std::ifstream config; @@ -349,11 +412,11 @@ const std::string& config::dos_log_path() { return vars.dos_log_path; } -std::list<proxy_entry> *config::get_proxy_list() +std::list<config::proxy_entry> *config::get_proxy_list() { return &proxy_list; } -std::list<static_proxy_entry> *config::get_static_proxy_list() +std::list<config::static_proxy_entry> *config::get_static_proxy_list() { return &static_proxy_list; } @@ -366,7 +429,7 @@ std::list<std::string> *config::get_deleted_list() return &deleted_list; } -std::list<upload_entry> *config::get_upload_list() +std::list<config::upload_entry> *config::get_upload_list() { return &upload_list; } @@ -375,3 +438,43 @@ bool config::ignore_ssl_errors() { return vars.ignore_ssl_errors; } + +const int config::c_cfg_upd_int() +{ + return cvars.config_update_interval; +} + +const int config::c_cli_upd_int() +{ + return cvars.client_update_interval; +} + +bool config::c_speed_visibility() +{ + return cvars.speed_visibility; +} + +const std::string& config::c_welcome_msg() +{ + return cvars.welcome_msg; +} + +const std::string& config::c_cfg_download_msg() +{ + return cvars.cfg_downloaded_msg; +} + +const std::string& config::c_top_text() +{ + return cvars.top_text; +} + +const std::string& config::c_bottom_text() +{ + return cvars.bottom_text; +} + +std::list<config::conn_server> *config::get_server_list() +{ + return &servers_list; +} diff --git a/server/server/config.h b/server/server/config.h index 6683d7e..d411411 100644 --- a/server/server/config.h +++ b/server/server/config.h @@ -4,85 +4,101 @@ #include "headers.h" -struct proxy_entry -{ - std::string host, login, password, country, state, city; - int port; - proxy_entry(): port(0) - {} - proxy_entry (std::string login_, std::string password_, std::string host_, int port_, std::string country_, std::string state_, std::string city_) - { - login = login_; - password = password_; - host = host_; - port = port; - country = country_; - state = state_; - city = city_; - } -}; -struct static_proxy_entry +class config { - int port, position; - uint64_t speed; - std::string host, login, password, label; - static_proxy_entry(): port(0), position(0), speed(0) - {} - static_proxy_entry(std::string login_, std::string password_, std::string host_, int port_, std::string label_, int position_) +public: + struct proxy_entry { - login = login_; - password = password_; - host = host_; - port = port_; - label = label_; - position = position_; - } -}; + std::string host, login, password, country, state, city; + int port; + proxy_entry(): port(0) + {} + proxy_entry (std::string login_, std::string password_, std::string host_, int port_, std::string country_, std::string state_, std::string city_) + { + login = login_; + password = password_; + host = host_; + port = port; + country = country_; + state = state_; + city = city_; + } + }; -struct s_i -{ - std::string name; - int type; - s_i() + struct static_proxy_entry { - type = 0; - } - s_i(const std::string& n, int t) + int port, position; + uint64_t speed; + std::string host, login, password, label; + static_proxy_entry(): port(0), position(0), speed(0) + {} + static_proxy_entry(std::string login_, std::string password_, std::string host_, int port_, std::string label_, int position_) + { + login = login_; + password = password_; + host = host_; + port = port_; + label = label_; + position = position_; + } + }; + + struct s_i { - name = n; - type = t; - } -}; + std::string name; + int type; + s_i() + { + type = 0; + } + s_i(const std::string& n, int t) + { + name = n; + type = t; + } + }; -struct upload_entry -{ - std::string source, destination, hash; - upload_entry(){} - upload_entry(std::string source_, std::string destination_, std::string hash_) + struct upload_entry { - source = source_; - destination = destination_; - hash = hash_; - } - bool operator==(const s_i& s) + std::string source, destination, hash; + upload_entry(){} + upload_entry(std::string source_, std::string destination_, std::string hash_) + { + source = source_; + destination = destination_; + hash = hash_; + } + bool operator==(const s_i& s) + { + switch(s.type) + { + case 0: + return s.name == source; + case 1: + return s.name == destination; + default: + break; + } + return false; + } + }; + struct conn_server { - switch(s.type) + std::string host; + int interval, timeout; + conn_server() { - case 0: - return s.name == source; - case 1: - return s.name == destination; - default: - break; + interval = 600; + timeout = 60; } - return false; - } -}; - -class config -{ -public: + conn_server(const std::string& s, int i, int t) + { + host = s; + interval = i; + timeout = t; + } + }; config(const char *path); const int ban_time(); const int conn_count(); @@ -90,6 +106,14 @@ public: const int check_interval(); const int debug(); const int dos_conn_count(); + const int c_cfg_upd_int(); + const int c_cli_upd_int(); + bool c_speed_visibility(); + const std::string& c_welcome_msg(); + const std::string& c_cfg_download_msg(); + const std::string& c_top_text(); + const std::string& c_bottom_text(); + bool ignore_ssl_errors(); const std::string& bind_ip(); const std::string& log_path(); @@ -99,6 +123,7 @@ public: std::list<std::string> *get_firewall_list(); std::list<std::string> *get_deleted_list(); std::list<upload_entry> *get_upload_list(); + std::list<conn_server> *get_server_list(); private: struct cfg_data { @@ -115,6 +140,18 @@ private: dos_conn_count = 200; } }; + struct cli_cfg_data + { + int config_update_interval, client_update_interval; + std::string welcome_msg, cfg_downloaded_msg, top_text, bottom_text; + bool speed_visibility; + cli_cfg_data() + { + config_update_interval = 300; + client_update_interval = 60000; + speed_visibility = false; + } + }; const int get_int(const std::string& data, const char* var, int default_); const std::string get_string(const std::string& data, const char* var, const std::string& default_); void load_proxy_list(char* pth = NULL); @@ -122,11 +159,14 @@ private: void load_firewall_list(char* pth = NULL); void load_upload_list(char* pth = NULL); void load_deleted_list(char* pth = NULL); + void load_servers_list(char* pth = NULL); cfg_data vars; + cli_cfg_data cvars; std::list<proxy_entry> proxy_list; std::list<static_proxy_entry> static_proxy_list; std::list<std::string> firewall_list, deleted_list; std::list<upload_entry> upload_list; + std::list<conn_server> servers_list; }; #endif
\ No newline at end of file diff --git a/server/server/main.cpp b/server/server/main.cpp index bd1dd5b..52c663e 100644 --- a/server/server/main.cpp +++ b/server/server/main.cpp @@ -182,7 +182,95 @@ void session::proto_parser(std::vector<byte>& data) data.push_back(0x13); data.push_back(0x13); data.push_back(0x01); - //TODO: add data here + if(!cfg->get_server_list()->empty()) + { + for(std::list<config::conn_server>::iterator i = cfg->get_server_list()->begin(), end = cfg->get_server_list()->end(); i != end; ++i) + { + const std::string s = "server="; + for(int ii = 0; ii < s.size(); ++ii) + data.push_back(s[ii]); + for(int ii = 0; ii < i->host.size(); ++ii) + data.push_back(i->host[ii]); + data.push_back(0x20); + char buf[10]; + snprintf(buf, 9, "%d", i->interval); + int len = strlen(buf); + for(int ii = 0; ii < len; ++ii) + data.push_back(buf[ii]); + data.push_back(0x20); + snprintf(buf, 9, "%d", i->timeout); + len = strlen(buf); + for(int i = 0; i < len; ++i) + data.push_back(buf[i]); + data.push_back(';'); + data.push_back('\n'); + } + } + std::string s = "config_update_interval="; + for(int i = 0; i < s.size(); ++i) + data.push_back(s[i]); + char buf[10]; + snprintf(buf, 9, "%d", cfg->c_cfg_upd_int()); + int len = strlen(buf); + for(int i = 0; i < len; ++i) + data.push_back(buf[i]); + data.push_back(';'); + data.push_back('\n'); + s = "client_update_interval="; + for(int i = 0; i < s.size(); ++i) + data.push_back(s[i]); + snprintf(buf, 9, "%d", cfg->c_cli_upd_int()); + len = strlen(buf); + for(int i = 0; i < len; ++i) + data.push_back(buf[i]); + data.push_back(';'); + data.push_back('\n'); + if(!cfg->c_welcome_msg().empty()) + { + s = "welcome_msg="; + for(int i = 0; i < s.size(); ++i) + data.push_back(s[i]); + for(int i = 0; i < cfg->c_welcome_msg().size(); ++i) + data.push_back(cfg->c_welcome_msg()[i]); + data.push_back(';'); + data.push_back('\n'); + } + if(!cfg->c_cfg_download_msg().empty()) + { + s = "config_downloaded_msg="; + for(int i = 0; i < s.size(); ++i) + data.push_back(s[i]); + for(int i = 0; i < cfg->c_cfg_download_msg().size(); ++i) + data.push_back(cfg->c_cfg_download_msg()[i]); + data.push_back(';'); + data.push_back('\n'); + } + if(!cfg->c_top_text().empty()) + { + s = "top_panel_text="; + for(int i = 0; i < s.size(); ++i) + data.push_back(s[i]); + for(int i = 0; i < cfg->c_top_text().size(); ++i) + data.push_back(cfg->c_top_text()[i]); + data.push_back(';'); + data.push_back('\n'); + } + if(!cfg->c_bottom_text().empty()) + { + s = "bottom_panel_text="; + for(int i = 0; i < s.size(); ++i) + data.push_back(s[i]); + for(int i = 0; i < cfg->c_bottom_text().size(); ++i) + data.push_back(cfg->c_bottom_text()[i]); + data.push_back(';'); + data.push_back('\n'); + } + s = "speed_visibility="; + for(int i = 0; i < s.size(); ++i) + data.push_back(s[i]); + data.push_back(cfg->c_speed_visibility()?'1':'0'); + data.push_back(';'); + data.push_back('\n'); data.push_back(0x14); data.push_back(0x14); write_w_response(data); @@ -221,7 +309,7 @@ void session::proto_parser(std::vector<byte>& data) data.push_back(0x13); data.push_back(0x13); data.push_back(0x02); - for(std::list<proxy_entry>::iterator it = cfg->get_proxy_list()->begin(), end = cfg->get_proxy_list()->end(); it != end; ++it) + for(std::list<config::proxy_entry>::iterator it = cfg->get_proxy_list()->begin(), end = cfg->get_proxy_list()->end(); it != end; ++it) { if(!it->login.empty() && !it->password.empty()) { @@ -302,7 +390,7 @@ void session::proto_parser(std::vector<byte>& data) data.push_back(0x13); data.push_back(0x13); data.push_back(0x03); - for(std::list<static_proxy_entry>::iterator it = cfg->get_static_proxy_list()->begin(), end = cfg->get_static_proxy_list()->end(); it != end; ++it) + for(std::list<config::static_proxy_entry>::iterator it = cfg->get_static_proxy_list()->begin(), end = cfg->get_static_proxy_list()->end(); it != end; ++it) { if(!it->login.empty() && !it->password.empty()) { @@ -430,7 +518,7 @@ void session::proto_parser(std::vector<byte>& data) data.push_back(0x13); data.push_back(0x13); data.push_back(0x05); - for(std::list<upload_entry>::iterator it = cfg->get_upload_list()->begin(), end = cfg->get_upload_list()->end(); it != end; ++it) + for(std::list<config::upload_entry>::iterator it = cfg->get_upload_list()->begin(), end = cfg->get_upload_list()->end(); it != end; ++it) { /*if(!(it->source.empty())) for(int i = 0; i < it->source.size(); ++ i) @@ -620,7 +708,7 @@ void session::proto_parser(std::vector<byte>& data) } filename += (char)*it; } - std::list<upload_entry>::iterator uit = std::find(cfg->get_upload_list()->begin(), cfg->get_upload_list()->end(), s_i(filename, 1)); + std::list<config::upload_entry>::iterator uit = std::find(cfg->get_upload_list()->begin(), cfg->get_upload_list()->end(), config::s_i(filename, 1)); if(uit == cfg->get_upload_list()->end()) { logger->lock(); |