diff options
Diffstat (limited to 'client/Proxifier.cpp')
-rw-r--r-- | client/Proxifier.cpp | 45 |
1 files changed, 37 insertions, 8 deletions
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; |