mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
refactor fakedns
This commit is contained in:
@@ -181,8 +181,7 @@ namespace NekoGui {
|
||||
|
||||
// Inbounds
|
||||
QJsonObject sniffing{
|
||||
{"destOverride", dataStore->fake_dns ? QJsonArray{"fakedns", "http", "tls", "quic"}
|
||||
: QJsonArray{"http", "tls", "quic"}},
|
||||
{"destOverride", QJsonArray{"http", "tls", "quic"}},
|
||||
{"enabled", true},
|
||||
{"metadataOnly", false},
|
||||
{"routeOnly", dataStore->routing->sniffing_mode == SniffingMode::FOR_ROUTING},
|
||||
@@ -196,7 +195,7 @@ namespace NekoGui {
|
||||
inboundObj["listen"] = dataStore->inbound_address;
|
||||
inboundObj["port"] = dataStore->inbound_socks_port;
|
||||
QJsonObject socksSettings = {{"udp", true}};
|
||||
if (dataStore->fake_dns || dataStore->routing->sniffing_mode != SniffingMode::DISABLE) {
|
||||
if (dataStore->routing->sniffing_mode != SniffingMode::DISABLE) {
|
||||
inboundObj["sniffing"] = sniffing;
|
||||
}
|
||||
if (dataStore->inbound_auth->NeedAuth()) {
|
||||
@@ -295,7 +294,7 @@ namespace NekoGui {
|
||||
|
||||
// Remote or FakeDNS
|
||||
QJsonObject dnsServerRemote;
|
||||
dnsServerRemote["address"] = dataStore->fake_dns ? "fakedns" : dataStore->routing->remote_dns;
|
||||
dnsServerRemote["address"] = dataStore->routing->remote_dns;
|
||||
dnsServerRemote["domains"] = QList2QJsonArray<QString>(status->domainListDNSRemote);
|
||||
dnsServerRemote["queryStrategy"] = dataStore->routing->remote_dns_strategy;
|
||||
if (!status->forTest) dnsServers += dnsServerRemote;
|
||||
@@ -864,6 +863,19 @@ namespace NekoGui {
|
||||
{"detour", "direct"},
|
||||
};
|
||||
|
||||
// Fakedns
|
||||
if (IS_NEKO_BOX_INTERNAL_TUN && dataStore->spmode_vpn && !status->forTest) {
|
||||
dnsServers += QJsonObject{
|
||||
{"tag", "dns-fake"},
|
||||
{"address", "fakeip"},
|
||||
};
|
||||
dns["fakeip"] = QJsonObject{
|
||||
{"enabled", true},
|
||||
{"inet4_range", "198.18.0.0/15"},
|
||||
{"inet6_range", "fc00::/18"},
|
||||
};
|
||||
}
|
||||
|
||||
// Underlying 100% Working DNS
|
||||
dnsServers += QJsonObject{
|
||||
{"tag", "dns-local"},
|
||||
@@ -878,10 +890,17 @@ namespace NekoGui {
|
||||
rule["server"] = server;
|
||||
dnsRules += rule;
|
||||
};
|
||||
|
||||
add_rule_dns(status->domainListDNSRemote, "dns-remote");
|
||||
add_rule_dns(status->domainListDNSDirect, "dns-direct");
|
||||
|
||||
// fakedns rule
|
||||
if (IS_NEKO_BOX_INTERNAL_TUN && dataStore->spmode_vpn && !status->forTest) {
|
||||
dnsRules += QJsonObject{
|
||||
{"inbound", "tun-in"},
|
||||
{"server", "dns-fake"},
|
||||
};
|
||||
}
|
||||
|
||||
dns["servers"] = dnsServers;
|
||||
dns["rules"] = dnsRules;
|
||||
dns["independent_cache"] = true;
|
||||
@@ -1042,16 +1061,17 @@ namespace NekoGui {
|
||||
auto configFn = ":/neko/vpn/sing-box-vpn.json";
|
||||
if (QFile::exists("vpn/sing-box-vpn.json")) configFn = "vpn/sing-box-vpn.json";
|
||||
auto config = ReadFileText(configFn)
|
||||
.replace("%IPV6_ADDRESS%", dataStore->vpn_ipv6 ? R"("inet6_address": "fdfe:dcba:9876::1/126",)" : "")
|
||||
.replace("//%IPV6_ADDRESS%", dataStore->vpn_ipv6 ? R"("inet6_address": "fdfe:dcba:9876::1/126",)" : "")
|
||||
.replace("//%SOCKS_USER_PASS%", socks_user_pass)
|
||||
.replace("//%PROCESS_NAME_RULE%", process_name_rule)
|
||||
.replace("//%CIDR_RULE%", cidr_rule)
|
||||
.replace("%MTU%", Int2String(dataStore->vpn_mtu))
|
||||
.replace("%STACK%", Preset::SingBox::VpnImplementation.value(dataStore->vpn_implementation))
|
||||
.replace("%PROCESS_NAME_RULE%", process_name_rule)
|
||||
.replace("%CIDR_RULE%", cidr_rule)
|
||||
.replace("%TUN_NAME%", genTunName())
|
||||
.replace("%STRICT_ROUTE%", dataStore->vpn_strict_route ? "true" : "false")
|
||||
.replace("%SOCKS_USER_PASS%", socks_user_pass)
|
||||
.replace("%FINAL_OUT%", no_match_out)
|
||||
.replace("%DNS_ADDRESS%", BOX_UNDERLYING_DNS)
|
||||
.replace("%FAKE_DNS_INBOUND%", dataStore->fake_dns ? "tun-in" : "empty")
|
||||
.replace("%PORT%", Int2String(dataStore->inbound_socks_port));
|
||||
// hook.js
|
||||
auto source = qjs::ReadHookJS();
|
||||
|
||||
@@ -1,19 +1,62 @@
|
||||
{
|
||||
"log": {
|
||||
"level": "info"
|
||||
},
|
||||
"dns": {
|
||||
"fakeip": {
|
||||
"enabled": true,
|
||||
"inet4_range": "198.18.0.0/15",
|
||||
"inet6_range": "fc00::/18"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"tag": "dns-remote",
|
||||
"address": "8.8.8.8",
|
||||
"detour": "nekoray-socks"
|
||||
},
|
||||
{
|
||||
"tag": "dns-direct",
|
||||
"address": "%DNS_ADDRESS%",
|
||||
"detour": "direct"
|
||||
},
|
||||
{
|
||||
"address": "fakeip",
|
||||
"tag": "dns-fake"
|
||||
},
|
||||
{
|
||||
"address": "rcode://success",
|
||||
"tag": "dns-block"
|
||||
}
|
||||
],
|
||||
"rules": [
|
||||
{
|
||||
"domain_suffix": [
|
||||
".lan"
|
||||
],
|
||||
"server": "dns-block"
|
||||
},
|
||||
{
|
||||
"process_name": [
|
||||
"nekoray_core",
|
||||
"nekoray_core.exe",
|
||||
"nekobox_core",
|
||||
"nekobox_core.exe"
|
||||
],
|
||||
"server": "dns-direct"
|
||||
},
|
||||
{
|
||||
"inbound": "%FAKE_DNS_INBOUND%",
|
||||
"server": "dns-fake"
|
||||
}
|
||||
]
|
||||
},
|
||||
"inbounds": [
|
||||
{
|
||||
"type": "tun",
|
||||
"tag": "tun-in",
|
||||
"interface_name": "%TUN_NAME%",
|
||||
"inet4_address": "172.19.0.1/28",
|
||||
%IPV6_ADDRESS%
|
||||
//%IPV6_ADDRESS%
|
||||
"mtu": %MTU%,
|
||||
"auto_route": true,
|
||||
"strict_route": %STRICT_ROUTE%,
|
||||
@@ -27,7 +70,7 @@
|
||||
"type": "socks",
|
||||
"tag": "nekoray-socks",
|
||||
"udp_fragment": true,
|
||||
%SOCKS_USER_PASS%
|
||||
//%SOCKS_USER_PASS%
|
||||
"server": "127.0.0.1",
|
||||
"server_port": %PORT%
|
||||
},
|
||||
@@ -48,10 +91,6 @@
|
||||
"final": "%FINAL_OUT%",
|
||||
"auto_detect_interface": true,
|
||||
"rules": [
|
||||
{
|
||||
"inbound": "dns-in",
|
||||
"outbound": "dns-out"
|
||||
},
|
||||
{
|
||||
"network": "udp",
|
||||
"port": [
|
||||
@@ -93,9 +132,13 @@
|
||||
"nekobox_core.exe"
|
||||
],
|
||||
"outbound": "direct"
|
||||
},
|
||||
//%PROCESS_NAME_RULE%
|
||||
//%CIDR_RULE%
|
||||
{
|
||||
"port": 53,
|
||||
"outbound": "dns-out"
|
||||
}
|
||||
%PROCESS_NAME_RULE%
|
||||
%CIDR_RULE%
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -695,6 +695,12 @@ These settings can be changed later.</source>
|
||||
<source>Format</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>This is especially important and it is recommended to use the default value of "localhost".
|
||||
If the default value does not work, try changing it to "223.5.5.5".
|
||||
For more information, see the document "Configuration/DNS".</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DialogVPNSettings</name>
|
||||
|
||||
@@ -688,6 +688,12 @@ These settings can be changed later.</source>
|
||||
<source>Remove routing: %1</source>
|
||||
<translation>Удалить маршруты: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>This is especially important and it is recommended to use the default value of "localhost".
|
||||
If the default value does not work, try changing it to "223.5.5.5".
|
||||
For more information, see the document "Configuration/DNS".</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DialogVPNSettings</name>
|
||||
|
||||
@@ -689,6 +689,14 @@ These settings can be changed later.</source>
|
||||
<source>Format</source>
|
||||
<translation>格式化</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>This is especially important and it is recommended to use the default value of "localhost".
|
||||
If the default value does not work, try changing it to "223.5.5.5".
|
||||
For more information, see the document "Configuration/DNS".</source>
|
||||
<translation>此项尤为重要,建议使用默认值 "localhost"。
|
||||
如果默认值不工作,可以尝试更改为 "223.5.5.5"。
|
||||
更多信息,请参阅文档 "配置/DNS"。</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DialogVPNSettings</name>
|
||||
@@ -1650,7 +1658,7 @@ Release note:
|
||||
</message>
|
||||
<message>
|
||||
<source>Default</source>
|
||||
<translation type="unfinished">默认</translation>
|
||||
<translation>默认</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>650</width>
|
||||
<height>500</height>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@@ -33,7 +33,7 @@
|
||||
<item row="2" column="3">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>3</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_1">
|
||||
<attribute name="title">
|
||||
@@ -606,7 +606,7 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="mux_padding">
|
||||
<property name="text">
|
||||
<string>padding</string>
|
||||
<string notr="true">Padding</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -701,8 +701,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>515</width>
|
||||
<height>315</height>
|
||||
<width>198</width>
|
||||
<height>58</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
|
||||
@@ -159,6 +159,11 @@ For sing-box, it sets inbound.domain_strategy</string>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="toolTip">
|
||||
<string>This is especially important and it is recommended to use the default value of "localhost".
|
||||
If the default value does not work, try changing it to "223.5.5.5".
|
||||
For more information, see the document "Configuration/DNS".</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Direct DNS</string>
|
||||
</property>
|
||||
|
||||
@@ -11,9 +11,7 @@ DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new
|
||||
ui->setupUi(this);
|
||||
ADD_ASTERISK(this);
|
||||
|
||||
ui->fake_dns->setVisible(!IS_NEKO_BOX);
|
||||
ui->fake_dns->setChecked(NekoGui::dataStore->fake_dns);
|
||||
//
|
||||
ui->vpn_implementation->setCurrentIndex(NekoGui::dataStore->vpn_implementation);
|
||||
ui->vpn_mtu->setCurrentText(Int2String(NekoGui::dataStore->vpn_mtu));
|
||||
ui->vpn_ipv6->setChecked(NekoGui::dataStore->vpn_ipv6);
|
||||
|
||||
@@ -376,6 +376,12 @@ void MainWindow::neko_start(int _id) {
|
||||
restartMsgboxTimer->cancel();
|
||||
restartMsgboxTimer->deleteLater();
|
||||
restartMsgbox->deleteLater();
|
||||
#ifdef Q_OS_LINUX
|
||||
// Check systemd-resolved
|
||||
if (NekoGui::dataStore->spmode_vpn && NekoGui::dataStore->routing->direct_dns.startsWith("local") && ReadFileText("/etc/resolv.conf").contains("systemd-resolved")) {
|
||||
MW_show_log("[Warning] The default Direct DNS may not works with systemd-resolved, you may consider change your DNS settings.");
|
||||
}
|
||||
#endif
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user