From c63990f720e9dd6ce5c385d1d923822239c3c96a Mon Sep 17 00:00:00 2001 From: pokamest Date: Wed, 24 Feb 2021 21:58:32 +0300 Subject: [PATCH] Auto start Auto connect Dns settings ui fixes --- client/client.pro | 2 + client/images/close.png | Bin 342 -> 344 bytes client/images/reload.png | Bin 0 -> 690 bytes client/protocols/openvpnprotocol.cpp | 2 - client/protocols/shadowsocksvpnprotocol.cpp | 1 - client/resources.qrc | 1 + client/settings.h | 3 + client/ui/mainwindow.cpp | 63 +- client/ui/mainwindow.h | 4 +- client/ui/mainwindow.ui | 620 +++++++++++++++++--- client/ui/qautostart.cpp | 154 +++++ client/ui/qautostart.h | 39 ++ client/vpnconnection.cpp | 9 +- deploy/windows-env.bat | 2 +- 14 files changed, 801 insertions(+), 99 deletions(-) create mode 100644 client/images/reload.png create mode 100644 client/ui/qautostart.cpp create mode 100644 client/ui/qautostart.h diff --git a/client/client.pro b/client/client.pro index 1256427f..fd56dfcd 100644 --- a/client/client.pro +++ b/client/client.pro @@ -24,6 +24,7 @@ HEADERS += \ settings.h \ ui/Controls/SlidingStackedWidget.h \ ui/mainwindow.h \ + ui/qautostart.h \ utils.h \ vpnconnection.h \ protocols/vpnprotocol.h \ @@ -41,6 +42,7 @@ SOURCES += \ settings.cpp \ ui/Controls/SlidingStackedWidget.cpp \ ui/mainwindow.cpp \ + ui/qautostart.cpp \ utils.cpp \ vpnconnection.cpp \ protocols/vpnprotocol.cpp \ diff --git a/client/images/close.png b/client/images/close.png index 2fc5db3e16bc33d6cb7ed332e17f0688d9777936..072232c1608685c0f88f2fc394a314c2be9a8859 100644 GIT binary patch delta 267 zcmV+m0rdXX0@wnOR)6hDL_t(|0fmyu4Z<)KMCUt>2%KC2;=q9;bPyy8fDWJo=pY?X z0-^%M8Kh83O2`QXWihrRqAa$Ui?{#$$0L&n!WoEPAd5qqy%IPi{BQ}*&lnXuFYxC# z5JHf*4ZP_+E0WX-_&ip13*_v>bO%VOI>;HAADhlLKurO-p041pM zwYE9{-jBVmr{=~!i0Y)qOCRV!L$E3709vfQFzFFa?LB2RLQib)=-QH!tW&gv!(1t$ zDp#&l$p-x1;7XNTfIXZVWaeu)fF>MSt{bbww-6!}VzP zR0c$tzJat2ZMD4{2fOOu|D^M64!V#gA$eJkv zsZw*SMGv7=DFg(<$w3hrI)nfgS7u}RRU#}PwU$ba_V^=yF-b;SUcUhz%YrL5O7yP) P0000$TRKr$rU-2;#w5bhg<8@Kw1P=As)XrI986O=wdLc$$$;_62Ty(H=db0(2| zK(wNchuyVJHrR1W!lC^nOZLwC`*wC`z6H4Jz_OreIp#*?p+g9}2xt?4m4*fY6cE9u z$*AAW=2y25zM>c(5Bsl{3RIu%Ibg635|~f|AsPVD$rQM6U@Qb6_&)4yWpP&YQ*Hb3 z6gm5-$cg+I=s2QZTjOC5})V{i@0(b)anPW7;TGf2_cGGlZy`? zl;H96{UgTkR3n_rz|bdG>-)`&d>XTz@S+ziA~x%9ECV*1@|}P@aYjzjJYzl|Owx?$ zI2?5YC;^Afwph$zvg+AJsLYE5waRzIVryQ34t!)tm(h5wgX~K#y zpT4zIvO!KjbgLRPDv=Egd9X5WArILfD9x6S%H$FKH5N)arW; z_(vozfDP$SdLR7}2nV8iC~m10AnQmgfEz;1&HP9>s~+R}$L08ZbnnT_M #include -//#include "communicator.h" #include "debug.h" #include "openvpnprotocol.h" #include "utils.h" @@ -189,7 +188,6 @@ ErrorCode OpenVpnProtocol::start() m_openVpnProcess->start(); - //m_communicator->sendMessage(Message(Message::State::StartRequest, args)); //startTimeoutTimer(); return ErrorCode::NoError; diff --git a/client/protocols/shadowsocksvpnprotocol.cpp b/client/protocols/shadowsocksvpnprotocol.cpp index f853cf69..2b4d20c1 100644 --- a/client/protocols/shadowsocksvpnprotocol.cpp +++ b/client/protocols/shadowsocksvpnprotocol.cpp @@ -1,7 +1,6 @@ #include "shadowsocksvpnprotocol.h" #include "core/servercontroller.h" -//#include "communicator.h" #include "debug.h" #include "utils.h" diff --git a/client/resources.qrc b/client/resources.qrc index b20355a1..d5e681ee 100644 --- a/client/resources.qrc +++ b/client/resources.qrc @@ -40,5 +40,6 @@ server_scripts/setup_shadowsocks_server.sh server_scripts/template_shadowsocks.ovpn server_scripts/setup_firewall.sh + images/reload.png diff --git a/client/settings.h b/client/settings.h index 602184c9..a6dc1b66 100644 --- a/client/settings.h +++ b/client/settings.h @@ -34,6 +34,9 @@ public: void setServerCredentials(const ServerCredentials &credentials); bool haveAuthData() const; + bool isAutoConnect() const { return m_settings.value("Conf/autoConnect", QString()).toBool(); } + void setAutoConnect(bool enabled) { m_settings.setValue("Conf/autoConnect", enabled); } + bool customRouting() const { return m_settings.value("Conf/customRouting", false).toBool(); } void setCustomRouting(bool customRouting) { m_settings.setValue("Conf/customRouting", customRouting); } diff --git a/client/ui/mainwindow.cpp b/client/ui/mainwindow.cpp index 6c989593..9a91d170 100644 --- a/client/ui/mainwindow.cpp +++ b/client/ui/mainwindow.cpp @@ -11,11 +11,10 @@ #include #include -//#include "communicator.h" - #include "core/errorstrings.h" #include "core/openvpnconfigurator.h" #include "core/servercontroller.h" +#include "ui/qautostart.h" #include "debug.h" #include "defines.h" @@ -74,7 +73,6 @@ MainWindow::MainWindow(QWidget *parent) : updateSettings(); //ui->pushButton_general_settings_exit->hide(); - //ui->pushButton_share_connection->hide(); setFixedSize(width(),height()); @@ -90,7 +88,20 @@ MainWindow::MainWindow(QWidget *parent) : onConnectionStateChanged(VpnProtocol::ConnectionState::Disconnected); + if (m_settings.isAutoConnect() && m_settings.haveAuthData()) { + QTimer::singleShot(1000, this, [this](){ + ui->pushButton_connect->setEnabled(false); + onConnect(); + }); + } + qDebug().noquote() << QString("Default config: %1").arg(Utils::defaultVpnConfigFileName()); + + m_ipAddressValidator.setRegExp(QRegExp("^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\\.(?!$)|$)){4}$")); + + ui->lineEdit_new_server_ip->setValidator(&m_ipAddressValidator); + ui->lineEdit_network_settings_dns1->setValidator(&m_ipAddressValidator); + ui->lineEdit_network_settings_dns2->setValidator(&m_ipAddressValidator); } MainWindow::~MainWindow() @@ -146,6 +157,8 @@ QWidget *MainWindow::getPageWidget(MainWindow::Page page) case(Page::NewServer): return ui->page_new_server; case(Page::Vpn): return ui->page_vpn; case(Page::GeneralSettings): return ui->page_general_settings; + case(Page::AppSettings): return ui->page_app_settings; + case(Page::NetworkSettings): return ui->page_network_settings; case(Page::ServerSettings): return ui->page_server_settings; case(Page::ShareConnection): return ui->page_share_connection; case(Page::Sites): return ui->page_sites; @@ -525,6 +538,8 @@ void MainWindow::setupUiConnections() connect(ui->pushButton_vpn_add_site, &QPushButton::clicked, this, [this](){ goToPage(Page::Sites); }); connect(ui->pushButton_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); }); + connect(ui->pushButton_app_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::AppSettings); }); + connect(ui->pushButton_network_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::NetworkSettings); }); connect(ui->pushButton_server_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::ServerSettings); }); connect(ui->pushButton_share_connection, &QPushButton::clicked, this, [this](){ goToPage(Page::ShareConnection); @@ -535,7 +550,7 @@ void MainWindow::setupUiConnections() QGuiApplication::clipboard()->setText(ui->textEdit_sharing_code->toPlainText()); ui->pushButton_copy_sharing_code->setText(tr("Copied")); - QTimer::singleShot(3000, [this]() { + QTimer::singleShot(3000, this, [this]() { ui->pushButton_copy_sharing_code->setText(tr("Copy")); }); }); @@ -544,6 +559,8 @@ void MainWindow::setupUiConnections() connect(ui->pushButton_back_from_sites, &QPushButton::clicked, this, [this](){ goToPage(Page::Vpn); }); connect(ui->pushButton_back_from_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::Vpn); }); connect(ui->pushButton_back_from_new_server, &QPushButton::clicked, this, [this](){ goToPage(Page::Start); }); + connect(ui->pushButton_back_from_app_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); }); + connect(ui->pushButton_back_from_network_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); }); connect(ui->pushButton_back_from_server_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); }); connect(ui->pushButton_back_from_share, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); }); @@ -555,6 +572,38 @@ void MainWindow::setupUiConnections() connect(ui->radioButton_mode_selected_sites, &QRadioButton::toggled, this, [this](bool toggled) { m_settings.setCustomRouting(toggled); }); + + connect(ui->checkBox_autostart, &QCheckBox::stateChanged, this, [this](int state){ + if (state == Qt::Unchecked) { + ui->checkBox_autoconnect->setChecked(false); + } + Autostart::setAutostart(state == Qt::Checked); + }); + + connect(ui->checkBox_autoconnect, &QCheckBox::stateChanged, this, [this](int state){ + m_settings.setAutoConnect(state == Qt::Checked); + }); + + connect(ui->pushButton_network_settings_resetdns1, &QPushButton::clicked, this, [this](){ + m_settings.setPrimaryDns(m_settings.cloudFlareNs1()); + updateSettings(); + }); + connect(ui->pushButton_network_settings_resetdns2, &QPushButton::clicked, this, [this](){ + m_settings.setPrimaryDns(m_settings.cloudFlareNs2()); + updateSettings(); + }); + + connect(ui->lineEdit_network_settings_dns1, &QLineEdit::textEdited, this, [this](const QString &newText){ + if (m_ipAddressValidator.regExp().exactMatch(newText)) { + m_settings.setPrimaryDns(newText); + } + }); + connect(ui->lineEdit_network_settings_dns2, &QLineEdit::textEdited, this, [this](const QString &newText){ + if (m_ipAddressValidator.regExp().exactMatch(newText)) { + m_settings.setSecondaryDns(newText); + } + }); + } void MainWindow::setTrayState(VpnProtocol::ConnectionState state) @@ -723,6 +772,12 @@ void MainWindow::updateSettings() customSitesModel->setStringList(m_settings.customSites()); ui->radioButton_mode_selected_sites->setChecked(m_settings.customRouting()); ui->pushButton_vpn_add_site->setEnabled(m_settings.customRouting()); + + ui->checkBox_autostart->setChecked(Autostart::isAutostart()); + ui->checkBox_autoconnect->setChecked(m_settings.isAutoConnect()); + + ui->lineEdit_network_settings_dns1->setText(m_settings.primaryDns()); + ui->lineEdit_network_settings_dns2->setText(m_settings.secondaryDns()); } void MainWindow::updateShareCode() diff --git a/client/ui/mainwindow.h b/client/ui/mainwindow.h index 58cbcbd3..78b70243 100644 --- a/client/ui/mainwindow.h +++ b/client/ui/mainwindow.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -35,7 +36,7 @@ public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); - enum Page {Start, NewServer, Vpn, GeneralSettings, ServerSettings, ShareConnection, Sites}; + enum Page {Start, NewServer, Vpn, GeneralSettings, AppSettings, NetworkSettings, ServerSettings, ShareConnection, Sites}; Q_ENUM(Page) private slots: @@ -90,6 +91,7 @@ private: QMenu* m_menu; QStringListModel *customSitesModel = nullptr; + QRegExpValidator m_ipAddressValidator; bool canMove = false; QPoint offset; diff --git a/client/ui/mainwindow.ui b/client/ui/mainwindow.ui index e5843d3a..13d1158b 100644 --- a/client/ui/mainwindow.ui +++ b/client/ui/mainwindow.ui @@ -60,31 +60,26 @@ QLineEdit:disabled { QCheckBox { - color: rgb(200, 200, 200); + color: #181922; font: 63 11pt "Open Sans"; /*font: 11pt "JMH Cthulhumbus";*/ background: transparent; - - } QCheckBox::indicator { min-height: 20px; min-width: 20px; -border-image: url(:/images/controls/checkbox_unchecked.png) 0 0 0 0 stretch stretch; +border-image: url(:/images/controls/check_off.png) 0 0 0 0 stretch stretch; } QCheckBox::indicator:unchecked { -border-image: url(:/images/controls/checkbox_unchecked.png) 0 0 0 0 stretch stretch; -} -QCheckBox::indicator:unchecked:hover { -border-image: url(:/images/controls/checkbox_hover.png); +border-image: url(:/images/controls/check_off.png) 0 0 0 0 stretch stretch; } QCheckBox::indicator:checked { -border-image: url(:/images/controls/checkbox_checked.png); +border-image: url(:/images/controls/check_on.png); } @@ -259,7 +254,7 @@ QPushButton:hover { - 2 + 0 @@ -383,6 +378,10 @@ line-height: 21px; background: #100A44; border-radius: 4px; } + +QPushButton:hover { +background: #211966; +} @@ -634,7 +633,9 @@ line-height: 21px; background: #100A44; border-radius: 4px; } - +QPushButton:hover { +background: #211966; +} Connect @@ -952,6 +953,10 @@ line-height: 21px; QPushButton:!enabled { background: #484952; +} + +QPushButton:hover { +background: #282932; } @@ -1119,9 +1124,9 @@ color: #181922; 0 - 300 + 290 381 - 51 + 61 @@ -1243,10 +1248,10 @@ QPushButton:hover { - 19 + 20 50 - 341 - 41 + 340 + 40 @@ -1255,11 +1260,8 @@ font-style: normal; font-weight: bold; font-size: 20px; line-height: 25px; - -/* or 125% */ - -/* black */ -color: #181922; +color: #100A44; + These sites will be opened using VPN @@ -1338,10 +1340,15 @@ border: 1px solid #A7A7A7; PointingHandCursor - background: #100A44; + QPushButton { +background: #100A44; border-radius: 4px; font-size: 24px; -color: white +color: white +} +QPushButton:hover { +background: #211966; +} + @@ -1434,7 +1441,7 @@ QPushButton:hover { 10 40 360 - 1 + 10 @@ -1448,7 +1455,7 @@ QPushButton:hover { 30 - 60 + 180 330 30 @@ -1456,6 +1463,9 @@ QPushButton:hover { PointingHandCursor + + Reinstall server, clear server + font-family: Lato; font-style: normal; @@ -1474,16 +1484,16 @@ background-repeat: no-repeat; background-position: left center; - Server settings + Server management 10 - 110 + 160 360 - 1 + 10 @@ -1500,7 +1510,7 @@ background-repeat: no-repeat; 30 - 130 + 240 330 30 @@ -1533,9 +1543,9 @@ background-repeat: no-repeat; 10 - 180 + 220 360 - 1 + 10 @@ -1551,7 +1561,7 @@ background-repeat: no-repeat; 10 620 360 - 1 + 10 @@ -1568,7 +1578,7 @@ background-repeat: no-repeat; 30 - 570 + 580 330 30 @@ -1600,9 +1610,9 @@ background-repeat: no-repeat; 10 - 550 + 560 360 - 1 + 10 @@ -1612,6 +1622,463 @@ background-repeat: no-repeat; + + + + 30 + 60 + 330 + 30 + + + + PointingHandCursor + + + Auto start, Auto connect + + + font-family: Lato; +font-style: normal; +font-weight: bold; +font-size: 20px; +line-height: 25px; +Text-align:left; +padding-left: 30px; + + +/* black */ +color: #100A44; + +background-image: url(:/images/settings.png); +background-repeat: no-repeat; + background-position: left center; + + + App settings + + + + + + 10 + 280 + 360 + 10 + + + + image: url(:/images/line.png); + + + + + + + + + 10 + 100 + 360 + 10 + + + + image: url(:/images/line.png); + + + + + + + + + 30 + 120 + 330 + 30 + + + + PointingHandCursor + + + Dns, Kill Switch + + + font-family: Lato; +font-style: normal; +font-weight: bold; +font-size: 20px; +line-height: 25px; +Text-align:left; +padding-left: 30px; + + +/* black */ +color: #100A44; + +background-image: url(:/images/settings.png); +background-repeat: no-repeat; + background-position: left center; + + + Network settings + + + + + + + + 10 + 10 + 26 + 20 + + + + PointingHandCursor + + + QPushButton { + image: url(:/images/arrow_right.png); + image-position: left; + text-align: left; + /*font: 17pt "Ancient";*/ + + padding: 1px; + image: url(:/images/arrow_left.png); +} +QPushButton:hover { + padding: 0px; +} + + + + + + + + + + + 110 + 590 + 150 + 22 + + + + image: url(:/images/AmneziaVPN.png); + + + + + + + + + 30 + 100 + 211 + 31 + + + + Auto start + + + + + + 20 + 50 + 340 + 40 + + + + font-family: Lato; +font-style: normal; +font-weight: bold; +font-size: 20px; +line-height: 25px; +color: #100A44; + + + + Application Settings + + + Qt::AlignCenter + + + + + + 30 + 140 + 211 + 31 + + + + Auto connect + + + + + + 30 + 220 + 321 + 41 + + + + PointingHandCursor + + + QPushButton { +color:rgb(212, 212, 212); +border-radius: 4px; + +font-family: Lato; +font-style: normal; +font-weight: normal; +font-size: 16px; +line-height: 21px; + +background: #100A44; +border-radius: 4px; +} + +QPushButton:hover { +background: #211966; +} + + + Check for updates + + + + + + + + 20 + 20 + 26 + 20 + + + + PointingHandCursor + + + QPushButton { + image: url(:/images/arrow_right.png); + image-position: left; + text-align: left; + /*font: 17pt "Ancient";*/ + + padding: 1px; + image: url(:/images/arrow_left.png); +} +QPushButton:hover { + padding: 0px; +} + + + + + + + + + + + 120 + 600 + 150 + 22 + + + + image: url(:/images/AmneziaVPN.png); + + + + + + + + + 40 + 120 + 271 + 40 + + + + background: #F4F4F4; + +/* grey */ +border: 1px solid #A7A7A7; +color: #333333; + + + + + + + + + 20 + 50 + 340 + 40 + + + + font-family: Lato; +font-style: normal; +font-weight: bold; +font-size: 20px; +line-height: 25px; +color: #100A44; + + + + DNS Servers + + + Qt::AlignCenter + + + + + + 40 + 200 + 271 + 40 + + + + background: #F4F4F4; + +/* grey */ +border: 1px solid #A7A7A7; +color: #333333; + + + + + + + + true + + + + 320 + 130 + 18 + 18 + + + + PointingHandCursor + + + Reset to default value + + + QPushButton { +image: url(:/images/reload.png); +padding:1px; +} +QPushButton:hover { +padding:0px; +} + + + + + + + + + true + + + + 320 + 210 + 18 + 18 + + + + PointingHandCursor + + + Reset to default value + + + QPushButton { +image: url(:/images/reload.png); +padding:1px; +} +QPushButton:hover { +padding:0px; +} + + + + + + + + + true + + + + 40 + 95 + 291 + 21 + + + + Primary DNS server + + + true + + + + + true + + + + 40 + 175 + 291 + 21 + + + + Secondray DNS server + + + true + + @@ -1633,31 +2100,6 @@ background-repeat: no-repeat; true - - - - 40 - 100 - 171 - 21 - - - - font-family: Lato; -font-style: normal; -font-weight: normal; -font-size: 16px; -line-height: 150%; - -/* or 24px */ - -/* text */ -color: #333333; - - - You connected to - - @@ -1684,7 +2126,9 @@ line-height: 21px; background: #100A44; border-radius: 4px; } - +QPushButton:hover { +background: #211966; +} Reinstall Amnezia server @@ -1725,17 +2169,17 @@ QPushButton:hover { - 10 + 20 40 - 361 - 71 + 340 + 40 font-family: Lato; font-style: normal; font-weight: bold; -font-size: 24px; +font-size: 20px; line-height: 25px; color: #100A44; @@ -1836,7 +2280,9 @@ line-height: 21px; background: #100A44; border-radius: 4px; } - +QPushButton:hover { +background: #211966; +} Clear server from Amnezia software @@ -1868,7 +2314,9 @@ line-height: 21px; background: #100A44; border-radius: 4px; } - +QPushButton:hover { +background: #211966; +} Forget this server @@ -1877,9 +2325,9 @@ border-radius: 4px; - 40 - 130 - 321 + 20 + 80 + 341 41 @@ -1893,9 +2341,11 @@ color: #333333; root@yourserver.org + + Qt::AlignCenter + label_server_settings_wait_info - label_13 pushButton_back_from_server_settings label_16 progressBar_server_settings_reinstall @@ -1949,8 +2399,8 @@ QPushButton:hover { 20 40 - 341 - 41 + 340 + 40 @@ -1959,17 +2409,14 @@ font-style: normal; font-weight: bold; font-size: 20px; line-height: 25px; - -/* or 125% */ - -/* black */ -color: #181922; +color: #100A44; + Connection string - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + Qt::AlignCenter true @@ -2049,7 +2496,9 @@ font-size: 16px; line-height: 21px; } - +QPushButton:hover { +background: #282932; +} Copy @@ -2065,21 +2514,18 @@ line-height: 21px; - - -font-family: Lato; + font-family: Lato; font-style: normal; font-weight: normal; font-size: 16px; line-height: 150%; -/* or 24px */ -/* grey */ -color: #A7A7A7; +color: #181922; - Anyone who logs in with this code will have the same rights to use the VPN as you. To create a new code, change your login and / or password for connection in your server settings. + Anyone who logs in with this code will have the same rights to use the VPN as you. This code includes your server credentials! +Provide this code only to TRUSTED users. Qt::AlignJustify|Qt::AlignVCenter diff --git a/client/ui/qautostart.cpp b/client/ui/qautostart.cpp new file mode 100644 index 00000000..fa93bb77 --- /dev/null +++ b/client/ui/qautostart.cpp @@ -0,0 +1,154 @@ +// The MIT License (MIT) +// +// Copyright (C) 2016 Mostafa Sedaghat Joo (mostafa.sedaghat@gmail.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include "qautostart.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined (Q_OS_WIN) +#define REG_KEY "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" + +bool Autostart::isAutostart() { + QSettings settings(REG_KEY, QSettings::NativeFormat); + + if (settings.value(appName()).isNull()) { + return false; + } + + return true; +} + +void Autostart::setAutostart(bool autostart) { + QSettings settings(REG_KEY, QSettings::NativeFormat); + + if (autostart) { + settings.setValue(appName() , appPath().replace('/','\\')); + } else { + settings.remove(appName()); + } +} + +QString Autostart::appPath() { + return QCoreApplication::applicationFilePath() + " --autostart"; +} + +#elif defined (Q_OS_MAC) + +bool Autostart::isAutostart() { + QProcess process; + process.start("osascript", { + "-e tell application \"System Events\" to get the path of every login item" + }); + process.waitForFinished(3000); + const auto output = QString::fromLocal8Bit(process.readAllStandardOutput()); + return output.contains(appPath()); +} + +void Autostart::setAutostart(bool autostart) { + // Remove any existing login entry for this app first, in case there was one + // from a previous installation, that may be under a different launch path. + { + QProcess::execute("osascript", { + "-e tell application \"System Events\" to delete every login item whose name is \"" + appName() + "\"" + }); + } + + // Now install the login item, if needed. + if ( autostart ) + { + QProcess::execute("osascript", { + "-e tell application \"System Events\" to make login item at end with properties {path:\"" + appPath() + "\", hidden:true, name: \"" + appName() + "\"}" + }); + } +} + +QString Autostart::appPath() { + QDir appDir = QDir(QCoreApplication::applicationDirPath()); + appDir.cdUp(); + appDir.cdUp(); + QString absolutePath = appDir.absolutePath(); + + return absolutePath; +} + +#elif defined (Q_OS_LINUX) +bool Autostart::isAutostart() { + QFileInfo check_file(QDir::homePath() + "/.config/autostart/" + appName() +".desktop"); + + if (check_file.exists() && check_file.isFile()) { + return true; + } + + return false; +} + +void Autostart::setAutostart(bool autostart) { + QString path = QDir::homePath() + "/.config/autostart/"; + QString name = appName() +".desktop"; + QFile file(path+name); + + file.remove(); + + if(autostart) { + QDir dir(path); + if(!dir.exists()) { + dir.mkpath(path); + } + + if (file.open(QIODevice::ReadWrite)) { + QTextStream stream(&file); + stream << "[Desktop Entry]" << endl; + stream << "Exec=" << appPath() << endl; + stream << "Type=Application" << endl; + } + } +} + +QString Autostart::appPath() { + return QCoreApplication::applicationFilePath() + " --autostart"; +} + +#else + +bool Autostart::isAutostart() { + return false; +} + +void Autostart::setAutostart(bool autostart) { + Q_UNUSED(autostart); +} + +QString Autostart::appPath() { + return QString(); +} +#endif + +QString Autostart::appName() { + return QCoreApplication::applicationName(); +} diff --git a/client/ui/qautostart.h b/client/ui/qautostart.h new file mode 100644 index 00000000..eef7f846 --- /dev/null +++ b/client/ui/qautostart.h @@ -0,0 +1,39 @@ +// The MIT License (MIT) +// +// Copyright (C) 2016 Mostafa Sedaghat Joo (mostafa.sedaghat@gmail.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#ifndef AUTOSTART_H +#define AUTOSTART_H + +#include + +class Autostart +{ +public: + static bool isAutostart(); + static void setAutostart(bool autostart); + +protected: + static QString appPath(); + static QString appName(); + }; + +#endif // AUTOSTART_H diff --git a/client/vpnconnection.cpp b/client/vpnconnection.cpp index ba1302b0..68796937 100644 --- a/client/vpnconnection.cpp +++ b/client/vpnconnection.cpp @@ -49,7 +49,7 @@ void VpnConnection::onConnectionStateChanged(VpnProtocol::ConnectionState state) IpcClient::Interface()->routeAddList(m_vpnProtocol->vpnGateway(), black_custom); } } - else if (state == VpnProtocol::ConnectionState::Error || state == VpnProtocol::ConnectionState::Disconnected) { + else if (state == VpnProtocol::ConnectionState::Error) { IpcClient::Interface()->flushDns(); if (m_settings.customRouting()) { @@ -162,8 +162,11 @@ void VpnConnection::disconnectFromVpn() { qDebug() << "Disconnect from VPN"; -// m_vpnProtocol->communicator()->sendMessage(Message(Message::State::ClearSavedRoutesRequest, QStringList())); -// m_vpnProtocol->communicator()->sendMessage(Message(Message::State::FlushDnsRequest, QStringList())); + IpcClient::Interface()->flushDns(); + + if (m_settings.customRouting()) { + IpcClient::Interface()->clearSavedRoutes(); + } if (!m_vpnProtocol.data()) { return; diff --git a/deploy/windows-env.bat b/deploy/windows-env.bat index 349bd868..fc14b825 100644 --- a/deploy/windows-env.bat +++ b/deploy/windows-env.bat @@ -1 +1 @@ -"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" +"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat"