Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
Fix a potential bug which will cause SSD subscription to be ignored.
Add experimental Surge subscription output.
Change the default generate options.
Update build scripts.
  • Loading branch information
tindy2013 committed Nov 8, 2019
1 parent 46b78ce commit 6533df2
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 35 deletions.
8 changes: 4 additions & 4 deletions build.alpine.release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ git clone https://github.com/curl/curl
cd curl
./buildconf
./configure --with-ssl --disable-ldap --disable-ldaps --disable-rtsp --without-libidn2 > /dev/null
make install -j4
make install -j4 > /dev/null
cd ..

git clone https://github.com/jbeder/yaml-cpp
cd yaml-cpp
cmake .
make install -j4
cmake . > /dev/null
make install -j4 > /dev/null
cd ..

git clone git://sourceware.org/git/bzip2.git
cd bzip2
make install -j4
make install -j4 > /dev/null
cd ..

g++ -Wall -std=c++17 -fexceptions -DCURL_STATICLIB -c logger.cpp -o obj\logger.o
Expand Down
6 changes: 3 additions & 3 deletions build.macos.release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ brew reinstall yaml-cpp rapidjson libevent zlib

git clone https://github.com/curl/curl
cd curl
./buildconf
./buildconf > /dev/null
./configure --with-ssl=/usr/local/opt/openssl@1.1 --without-mbedtls --disable-ldap --disable-ldaps --disable-rtsp --without-libidn2 > /dev/null
make -j8
make -j8 > /dev/null
cd ..

curl -L -o bzip2-1.0.6.tar.gz https://sourceforge.net/projects/bzip2/files/bzip2-1.0.6.tar.gz/download
tar xvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make -j8
make -j8 > /dev/null
cd ..

cp /usr/local/lib/libevent.a .
Expand Down
35 changes: 34 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void readConf()
}

std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &baseConf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, bool clashR);
std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, int surge_ver);
std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, string_array &ruleset_array, string_array &extra_proxy_group, int surge_ver);

int main()
{
Expand Down Expand Up @@ -239,6 +239,39 @@ int main()
return netchToClash(nodes, clash_base_content, ruleset_content_array, clash_extra_group, true);
});

append_response("GET", "/surge", "text/plain;charset=utf-8", [](RESPONSE_CALLBACK_ARGS) -> std::string
{
if(!api_mode)
readConf();
std::string surge_base_content;
std::string url = UrlDecode(getUrlArg(argument, "url")), include = UrlDecode(getUrlArg(argument, "regex")), group = UrlDecode(getUrlArg(argument, "group"));
int surge_ver = stoi(getUrlArg(argument, "ver"));
if(!url.size()) url = default_url;
string_array urls = split(url, "|");
std::vector<nodeInfo> nodes;
if(include.size())
{
eraseElements(def_include_remarks);
def_include_remarks.emplace_back(include);
}
if(group.size()) custom_group = group;
for(std::string &x : urls)
{
std::cerr<<"Fetching node data from url '"<<x<<"'. Generate target: Surge "<<surge_ver<<std::endl;
addNodes(x, nodes);
}
if(fileExist(surge_rule_base))
{
surge_base_content = fileGet(surge_rule_base, false);
}
else
surge_base_content = webGet(surge_rule_base, getSystemProxy());

if(update_ruleset_on_request)
refreshRulesets();
return netchToSurge(nodes, surge_base_content, rulesets, clash_extra_group, surge_ver);
});

