From 2482a5b48f7f75f3eb0b7138ce22038678676181 Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Sun, 29 Jan 2023 12:02:58 +0900 Subject: [PATCH] vpn final outbound rule GUI --- db/ConfigBuilder.cpp | 16 ++++++++++++---- main/GuiUtils.hpp | 14 ++++++++++++++ main/NekoRay.cpp | 5 +++-- main/NekoRay_DataStore.hpp | 5 +++-- res/vpn/sing-box-vpn.json | 1 + translations/fa_IR.ts | 16 ++++++++++++++++ translations/zh_CN.ts | 16 ++++++++++++++++ ui/dialog_vpn_settings.cpp | 21 +++++++++++++++++---- ui/dialog_vpn_settings.ui | 32 +++++++++++++++++++++++--------- ui/edit/dialog_edit_profile.cpp | 7 +------ 10 files changed, 106 insertions(+), 27 deletions(-) diff --git a/db/ConfigBuilder.cpp b/db/ConfigBuilder.cpp index 683b587..2911023 100644 --- a/db/ConfigBuilder.cpp +++ b/db/ConfigBuilder.cpp @@ -865,21 +865,28 @@ namespace NekoRay { } QString WriteVPNSingBoxConfig() { + auto match_out = NekoRay::dataStore->vpn_rule_white ? "proxy" : "direct"; + auto no_match_out = NekoRay::dataStore->vpn_rule_white ? "direct" : "proxy"; // user rule - QString process_name_rule = dataStore->vpn_bypass_process.trimmed(); + QString process_name_rule = dataStore->vpn_rule_process.trimmed(); if (!process_name_rule.isEmpty()) { auto arr = SplitLinesSkipSharp(process_name_rule); - QJsonObject rule{{"outbound", "direct"}, + QJsonObject rule{{"outbound", match_out}, {"process_name", QList2QJsonArray(arr)}}; process_name_rule = "," + QJsonObject2QString(rule, false); } - QString cidr_rule = dataStore->vpn_bypass_cidr.trimmed(); + QString cidr_rule = dataStore->vpn_rule_cidr.trimmed(); if (!cidr_rule.isEmpty()) { auto arr = SplitLinesSkipSharp(cidr_rule); - QJsonObject rule{{"outbound", "direct"}, + QJsonObject rule{{"outbound", match_out}, {"ip_cidr", QList2QJsonArray(arr)}}; cidr_rule = "," + QJsonObject2QString(rule, false); } + // no_match_rule + auto no_match_rule = QJsonObject{ + {"port_range", ":"}, + {"outbound", no_match_out}, + }; // tun name auto tun_name = "nekoray-tun"; #ifdef Q_OS_MACOS @@ -903,6 +910,7 @@ namespace NekoRay { .replace("%TUN_NAME%", tun_name) .replace("%STRICT_ROUTE%", dataStore->vpn_strict_route ? "true" : "false") .replace("%SOCKS_USER_PASS%", socks_user_pass) + .replace("%NO_MATCH_RULE%", "," + QJsonObject2QString(no_match_rule, false)) .replace("%PORT%", Int2String(dataStore->inbound_socks_port)); // hook.js auto source = qjs::ReadHookJS(); diff --git a/main/GuiUtils.hpp b/main/GuiUtils.hpp index 6573226..ae47472 100644 --- a/main/GuiUtils.hpp +++ b/main/GuiUtils.hpp @@ -80,3 +80,17 @@ #else #define ACTIVE_THIS_WINDOW _ACTIVE_THIS_WINDOW_COMMON #endif + +#define ADD_ASTERISK(parent) \ + for (auto label: parent->findChildren()) { \ + auto text = label->text(); \ + if (!label->toolTip().isEmpty() && !text.endsWith("*")) { \ + label->setText(text + "*"); \ + } \ + } \ + for (auto checkBox: parent->findChildren()) { \ + auto text = checkBox->text(); \ + if (!checkBox->toolTip().isEmpty() && !text.endsWith("*")) { \ + checkBox->setText(text + "*"); \ + } \ + } diff --git a/main/NekoRay.cpp b/main/NekoRay.cpp index 91371d8..69f77cb 100644 --- a/main/NekoRay.cpp +++ b/main/NekoRay.cpp @@ -60,8 +60,9 @@ namespace NekoRay { _add(new configItem("vpn_ipv6", &vpn_ipv6, itemType::boolean)); _add(new configItem("vpn_hide_console", &vpn_hide_console, itemType::boolean)); _add(new configItem("vpn_strict_route", &vpn_strict_route, itemType::boolean)); - _add(new configItem("vpn_bypass_process", &vpn_bypass_process, itemType::string)); - _add(new configItem("vpn_bypass_cidr", &vpn_bypass_cidr, itemType::string)); + _add(new configItem("vpn_bypass_process", &vpn_rule_process, itemType::string)); + _add(new configItem("vpn_bypass_cidr", &vpn_rule_cidr, itemType::string)); + _add(new configItem("vpn_rule_white", &vpn_rule_white, itemType::boolean)); _add(new configItem("check_include_pre", &check_include_pre, itemType::boolean)); _add(new configItem("sp_format", &system_proxy_format, itemType::string)); _add(new configItem("sub_clear", &sub_clear, itemType::boolean)); diff --git a/main/NekoRay_DataStore.hpp b/main/NekoRay_DataStore.hpp index 4b8b28e..f9cf4d7 100644 --- a/main/NekoRay_DataStore.hpp +++ b/main/NekoRay_DataStore.hpp @@ -133,8 +133,9 @@ namespace NekoRay { bool vpn_ipv6 = false; bool vpn_hide_console = false; bool vpn_strict_route = false; - QString vpn_bypass_process = ""; - QString vpn_bypass_cidr = ""; + bool vpn_rule_white = false; + QString vpn_rule_process = ""; + QString vpn_rule_cidr = ""; // Hotkey QString hotkey_mainwindow = ""; diff --git a/res/vpn/sing-box-vpn.json b/res/vpn/sing-box-vpn.json index 6679c27..4a73da3 100644 --- a/res/vpn/sing-box-vpn.json +++ b/res/vpn/sing-box-vpn.json @@ -95,6 +95,7 @@ } %PROCESS_NAME_RULE% %CIDR_RULE% + %NO_MATCH_RULE% ] } } \ No newline at end of file diff --git a/translations/fa_IR.ts b/translations/fa_IR.ts index 1c26439..553e781 100644 --- a/translations/fa_IR.ts +++ b/translations/fa_IR.ts @@ -583,6 +583,22 @@ Bypass Process Name + + Whether blacklisted or whitelisted, your traffic will be handled by nekobox_core (sing-tun). This is NOT equal to "process mode" of some software. + + + + Whitelist mode + + + + Proxy CIDR + + + + Proxy Process Name + + EditChain diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index b3c952f..b968e94 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -589,6 +589,22 @@ Bypass Process Name 绕过进程名 + + Whitelist mode + 白名单模式 + + + Proxy CIDR + 代理 CIDR + + + Proxy Process Name + 代理进程名 + + + Whether blacklisted or whitelisted, your traffic will be handled by nekobox_core (sing-tun). This is NOT equal to "process mode" of some software. + 无论是黑名单还是白名单,您的流量都将由 nekobox_core (sing-tun) 处理。这不等于某些软件的「进程模式」。 + EditChain diff --git a/ui/dialog_vpn_settings.cpp b/ui/dialog_vpn_settings.cpp index ee75731..bfd0b6d 100644 --- a/ui/dialog_vpn_settings.cpp +++ b/ui/dialog_vpn_settings.cpp @@ -6,6 +6,7 @@ DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new Ui::DialogVPNSettings) { ui->setupUi(this); + ADD_ASTERISK(this); ui->fake_dns->setVisible(!IS_NEKO_BOX); ui->fake_dns->setChecked(NekoRay::dataStore->fake_dns); @@ -19,8 +20,19 @@ DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new #endif ui->strict_route->setChecked(NekoRay::dataStore->vpn_strict_route); // - D_LOAD_STRING(vpn_bypass_cidr) - D_LOAD_STRING(vpn_bypass_process) + D_LOAD_STRING(vpn_rule_cidr) + D_LOAD_STRING(vpn_rule_process) + // + connect(ui->whitelist_mode, &QCheckBox::stateChanged, this, [=](int state) { + if (state == Qt::Checked) { + ui->gb_cidr->setTitle(tr("Proxy CIDR")); + ui->gb_process_name->setTitle(tr("Proxy Process Name")); + } else { + ui->gb_cidr->setTitle(tr("Bypass CIDR")); + ui->gb_process_name->setTitle(tr("Bypass Process Name")); + } + }); + ui->whitelist_mode->setChecked(NekoRay::dataStore->vpn_rule_white); } DialogVPNSettings::~DialogVPNSettings() { @@ -37,9 +49,10 @@ void DialogVPNSettings::accept() { NekoRay::dataStore->vpn_ipv6 = ui->vpn_ipv6->isChecked(); NekoRay::dataStore->vpn_hide_console = ui->hide_console->isChecked(); NekoRay::dataStore->vpn_strict_route = ui->strict_route->isChecked(); + NekoRay::dataStore->vpn_rule_white = ui->whitelist_mode->isChecked(); // - D_SAVE_STRING_QTEXTEDIT(vpn_bypass_cidr) - D_SAVE_STRING_QTEXTEDIT(vpn_bypass_process) + D_SAVE_STRING_QTEXTEDIT(vpn_rule_cidr) + D_SAVE_STRING_QTEXTEDIT(vpn_rule_process) // MW_dialog_message("", "UpdateDataStore,VPNChanged"); QDialog::accept(); diff --git a/ui/dialog_vpn_settings.ui b/ui/dialog_vpn_settings.ui index 16a7b86..b6fa35c 100644 --- a/ui/dialog_vpn_settings.ui +++ b/ui/dialog_vpn_settings.ui @@ -120,25 +120,25 @@ - + Bypass CIDR - + - + Bypass Process Name - + @@ -146,11 +146,25 @@ - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + Whether blacklisted or whitelisted, your traffic will be handled by nekobox_core (sing-tun). This is NOT equal to "process mode" of some software. + + + Whitelist mode + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + diff --git a/ui/edit/dialog_edit_profile.cpp b/ui/edit/dialog_edit_profile.cpp index 206048f..a4160ae 100644 --- a/ui/edit/dialog_edit_profile.cpp +++ b/ui/edit/dialog_edit_profile.cpp @@ -248,12 +248,7 @@ void DialogEditProfile::typeSelected(const QString &newType) { ui->port->setValidator(QRegExpValidator_Number); // 星号 - for (auto label: findChildren()) { - auto text = label->text(); - if (!label->toolTip().isEmpty() && !text.endsWith("*")) { - label->setText(text + "*"); - } - } + ADD_ASTERISK(this); // 设置 for NekoBox if (IS_NEKO_BOX) {