mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 05:30:06 +08:00
Better local DNS override handling
This commit is contained in:
parent
6a99a956b6
commit
ede263056a
@ -4,6 +4,14 @@
|
||||
#include "include/sys/Process.hpp"
|
||||
|
||||
namespace Configs {
|
||||
enum OSType
|
||||
{
|
||||
Unknown = 0,
|
||||
Linux = 1,
|
||||
Windows = 2,
|
||||
Darwin = 3,
|
||||
};
|
||||
|
||||
class ExtraCoreData
|
||||
{
|
||||
public:
|
||||
@ -52,6 +60,20 @@ namespace Configs {
|
||||
QJsonArray endpoints;
|
||||
};
|
||||
|
||||
inline OSType getOS()
|
||||
{
|
||||
#ifdef Q_OS_MACOS
|
||||
return Darwin;
|
||||
#endif
|
||||
#ifdef Q_OS_LINUX
|
||||
return Linux;
|
||||
#endif
|
||||
#ifdef Q_OS_WIN
|
||||
return Windows;
|
||||
#endif
|
||||
return Unknown;
|
||||
};
|
||||
|
||||
bool IsValid(const std::shared_ptr<ProxyEntity> &ent);
|
||||
|
||||
std::shared_ptr<BuildTestConfigResult> BuildTestConfig(const QList<std::shared_ptr<ProxyEntity>>& profiles, const std::map<std::string, std::string>& ruleSetMap);
|
||||
|
||||
@ -284,7 +284,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<item row="5" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="dns_final_out_l">
|
||||
@ -309,17 +309,8 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" 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>
|
||||
</widget>
|
||||
<item row="3" column="2">
|
||||
<widget class="QLineEdit" name="local_override"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
@ -368,6 +359,28 @@ For more information, see the document "Configuration/DNS".</string>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Local DNS can not be used in some configurations, you will have to set an ip here to be used as local dns in such situations</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Local Override</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" 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>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
@ -420,7 +433,7 @@ For more information, see the document "Configuration/DNS".</string>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="enable_fakeip">
|
||||
<property name="text">
|
||||
<string>Enable FakeIP</string>
|
||||
|
||||
@ -434,6 +434,13 @@ namespace Configs {
|
||||
{"type", "underlying"}
|
||||
};
|
||||
}
|
||||
if (tunEnabled && getOS() == Darwin)
|
||||
{
|
||||
return {
|
||||
{"type", "udp"},
|
||||
{"server", dataStore->core_box_underlying_dns}
|
||||
};
|
||||
}
|
||||
return {
|
||||
{"type", "local"}
|
||||
};
|
||||
@ -522,6 +529,12 @@ namespace Configs {
|
||||
}
|
||||
}
|
||||
routeChain->Save();
|
||||
|
||||
if (getOS() == Darwin && dataStore->core_box_underlying_dns.isEmpty() && dataStore->spmode_vpn)
|
||||
{
|
||||
status->result->error = QObject::tr("Local DNS and Tun mode do not work together, please set an IP to be used as the Local DNS server in the Routing Settings -> Local override");
|
||||
return;
|
||||
}
|
||||
|
||||
// copy for modification
|
||||
routeChain = std::make_shared<RoutingChain>(*routeChain);
|
||||
@ -789,7 +802,7 @@ namespace Configs {
|
||||
};
|
||||
}
|
||||
}
|
||||
if (Configs::dataStore->adblock_enable) {
|
||||
if (dataStore->adblock_enable) {
|
||||
ruleSetArray += QJsonObject{
|
||||
{"type", "remote"},
|
||||
{"tag", "throne-adblocksingbox"},
|
||||
@ -925,7 +938,7 @@ namespace Configs {
|
||||
};
|
||||
}
|
||||
|
||||
// Underlying 100% Working DNS
|
||||
// Underlying DNS
|
||||
auto dnsLocalAddress = dataStore->core_box_underlying_dns.isEmpty() ? "local" : dataStore->core_box_underlying_dns;
|
||||
auto dnsLocalObj = BuildDnsObject(dnsLocalAddress, dataStore->spmode_vpn);
|
||||
dnsLocalObj["tag"] = "dns-local";
|
||||
|
||||
@ -269,19 +269,8 @@ void DialogBasicSettings::on_core_settings_clicked() {
|
||||
auto line = -1;
|
||||
MyLineEdit *core_box_clash_api;
|
||||
MyLineEdit *core_box_clash_api_secret;
|
||||
MyLineEdit *core_box_underlying_dns;
|
||||
MyLineEdit *core_box_clash_listen_addr;
|
||||
//
|
||||
auto core_box_underlying_dns_l = new QLabel(tr("Override underlying DNS"));
|
||||
core_box_underlying_dns_l->setToolTip(tr(
|
||||
"It is recommended to leave it blank, but it sometimes does not work, at this time you can set this option.\n"
|
||||
"this rewrites the underlying(localhost) DNS in Tun Mode, normal mode, and also URL Test."));
|
||||
core_box_underlying_dns = new MyLineEdit;
|
||||
core_box_underlying_dns->setText(Configs::dataStore->core_box_underlying_dns);
|
||||
core_box_underlying_dns->setMinimumWidth(300);
|
||||
layout->addWidget(core_box_underlying_dns_l, ++line, 0);
|
||||
layout->addWidget(core_box_underlying_dns, line, 1);
|
||||
//
|
||||
auto core_box_clash_listen_addr_l = new QLabel("Clash Api Listen Address");
|
||||
core_box_clash_listen_addr = new MyLineEdit;
|
||||
core_box_clash_listen_addr->setText(Configs::dataStore->core_box_clash_listen_addr);
|
||||
@ -304,7 +293,6 @@ void DialogBasicSettings::on_core_settings_clicked() {
|
||||
box->setOrientation(Qt::Horizontal);
|
||||
box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
||||
connect(box, &QDialogButtonBox::accepted, w, [=,this] {
|
||||
Configs::dataStore->core_box_underlying_dns = core_box_underlying_dns->text();
|
||||
Configs::dataStore->core_box_clash_api = core_box_clash_api->text().toInt();
|
||||
Configs::dataStore->core_box_clash_listen_addr = core_box_clash_listen_addr->text();
|
||||
Configs::dataStore->core_box_clash_api_secret = core_box_clash_api_secret->text();
|
||||
|
||||
@ -84,6 +84,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent, const std::map<std::stri
|
||||
|
||||
ui->direct_dns_strategy->addItems(qsValue);
|
||||
ui->remote_dns_strategy->addItems(qsValue);
|
||||
ui->local_override->setText(Configs::dataStore->core_box_underlying_dns);
|
||||
ui->enable_fakeip->setChecked(Configs::dataStore->fake_dns);
|
||||
//
|
||||
connect(ui->use_dns_object, &QCheckBox::stateChanged, this, [=,this](int state) {
|
||||
@ -200,6 +201,7 @@ void DialogManageRoutes::accept() {
|
||||
Configs::dataStore->routing->remote_dns_strategy = ui->remote_dns_strategy->currentText();
|
||||
Configs::dataStore->routing->direct_dns = ui->direct_dns->currentText();
|
||||
Configs::dataStore->routing->direct_dns_strategy = ui->direct_dns_strategy->currentText();
|
||||
Configs::dataStore->core_box_underlying_dns = ui->local_override->text().trimmed();
|
||||
Configs::dataStore->routing->dns_final_out = ui->dns_final_out->currentText();
|
||||
Configs::dataStore->fake_dns = ui->enable_fakeip->isChecked();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user