summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Borisov <borisov.alexandr@rambler.ru>2011-12-16 02:49:05 +0200
committerAlex Borisov <borisov.alexandr@rambler.ru>2011-12-16 02:49:05 +0200
commit9b513cd84e28c725d784368da3621376b74d3164 (patch)
treed9b9d4c405e748292a24918583e872d628ca945a
parent897b78bc5000b7ae7a4a56d4072ef02b6bcec222 (diff)
parent52edbe76a13d400848cfd4a13f2eedc03dcb133e (diff)
Merge branch 'master' of ssh://sss.chaoslab.ru//home/private_git/proxy_ui
-rwxr-xr-xserver/server/config.cpp125
-rwxr-xr-xserver/server/config.h25
-rwxr-xr-xserver/server/p_xml.cpp30
-rwxr-xr-xserver/server/p_xml.h8
4 files changed, 121 insertions, 67 deletions
diff --git a/server/server/config.cpp b/server/server/config.cpp
index 188c04b..688d818 100755
--- a/server/server/config.cpp
+++ b/server/server/config.cpp
@@ -1,58 +1,89 @@
#include "headers.h"
+void reload_config_thread_func(config *cfg)
+{
+ while(!boost::this_thread::interruption_requested())
+ {
+ boost::this_thread::sleep(boost::posix_time::seconds(cfg->config_reload_interval()));
+ if(boost::this_thread::interruption_requested())
+ return;
+ cfg->load_vars();
+ cfg->load_cvars();
+ cfg->load_proxy_list();
+ cfg->load_static_proxy_list();
+ cfg->load_firewall_list();
+ cfg->load_deleted_list();
+ cfg->load_upload_list();
+ cfg->load_servers_list();
+ }
+}
+
+void config::load_vars()
+{
+ std::ifstream config;
+ config.open(config_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();
+ 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=", "");
+ 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);
+ vars.config_reload_interval = get_int(cfg_str, "ConfigReloadInterval=", 600);
+ vars.proxy_check_interval = get_int(cfg_str, "ProxyCheckInterval=", 6000);
+ }
+}
+
+void config::load_cvars()
+{
+ std::ifstream config;
+ config.open(cli_config_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);
+ }
+}
+
config::config(const char *pth)
{
+ if(pth)
+ config_path = pth;
+ else
{
- 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=", "");
- 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);
- }
+ std::string cfg_path = boost::filesystem::initial_path().string();
+ cfg_path += "/server.cfg";
+ config_path = cfg_path;
}
{
- std::ifstream config;
std::string cfg_path = boost::filesystem::initial_path().string();
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);
- }
+ cli_config_path = cfg_path;
}
+ load_vars();
+ load_cvars();
load_proxy_list();
load_static_proxy_list();
load_firewall_list();
load_deleted_list();
load_upload_list();
load_servers_list();
+ cfg_reload_thr = new boost::thread(boost::bind(reload_config_thread_func, this));
}
const int config::get_int(const std::string& data, const char* var, int default_)
{
@@ -423,7 +454,8 @@ void config::load_deleted_list(char* pth)
std::list<config::p_proxy_entry> *config::make_p_proxy_list()
{
- p_proxy_list.clear();
+ if(!p_proxy_list.empty())
+ p_proxy_list.clear();
if(!static_proxy_list.empty())
{
for(std::list<config::static_proxy_entry>::iterator i = static_proxy_list.begin(), end = static_proxy_list.end(); i != end; ++i)
@@ -566,3 +598,16 @@ std::list<config::conn_server> *config::get_server_list()
{
return &servers_list;
}
+const int config::config_reload_interval()
+{
+ return vars.config_reload_interval;
+}
+const int config::proxy_check_interval()
+{
+ return vars.proxy_check_interval;
+}
+
+config::~config()
+{
+ cfg_reload_thr->interrupt();
+}
diff --git a/server/server/config.h b/server/server/config.h
index d94bf14..efbd1cc 100755
--- a/server/server/config.h
+++ b/server/server/config.h
@@ -141,9 +141,12 @@ public:
}
};
config(const char *path = NULL);
+ ~config();
const int ban_time();
const int conn_count();
const int conn_time();
+ const int config_reload_interval();
+ const int proxy_check_interval();
const int check_interval();
const int debug();
const int dos_conn_count();
@@ -154,7 +157,14 @@ public:
const std::string& c_cfg_download_msg();
const std::string& c_top_text();
const std::string& c_bottom_text();
-
+ void load_vars();
+ void load_cvars();
+ void load_proxy_list(char* pth = NULL);
+ void load_static_proxy_list(char* pth = NULL);
+ 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);
bool ignore_ssl_errors();
const std::string& bind_ip();
const std::string& log_path();
@@ -170,13 +180,15 @@ public:
private:
struct cfg_data
{
- int ban_time, conn_count, check_interval, debug, dos_conn_count, conn_time;
+ int ban_time, conn_count, check_interval, debug, dos_conn_count, conn_time, config_reload_interval, proxy_check_interval;
bool ignore_ssl_errors;
std::string log_path, bind_ip, dos_log_path, proxifier_path;
cfg_data()
{
ignore_ssl_errors = false;
ban_time = conn_time = 60;
+ config_reload_interval = 600;
+ proxy_check_interval = 3600;
conn_count = 30;
check_interval = 30;
debug = 0;
@@ -197,14 +209,9 @@ private:
speed_visibility = false;
}
};
+ std::string config_path, cli_config_path;
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);
- void load_static_proxy_list(char* pth = NULL);
- 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;
@@ -212,8 +219,8 @@ private:
std::list<std::string> firewall_list, deleted_list;
std::list<upload_entry> upload_list;
std::list<conn_server> servers_list;
-
std::list<p_proxy_entry> p_proxy_list;
+ boost::thread *cfg_reload_thr;
};
#endif \ No newline at end of file
diff --git a/server/server/p_xml.cpp b/server/server/p_xml.cpp
index 152949a..df41655 100755
--- a/server/server/p_xml.cpp
+++ b/server/server/p_xml.cpp
@@ -1,10 +1,11 @@
#include "headers.h"
-extern config *cfg;
using namespace rapidxml;
-bool p_load_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
+bool p_load_proxy_list(std::list<config::p_proxy_entry> *list, config *cfg, const char *path)
{
+ if(!list->empty())
+ list->clear();
std::ifstream file;
if(!path)
file.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str(), std::ios::in); //TODO: handle different locations
@@ -38,7 +39,7 @@ bool p_load_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
xml_node<> *auth = node->first_node("Authentication");
if(auth)
{
- e.enable_auth = atoi(auth->first_attribute("Enabled")->value());
+ 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)
}
@@ -50,8 +51,10 @@ bool p_load_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
return false;
}
-bool p_load_proxy_chains(std::list<config::p_proxy_chain> *list, char *path)
+bool p_load_proxy_chains(std::list<config::p_proxy_chain> *list, config *cfg, const char *path)
{
+ if(!list->empty())
+ list->clear();
std::ifstream file;
if(!path)
file.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str(), std::ios::in); //TODO: handle different locations
@@ -86,7 +89,7 @@ bool p_load_proxy_chains(std::list<config::p_proxy_chain> *list, char *path)
return false;
}
-bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
+bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, config *cfg, const char *path)
{
std::list<config::p_proxy_entry> *p_list = cfg->make_p_proxy_list();
if(p_list->empty())
@@ -107,10 +110,7 @@ bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
{
proxy_list->remove_all_nodes();
proxy_list->remove_all_attributes();
- doc.remove_node(proxy_list);
}
- proxy_list = doc.allocate_node(node_element, "ProxyList");
- doc.append_node(proxy_list);
for(std::list<config::p_proxy_entry>::iterator i = p_list->begin(), end = p_list->end(); i != end; ++i)
{
xml_node<> *proxy = doc.allocate_node(node_element, "Proxy");
@@ -136,14 +136,14 @@ bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
}
attr = doc.allocate_attribute("type", doc.allocate_string(type.c_str()));
proxy->append_attribute(attr);
- xml_node<> *node = doc.allocate_node(node_data, "Address");
+ xml_node<> *node = doc.allocate_node(node_element, "Address");
node->value(doc.allocate_string(i->host.c_str()));
proxy->append_node(node);
- node = doc.allocate_node(node_data, "Port");
+ node = doc.allocate_node(node_element, "Port");
snprintf(val, 7, "%d", i->port);
node->value(doc.allocate_string(val));
proxy->append_node(node);
- node = doc.allocate_node(node_data, "Options");
+ node = doc.allocate_node(node_element, "Options");
snprintf(val, 7, "%d", i->options);
node->value(doc.allocate_string(val));
proxy->append_node(node);
@@ -151,10 +151,11 @@ bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
{
xml_node<> *auth = doc.allocate_node(node_element, "Authentication");
attr = doc.allocate_attribute("enabled", i->enable_auth?"true":"false");
- node = doc.allocate_node(node_data, "Username");
+ auth->append_attribute(attr);
+ node = doc.allocate_node(node_element, "Username");
node->value(doc.allocate_string(i->login.c_str()));
auth->append_node(node);
- node = doc.allocate_node(node_data, "Password");
+ node = doc.allocate_node(node_element, "Password");
node->value(doc.allocate_string(i->password.c_str()));
auth->append_node(node);
proxy->append_node(auth);
@@ -168,6 +169,7 @@ bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
outfile.open(path);
if(outfile.is_open())
{
+ outfile<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
outfile<<doc;
return true;
}
@@ -175,6 +177,6 @@ bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
return false;
}
-bool p_save_proxy_chains(std::list<config::p_proxy_chain> *list, char *path)
+bool p_save_proxy_chains(std::list<config::p_proxy_chain> *list, config *cfg, const char *path)
{
} \ No newline at end of file
diff --git a/server/server/p_xml.h b/server/server/p_xml.h
index 08f1110..4a754e9 100755
--- a/server/server/p_xml.h
+++ b/server/server/p_xml.h
@@ -1,9 +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);
+bool p_load_proxy_list(std::list<config::p_proxy_entry> *list, config *cfg, const char* path = NULL);
+bool p_load_proxy_chains(std::list<config::p_proxy_chain> *list, config *cfg, const char *path = NULL);
+bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, config *cfg, const char *path = NULL);
+bool p_save_proxy_chains(std::list<config::p_proxy_chain> *list, config *cfg, const char *path = NULL);
#endif \ No newline at end of file