mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-07 04:03:26 +00:00
Enhancements
Add basic support for generating sing-box configs. Use cpp-httplib as web server. Optimize codes.
This commit is contained in:
32 files changed
+10286
-234
No files matched your search
+39
-23
@@ -89,30 +89,28 @@ const std::vector<UAProfile> UAMatchList = {
|
||||
{"V2RayX","","","v2ray"}
|
||||
};
|
||||
|
||||
bool verGreaterEqual(const std::string &src_ver, const std::string &target_ver)
|
||||
bool verGreaterEqual(const std::string& src_ver, const std::string& target_ver)
|
||||
{
|
||||
string_size src_pos_beg = 0, src_pos_end, target_pos_beg = 0, target_pos_end;
|
||||
while(true)
|
||||
{
|
||||
src_pos_end = src_ver.find('.', src_pos_beg);
|
||||
if(src_pos_end == src_ver.npos)
|
||||
src_pos_end = src_ver.size();
|
||||
int part_src = std::stoi(src_ver.substr(src_pos_beg, src_pos_end - src_pos_beg));
|
||||
target_pos_end = target_ver.find('.', target_pos_beg);
|
||||
if(target_pos_end == target_ver.npos)
|
||||
target_pos_end = target_ver.size();
|
||||
int part_target = std::stoi(target_ver.substr(target_pos_beg, target_pos_end - target_pos_beg));
|
||||
if(part_src > part_target)
|
||||
break;
|
||||
else if(part_src < part_target)
|
||||
return false;
|
||||
else if(src_pos_end >= src_ver.size() - 1 || target_pos_end >= target_ver.size() - 1)
|
||||
break;
|
||||
src_pos_beg = src_pos_end + 1;
|
||||
target_pos_beg = target_pos_end + 1;
|
||||
std::istringstream src_stream(src_ver), target_stream(target_ver);
|
||||
int src_part, target_part;
|
||||
char dot;
|
||||
while (src_stream >> src_part) {
|
||||
if (target_stream >> target_part) {
|
||||
if (src_part < target_part) {
|
||||
return false;
|
||||
} else if (src_part > target_part) {
|
||||
return true;
|
||||
}
|
||||
// Skip the dot separator in both streams
|
||||
src_stream >> dot;
|
||||
target_stream >> dot;
|
||||
} else {
|
||||
// If we run out of target parts, the source version is greater only if it has more parts
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
// If we get here, the common parts are equal, so check if target_ver has more parts
|
||||
return !bool(target_stream >> target_part);
|
||||
}
|
||||
|
||||
void matchUserAgent(const std::string &user_agent, std::string &target, tribool &clash_new_name, int &surge_ver)
|
||||
@@ -321,7 +319,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
||||
case "ss"_hash: case "ssd"_hash: case "ssr"_hash: case "sssub"_hash: case "v2ray"_hash: case "trojan"_hash: case "mixed"_hash:
|
||||
lSimpleSubscription = true;
|
||||
break;
|
||||
case "clash"_hash: case "clashr"_hash: case "surge"_hash: case "quan"_hash: case "quanx"_hash: case "loon"_hash: case "surfboard"_hash: case "mellow"_hash:
|
||||
case "clash"_hash: case "clashr"_hash: case "surge"_hash: case "quan"_hash: case "quanx"_hash: case "loon"_hash: case "surfboard"_hash: case "mellow"_hash: case "singbox"_hash:
|
||||
break;
|
||||
default:
|
||||
*status_code = 400;
|
||||
@@ -363,6 +361,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
||||
/// for external configuration
|
||||
std::string lClashBase = global.clashBase, lSurgeBase = global.surgeBase, lMellowBase = global.mellowBase, lSurfboardBase = global.surfboardBase;
|
||||
std::string lQuanBase = global.quanBase, lQuanXBase = global.quanXBase, lLoonBase = global.loonBase, lSSSubBase = global.SSSubBase;
|
||||
std::string lSingBoxBase = global.singBoxBase;
|
||||
|
||||
/// validate urls
|
||||
argEnableInsert.define(global.enableInsert);
|
||||
@@ -458,6 +457,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
||||
checkExternalBase(extconf.quan_rule_base, lQuanBase);
|
||||
checkExternalBase(extconf.quanx_rule_base, lQuanXBase);
|
||||
checkExternalBase(extconf.loon_rule_base, lLoonBase);
|
||||
checkExternalBase(extconf.singbox_rule_base, lSingBoxBase);
|
||||
|
||||
if(extconf.surge_ruleset.size())
|
||||
lCustomRulesets = extconf.surge_ruleset;
|
||||
@@ -877,6 +877,22 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
||||
if(argUpload)
|
||||
uploadGist("ssd", argUploadPath, output_content, false);
|
||||
break;
|
||||
case "singbox"_hash:
|
||||
writeLog(0, "Generate target: sing-box", LOG_LEVEL_INFO);
|
||||
if(!ext.nodelist)
|
||||
{
|
||||
if(render_template(fetchFile(lSingBoxBase, proxy, global.cacheConfig), tpl_args, base_content, global.templatePath) != 0)
|
||||
{
|
||||
*status_code = 400;
|
||||
return base_content;
|
||||
}
|
||||
}
|
||||
|
||||
output_content = proxyToSingBox(nodes, base_content, lRulesetContent, lCustomProxyGroups, ext);
|
||||
|
||||
if(argUpload)
|
||||
uploadGist("singbox", argUploadPath, output_content, false);
|
||||
break;
|
||||
default:
|
||||
writeLog(0, "Generate target: Unspecified", LOG_LEVEL_INFO);
|
||||
*status_code = 500;
|
||||
|
||||
@@ -331,6 +331,7 @@ void readYAMLConf(YAML::Node &node)
|
||||
section["quanx_rule_base"] >> global.quanXBase;
|
||||
section["loon_rule_base"] >> global.loonBase;
|
||||
section["sssub_rule_base"] >> global.SSSubBase;
|
||||
section["singbox_rule_base"] >> global.singBoxBase;
|
||||
|
||||
section["default_external_config"] >> global.defaultExtConfig;
|
||||
section["append_proxy_type"] >> global.appendType;
|
||||
@@ -605,6 +606,8 @@ void readTOMLConf(toml::value &root)
|
||||
"quan_rule_base", global.quanBase,
|
||||
"quanx_rule_base", global.quanXBase,
|
||||
"loon_rule_base", global.loonBase,
|
||||
"sssub_rule_base", global.SSSubBase,
|
||||
"singbox_rule_base", global.singBoxBase,
|
||||
"proxy_config", global.proxyConfig,
|
||||
"proxy_ruleset", global.proxyRuleset,
|
||||
"proxy_subscription", global.proxySubscription,
|
||||
@@ -842,6 +845,8 @@ void readConf()
|
||||
ini.get_if_exist("quan_rule_base", global.quanBase);
|
||||
ini.get_if_exist("quanx_rule_base", global.quanXBase);
|
||||
ini.get_if_exist("loon_rule_base", global.loonBase);
|
||||
ini.get_if_exist("sssub_rule_base", global.SSSubBase);
|
||||
ini.get_if_exist("singbox_rule_base", global.singBoxBase);
|
||||
ini.get_if_exist("default_external_config", global.defaultExtConfig);
|
||||
ini.get_bool_if_exist("append_proxy_type", global.appendType);
|
||||
ini.get_if_exist("proxy_config", global.proxyConfig);
|
||||
@@ -1074,6 +1079,7 @@ int loadExternalYAML(YAML::Node &node, ExternalConfig &ext)
|
||||
section["quanx_rule_base"] >> ext.quanx_rule_base;
|
||||
section["loon_rule_base"] >> ext.loon_rule_base;
|
||||
section["sssub_rule_base"] >> ext.sssub_rule_base;
|
||||
section["singbox_rule_base"] >> ext.singbox_rule_base;
|
||||
|
||||
section["enable_rule_generator"] >> ext.enable_rule_generator;
|
||||
section["overwrite_original_rules"] >> ext.overwrite_original_rules;
|
||||
@@ -1146,7 +1152,9 @@ int loadExternalTOML(toml::value &root, ExternalConfig &ext)
|
||||
"mellow_rule_base", ext.mellow_rule_base,
|
||||
"quan_rule_base", ext.quan_rule_base,
|
||||
"quanx_rule_base", ext.quanx_rule_base,
|
||||
"loon_rule_base", ext.loon_rule_base,
|
||||
"sssub_rule_base", ext.sssub_rule_base,
|
||||
"singbox_rule_base", ext.singbox_rule_base,
|
||||
"add_emoji", ext.add_emoji,
|
||||
"remove_old_emoji", ext.remove_old_emoji,
|
||||
"include_remarks", ext.include,
|
||||
@@ -1248,6 +1256,7 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
|
||||
ini.get_if_exist("quanx_rule_base", ext.quanx_rule_base);
|
||||
ini.get_if_exist("loon_rule_base", ext.loon_rule_base);
|
||||
ini.get_if_exist("sssub_rule_base", ext.sssub_rule_base);
|
||||
ini.get_if_exist("singbox_rule_base", ext.singbox_rule_base);
|
||||
|
||||
ini.get_bool_if_exist("overwrite_original_rules", ext.overwrite_original_rules);
|
||||
ini.get_bool_if_exist("enable_rule_generator", ext.enable_rule_generator);
|
||||
|
||||
@@ -54,7 +54,7 @@ struct Settings
|
||||
|
||||
std::string clashBase;
|
||||
ProxyGroupConfigs customProxyGroups;
|
||||
std::string surgeBase, surfboardBase, mellowBase, quanBase, quanXBase, loonBase, SSSubBase;
|
||||
std::string surgeBase, surfboardBase, mellowBase, quanBase, quanXBase, loonBase, SSSubBase, singBoxBase;
|
||||
std::string surgeSSRPath, quanXDevID;
|
||||
|
||||
//cache system
|
||||
@@ -83,6 +83,7 @@ struct ExternalConfig
|
||||
std::string quanx_rule_base;
|
||||
std::string loon_rule_base;
|
||||
std::string sssub_rule_base;
|
||||
std::string singbox_rule_base;
|
||||
RegexMatchConfigs rename;
|
||||
RegexMatchConfigs emoji;
|
||||
string_array include;
|
||||
|
||||
Reference in new issue
Block a user