From 990f1006d167517ebb300b8374a5056040419250 Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Tue, 18 Apr 2023 09:47:17 +0900 Subject: [PATCH] update nekoray_core options --- go/cmd/nekoray_core/core_ray.go | 4 +-- .../protect_bindinterface_windows.go | 33 ++++++++++++------- main/NekoRay.cpp | 2 ++ main/NekoRay_DataStore.hpp | 2 ++ sys/ExternalProcess.cpp | 4 +++ translations/fa_IR.ts | 20 ++++++----- translations/zh_CN.ts | 20 ++++++----- ui/dialog_basic_settings.cpp | 32 +++++++++++++++--- ui/mainwindow.cpp | 7 ++++ 9 files changed, 90 insertions(+), 34 deletions(-) diff --git a/go/cmd/nekoray_core/core_ray.go b/go/cmd/nekoray_core/core_ray.go index f13d5dc4e..d4393ecca 100644 --- a/go/cmd/nekoray_core/core_ray.go +++ b/go/cmd/nekoray_core/core_ray.go @@ -48,10 +48,10 @@ func setupCore() { // localdns setup resolver_def := &net.Resolver{PreferGo: false} resolver_go := &net.Resolver{PreferGo: true} - if underlyingNetDialer != nil && os.Getenv("NKR_VPN_LEGACY_DNS") == "1" { + if underlyingNetDialer != nil && os.Getenv("NKR_CORE_RAY_DIRECT_DNS") == "1" { resolver_def.Dial = underlyingNetDialer.DialContext resolver_go.Dial = underlyingNetDialer.DialContext - log.Println("using NKR_VPN_LEGACY_DNS") + log.Println("using NKR_CORE_RAY_DIRECT_DNS") } localdns.SetLookupFunc(func(network string, host string) (ips []net.IP, err error) { // fix old sekai diff --git a/go/cmd/nekoray_core/protect_bindinterface_windows.go b/go/cmd/nekoray_core/protect_bindinterface_windows.go index 22cb70e37..43c1862c6 100644 --- a/go/cmd/nekoray_core/protect_bindinterface_windows.go +++ b/go/cmd/nekoray_core/protect_bindinterface_windows.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "log" "net" + "os" "strings" "sync" "syscall" @@ -20,6 +21,26 @@ var interfaces []net.Interface var lock sync.Mutex func init() { + if os.Getenv("NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE") == "1" { + log.Println("using NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE") + } else { + initRoute() + } + // + getNekorayTunIndex = func() (index int) { + lock.Lock() + defer lock.Unlock() + for _, intf := range interfaces { + if intf.Name == "nekoray-tun" { + index = intf.Index + return + } + } + return + } +} + +func initRoute() { internet.RegisterListenerController(func(network, address string, fd uintptr) error { bindInterfaceIndex := getBindInterfaceIndex(address) if bindInterfaceIndex != 0 { @@ -75,18 +96,6 @@ func init() { updateRoutes() return 0 }, false) - // - getNekorayTunIndex = func() (index int) { - lock.Lock() - defer lock.Unlock() - for _, intf := range interfaces { - if intf.Name == "nekoray-tun" { - index = intf.Index - return - } - } - return - } } func updateRoutes() { diff --git a/main/NekoRay.cpp b/main/NekoRay.cpp index 9eb54f2db..197a2d9f8 100644 --- a/main/NekoRay.cpp +++ b/main/NekoRay.cpp @@ -79,7 +79,9 @@ namespace NekoRay { _add(new configItem("core_box_clash_api", &core_box_clash_api, itemType::integer)); _add(new configItem("core_box_clash_api_secret", &core_box_clash_api_secret, itemType::string)); _add(new configItem("core_box_underlying_dns", &core_box_underlying_dns, itemType::string)); + _add(new configItem("core_ray_direct_dns", &core_ray_direct_dns, itemType::boolean)); #ifndef Q_OS_WIN + _add(new configItem("core_ray_windows_disable_auto_interface", &core_ray_windows_disable_auto_interface, itemType::boolean)); _add(new configItem("vpn_already_admin", &vpn_already_admin, itemType::boolean)); #endif } diff --git a/main/NekoRay_DataStore.hpp b/main/NekoRay_DataStore.hpp index 683a24e1a..1961467d0 100644 --- a/main/NekoRay_DataStore.hpp +++ b/main/NekoRay_DataStore.hpp @@ -154,6 +154,8 @@ namespace NekoRay { int core_box_clash_api = -9090; QString core_box_clash_api_secret = ""; QString core_box_underlying_dns = ""; + bool core_ray_direct_dns = false; + bool core_ray_windows_disable_auto_interface = false; // Other Core ExtraCore *extraCore = new ExtraCore; diff --git a/sys/ExternalProcess.cpp b/sys/ExternalProcess.cpp index 852ad316f..da7513d82 100644 --- a/sys/ExternalProcess.cpp +++ b/sys/ExternalProcess.cpp @@ -119,11 +119,15 @@ namespace NekoRay::sys { void CoreProcess::Start() { show_stderr = false; + // set extra env auto v2ray_asset_dir = FindCoreAsset("geoip.dat"); if (!v2ray_asset_dir.isEmpty()) { v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath(); env << "V2RAY_LOCATION_ASSET=" + v2ray_asset_dir; } + if (NekoRay::dataStore->core_ray_direct_dns) env << "NKR_CORE_RAY_DIRECT_DNS=1"; + if (NekoRay::dataStore->core_ray_windows_disable_auto_interface) env << "NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE=1"; + // ExternalProcess::Start(); write((dataStore->core_token + "\n").toUtf8()); } diff --git a/translations/fa_IR.ts b/translations/fa_IR.ts index d25edc7d4..7225677da 100644 --- a/translations/fa_IR.ts +++ b/translations/fa_IR.ts @@ -79,14 +79,6 @@ Default: dir of "nekoray" - - Settings changed - تنظیمات تغییر کرد - - - Restart nekoray to take effect. - برای اعمال تغییرات nekoray را مجددا راه اندازی کنید. - Concurrent هم زمان @@ -247,6 +239,10 @@ For NekoRay, this rewrites the underlying(localhost) DNS in VPN mode. For NekoBox, this rewrites the underlying(localhost) DNS in VPN mode, normal mode, and also URL Test. + + If you VPN mode is not working, try to change this option. + + DialogEditGroup @@ -1354,6 +1350,14 @@ End: %2 Show Window نمایش پنجره برنامه + + Settings changed + تنظیمات تغییر کرد + + + Restart nekoray to take effect. + برای اعمال تغییرات nekoray را مجددا راه اندازی کنید. + ProxyItem diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 796758a1a..c7a967f61 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -79,14 +79,6 @@ Default: dir of "nekoray" 默认值:和 nekoray 同路径 - - Settings changed - 设置改变 - - - Restart nekoray to take effect. - 重启 nekoray 生效。 - Concurrent 并发 @@ -243,6 +235,10 @@ For NekoBox, this rewrites the underlying(localhost) DNS in VPN mode, normal mod 对于 NekoRay 来说,在 VPN 模式下会重写 underlying(localhost) DNS。 对于 NekoBox 来说,在 VPN 模式、正常模式和 URL 测试中会重写 underlying(localhost) DNS。 + + If you VPN mode is not working, try to change this option. + 如果您的VPN模式有问题,请尝试更改此选项。 + DialogEditGroup @@ -1344,6 +1340,14 @@ Split by line. Show Window 显示主窗口 + + Settings changed + 设置改变 + + + Restart nekoray to take effect. + 重启 nekoray 生效。 + ProxyItem diff --git a/ui/dialog_basic_settings.cpp b/ui/dialog_basic_settings.cpp index ee79e87e3..7d0b78658 100644 --- a/ui/dialog_basic_settings.cpp +++ b/ui/dialog_basic_settings.cpp @@ -155,7 +155,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) file.write("0"); } file.close(); - MessageBoxWarning(tr("Settings changed"), tr("Restart nekoray to take effect.")); + CACHE.needRestart = true; }); // Subscription @@ -259,8 +259,6 @@ DialogBasicSettings::~DialogBasicSettings() { } void DialogBasicSettings::accept() { - if (CACHE.needRestart) MessageBoxWarning(tr("Settings changed"), tr("Restart nekoray to take effect.")); - // Common NekoRay::dataStore->inbound_address = ui->socks_ip->text(); @@ -316,7 +314,9 @@ void DialogBasicSettings::accept() { MW_dialog_message("", "ClearConnectionList"); } - MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore"); + QStringList str{"UpdateDataStore"}; + if (CACHE.needRestart) str << "NeedRestart"; + MW_dialog_message(Dialog_DialogBasicSettings, str.join(",")); QDialog::accept(); } @@ -399,6 +399,8 @@ void DialogBasicSettings::on_core_settings_clicked() { MyLineEdit *core_box_clash_api; MyLineEdit *core_box_clash_api_secret; MyLineEdit *core_box_underlying_dns; + QCheckBox *core_ray_direct_dns; + QCheckBox *core_ray_windows_disable_auto_interface; // auto core_box_underlying_dns_l = new QLabel(tr("Override underlying DNS")); core_box_underlying_dns_l->setToolTip(tr( @@ -435,6 +437,23 @@ void DialogBasicSettings::on_core_settings_clicked() { core_box_clash_api_secret->setText(NekoRay::dataStore->core_box_clash_api_secret); layout->addWidget(core_box_clash_api_secret_l, ++line, 0); layout->addWidget(core_box_clash_api_secret, line, 1); + } else { + auto core_ray_direct_dns_l = new QLabel("NKR_CORE_RAY_DIRECT_DNS"); + core_ray_direct_dns_l->setToolTip(tr("If you VPN mode is not working, try to change this option.")); + core_ray_direct_dns = new QCheckBox; + core_ray_direct_dns->setChecked(NekoRay::dataStore->core_ray_direct_dns); + connect(core_ray_direct_dns, &QCheckBox::clicked, this, [&] { CACHE.needRestart = true; }); + layout->addWidget(core_ray_direct_dns_l, ++line, 0); + layout->addWidget(core_ray_direct_dns, line, 1); +#ifdef Q_OS_WIN + auto core_ray_windows_disable_auto_interface_l = new QLabel("NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE"); + core_ray_windows_disable_auto_interface_l->setToolTip(tr("If you VPN mode is not working, try to change this option.")); + core_ray_windows_disable_auto_interface = new QCheckBox; + core_ray_windows_disable_auto_interface->setChecked(NekoRay::dataStore->core_ray_windows_disable_auto_interface); + connect(core_ray_windows_disable_auto_interface, &QCheckBox::clicked, this, [&] { CACHE.needRestart = true; }); + layout->addWidget(core_ray_windows_disable_auto_interface_l, ++line, 0); + layout->addWidget(core_ray_windows_disable_auto_interface, line, 1); +#endif } // auto box = new QDialogButtonBox; @@ -446,6 +465,11 @@ void DialogBasicSettings::on_core_settings_clicked() { NekoRay::dataStore->core_box_auto_detect_interface = core_box_auto_detect_interface->isChecked(); NekoRay::dataStore->core_box_clash_api = core_box_clash_api->text().toInt() * (core_box_enable_clash_api->isChecked() ? 1 : -1); NekoRay::dataStore->core_box_clash_api_secret = core_box_clash_api_secret->text(); + } else { + NekoRay::dataStore->core_ray_direct_dns = core_ray_direct_dns->isChecked(); +#ifdef Q_OS_WIN + NekoRay::dataStore->core_ray_windows_disable_auto_interface = core_ray_windows_disable_auto_interface->isChecked(); +#endif } MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore"); w->accept(); diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 5433ee673..ce0ff6171 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -522,6 +522,13 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) } refresh_status(); } + if (info.contains("NeedRestart")) { + auto n = QMessageBox::warning(GetMessageBoxParent(), tr("Settings changed"), tr("Restart nekoray to take effect."), QMessageBox::Yes | QMessageBox::No); + if (n == QMessageBox::Yes) { + this->exit_reason = 2; + on_menu_exit_triggered(); + } + } // if (info == "RestartProgram") { this->exit_reason = 2;