update nekoray_core options

This commit is contained in:
arm64v8a 2023-04-18 09:47:17 +09:00
parent 54d8de64d0
commit 990f1006d1
9 changed files with 90 additions and 34 deletions

View File

@ -48,10 +48,10 @@ func setupCore() {
// localdns setup // localdns setup
resolver_def := &net.Resolver{PreferGo: false} resolver_def := &net.Resolver{PreferGo: false}
resolver_go := &net.Resolver{PreferGo: true} 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_def.Dial = underlyingNetDialer.DialContext
resolver_go.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) { localdns.SetLookupFunc(func(network string, host string) (ips []net.IP, err error) {
// fix old sekai // fix old sekai

View File

@ -4,6 +4,7 @@ import (
"encoding/binary" "encoding/binary"
"log" "log"
"net" "net"
"os"
"strings" "strings"
"sync" "sync"
"syscall" "syscall"
@ -20,6 +21,26 @@ var interfaces []net.Interface
var lock sync.Mutex var lock sync.Mutex
func init() { 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 { internet.RegisterListenerController(func(network, address string, fd uintptr) error {
bindInterfaceIndex := getBindInterfaceIndex(address) bindInterfaceIndex := getBindInterfaceIndex(address)
if bindInterfaceIndex != 0 { if bindInterfaceIndex != 0 {
@ -75,18 +96,6 @@ func init() {
updateRoutes() updateRoutes()
return 0 return 0
}, false) }, 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() { func updateRoutes() {

View File

@ -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", &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_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_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 #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)); _add(new configItem("vpn_already_admin", &vpn_already_admin, itemType::boolean));
#endif #endif
} }

View File

@ -154,6 +154,8 @@ namespace NekoRay {
int core_box_clash_api = -9090; int core_box_clash_api = -9090;
QString core_box_clash_api_secret = ""; QString core_box_clash_api_secret = "";
QString core_box_underlying_dns = ""; QString core_box_underlying_dns = "";
bool core_ray_direct_dns = false;
bool core_ray_windows_disable_auto_interface = false;
// Other Core // Other Core
ExtraCore *extraCore = new ExtraCore; ExtraCore *extraCore = new ExtraCore;

View File

@ -119,11 +119,15 @@ namespace NekoRay::sys {
void CoreProcess::Start() { void CoreProcess::Start() {
show_stderr = false; show_stderr = false;
// set extra env
auto v2ray_asset_dir = FindCoreAsset("geoip.dat"); auto v2ray_asset_dir = FindCoreAsset("geoip.dat");
if (!v2ray_asset_dir.isEmpty()) { if (!v2ray_asset_dir.isEmpty()) {
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath(); v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
env << "V2RAY_LOCATION_ASSET=" + v2ray_asset_dir; 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(); ExternalProcess::Start();
write((dataStore->core_token + "\n").toUtf8()); write((dataStore->core_token + "\n").toUtf8());
} }

View File

@ -79,14 +79,6 @@
<source>Default: dir of &quot;nekoray&quot;</source> <source>Default: dir of &quot;nekoray&quot;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Settings changed</source>
<translation>تنظیمات تغییر کرد</translation>
</message>
<message>
<source>Restart nekoray to take effect.</source>
<translation>برای اعمال تغییرات nekoray را مجددا راه اندازی کنید.</translation>
</message>
<message> <message>
<source>Concurrent</source> <source>Concurrent</source>
<translation>هم زمان</translation> <translation>هم زمان</translation>
@ -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.</source> For NekoBox, this rewrites the underlying(localhost) DNS in VPN mode, normal mode, and also URL Test.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>If you VPN mode is not working, try to change this option.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>DialogEditGroup</name> <name>DialogEditGroup</name>
@ -1354,6 +1350,14 @@ End: %2</source>
<source>Show Window</source> <source>Show Window</source>
<translation>نمایش پنجره برنامه</translation> <translation>نمایش پنجره برنامه</translation>
</message> </message>
<message>
<source>Settings changed</source>
<translation type="unfinished">تنظیمات تغییر کرد</translation>
</message>
<message>
<source>Restart nekoray to take effect.</source>
<translation type="unfinished">برای اعمال تغییرات nekoray را مجددا راه اندازی کنید.</translation>
</message>
</context> </context>
<context> <context>
<name>ProxyItem</name> <name>ProxyItem</name>

View File

@ -79,14 +79,6 @@
<source>Default: dir of &quot;nekoray&quot;</source> <source>Default: dir of &quot;nekoray&quot;</source>
<translation> nekoray </translation> <translation> nekoray </translation>
</message> </message>
<message>
<source>Settings changed</source>
<translation></translation>
</message>
<message>
<source>Restart nekoray to take effect.</source>
<translation> nekoray </translation>
</message>
<message> <message>
<source>Concurrent</source> <source>Concurrent</source>
<translation></translation> <translation></translation>
@ -243,6 +235,10 @@ For NekoBox, this rewrites the underlying(localhost) DNS in VPN mode, normal mod
NekoRay VPN underlying(localhost) DNS NekoRay VPN underlying(localhost) DNS
NekoBox VPN URL underlying(localhost) DNS</translation> NekoBox VPN URL underlying(localhost) DNS</translation>
</message> </message>
<message>
<source>If you VPN mode is not working, try to change this option.</source>
<translation>VPN模式有问题</translation>
</message>
</context> </context>
<context> <context>
<name>DialogEditGroup</name> <name>DialogEditGroup</name>
@ -1344,6 +1340,14 @@ Split by line.</source>
<source>Show Window</source> <source>Show Window</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Settings changed</source>
<translation></translation>
</message>
<message>
<source>Restart nekoray to take effect.</source>
<translation> nekoray </translation>
</message>
</context> </context>
<context> <context>
<name>ProxyItem</name> <name>ProxyItem</name>

View File

@ -155,7 +155,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
file.write("0"); file.write("0");
} }
file.close(); file.close();
MessageBoxWarning(tr("Settings changed"), tr("Restart nekoray to take effect.")); CACHE.needRestart = true;
}); });
// Subscription // Subscription
@ -259,8 +259,6 @@ DialogBasicSettings::~DialogBasicSettings() {
} }
void DialogBasicSettings::accept() { void DialogBasicSettings::accept() {
if (CACHE.needRestart) MessageBoxWarning(tr("Settings changed"), tr("Restart nekoray to take effect."));
// Common // Common
NekoRay::dataStore->inbound_address = ui->socks_ip->text(); NekoRay::dataStore->inbound_address = ui->socks_ip->text();
@ -316,7 +314,9 @@ void DialogBasicSettings::accept() {
MW_dialog_message("", "ClearConnectionList"); 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(); QDialog::accept();
} }
@ -399,6 +399,8 @@ void DialogBasicSettings::on_core_settings_clicked() {
MyLineEdit *core_box_clash_api; MyLineEdit *core_box_clash_api;
MyLineEdit *core_box_clash_api_secret; MyLineEdit *core_box_clash_api_secret;
MyLineEdit *core_box_underlying_dns; 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")); auto core_box_underlying_dns_l = new QLabel(tr("Override underlying DNS"));
core_box_underlying_dns_l->setToolTip(tr( 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); 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_l, ++line, 0);
layout->addWidget(core_box_clash_api_secret, line, 1); 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; 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_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 = 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(); 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"); MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore");
w->accept(); w->accept();

View File

@ -522,6 +522,13 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info)
} }
refresh_status(); 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") { if (info == "RestartProgram") {
this->exit_reason = 2; this->exit_reason = 2;