mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2025-10-26 02:42:25 +00:00
Enhancements
Add support for new field names for Clash. Optimize logger. Update build scripts.
This commit is contained in:
42
.github/workflows/build.yml
vendored
Normal file
42
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
name: GitHub CI
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
linux32_build:
|
||||
name: Linux x86 Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build
|
||||
run: docker run --rm -v $GITHUB_WORKSPACE:/root/workdir multiarch/alpine:x86-edge /bin/sh -c "apk add bash git && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: subconverter_linux32
|
||||
path: subconverter/
|
||||
|
||||
linux64_build:
|
||||
name: Linux x86_64 Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build
|
||||
run: docker run -v $GITHUB_WORKSPACE:/root/workdir multiarch/alpine:amd64-edge /bin/sh -c "apk add bash git && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: subconverter_linux64
|
||||
path: subconverter/
|
||||
|
||||
macos_build:
|
||||
name: macOS Build
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build
|
||||
run: bash scripts/build.macos.release.sh
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: subconverter_darwin64
|
||||
path: subconverter/
|
||||
13
.travis.yml
13
.travis.yml
@@ -13,6 +13,7 @@ jobs:
|
||||
osx_image: xcode10.3
|
||||
script:
|
||||
- bash scripts/build.macos.release.sh
|
||||
- tar czf subconverter_darwin64.tar.gz subconverter
|
||||
deploy:
|
||||
provider: releases
|
||||
token: "$GITHUB_OAUTH_TOKEN"
|
||||
@@ -25,8 +26,7 @@ jobs:
|
||||
services: docker
|
||||
script:
|
||||
- docker run --rm -v $TRAVIS_BUILD_DIR:/root/workdir multiarch/alpine:x86-edge /bin/sh -c "apk add bash git && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
|
||||
before_deploy:
|
||||
- mv subconverter_linux64.tar.gz subconverter_linux32.tar.gz
|
||||
- tar czf subconverter_linux32.tar.gz subconverter/
|
||||
deploy:
|
||||
provider: releases
|
||||
token: "$GITHUB_OAUTH_TOKEN"
|
||||
@@ -39,6 +39,7 @@ jobs:
|
||||
services: docker
|
||||
script:
|
||||
- docker run -v $TRAVIS_BUILD_DIR:/root/workdir multiarch/alpine:amd64-edge /bin/sh -c "apk add bash git && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
|
||||
- tar czf subconverter_linux64.tar.gz subconverter/
|
||||
deploy:
|
||||
provider: releases
|
||||
token: "$GITHUB_OAUTH_TOKEN"
|
||||
@@ -52,8 +53,7 @@ jobs:
|
||||
arch: arm64
|
||||
script:
|
||||
- docker run --rm -v $TRAVIS_BUILD_DIR:/root/workdir multiarch/alpine:armhf-edge /bin/sh -c "apk add bash git && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
|
||||
before_deploy:
|
||||
- mv subconverter_linux64.tar.gz subconverter_armhf.tar.gz
|
||||
- tar czf subconverter_armhf.tar.gz subconverter/
|
||||
deploy:
|
||||
provider: releases
|
||||
token: "$GITHUB_OAUTH_TOKEN"
|
||||
@@ -67,8 +67,7 @@ jobs:
|
||||
arch: arm64
|
||||
script:
|
||||
- docker run -v $TRAVIS_BUILD_DIR:/root/workdir multiarch/alpine:aarch64-edge /bin/sh -c "apk add bash git && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
|
||||
before_deploy:
|
||||
- mv subconverter_linux64.tar.gz subconverter_aarch64.tar.gz
|
||||
- tar czf subconverter_aarch64.tar.gz subconverter/
|
||||
deploy:
|
||||
provider: releases
|
||||
token: "$GITHUB_OAUTH_TOKEN"
|
||||
@@ -76,4 +75,4 @@ jobs:
|
||||
skip_cleanup: true
|
||||
draft: true
|
||||
on:
|
||||
tags: true
|
||||
tags: true
|
||||
|
||||
@@ -36,6 +36,8 @@ node_pref:
|
||||
sort_flag: false
|
||||
skip_cert_verify_flag: false
|
||||
filter_deprecated_nodes: false
|
||||
append_sub_userinfo: true
|
||||
clash_use_new_field_name: false
|
||||
rename_node:
|
||||
# - {match: "\\(?((x|X)?(\\d+)(\\.?\\d+)?)((\\s?倍率?)|(x|X))\\)?", replace: "$1x"}
|
||||
- {import: snippets/rename_node.txt}
|
||||
|
||||
@@ -72,6 +72,8 @@ tcp_fast_open_flag=false
|
||||
sort_flag=false
|
||||
skip_cert_verify_flag=false
|
||||
filter_deprecated_nodes=false
|
||||
append_sub_userinfo=true
|
||||
clash_use_new_field_name=false
|
||||
|
||||
;Rename remarks with the following patterns. Supports regular expression.
|
||||
;Format: Search_Pattern@Replace_Pattern
|
||||
|
||||
@@ -20,5 +20,3 @@ chmod +rx subconverter
|
||||
chmod +r *
|
||||
cd ..
|
||||
mv base subconverter
|
||||
|
||||
tar czf subconverter_linux64.tar.gz subconverter/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -xe
|
||||
|
||||
brew reinstall yaml-cpp rapidjson libevent zlib pcre2 bzip2 pkgconfig
|
||||
brew reinstall rapidjson libevent zlib pcre2 bzip2 libssh2 pkgconfig
|
||||
|
||||
git clone https://github.com/curl/curl
|
||||
cd curl
|
||||
@@ -11,26 +11,32 @@ cmake -DHTTP_ONLY=ON -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DOPENSSL_ROOT_
|
||||
make -j8 > /dev/null
|
||||
cd ..
|
||||
|
||||
git clone https://github.com/jbeder/yaml-cpp
|
||||
cd yaml-cpp
|
||||
cmake -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF . > /dev/null
|
||||
make install -j8 > /dev/null
|
||||
cd ..
|
||||
|
||||
cp curl/lib/libcurl.a .
|
||||
cp yaml-cpp/libyaml-cpp.a .
|
||||
cp /usr/local/lib/libevent.a .
|
||||
cp /usr/local/opt/zlib/lib/libz.a .
|
||||
cp /usr/local/opt/openssl@1.1/lib/libssl.a .
|
||||
cp /usr/local/opt/openssl@1.1/lib/libcrypto.a .
|
||||
cp /usr/local/lib/libyaml-cpp.a .
|
||||
cp /usr/local/lib/libpcre2-8.a .
|
||||
cp /usr/local/opt/bzip2/lib/libbz2.a .
|
||||
cp /usr/local/lib/libssh2.a .
|
||||
|
||||
export CMAKE_CXX_FLAGS="-I/usr/local/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/curl/include"
|
||||
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@1.1 .
|
||||
make -j8
|
||||
rm subconverter
|
||||
c++ -Xlinker -unexported_symbol -Xlinker "*" -o base/subconverter CMakeFiles/subconverter.dir/src/*.o libpcre2-8.a libevent.a libcurl.a libz.a libssl.a libcrypto.a libyaml-cpp.a libbz2.a -ldl -lpthread -O3
|
||||
c++ -Xlinker -unexported_symbol -Xlinker "*" -o base/subconverter CMakeFiles/subconverter.dir/src/*.o libpcre2-8.a libevent.a libcurl.a libz.a libssl.a libcrypto.a libyaml-cpp.a libbz2.a libssh2.a -ldl -lpthread -O3
|
||||
|
||||
cd base
|
||||
chmod +rx subconverter
|
||||
chmod +r *
|
||||
cd ..
|
||||
mv base subconverter
|
||||
tar czf subconverter_darwin64.tar.gz subconverter
|
||||
|
||||
set +xe
|
||||
|
||||
@@ -40,6 +40,7 @@ std::mutex on_configuring;
|
||||
string_array renames, emojis;
|
||||
bool add_emoji = false, remove_old_emoji = false, append_proxy_type = false, filter_deprecated = true;
|
||||
bool udp_flag = false, tfo_flag = false, scv_flag = false, do_sort = false, config_update_strict = false;
|
||||
bool clash_use_new_field_name = false;
|
||||
std::string proxy_config, proxy_ruleset, proxy_subscription;
|
||||
int config_update_interval = 0;
|
||||
|
||||
@@ -452,6 +453,7 @@ void readYAMLConf(YAML::Node &node)
|
||||
section["skip_cert_verify_flag"] >> scv_flag;
|
||||
section["filter_deprecated_nodes"] >> filter_deprecated;
|
||||
section["append_sub_userinfo"] >> append_userinfo;
|
||||
section["clash_use_new_field_name"] >> clash_use_new_field_name;
|
||||
}
|
||||
|
||||
if(section["rename_node"].IsSequence())
|
||||
@@ -658,6 +660,8 @@ void readConf()
|
||||
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.Get("clash_use_new_field_name");
|
||||
if(ini.ItemPrefixExist("rename_node"))
|
||||
{
|
||||
ini.GetAll("rename_node", tempArray);
|
||||
@@ -952,7 +956,7 @@ void generateBase()
|
||||
try
|
||||
{
|
||||
clash_base = YAML::Load(base_content);
|
||||
rulesetToClash(clash_base, ruleset_content_array, overwrite_original_rules);
|
||||
rulesetToClash(clash_base, ruleset_content_array, overwrite_original_rules, clash_use_new_field_name);
|
||||
}
|
||||
catch (YAML::Exception &e)
|
||||
{
|
||||
@@ -983,6 +987,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
||||
std::string include = UrlDecode(getUrlArg(argument, "include")), exclude = UrlDecode(getUrlArg(argument, "exclude")), sort_flag = getUrlArg(argument, "sort");
|
||||
std::string scv = getUrlArg(argument, "scv"), fdn = getUrlArg(argument, "fdn"), expand = getUrlArg(argument, "expand"), append_sub_userinfo = getUrlArg(argument, "append_info");
|
||||
std::string dev_id = getUrlArg(argument, "dev_id"), filename = getUrlArg(argument, "filename"), interval_str = getUrlArg(argument, "interval"), strict_str = getUrlArg(argument, "strict");
|
||||
std::string clash_new_field = getUrlArg(argument, "new_name");
|
||||
std::string base_content, output_content;
|
||||
string_array extra_group, extra_ruleset, include_remarks, exclude_remarks;
|
||||
std::string groups = urlsafe_base64_decode(getUrlArg(argument, "groups")), ruleset = urlsafe_base64_decode(getUrlArg(argument, "ruleset")), config = UrlDecode(getUrlArg(argument, "config"));
|
||||
@@ -1047,6 +1052,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
||||
ext.sort_flag = sort_flag.size() ? sort_flag == "true" : do_sort;
|
||||
ext.skip_cert_verify = scv.size() ? scv == "true" : scv_flag;
|
||||
ext.filter_deprecated = fdn.size() ? fdn == "true" : filter_deprecated;
|
||||
ext.clash_new_field_name = clash_new_field.size() ? clash_new_field == "true" : clash_use_new_field_name;
|
||||
|
||||
ext.nodelist = nodelist == "true";
|
||||
ext.surge_ssr_path = surge_ssr_path;
|
||||
@@ -1483,6 +1489,8 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
|
||||
string_array dummy_str_array;
|
||||
std::vector<nodeInfo> nodes;
|
||||
std::string base_content, url = argument.size() <= 5 ? "" : argument.substr(5), dummy;
|
||||
const std::string proxygroup_name = clash_use_new_field_name ? "proxy-groups" : "Proxy Group", rule_name = clash_use_new_field_name ? "rules" : "Rule";
|
||||
|
||||
ini.store_any_line = true;
|
||||
|
||||
if(!url.size())
|
||||
@@ -1566,7 +1574,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
|
||||
else
|
||||
singlegroup["proxies"].push_back(trim(dummy_str_array[i]));
|
||||
}
|
||||
clash["Proxy Group"].push_back(singlegroup);
|
||||
clash[proxygroup_name].push_back(singlegroup);
|
||||
}
|
||||
|
||||
std::string subInfo;
|
||||
@@ -1588,7 +1596,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
|
||||
return "No nodes were found!";
|
||||
}
|
||||
|
||||
extra_settings ext = {true, true, dummy_str_array, dummy_str_array, false, false, false, udp_flag, tfo_flag, false, do_sort, scv_flag, filter_deprecated, "", "", ""};
|
||||
extra_settings ext = {true, true, dummy_str_array, dummy_str_array, false, false, false, udp_flag, tfo_flag, false, do_sort, scv_flag, filter_deprecated, clash_use_new_field_name, "", "", ""};
|
||||
|
||||
netchToClash(nodes, clash, dummy_str_array, false, ext);
|
||||
|
||||
@@ -1617,7 +1625,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
|
||||
}
|
||||
else
|
||||
continue;
|
||||
clash["Proxy Group"].push_back(singlegroup);
|
||||
clash[proxygroup_name].push_back(singlegroup);
|
||||
}
|
||||
|
||||
eraseElements(dummy_str_array);
|
||||
@@ -1665,7 +1673,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
|
||||
}
|
||||
rule.push_back(x);
|
||||
}
|
||||
clash["Rule"] = rule;
|
||||
clash[rule_name] = rule;
|
||||
|
||||
return YAML::Dump(clash);
|
||||
}
|
||||
|
||||
@@ -42,25 +42,28 @@ void writeLog(int type, std::string content, int level)
|
||||
*/
|
||||
if(level > global_log_level)
|
||||
return;
|
||||
std::cerr<<getTime(2)<<" ["<<getpid()<<"]";
|
||||
|
||||
switch(level)
|
||||
{
|
||||
case LOG_LEVEL_VERBOSE:
|
||||
std::cerr<<getTime(2)<<" [VERBOSE] "<<content<<"\n";
|
||||
std::cerr<<"[VERB]";
|
||||
break;
|
||||
case LOG_LEVEL_DEBUG:
|
||||
std::cerr<<getTime(2)<<" [DEBUG] "<<content<<"\n";
|
||||
std::cerr<<"[DEBG]";
|
||||
break;
|
||||
case LOG_LEVEL_INFO:
|
||||
std::cerr<<getTime(2)<<" [INFO] "<<content<<"\n";
|
||||
std::cerr<<"[INFO]";
|
||||
break;
|
||||
case LOG_LEVEL_WARNING:
|
||||
std::cerr<<getTime(2)<<" [WARNING] "<<content<<"\n";
|
||||
std::cerr<<"[WARN]";
|
||||
break;
|
||||
case LOG_LEVEL_ERROR:
|
||||
std::cerr<<getTime(2)<<" [ERROR] "<<content<<"\n";
|
||||
std::cerr<<"[ERRO]";
|
||||
break;
|
||||
case LOG_LEVEL_FATAL:
|
||||
std::cerr<<getTime(2)<<" [FATAL] "<<content<<"\n";
|
||||
std::cerr<<"[FATL]";
|
||||
break;
|
||||
}
|
||||
std::cerr<<" "<<content<<"\n";
|
||||
}
|
||||
|
||||
@@ -393,15 +393,16 @@ std::string addEmoji(std::string remark, int groupID, const string_array &emoji_
|
||||
return remark;
|
||||
}
|
||||
|
||||
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules)
|
||||
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules, bool new_field_name)
|
||||
{
|
||||
string_array allRules, vArray;
|
||||
std::string rule_group, retrived_rules, strLine;
|
||||
std::stringstream strStrm;
|
||||
const std::string field_name = new_field_name ? "rules" : "Rule";
|
||||
YAML::Node Rules;
|
||||
|
||||
if(!overwrite_original_rules && base_rule["Rule"].IsDefined())
|
||||
Rules = base_rule["Rule"];
|
||||
if(!overwrite_original_rules && base_rule[field_name].IsDefined())
|
||||
Rules = base_rule[field_name];
|
||||
|
||||
for(ruleset_content &x : ruleset_content_array)
|
||||
{
|
||||
@@ -461,7 +462,7 @@ void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset
|
||||
Rules.push_back(x);
|
||||
}
|
||||
|
||||
base_rule["Rule"] = Rules;
|
||||
base_rule[field_name] = Rules;
|
||||
}
|
||||
|
||||
void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_content_array, int surge_ver, bool overwrite_original_rules, std::string remote_path_prefix)
|
||||
@@ -868,7 +869,11 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_arr
|
||||
return;
|
||||
}
|
||||
|
||||
yamlnode["Proxy"] = proxies;
|
||||
if(ext.clash_new_field_name)
|
||||
yamlnode["proxies"] = proxies;
|
||||
else
|
||||
yamlnode["Proxy"] = proxies;
|
||||
|
||||
std::string groupname;
|
||||
|
||||
for(std::string &x : extra_proxy_group)
|
||||
@@ -925,7 +930,10 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_arr
|
||||
original_groups.push_back(singlegroup);
|
||||
}
|
||||
|
||||
yamlnode["Proxy Group"] = original_groups;
|
||||
if(ext.clash_new_field_name)
|
||||
yamlnode["proxy-groups"] = original_groups;
|
||||
else
|
||||
yamlnode["Proxy Group"] = original_groups;
|
||||
}
|
||||
|
||||
std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, bool clashR, extra_settings &ext)
|
||||
@@ -947,7 +955,7 @@ std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
return YAML::Dump(yamlnode);
|
||||
|
||||
if(ext.enable_rule_generator)
|
||||
rulesetToClash(yamlnode, ruleset_content_array, ext.overwrite_original_rules);
|
||||
rulesetToClash(yamlnode, ruleset_content_array, ext.overwrite_original_rules, ext.clash_new_field_name);
|
||||
|
||||
return YAML::Dump(yamlnode);
|
||||
}
|
||||
|
||||
@@ -30,12 +30,13 @@ struct extra_settings
|
||||
bool sort_flag = false;
|
||||
bool skip_cert_verify = false;
|
||||
bool filter_deprecated = false;
|
||||
bool clash_new_field_name = false;
|
||||
std::string surge_ssr_path;
|
||||
std::string managed_config_prefix;
|
||||
std::string quanx_dev_id;
|
||||
};
|
||||
|
||||
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules);
|
||||
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules, bool new_field_name);
|
||||
void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_content_array, int surge_ver, bool overwrite_original_rules, std::string remote_path_prefix);
|
||||
void preprocessNodes(std::vector<nodeInfo> &nodes, extra_settings &ext);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user