Enhancements

Fix TLS settings missing when parsing Clash configurations.
Add support for adding route settings to Shadowsocks Android subscriptions.
Add serve_cache_on_fetch_fail option to determine whether to serve cached content when failed to download a file.
Optimize codes.
This commit is contained in:
Tindy X committed 2020-03-24 16:56:41 +08:00
1 parent e99e836ad5
commit a3e337c569
9 files changed
+294 -161

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
{
"route": "bypass-lan-china",
"remote_dns": "dns.google",
"ipv6": false,
"metered": false,
"proxy_apps": {
"enabled": false,
"bypass": true,
"android_list": [
"com.eg.android.AlipayGphone",
"com.wudaokou.hippo",
"com.zhihu.android"
]
},
"udpdns": false
}
+1
View File
@@ -12,6 +12,7 @@ common:
quan_rule_base: base/quan.conf
quanx_rule_base: base/quanx.conf
loon_rule_base: base/loon.conf
sssub_rule_base: base/shadowsocks_base.json
proxy_config: SYSTEM
proxy_ruleset: SYSTEM
proxy_subscription: NONE
+3
View File
@@ -39,6 +39,9 @@ quanx_rule_base=base/quanx.conf
;Loon config base used by the generator, supports local files/URL
loon_rule_base=base/loon.conf
;Shadowsocks Android config base used by the generator, supports local files/URL
sssub_rule_base=base/shadowsocks_base.json
;Proxy used to download configs, rulesets or subscriptions, set to NONE or empty to disable it, set to SYSTEM to use system proxy.
;Accept cURL-supported proxies (http:// https:// socks4a:// socks5://)
proxy_config=SYSTEM
+123 -48
View File
@@ -127,7 +127,7 @@ public:
/**
* @brief Parse a file during initialization.
*/
INIReader(std::string filePath)
INIReader(const std::string &filePath)
{
parsed = false;
ParseFile(filePath);
@@ -168,7 +168,7 @@ public:
/**
* @brief Exclude a section with the given name.
*/
void ExcludeSection(std::string section)
void ExcludeSection(const std::string &section)
{
exclude_sections.emplace_back(section);
}
@@ -176,7 +176,7 @@ public:
/**
* @brief Include a section with the given name.
*/
void IncludeSection(std::string section)
void IncludeSection(const std::string &section)
{
include_sections.emplace_back(section);
}
@@ -184,7 +184,7 @@ public:
/**
* @brief Add a section to the direct-save sections list.
*/
void AddDirectSaveSection(std::string section)
void AddDirectSaveSection(const std::string &section)
{
direct_save_sections.emplace_back(section);
}
@@ -192,7 +192,7 @@ public:
/**
* @brief Set isolated items to given section.
*/
void SetIsolatedItemsSection(std::string section)
void SetIsolatedItemsSection(const std::string &section)
{
isolated_items_section = section;
}
@@ -318,7 +318,7 @@ public:
/**
* @brief Parse an INI file into mapped data structure.
*/
int ParseFile(std::string filePath)
int ParseFile(const std::string &filePath)
{
if(!fileExist(filePath))
return __priv_save_error_and_return(INIREADER_EXCEPTION_NOTEXIST);
@@ -328,7 +328,7 @@ public:
/**
* @brief Check whether a section exist.
*/
bool SectionExist(std::string section)
bool SectionExist(const std::string &section)
{
return ini_content.find(section) != ini_content.end();
}
@@ -360,7 +360,7 @@ public:
/**
* @brief Enter a section with the given name. Section name and data will be cached to speed up the following reading process.
*/
int EnterSection(std::string section)
int EnterSection(const std::string &section)
{
if(!SectionExist(section))
return __priv_save_error_and_return(INIREADER_EXCEPTION_NOTEXIST);
@@ -372,7 +372,7 @@ public:
/**
* @brief Set current section.
*/
void SetCurrentSection(std::string section)
void SetCurrentSection(const std::string &section)
{
current_section = section;
}
@@ -380,7 +380,7 @@ public:
/**
* @brief Check whether an item exist in the given section. Return false if the section does not exist.
*/
bool ItemExist(std::string section, std::string itemName)
bool ItemExist(const std::string &section, const std::string &itemName)
{
if(!SectionExist(section))
return false;
@@ -397,7 +397,7 @@ public:
/**
* @brief Check whether an item exist in current section. Return false if the section does not exist.
*/
bool ItemExist(std::string itemName)
bool ItemExist(const std::string &itemName)
{
return current_section.size() ? ItemExist(current_section, itemName) : false;
}
@@ -405,7 +405,7 @@ public:
/**
* @brief Check whether an item with the given name prefix exist in the given section. Return false if the section does not exist.
*/
bool ItemPrefixExist(std::string section, std::string itemName)
bool ItemPrefixExist(const std::string &section, const std::string &itemName)
{
if(!SectionExist(section))
return false;
@@ -428,7 +428,7 @@ public:
/**
* @brief Check whether an item with the given name prefix exist in current section. Return false if the section does not exist.
*/
bool ItemPrefixExist(std::string itemName)
bool ItemPrefixExist(const std::string &itemName)
{
return current_section.size() ? ItemPrefixExist(current_section, itemName) : false;
}
@@ -436,7 +436,7 @@ public:
/**
* @brief Count of items in the given section. Return 0 if the section does not exist.
*/
unsigned int ItemCount(std::string section)
unsigned int ItemCount(const std::string &section)
{
if(!parsed || !SectionExist(section))
return __priv_save_error_and_return(INIREADER_EXCEPTION_NOTPARSED);
@@ -457,7 +457,7 @@ public:
/**
* @brief Retrieve all items in the given section.
*/
int GetItems(std::string section, string_multimap &data)
int GetItems(const std::string &section, string_multimap &data)
{
if(!parsed || !SectionExist(section))
return __priv_save_error_and_return(INIREADER_EXCEPTION_NOTEXIST);
@@ -483,7 +483,7 @@ public:
/**
* @brief Retrieve item(s) with the same name prefix in the given section.
*/
int GetAll(std::string section, std::string itemName, string_array &results) //retrieve item(s) with the same itemName prefix
int GetAll(const std::string &section, const std::string &itemName, string_array &results) //retrieve item(s) with the same itemName prefix
{
if(!parsed)
return __priv_save_error_and_return(INIREADER_EXCEPTION_NOTPARSED);
@@ -505,7 +505,7 @@ public:
/**
* @brief Retrieve item(s) with the same name prefix in current section.
*/
int GetAll(std::string itemName, string_array &results)
int GetAll(const std::string &itemName, string_array &results)
{
return current_section.size() ? GetAll(current_section, itemName, results) : -1;
}
@@ -513,17 +513,23 @@ public:
/**
* @brief Retrieve one item with the exact same name in the given section.
*/
std::string Get(std::string section, std::string itemName) //retrieve one item with the exact same itemName
std::string Get(const std::string &section, const std::string &itemName) //retrieve one item with the exact same itemName
{
if(!parsed)
if(!parsed || !SectionExist(section))
return std::string();
/*
string_multimap mapTemp;
if(GetItems(section, mapTemp) != 0)
return std::string();
*/
if(cached_section != section)
{
cached_section = section;
cached_section_content = ini_content.at(section);
}
for(auto &x : mapTemp)
for(auto &x : cached_section_content)
{
if(x.first == itemName)
return x.second;
@@ -535,15 +541,40 @@ public:
/**
* @brief Retrieve one item with the exact same name in current section.
*/
std::string Get(std::string itemName)
std::string Get(const std::string &itemName)
{
return current_section.size() ? Get(current_section, itemName) : std::string();
}
/**
* @brief Retrieve one item with the exact same name in the given section, if exist.
*/
int GetIfExist(const std::string &section, const std::string &itemName, std::string &target) //retrieve one item with the exact same itemName
{
if(!parsed)
return __priv_save_error_and_return(INIREADER_EXCEPTION_NOTPARSED);
if(ItemExist(section, itemName))
{
target = Get(section, itemName);
return __priv_save_error_and_return(INIREADER_EXCEPTION_NONE);
}
return __priv_save_error_and_return(INIREADER_EXCEPTION_NOTEXIST);
}
/**
* @brief Retrieve one item with the exact same name in current section, if exist.
*/
int GetIfExist(const std::string &itemName, std::string &target)
{
return current_section.size() ? GetIfExist(current_section, itemName, target) : INIREADER_EXCEPTION_NOTEXIST;
}
/**
* @brief Retrieve one boolean item value with the exact same name in the given section.
*/
bool GetBool(std::string section, std::string itemName)
bool GetBool(const std::string &section, const std::string &itemName)
{
return Get(section, itemName) == "true";
}
@@ -551,23 +582,67 @@ public:
/**
* @brief Retrieve one boolean item value with the exact same name in current section.
*/
bool GetBool(std::string itemName)
bool GetBool(const std::string &itemName)
{
return current_section.size() ? Get(current_section, itemName) == "true" : false;
}
/**
* @brief Retrieve one boolean item value with the exact same name in the given section.
*/
int GetBoolIfExist(const std::string &section, const std::string &itemName, bool &target)
{
std::string result;
int retval = GetIfExist(section, itemName, result);
if(retval != INIREADER_EXCEPTION_NONE)
return retval;
if(result.size())
target = result == "true";
return INIREADER_EXCEPTION_NONE;
}
/**
* @brief Retrieve one boolean item value with the exact same name in current section.
*/
int GetBoolIfExist(const std::string &itemName, bool &target)
{
return current_section.size() ? GetBoolIfExist(current_section, itemName, target) : INIREADER_EXCEPTION_NOTEXIST;
}
/**
* @brief Retrieve one boolean item value with the exact same name in the given section.
*/
int GetIntIfExist(const std::string &section, const std::string &itemName, int &target)
{
std::string result;
int retval = GetIfExist(section, itemName, result);
if(retval != INIREADER_EXCEPTION_NONE)
return retval;
if(result.size())
target = to_int(result, target);
return INIREADER_EXCEPTION_NONE;
}
/**
* @brief Retrieve one boolean item value with the exact same name in current section.
*/
int GetIntIfExist(const std::string &itemName, int &target)
{
return current_section.size() ? GetIntIfExist(current_section, itemName, target) : INIREADER_EXCEPTION_NOTEXIST;
}
/**
* @brief Retrieve one integer item value with the exact same name in the given section.
*/
int GetInt(std::string section, std::string itemName)
int GetInt(const std::string &section, const std::string &itemName)
{
return stoi(Get(section, itemName));
return to_int(Get(section, itemName), 0);
}
/**
* @brief Retrieve one integer item value with the exact same name in current section.
*/
int GetInt(std::string itemName)
int GetInt(const std::string &itemName)
{
return GetInt(current_section, itemName);
}
@@ -575,7 +650,7 @@ public:
/**
* @brief Retrieve the first item found in the given section.
*/
std::string GetFirst(std::string section, std::string itemName) //return the first item value found in section
std::string GetFirst(const std::string &section, const std::string &itemName) //return the first item value found in section
{
if(!parsed)
return std::string();
@@ -589,7 +664,7 @@ public:
/**
* @brief Retrieve the first item found in current section.
*/
std::string GetFirst(std::string itemName)
std::string GetFirst(const std::string &itemName)
{
return current_section.size() ? GetFirst(current_section, itemName) : std::string();
}
@@ -597,7 +672,7 @@ public:
/**
* @brief Retrieve a string style array with specific separator and write into integer array.
*/
template <typename T> void GetIntArray(std::string section, std::string itemName, std::string separator, T &Array)
template <typename T> void GetIntArray(const std::string &section, const std::string &itemName, const std::string &separator, T &Array)
{
string_array vArray;
unsigned int index, UBound = sizeof(Array) / sizeof(Array[0]);
@@ -611,7 +686,7 @@ public:
/**
* @brief Retrieve a string style array with specific separator and write into integer array.
*/
template <typename T> void GetIntArray(std::string itemName, std::string separator, T &Array)
template <typename T> void GetIntArray(const std::string &itemName, const std::string &separator, T &Array)
{
if(current_section.size())
GetIntArray(current_section, itemName, separator, Array);
@@ -620,7 +695,7 @@ public:
/**
* @brief Add a std::string value with given values.
*/
int Set(std::string section, std::string itemName, std::string itemVal)
int Set(const std::string &section, const std::string &itemName, const std::string &itemVal)
{
if(!section.size())
return __priv_save_error_and_return(INIREADER_EXCEPTION_NOTEXIST);
@@ -647,7 +722,7 @@ public:
/**
* @brief Add a string value with given values.
*/
int Set(std::string itemName, std::string itemVal)
int Set(const std::string &itemName, const std::string &itemVal)
{
if(!current_section.size())
return __priv_save_error_and_return(INIREADER_EXCEPTION_NOTEXIST);
@@ -657,7 +732,7 @@ public:
/**
* @brief Add a boolean value with given values.
*/
int SetBool(std::string section, std::string itemName, bool itemVal)
int SetBool(const std::string &section, const std::string &itemName, bool itemVal)
{
return Set(section, itemName, itemVal ? "true" : "false");
}
@@ -665,7 +740,7 @@ public:
/**
* @brief Add a boolean value with given values.
*/
int SetBool(std::string itemName, bool itemVal)
int SetBool(const std::string &itemName, bool itemVal)
{
return SetBool(current_section, itemName, itemVal);
}
@@ -673,7 +748,7 @@ public:
/**
* @brief Add a double value with given values.
*/
int SetDouble(std::string section, std::string itemName, double itemVal)
int SetDouble(const std::string &section, const std::string &itemName, double itemVal)
{
return Set(section, itemName, std::to_string(itemVal));
}
@@ -681,7 +756,7 @@ public:
/**
* @brief Add a double value with given values.
*/
int SetDouble(std::string itemName, double itemVal)
int SetDouble(const std::string &itemName, double itemVal)
{
return SetDouble(current_section, itemName, itemVal);
}
@@ -689,7 +764,7 @@ public:
/**
* @brief Add a long value with given values.
*/
int SetLong(std::string section, std::string itemName, long itemVal)
int SetLong(const std::string &section, const std::string &itemName, long itemVal)
{
return Set(section, itemName, std::to_string(itemVal));
}
@@ -697,7 +772,7 @@ public:
/**
* @brief Add a long value with given values.
*/
int SetLong(std::string itemName, long itemVal)
int SetLong(const std::string &itemName, long itemVal)
{
return SetLong(current_section, itemName, itemVal);
}
@@ -705,7 +780,7 @@ public:
/**
* @brief Add an array with the given separator.
*/
template <typename T> int SetArray(std::string section, std::string itemName, std::string separator, T &Array)
template <typename T> int SetArray(const std::string &section, const std::string &itemName, const std::string &separator, T &Array)
{
std::string data;
for(auto &x : Array)
@@ -717,12 +792,12 @@ public:
/**
* @brief Add an array with the given separator.
*/
template <typename T> int SetArray(std::string itemName, std::string separator, T &Array)
template <typename T> int SetArray(const std::string &itemName, const std::string &separator, T &Array)
{
return current_section.size() ? SetArray(current_section, itemName, separator, Array) : -1;
}
int RenameSection(std::string oldName, std::string newName)
int RenameSection(const std::string &oldName, const std::string &newName)
{
if(!SectionExist(oldName) || SectionExist(newName))
return __priv_save_error_and_return(INIREADER_EXCEPTION_DUPLICATE);
@@ -740,7 +815,7 @@ public:
/**
* @brief Erase all items with the given name.
*/
int Erase(std::string section, std::string itemName)
int Erase(const std::string &section, const std::string &itemName)
{
int retVal;
if(!SectionExist(section))
@@ -757,7 +832,7 @@ public:
/**
* @brief Erase all items with the given name.
*/
int Erase(std::string itemName)
int Erase(const std::string &itemName)
{
return current_section.size() ? Erase(current_section, itemName) : -1;
}
@@ -765,7 +840,7 @@ public:
/**
* @brief Erase the first item with the given name.
*/
int EraseFirst(std::string section, std::string itemName)
int EraseFirst(const std::string &section, const std::string &itemName)
{
string_multimap &mapTemp = ini_content.at(section);
string_multimap::iterator iter = mapTemp.find(itemName);
@@ -787,7 +862,7 @@ public:
/**
* @brief Erase the first item with the given name.
*/
int EraseFirst(std::string itemName)
int EraseFirst(const std::string &itemName)
{
return current_section.size() ? EraseFirst(current_section, itemName) : -1;
}
@@ -795,7 +870,7 @@ public:
/**
* @brief Erase all items in the given section.
*/
void EraseSection(std::string section)
void EraseSection(const std::string &section)
{
if(ini_content.find(section) == ini_content.end())
return;
@@ -848,7 +923,7 @@ public:
/**
* @brief Export the whole INI data structure into a file.
*/
int ToFile(std::string filePath)
int ToFile(const std::string &filePath)
{
return fileWrite(filePath, ToString(), true);
}
+69 -107
View File
@@ -46,7 +46,7 @@ int config_update_interval = 0;
std::string clash_rule_base;
string_array clash_extra_group;
std::string surge_rule_base, surfboard_rule_base, mellow_rule_base, quan_rule_base, quanx_rule_base, loon_rule_base;
std::string surge_rule_base, surfboard_rule_base, mellow_rule_base, quan_rule_base, quanx_rule_base, loon_rule_base, sssub_rule_base;
std::string surge_ssr_path, quanx_script_id;
//pre-compiled rule bases
@@ -54,6 +54,7 @@ YAML::Node clash_base;
INIReader surge_base, mellow_base;
//cache system
bool serve_cache_on_fetch_fail = false;
int cache_subscription = 60, cache_config = 300, cache_ruleset = 21600;
string_array regex_blacklist = {"(.*)*"};
@@ -422,6 +423,7 @@ void readYAMLConf(YAML::Node &node)
section["quan_rule_base"] >> quan_rule_base;
section["quanx_rule_base"] >> quanx_rule_base;
section["loon_rule_base"] >> loon_rule_base;
section["sssub_rule_base"] >> sssub_rule_base;
section["append_proxy_type"] >> append_proxy_type;
section["proxy_config"] >> proxy_config;
@@ -557,6 +559,7 @@ void readYAMLConf(YAML::Node &node)
node["advanced"]["cache_subscription"] >> cache_subscription;
node["advanced"]["cache_config"] >> cache_config;
node["advanced"]["cache_ruleset"] >> cache_ruleset;
node["advanced"]["serve_cache_on_fetch_fail"] >> serve_cache_on_fetch_fail;
}
else
cache_subscription = cache_config = cache_ruleset = 0; //disable cache
@@ -605,65 +608,42 @@ void readConf()
string_array tempArray;
ini.EnterSection("common");
if(ini.ItemExist("api_mode"))
api_mode = ini.GetBool("api_mode");
if(ini.ItemExist("api_access_token"))
access_token = ini.Get("api_access_token");
if(ini.ItemExist("default_url"))
default_url = ini.Get("default_url");
if(ini.ItemExist("insert_url"))
insert_url = ini.Get("insert_url");
ini.GetBoolIfExist("api_mode", api_mode);
ini.GetIfExist("api_access_token", access_token);
ini.GetIfExist("default_url", default_url);
ini.GetIfExist("insert_url", insert_url);
if(ini.ItemPrefixExist("exclude_remarks"))
ini.GetAll("exclude_remarks", def_exclude_remarks);
if(ini.ItemPrefixExist("include_remarks"))
ini.GetAll("include_remarks", def_include_remarks);
if(ini.ItemExist("clash_rule_base"))
clash_rule_base = ini.Get("clash_rule_base");
if(ini.ItemExist("surge_rule_base"))
surge_rule_base = ini.Get("surge_rule_base");
if(ini.ItemExist("surfboard_rule_base"))
surfboard_rule_base = ini.Get("surfboard_rule_base");
if(ini.ItemExist("mellow_rule_base"))
mellow_rule_base = ini.Get("mellow_rule_base");
if(ini.ItemExist("quan_rule_base"))
quan_rule_base = ini.Get("quan_rule_base");
if(ini.ItemExist("quanx_rule_base"))
quanx_rule_base = ini.Get("quanx_rule_base");
if(ini.ItemExist("loon_rule_base"))
loon_rule_base = ini.Get("loon_rule_base");
if(ini.ItemExist("append_proxy_type"))
append_proxy_type = ini.GetBool("append_proxy_type");
if(ini.ItemExist("proxy_config"))
proxy_config = ini.Get("proxy_config");
if(ini.ItemExist("proxy_ruleset"))
proxy_ruleset = ini.Get("proxy_ruleset");
if(ini.ItemExist("proxy_subscription"))
proxy_subscription = ini.Get("proxy_subscription");
ini.GetIfExist("clash_rule_base", clash_rule_base);
ini.GetIfExist("surge_rule_base", surge_rule_base);
ini.GetIfExist("surfboard_rule_base", surfboard_rule_base);
ini.GetIfExist("mellow_rule_base", mellow_rule_base);
ini.GetIfExist("quan_rule_base", quan_rule_base);
ini.GetIfExist("quanx_rule_base", quanx_rule_base);
ini.GetIfExist("loon_rule_base", loon_rule_base);
ini.GetBoolIfExist("append_proxy_type", append_proxy_type);
ini.GetIfExist("proxy_config", proxy_config);
ini.GetIfExist("proxy_ruleset", proxy_ruleset);
ini.GetIfExist("proxy_subscription", proxy_subscription);
if(ini.SectionExist("surge_external_proxy"))
{
ini.EnterSection("surge_external_proxy");
if(ini.ItemExist("surge_ssr_path"))
surge_ssr_path = ini.Get("surge_ssr_path");
ini.GetIfExist("surge_ssr_path", surge_ssr_path);
}
if(ini.SectionExist("node_pref"))
{
ini.EnterSection("node_pref");
if(ini.ItemExist("udp_flag"))
udp_flag = ini.GetBool("udp_flag");
if(ini.ItemExist("tcp_fast_open_flag"))
tfo_flag = ini.GetBool("tcp_fast_open_flag");
if(ini.ItemExist("sort_flag"))
do_sort = ini.GetBool("sort_flag");
if(ini.ItemExist("skip_cert_verify_flag"))
scv_flag = ini.GetBool("skip_cert_verify_flag");
if(ini.ItemExist("filter_deprecated_nodes"))
filter_deprecated = ini.GetBool("filter_deprecated_nodes");
if(ini.ItemExist("append_sub_userinfo"))
append_userinfo = ini.GetBool("append_sub_userinfo");
if(ini.ItemExist("clash_use_new_field_name"))
clash_use_new_field_name = ini.GetBool("clash_use_new_field_name");
ini.GetBoolIfExist("udp_flag", udp_flag);
ini.GetBoolIfExist("tcp_fast_open_flag", tfo_flag);
ini.GetBoolIfExist("sort_flag", do_sort);
ini.GetBoolIfExist("skip_cert_verify_flag", scv_flag);
ini.GetBoolIfExist("filter_deprecated_nodes", filter_deprecated);
ini.GetBoolIfExist("append_sub_userinfo", append_userinfo);
ini.GetBoolIfExist("clash_use_new_field_name", clash_use_new_field_name);
if(ini.ItemPrefixExist("rename_node"))
{
ini.GetAll("rename_node", tempArray);
@@ -693,22 +673,15 @@ void readConf()
}
ini.EnterSection("managed_config");
if(ini.ItemExist("write_managed_config"))
write_managed_config = ini.GetBool("write_managed_config");
if(ini.ItemExist("managed_config_prefix"))
managed_config_prefix = ini.Get("managed_config_prefix");
if(ini.ItemExist("config_update_interval"))
config_update_interval = ini.GetInt("config_update_interval");
if(ini.ItemExist("config_update_strict"))
config_update_strict = ini.GetBool("config_update_strict");
if(ini.ItemExist("quanx_device_id"))
quanx_script_id = ini.Get("quanx_device_id");
ini.GetBoolIfExist("write_managed_config", write_managed_config);
ini.GetIfExist("managed_config_prefix", managed_config_prefix);
ini.GetIntIfExist("config_update_interval", config_update_interval);
ini.GetBoolIfExist("config_update_strict", config_update_strict);
ini.GetIfExist("quanx_device_id", quanx_script_id);
ini.EnterSection("emojis");
if(ini.ItemExist("add_emoji"))
add_emoji = ini.GetBool("add_emoji");
if(ini.ItemExist("remove_old_emoji"))
remove_old_emoji = ini.GetBool("remove_old_emoji");
ini.GetBoolIfExist("add_emoji", add_emoji);
ini.GetBoolIfExist("remove_old_emoji", remove_old_emoji);
if(ini.ItemPrefixExist("rule"))
{
ini.GetAll("rule", tempArray);
@@ -721,10 +694,8 @@ void readConf()
enable_rule_generator = ini.GetBool("enabled");
if(enable_rule_generator)
{
if(ini.ItemExist("overwrite_original_rules"))
overwrite_original_rules = ini.GetBool("overwrite_original_rules");
if(ini.ItemExist("update_ruleset_on_request"))
update_ruleset_on_request = ini.GetBool("update_ruleset_on_request");
ini.GetBoolIfExist("overwrite_original_rules", overwrite_original_rules);
ini.GetBoolIfExist("update_ruleset_on_request", update_ruleset_on_request);
if(ini.ItemPrefixExist("surge_ruleset"))
{
ini.GetAll("surge_ruleset", rulesets);
@@ -745,17 +716,13 @@ void readConf()
}
ini.EnterSection("server");
if(ini.ItemExist("listen"))
listen_address = ini.Get("listen");
if(ini.ItemExist("port"))
listen_port = ini.GetInt("port");
ini.GetIfExist("listen", listen_address);
ini.GetIntIfExist("port", listen_port);
ini.EnterSection("advanced");
std::string log_level;
if(ini.ItemExist("log_level"))
log_level = ini.Get("log_level");
if(ini.ItemExist("print_debug_info"))
print_debug_info = ini.GetBool("print_debug_info");
ini.GetIfExist("log_level", log_level);
ini.GetBoolIfExist("print_debug_info", print_debug_info);
if(print_debug_info)
global_log_level = LOG_LEVEL_VERBOSE;
else
@@ -781,28 +748,25 @@ void readConf()
global_log_level = LOG_LEVEL_INFO;
}
}
if(ini.ItemExist("max_pending_connections"))
max_pending_connections = ini.GetInt("max_pending_connections");
if(ini.ItemExist("max_concurrent_threads"))
max_concurrent_threads = ini.GetInt("max_concurrent_threads");
if(ini.ItemExist("enable_base_gen"))
enable_base_gen = ini.GetBool("enable_base_gen");
ini.GetIntIfExist("max_pending_connections", max_pending_connections);
ini.GetIntIfExist("max_concurrent_threads", max_concurrent_threads);
ini.GetBoolIfExist("enable_base_gen", enable_base_gen);
if(ini.ItemExist("enable_cache"))
{
if(ini.GetBool("enable_cache"))
{
if(ini.ItemExist("cache_subscription"))
cache_subscription = ini.GetInt("cache_subscription");
if(ini.ItemExist("cache_config"))
cache_config = ini.GetInt("cache_config");
if(ini.ItemExist("cache_ruleset"))
cache_ruleset = ini.GetInt("cache_ruleset");
ini.GetIntIfExist("cache_subscription", cache_subscription);
ini.GetIntIfExist("cache_config", cache_config);
ini.GetIntIfExist("cache_ruleset", cache_ruleset);
ini.GetBoolIfExist("serve_cache_on_fetch_fail", serve_cache_on_fetch_fail);
}
else
{
cache_subscription = cache_config = cache_ruleset = 0; //disable cache
serve_cache_on_fetch_fail = false;
}
}
if(ini.ItemExist("async_fetch_ruleset"))
async_fetch_ruleset = ini.GetBool("async_fetch_ruleset");
ini.GetBoolIfExist("async_fetch_ruleset", async_fetch_ruleset);
//std::cerr<<"Read preference settings completed."<<std::endl;
writeLog(0, "Read preference settings completed.", LOG_LEVEL_INFO);
@@ -819,6 +783,7 @@ struct ExternalConfig
std::string quan_rule_base;
std::string quanx_rule_base;
std::string loon_rule_base;
std::string sssub_rule_base;
string_array rename;
string_array emoji;
string_array include;
@@ -840,6 +805,7 @@ int loadExternalYAML(YAML::Node &node, ExternalConfig &ext)
section["quan_rule_base"] >> ext.quan_rule_base;
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["enable_rule_generator"] >> ext.enable_rule_generator;
section["overwrite_original_rules"] >> ext.overwrite_original_rules;
@@ -898,25 +864,17 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
importItems(ext.surge_ruleset, api_mode);
}
if(ini.ItemExist("clash_rule_base"))
ext.clash_rule_base = ini.Get("clash_rule_base");
if(ini.ItemExist("surge_rule_base"))
ext.surge_rule_base = ini.Get("surge_rule_base");
if(ini.ItemExist("surfboard_rule_base"))
ext.surfboard_rule_base = ini.Get("surfboard_rule_base");
if(ini.ItemExist("mellow_rule_base"))
ext.mellow_rule_base = ini.Get("mellow_rule_base");
if(ini.ItemExist("quan_rule_base"))
ext.quan_rule_base = ini.Get("quan_rule_base");
if(ini.ItemExist("quanx_rule_base"))
ext.quanx_rule_base = ini.Get("quanx_rule_base");
if(ini.ItemExist("loon_rule_base"))
ext.loon_rule_base = ini.Get("loon_rule_base");
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);
if(ini.ItemExist("overwrite_original_rules"))
ext.overwrite_original_rules = ini.GetBool("overwrite_original_rules");
if(ini.ItemExist("enable_rule_generator"))
ext.enable_rule_generator = ini.GetBool("enable_rule_generator");
ini.GetBoolIfExist("overwrite_original_rules", ext.overwrite_original_rules);
ini.GetBoolIfExist("enable_rule_generator", ext.enable_rule_generator);
if(ini.ItemPrefixExist("rename"))
{
@@ -991,7 +949,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
//for external configuration
std::string ext_clash_base = clash_rule_base, ext_surge_base = surge_rule_base, ext_mellow_base = mellow_rule_base, ext_surfboard_base = surfboard_rule_base;
std::string ext_quan_base = quan_rule_base, ext_quanx_base = quanx_rule_base, ext_loon_base = loon_rule_base;
std::string ext_quan_base = quan_rule_base, ext_quanx_base = quanx_rule_base, ext_loon_base = loon_rule_base, ext_sssub_base = sssub_rule_base;
//validate urls
if(!url.size() && (!api_mode || authorized))
@@ -1070,6 +1028,8 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
ext_quanx_base = extconf.quanx_rule_base;
if(extconf.loon_rule_base.size())
ext_loon_base = extconf.loon_rule_base;
if(extconf.sssub_rule_base.size())
ext_sssub_base = extconf.sssub_rule_base;
if(extconf.rename.size())
ext.rename_array = extconf.rename;
if(extconf.emoji.size())
@@ -1285,7 +1245,9 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
case "sssub"_hash:
//std::cerr<<"SS Subscription"<<std::endl;
writeLog(0, "Generate target: SS Subscription", LOG_LEVEL_INFO);
output_content = netchToSSSub(nodes, ext);
base_content = fetchFile(ext_sssub_base, proxy, cache_config);
output_content = netchToSSSub(base_content, nodes, ext);
if(upload == "true")
uploadGist("sssub", upload_path, output_content, false);
break;
+2 -1
View File
@@ -964,9 +964,10 @@ void explodeClash(Node yamlnode, const std::string &custom_port, int local_port,
singleproxy["username"] >> user;
singleproxy["password"] >> password;
singleproxy["tls"] >> tls;
node.linkType = SPEEDTEST_MESSAGE_FOUNDHTTP;
node.proxyStr = httpConstruct(ps, server, port, user, password);
node.proxyStr = httpConstruct(ps, server, port, user, password, tls == "true");
break;
case "trojan"_hash:
group = TROJAN_DEFAULT_GROUP;
+76 -1
View File
@@ -1321,7 +1321,7 @@ std::string netchToSS(std::vector<nodeInfo> &nodes, extra_settings &ext)
return base64_encode(allLinks);
}
std::string netchToSSSub(std::vector<nodeInfo> &nodes, extra_settings &ext)
std::string netchToSSSub(std::string &base_conf, std::vector<nodeInfo> &nodes, extra_settings &ext)
{
rapidjson::Document json;
rapidjson::StringBuffer sb;
@@ -1329,8 +1329,33 @@ std::string netchToSSSub(std::vector<nodeInfo> &nodes, extra_settings &ext)
std::string remark, hostname, password, method;
std::string plugin, pluginopts;
std::string protocol, obfs;
std::string route, remote_dns, ipv6, metered, proxy_apps_enabled, bypass, udpdns;
string_array android_list;
int port;
json.Parse(base_conf.data());
if(!json.HasParseError())
{
route = GetMember(json, "route");
remote_dns = GetMember(json, "remote_dns");
ipv6 = GetMember(json, "ipv6");
metered = GetMember(json, "metered");
udpdns = GetMember(json, "udpdns");
if(json.HasMember("proxy_apps") && json["proxy_apps"].IsObject())
{
proxy_apps_enabled = GetMember(json["proxy_apps"], "enabled");
bypass = GetMember(json["proxy_apps"], "bypass");
if(json["proxy_apps"].HasMember("android_list") && json["proxy_apps"]["android_list"].IsArray())
{
for(size_t i = 0; i < json["proxy_apps"]["android_list"].Size(); i++)
{
if(json["proxy_apps"]["android_list"][i].IsString())
android_list.push_back(json["proxy_apps"]["android_list"][i].GetString());
}
}
}
}
writer.StartArray();
for(nodeInfo &x : nodes)
{
@@ -1374,6 +1399,56 @@ std::string netchToSSSub(std::vector<nodeInfo> &nodes, extra_settings &ext)
writer.String(plugin.data());
writer.Key("plugin_opts");
writer.String(pluginopts.data());
if(route.size())
{
writer.Key("route");
writer.String(route.data());
}
if(remote_dns.size())
{
writer.Key("remote_dns");
writer.Bool(remote_dns == "true");
}
if(ipv6.size())
{
writer.Key("ipv6");
writer.Bool(ipv6 == "true");
}
if(metered.size())
{
writer.Key("metered");
writer.Bool(metered == "true");
}
if(udpdns.size())
{
writer.Key("udpdns");
writer.Bool(udpdns == "true");
}
if(proxy_apps_enabled.size())
{
bool enabled = proxy_apps_enabled == "true";
writer.Key("proxy_apps");
writer.StartObject();
writer.Key("enabled");
writer.Bool(enabled);
if(enabled)
{
if(bypass.size())
{
writer.Key("bypass");
writer.Bool(bypass == "true");
}
}
if(android_list.size())
{
writer.Key("android_list");
writer.StartArray();
for(const std::string &x : android_list)
writer.String(x.data());
writer.EndArray();
}
writer.EndObject();
}
writer.EndObject();
}
writer.EndArray();
+1 -1
View File
@@ -48,7 +48,7 @@ std::string netchToMellow(std::vector<nodeInfo> &nodes, std::string &base_conf,
void netchToMellow(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
std::string netchToLoon(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
std::string netchToSS(std::vector<nodeInfo> &nodes, extra_settings &ext);
std::string netchToSSSub(std::vector<nodeInfo> &nodes, extra_settings &ext);
std::string netchToSSSub(std::string &base_conf, std::vector<nodeInfo> &nodes, extra_settings &ext);
std::string netchToSSR(std::vector<nodeInfo> &nodes, extra_settings &ext);
std::string netchToVMess(std::vector<nodeInfo> &nodes, extra_settings &ext);
std::string netchToTrojan(std::vector<nodeInfo> &nodes, extra_settings &ext);
+3 -3
View File
@@ -16,7 +16,7 @@
#endif // _stat
#endif // _WIN32
extern bool print_debug_info;
extern bool print_debug_info, serve_cache_on_fetch_fail;
extern int global_log_level;
typedef std::lock_guard<std::mutex> guarded_mutex;
@@ -146,7 +146,7 @@ std::string webGet(std::string url, std::string proxy, std::string &response_hea
}
else
{
if(fileExist(path)) // failed, check if cache exist
if(fileExist(path) && serve_cache_on_fetch_fail) // failed, check if cache exist
{
writeLog(0, "Fetch failed. Serving cached content."); // cache exist, serving cache
guarded_mutex guard(cache_rw_lock);
@@ -154,7 +154,7 @@ std::string webGet(std::string url, std::string proxy, std::string &response_hea
response_headers = fileGet(path_header, true);
}
else
writeLog(0, "Fetch failed. No local cache available."); // cache not exist, serving nothing
writeLog(0, "Fetch failed. No local cache available."); // cache not exist or not allow to serve cache, serving nothing
}
return content;
}