move default outbound to routing profile

This commit is contained in:
Nova 2025-06-01 07:50:14 +03:30
parent e6bf936c8e
commit 61af47367f
9 changed files with 72 additions and 64 deletions

View File

@ -5,6 +5,23 @@
#include "include/global/NekoGui.hpp" #include "include/global/NekoGui.hpp"
namespace NekoGui { namespace NekoGui {
enum outboundID {proxyID=-1, directID=-2, blockID=-3, dnsOutID=-4};
inline QString outboundIDToString(int id)
{
if (id == proxyID) return {"proxy"};
if (id == directID) return {"direct"};
if (id == blockID) return {"block"};
if (id == dnsOutID) return {"dns"};
return {"unknown"};
}
inline outboundID stringToOutboundID(const QString& out)
{
if (out == "proxy") return proxyID;
if (out == "direct") return directID;
if (out == "block") return blockID;
if (out == "dns_out") return dnsOutID;
return proxyID;
}
enum inputType {trufalse, select, text}; enum inputType {trufalse, select, text};
const int IranBypassChainID = 111111111; const int IranBypassChainID = 111111111;
const int ChinaBypassChainID = 222222222; const int ChinaBypassChainID = 222222222;
@ -57,7 +74,7 @@ namespace NekoGui {
QList<QString> process_path_regex; QList<QString> process_path_regex;
QList<QString> rule_set; QList<QString> rule_set;
bool invert = false; bool invert = false;
int outboundID = -2; // -1 is proxy -2 is direct -3 is block -4 is dns_out int outboundID = directID; // -1 is proxy -2 is direct -3 is block -4 is dns_out
// since sing-box 1.11.0 // since sing-box 1.11.0
QString action = "route"; QString action = "route";
@ -94,6 +111,7 @@ namespace NekoGui {
QString name = ""; QString name = "";
QList<std::shared_ptr<RouteRule>> Rules; QList<std::shared_ptr<RouteRule>> Rules;
QList<JsonStore*> castedRules; QList<JsonStore*> castedRules;
int defaultOutboundID = proxyID;
RoutingChain(); RoutingChain();

View File

@ -7,7 +7,6 @@ namespace NekoGui {
class Routing : public JsonStore { class Routing : public JsonStore {
public: public:
int current_route_id = 0; int current_route_id = 0;
QString def_outbound = "proxy";
// DNS // DNS
QString remote_dns = "tls://8.8.8.8"; QString remote_dns = "tls://8.8.8.8";

View File

@ -34,6 +34,20 @@
<item> <item>
<widget class="QGroupBox" name="simple_direct_box"> <widget class="QGroupBox" name="simple_direct_box">
<layout class="QVBoxLayout" name="verticalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QComboBox" name="def_out">
<item>
<property name="text">
<string>proxy</string>
</property>
</item>
<item>
<property name="text">
<string>direct</string>
</property>
</item>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">

View File

@ -27,61 +27,8 @@
<item> <item>
<widget class="QWidget" name="widget" native="true"> <widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="1"> <item row="4" column="1">
<widget class="QComboBox" name="outbound_domain_strategy"> <widget class="QComboBox" name="route_prof"/>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="domainStrategyCombo">
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="route_prof_l">
<property name="text">
<string>Routing Profile</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="default_out">
<item>
<property name="text">
<string notr="true">proxy</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">direct</string>
</property>
</item>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="default_out_l">
<property name="toolTip">
<string>The outbound tag to use when the request is not handled by any rule</string>
</property>
<property name="text">
<string>Default Outbound</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="toolTip">
<string notr="true">inbound.domain_strategy
when used, domain destinations are resolved to IP before routing.</string>
</property>
<property name="text">
<string>Inbound Domain Strategy</string>
</property>
</widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
@ -95,8 +42,12 @@ also if the connection cannot be established with the current address family (ip
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="3" column="1">
<widget class="QComboBox" name="route_prof"/> <widget class="QComboBox" name="outbound_domain_strategy">
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
@ -108,6 +59,17 @@ also if the connection cannot be established with the current address family (ip
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="toolTip">
<string notr="true">inbound.domain_strategy
when used, domain destinations are resolved to IP before routing.</string>
</property>
<property name="text">
<string>Inbound Domain Strategy</string>
</property>
</widget>
</item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QComboBox" name="sniffing_mode"> <widget class="QComboBox" name="sniffing_mode">
<item> <item>
@ -127,6 +89,20 @@ also if the connection cannot be established with the current address family (ip
</item> </item>
</widget> </widget>
</item> </item>
<item row="4" column="0">
<widget class="QLabel" name="route_prof_l">
<property name="text">
<string>Routing Profile</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="domainStrategyCombo">
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -520,7 +520,7 @@ namespace NekoGui {
if (dataStore->vpn_ipv6) tunAddress += "fdfe:dcba:9876::1/96"; if (dataStore->vpn_ipv6) tunAddress += "fdfe:dcba:9876::1/96";
inboundObj["address"] = tunAddress; inboundObj["address"] = tunAddress;
inboundObj["domain_strategy"] = dataStore->routing->domain_strategy; inboundObj["domain_strategy"] = dataStore->routing->domain_strategy;
if (dataStore->enable_tun_routing && dataStore->routing->def_outbound == "proxy") if (dataStore->enable_tun_routing && routeChain->defaultOutboundID == proxyID)
{ {
if (!directIPCIDRs.isEmpty()) inboundObj["route_exclude_address"] = directIPCIDRs; if (!directIPCIDRs.isEmpty()) inboundObj["route_exclude_address"] = directIPCIDRs;
if (!directIPSets.isEmpty()) inboundObj["route_exclude_address_set"] = directIPSets; if (!directIPSets.isEmpty()) inboundObj["route_exclude_address_set"] = directIPSets;
@ -592,7 +592,7 @@ namespace NekoGui {
{ {
routeObj["find_process"] = true; routeObj["find_process"] = true;
} }
if (!status->forTest) routeObj["final"] = dataStore->routing->def_outbound; if (!status->forTest) routeObj["final"] = outboundIDToString(routeChain->defaultOutboundID);
if (dataStore->routing->sniffing_mode != SniffingMode::DISABLE) if (dataStore->routing->sniffing_mode != SniffingMode::DISABLE)
{ {

View File

@ -815,6 +815,7 @@ namespace NekoGui {
_add(new configItem("id", &id, itemType::integer)); _add(new configItem("id", &id, itemType::integer));
_add(new configItem("name", &name, itemType::string)); _add(new configItem("name", &name, itemType::string));
_add(new configItem("default_outbound", &defaultOutboundID, itemType::integer));
_add(new configItem("rules", &castedRules, itemType::jsonStoreList)); _add(new configItem("rules", &castedRules, itemType::jsonStoreList));
} }

View File

@ -334,7 +334,6 @@ namespace NekoGui {
if (!Preset::SingBox::DomainStrategy.contains(domain_strategy)) domain_strategy = ""; if (!Preset::SingBox::DomainStrategy.contains(domain_strategy)) domain_strategy = "";
if (!Preset::SingBox::DomainStrategy.contains(outbound_domain_strategy)) outbound_domain_strategy = ""; if (!Preset::SingBox::DomainStrategy.contains(outbound_domain_strategy)) outbound_domain_strategy = "";
_add(new configItem("current_route_id", &this->current_route_id, itemType::integer)); _add(new configItem("current_route_id", &this->current_route_id, itemType::integer));
_add(new configItem("default_outbound", &this->def_outbound, itemType::string));
// //
_add(new configItem("remote_dns", &this->remote_dns, itemType::string)); _add(new configItem("remote_dns", &this->remote_dns, itemType::string));
_add(new configItem("remote_dns_strategy", &this->remote_dns_strategy, itemType::string)); _add(new configItem("remote_dns_strategy", &this->remote_dns_strategy, itemType::string));

View File

@ -121,6 +121,8 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<NekoGui::RoutingChai
ui->rule_preview->setReadOnly(true); ui->rule_preview->setReadOnly(true);
updateRuleSection(); updateRuleSection();
ui->def_out->setCurrentText(NekoGui::outboundIDToString(chain->defaultOutboundID));
// simple rules setup // simple rules setup
QStringList ruleItems = {"domain:", "suffix:", "regex:", "keyword:", "ip:", "processName:", "processPath:"}; QStringList ruleItems = {"domain:", "suffix:", "regex:", "keyword:", "ip:", "processName:", "processPath:"};
for (const auto& geoIP : geoIpList) { for (const auto& geoIP : geoIpList) {
@ -337,6 +339,7 @@ void RouteItem::accept() {
}); });
return; return;
} }
chain->defaultOutboundID = NekoGui::stringToOutboundID(ui->def_out->currentText());
emit settingsChanged(chain); emit settingsChanged(chain);

View File

@ -76,7 +76,6 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
QStringList qsValue = {""}; QStringList qsValue = {""};
QString dnsHelpDocumentUrl; QString dnsHelpDocumentUrl;
ui->default_out->setCurrentText(NekoGui::dataStore->routing->def_outbound);
ui->outbound_domain_strategy->addItems(Preset::SingBox::DomainStrategy); ui->outbound_domain_strategy->addItems(Preset::SingBox::DomainStrategy);
ui->domainStrategyCombo->addItems(Preset::SingBox::DomainStrategy); ui->domainStrategyCombo->addItems(Preset::SingBox::DomainStrategy);
qsValue += QString("prefer_ipv4 prefer_ipv6 ipv4_only ipv6_only").split(" "); qsValue += QString("prefer_ipv4 prefer_ipv6 ipv4_only ipv6_only").split(" ");
@ -209,7 +208,6 @@ void DialogManageRoutes::accept() {
NekoGui::profileManager->UpdateRouteChains(chainList); NekoGui::profileManager->UpdateRouteChains(chainList);
NekoGui::dataStore->routing->current_route_id = currentRoute->id; NekoGui::dataStore->routing->current_route_id = currentRoute->id;
NekoGui::dataStore->routing->def_outbound = ui->default_out->currentText();
NekoGui::dataStore->enable_dns_server = ui->dnshijack_enable->isChecked(); NekoGui::dataStore->enable_dns_server = ui->dnshijack_enable->isChecked();
NekoGui::dataStore->dns_server_listen_port = ui->dnshijack_listenport->text().toInt(); NekoGui::dataStore->dns_server_listen_port = ui->dnshijack_listenport->text().toInt();