The couple objects were added from Mozilla VPN for Killswitch functionality
This commit is contained in:
parent
8f23970ccc
commit
858537df1f
15 changed files with 1794 additions and 81 deletions
|
|
@ -8,11 +8,79 @@
|
|||
#include "router_linux.h"
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <QNetworkInterface>
|
||||
#include "windowsfirewall.h"
|
||||
//#include "netadpinfo.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr char IKEV2[] {"AmneziaVPN IKEv2"};
|
||||
constexpr char WG[] {"AmneziaVPN.WireGuard0"};
|
||||
constexpr char OVPN[] {"TAP-Windows Adapter V9"};
|
||||
|
||||
bool get_eth_name(const QString &adp_name){
|
||||
//char buff[128]{};
|
||||
PIP_ADAPTER_INFO pAdapterInfo{};
|
||||
pAdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof(IP_ADAPTER_INFO));
|
||||
ULONG buflen = sizeof(IP_ADAPTER_INFO);
|
||||
if(GetAdaptersInfo(pAdapterInfo, &buflen) == ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
free(pAdapterInfo);
|
||||
pAdapterInfo = (IP_ADAPTER_INFO *)
|
||||
malloc(buflen);
|
||||
}
|
||||
if(GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) {
|
||||
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
|
||||
while (pAdapter) {
|
||||
qDebug()<<"Adapter Name: "<< pAdapter->AdapterName;
|
||||
qDebug()<<"Adapter Desc: "<<pAdapter->Description;
|
||||
if (adp_name == pAdapter->Description)
|
||||
return true;
|
||||
pAdapter = pAdapter->Next;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void enable_killswitch(){
|
||||
auto VPN_LIST = []()->int{
|
||||
auto adapterList = QNetworkInterface::allInterfaces();
|
||||
for (const auto& adapter : adapterList) {
|
||||
bool finded{false};
|
||||
finded = get_eth_name(OVPN);
|
||||
if ( adapter.humanReadableName().contains(IKEV2) ||
|
||||
adapter.humanReadableName().contains(WG) ||
|
||||
finded ||
|
||||
adapter.humanReadableName().contains(OVPN)
|
||||
) {
|
||||
return adapter.index();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
const auto ¤t_vpn = VPN_LIST();
|
||||
if (current_vpn != -1){
|
||||
qInfo()<<"KillSwitch activated";
|
||||
auto cf = WindowsFirewall::instance();
|
||||
//cf->enableKillSwitch(current_vpn);
|
||||
cf->disableKillSwitch();
|
||||
}else{
|
||||
qCritical().noquote() <<"No any adapters was found";
|
||||
}
|
||||
}
|
||||
}// end namespace
|
||||
#endif
|
||||
|
||||
|
||||
int Router::routeAddList(const QString &gw, const QStringList &ips)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
return RouterWin::Instance().routeAddList(gw, ips);
|
||||
auto value = RouterWin::Instance().routeAddList(gw, ips);
|
||||
enable_killswitch();
|
||||
return value;
|
||||
//return RouterWin::Instance().routeAddList(gw, ips);
|
||||
#elif defined (Q_OS_MAC)
|
||||
return RouterMac::Instance().routeAddList(gw, ips);
|
||||
#elif defined Q_OS_LINUX
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue