Skip to content

Commit 114f87f

Browse files
author
Ed Guloien
committed
Added v2.3.15 changes
1 parent 08274a4 commit 114f87f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

40 files changed

+383
-167
lines changed

backend/engine/engine/connectionmanager/finishactiveconnections.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
#include "engine/helper/helper_mac.h"
1515
#endif
1616

17+
#ifdef Q_OS_LINUX
18+
#include "engine/helper/helper_posix.h"
19+
#endif
20+
1721
void FinishActiveConnections::finishAllActiveConnections(IHelper *helper)
1822
{
1923
#ifdef Q_OS_WIN
2024
finishAllActiveConnections_win(helper);
2125
#elif defined Q_OS_MAC
2226
finishAllActiveConnections_mac(helper);
2327
#elif defined Q_OS_LINUX
24-
//todo linux
25-
//Q_ASSERT(false);
26-
Q_UNUSED(helper);
28+
finishAllActiveConnections_linux(helper);
2729
#endif
2830
}
2931

@@ -96,4 +98,22 @@ void FinishActiveConnections::finishWireGuardActiveConnections_mac(IHelper *help
9698
helper->setDefaultWireGuardDeviceName(WireGuardConnection::getWireGuardAdapterName());
9799
helper->stopWireGuard();
98100
}
101+
#elif defined Q_OS_LINUX
102+
103+
void FinishActiveConnections::finishAllActiveConnections_linux(IHelper *helper)
104+
{
105+
// todo: kill openvpn, wireguard for Linux
106+
removeDnsLeaksprotection_linux(helper);
107+
}
108+
109+
void FinishActiveConnections::removeDnsLeaksprotection_linux(IHelper *helper)
110+
{
111+
Helper_posix *helperPosix = dynamic_cast<Helper_posix *>(helper);
112+
int exitCode;
113+
helperPosix->executeRootCommand("/etc/windscribe/dns-leak-protect down", &exitCode);
114+
}
115+
99116
#endif
117+
118+
119+

backend/engine/engine/connectionmanager/finishactiveconnections.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class FinishActiveConnections
1818
static void finishAllActiveConnections_mac(IHelper *helper);
1919
static void finishOpenVpnActiveConnections_mac(IHelper *helper);
2020
static void finishWireGuardActiveConnections_mac(IHelper *helper);
21+
#elif defined Q_OS_LINUX
22+
static void finishAllActiveConnections_linux(IHelper *helper);
23+
static void removeDnsLeaksprotection_linux(IHelper *helper);
2124
#endif
2225
};
2326

backend/engine/engine/dnsresolver/dnsutils_linux.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,37 @@ namespace DnsUtils
99
std::vector<std::wstring> getOSDefaultDnsServers()
1010
{
1111
std::vector<std::wstring> dnsServers;
12-
//todo linux
12+
13+
14+
QString strReply;
15+
FILE *file = popen("(nmcli dev list || nmcli dev show ) 2>/dev/null | grep DNS", "r");
16+
if (file)
17+
{
18+
char szLine[4096];
19+
while(fgets(szLine, sizeof(szLine), file) != 0)
20+
{
21+
strReply += szLine;
22+
}
23+
pclose(file);
24+
}
25+
26+
if (strReply.isEmpty())
27+
{
28+
qCDebug(LOG_FIREWALL_CONTROLLER) << "Can't get OS default DNS list: probably the nmcli utility (network-manager package) is not installed";
29+
return dnsServers;
30+
}
31+
32+
const QStringList lines = strReply.split('\n', QString::SkipEmptyParts);
33+
qCDebug(LOG_FIREWALL_CONTROLLER) << "Get OS default DNS list:" << lines;
34+
for (auto &it : lines)
35+
{
36+
const QStringList pars = it.split(QRegExp("\\s+"), QString::SkipEmptyParts);
37+
if (pars.size() == 2)
38+
{
39+
dnsServers.push_back(pars[1].toStdWString());
40+
}
41+
}
42+
1343
return dnsServers;
1444
}
1545

backend/engine/engine/engine.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ Engine::Engine(const EngineSettings &engineSettings) : QObject(nullptr),
9090
lastDownloadProgress_(0),
9191
installerUrl_(""),
9292
guiWindowHandle_(0),
93-
overrideUpdateChannelWithInternal_(false)
93+
overrideUpdateChannelWithInternal_(false),
94+
bPrevNetworkInterfaceInitialized_(false)
9495
{
9596
connectStateController_ = new ConnectStateController(nullptr);
9697
connect(connectStateController_, SIGNAL(stateChanged(CONNECT_STATE,DISCONNECT_REASON,ProtoTypes::ConnectError,LocationID)), SLOT(onConnectStateChanged(CONNECT_STATE,DISCONNECT_REASON,ProtoTypes::ConnectError,LocationID)));
@@ -501,11 +502,6 @@ void Engine::forceUpdateServerLocations()
501502
QMetaObject::invokeMethod(this, "forceUpdateServerLocationsImpl");
502503
}
503504

504-
void Engine::updateCurrentNetworkInterface()
505-
{
506-
QMetaObject::invokeMethod(this, "updateCurrentNetworkInterfaceImpl");
507-
}
508-
509505
void Engine::updateCurrentInternetConnectivity()
510506
{
511507
QMetaObject::invokeMethod(this, "updateCurrentInternetConnectivityImpl");
@@ -983,7 +979,7 @@ void Engine::loginImpl(bool bSkipLoadingFromSettings)
983979

984980
updateSessionStatus();
985981
updateServerLocations();
986-
updateCurrentNetworkInterface();
982+
updateCurrentNetworkInterfaceImpl();
987983
Q_EMIT loginFinished(true, authHash, apiInfo_->getPortMap());
988984
}
989985
}
@@ -1197,7 +1193,15 @@ void Engine::updateCurrentInternetConnectivityImpl()
11971193

11981194
void Engine::updateCurrentNetworkInterfaceImpl()
11991195
{
1200-
networkDetectionManager_->updateCurrentNetworkInterface();
1196+
ProtoTypes::NetworkInterface networkInterface;
1197+
networkDetectionManager_->getCurrentNetworkInterface(networkInterface);
1198+
1199+
if (!bPrevNetworkInterfaceInitialized_ || !google::protobuf::util::MessageDifferencer::Equals(networkInterface, prevNetworkInterface_))
1200+
{
1201+
prevNetworkInterface_ = networkInterface;
1202+
bPrevNetworkInterfaceInitialized_ = true;
1203+
Q_EMIT networkChanged(networkInterface);
1204+
}
12011205
}
12021206

12031207
void Engine::firewallOnImpl()
@@ -1381,7 +1385,7 @@ void Engine::onLoginControllerFinished(LOGIN_RET retCode, const apiinfo::ApiInfo
13811385
{
13821386
loginState_ = LOGIN_FINISHED;
13831387
}
1384-
updateCurrentNetworkInterface();
1388+
updateCurrentNetworkInterfaceImpl();
13851389
Q_EMIT loginFinished(false, apiInfo_->getAuthHash(), apiInfo_->getPortMap());
13861390
}
13871391
else if (retCode == LOGIN_NO_CONNECTIVITY)

backend/engine/engine/engine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class Engine : public QObject
8989
void speedRating(int rating, const QString &localExternalIp); //rate current connection(0 - down, 1 - up)
9090

9191
void updateServerConfigs();
92-
void updateCurrentNetworkInterface();
9392
void updateCurrentInternetConnectivity();
9493

9594
// emergency connect functions
@@ -401,6 +400,8 @@ private slots:
401400
qint32 guiWindowHandle_;
402401

403402
bool overrideUpdateChannelWithInternal_;
403+
bool bPrevNetworkInterfaceInitialized_;
404+
ProtoTypes::NetworkInterface prevNetworkInterface_;
404405
};
405406

406407
#endif // ENGINE_H

backend/engine/engine/firewall/firewallcontroller_linux.cpp

