diff --git a/CMakeLists.txt b/CMakeLists.txt index 16195e6..2d73f80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,6 @@ enable_language("RC") add_executable(ZJUConnectForWindows WIN32 main.cpp mainwindow.cpp - l2tpmode.cpp - webloginmode.cpp zjuconnectmode.cpp zjuconnectcontroller/zjuconnectcontroller.cpp portforwardingwindow/portforwardingwindow.cpp diff --git a/l2tpmode.cpp b/l2tpmode.cpp deleted file mode 100644 index ac8260e..0000000 --- a/l2tpmode.cpp +++ /dev/null @@ -1,263 +0,0 @@ -#include -#include - -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "utils/utils.h" - -void MainWindow::setModeToL2tp() -{ - mode = "有线网 L2TP"; - - clearLog(); - - networkDetector->start(); - - ui->interfaceLabel->hide(); - ui->refreshInterfaceButton->hide(); - ui->interfaceComboBox->hide(); - ui->tunCheckBox->hide(); - - // 清除系统代理 - if (isSystemProxySet) - { - Utils::clearSystemProxy(); - isSystemProxySet = false; - addLog("已清除系统代理设置"); - } - - disconnect(ui->pushButton1, &QPushButton::clicked, nullptr, nullptr); - - if (!isL2tpLinked) - { - ui->pushButton1->setText("连接 L2TP"); - } - else - { - ui->pushButton1->setText("断开 L2TP"); - } - - ui->pushButton1->setEnabled(false); - - disconnect(ui->pushButton2, &QPushButton::clicked, nullptr, nullptr); - ui->pushButton2->hide(); - - addLog("工作模式设置为:有线网 L2TP"); - - // 检查是否存在 VPN - disconnect(processForL2tp, &QProcess::finished, nullptr, nullptr); - connect(processForL2tp, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString(processForL2tp->readAllStandardOutput()).trimmed(); - if (output.isEmpty()) - { - addLog("警告:在系统中未发现 VPN 配置!请使用高级 - 创建 L2TP VPN 创建 VPN"); - } - else - { - QString line; - QTextStream stream(&output); - - bool isVpnInSettingsExist = false; - - while (!stream.atEnd()) - { - line = stream.readLine(); - if (line.contains("Name") && line.contains(settings->value("L2TP/Name", "ZJUVPN").toString())) - { - auto vpnName = line.split(":")[1].trimmed(); - if (vpnName == settings->value("L2TP/Name", "ZJUVPN").toString()) - { - isVpnInSettingsExist = true; - break; - } - } - } - - if (!isVpnInSettingsExist) - { - addLog( - "警告:在系统中未发现名称为 " - + settings->value("L2TP/Name", "ZJUVPN").toString() - + " 的 VPN,请在设置中修改 VPN 名称" - ); - } - } - - ui->pushButton1->setEnabled(true); - - emit SetModeFinished(); - }); - - processForL2tp->start("powershell", QStringList() << "-command" << "Get-VpnConnection"); - - connect(ui->pushButton1, &QPushButton::clicked, - [&]() - { - ui->pushButton1->setEnabled(false); - ui->modeComboBox->setEnabled(false); - ui->createL2tpAction->setEnabled(false); - - QString l2tpName = settings->value("L2TP/Name", "ZJUVPN").toString(); - if (l2tpName.isEmpty()) - { - QMessageBox::critical(this, "错误", "L2TP VPN 名称不能为空"); - return; - } - - if (!isL2tpLinked) - { - if (settings->value("Common/Username", "").toString().isEmpty()) - { - QMessageBox::critical(this, "错误", "用户名不能为空"); - return; - } - - if (QByteArray::fromBase64(settings->value("Common/Password", "").toString().toUtf8()).isEmpty()) - { - QMessageBox::critical(this, "错误", "密码不能为空"); - return; - } - - disconnect(processForL2tp, &QProcess::finished, nullptr, nullptr); - connect(processForL2tp, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString(processForL2tp->readAllStandardOutput()).trimmed(); - if (output.contains("命令已完成") || output.contains("Command completed successfully")) - { - isL2tpLinked = true; - ui->pushButton1->setText("断开 L2TP"); - addLog("连接成功!"); - showNotification("有线网 L2TP", "连接成功!"); - - if (settings->value("L2TP/AutoReconnect", false).toBool()) - { - l2tpCheckTimer = new QTimer(this); - connect(l2tpCheckTimer, &QTimer::timeout, this, [&]() - { - disconnect(processForL2tpCheck, &QProcess::finished, nullptr, nullptr); - connect(processForL2tpCheck, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString( - processForL2tpCheck->readAllStandardOutput() - ).trimmed(); - if (output.contains("(0%") && !output.contains("unreachable") && - !output.contains("无法")) - { - addLog("自动检测结果:L2TP VPN 连接正常"); - } - else - { - addLog("自动检测结果:L2TP VPN 连接异常,正在重连..."); - showNotification( - "有线网 L2TP", - "自动检测结果:L2TP VPN 连接异常,正在重连...", - QSystemTrayIcon::MessageIcon::Warning - ); - isL2tpReconnecting = true; - ui->pushButton1->click(); - } - }); - - processForL2tpCheck->start( - "ping", - QStringList() - << "-n" - << "1" - << settings->value("L2TP/CheckIp", "223.5.5.5").toString() - ); - }); - - l2tpCheckTimer->start(settings->value("L2TP/CheckTime", 600).toInt() * 1000); - } - } - else - { - addLog("连接失败!"); - - if (output.contains("623")) - { - output = "请检查 VPN 名称是否设置正确\n" - "如果你没有创建过 VPN,请使用高级-创建 L2TP VPN\n" - "如果你创建过 VPN,请打开系统设置-网络-VPN,将 VPN 名称填写在本软件设置-L2TP 中\n" - "详细信息为:\n" + output; - } - else if (output.contains("691")) - { - output = "请检查设置中的网络账号和密码是否设置正确!\n详细信息为:\n" + output; - } - else if (output.contains("789")) - { - output = "连接失败!这个问题通常是注册表造成的\n" - "建议删除现有 VPN,然后使用高级-创建 L2TP VPN\n" - "如果您刚刚使用本程序创建了 VPN,请重启电脑\n详细信息为:\n" + output; - } - else if (output.contains("868")) - { - output = "请检查系统 DNS 是否设置正确!\n详细信息为:\n" + output; - } - - addLog(output); - ui->modeComboBox->setEnabled(true); - ui->createL2tpAction->setEnabled(true); - QMessageBox::critical(this, "错误", output); - } - - ui->pushButton1->setEnabled(true); - }); - - processForL2tp->start( - "rasdial", - QStringList() - << l2tpName - << settings->value("Common/Username").toString() - << QByteArray::fromBase64(settings->value("Common/Password").toString().toUtf8()) - ); - - addLog("正在连接 L2TP VPN: " + l2tpName); - } - else - { - if (l2tpCheckTimer != nullptr) - { - disconnect(processForL2tpCheck, &QProcess::finished, nullptr, nullptr); - l2tpCheckTimer->stop(); - delete l2tpCheckTimer; - l2tpCheckTimer = nullptr; - } - - disconnect(processForL2tp, &QProcess::finished, nullptr, nullptr); - connect(processForL2tp, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString(processForL2tp->readAllStandardOutput()); - if (output.contains("命令已完成") || output.contains("Command completed successfully")) - { - isL2tpLinked = false; - - ui->pushButton1->setText("连接 L2TP"); - addLog("断开成功!"); - } - else - { - addLog("断开失败!"); - addLog(output); - QMessageBox::critical(this, "错误", output); - } - - ui->pushButton1->setEnabled(true); - ui->modeComboBox->setEnabled(true); - ui->createL2tpAction->setEnabled(true); - - if (isL2tpReconnecting) - { - isL2tpReconnecting = false; - ui->pushButton1->click(); - } - }); - - processForL2tp->start("rasdial", QStringList() << l2tpName << "/DISCONNECT"); - - addLog("正在断开 L2TP VPN: " + l2tpName); - } - }); -} diff --git a/main.cpp b/main.cpp index 45ad936..9a92f12 100644 --- a/main.cpp +++ b/main.cpp @@ -7,7 +7,7 @@ int main(int argc, char *argv[]) { SingleApplication app(argc, argv); - QApplication::setApplicationName("ZJU Connect for Windows"); + QApplication::setApplicationName("HITsz Connect for Windows"); QApplication::setApplicationVersion("1.1.2"); MainWindow mainWindow; diff --git a/mainwindow.cpp b/mainwindow.cpp index 03bb857..08e3bdc 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -109,260 +109,6 @@ MainWindow::MainWindow(QWidget *parent) : settingWindow->show(); }); - // 高级-创建 L2TP VPN - connect(ui->createL2tpAction, &QAction::triggered, - [&]() - { - QMessageBox messageBox(this); - messageBox.setWindowTitle("创建 L2TP VPN"); - messageBox.setText( - "是否创建名称为 " - + settings->value("L2TP/Name", "ZJUVPN").toString() - + " 的 L2TP VPN?\n要创建的 VPN 名称可在设置中更改\n在创建过程中会请求管理员权限" - ); - - messageBox.addButton(QMessageBox::Yes)->setText("是"); - messageBox.addButton(QMessageBox::No)->setText("否"); - messageBox.setDefaultButton(QMessageBox::Yes); - - if (messageBox.exec() == QMessageBox::Yes) - { - disconnect(process, &QProcess::finished, nullptr, nullptr); - connect(process, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString(process->readAllStandardError()); - if (!output.contains("Add-VpnConnection")) - { - HINSTANCE hInstance = ShellExecute( - nullptr, - L"runas", - L"cmd.exe", - L"/c reg add \"HKLM\\System\\CurrentControlSet\\Services\\Rasman\\Parameters\" /v ProhibitIpSec /t REG_DWORD /d 0x1 /f", - nullptr, - SW_HIDE - ); - - if (hInstance > (HINSTANCE) 32) - { - addLog("创建 L2TP VPN 成功!"); - - QMessageBox::information( - this, - "提示", - "创建成功!\n如果这是您第一次创建 L2TP VPN,请重启电脑" - ); - } - else - { - addLog("创建 L2TP VPN 成功,但添加注册表项失败!"); - - QMessageBox::critical( - this, - "错误", - "创建 VPN 成功,但添加注册表项失败!\n这可能是您拒绝了权限请求导致的\n请打开系统设置-网络-VPN,删除存在的 VPN 后重试" - ); - } - } - else - { - addLog("创建 L2TP VPN 失败!"); - addLog(output); - QMessageBox::critical( - this, - "错误", - "创建失败!请检查是否已存在同名 VPN。详细信息:\n" + output - ); - } - }); - - process->start( - "powershell", - QStringList() - << "-command" - << "Add-VpnConnection" - << "-Name" - << '"' + settings->value("L2TP/Name", "ZJUVPN").toString() + '"' - << "-ServerAddress" - << "lns.zju.edu.cn" - << "-TunnelType" - << "L2tp" - << "-EncryptionLevel" - << "Optional" - << "-AuthenticationMethod" - << "('Chap','MSChapv2')" - << "-RememberCredential" - ); - } - }); - - // 高级-静态路由-设置静态路由 - connect(ui->setRouteAction, &QAction::triggered, - [&]() - { - connect(networkDetector, &NetworkDetector::finished, this, - [&](const NetworkDetectResult &result) - { - disconnect(networkDetector, &NetworkDetector::finished, this, nullptr); - networkDetectResult = result; - - if (!networkDetectResult.isZjuLan) - { - QMessageBox::critical( - this, "错误", - "未检测到 ZJU 有线网,无法设置静态路由!\n如果你正在使用路由器,请在路由器端设置静态路由" - ); - return; - } - - QMessageBox messageBox(this); - messageBox.setWindowTitle("设置静态路由"); - messageBox.setText( - "在使用 L2TP 时,设置静态路由有助于从校网访问 RDP、NHD 等服务\n是否设置网关为 " - + networkDetectResult.zjuLanGateway - + " 的静态路由?\n在设置过程中会请求管理员权限" - ); - - messageBox.addButton(QMessageBox::Yes)->setText("是"); - messageBox.addButton(QMessageBox::No)->setText("否"); - messageBox.setDefaultButton(QMessageBox::Yes); - - if (messageBox.exec() == QMessageBox::Yes) - { - QString command = - "/c route -p add 10.0.0.0 mask 255.0.0.0 " - + networkDetectResult.zjuLanGateway - + " metric 1 & " - + "route -p add 210.32.0.0 mask 255.255.240.0 " - + networkDetectResult.zjuLanGateway - + " metric 1 & " - + "route -p add 222.205.0.0 mask 255.255.128.0 " - + networkDetectResult.zjuLanGateway - + " metric 1 & " - + "route -p add 210.32.128.0 mask 255.255.224.0 " - + networkDetectResult.zjuLanGateway - + " metric 1 & " - + "route -p add 210.32.160.0 mask 255.255.248.0 " - + networkDetectResult.zjuLanGateway - + " metric 1 & " - + "route -p add 210.32.168.0 mask 255.255.252.0 " - + networkDetectResult.zjuLanGateway - + " metric 1 & " - + "route -p add 210.32.172.0 mask 255.255.254.0 " - + networkDetectResult.zjuLanGateway - + " metric 1 & " - + "route -p add 210.32.174.0 mask 255.255.255.0 " - + networkDetectResult.zjuLanGateway - + " metric 1 & " - + "route -p add 210.32.176.0 mask 255.255.240.0 " - + networkDetectResult.zjuLanGateway - + " metric 1 & " - + "route -p add 58.196.192.0 mask 255.255.224.0 " - + networkDetectResult.zjuLanGateway - + " metric 1 & " - + "route -p add 58.196.224.0 mask 255.255.240.0 " - + networkDetectResult.zjuLanGateway - + " metric 1"; - - HINSTANCE hInstance = ShellExecute( - nullptr, - L"runas", - L"cmd.exe", - command.toStdWString().c_str(), - nullptr, - SW_HIDE - ); - - if (hInstance > (HINSTANCE) 32) - { - addLog("设置静态路由成功!"); - - QMessageBox successBox(this); - successBox.setWindowTitle("提示"); - successBox.setTextFormat(Qt::RichText); - successBox.setText( - "设置成功!" - "
请打开 http://speedtest.zju.edu.cn 测速" - "
若显示的 IP 地址为 10.x.x.x,说明静态路由已生效!" - ); - successBox.exec(); - } - else - { - addLog("设置静态路由失败!"); - - QMessageBox::critical( - this, - "错误", - "设置失败!\n这可能是您拒绝了权限请求导致的" - ); - } - } - }); - - networkDetector->start(); - }); - - // 高级-静态路由-删除静态路由 - connect(ui->deleteRouteAction, &QAction::triggered, - [&]() - { - QMessageBox messageBox(this); - messageBox.setWindowTitle("删除静态路由"); - messageBox.setText( - "是否删除静态路由?\n在删除过程中会请求管理员权限" - ); - - messageBox.addButton(QMessageBox::Yes)->setText("是"); - messageBox.addButton(QMessageBox::No)->setText("否"); - messageBox.setDefaultButton(QMessageBox::Yes); - - if (messageBox.exec() == QMessageBox::Yes) - { - QString command = - QString("/c route -p delete 10.0.0.0 mask 255.0.0.0 & ") - + "route -p delete 210.32.0.0 mask 255.255.240.0 & " - + "route -p delete 222.205.0.0 mask 255.255.128.0 & " - + "route -p delete 210.32.128.0 mask 255.255.224.0 & " - + "route -p delete 210.32.160.0 mask 255.255.248.0 & " - + "route -p delete 210.32.168.0 mask 255.255.252.0 & " - + "route -p delete 210.32.172.0 mask 255.255.254.0 & " - + "route -p delete 210.32.174.0 mask 255.255.255.0 & " - + "route -p delete 210.32.176.0 mask 255.255.240.0 & " - + "route -p delete 58.196.192.0 mask 255.255.224.0 & " - + "route -p delete 58.196.224.0 mask 255.255.240.0"; - - HINSTANCE hInstance = ShellExecute( - nullptr, - L"runas", - L"cmd.exe", - command.toStdWString().c_str(), - nullptr, - SW_HIDE - ); - - if (hInstance > (HINSTANCE) 32) - { - addLog("删除静态路由成功!"); - - QMessageBox::information( - this, - "提示", - "删除成功!" - ); - } - else - { - addLog("删除静态路由失败!"); - - QMessageBox::critical( - this, - "错误", - "删除失败!\n这可能是您拒绝了权限请求导致的" - ); - } - } - }); - // 帮助-清除系统代理 connect(ui->disableProxyAction, &QAction::triggered, [&]() @@ -392,116 +138,6 @@ MainWindow::MainWindow(QWidget *parent) : addLog("已清除系统代理设置"); }); - // 帮助-网络诊断 - connect(ui->diagnosisAction, &QAction::triggered, - [&]() - { - diagnosisContext = new QObject(this); - connect(networkDetector, &NetworkDetector::finished, diagnosisContext, - [&](const NetworkDetectResult &result) - { - networkDetectResult = result; - - delete diagnosisContext; - - QString resultString = ""; - if (result.isDefaultDnsAvailable) - { - resultString += "dns=true&"; - } - else - { - resultString += "dns=false&"; - } - - if (result.isZjuNet) - { - resultString += "zjunet=true&"; - } - else - { - resultString += "zjunet=false&"; - } - - if (result.isZjuDnsCorrect) - { - resultString += "zjudns=true&"; - } - else - { - resultString += "zjudns=false&"; - } - - if (result.isZjuWlan) - { - resultString += "zjuwlan=true&"; - } - else - { - resultString += "zjuwlan=false&"; - } - - if (result.isZjuWlanSecure) - { - resultString += "zjuwlansecure=true&"; - } - else - { - resultString += "zjuwlansecure=false&"; - } - - if (result.isZjuLan) - { - resultString += "zjulan=true&"; - resultString += "zjulangateway=" + result.zjuLanGateway + "&"; - } - else - { - resultString += "zjulan=false&"; - } - - if (result.isInternetAvailable) - { - resultString += "internet=true&"; - } - else - { - resultString += "internet=false&"; - } - - if (result.isProxyEnabled) - { - resultString += "proxy=true"; - } - else - { - resultString += "proxy=false"; - } - - auto url = "https://diagnosis.myth.cx/query?" + resultString; - auto qrCode = qrGenerator.generateQr(url); - auto *dialog = new QDialog(this); - auto *layout = new QVBoxLayout(); - auto *textLabel = new QLabel(dialog); - textLabel->setWordWrap(true); - textLabel->setText( - "请使用手机扫描下方二维码。如当前电脑有网络,也可点此进行诊断" - ); - textLabel->setTextFormat(Qt::RichText); - textLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); - textLabel->setOpenExternalLinks(true); - auto *imageLabel = new QLabel(dialog); - imageLabel->setAlignment(Qt::AlignCenter); - imageLabel->setPixmap(QPixmap::fromImage(qrCode)); - layout->addWidget(textLabel); - layout->addWidget(imageLabel); - dialog->setLayout(layout); - dialog->setWindowTitle("网络诊断"); - dialog->exec(); - }); - - networkDetector->start(); - }); // 帮助-关于本软件 connect(ui->aboutAction, &QAction::triggered, @@ -520,6 +156,7 @@ MainWindow::MainWindow(QWidget *parent) : ); // 检查更新 + /* QTimer::singleShot(10000, [&]() { QNetworkRequest request(QUrl("https://zjuconnect.myth.cx/version.json")); @@ -529,6 +166,7 @@ MainWindow::MainWindow(QWidget *parent) : ); networkAccessManager->get(request); }); + */ connect(networkAccessManager, &QNetworkAccessManager::finished, [&](QNetworkReply *reply) @@ -543,12 +181,6 @@ MainWindow::MainWindow(QWidget *parent) : if (version != QApplication::applicationVersion()) { - QString text = "有新版本可用:v" + version + - "
更新内容:" + description + - "
点击此处下载"; - - ui->statusLabel->setText(text); - disconnect(trayIcon, &QSystemTrayIcon::messageClicked, nullptr, nullptr); trayIcon->showMessage( "有新版本可用", @@ -570,76 +202,6 @@ MainWindow::MainWindow(QWidget *parent) : } }); - // 网络接口 - connect(ui->refreshInterfaceButton, &QPushButton::clicked, - [&]() - { - auto currentInterfaceName = ui->interfaceComboBox->currentText(); - ui->interfaceComboBox->clear(); - ui->interfaceComboBox->addItem("默认"); - auto interfaces = QNetworkInterface::allInterfaces(); - bool notDefault = false; - for (auto &singleInterface: interfaces) - { - if ((singleInterface.type() != QNetworkInterface::Ethernet - && singleInterface.type() != QNetworkInterface::Wifi) - || !singleInterface.flags().testFlag(QNetworkInterface::IsRunning)) - { - continue; - } - - QString ipv4Address; - auto addresses = singleInterface.addressEntries(); - for (auto &address: addresses) - { - if (address.ip().protocol() == QAbstractSocket::IPv4Protocol) - { - ipv4Address = address.ip().toString(); - break; - } - } - - ui->interfaceComboBox->addItem(singleInterface.humanReadableName(), ipv4Address); - - if (currentInterfaceName == singleInterface.humanReadableName()) - { - notDefault = true; - ui->interfaceComboBox->setCurrentText(singleInterface.humanReadableName()); - } - } - - if (!notDefault) - { - ui->interfaceComboBox->setCurrentText("默认"); - } - }); - - Utils::setWidgetFixedWhenHidden(ui->interfaceLabel); - Utils::setWidgetFixedWhenHidden(ui->refreshInterfaceButton); - Utils::setWidgetFixedWhenHidden(ui->interfaceComboBox); - - ui->interfaceLabel->hide(); - ui->refreshInterfaceButton->hide(); - ui->interfaceComboBox->hide(); - - // 更改工作模式 - connect(ui->modeComboBox, &QComboBox::currentTextChanged, - [&](const QString &text) - { - if (text == "有线网 L2TP") - { - setModeToL2tp(); - } - else if (text == "网页认证登录") - { - setModeToWebLogin(); - } - else if (text == "RVPN") - { - setModeToZjuConnect(); - } - }); - // 网络检测 connect(networkDetector, &NetworkDetector::finished, this, [&](const NetworkDetectResult &result) @@ -657,52 +219,6 @@ MainWindow::MainWindow(QWidget *parent) : resultString += "默认 DNS 可用:否 | "; } - if (result.isZjuNet) - { - resultString += "ZJU 校园网:是 | "; - } - else - { - resultString += "ZJU 校园网:否 | "; - } - - if (result.isZjuDnsCorrect) - { - resultString += "ZJU 内网 DNS 解析:是 | "; - } - else - { - resultString += "ZJU 内网 DNS 解析:否 | "; - } - - if (result.isZjuWlan) - { - resultString += "ZJUWLAN:是 | "; - } - else - { - resultString += "ZJUWLAN:否 | "; - } - - if (result.isZjuWlanSecure) - { - resultString += "ZJUWLAN-Secure:是 | "; - } - else - { - resultString += "ZJUWLAN-Secure:否 | "; - } - - if (result.isZjuLan) - { - resultString += "ZJU 有线网:是 | "; - resultString += "ZJU 有线网网关:" + result.zjuLanGateway + " | "; - } - else - { - resultString += "ZJU 有线网:否 | "; - } - if (result.isInternetAvailable) { resultString += "互联网连接:是 | "; @@ -736,19 +252,8 @@ MainWindow::MainWindow(QWidget *parent) : } }); - auto lastMode = settings->value("Common/LastMode", "RVPN").toString(); - if (lastMode == "有线网 L2TP") - { - ui->modeComboBox->setCurrentText("有线网 L2TP"); - } - else if (lastMode == "网页认证登录") - { - ui->modeComboBox->setCurrentText("网页认证登录"); - } - else - { - setModeToZjuConnect(); - } + + setModeToZjuConnect(); } void MainWindow::closeEvent(QCloseEvent *event) @@ -794,13 +299,6 @@ void MainWindow::upgradeSettings() } } - // Replace old ineffective check ip - if (settings->value("L2TP/CheckIp", "223.5.5.5").toString() == "39.156.66.10") - { - settings->setValue("L2TP/CheckIp", "223.5.5.5"); - settings->sync(); - } - return; } @@ -820,6 +318,7 @@ void MainWindow::upgradeSettings() { settings->setValue("Common/Username", settings->value("EasyConnect/Username")); settings->remove("EasyConnect/Username"); + } if (settings->contains("EasyConnect/Password")) @@ -869,7 +368,6 @@ void MainWindow::cleanUpWhenQuit() { settings->setValue("Common/ConfigVersion", 2); settings->setValue("Common/LastMode", mode); - settings->setValue("WebLogin/LastInterface", ui->interfaceComboBox->currentText()); settings->setValue("ZJUConnect/TunMode", ui->tunCheckBox->isChecked()); settings->sync(); } diff --git a/mainwindow.ui b/mainwindow.ui index caeb67f..f23a55a 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,172 +6,15 @@ 0 0 - 798 - 391 + 619 + 288 - ZJU Connect for Windows + HITsz Connect for Windows - - - - - 0 - 0 - - - - 只有同时连接有线无线时需要设置 - - - 网络接口 - - - - - - - - 0 - 0 - - - - 工作模式 - - - - - - - - 0 - 0 - - - - 刷新网络接口 - - - - - - - - 默认 - - - - - - - - - RVPN - - - - - 网页认证登录 - - - - - 有线网 L2TP - - - - - - - - - 0 - 0 - - - - Version: 1.0 -Windows Version: Windows 11 - - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 17 - - - - 你好呀 - - - ZJU Connect for Windows - - - - - - - true - - - 1000 - - - - - - - - Microsoft YaHei UI - 9 - - - - - - - Qt::RichText - - - Qt::AlignCenter - - - true - - - - - - - - 0 - 0 - - - - 复制日志到剪贴板 - - - 复制日志 - - - @@ -196,22 +39,6 @@ Windows Version: Windows 11 - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - @@ -228,6 +55,94 @@ Windows Version: Windows 11 + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 17 + + + + 你好呀 + + + HITsz Connect for Windows + + + + + + + + 0 + 0 + + + + 复制日志到剪贴板 + + + 复制日志 + + + + + + + + 0 + 0 + + + + Version: 1.0 +Windows Version: Arch Linux + + + + Qt::AlignCenter + + + + + + + true + + + 1000 + + + + + + + 提示:左上角“功能”->“设置”里可以填写账号信息 + + + @@ -235,7 +150,7 @@ Windows Version: Windows 11 0 0 - 798 + 619 22 @@ -254,32 +169,16 @@ Windows Version: Windows 11 帮助 - - 文件 + 功能 - - - 高级 - - - - 静态路由 - - - - - - - - @@ -300,26 +199,6 @@ Windows Version: Windows 11 设置 - - - 创建 L2TP VPN - - - - - 设置静态路由 - - - - - 删除静态路由 - - - - - 网络诊断 - - 清除系统代理 diff --git a/resource/icon.ico b/resource/icon.ico index e0a4ec7..2ee5645 100644 Binary files a/resource/icon.ico and b/resource/icon.ico differ diff --git a/resource/icon.png b/resource/icon.png index e386cb0..a7c77c6 100644 Binary files a/resource/icon.png and b/resource/icon.png differ diff --git a/settingwindow/settingwindow.cpp b/settingwindow/settingwindow.cpp index 17c7b6f..83fe56c 100644 --- a/settingwindow/settingwindow.cpp +++ b/settingwindow/settingwindow.cpp @@ -47,8 +47,9 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) : ui->connectAfterStartComboBox->setCurrentText("否"); } - ui->serverAddressLineEdit->setText(settings->value("ZJUConnect/ServerAddress", "rvpn.zju.edu.cn").toString()); + ui->serverAddressLineEdit->setText(settings->value("ZJUConnect/ServerAddress", "vpn.hitsz.edu.cn").toString()); ui->serverPortSpinBox->setValue(settings->value("ZJUConnect/ServerPort", 443).toInt()); + ui->dnsLineEdit->setText(settings->value("ZJUConnect/DNS", "10.248.98.30").toString()); ui->socks5PortSpinBox->setValue(settings->value("ZJUConnect/Socks5Port", 11080).toInt()); ui->httpPortSpinBox->setValue(settings->value("ZJUConnect/HttpPort", 11081).toInt()); ui->multiLineCheckBox->setChecked(settings->value("ZJUConnect/MultiLine", true).toBool()); @@ -61,40 +62,6 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) : ui->autoSetProxyCheckBox->setChecked(settings->value("ZJUConnect/AutoSetProxy", false).toBool()); ui->routeCheckBox->setChecked(settings->value("ZJUConnect/Route", false).toBool()); - ui->l2tpNameLineEdit->setText(settings->value("L2TP/Name", "ZJUVPN").toString()); - - if (settings->value("L2TP/AutoReconnect", false).toBool()) - { - ui->l2tpAutoCheckComboBox->setCurrentText("是"); - } - else - { - ui->l2tpAutoCheckComboBox->setCurrentText("否"); - } - - ui->l2tpCheckIpLineEdit->setText(settings->value("L2TP/CheckIp", "223.5.5.5").toString()); - ui->l2tpCheckTimeSpinBox->setValue(settings->value("L2TP/CheckTime", 600).toInt()); - - if (settings->value("WebLogin/IntlUrl", false).toBool()) - { - ui->intlUrlComboBox->setCurrentText("是"); - } - else - { - ui->intlUrlComboBox->setCurrentText("否"); - } - - if (settings->value("WebLogin/EnableCustomUrl", false).toBool()) - { - ui->customUrlComboBox->setCurrentText("是"); - } - else - { - ui->customUrlComboBox->setCurrentText("否"); - } - - ui->customUrlLineEdit->setText(settings->value("WebLogin/CustomUrl", "https://net.zju.edu.cn").toString()); - connect(ui->portForwardingPushButton, &QPushButton::clicked, [&]() { @@ -114,33 +81,6 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) : connect(ui->applyPushButton, &QPushButton::clicked, [&]() { - QRegularExpression re("^[A-Za-z]+$"); - QRegularExpressionMatch match = re.match(ui->l2tpNameLineEdit->text()); - if (!match.hasMatch()) - { - ui->tabWidget->setCurrentWidget(ui->l2tpTab); - QMessageBox::warning( - this, - "警告", - "建议 L2TP VPN 名称只包含英文字母,否则可能导致系统代理出错!\n" - "如果您之前自行配置过 VPN,建议修改此处 L2TP VPN 名称,之后在主界面点击高级-创建 L2TP VPN" - ); - } - - if (ui->l2tpCheckIpLineEdit->text().isEmpty() and ui->l2tpAutoCheckComboBox->currentText() == "是") - { - ui->tabWidget->setCurrentWidget(ui->l2tpTab); - QMessageBox::critical(this, "错误", "检测使用的 IP 不能为空!"); - return; - } - - QHostAddress address(ui->l2tpCheckIpLineEdit->text()); - if (QAbstractSocket::IPv4Protocol != address.protocol()) - { - ui->tabWidget->setCurrentWidget(ui->l2tpTab); - QMessageBox::critical(this, "错误", "请填写有效的 IPv4 地址!"); - return; - } settings->setValue("Common/Username", ui->usernameLineEdit->text()); settings->setValue("Common/Password", QString(ui->passwordLineEdit->text().toUtf8().toBase64())); @@ -149,6 +89,7 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) : settings->setValue("ZJUConnect/ServerAddress", ui->serverAddressLineEdit->text()); settings->setValue("ZJUConnect/ServerPort", ui->serverPortSpinBox->value()); + settings->setValue("ZJUConnect/DNS", ui->dnsLineEdit->text()); settings->setValue("ZJUConnect/Socks5Port", ui->socks5PortSpinBox->value()); settings->setValue("ZJUConnect/HttpPort", ui->httpPortSpinBox->value()); settings->setValue("ZJUConnect/MultiLine", ui->multiLineCheckBox->isChecked()); @@ -161,15 +102,6 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) : settings->setValue("ZJUConnect/AutoSetProxy", ui->autoSetProxyCheckBox->isChecked()); settings->setValue("ZJUConnect/Route", ui->routeCheckBox->isChecked()); - settings->setValue("L2TP/Name", ui->l2tpNameLineEdit->text()); - settings->setValue("L2TP/AutoReconnect", ui->l2tpAutoCheckComboBox->currentText() == "是"); - settings->setValue("L2TP/CheckIp", ui->l2tpCheckIpLineEdit->text()); - settings->setValue("L2TP/CheckTime", ui->l2tpCheckTimeSpinBox->value()); - - settings->setValue("WebLogin/IntlUrl", ui->intlUrlComboBox->currentText() == "是"); - settings->setValue("WebLogin/EnableCustomUrl", ui->customUrlComboBox->currentText() == "是"); - settings->setValue("WebLogin/CustomUrl", ui->customUrlLineEdit->text()); - settings->sync(); if (settings->value("Common/AutoStart").toBool()) diff --git a/settingwindow/settingwindow.ui b/settingwindow/settingwindow.ui index 03de76b..58a068a 100644 --- a/settingwindow/settingwindow.ui +++ b/settingwindow/settingwindow.ui @@ -6,8 +6,8 @@ 0 0 - 489 - 317 + 486 + 348 @@ -17,37 +17,17 @@ - + 取消 - - - - Qt::Horizontal - - - - 213 - 20 - - - - - - - - 应用 - - - - + - 0 + 1 @@ -185,234 +165,11 @@ - - - 有线网 L2TP - - - - - - - 9 - - - - 检测时间间隔 (s) - - - - - - - 12 - - - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 9 - - - - L2TP VPN 名称 - - - - - - - - 9 - - - - ZJUVPN - - - - - - - 自动检测互联网连接并重连 - - - - - - - 1 - - - 86400 - - - 600 - - - - - - - 检测使用的 IP - - - - - - - 223.5.5.5 - - - - - - - - 网页认证登录 - - - - - - 是否为海宁校区 - - - - - - - 是否自定义登录 URL - - - - - - - - 9 - - - - https://net.zju.edu.cn - - - - - - - - 9 - - - - 自定义登录 URL - - - - - - - 12 - - - - - - - - - - - - - - - - - 12 - - - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 140 - - - - - - - RVPN + VPN - - - - - 9 - - - - 服务器地址 - - - - - - - - 9 - - - - rvpn.zju.edu.cn - - - @@ -425,6 +182,106 @@ + + + + 调试模式 + + + + + + + 断线自动重连 + + + 自动重连 + + + false + + + + + + + HTTP 代理端口 + + + + + + + + 9 + + + + 65535 + + + 11080 + + + + + + + 自动选择线路 + + + true + + + false + + + false + + + + + + + 65535 + + + 11081 + + + + + + + TUN 模式下有效 + + + 自动设置路由 + + + + + + + 连接服务器后自动设置代理 + + + 自动设置系统代理 + + + + + + + + 9 + + + + SOCKS5 代理端口 + + + @@ -440,51 +297,55 @@ - - + + + + 设置端口转发 + + + + + 9 - SOCKS5 代理端口 + vpn.hitsz.edu.cn - - + + + + 86400 + + + 1 + + + + + + + 代理全部流量 + + + + + 9 - - 65535 - - - 11080 - - - - - - HTTP 代理端口 + 服务器地址 - - - - 65535 - - - 11081 - - - - + @@ -496,83 +357,27 @@ - - - - 86400 + + + + + false + - - 1 + + DNS 服务器 - - - - 自动选择线路 - - - true - - - false - - - false - - - - - - - 代理全部流量 - - - - - - - 断线自动重连 + + + + + false + - 自动重连 - - - false - - - - - - - 连接服务器后自动设置代理 - - - 自动设置系统代理 - - - - - - - 设置端口转发 - - - - - - - 调试模式 - - - - - - - TUN 模式下有效 - - - 自动设置路由 + 10.248.98.30 @@ -580,6 +385,26 @@ + + + + Qt::Horizontal + + + + 213 + 20 + + + + + + + + 应用 + + + diff --git a/utils/utils.cpp b/utils/utils.cpp index f199074..52a97ba 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -70,7 +70,11 @@ void Utils::showAboutMessageBox(QWidget *parent) messageBox.setWindowTitle("关于本软件"); messageBox.setTextFormat(Qt::RichText); QString aboutText = QApplication::applicationName() + " v" + QApplication::applicationVersion() + + "
针对哈工大深圳的修改版 ZJU-Connect-for-Windows" + + "
作者: 尘息" + + "
项目主页: https://github.com/chenx-dust/HITsz-Connect-for-Windows" + "
基于 Qt 编写的 ZJUConnect 图形界面" + + "

ZJU-Connect-for-Windows" + "
作者: Myth" + "
项目主页: https://github.com/Mythologyli/ZJU-Connect-for-Windows" + "

zju-connect" + diff --git a/webloginmode.cpp b/webloginmode.cpp deleted file mode 100644 index 7d12d22..0000000 --- a/webloginmode.cpp +++ /dev/null @@ -1,200 +0,0 @@ -#include -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "utils/utils.h" - -void MainWindow::setModeToWebLogin() -{ - mode = "网页认证登录"; - - clearLog(); - - networkDetector->start(); - - ui->interfaceComboBox->clear(); - ui->interfaceComboBox->addItem("默认"); - ui->interfaceComboBox->setCurrentText("默认"); - auto interfaceName = settings->value("WebLogin/LastInterface", "默认").toString(); - if (interfaceName != "默认") - { - auto ipv4Address = Utils::getIpv4Address(interfaceName); - if (!ipv4Address.isEmpty()) - { - ui->interfaceComboBox->addItem(interfaceName, ipv4Address); - ui->interfaceComboBox->setCurrentText(interfaceName); - } - } - - ui->interfaceComboBox->setCurrentText(settings->value("WebLogin/LastInterface", "默认").toString()); - ui->interfaceLabel->show(); - ui->refreshInterfaceButton->show(); - ui->interfaceComboBox->show(); - ui->tunCheckBox->hide(); - - // 清除系统代理 - if (isSystemProxySet) - { - Utils::clearSystemProxy(); - isSystemProxySet = false; - addLog("已清除系统代理设置"); - } - - disconnect(ui->pushButton1, &QPushButton::clicked, nullptr, nullptr); - ui->pushButton1->setText("登录"); - disconnect(ui->pushButton2, &QPushButton::clicked, nullptr, nullptr); - ui->pushButton2->hide(); - - addLog("工作模式设置为:网页认证登录"); - - connect(ui->pushButton1, &QPushButton::clicked, - [&]() - { - ui->pushButton1->setEnabled(false); - ui->modeComboBox->setEnabled(false); - - if (!isWebLogged) - { - if (settings->value("Common/Username", "").toString().isEmpty()) - { - QMessageBox::critical(this, "错误", "用户名不能为空"); - return; - } - - if (QByteArray::fromBase64(settings->value("Common/Password", "").toString().toUtf8()).isEmpty()) - { - QMessageBox::critical(this, "错误", "密码不能为空"); - return; - } - - disconnect(processForWebLogin, &QProcess::finished, nullptr, nullptr); - connect(processForWebLogin, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString(processForWebLogin->readAllStandardOutput()).trimmed(); - if (output.contains("[Login Successful]") || output.contains("[Already Online]")) - { - isWebLogged = true; - ui->pushButton1->setText("注销"); - addLog("登录成功!"); - showNotification("网页认证登录", "登录成功!"); - } - else - { - addLog("登录失败!"); - - if (output.contains("dhcp")) - { - output = "IP 不在 DHCP 表中!\n" - "这通常表明您正在使用不支持网页认证登录的有线网/ZJUWLAN-Secure\n" - "详细信息为:\n" + output; - } - else if (output.contains("User not found") || output.contains("Password is error")) - { - output = "登录失败!\n" - "请检查设置中的网络账号和密码是否设置正确!\n" - "详细信息为:\n" + output; - } - - addLog(output); - ui->modeComboBox->setEnabled(true); - QMessageBox::critical(this, "错误", output); - } - - ui->pushButton1->setEnabled(true); - }); - - QString ip; - if (ui->interfaceComboBox->currentText() == "默认") - { - ip = "default"; - } - else - { - ip = ui->interfaceComboBox->currentData().toString(); - } - - QString url; - if (settings->value("WebLogin/EnableCustomUrl", false).toBool()) - { - url = settings->value("WebLogin/CustomUrl", "https://net.zju.edu.cn").toString(); - } - else if (settings->value("WebLogin/IntlUrl", false).toBool()) - { - url = "https://zjuwlan.intl.zju.edu.cn"; - } - else - { - url = "https://net.zju.edu.cn"; - } - - processForWebLogin->start( - "weblogin.exe", - QStringList() - << "login" - << "-u" - << settings->value("Common/Username").toString() - << "-p" - << QByteArray::fromBase64(settings->value("Common/Password").toString().toUtf8()) - << "-i" - << ip - << "--url" - << url - ); - - addLog("正在进行网页认证登录,接口:" + ui->interfaceComboBox->currentText()); - } - else - { - disconnect(processForWebLogin, &QProcess::finished, nullptr, nullptr); - connect(processForWebLogin, &QProcess::finished, this, [&]() - { - isWebLogged = false; - - ui->pushButton1->setText("登录"); - addLog("注销成功!"); - - ui->pushButton1->setEnabled(true); - ui->modeComboBox->setEnabled(true); - }); - - QString ip; - if (ui->interfaceComboBox->currentText() == "默认") - { - ip = "default"; - } - else - { - ip = ui->interfaceComboBox->currentData().toString(); - } - - QString url; - if (settings->value("WebLogin/EnableCustomUrl", false).toBool()) - { - url = settings->value("WebLogin/CustomUrl", "https://net.zju.edu.cn").toString(); - } - else if (settings->value("WebLogin/IntlUrl", false).toBool()) - { - url = "https://zjuwlan.intl.zju.edu.cn"; - } - else - { - url = "https://net.zju.edu.cn"; - } - - processForWebLogin->start( - "weblogin.exe", - QStringList() - << "logout" - << "-u" - << settings->value("Common/Username").toString() - << "-i" - << ip - << "--url" - << url - ); - - addLog("正在注销网页认证,接口:" + ui->interfaceComboBox->currentText()); - } - }); - - emit SetModeFinished(); -} diff --git a/zjuconnectcontroller/zjuconnectcontroller.cpp b/zjuconnectcontroller/zjuconnectcontroller.cpp index 3330474..0498d98 100644 --- a/zjuconnectcontroller/zjuconnectcontroller.cpp +++ b/zjuconnectcontroller/zjuconnectcontroller.cpp @@ -49,6 +49,7 @@ void ZjuConnectController::start( const QString &password, const QString &server, int port, + const QString& dns, bool disableMultiLine, bool proxyAll, const QString &socksBind, @@ -74,6 +75,12 @@ void ZjuConnectController::start( args.append(QString::number(port)); } + if (!dns.isEmpty()) + { + args.append("-zju-dns-server"); + args.append(dns); + } + if (disableMultiLine) { args.append("-disable-multi-line"); @@ -124,6 +131,11 @@ void ZjuConnectController::start( args.append(udpPortForwarding); } + QString cmd = program; + for (const auto& arg : args) + cmd += " " + arg; + emit outputRead(cmd); + zjuConnectProcess->start(program, args); zjuConnectProcess->waitForStarted(); } diff --git a/zjuconnectcontroller/zjuconnectcontroller.h b/zjuconnectcontroller/zjuconnectcontroller.h index 696feb8..c23d797 100644 --- a/zjuconnectcontroller/zjuconnectcontroller.h +++ b/zjuconnectcontroller/zjuconnectcontroller.h @@ -18,6 +18,7 @@ public: const QString &password, const QString &server = "", int port = 0, + const QString& dns = "", bool disableMultiLine = false, bool proxyAll = false, const QString &socksBind = "", diff --git a/zjuconnectmode.cpp b/zjuconnectmode.cpp index bdff592..cdba177 100644 --- a/zjuconnectmode.cpp +++ b/zjuconnectmode.cpp @@ -11,10 +11,6 @@ void MainWindow::setModeToZjuConnect() clearLog(); networkDetector->start(); - - ui->interfaceLabel->hide(); - ui->refreshInterfaceButton->hide(); - ui->interfaceComboBox->hide(); ui->tunCheckBox->show(); if (settings->contains("ZJUConnect/TunMode")) @@ -78,7 +74,6 @@ void MainWindow::setModeToZjuConnect() showNotification("RVPN", "RVPN 断开!", QSystemTrayIcon::MessageIcon::Warning); isZjuConnectLinked = false; ui->pushButton1->setText("连接服务器"); - ui->modeComboBox->setEnabled(true); if (isZjuConnectLoginError) { @@ -97,7 +92,7 @@ void MainWindow::setModeToZjuConnect() { if (!isZjuConnectLinked) { - if (settings->value("ZJUConnect/ServerAddress", "rvpn.zju.edu.cn").toString().isEmpty()) + if (settings->value("ZJUConnect/ServerAddress", "vpn.hitsz.edu.cn").toString().isEmpty()) { QMessageBox::critical(this, "错误", "服务器地址不能为空"); return; @@ -121,6 +116,7 @@ void MainWindow::setModeToZjuConnect() QByteArray::fromBase64(settings->value("Common/Password").toString().toUtf8()), settings->value("ZJUConnect/ServerAddress").toString(), settings->value("ZJUConnect/ServerPort", 443).toInt(), + settings->value("ZJUConnect/DNS").toString(), !settings->value("ZJUConnect/MultiLine", true).toBool(), settings->value("ZJUConnect/ProxyAll", false).toBool(), "127.0.0.1:" + QString::number(settings->value("ZJUConnect/Socks5Port", 11080).toInt()), @@ -133,7 +129,6 @@ void MainWindow::setModeToZjuConnect() ); isZjuConnectLinked = true; - ui->modeComboBox->setEnabled(false); ui->pushButton1->setText("断开服务器"); ui->pushButton2->show(); @@ -155,7 +150,6 @@ void MainWindow::setModeToZjuConnect() ui->pushButton1->setText("连接服务器"); ui->pushButton2->hide(); - ui->modeComboBox->setEnabled(true); } });