if(!api_mode)
{
append_response("GET", "/get", "text/plain;charset=utf-8", [](RESPONSE_CALLBACK_ARGS) -> std::string
Expand Down
51 changes: 29 additions & 22 deletions pref.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
default_url=

;Exclude nodes which remarks match the following patterns. Supports regular expression.
exclude_remarks=(剩余流量|到期时间|过期时间|官网地址|产品名称)
exclude_remarks=(流量|时间|官网|产品)
;exclude_remarks=(other rule)

;Only include nodes which remarks match the following patterns. Supports regular expression.
Expand All @@ -12,6 +12,9 @@ exclude_remarks=(剩余流量|到期时间|过期时间|官网地址|产品名
;Clash config base used by the generator, supports local files/URL
clash_rule_base=simple_base.yml

;Surge config base used by the generator, supports local files/URL
surge_rule_base=surge.conf

;Rename remarks with the following patterns. Supports regular expression.
;Format: Search_Pattern@Replace_Pattern
;rename_node=IPLC@专线
Expand Down Expand Up @@ -76,19 +79,19 @@ update_ruleset_on_request=false
; Group name,[]Rule

surge_ruleset=DIRECT,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Unbreak.list
surge_ruleset=Advertising,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Advertising.list
surge_ruleset=Hijacking,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Hijacking.list
surge_ruleset=YouTube,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Media/YouTube.list
surge_ruleset=Netflix,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Media/Netflix.list
surge_ruleset=⛔️ 广告拦截,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Advertising.list
surge_ruleset=🚫 运营劫持,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Hijacking.list
surge_ruleset=🌌 YouTube,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Media/YouTube.list
surge_ruleset=🎥 NETFLIX,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Media/Netflix.list
;surge_ruleset=HBO,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Media/HBO.list
;surge_ruleset=Fox,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Media/Fox.list
surge_ruleset=GlobalMedia,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/GlobalMedia.list
surge_ruleset=HKMTMedia,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/HKMTMedia.list
surge_ruleset=Telegram,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Telegram.list
surge_ruleset=PROXY,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Global.list
surge_ruleset=Apple,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Apple.list
surge_ruleset=🌍 国外媒体,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/GlobalMedia.list
surge_ruleset=🌏 港台媒体,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/HKMTMedia.list
surge_ruleset=📲 电报信息,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Telegram.list
surge_ruleset=🔰 节点选择,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Global.list
surge_ruleset=🍎 苹果服务,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/Apple.list
surge_ruleset=DIRECT,https://raw.githubusercontent.com/ConnersHua/Profiles/master/Surge/Ruleset/China.list
surge_ruleset=Final,[]MATCH
surge_ruleset=💕 规则自选,[]MATCH

[clash_proxy_group]
;Generate Clash Proxy Group with the following patterns. Node filterting rule supports regular expression.
Expand All @@ -101,7 +104,8 @@ surge_ruleset=Final,[]MATCH
;custom_proxy_group=LoadBalance`load-balance`.*`http://www.gstatic.com/generate_204`300

;for forcerule.yml
;custom_proxy_group=Proxy`select`.*
;custom_proxy_group=Proxy`select`.*[]AUTO`[]DIRECT`.*
;custom_proxy_group=AUTO`url-test`.*`http://www.gstatic.com/generate_204`300
;custom_proxy_group=google`select`.*
;custom_proxy_group=netflix`select`.*
;custom_proxy_group=动画疯`select`(深台|彰化|新北|台)
Expand All @@ -116,16 +120,19 @@ surge_ruleset=Final,[]MATCH
;custom_proxy_group=Telegram`select`新加坡`[]Proxy

;for DivineEngine_Profiles
custom_proxy_group=PROXY`select`.*
custom_proxy_group=YouTube`select`.*
custom_proxy_group=Netflix`select`.*
custom_proxy_group=Advertising`select`[]REJECT`[]DIRECT`[]PROXY
custom_proxy_group=Hijacking`select`[]REJECT`[]DIRECT`[]PROXY
custom_proxy_group=GlobalMedia`select`.*
custom_proxy_group=HKMTMedia`select`(HGC|HKBN|PCCW|HKT|深台|彰化|新北|台|新加坡|sg|hk|tw)
custom_proxy_group=Telegram`select`新加坡`[]PROXY
custom_proxy_group=Apple`select`[]DIRECT`[]PROXY
custom_proxy_group=Final`select`[]PROXY`[]DIRECT
custom_proxy_group=🔰 节点选择`select`[]♻️ 自动选择`[]🎯 全球直连`.*
custom_proxy_group=♻️ 自动选择`url-test`.*`http://www.gstatic.com/generate_204`300
custom_proxy_group=🌌 YouTube`select`[]🔰 节点选择`[]♻️ 自动选择`[]🎯 全球直连`.*
custom_proxy_group=🎥 NETFLIX`select`[]🔰 节点选择`[]♻️ 自动选择`[]🎯 全球直连`.*
custom_proxy_group=⛔️ 广告拦截`select`[]🛑 全球拦截`[]🎯 全球直连`[]🔰 节点选择
custom_proxy_group=🚫 运营劫持`select`[]🛑 全球拦截`[]🎯 全球直连`[]🔰 节点选择
custom_proxy_group=🌍 国外媒体`select`[]♻️ 自动选择`[]🎯 全球直连`.*
custom_proxy_group=🌏 港台媒体`select`(HGC|HKBN|PCCW|HKT|深台|彰化|新北|台|hk|香港|tw)
custom_proxy_group=📲 电报信息`select`[]🔰 节点选择`[]♻️ 自动选择`[]DIRECT`(美|新加坡|sg|us)`.*
custom_proxy_group=🍎 苹果服务`select`[]🔰 节点选择`[]🎯 全球直连`[]♻️ 自动选择`.*
custom_proxy_group=💕 规则自选`select`[]🔰 节点选择`[]🎯 全球直连`[]♻️ 自动选择`.*
custom_proxy_group=🎯 全球直连`select`[]DIRECT
custom_proxy_group=🛑 全球拦截`select`[]REJECT

[server]
;Address to bind on for Web Server
Expand Down
10 changes: 5 additions & 5 deletions speedtestutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1486,9 +1486,10 @@ void explodeSub(std::string sub, bool sslibev, bool ssrlibev, std::string custom
std::string strLink;
nodeInfo node;

//try to parse as surge configuration
if(explodeSurge(sub, custom_port, local_port, nodes, sslibev))
//try to parse as SSD configuration
if(strFind(sub, "ssd://"))
{
explodeSSD(sub, sslibev, custom_port, local_port, nodes);
return;
}

Expand All @@ -1510,10 +1511,9 @@ void explodeSub(std::string sub, bool sslibev, bool ssrlibev, std::string custom
//ignore
}

//try to parse as SSD configuration
if(strFind(sub, "ssd://"))
//try to parse as surge configuration
if(explodeSurge(sub, custom_port, local_port, nodes, sslibev))
{
explodeSSD(sub, sslibev, custom_port, local_port, nodes);
return;
}

Expand Down
Loading

0 comments on commit 6533df2

Please sign in to comment.