mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-02 01:33:04 +00:00
Enhancements
Fix support for generating Loon configs. Refactor libraries.
This commit is contained in:
1 parent
4205dee94a
commit
deb73c5669
24 files changed
+605
-618
No files matched your search
+24
-24
@@ -958,15 +958,15 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
|
||||
|
||||
base_content = fetchFile(url, proxy, global.cacheConfig);
|
||||
|
||||
if(ini.Parse(base_content) != INIREADER_EXCEPTION_NONE)
|
||||
if(ini.parse(base_content) != INIREADER_EXCEPTION_NONE)
|
||||
{
|
||||
std::string errmsg = "Parsing Surge config failed! Reason: " + ini.GetLastError();
|
||||
std::string errmsg = "Parsing Surge config failed! Reason: " + ini.get_last_error();
|
||||
//std::cerr<<errmsg<<"\n";
|
||||
writeLog(0, errmsg, LOG_LEVEL_ERROR);
|
||||
*status_code = 400;
|
||||
return errmsg;
|
||||
}
|
||||
if(!ini.SectionExist("Proxy") || !ini.SectionExist("Proxy Group") || !ini.SectionExist("Rule"))
|
||||
if(!ini.section_exist("Proxy") || !ini.section_exist("Proxy Group") || !ini.section_exist("Rule"))
|
||||
{
|
||||
std::string errmsg = "Incomplete surge config! Missing critical sections!";
|
||||
//std::cerr<<errmsg<<"\n";
|
||||
@@ -977,7 +977,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
|
||||
|
||||
//scan groups first, get potential policy-path
|
||||
string_multimap section;
|
||||
ini.GetItems("Proxy Group", section);
|
||||
ini.get_items("Proxy Group", section);
|
||||
std::string name, type, content;
|
||||
string_array links;
|
||||
links.emplace_back(url);
|
||||
@@ -1058,7 +1058,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
|
||||
proxyToClash(nodes, clash, dummy_groups, false, ext);
|
||||
|
||||
section.clear();
|
||||
ini.GetItems("Proxy", section);
|
||||
ini.get_items("Proxy", section);
|
||||
for(auto &x : section)
|
||||
{
|
||||
singlegroup.reset();
|
||||
@@ -1088,7 +1088,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
|
||||
}
|
||||
|
||||
eraseElements(dummy_str_array);
|
||||
ini.GetAll("Rule", "{NONAME}", dummy_str_array);
|
||||
ini.get_all("Rule", "{NONAME}", dummy_str_array);
|
||||
YAML::Node rule;
|
||||
string_array strArray;
|
||||
std::string strLine;
|
||||
@@ -1166,17 +1166,17 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS)
|
||||
//std::cerr<<"Trying to load profile '" + name + "'.\n";
|
||||
writeLog(0, "Trying to load profile '" + name + "'.", LOG_LEVEL_INFO);
|
||||
INIReader ini;
|
||||
if(ini.Parse(profile_content) != INIREADER_EXCEPTION_NONE && !ini.SectionExist("Profile"))
|
||||
if(ini.parse(profile_content) != INIREADER_EXCEPTION_NONE && !ini.section_exist("Profile"))
|
||||
{
|
||||
//std::cerr<<"Load profile failed! Reason: "<<ini.GetLastError()<<"\n";
|
||||
writeLog(0, "Load profile failed! Reason: " + ini.GetLastError(), LOG_LEVEL_ERROR);
|
||||
//std::cerr<<"Load profile failed! Reason: "<<ini.get_last_error()<<"\n";
|
||||
writeLog(0, "Load profile failed! Reason: " + ini.get_last_error(), LOG_LEVEL_ERROR);
|
||||
*status_code = 500;
|
||||
return "Broken profile!";
|
||||
}
|
||||
//std::cerr<<"Trying to parse profile '" + name + "'.\n";
|
||||
writeLog(0, "Trying to parse profile '" + name + "'.", LOG_LEVEL_INFO);
|
||||
string_multimap contents;
|
||||
ini.GetItems("Profile", contents);
|
||||
ini.get_items("Profile", contents);
|
||||
if(!contents.size())
|
||||
{
|
||||
//std::cerr<<"Load profile failed! Reason: Empty Profile section\n";
|
||||
@@ -1218,12 +1218,12 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS)
|
||||
writeLog(0, "Ignoring non-exist profile '" + name + "'...", LOG_LEVEL_WARNING);
|
||||
continue;
|
||||
}
|
||||
if(ini.ParseFile(name) != INIREADER_EXCEPTION_NONE && !ini.SectionExist("Profile"))
|
||||
if(ini.parse_file(name) != INIREADER_EXCEPTION_NONE && !ini.section_exist("Profile"))
|
||||
{
|
||||
writeLog(0, "Ignoring broken profile '" + name + "'...", LOG_LEVEL_WARNING);
|
||||
continue;
|
||||
}
|
||||
url = ini.Get("Profile", "url");
|
||||
url = ini.get("Profile", "url");
|
||||
if(url.size())
|
||||
{
|
||||
all_urls += "|" + url;
|
||||
@@ -1308,16 +1308,16 @@ int simpleGenerator()
|
||||
}
|
||||
|
||||
INIReader ini;
|
||||
if(ini.Parse(config) != INIREADER_EXCEPTION_NONE)
|
||||
if(ini.parse(config) != INIREADER_EXCEPTION_NONE)
|
||||
{
|
||||
//std::cerr<<"Generator configuration broken! Reason:"<<ini.GetLastError()<<"\n";
|
||||
writeLog(0, "Generator configuration broken! Reason:" + ini.GetLastError(), LOG_LEVEL_ERROR);
|
||||
//std::cerr<<"Generator configuration broken! Reason:"<<ini.get_last_error()<<"\n";
|
||||
writeLog(0, "Generator configuration broken! Reason:" + ini.get_last_error(), LOG_LEVEL_ERROR);
|
||||
return -2;
|
||||
}
|
||||
//std::cerr<<"Read generator configuration completed.\n\n";
|
||||
writeLog(0, "Read generator configuration completed.\n", LOG_LEVEL_INFO);
|
||||
|
||||
string_array sections = ini.GetSections();
|
||||
string_array sections = ini.get_section_names();
|
||||
if(global.generateProfiles.size())
|
||||
{
|
||||
//std::cerr<<"Generating with specific artifacts: \""<<gen_profile<<"\"...\n";
|
||||
@@ -1352,26 +1352,26 @@ int simpleGenerator()
|
||||
response.status_code = 200;
|
||||
//std::cerr<<"Generating artifact '"<<x<<"'...\n";
|
||||
writeLog(0, "Generating artifact '" + x + "'...", LOG_LEVEL_INFO);
|
||||
ini.EnterSection(x);
|
||||
if(ini.ItemExist("path"))
|
||||
path = ini.Get("path");
|
||||
ini.enter_section(x);
|
||||
if(ini.item_exist("path"))
|
||||
path = ini.get("path");
|
||||
else
|
||||
{
|
||||
//std::cerr<<"Artifact '"<<x<<"' output path missing! Skipping...\n\n";
|
||||
writeLog(0, "Artifact '" + x + "' output path missing! Skipping...\n", LOG_LEVEL_ERROR);
|
||||
continue;
|
||||
}
|
||||
if(ini.ItemExist("profile"))
|
||||
if(ini.item_exist("profile"))
|
||||
{
|
||||
profile = ini.Get("profile");
|
||||
profile = ini.get("profile");
|
||||
request.argument = "name=" + urlEncode(profile) + "&token=" + global.accessToken + "&expand=true";
|
||||
content = getProfile(request, response);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ini.GetBool("direct") == true)
|
||||
if(ini.get_bool("direct") == true)
|
||||
{
|
||||
std::string url = ini.Get("url");
|
||||
std::string url = ini.get("url");
|
||||
content = fetchFile(url, proxy, global.cacheSubscription);
|
||||
if(content.empty())
|
||||
{
|
||||
@@ -1384,7 +1384,7 @@ int simpleGenerator()
|
||||
fileWrite(path, "\xEF\xBB\xBF" + content, true);
|
||||
continue;
|
||||
}
|
||||
ini.GetItems(allItems);
|
||||
ini.get_items(allItems);
|
||||
allItems.emplace("expand", "true");
|
||||
for(auto &y : allItems)
|
||||
{
|
||||
|
||||
+143
-143
@@ -804,7 +804,7 @@ void readConf()
|
||||
try
|
||||
{
|
||||
std::string prefdata = fileGet(global.prefPath, false);
|
||||
if(prefdata.find("common:") != prefdata.npos)
|
||||
if(prefdata.find("common:") != std::string::npos)
|
||||
{
|
||||
YAML::Node yaml = YAML::Load(prefdata);
|
||||
if(yaml.size() && yaml["common"])
|
||||
@@ -830,69 +830,69 @@ void readConf()
|
||||
INIReader ini;
|
||||
ini.allow_dup_section_titles = true;
|
||||
//ini.do_utf8_to_gbk = true;
|
||||
int retVal = ini.ParseFile(global.prefPath);
|
||||
int retVal = ini.parse_file(global.prefPath);
|
||||
if(retVal != INIREADER_EXCEPTION_NONE)
|
||||
{
|
||||
writeLog(0, "Unable to load preference settings as INI. Reason: " + ini.GetLastError(), LOG_LEVEL_FATAL);
|
||||
writeLog(0, "Unable to load preference settings as INI. Reason: " + ini.get_last_error(), LOG_LEVEL_FATAL);
|
||||
return;
|
||||
}
|
||||
|
||||
string_array tempArray;
|
||||
|
||||
ini.EnterSection("common");
|
||||
ini.GetBoolIfExist("api_mode", global.APIMode);
|
||||
ini.GetIfExist("api_access_token", global.accessToken);
|
||||
ini.GetIfExist("default_url", global.defaultUrls);
|
||||
global.enableInsert = ini.Get("enable_insert");
|
||||
ini.GetIfExist("insert_url", global.insertUrls);
|
||||
ini.GetBoolIfExist("prepend_insert_url", global.prependInsert);
|
||||
if(ini.ItemPrefixExist("exclude_remarks"))
|
||||
ini.GetAll("exclude_remarks", global.excludeRemarks);
|
||||
if(ini.ItemPrefixExist("include_remarks"))
|
||||
ini.GetAll("include_remarks", global.includeRemarks);
|
||||
global.filterScript = ini.GetBool("enable_filter") ? ini.Get("filter_script"): "";
|
||||
ini.GetIfExist("base_path", global.basePath);
|
||||
ini.GetIfExist("clash_rule_base", global.clashBase);
|
||||
ini.GetIfExist("surge_rule_base", global.surgeBase);
|
||||
ini.GetIfExist("surfboard_rule_base", global.surfboardBase);
|
||||
ini.GetIfExist("mellow_rule_base", global.mellowBase);
|
||||
ini.GetIfExist("quan_rule_base", global.quanBase);
|
||||
ini.GetIfExist("quanx_rule_base", global.quanXBase);
|
||||
ini.GetIfExist("loon_rule_base", global.loonBase);
|
||||
ini.GetIfExist("default_external_config", global.defaultExtConfig);
|
||||
ini.GetBoolIfExist("append_proxy_type", global.appendType);
|
||||
ini.GetIfExist("proxy_config", global.proxyConfig);
|
||||
ini.GetIfExist("proxy_ruleset", global.proxyRuleset);
|
||||
ini.GetIfExist("proxy_subscription", global.proxySubscription);
|
||||
ini.enter_section("common");
|
||||
ini.get_bool_if_exist("api_mode", global.APIMode);
|
||||
ini.get_if_exist("api_access_token", global.accessToken);
|
||||
ini.get_if_exist("default_url", global.defaultUrls);
|
||||
global.enableInsert = ini.get("enable_insert");
|
||||
ini.get_if_exist("insert_url", global.insertUrls);
|
||||
ini.get_bool_if_exist("prepend_insert_url", global.prependInsert);
|
||||
if(ini.item_prefix_exist("exclude_remarks"))
|
||||
ini.get_all("exclude_remarks", global.excludeRemarks);
|
||||
if(ini.item_prefix_exist("include_remarks"))
|
||||
ini.get_all("include_remarks", global.includeRemarks);
|
||||
global.filterScript = ini.get_bool("enable_filter") ? ini.get("filter_script") : "";
|
||||
ini.get_if_exist("base_path", global.basePath);
|
||||
ini.get_if_exist("clash_rule_base", global.clashBase);
|
||||
ini.get_if_exist("surge_rule_base", global.surgeBase);
|
||||
ini.get_if_exist("surfboard_rule_base", global.surfboardBase);
|
||||
ini.get_if_exist("mellow_rule_base", global.mellowBase);
|
||||
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("default_external_config", global.defaultExtConfig);
|
||||
ini.get_bool_if_exist("append_proxy_type", global.appendType);
|
||||
ini.get_if_exist("proxy_config", global.proxyConfig);
|
||||
ini.get_if_exist("proxy_ruleset", global.proxyRuleset);
|
||||
ini.get_if_exist("proxy_subscription", global.proxySubscription);
|
||||
|
||||
if(ini.SectionExist("surge_external_proxy"))
|
||||
if(ini.section_exist("surge_external_proxy"))
|
||||
{
|
||||
ini.EnterSection("surge_external_proxy");
|
||||
ini.GetIfExist("surge_ssr_path", global.surgeSSRPath);
|
||||
ini.GetBoolIfExist("resolve_hostname", global.surgeResolveHostname);
|
||||
ini.enter_section("surge_external_proxy");
|
||||
ini.get_if_exist("surge_ssr_path", global.surgeSSRPath);
|
||||
ini.get_bool_if_exist("resolve_hostname", global.surgeResolveHostname);
|
||||
}
|
||||
|
||||
if(ini.SectionExist("node_pref"))
|
||||
if(ini.section_exist("node_pref"))
|
||||
{
|
||||
ini.EnterSection("node_pref");
|
||||
ini.enter_section("node_pref");
|
||||
/*
|
||||
ini.GetBoolIfExist("udp_flag", udp_flag);
|
||||
ini.GetBoolIfExist("tcp_fast_open_flag", tfo_flag);
|
||||
ini.GetBoolIfExist("skip_cert_verify_flag", scv_flag);
|
||||
ini.get_bool_if_exist("tcp_fast_open_flag", tfo_flag);
|
||||
ini.get_bool_if_exist("skip_cert_verify_flag", scv_flag);
|
||||
*/
|
||||
global.UDPFlag.set(ini.Get("udp_flag"));
|
||||
global.TFOFlag.set(ini.Get("tcp_fast_open_flag"));
|
||||
global.skipCertVerify.set(ini.Get("skip_cert_verify_flag"));
|
||||
global.TLS13Flag.set(ini.Get("tls13_flag"));
|
||||
ini.GetBoolIfExist("sort_flag", global.enableSort);
|
||||
global.sortScript = ini.Get("sort_script");
|
||||
ini.GetBoolIfExist("filter_deprecated_nodes", global.filterDeprecated);
|
||||
ini.GetBoolIfExist("append_sub_userinfo", global.appendUserinfo);
|
||||
ini.GetBoolIfExist("clash_use_new_field_name", global.clashUseNewField);
|
||||
ini.GetIfExist("clash_proxies_style", global.clashProxiesStyle);
|
||||
if(ini.ItemPrefixExist("rename_node"))
|
||||
global.UDPFlag.set(ini.get("udp_flag"));
|
||||
global.TFOFlag.set(ini.get("tcp_fast_open_flag"));
|
||||
global.skipCertVerify.set(ini.get("skip_cert_verify_flag"));
|
||||
global.TLS13Flag.set(ini.get("tls13_flag"));
|
||||
ini.get_bool_if_exist("sort_flag", global.enableSort);
|
||||
global.sortScript = ini.get("sort_script");
|
||||
ini.get_bool_if_exist("filter_deprecated_nodes", global.filterDeprecated);
|
||||
ini.get_bool_if_exist("append_sub_userinfo", global.appendUserinfo);
|
||||
ini.get_bool_if_exist("clash_use_new_field_name", global.clashUseNewField);
|
||||
ini.get_if_exist("clash_proxies_style", global.clashProxiesStyle);
|
||||
if(ini.item_prefix_exist("rename_node"))
|
||||
{
|
||||
ini.GetAll("rename_node", tempArray);
|
||||
ini.get_all("rename_node", tempArray);
|
||||
importItems(tempArray, false);
|
||||
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, "@");
|
||||
safe_set_renames(configs);
|
||||
@@ -900,20 +900,20 @@ void readConf()
|
||||
}
|
||||
}
|
||||
|
||||
if(ini.SectionExist("userinfo"))
|
||||
if(ini.section_exist("userinfo"))
|
||||
{
|
||||
ini.EnterSection("userinfo");
|
||||
if(ini.ItemPrefixExist("stream_rule"))
|
||||
ini.enter_section("userinfo");
|
||||
if(ini.item_prefix_exist("stream_rule"))
|
||||
{
|
||||
ini.GetAll("stream_rule", tempArray);
|
||||
ini.get_all("stream_rule", tempArray);
|
||||
importItems(tempArray, false);
|
||||
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, "|");
|
||||
safe_set_streams(configs);
|
||||
eraseElements(tempArray);
|
||||
}
|
||||
if(ini.ItemPrefixExist("time_rule"))
|
||||
if(ini.item_prefix_exist("time_rule"))
|
||||
{
|
||||
ini.GetAll("time_rule", tempArray);
|
||||
ini.get_all("time_rule", tempArray);
|
||||
importItems(tempArray, false);
|
||||
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, "|");
|
||||
safe_set_times(configs);
|
||||
@@ -921,45 +921,45 @@ void readConf()
|
||||
}
|
||||
}
|
||||
|
||||
ini.EnterSection("managed_config");
|
||||
ini.GetBoolIfExist("write_managed_config", global.writeManagedConfig);
|
||||
ini.GetIfExist("managed_config_prefix", global.managedConfigPrefix);
|
||||
ini.GetIntIfExist("config_update_interval", global.updateInterval);
|
||||
ini.GetBoolIfExist("config_update_strict", global.updateStrict);
|
||||
ini.GetIfExist("quanx_device_id", global.quanXDevID);
|
||||
ini.enter_section("managed_config");
|
||||
ini.get_bool_if_exist("write_managed_config", global.writeManagedConfig);
|
||||
ini.get_if_exist("managed_config_prefix", global.managedConfigPrefix);
|
||||
ini.get_int_if_exist("config_update_interval", global.updateInterval);
|
||||
ini.get_bool_if_exist("config_update_strict", global.updateStrict);
|
||||
ini.get_if_exist("quanx_device_id", global.quanXDevID);
|
||||
|
||||
ini.EnterSection("emojis");
|
||||
ini.GetBoolIfExist("add_emoji", global.addEmoji);
|
||||
ini.GetBoolIfExist("remove_old_emoji", global.removeEmoji);
|
||||
if(ini.ItemPrefixExist("rule"))
|
||||
ini.enter_section("emojis");
|
||||
ini.get_bool_if_exist("add_emoji", global.addEmoji);
|
||||
ini.get_bool_if_exist("remove_old_emoji", global.removeEmoji);
|
||||
if(ini.item_prefix_exist("rule"))
|
||||
{
|
||||
ini.GetAll("rule", tempArray);
|
||||
ini.get_all("rule", tempArray);
|
||||
importItems(tempArray, false);
|
||||
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, ",");
|
||||
safe_set_emojis(configs);
|
||||
eraseElements(tempArray);
|
||||
}
|
||||
|
||||
if(ini.SectionExist("rulesets"))
|
||||
ini.EnterSection("rulesets");
|
||||
if(ini.section_exist("rulesets"))
|
||||
ini.enter_section("rulesets");
|
||||
else
|
||||
ini.EnterSection("ruleset");
|
||||
global.enableRuleGen = ini.GetBool("enabled");
|
||||
ini.enter_section("ruleset");
|
||||
global.enableRuleGen = ini.get_bool("enabled");
|
||||
if(global.enableRuleGen)
|
||||
{
|
||||
ini.GetBoolIfExist("overwrite_original_rules", global.overwriteOriginalRules);
|
||||
ini.GetBoolIfExist("update_ruleset_on_request", global.updateRulesetOnRequest);
|
||||
if(ini.ItemPrefixExist("ruleset"))
|
||||
ini.get_bool_if_exist("overwrite_original_rules", global.overwriteOriginalRules);
|
||||
ini.get_bool_if_exist("update_ruleset_on_request", global.updateRulesetOnRequest);
|
||||
if(ini.item_prefix_exist("ruleset"))
|
||||
{
|
||||
string_array vArray;
|
||||
ini.GetAll("ruleset", vArray);
|
||||
ini.get_all("ruleset", vArray);
|
||||
importItems(vArray, false);
|
||||
global.customRulesets = INIBinding::from<RulesetConfig>::from_ini(vArray);
|
||||
}
|
||||
else if(ini.ItemPrefixExist("surge_ruleset"))
|
||||
else if(ini.item_prefix_exist("surge_ruleset"))
|
||||
{
|
||||
string_array vArray;
|
||||
ini.GetAll("surge_ruleset", vArray);
|
||||
ini.get_all("surge_ruleset", vArray);
|
||||
importItems(vArray, false);
|
||||
global.customRulesets = INIBinding::from<RulesetConfig>::from_ini(vArray);
|
||||
}
|
||||
@@ -970,22 +970,22 @@ void readConf()
|
||||
global.updateRulesetOnRequest = false;
|
||||
}
|
||||
|
||||
if(ini.SectionExist("proxy_groups"))
|
||||
ini.EnterSection("proxy_groups");
|
||||
if(ini.section_exist("proxy_groups"))
|
||||
ini.enter_section("proxy_groups");
|
||||
else
|
||||
ini.EnterSection("clash_proxy_group");
|
||||
if(ini.ItemPrefixExist("custom_proxy_group"))
|
||||
ini.enter_section("clash_proxy_group");
|
||||
if(ini.item_prefix_exist("custom_proxy_group"))
|
||||
{
|
||||
string_array vArray;
|
||||
ini.GetAll("custom_proxy_group", vArray);
|
||||
ini.get_all("custom_proxy_group", vArray);
|
||||
importItems(vArray, false);
|
||||
global.customProxyGroups = INIBinding::from<ProxyGroupConfig>::from_ini(vArray);
|
||||
}
|
||||
|
||||
ini.EnterSection("template");
|
||||
ini.GetIfExist("template_path", global.templatePath);
|
||||
ini.enter_section("template");
|
||||
ini.get_if_exist("template_path", global.templatePath);
|
||||
string_multimap tempmap;
|
||||
ini.GetItems(tempmap);
|
||||
ini.get_items(tempmap);
|
||||
eraseElements(global.templateVars);
|
||||
for(auto &x : tempmap)
|
||||
{
|
||||
@@ -995,36 +995,36 @@ void readConf()
|
||||
}
|
||||
global.templateVars["managed_config_prefix"] = global.managedConfigPrefix;
|
||||
|
||||
if(ini.SectionExist("aliases"))
|
||||
if(ini.section_exist("aliases"))
|
||||
{
|
||||
ini.EnterSection("aliases");
|
||||
ini.GetItems(tempmap);
|
||||
ini.enter_section("aliases");
|
||||
ini.get_items(tempmap);
|
||||
webServer.reset_redirect();
|
||||
for(auto &x : tempmap)
|
||||
webServer.append_redirect(x.first, x.second);
|
||||
}
|
||||
|
||||
if(ini.SectionExist("tasks"))
|
||||
if(ini.section_exist("tasks"))
|
||||
{
|
||||
string_array vArray;
|
||||
ini.EnterSection("tasks");
|
||||
ini.GetAll("task", vArray);
|
||||
ini.enter_section("tasks");
|
||||
ini.get_all("task", vArray);
|
||||
importItems(vArray, false);
|
||||
global.enableCron = !vArray.empty();
|
||||
global.cronTasks = INIBinding::from<CronTaskConfig>::from_ini(vArray);
|
||||
refresh_schedule();
|
||||
}
|
||||
|
||||
ini.EnterSection("server");
|
||||
ini.GetIfExist("listen", global.listenAddress);
|
||||
ini.GetIntIfExist("port", global.listenPort);
|
||||
webServer.serve_file_root = ini.Get("serve_file_root");
|
||||
ini.enter_section("server");
|
||||
ini.get_if_exist("listen", global.listenAddress);
|
||||
ini.get_int_if_exist("port", global.listenPort);
|
||||
webServer.serve_file_root = ini.get("serve_file_root");
|
||||
webServer.serve_file = !webServer.serve_file_root.empty();
|
||||
|
||||
ini.EnterSection("advanced");
|
||||
ini.enter_section("advanced");
|
||||
std::string log_level;
|
||||
ini.GetIfExist("log_level", log_level);
|
||||
ini.GetBoolIfExist("print_debug_info", global.printDbgInfo);
|
||||
ini.get_if_exist("log_level", log_level);
|
||||
ini.get_bool_if_exist("print_debug_info", global.printDbgInfo);
|
||||
if(global.printDbgInfo)
|
||||
global.logLevel = LOG_LEVEL_VERBOSE;
|
||||
else
|
||||
@@ -1050,19 +1050,19 @@ void readConf()
|
||||
global.logLevel = LOG_LEVEL_INFO;
|
||||
}
|
||||
}
|
||||
ini.GetIntIfExist("max_pending_connections", global.maxPendingConns);
|
||||
ini.GetIntIfExist("max_concurrent_threads", global.maxConcurThreads);
|
||||
ini.GetNumberIfExist("max_allowed_rulesets", global.maxAllowedRulesets);
|
||||
ini.GetNumberIfExist("max_allowed_rules", global.maxAllowedRules);
|
||||
ini.GetNumberIfExist("max_allowed_download_size", global.maxAllowedDownloadSize);
|
||||
if(ini.ItemExist("enable_cache"))
|
||||
ini.get_int_if_exist("max_pending_connections", global.maxPendingConns);
|
||||
ini.get_int_if_exist("max_concurrent_threads", global.maxConcurThreads);
|
||||
ini.get_number_if_exist("max_allowed_rulesets", global.maxAllowedRulesets);
|
||||
ini.get_number_if_exist("max_allowed_rules", global.maxAllowedRules);
|
||||
ini.get_number_if_exist("max_allowed_download_size", global.maxAllowedDownloadSize);
|
||||
if(ini.item_exist("enable_cache"))
|
||||
{
|
||||
if(ini.GetBool("enable_cache"))
|
||||
if(ini.get_bool("enable_cache"))
|
||||
{
|
||||
ini.GetIntIfExist("cache_subscription", global.cacheSubscription);
|
||||
ini.GetIntIfExist("cache_config", global.cacheConfig);
|
||||
ini.GetIntIfExist("cache_ruleset", global.cacheRuleset);
|
||||
ini.GetBoolIfExist("serve_cache_on_fetch_fail", global.serveCacheOnFetchFail);
|
||||
ini.get_int_if_exist("cache_subscription", global.cacheSubscription);
|
||||
ini.get_int_if_exist("cache_config", global.cacheConfig);
|
||||
ini.get_int_if_exist("cache_ruleset", global.cacheRuleset);
|
||||
ini.get_bool_if_exist("serve_cache_on_fetch_fail", global.serveCacheOnFetchFail);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1070,9 +1070,9 @@ void readConf()
|
||||
global.serveCacheOnFetchFail = false;
|
||||
}
|
||||
}
|
||||
ini.GetBoolIfExist("script_clean_context", global.scriptCleanContext);
|
||||
ini.GetBoolIfExist("async_fetch_ruleset", global.asyncFetchRuleset);
|
||||
ini.GetBoolIfExist("skip_failed_links", global.skipFailedLinks);
|
||||
ini.get_bool_if_exist("script_clean_context", global.scriptCleanContext);
|
||||
ini.get_bool_if_exist("async_fetch_ruleset", global.asyncFetchRuleset);
|
||||
ini.get_bool_if_exist("skip_failed_links", global.skipFailedLinks);
|
||||
|
||||
writeLog(0, "Load preference settings in INI format completed.", LOG_LEVEL_INFO);
|
||||
}
|
||||
@@ -1227,27 +1227,27 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
|
||||
|
||||
INIReader ini;
|
||||
ini.store_isolated_line = true;
|
||||
ini.SetIsolatedItemsSection("custom");
|
||||
if(ini.Parse(base_content) != INIREADER_EXCEPTION_NONE)
|
||||
ini.set_isolated_items_section("custom");
|
||||
if(ini.parse(base_content) != INIREADER_EXCEPTION_NONE)
|
||||
{
|
||||
//std::cerr<<"Load external configuration failed. Reason: "<<ini.GetLastError()<<"\n";
|
||||
writeLog(0, "Load external configuration failed. Reason: " + ini.GetLastError(), LOG_LEVEL_ERROR);
|
||||
//std::cerr<<"Load external configuration failed. Reason: "<<ini.get_last_error()<<"\n";
|
||||
writeLog(0, "Load external configuration failed. Reason: " + ini.get_last_error(), LOG_LEVEL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ini.EnterSection("custom");
|
||||
if(ini.ItemPrefixExist("custom_proxy_group"))
|
||||
ini.enter_section("custom");
|
||||
if(ini.item_prefix_exist("custom_proxy_group"))
|
||||
{
|
||||
string_array vArray;
|
||||
ini.GetAll("custom_proxy_group", vArray);
|
||||
ini.get_all("custom_proxy_group", vArray);
|
||||
importItems(vArray, global.APIMode);
|
||||
ext.custom_proxy_group = INIBinding::from<ProxyGroupConfig>::from_ini(vArray);
|
||||
}
|
||||
std::string ruleset_name = ini.ItemPrefixExist("ruleset") ? "ruleset" : "surge_ruleset";
|
||||
if(ini.ItemPrefixExist(ruleset_name))
|
||||
std::string ruleset_name = ini.item_prefix_exist("ruleset") ? "ruleset" : "surge_ruleset";
|
||||
if(ini.item_prefix_exist(ruleset_name))
|
||||
{
|
||||
string_array vArray;
|
||||
ini.GetAll(ruleset_name, vArray);
|
||||
ini.get_all(ruleset_name, vArray);
|
||||
importItems(vArray, global.APIMode);
|
||||
if(global.maxAllowedRulesets && vArray.size() > global.maxAllowedRulesets)
|
||||
{
|
||||
@@ -1257,44 +1257,44 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
|
||||
ext.surge_ruleset = INIBinding::from<RulesetConfig>::from_ini(vArray);
|
||||
}
|
||||
|
||||
ini.GetIfExist("clash_rule_base", ext.clash_rule_base);
|
||||
ini.GetIfExist("surge_rule_base", ext.surge_rule_base);
|
||||
ini.GetIfExist("surfboard_rule_base", ext.surfboard_rule_base);
|
||||
ini.GetIfExist("mellow_rule_base", ext.mellow_rule_base);
|
||||
ini.GetIfExist("quan_rule_base", ext.quan_rule_base);
|
||||
ini.GetIfExist("quanx_rule_base", ext.quanx_rule_base);
|
||||
ini.GetIfExist("loon_rule_base", ext.loon_rule_base);
|
||||
ini.GetIfExist("sssub_rule_base", ext.sssub_rule_base);
|
||||
ini.get_if_exist("clash_rule_base", ext.clash_rule_base);
|
||||
ini.get_if_exist("surge_rule_base", ext.surge_rule_base);
|
||||
ini.get_if_exist("surfboard_rule_base", ext.surfboard_rule_base);
|
||||
ini.get_if_exist("mellow_rule_base", ext.mellow_rule_base);
|
||||
ini.get_if_exist("quan_rule_base", ext.quan_rule_base);
|
||||
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.GetBoolIfExist("overwrite_original_rules", ext.overwrite_original_rules);
|
||||
ini.GetBoolIfExist("enable_rule_generator", ext.enable_rule_generator);
|
||||
ini.get_bool_if_exist("overwrite_original_rules", ext.overwrite_original_rules);
|
||||
ini.get_bool_if_exist("enable_rule_generator", ext.enable_rule_generator);
|
||||
|
||||
if(ini.ItemPrefixExist("rename"))
|
||||
if(ini.item_prefix_exist("rename"))
|
||||
{
|
||||
string_array vArray;
|
||||
ini.GetAll("rename", vArray);
|
||||
ini.get_all("rename", vArray);
|
||||
importItems(vArray, global.APIMode);
|
||||
ext.rename = INIBinding::from<RegexMatchConfig>::from_ini(vArray, "@");
|
||||
}
|
||||
ext.add_emoji = ini.Get("add_emoji");
|
||||
ext.remove_old_emoji = ini.Get("remove_old_emoji");
|
||||
if(ini.ItemPrefixExist("emoji"))
|
||||
ext.add_emoji = ini.get("add_emoji");
|
||||
ext.remove_old_emoji = ini.get("remove_old_emoji");
|
||||
if(ini.item_prefix_exist("emoji"))
|
||||
{
|
||||
string_array vArray;
|
||||
ini.GetAll("emoji", vArray);
|
||||
ini.get_all("emoji", vArray);
|
||||
importItems(vArray, global.APIMode);
|
||||
ext.emoji = INIBinding::from<RegexMatchConfig>::from_ini(vArray, ",");
|
||||
}
|
||||
if(ini.ItemPrefixExist("include_remarks"))
|
||||
ini.GetAll("include_remarks", ext.include);
|
||||
if(ini.ItemPrefixExist("exclude_remarks"))
|
||||
ini.GetAll("exclude_remarks", ext.exclude);
|
||||
if(ini.item_prefix_exist("include_remarks"))
|
||||
ini.get_all("include_remarks", ext.include);
|
||||
if(ini.item_prefix_exist("exclude_remarks"))
|
||||
ini.get_all("exclude_remarks", ext.exclude);
|
||||
|
||||
if(ini.SectionExist("template") && ext.tpl_args != nullptr)
|
||||
if(ini.section_exist("template") && ext.tpl_args != nullptr)
|
||||
{
|
||||
ini.EnterSection("template");
|
||||
ini.enter_section("template");
|
||||
string_multimap tempmap;
|
||||
ini.GetItems(tempmap);
|
||||
ini.get_items(tempmap);
|
||||
for(auto &x : tempmap)
|
||||
ext.tpl_args->local_vars[x.first] = x.second;
|
||||
}
|
||||
|
||||
+16
-16
@@ -41,15 +41,15 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
|
||||
return -1;
|
||||
}
|
||||
|
||||
ini.ParseFile("gistconf.ini");
|
||||
if(ini.EnterSection("common") != 0)
|
||||
ini.parse_file("gistconf.ini");
|
||||
if(ini.enter_section("common") != 0)
|
||||
{
|
||||
//std::cerr<<"gistconf.ini has incorrect format. Skipping...\n";
|
||||
writeLog(0, "gistconf.ini has incorrect format. Skipping...", LOG_LEVEL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
token = ini.Get("token");
|
||||
token = ini.get("token");
|
||||
if(!token.size())
|
||||
{
|
||||
//std::cerr<<"No token is provided. Skipping...\n";
|
||||
@@ -57,12 +57,12 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
|
||||
return -1;
|
||||
}
|
||||
|
||||
id = ini.Get("id");
|
||||
username = ini.Get("username");
|
||||
id = ini.get("id");
|
||||
username = ini.get("username");
|
||||
if(!path.size())
|
||||
{
|
||||
if(ini.ItemExist("path"))
|
||||
path = ini.Get(name, "path");
|
||||
if(ini.item_exist("path"))
|
||||
path = ini.get(name, "path");
|
||||
else
|
||||
path = name;
|
||||
}
|
||||
@@ -102,16 +102,16 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
|
||||
//std::cerr<<"Writing to Gist success!\nGenerator: "<<name<<"\nPath: "<<path<<"\nRaw URL: "<<url<<"\nGist owner: "<<username<<"\n";
|
||||
writeLog(0, "Writing to Gist success!\nGenerator: " + name + "\nPath: " + path + "\nRaw URL: " + url + "\nGist owner: " + username, LOG_LEVEL_INFO);
|
||||
|
||||
ini.EraseSection();
|
||||
ini.Set("token", token);
|
||||
ini.Set("id", id);
|
||||
ini.Set("username", username);
|
||||
ini.erase_section();
|
||||
ini.set("token", token);
|
||||
ini.set("id", id);
|
||||
ini.set("username", username);
|
||||
|
||||
ini.SetCurrentSection(path);
|
||||
ini.EraseSection();
|
||||
ini.Set("type", name);
|
||||
ini.Set("url", url);
|
||||
ini.set_current_section(path);
|
||||
ini.erase_section();
|
||||
ini.set("type", name);
|
||||
ini.set("url", url);
|
||||
|
||||
ini.ToFile("gistconf.ini");
|
||||
ini.to_file("gistconf.ini");
|
||||
return 0;
|
||||
}
|
||||
@@ -295,10 +295,10 @@ static int curlGet(const FetchArgument &argument, FetchResult &result)
|
||||
static std::string dataGet(const std::string &url)
|
||||
{
|
||||
if (!startsWith(url, "data:"))
|
||||
return std::string();
|
||||
return "";
|
||||
std::string::size_type comma = url.find(',');
|
||||
if (comma == std::string::npos || comma == url.size() - 1)
|
||||
return std::string();
|
||||
return "";
|
||||
|
||||
std::string data = urlDecode(url.substr(comma + 1));
|
||||
if (endsWith(url.substr(0, comma), ";base64")) {
|
||||
|
||||
Reference in new issue
Block a user