OpenClash: sync with upstream source
This commit is contained in:
parent
6361bb9ada
commit
758ab4a011
@ -109,7 +109,7 @@ if [ -d "/tmp/openclash_core/" ]; then
|
||||
fi
|
||||
mkdir -p /lib/upgrade/keep.d >/dev/null 2>&1
|
||||
cat > "/lib/upgrade/keep.d/luci-app-openclash" <<-EOF
|
||||
/etc/openclash/clash
|
||||
/etc/openclash/core/
|
||||
/etc/openclash/custom/
|
||||
/etc/openclash/config/
|
||||
/etc/openclash/game_rules/
|
||||
|
||||
@ -105,9 +105,10 @@ fake_block() {
|
||||
|
||||
yml_check()
|
||||
{
|
||||
#替换tab
|
||||
#格式替换
|
||||
sed -i 's/\t/ /g' "$3" 2>/dev/null
|
||||
|
||||
sed -i "s/- \{2,\}/- /g" "$3" 2>/dev/null
|
||||
|
||||
#检查关键字避免后续操作出错
|
||||
#proxies
|
||||
[ -z "$(grep "^Proxy:" "$3")" ] && {
|
||||
@ -798,9 +799,9 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
|
||||
ln -s /usr/share/openclash/yacd /www/luci-static/openclash 2>/dev/null
|
||||
|
||||
echo "第八步: 设置防火墙规则..." >$START_LOG
|
||||
if [ "$(iptables -t nat -nL PREROUTING --line-number |grep "udp dpt:53" |wc -l)" -gt 1 ] && [ "$enable_redirect_dns" -eq "1" ]; then
|
||||
if [ "$(iptables -t nat -nL PREROUTING --line-number |grep "udp dpt:53" |grep "0.0.0.0/0 \{0,\}0.0.0.0/0" |wc -l)" -gt 1 ] && [ "$enable_redirect_dns" -eq "1" ]; then
|
||||
echo "发现53端口被劫持,清理防火墙规则..." >$START_LOG
|
||||
pre_lines=$(iptables -nvL PREROUTING -t nat |sed 1,2d |sed -n '/udp dpt:53/=' 2>/dev/null |sort -rn)
|
||||
pre_lines=$(iptables -nvL PREROUTING -t nat |sed 1,2d |sed -n '/0.0.0.0\/0 \{0,\}0.0.0.0\/0 \{0,\}udp dpt:53/=' 2>/dev/null |sort -rn)
|
||||
for pre_line in $pre_lines; do
|
||||
iptables -t nat -D PREROUTING "$pre_line" >/dev/null 2>&1
|
||||
done
|
||||
|
||||
@ -130,7 +130,15 @@ o.write = function()
|
||||
fs.unlink("/tmp/Proxy_Group")
|
||||
m.uci:set("openclash", "config", "enable", 1)
|
||||
m.uci:commit("openclash")
|
||||
SYS.call("rm -rf /etc/openclash/backup/* 2>/dev/null")
|
||||
uci:foreach("openclash", "config_subscribe",
|
||||
function(s)
|
||||
if s.name ~= "" and s.name ~= nil and s.enabled == "1" then
|
||||
local back_cfg_path_yaml="/etc/openclash/backup/" .. s.name .. ".yaml"
|
||||
local back_cfg_path_yml="/etc/openclash/backup/" .. s.name .. ".yaml"
|
||||
fs.unlink(back_cfg_path_yaml)
|
||||
fs.unlink(back_cfg_path_yml)
|
||||
end
|
||||
end)
|
||||
SYS.call("/usr/share/openclash/openclash.sh >/dev/null 2>&1 &")
|
||||
HTTP.redirect(DISP.build_url("admin", "services", "openclash"))
|
||||
end
|
||||
|
||||
@ -100,7 +100,7 @@ cfg_new_servers_groups_check()
|
||||
fi
|
||||
|
||||
[ "$1" = "$2" ] && {
|
||||
config_group_exist="1"
|
||||
config_group_exist=$(( $config_group_exist + 1 ))
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,13 +123,21 @@ cfg_group_name()
|
||||
fi
|
||||
|
||||
config_list_foreach "config" "new_servers_group" cfg_new_servers_groups_check "$name"
|
||||
|
||||
config_group_exists=$(( $config_group_exists + 1 ))
|
||||
}
|
||||
|
||||
#判断当前配置文件策略组信息是否包含指定策略组
|
||||
config_group_exist=0
|
||||
config_group_exists=0
|
||||
config_load "openclash"
|
||||
config_foreach cfg_group_name "groups"
|
||||
|
||||
if [ "$config_group_exists" -eq "$config_group_exist" ]; then
|
||||
config_group_exist=1
|
||||
else
|
||||
config_group_exist=0
|
||||
fi
|
||||
|
||||
echo "开始更新【$CONFIG_NAME】的代理集配置..." >$START_LOG
|
||||
|
||||
yml_provider_name_get()
|
||||
@ -255,7 +263,7 @@ do
|
||||
|
||||
|
||||
#加入策略组
|
||||
if [ "$servers_if_update" = "1" ] && [ ! -z "$new_servers_group" ] && [ ! -z "$config_group_exist" ]; then
|
||||
if [ "$servers_if_update" = "1" ] && [ ! -z "$new_servers_group" ] && [ "$config_group_exist" -eq 1 ]; then
|
||||
#新代理集且设置默认策略组时加入指定策略组
|
||||
config_load "openclash"
|
||||
config_list_foreach "config" "new_servers_group" cfg_new_provider_groups_get
|
||||
@ -715,7 +723,7 @@ do
|
||||
fi
|
||||
|
||||
#加入策略组
|
||||
if [ "$servers_if_update" = "1" ] && [ ! -z "$new_servers_group" ] && [ ! -z "$config_group_exist" ]; then
|
||||
if [ "$servers_if_update" = "1" ] && [ ! -z "$new_servers_group" ] && [ "$config_group_exist" -eq 1 ]; then
|
||||
#新节点且设置默认策略组时加入指定策略组
|
||||
config_load "openclash"
|
||||
config_list_foreach "config" "new_servers_group" cfg_new_servers_groups_get
|
||||
|
||||
@ -2,10 +2,7 @@
|
||||
|
||||
check_def=0
|
||||
if [ "$2" != 0 ]; then
|
||||
if [ ! -f /etc/openclash/"$2".yaml ]; then
|
||||
echo "${1} /etc/openclash/"$2".yaml Not Exist, Will Use Self Rules, Please Update and Try Again" >>/tmp/openclash.log
|
||||
exit 0
|
||||
elif [ "$(uci get openclash.config.Proxy)" = "读取错误,配置文件异常!" ]; then
|
||||
if [ "$(uci get openclash.config.Proxy)" = "读取错误,配置文件异常!" ]; then
|
||||
echo "${1} Warning: Can not Get The Porxy-Group's Name, Stop Setting The Other Rules!" >>/tmp/openclash.log
|
||||
exit 0
|
||||
else
|
||||
@ -147,6 +144,7 @@ elif [ "$2" = 0 ]; then
|
||||
}
|
||||
fi
|
||||
|
||||
sed -i "s/'//g" "$4" 2>/dev/null
|
||||
sed -i '/^##Custom Rules##/,/^##Custom Rules End##/d' "$4" 2>/dev/null
|
||||
sed -i '/^##Custom Rules##/d' "$4" 2>/dev/null
|
||||
sed -i '/^##Custom Rules End##/d' "$4" 2>/dev/null
|
||||
@ -157,18 +155,21 @@ fi
|
||||
sed -i '/- DOMAIN-KEYWORD,announce,DIRECT/d' "$4" 2>/dev/null
|
||||
sed -i '/- DOMAIN-KEYWORD,torrent,DIRECT/d' "$4" 2>/dev/null
|
||||
|
||||
if [ -z "$(grep '- IP-CIDR,198.18.0.1/16,REJECT,no-resolve' "$4")" ] && [ "$6" = "fake-ip" ]; then
|
||||
if [ -z "$(grep '^ \{0,\}- IP-CIDR,198.18.0.1/16,REJECT,no-resolve' "$4")" ] && [ "$6" = "fake-ip" ]; then
|
||||
if [ ! -z "$(grep "^ \{0,\}- IP-CIDR,198.18.0.1/16" "$4")" ]; then
|
||||
sed -i "/^ \{0,\}- IP-CIDR,198.18.0.1\/16/c\- IP-CIDR,198.18.0.1\/16,REJECT,no-resolve" "$4"
|
||||
sed -i "/^ \{0,\}- IP-CIDR,198.18.0.1\/16/c\- IP-CIDR,198.18.0.1\/16,REJECT,no-resolve" "$4" 2>/dev/null
|
||||
else
|
||||
sed -i '1,/^ \{0,\}- GEOIP/{/^ \{0,\}- GEOIP/s/^ \{0,\}- GEOIP/- IP-CIDR,198.18.0.1\/16,REJECT,no-resolve\n&/}' "$4"\
|
||||
|| sed -i '1,/^ \{0,\}- MATCH/{/^ \{0,\}- MATCH/s/^ \{0,\}- MATCH/- IP-CIDR,198.18.0.1\/16,REJECT,no-resolve\n&/}' "$4"\
|
||||
|| sed -i '1,/^ \{0,\}- FINAL/{/^ \{0,\}- FINAL/s/^ \{0,\}- FINAL/- IP-CIDR,198.18.0.1\/16,REJECT,no-resolve\n&/}' "$4"
|
||||
sed -i '1,/^ \{0,\}- GEOIP/{/^ \{0,\}- GEOIP/s/^ \{0,\}- GEOIP/- IP-CIDR,198.18.0.1\/16,REJECT,no-resolve\n&/}' "$4" 2>/dev/null\
|
||||
|| sed -i '1,/^ \{0,\}- MATCH/{/^ \{0,\}- MATCH/s/^ \{0,\}- MATCH/- IP-CIDR,198.18.0.1\/16,REJECT,no-resolve\n&/}' "$4" 2>/dev/null\
|
||||
|| sed -i '1,/^ \{0,\}- FINAL/{/^ \{0,\}- FINAL/s/^ \{0,\}- FINAL/- IP-CIDR,198.18.0.1\/16,REJECT,no-resolve\n&/}' "$4" 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$7" = 1 ]; then
|
||||
sed -i '1,/^ \{0,\}- GEOIP/{/^ \{0,\}- GEOIP/s/^ \{0,\}- GEOIP/- DOMAIN-KEYWORD,tracker,DIRECT\n&/}' "$4" 2>/dev/null
|
||||
sed -i '1,/^ \{0,\}- GEOIP/{/^ \{0,\}- GEOIP/s/^ \{0,\}- GEOIP/- DOMAIN-KEYWORD,tracker,DIRECT\n&/}' "$4" 2>/dev/null\
|
||||
|| sed -i '1,/^ \{0,\}- MATCH/{/^ \{0,\}- MATCH/s/^ \{0,\}- MATCH/- DOMAIN-KEYWORD,tracker,DIRECT\n&/}' "$4" 2>/dev/null\
|
||||
|| sed -i '1,/^ \{0,\}- FINAL/{/^ \{0,\}- FINAL/s/^ \{0,\}- FINAL/- DOMAIN-KEYWORD,tracker,DIRECT\n&/}' "$4" 2>/dev/null\
|
||||
|| echo "- DOMAIN-KEYWORD,tracker,DIRECT" >> "$4" 2>/dev/null
|
||||
sed -i "/- DOMAIN-KEYWORD,tracker,DIRECT/a\- DOMAIN-KEYWORD,announce,DIRECT" "$4" 2>/dev/null
|
||||
sed -i "/- DOMAIN-KEYWORD,tracker,DIRECT/a\- DOMAIN-KEYWORD,torrent,DIRECT" "$4" 2>/dev/null
|
||||
if [ -z "$(grep "###- MATCH," "$4")" ] && [ -z "$(grep "###- FINAL," "$4")" ]; then
|
||||
@ -188,7 +189,9 @@ fi
|
||||
sed -i '/^Rule:/a\##Custom Rules End##' "$4" 2>/dev/null
|
||||
sed -i '/^Rule:/a\##Custom Rules##' "$4" 2>/dev/null
|
||||
sed -i '/^##Custom Rules##/r/etc/openclash/custom/openclash_custom_rules.list' "$4" 2>/dev/null
|
||||
sed -i '/^ \{0,\}- MATCH,/i\##Custom Rules 2##' "$4" 2>/dev/null
|
||||
sed -i '/^ \{0,\}- MATCH,/i\##Custom Rules 2##' "$4" 2>/dev/null\
|
||||
|| sed -i '/^ \{0,\}- FINAL,/i\##Custom Rules 2##' "$4" 2>/dev/null\
|
||||
|| echo "##Custom Rules 2##" >> "$4" 2>/dev/null
|
||||
sed -i '/^##Custom Rules 2##/a\##Custom Rules 2 End##' "$4" 2>/dev/null
|
||||
sed -i '/^##Custom Rules 2##/r/etc/openclash/custom/openclash_custom_rules_2.list' "$4" 2>/dev/null
|
||||
fi
|
||||
|
||||
Loading…
Reference in New Issue
Block a user