mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
refactor fakedns
This commit is contained in:
@@ -181,8 +181,7 @@ namespace NekoGui {
|
|||||||
|
|
||||||
// Inbounds
|
// Inbounds
|
||||||
QJsonObject sniffing{
|
QJsonObject sniffing{
|
||||||
{"destOverride", dataStore->fake_dns ? QJsonArray{"fakedns", "http", "tls", "quic"}
|
{"destOverride", QJsonArray{"http", "tls", "quic"}},
|
||||||
: QJsonArray{"http", "tls", "quic"}},
|
|
||||||
{"enabled", true},
|
{"enabled", true},
|
||||||
{"metadataOnly", false},
|
{"metadataOnly", false},
|
||||||
{"routeOnly", dataStore->routing->sniffing_mode == SniffingMode::FOR_ROUTING},
|
{"routeOnly", dataStore->routing->sniffing_mode == SniffingMode::FOR_ROUTING},
|
||||||
@@ -196,7 +195,7 @@ namespace NekoGui {
|
|||||||
inboundObj["listen"] = dataStore->inbound_address;
|
inboundObj["listen"] = dataStore->inbound_address;
|
||||||
inboundObj["port"] = dataStore->inbound_socks_port;
|
inboundObj["port"] = dataStore->inbound_socks_port;
|
||||||
QJsonObject socksSettings = {{"udp", true}};
|
QJsonObject socksSettings = {{"udp", true}};
|
||||||
if (dataStore->fake_dns || dataStore->routing->sniffing_mode != SniffingMode::DISABLE) {
|
if (dataStore->routing->sniffing_mode != SniffingMode::DISABLE) {
|
||||||
inboundObj["sniffing"] = sniffing;
|
inboundObj["sniffing"] = sniffing;
|
||||||
}
|
}
|
||||||
if (dataStore->inbound_auth->NeedAuth()) {
|
if (dataStore->inbound_auth->NeedAuth()) {
|
||||||
@@ -295,7 +294,7 @@ namespace NekoGui {
|
|||||||
|
|
||||||
// Remote or FakeDNS
|
// Remote or FakeDNS
|
||||||
QJsonObject dnsServerRemote;
|
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["domains"] = QList2QJsonArray<QString>(status->domainListDNSRemote);
|
||||||
dnsServerRemote["queryStrategy"] = dataStore->routing->remote_dns_strategy;
|
dnsServerRemote["queryStrategy"] = dataStore->routing->remote_dns_strategy;
|
||||||
if (!status->forTest) dnsServers += dnsServerRemote;
|
if (!status->forTest) dnsServers += dnsServerRemote;
|
||||||
@@ -864,6 +863,19 @@ namespace NekoGui {
|
|||||||
{"detour", "direct"},
|
{"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
|
// Underlying 100% Working DNS
|
||||||
dnsServers += QJsonObject{
|
dnsServers += QJsonObject{
|
||||||
{"tag", "dns-local"},
|
{"tag", "dns-local"},
|
||||||
@@ -878,10 +890,17 @@ namespace NekoGui {
|
|||||||
rule["server"] = server;
|
rule["server"] = server;
|
||||||
dnsRules += rule;
|
dnsRules += rule;
|
||||||
};
|
};
|
||||||
|
|
||||||
add_rule_dns(status->domainListDNSRemote, "dns-remote");
|
add_rule_dns(status->domainListDNSRemote, "dns-remote");
|
||||||
add_rule_dns(status->domainListDNSDirect, "dns-direct");
|
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["servers"] = dnsServers;
|
||||||
dns["rules"] = dnsRules;
|
dns["rules"] = dnsRules;
|
||||||
dns["independent_cache"] = true;
|
dns["independent_cache"] = true;
|
||||||
@@ -1042,16 +1061,17 @@ namespace NekoGui {
|
|||||||
auto configFn = ":/neko/vpn/sing-box-vpn.json";
|
auto configFn = ":/neko/vpn/sing-box-vpn.json";
|
||||||
if (QFile::exists("vpn/sing-box-vpn.json")) configFn = "vpn/sing-box-vpn.json";
|
if (QFile::exists("vpn/sing-box-vpn.json")) configFn = "vpn/sing-box-vpn.json";
|
||||||
auto config = ReadFileText(configFn)
|
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("%MTU%", Int2String(dataStore->vpn_mtu))
|
||||||
.replace("%STACK%", Preset::SingBox::VpnImplementation.value(dataStore->vpn_implementation))
|
.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("%TUN_NAME%", genTunName())
|
||||||
.replace("%STRICT_ROUTE%", dataStore->vpn_strict_route ? "true" : "false")
|
.replace("%STRICT_ROUTE%", dataStore->vpn_strict_route ? "true" : "false")
|
||||||
.replace("%SOCKS_USER_PASS%", socks_user_pass)
|
|
||||||
.replace("%FINAL_OUT%", no_match_out)
|
.replace("%FINAL_OUT%", no_match_out)
|
||||||
.replace("%DNS_ADDRESS%", BOX_UNDERLYING_DNS)
|
.replace("%DNS_ADDRESS%", BOX_UNDERLYING_DNS)
|
||||||
|
.replace("%FAKE_DNS_INBOUND%", dataStore->fake_dns ? "tun-in" : "empty")
|
||||||
.replace("%PORT%", Int2String(dataStore->inbound_socks_port));
|
.replace("%PORT%", Int2String(dataStore->inbound_socks_port));
|
||||||
// hook.js
|
// hook.js
|
||||||
auto source = qjs::ReadHookJS();
|
auto source = qjs::ReadHookJS();
|
||||||
|
|||||||
@@ -1,19 +1,62 @@
|
|||||||
{
|
{
|
||||||
|
"log": {
|
||||||
|
"level": "info"
|
||||||
|
},
|
||||||
"dns": {
|
"dns": {
|
||||||
|
"fakeip": {
|
||||||
|
"enabled": true,
|
||||||
|
"inet4_range": "198.18.0.0/15",
|
||||||
|
"inet6_range": "fc00::/18"
|
||||||
|
},
|
||||||
"servers": [
|
"servers": [
|
||||||
|
{
|
||||||
|
"tag": "dns-remote",
|
||||||
|
"address": "8.8.8.8",
|
||||||
|
"detour": "nekoray-socks"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"tag": "dns-direct",
|
"tag": "dns-direct",
|
||||||
"address": "%DNS_ADDRESS%",
|
"address": "%DNS_ADDRESS%",
|
||||||
"detour": "direct"
|
"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": [
|
"inbounds": [
|
||||||
{
|
{
|
||||||
"type": "tun",
|
"type": "tun",
|
||||||
|
"tag": "tun-in",
|
||||||
"interface_name": "%TUN_NAME%",
|
"interface_name": "%TUN_NAME%",
|
||||||
"inet4_address": "172.19.0.1/28",
|
"inet4_address": "172.19.0.1/28",
|
||||||
%IPV6_ADDRESS%
|
//%IPV6_ADDRESS%
|
||||||
"mtu": %MTU%,
|
"mtu": %MTU%,
|
||||||
"auto_route": true,
|
"auto_route": true,
|
||||||
"strict_route": %STRICT_ROUTE%,
|
"strict_route": %STRICT_ROUTE%,
|
||||||
@@ -27,7 +70,7 @@
|
|||||||
"type": "socks",
|
"type": "socks",
|
||||||
"tag": "nekoray-socks",
|
"tag": "nekoray-socks",
|
||||||
"udp_fragment": true,
|
"udp_fragment": true,
|
||||||
%SOCKS_USER_PASS%
|
//%SOCKS_USER_PASS%
|
||||||
"server": "127.0.0.1",
|
"server": "127.0.0.1",
|
||||||
"server_port": %PORT%
|
"server_port": %PORT%
|
||||||
},
|
},
|
||||||
@@ -48,10 +91,6 @@
|
|||||||
"final": "%FINAL_OUT%",
|
"final": "%FINAL_OUT%",
|
||||||
"auto_detect_interface": true,
|
"auto_detect_interface": true,
|
||||||
"rules": [
|
"rules": [
|
||||||
{
|
|
||||||
"inbound": "dns-in",
|
|
||||||
"outbound": "dns-out"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"network": "udp",
|
"network": "udp",
|
||||||
"port": [
|
"port": [
|
||||||
@@ -93,9 +132,13 @@
|
|||||||
"nekobox_core.exe"
|
"nekobox_core.exe"
|
||||||
],
|
],
|
||||||
"outbound": "direct"
|
"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>
|
<source>Format</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</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>
|
||||||
<context>
|
<context>
|
||||||
<name>DialogVPNSettings</name>
|
<name>DialogVPNSettings</name>
|
||||||
|
|||||||
@@ -688,6 +688,12 @@ These settings can be changed later.</source>
|
|||||||
<source>Remove routing: %1</source>
|
<source>Remove routing: %1</source>
|
||||||
<translation>Удалить маршруты: %1</translation>
|
<translation>Удалить маршруты: %1</translation>
|
||||||
</message>
|
</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>
|
||||||
<context>
|
<context>
|
||||||
<name>DialogVPNSettings</name>
|
<name>DialogVPNSettings</name>
|
||||||
|
|||||||
@@ -689,6 +689,14 @@ These settings can be changed later.</source>
|
|||||||
<source>Format</source>
|
<source>Format</source>
|
||||||
<translation>格式化</translation>
|
<translation>格式化</translation>
|
||||||
</message>
|
</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>
|
||||||
<context>
|
<context>
|
||||||
<name>DialogVPNSettings</name>
|
<name>DialogVPNSettings</name>
|
||||||
@@ -1650,7 +1658,7 @@ Release note:
|
|||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Default</source>
|
<source>Default</source>
|
||||||
<translation type="unfinished">默认</translation>
|
<translation>默认</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>650</width>
|
<width>600</width>
|
||||||
<height>500</height>
|
<height>400</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<item row="2" column="3">
|
<item row="2" column="3">
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>3</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab_1">
|
<widget class="QWidget" name="tab_1">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
@@ -606,7 +606,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="mux_padding">
|
<widget class="QCheckBox" name="mux_padding">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>padding</string>
|
<string notr="true">Padding</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -701,8 +701,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>515</width>
|
<width>198</width>
|
||||||
<height>315</height>
|
<height>58</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||||
|
|||||||
@@ -159,6 +159,11 @@ For sing-box, it sets inbound.domain_strategy</string>
|
|||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_8">
|
<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">
|
<property name="text">
|
||||||
<string>Direct DNS</string>
|
<string>Direct DNS</string>
|
||||||
</property>
|
</property>
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ADD_ASTERISK(this);
|
ADD_ASTERISK(this);
|
||||||
|
|
||||||
ui->fake_dns->setVisible(!IS_NEKO_BOX);
|
|
||||||
ui->fake_dns->setChecked(NekoGui::dataStore->fake_dns);
|
ui->fake_dns->setChecked(NekoGui::dataStore->fake_dns);
|
||||||
//
|
|
||||||
ui->vpn_implementation->setCurrentIndex(NekoGui::dataStore->vpn_implementation);
|
ui->vpn_implementation->setCurrentIndex(NekoGui::dataStore->vpn_implementation);
|
||||||
ui->vpn_mtu->setCurrentText(Int2String(NekoGui::dataStore->vpn_mtu));
|
ui->vpn_mtu->setCurrentText(Int2String(NekoGui::dataStore->vpn_mtu));
|
||||||
ui->vpn_ipv6->setChecked(NekoGui::dataStore->vpn_ipv6);
|
ui->vpn_ipv6->setChecked(NekoGui::dataStore->vpn_ipv6);
|
||||||
|
|||||||
@@ -376,6 +376,12 @@ void MainWindow::neko_start(int _id) {
|
|||||||
restartMsgboxTimer->cancel();
|
restartMsgboxTimer->cancel();
|
||||||
restartMsgboxTimer->deleteLater();
|
restartMsgboxTimer->deleteLater();
|
||||||
restartMsgbox->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