Lines changed: 70 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,54 +50,19 @@ bool FirewallController_linux::firewallOff()
5050
FirewallController::firewallOff();
5151
if (isStateChanged())
5252
{
53-
// get current rules to temp file
53+
QString cmd;
5454
int exitCode;
55-
QString cmd = "iptables-save > " + pathToTempTable_;
56-
helper_->executeRootCommand(cmd, &exitCode);
57-
if (exitCode != 0)
58-
{
59-
qCDebug(LOG_FIREWALL_CONTROLLER) << "Unsuccessful exit code:" << exitCode << " for cmd:" << cmd;
60-
return false;
61-
}
62-
// Get Windscribe rules
63-
QStringList rules;
64-
QFile file(pathToTempTable_);
65-
if (!file.open(QIODevice::ReadOnly))
66-
{
67-
qCDebug(LOG_FIREWALL_CONTROLLER) << "Can't open file:" << pathToTempTable_;
68-
return false;
69-
}
70-
71-
QTextStream in(&file);
72-
bool bFound = false;
73-
while (!in.atEnd())
74-
{
75-
std::string line = in.readLine().toStdString();
76-
if ((line.rfind("*", 0) == 0) || // string starts with "*"
77-
(line.find("COMMIT") != std::string::npos) ||
78-
((line.rfind("-A", 0) == 0) && (line.find("-m comment --comment " + comment_.toStdString()) != std::string::npos)) )
79-
{
80-
if (line.rfind("-A", 0) == 0)
81-
{
82-
line[1] = 'D';
83-
bFound = true;
84-
}
85-
rules << QString::fromStdString(line);
86-
}
87-
88-
}
89-
file.close();
55+
QStringList rules = getWindscribeRules(comment_, true);
9056

9157
// delete Windscribe rules, if found
92-
if (bFound && !rules.isEmpty())
58+
if (!rules.isEmpty())
9359
{
9460
if (rules.last().contains("COMMIT"))
9561
{
9662
rules.insert(rules.count() - 1, "-X windscribe_input");
9763
rules.insert(rules.count() - 1, "-X windscribe_output");
9864
}
9965

100-
file.remove();
10166
QFile file2(pathToTempTable_);
10267
if (file2.open(QIODevice::WriteOnly | QIODevice::Text))
10368
{
@@ -146,7 +111,6 @@ bool FirewallController_linux::firewallOff()
146111
qCDebug(LOG_FIREWALL_CONTROLLER) << "Unsuccessful exit code:" << exitCode << " for cmd:" << cmd;
147112
}
148113

149-
150114
return true;
151115
}
152116
else
@@ -197,6 +161,9 @@ void FirewallController_linux::enableFirewallOnBoot(bool bEnable)
197161

198162
bool FirewallController_linux::firewallOnImpl(const QString &ip, bool bAllowLanTraffic, const apiinfo::StaticIpPortsVector &ports)
199163
{
164+
// TODO: this is need for Linux?
165+
Q_UNUSED(ports);
166+
200167
// if the firewall is not installed by the program, then save iptables to file in order to restore when will we turn off the firewall
201168
if (!firewallActualState())
202169
{
@@ -209,6 +176,10 @@ bool FirewallController_linux::firewallOnImpl(const QString &ip, bool bAllowLanT
209176
}
210177
}
211178

179+
// get firewall rules, which could have been installed by a script update-resolv-conf/update-systemd-resolved to avoid DNS-leaks
180+
// if these rules exist, then we should leave(not delete) them.
181+
const QStringList dnsLeaksRules = getWindscribeRules("\"Windscribe client dns leak protection\"", false);
182+
212183
forceUpdateInterfaceToSkip_ = false;
213184

214185
QFile file(pathToTempTable_);
@@ -220,6 +191,18 @@ bool FirewallController_linux::firewallOnImpl(const QString &ip, bool bAllowLanT
220191
stream << ":windscribe_input - [0:0]\n";
221192
stream << ":windscribe_output - [0:0]\n";
222193

194+
if (!dnsLeaksRules.isEmpty())
195+
{
196+
stream << ":windscribe_dnsleaks - [0:0]\n";
197+
for (auto &rule : dnsLeaksRules)
198+
{
199+
if (rule.startsWith("-A"))
200+
{
201+
stream << rule + "\n";
202+
}
203+
}
204+
}
205+
223206
stream << "-A INPUT -j windscribe_input -m comment --comment " + comment_ + "\n";
224207
stream << "-A OUTPUT -j windscribe_output -m comment --comment " + comment_ + "\n";
225208

@@ -318,3 +301,51 @@ bool FirewallController_linux::firewallOnImpl(const QString &ip, bool bAllowLanT
318301

319302
return true;
320303
}
304+
305+
// Extract rules from iptables with comment.If modifyForDelete == true, then replace commands for delete.
306+
QStringList FirewallController_linux::getWindscribeRules(const QString &comment, bool modifyForDelete)
307+
{
308+
QStringList rules;
309+
int exitCode;
310+
QString cmd = "iptables-save > " + pathToTempTable_;
311+
helper_->executeRootCommand(cmd, &exitCode);
312+
if (exitCode != 0)
313+
{
314+
qCDebug(LOG_FIREWALL_CONTROLLER) << "Unsuccessful exit code:" << exitCode << " for cmd:" << cmd;
315+
}
316+
// Get Windscribe rules
317+
QFile file(pathToTempTable_);
318+
if (!file.open(QIODevice::ReadOnly))
319+
{
320+
qCDebug(LOG_FIREWALL_CONTROLLER) << "Can't open file:" << pathToTempTable_;
321+
}
322+
323+
QTextStream in(&file);
324+
bool bFound = false;
325+
while (!in.atEnd())
326+
{
327+
std::string line = in.readLine().toStdString();
328+
if ((line.rfind("*", 0) == 0) || // string starts with "*"
329+
(line.find("COMMIT") != std::string::npos) ||
330+
((line.rfind("-A", 0) == 0) && (line.find("-m comment --comment " + comment.toStdString()) != std::string::npos)) )
331+
{
332+
if (line.rfind("-A", 0) == 0)
333+
{
334+
if (modifyForDelete)
335+
{
336+
line[1] = 'D';
337+
}
338+
bFound = true;
339+
}
340+
rules << QString::fromStdString(line);
341+
}
342+
}
343+
344+
file.close();
345+
file.remove();
346+
if (!bFound)
347+
{
348+
rules.clear();
349+
}
350+
return rules;
351+
}

backend/engine/engine/firewall/firewallcontroller_linux.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class FirewallController_linux : public FirewallController
3232
QString comment_;
3333

3434
bool firewallOnImpl(const QString &ip, bool bAllowLanTraffic, const apiinfo::StaticIpPortsVector &ports);
35+
QStringList getWindscribeRules(const QString &comment, bool modifyForDelete);
3536
};
3637

3738
#endif // FIREWALLCONTROLLER_LINUX_H

backend/engine/engine/macaddresscontroller/macaddresscontroller_mac.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ void MacAddressController_mac::setMacAddrSpoofing(const ProtoTypes::MacAddrSpoof
5959

6060
if (actuallyAutoRotate_) // auto-rotate
6161
{
62-
const ProtoTypes::NetworkInterface lastInterface = networkDetectionManager_->lastNetworkInterface();
62+
ProtoTypes::NetworkInterface lastInterface;
63+
networkDetectionManager_->getCurrentNetworkInterface(lastInterface);
6364
int spoofIndex = lastInterface.interface_index();
6465
if (spoofIndex != -1)
6566
{
@@ -244,8 +245,11 @@ void MacAddressController_mac::autoRotateUpdateMacSpoof()
244245
{
245246
ProtoTypes::MacAddrSpoofing updatedMacAddrSpoofing = macAddrSpoofingWithUpdatedNetworkList();
246247

247-
bool lastIsSameAsSelected = networkDetectionManager_->lastNetworkInterface().interface_index() == updatedMacAddrSpoofing.selected_network_interface().interface_index();
248-
bool lastUp = MacUtils::isAdapterUp(QString::fromStdString(networkDetectionManager_->lastNetworkInterface().interface_name()));
248+
ProtoTypes::NetworkInterface lastInterface;
249+
networkDetectionManager_->getCurrentNetworkInterface(lastInterface);
250+
251+
bool lastIsSameAsSelected = lastInterface.interface_index() == updatedMacAddrSpoofing.selected_network_interface().interface_index();
252+
bool lastUp = MacUtils::isAdapterUp(QString::fromStdString(lastInterface.interface_name()));
249253

250254
if (autoRotate_ && lastIsSameAsSelected && lastUp) // apply-able interface
251255
{
@@ -259,7 +263,7 @@ void MacAddressController_mac::autoRotateUpdateMacSpoof()
259263
qCDebug(LOG_BASIC) << "Couldn't rotate";
260264
qCDebug(LOG_BASIC) << "Auto rotate ON: " << autoRotate_;
261265
qCDebug(LOG_BASIC) << "Last is same as selected: " << lastIsSameAsSelected << " "
262-
<< QString::fromStdString(networkDetectionManager_->lastNetworkInterface().interface_name()) << " (last) "
266+
<< QString::fromStdString(lastInterface.interface_name()) << " (last) "
263267
<< QString::fromStdString(updatedMacAddrSpoofing.selected_network_interface().interface_name()) << "(selected)";
264268
qCDebug(LOG_BASIC) << "Last is up?: " << lastUp;
265269
}

backend/engine/engine/networkdetectionmanager/inetworkdetectionmanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class INetworkDetectionManager : public QObject
1010
public:
1111
explicit INetworkDetectionManager(QObject *parent) : QObject(parent) {}
1212
virtual ~INetworkDetectionManager() {}
13-
virtual void updateCurrentNetworkInterface() = 0;
13+
virtual void getCurrentNetworkInterface(ProtoTypes::NetworkInterface &networkInterface) = 0;
1414
virtual bool isOnline() = 0;
1515

1616
signals:

0 commit comments

Comments
 (0)