diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/Config.cpp | 5 | ||||
-rw-r--r-- | client/Config.h | 6 | ||||
-rw-r--r-- | client/Logger.cpp | 1 | ||||
-rw-r--r-- | client/Proxifier.cpp | 45 | ||||
-rw-r--r-- | client/Proxifier.h | 13 | ||||
-rw-r--r-- | client/ProxyClientApp.cpp | 17 |
6 files changed, 78 insertions, 9 deletions
diff --git a/client/Config.cpp b/client/Config.cpp index 8fdd507..45d8f72 100644 --- a/client/Config.cpp +++ b/client/Config.cpp @@ -281,6 +281,11 @@ vector<Config::FileEntry> Config::GetDownloadList() return downloadLst; } +vector<Config::FirewallEntry> Config::GetFirewallList() +{ + return firewalls; +} + void Config::ParseConfig(string data) { diff --git a/client/Config.h b/client/Config.h index 1e3dd72..ac2ed31 100644 --- a/client/Config.h +++ b/client/Config.h @@ -229,6 +229,12 @@ public: vector<FileEntry> GetDownloadList(); /** + * @brief Get list of firewall rules + * @return List of FirewallEntry wrapper object that describe firewall rules + */ + vector<FirewallEntry> GetFirewallList(); + + /** * @brief Static proxy speed value limit.<br/> * This value is used to determine speed label color. * All speed value below this constant will be red, higher values will be green diff --git a/client/Logger.cpp b/client/Logger.cpp index 74449ae..1367751 100644 --- a/client/Logger.cpp +++ b/client/Logger.cpp @@ -18,6 +18,7 @@ void Logger::InitLogFile() if (logFile == NULL) { logFile = fopen("client.log", "a"); + setbuf(logFile, NULL); } } diff --git a/client/Proxifier.cpp b/client/Proxifier.cpp index 6c8acdb..4485647 100644 --- a/client/Proxifier.cpp +++ b/client/Proxifier.cpp @@ -15,6 +15,8 @@ // static field initialization string Proxifier::defaultChain = "Client"; string Proxifier::defaultRule = "Default"; +string Proxifier::firewallRule = "Firewall"; + Proxifier* Proxifier::instance = NULL; @@ -332,10 +334,8 @@ bool Proxifier::TurnProxyOn(Proxy& proxy) { // the "Default" rule can't be disabled from Proxifier's UI // so we can skip this check here - string action = "Chain"; - Logger::Debug("Changing default rule action\n"); - + string action = "Chain"; if (!SetRuleAction(defaultRule, action, chainId)) { return false; @@ -400,6 +400,32 @@ bool Proxifier::TurnProxyOff(Proxy& proxy) return true; } +bool Proxifier::ApplyFirewallRules(vector<Config::FirewallEntry> rules) +{ + Logger::Trace("Applying new firewall list\n"); + if (! RemoveRule(firewallRule)) + { + return false; + } + + Rule _rule; + _rule.isEnabled = true; + _rule.name = firewallRule; + _rule.apps = ""; + _rule.ports = ""; + _rule.action = "Block"; + for (unsigned i = 0; i < rules.size(); i++) + { + _rule.targets.append(rules[i].host); + _rule.targets.append(";"); + } + if (! AddRule(_rule)) + { + return false; + } + return true; +} + void Proxifier::ReadConfig() { @@ -1150,13 +1176,13 @@ bool Proxifier::AddRule(Rule& rule) // targets element if (! rule.targets.empty()) { - QDomElement targetsElem = configDom.createElement("Applications"); + QDomElement targetsElem = configDom.createElement("Targets"); QDomText targetsTxt = configDom.createTextNode(QString::fromLocal8Bit(rule.targets.c_str())); targetsElem.appendChild(targetsTxt); ruleElem.appendChild(targetsElem); } // ports element - if (! rule.targets.empty()) + if (! rule.ports.empty()) { QDomElement portsElem = configDom.createElement("Ports"); QDomText portsTxt = configDom.createTextNode(QString::fromLocal8Bit(rule.ports.c_str())); @@ -1180,6 +1206,9 @@ bool Proxifier::AddRule(Rule& rule) actionElem.appendChild(actId); } ruleElem.appendChild(actionElem); + // Default rule should be the last one, so we can't just append it to the end, but to the start + ruleListElem.insertBefore(ruleElem, ruleListElem.firstChildElement()); + // update state to reflect all the changes ReadRuleList(root); @@ -1256,7 +1285,7 @@ bool Proxifier::SetRuleAction(string& name, string& action, int actId) ruleElem = ruleElem.nextSiblingElement("Rule"); } // update state to reflect all the changes - ReadRuleList(root); + ReadRuleList(root); // save new DOM to file config = new QFile(filePath); @@ -1264,7 +1293,7 @@ bool Proxifier::SetRuleAction(string& name, string& action, int actId) { Logger::Error("Can't open Proxifier config file for writing\n"); return false; - } + } QTextStream(config) << configDom.toString(indent); config->close(); delete config; @@ -1297,7 +1326,7 @@ bool Proxifier::RemoveRule(string& name) Logger::Error("Invalid Proxifier configuration file!\n"); return false; } - QDomElement ruleListElem = root.firstChildElement("ChainList"); + QDomElement ruleListElem = root.firstChildElement("RuleList"); if (ruleListElem.isNull()) { return false; diff --git a/client/Proxifier.h b/client/Proxifier.h index 112bc90..9d5b316 100644 --- a/client/Proxifier.h +++ b/client/Proxifier.h @@ -7,6 +7,7 @@ #include <string> #include <QDomElement> #include <QString> +#include "Config.h" #include "Proxy.h" @@ -67,7 +68,13 @@ public: * send all traffic directly to servers */ bool TurnProxyOff(Proxy& proxy); - + /** + * @brief apply firewall rules + * @param rules firewall rules to apply + * @return true on success or false otherwise + * @note all existing rules will be overwritten + */ + bool ApplyFirewallRules(vector<Config::FirewallEntry> rules); private: /** * @brief class representing Proxifier's proxy setting @@ -152,6 +159,10 @@ private: */ static string defaultRule; /** + * @brief default firewall rule name + */ + static string firewallRule; + /** * @brief pointer to sigleton instance */ static Proxifier *instance; diff --git a/client/ProxyClientApp.cpp b/client/ProxyClientApp.cpp index 0ba813c..62de86f 100644 --- a/client/ProxyClientApp.cpp +++ b/client/ProxyClientApp.cpp @@ -3,6 +3,7 @@ #include "client.h" #include "Dialog.h" +#include "Proxifier.h" #include "ProxyClientApp.h" #include "UpdatedConfig.h" @@ -92,6 +93,22 @@ void ProxyClientApp::configUpdated() fileOpThread.start(QThread::NormalPriority); UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); + Proxifier *proxifier = Proxifier::GetInstance(); + //update Proxifier Rules + if (proxifier->IsValid()) + { + proxifier->ApplyFirewallRules(cfg->GetFirewallList()); + if (!proxifier->Restart()) + { + Logger::Error("Unable to restart Proxifier process!\n"); + } + } + else + { + Logger::Error("No valid proxifier configuration file found!\n"); + } + + // show message when config updated QString msg = QString::fromLocal8Bit(cfg->ConfigLoadedMsg.c_str()); QMessageBox updatedMsg; updatedMsg.setText(msg); |