mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 05:30:06 +08:00
update nekoray_core options
This commit is contained in:
parent
54d8de64d0
commit
990f1006d1
@ -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
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -79,14 +79,6 @@
|
||||
<source>Default: dir of "nekoray"</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Settings changed</source>
|
||||
<translation>تنظیمات تغییر کرد</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Restart nekoray to take effect.</source>
|
||||
<translation>برای اعمال تغییرات nekoray را مجددا راه اندازی کنید.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Concurrent</source>
|
||||
<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>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>If you VPN mode is not working, try to change this option.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DialogEditGroup</name>
|
||||
@ -1354,6 +1350,14 @@ End: %2</source>
|
||||
<source>Show Window</source>
|
||||
<translation>نمایش پنجره برنامه</translation>
|
||||
</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>
|
||||
<name>ProxyItem</name>
|
||||
|
||||
@ -79,14 +79,6 @@
|
||||
<source>Default: dir of "nekoray"</source>
|
||||
<translation>默认值:和 nekoray 同路径</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Settings changed</source>
|
||||
<translation>设置改变</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Restart nekoray to take effect.</source>
|
||||
<translation>重启 nekoray 生效。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Concurrent</source>
|
||||
<translation>并发</translation>
|
||||
@ -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。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>If you VPN mode is not working, try to change this option.</source>
|
||||
<translation>如果您的VPN模式有问题,请尝试更改此选项。</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DialogEditGroup</name>
|
||||
@ -1344,6 +1340,14 @@ Split by line.</source>
|
||||
<source>Show Window</source>
|
||||
<translation>显示主窗口</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Settings changed</source>
|
||||
<translation>设置改变</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Restart nekoray to take effect.</source>
|
||||
<translation>重启 nekoray 生效。</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyItem</name>
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user