mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-03 18:24:58 +00:00
Fix implementation of using Clash rule-providers as rule sources
Add option for whether to try to resolve hostnames when generating ShadowsocksR nodes in Surge configurations.
This commit is contained in:
5 files changed
+37
-9
No files matched your search
@@ -62,6 +62,7 @@ managed_config:
|
|||||||
|
|
||||||
surge_external_proxy:
|
surge_external_proxy:
|
||||||
surge_ssr_path: "" # /usr/bin/ssr-local
|
surge_ssr_path: "" # /usr/bin/ssr-local
|
||||||
|
resolve_hostname: true
|
||||||
|
|
||||||
emojis:
|
emojis:
|
||||||
add_emoji: true
|
add_emoji: true
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ quanx_device_id=
|
|||||||
|
|
||||||
[surge_external_proxy]
|
[surge_external_proxy]
|
||||||
;surge_ssr_path=/usr/bin/ssr-local
|
;surge_ssr_path=/usr/bin/ssr-local
|
||||||
|
resolve_hostname=true
|
||||||
|
|
||||||
[emojis]
|
[emojis]
|
||||||
add_emoji=true
|
add_emoji=true
|
||||||
|
|||||||
+5
-1
@@ -30,7 +30,7 @@ std::string listen_address = "127.0.0.1", default_url, insert_url, managed_confi
|
|||||||
int listen_port = 25500, max_pending_connections = 10, max_concurrent_threads = 4;
|
int listen_port = 25500, max_pending_connections = 10, max_concurrent_threads = 4;
|
||||||
bool prepend_insert_url = true;
|
bool prepend_insert_url = true;
|
||||||
bool api_mode = true, write_managed_config = false, enable_rule_generator = true, update_ruleset_on_request = false, overwrite_original_rules = true;
|
bool api_mode = true, write_managed_config = false, enable_rule_generator = true, update_ruleset_on_request = false, overwrite_original_rules = true;
|
||||||
bool print_debug_info = false, cfw_child_process = false, append_userinfo = true, enable_base_gen = false, async_fetch_ruleset = false;
|
bool print_debug_info = false, cfw_child_process = false, append_userinfo = true, enable_base_gen = false, async_fetch_ruleset = false, surge_ssr_resolve = true;
|
||||||
std::string access_token, base_path = "base";
|
std::string access_token, base_path = "base";
|
||||||
extern std::string custom_group;
|
extern std::string custom_group;
|
||||||
extern int global_log_level;
|
extern int global_log_level;
|
||||||
@@ -676,7 +676,10 @@ void readYAMLConf(YAML::Node &node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(node["surge_external_proxy"].IsDefined())
|
if(node["surge_external_proxy"].IsDefined())
|
||||||
|
{
|
||||||
node["surge_external_proxy"]["surge_ssr_path"] >> surge_ssr_path;
|
node["surge_external_proxy"]["surge_ssr_path"] >> surge_ssr_path;
|
||||||
|
node["surge_external_proxy"]["resolve_hostname"] >> surge_ssr_resolve;
|
||||||
|
}
|
||||||
|
|
||||||
if(node["emojis"].IsDefined())
|
if(node["emojis"].IsDefined())
|
||||||
{
|
{
|
||||||
@@ -869,6 +872,7 @@ void readConf()
|
|||||||
{
|
{
|
||||||
ini.EnterSection("surge_external_proxy");
|
ini.EnterSection("surge_external_proxy");
|
||||||
ini.GetIfExist("surge_ssr_path", surge_ssr_path);
|
ini.GetIfExist("surge_ssr_path", surge_ssr_path);
|
||||||
|
ini.GetBoolIfExist("resolve_hostname", surge_ssr_resolve);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ini.SectionExist("node_pref"))
|
if(ini.SectionExist("node_pref"))
|
||||||
|
|||||||
+6
-3
@@ -24,7 +24,7 @@
|
|||||||
#include "yamlcpp_extra.h"
|
#include "yamlcpp_extra.h"
|
||||||
#include "interfaces.h"
|
#include "interfaces.h"
|
||||||
|
|
||||||
extern bool api_mode;
|
extern bool api_mode, surge_ssr_resolve;
|
||||||
extern string_array ss_ciphers, ssr_ciphers;
|
extern string_array ss_ciphers, ssr_ciphers;
|
||||||
extern size_t max_allowed_rules;
|
extern size_t max_allowed_rules;
|
||||||
|
|
||||||
@@ -1611,8 +1611,11 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, const std::string &base_c
|
|||||||
{
|
{
|
||||||
return std::move(a) + "\", args=\"" + std::move(b);
|
return std::move(a) + "\", args=\"" + std::move(b);
|
||||||
});
|
});
|
||||||
proxy += "\", local-port=" + std::to_string(local_port) + ", addresses=" + ((isIPv4(hostname) || isIPv6(hostname)) ? hostname : hostnameToIPAddr(hostname));
|
proxy += "\", local-port=" + std::to_string(local_port);
|
||||||
//proxy += "\", local-port=" + std::to_string(local_port);
|
if(isIPv4(hostname) || isIPv6(hostname))
|
||||||
|
proxy += ", addresses=" + hostname;
|
||||||
|
else if(surge_ssr_resolve)
|
||||||
|
proxy += ", addresses=" + hostnameToIPAddr(hostname);
|
||||||
local_port++;
|
local_port++;
|
||||||
break;
|
break;
|
||||||
case SPEEDTEST_MESSAGE_FOUNDSOCKS:
|
case SPEEDTEST_MESSAGE_FOUNDSOCKS:
|
||||||
|
|||||||
+24
-5
@@ -232,8 +232,8 @@ std::string findFileName(const std::string &path)
|
|||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
string_size pos2 = path.rfind('.');
|
string_size pos2 = path.rfind('.');
|
||||||
if(pos2 < pos)
|
if(pos2 < pos || pos2 == path.npos)
|
||||||
pos2 = path.size() - 1;
|
pos2 = path.size();
|
||||||
return path.substr(pos + 1, pos2 - pos - 1);
|
return path.substr(pos + 1, pos2 - pos - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector<ruleset_content> &rules
|
|||||||
string_array vArray, groups;
|
string_array vArray, groups;
|
||||||
string_map keywords, urls, names;
|
string_map keywords, urls, names;
|
||||||
std::map<std::string, bool> has_domain, has_ipcidr;
|
std::map<std::string, bool> has_domain, has_ipcidr;
|
||||||
std::map<std::string, int> ruleset_interval;
|
std::map<std::string, int> ruleset_interval, rule_type;
|
||||||
string_array rules;
|
string_array rules;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@@ -293,6 +293,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector<ruleset_content> &rules
|
|||||||
rule_name = old_rule_name + "_" + std::to_string(idx++);
|
rule_name = old_rule_name + "_" + std::to_string(idx++);
|
||||||
names[rule_name] = rule_group;
|
names[rule_name] = rule_group;
|
||||||
urls[rule_name] = "*" + rule_path;
|
urls[rule_name] = "*" + rule_path;
|
||||||
|
rule_type[rule_name] = x.rule_type;
|
||||||
ruleset_interval[rule_name] = x.update_interval;
|
ruleset_interval[rule_name] = x.update_interval;
|
||||||
switch(x.rule_type)
|
switch(x.rule_type)
|
||||||
{
|
{
|
||||||
@@ -400,13 +401,31 @@ int renderClashScript(YAML::Node &base_rule, std::vector<ruleset_content> &rules
|
|||||||
if(clash_classical_ruleset)
|
if(clash_classical_ruleset)
|
||||||
{
|
{
|
||||||
std::string yaml_key = x;
|
std::string yaml_key = x;
|
||||||
|
|
||||||
|
switch(rule_type[yaml_key])
|
||||||
|
{
|
||||||
|
case RULESET_CLASH_CLASSICAL:
|
||||||
|
base_rule["rule-providers"][yaml_key]["behavior"] = "classical";
|
||||||
|
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + x + "_classical.yaml";
|
||||||
|
break;
|
||||||
|
case RULESET_CLASH_DOMAIN:
|
||||||
|
yaml_key += "_domain";
|
||||||
|
base_rule["rule-providers"][yaml_key]["behavior"] = "domain";
|
||||||
|
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + x + "_domain.yaml";
|
||||||
|
break;
|
||||||
|
case RULESET_CLASH_IPCIDR:
|
||||||
|
yaml_key += "_ipcidr";
|
||||||
|
base_rule["rule-providers"][yaml_key]["behavior"] = "ipcidr";
|
||||||
|
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + x + "_ipcidr.yaml";
|
||||||
|
break;
|
||||||
|
}
|
||||||
base_rule["rule-providers"][yaml_key]["type"] = "http";
|
base_rule["rule-providers"][yaml_key]["type"] = "http";
|
||||||
base_rule["rule-providers"][yaml_key]["behavior"] = "classical";
|
|
||||||
if(url[0] == '*')
|
if(url[0] == '*')
|
||||||
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
|
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
|
||||||
else
|
else
|
||||||
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=6&url=" + urlsafe_base64_encode(url);
|
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=6&url=" + urlsafe_base64_encode(url);
|
||||||
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + x + "_classical.yaml";
|
|
||||||
if(interval)
|
if(interval)
|
||||||
base_rule["rule-providers"][yaml_key]["interval"] = interval;
|
base_rule["rule-providers"][yaml_key]["interval"] = interval;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user