summaryrefslogtreecommitdiff
path: root/server/server/config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'server/server/config.cpp')
-rwxr-xr-xserver/server/config.cpp125
1 files changed, 85 insertions, 40 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();
+}