From c2f6c7d939035940fd72a176abe8e81db6ee70aa Mon Sep 17 00:00:00 2001 From: pokamest Date: Thu, 18 Mar 2021 22:13:05 +0300 Subject: [PATCH] route delete fixed (Windows) --- client/ui/mainwindow.cpp | 9 ++++++++- client/vpnconnection.cpp | 4 +++- ipc/ipcinterface.rep | 2 +- ipc/ipcserver.cpp | 4 ++-- ipc/ipcserver.h | 2 +- service/server/router.cpp | 4 ++-- service/server/router.h | 2 +- service/server/router_mac.cpp | 3 ++- service/server/router_win.cpp | 7 +++---- service/server/router_win.h | 2 +- 10 files changed, 24 insertions(+), 15 deletions(-) diff --git a/client/ui/mainwindow.cpp b/client/ui/mainwindow.cpp index c928b178..ce7cbe89 100644 --- a/client/ui/mainwindow.cpp +++ b/client/ui/mainwindow.cpp @@ -298,6 +298,13 @@ void MainWindow::onPushButtonNewServerConnectWithNewData(bool) serverCredentials.userName = ui->lineEdit_new_server_login->text(); if (ui->pushButton_new_server_connect_key->isChecked()){ QString key = ui->textEdit_new_server_ssh_key->toPlainText(); + if (key.startsWith("ssh-rsa")) { + QMessageBox::warning(this, APPLICATION_NAME, + tr("It's public key. Private key required")); + + return; + } + if (key.contains("OPENSSH") && key.contains("BEGIN") && key.contains("PRIVATE KEY")) { key = OpenVpnConfigurator::convertOpenSShKey(key); } @@ -833,7 +840,7 @@ void MainWindow::onPushButtonDeleteCustomSiteClicked(const QString &siteToDelete updateSettings(); if (m_vpnConnection->connectionState() == VpnProtocol::ConnectionState::Connected) { - IpcClient::Interface()->routeDelete(ipToDelete); + IpcClient::Interface()->routeDelete(ipToDelete, ""); IpcClient::Interface()->flushDns(); } } diff --git a/client/vpnconnection.cpp b/client/vpnconnection.cpp index 37fae151..1bfb8b42 100644 --- a/client/vpnconnection.cpp +++ b/client/vpnconnection.cpp @@ -40,11 +40,13 @@ void VpnConnection::onConnectionStateChanged(VpnProtocol::ConnectionState state) IpcClient::Interface()->flushDns(); if (m_settings.customRouting()) { + IpcClient::Interface()->routeDelete("0.0.0.0", m_vpnProtocol->vpnGateway()); + IpcClient::Interface()->routeAddList(m_vpnProtocol->vpnGateway(), QStringList() << m_settings.primaryDns() << m_settings.secondaryDns()); const QStringList &black_custom = m_settings.customIps(); - qDebug() << "onConnect :: adding custom black routes, count:" << black_custom.size(); + qDebug() << "VpnConnection::onConnectionStateChanged :: adding custom routes, count:" << black_custom.size(); IpcClient::Interface()->routeAddList(m_vpnProtocol->vpnGateway(), black_custom); } diff --git a/ipc/ipcinterface.rep b/ipc/ipcinterface.rep index 6c73bf97..80293961 100644 --- a/ipc/ipcinterface.rep +++ b/ipc/ipcinterface.rep @@ -10,7 +10,7 @@ class IpcInterface SLOT( bool routeAdd(const QString &ip, const QString &gw, const QString &mask) ); SLOT( int routeAddList(const QString &gw, const QStringList &ips) ); SLOT( bool clearSavedRoutes() ); - SLOT( bool routeDelete(const QString &ip) ); + SLOT( bool routeDelete(const QString &ip, const QString &gw) ); SLOT( void flushDns() ); SLOT( bool checkAndInstallDriver() ); diff --git a/ipc/ipcserver.cpp b/ipc/ipcserver.cpp index d366d6b7..4ba546a7 100644 --- a/ipc/ipcserver.cpp +++ b/ipc/ipcserver.cpp @@ -68,9 +68,9 @@ bool IpcServer::clearSavedRoutes() return Router::clearSavedRoutes(); } -bool IpcServer::routeDelete(const QString &ip) +bool IpcServer::routeDelete(const QString &ip, const QString &gw) { - return Router::routeDelete(ip); + return Router::routeDelete(ip, gw); } void IpcServer::flushDns() diff --git a/ipc/ipcserver.h b/ipc/ipcserver.h index ae3142cd..9978bde3 100644 --- a/ipc/ipcserver.h +++ b/ipc/ipcserver.h @@ -18,7 +18,7 @@ public: virtual bool routeAdd(const QString &ip, const QString &gw, const QString &mask = QString()) override; virtual int routeAddList(const QString &gw, const QStringList &ips) override; virtual bool clearSavedRoutes() override; - virtual bool routeDelete(const QString &ip) override; + virtual bool routeDelete(const QString &ip, const QString &gw) override; virtual void flushDns() override; virtual bool checkAndInstallDriver() override; virtual QStringList getTapList() override; diff --git a/service/server/router.cpp b/service/server/router.cpp index a046db87..bcd99014 100644 --- a/service/server/router.cpp +++ b/service/server/router.cpp @@ -34,10 +34,10 @@ bool Router::clearSavedRoutes() #endif } -bool Router::routeDelete(const QString &ip) +bool Router::routeDelete(const QString &ip, const QString &gw) { #ifdef Q_OS_WIN - return RouterWin::Instance().routeDelete(ip); + return RouterWin::Instance().routeDelete(ip, gw); #elif defined (Q_OS_MAC) return RouterMac::Instance().routeDelete(ip); #endif diff --git a/service/server/router.h b/service/server/router.h index dcc32faa..5ad49be2 100644 --- a/service/server/router.h +++ b/service/server/router.h @@ -18,7 +18,7 @@ public: static bool routeAdd(const QString &ip, const QString &gw, QString mask = QString()); static int routeAddList(const QString &gw, const QStringList &ips); static bool clearSavedRoutes(); - static bool routeDelete(const QString &ip); + static bool routeDelete(const QString &ip, const QString &gw); static void flushDns(); }; diff --git a/service/server/router_mac.cpp b/service/server/router_mac.cpp index d6c67455..097311e6 100644 --- a/service/server/router_mac.cpp +++ b/service/server/router_mac.cpp @@ -55,7 +55,8 @@ bool RouterMac::routeDelete(const QString &ip) p.waitForFinished(); qDebug().noquote() << "OUTPUT routeDelete: " + p.readAll(); - return p.exitCode() == 0;} + return p.exitCode() == 0; +} void RouterMac::flushDns() { diff --git a/service/server/router_win.cpp b/service/server/router_win.cpp index 9e0c4477..e09ffd25 100644 --- a/service/server/router_win.cpp +++ b/service/server/router_win.cpp @@ -274,14 +274,13 @@ bool RouterWin::clearSavedRoutes() return true; } -bool RouterWin::routeDelete(const QString &ip) +bool RouterWin::routeDelete(const QString &ip, const QString &gw) { - qDebug().noquote() << QString("ROUTE DELETE, IP: %1").arg(ip); + qDebug().noquote() << QString("ROUTE DELETE, IP: %1 GW %2").arg(ip).arg(gw); QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); - QString command = QString("route delete %1") - .arg(ip); + QString command = QString("route delete %1 %2").arg(ip).arg(gw); p.start(command); p.waitForFinished(); diff --git a/service/server/router_win.h b/service/server/router_win.h index 91765d4b..e9de7be1 100644 --- a/service/server/router_win.h +++ b/service/server/router_win.h @@ -41,7 +41,7 @@ public: bool routeAdd(const QString &ip, const QString &gw, QString mask = QString()); int routeAddList(const QString &gw, const QStringList &ips); bool clearSavedRoutes(); - bool routeDelete(const QString &ip); + bool routeDelete(const QString &ip, const QString &gw); void flushDns(); public slots: