Skip to content

Commit

Permalink
update nekoray_core options
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Apr 18, 2023
1 parent 54d8de6 commit 990f100
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 34 deletions.
4 changes: 2 additions & 2 deletions go/cmd/nekoray_core/core_ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 21 additions & 12 deletions go/cmd/nekoray_core/protect_bindinterface_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/binary"
"log"
"net"
"os"
"strings"
"sync"
"syscall"
Expand All @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions main/NekoRay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions main/NekoRay_DataStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions sys/ExternalProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
20 changes: 12 additions & 8 deletions translations/fa_IR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@
<source>Default: dir of &quot;nekoray&quot;</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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
20 changes: 12 additions & 8 deletions translations/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@
<source>Default: dir of &quot;nekoray&quot;</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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
32 changes: 28 additions & 4 deletions ui/dialog_basic_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 990f100

Please sign in to comment.