luci-app-openclash: sync source
This commit is contained in:
parent
2294c0b0c2
commit
be73fa2bab
@ -1,7 +1,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-openclash
|
||||
PKG_VERSION:=0.33.2
|
||||
PKG_VERSION:=0.33.3
|
||||
PKG_RELEASE:=beta
|
||||
PKG_MAINTAINER:=vernesong <https://github.com/vernesong/OpenClash>
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (c) 2011-2015 OpenWrt.org
|
||||
# Copyright (c) 2019 vernesong
|
||||
|
||||
START=99
|
||||
STOP=15
|
||||
@ -11,8 +11,8 @@ CRON_FILE="/etc/crontabs/root"
|
||||
CONFIG_FILE="/etc/openclash/config.yaml"
|
||||
LOG_FILE="/tmp/openclash.log"
|
||||
START_LOG="/tmp/openclash_start.log"
|
||||
BACKPACK_FILE="/etc/openclash/config.bak"
|
||||
START_BACKPACK="/tmp/config.sbak"
|
||||
BACKUP_FILE="/etc/openclash/config.bak"
|
||||
START_BACKUP="/tmp/config.sbak"
|
||||
CHANGE_FILE="/tmp/yaml_change.yaml"
|
||||
RULE_FILE="/tmp/yaml_rules.yaml"
|
||||
DNS_FILE="/tmp/yaml_dns.yaml"
|
||||
@ -282,8 +282,8 @@ status=$(ps|grep -c /etc/init.d/openclash)
|
||||
if [ ! -f "$CONFIG_FILE" ] && [ "$(ls -l /etc/openclash/config.yml 2>/dev/null |awk '{print int($5/1024)}')" -gt 0 ]; then
|
||||
mv "/etc/openclash/config.yml" "$CONFIG_FILE"
|
||||
fi
|
||||
if [ ! -f "$CONFIG_FILE" ] && [ -f "$BACKPACK_FILE" ]; then
|
||||
cp $BACKPACK_FILE $CONFIG_FILE
|
||||
if [ ! -f "$CONFIG_FILE" ] && [ -f "$BACKUP_FILE" ]; then
|
||||
cp $BACKUP_FILE $CONFIG_FILE
|
||||
fi
|
||||
|
||||
echo "OpenClash 开始启动..." >$START_LOG
|
||||
@ -308,12 +308,12 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
|
||||
http_port=$(uci get openclash.config.http_port 2>/dev/null)
|
||||
socks_port=$(uci get openclash.config.socks_port 2>/dev/null)
|
||||
echo "第二步: 配置文件检查..." >$START_LOG
|
||||
yml_check "$en_mode" "$enable_custom_dns" "$CONFIG_FILE" "$BACKPACK_FILE" "$START_BACKPACK"
|
||||
grep "^ \{0,\}nameserver:" $CONFIG_FILE >/dev/null 2>&1 && grep "^ \{0,\}Proxy:" $CONFIG_FILE >/dev/null 2>&1 && grep "^ \{0,\}Proxy Group:" $CONFIG_FILE >/dev/null 2>&1 && grep "^ \{0,\}Rule:" $CONFIG_FILE >/dev/null 2>&1
|
||||
yml_check "$en_mode" "$enable_custom_dns" "$CONFIG_FILE" "$BACKUP_FILE" "$START_BACKUP"
|
||||
grep "^ \{0,\}Proxy:" $CONFIG_FILE >/dev/null 2>&1 && grep "^ \{0,\}Proxy Group:" $CONFIG_FILE >/dev/null 2>&1 && grep "^ \{0,\}Rule:" $CONFIG_FILE >/dev/null 2>&1
|
||||
if [ "$?" -ne "0" ]; then
|
||||
nohup $CLASH -d "$CLASH_CONFIG" >> $LOG_FILE 2>&1 &
|
||||
echo "错误: 配置文件完整性检查不通过,已自动还原配置文件,请根据日志信息对照模板格式检查修改配置文件!" >$START_LOG
|
||||
mv $START_BACKPACK $CONFIG_FILE
|
||||
mv $START_BACKUP $CONFIG_FILE
|
||||
stop
|
||||
sleep 5
|
||||
echo "" >$START_LOG
|
||||
@ -334,7 +334,7 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
|
||||
if [ ! -z "$(sed -n '/^ \{0,\}nameserver:/{n;p}' $CONFIG_FILE |grep '^ \{0,\}fallback:')" ] || [ ! -z "$(sed -n '/^ \{0,\}nameserver:/{n;p}' $CONFIG_FILE |grep 'OpenClash-General')" ]; then
|
||||
echo "错误: 配置文件DNS选项下的Nameserver必须设置服务器,已自动还原配置文件,请重新设置!" >$START_LOG
|
||||
echo "${LOGTIME} Nameserver Must Be Set, Please Change Your Configrations In Config.yaml" >>$LOG_FILE
|
||||
mv $START_BACKPACK $CONFIG_FILE
|
||||
mv $START_BACKUP $CONFIG_FILE
|
||||
sleep 10
|
||||
echo "" >$START_LOG
|
||||
else
|
||||
@ -384,17 +384,46 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
|
||||
sleep 5
|
||||
echo "" >$START_LOG
|
||||
else
|
||||
echo "错误: OpenClash 启动失败,请到日志页面查看详细错误信息!" >$START_LOG
|
||||
echo "${LOGTIME} OpenClash Can Not Start, Please Check The Error Info And Try Again" >> $LOG_FILE
|
||||
sleep 10
|
||||
echo "" >$START_LOG
|
||||
stop && echo "" >$START_LOG
|
||||
if [ "$rule_source" != 0 ]; then
|
||||
echo "错误: OpenClash 启动失败,尝试还原规则并重新启动 Clash 主程序..." >$START_LOG
|
||||
echo "${LOGTIME} OpenClash Can Not Start, Try Use Backup Rules Start Again" >> $LOG_FILE
|
||||
mv "$BACKUP_FILE" /etc/openclash/configrules.bak
|
||||
sed -i -n '/^Rule:/,$p' /etc/openclash/configrules.bak
|
||||
sed -i '/^Rule:/,$d' "$CONFIG_FILE"
|
||||
cat /etc/openclash/configrules.bak >> "$CONFIG_FILE"
|
||||
rm -rf /etc/openclash/configrules.bak
|
||||
nohup $CLASH -d "$CLASH_CONFIG" >> $LOG_FILE 2>&1 &
|
||||
if pidof clash >/dev/null; then
|
||||
add_cron
|
||||
echo "OpenClash 使用备份规则启动成功,请更新、检查第三方规则后重试!" >$START_LOG
|
||||
echo "${LOGTIME} OpenClash Start Successful With Backup Rules Config, Please Check Or Update Other Rules And Retry" >> $LOG_FILE
|
||||
sleep 5
|
||||
echo "" >$START_LOG
|
||||
else
|
||||
echo "错误: OpenClash 启动失败,请到日志页面查看详细错误信息!" >$START_LOG
|
||||
echo "${LOGTIME} OpenClash Can Not Start, Please Check The Error Info And Try Again" >> $LOG_FILE
|
||||
sleep 10
|
||||
echo "" >$START_LOG
|
||||
stop && echo "" >$START_LOG
|
||||
fi
|
||||
else
|
||||
echo "错误: OpenClash 启动失败,请到日志页面查看详细错误信息!" >$START_LOG
|
||||
echo "${LOGTIME} OpenClash Can Not Start, Please Check The Error Info And Try Again" >> $LOG_FILE
|
||||
sleep 10
|
||||
echo "" >$START_LOG
|
||||
stop && echo "" >$START_LOG
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
rm -rf $START_BACKPACK 2>/dev/null
|
||||
rm -rf $START_BACKUP 2>/dev/null
|
||||
fi
|
||||
else
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
subscribe_url=$(uci get openclash.config.subscribe_url 2>/dev/null)
|
||||
if [ ! -f "$CONFIG_FILE" ] && [ ! -z "$subscribe_url" ]; then
|
||||
echo "OpenClash 配置文件不存在,开始下载..." >$START_LOG
|
||||
nohup /usr/share/openclash/openclash.sh &
|
||||
exit 0
|
||||
elif [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "错误: OpenClash 缺少配置文件,请上传或更新配置文件!" >$START_LOG
|
||||
echo "${LOGTIME} Config Not Found" >> $LOG_FILE
|
||||
sleep 5
|
||||
|
||||
@ -37,19 +37,19 @@ authentication: # 此项将被接管
|
||||
- "user1:pass1"
|
||||
- "user2:pass2"
|
||||
|
||||
dns: # 此参数必须保留,不能删除,如订阅配置无包括此项的所有DNS设置,OpenClash将自动添加
|
||||
dns: # 如订阅配置无包括此项的所有DNS设置,OpenClash将自动添加
|
||||
enable: true # set true to enable dns (default is false) # 此项将被接管为true
|
||||
ipv6: false # default is false # 此项将被接管
|
||||
listen: 0.0.0.0:53 # 端口为53时将被接管为7874
|
||||
enhanced-mode: redir-host # or fake-ip # 此项可被接管
|
||||
enhanced-mode: redir-host # or fake-ip # 此项将被接管
|
||||
fake-ip-range: 198.18.0.1/16 # if you don't know what it is, don't change it # 此项将被接管
|
||||
# experimental hosts, support wildcard (e.g. *.clash.dev Even *.foo.*.example.com)
|
||||
# static domain has a higher priority than wildcard domain (foo.example.com > *.example.com)
|
||||
# NOTE: hosts don't work with `fake-ip`
|
||||
# hosts:
|
||||
# hosts: # 此项将被接管
|
||||
# '*.clash.dev': 127.0.0.1
|
||||
# 'alpha.clash.dev': '::1'
|
||||
nameserver: # 此参数必须保留,不能删除
|
||||
nameserver:
|
||||
- 114.114.114.114
|
||||
- tls://dns.rubyfish.cn:853 # dns over tls
|
||||
- https://1.1.1.1/dns-query # dns over https
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -42,24 +42,17 @@ local function config_check()
|
||||
local yml = luci.sys.call("ls -l /etc/openclash/config.yml >/dev/null 2>&1")
|
||||
local nameserver,proxy,group,rule
|
||||
if (yaml == 0) then
|
||||
nameserver = luci.sys.call("egrep '^ {0,}nameserver:' /etc/openclash/config.yaml >/dev/null 2>&1")
|
||||
proxy = luci.sys.call("egrep '^ {0,}Proxy:' /etc/openclash/config.yaml >/dev/null 2>&1")
|
||||
group = luci.sys.call("egrep '^ {0,}Proxy Group:' /etc/openclash/config.yaml >/dev/null 2>&1")
|
||||
rule = luci.sys.call("egrep '^ {0,}Rule:' /etc/openclash/config.yaml >/dev/null 2>&1")
|
||||
else
|
||||
if (yml == 0) then
|
||||
nameserver = luci.sys.call("egrep '^ {0,}nameserver:' /etc/openclash/config.yml >/dev/null 2>&1")
|
||||
proxy = luci.sys.call("egrep '^ {0,}Proxy:' /etc/openclash/config.yml >/dev/null 2>&1")
|
||||
group = luci.sys.call("egrep '^ {0,}Proxy Group:' /etc/openclash/config.yml >/dev/null 2>&1")
|
||||
rule = luci.sys.call("egrep '^ {0,}Rule:' /etc/openclash/config.yml >/dev/null 2>&1")
|
||||
end
|
||||
end
|
||||
if (yaml == 0) or (yml == 0) then
|
||||
if (nameserver == 0) then
|
||||
nameserver = ""
|
||||
else
|
||||
nameserver = " - DNS服务器"
|
||||
end
|
||||
if (proxy == 0) then
|
||||
proxy = ""
|
||||
else
|
||||
@ -75,7 +68,7 @@ local function config_check()
|
||||
else
|
||||
rule = " - 规则"
|
||||
end
|
||||
return nameserver..proxy..group..rule
|
||||
return proxy..group..rule
|
||||
elseif (yaml ~= 0) and (yml ~= 0) then
|
||||
return "1"
|
||||
end
|
||||
|
||||
@ -164,7 +164,7 @@ o:value("3", translate("Every Wednesday"))
|
||||
o:value("4", translate("Every Thursday"))
|
||||
o:value("5", translate("Every Friday"))
|
||||
o:value("6", translate("Every Saturday"))
|
||||
o:value("7", translate("Every Sunday"))
|
||||
o:value("0", translate("Every Sunday"))
|
||||
o.default=1
|
||||
|
||||
o = s:taboption("config_update", ListValue, "auto_update_time", translate("Update time (every day)"))
|
||||
@ -211,7 +211,7 @@ o:value("3", translate("Every Wednesday"))
|
||||
o:value("4", translate("Every Thursday"))
|
||||
o:value("5", translate("Every Friday"))
|
||||
o:value("6", translate("Every Saturday"))
|
||||
o:value("7", translate("Every Sunday"))
|
||||
o:value("0", translate("Every Sunday"))
|
||||
o.default=1
|
||||
|
||||
o = s:taboption("rules_update", ListValue, "other_rule_update_day_time", translate("Update time (every day)"))
|
||||
@ -246,7 +246,7 @@ o:value("3", translate("Every Wednesday"))
|
||||
o:value("4", translate("Every Thursday"))
|
||||
o:value("5", translate("Every Friday"))
|
||||
o:value("6", translate("Every Saturday"))
|
||||
o:value("7", translate("Every Sunday"))
|
||||
o:value("0", translate("Every Sunday"))
|
||||
o.default=1
|
||||
|
||||
o = s:taboption("geo_update", ListValue, "geo_update_day_time", translate("Update time (every day)"))
|
||||
|
||||
@ -134,9 +134,9 @@
|
||||
if ( x && x.status == 200 ) {
|
||||
btn.value = '<%:检查并更新%>';
|
||||
btn.disabled = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function op_update(btn)
|
||||
@ -147,9 +147,9 @@
|
||||
if ( x && x.status == 200 ) {
|
||||
btn.value = '<%:检查并更新%>';
|
||||
btn.disabled = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function ma_core_update(btn)
|
||||
|
||||
@ -13,12 +13,12 @@ if [ "$URL_TYPE" == "V2ray" ]; then
|
||||
elif [ "$URL_TYPE" == "surge" ]; then
|
||||
echo "开始下载Surge配置文件..." >$START_LOG
|
||||
subscribe_url=`echo $subscribe_url |sed 's/{/%7B/g;s/}/%7D/g;s/:/%3A/g;s/\"/%22/g;s/,/%2C/g;s/?/%3F/g;s/=/%3D/g;s/&/%26/g;s/\//%2F/g'`
|
||||
wget-ssl --no-check-certificate --timeout=10 --debug --tries=2 https://tgbot.lbyczf.com/surge2clash?url="$subscribe_url" -O /tmp/config.yaml
|
||||
wget-ssl --no-check-certificate --quiet --timeout=10 --tries=2 https://tgbot.lbyczf.com/surge2clash?url="$subscribe_url" -O /tmp/config.yaml
|
||||
else
|
||||
echo "开始下载Clash配置文件..." >$START_LOG
|
||||
wget-ssl --no-check-certificate --quiet --timeout=10 --tries=2 "$subscribe_url" -O /tmp/config.yaml
|
||||
fi
|
||||
if [ "$?" -eq "0" ] && [ "$(ls -l /tmp/config.yaml |awk '{print int($5/1024)}')" -ne 0 ]; then
|
||||
if [ "$?" -eq "0" ] && [ "$(ls -l /tmp/config.yaml |awk '{print int($5/1024)}')" -ne 0 ] && [ "$(awk '/Proxy Group:/,/Rule:/{print}' /tmp/config.yaml 2>/dev/null |egrep '^ {0,}-' |grep name: |sed 's/,.*//' |awk -F 'name: ' '{print $2}' |sed 's/\"//g' |wc -l)" -gt 0 ]; then
|
||||
echo "配置文件下载成功,检查是否有更新..." >$START_LOG
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
cmp -s "$BACKPACK_FILE" /tmp/config.yaml
|
||||
@ -27,8 +27,8 @@ if [ "$?" -eq "0" ] && [ "$(ls -l /tmp/config.yaml |awk '{print int($5/1024)}')"
|
||||
mv /tmp/config.yaml "$CONFIG_FILE" 2>/dev/null\
|
||||
&& cp "$CONFIG_FILE" "$BACKPACK_FILE"\
|
||||
&& echo "配置文件替换成功,开始启动 OpenClash ..." >$START_LOG\
|
||||
&& echo "${LOGTIME} Config Update Successful" >>$LOG_FILE\
|
||||
&& /etc/init.d/openclash restart 2>/dev/null
|
||||
echo "${LOGTIME} Config Update Successful" >>$LOG_FILE
|
||||
else
|
||||
echo "配置文件没有任何更新,停止继续操作..." >$START_LOG
|
||||
rm -rf /tmp/config.yaml
|
||||
@ -41,13 +41,13 @@ if [ "$?" -eq "0" ] && [ "$(ls -l /tmp/config.yaml |awk '{print int($5/1024)}')"
|
||||
mv /tmp/config.yaml "$CONFIG_FILE" 2>/dev/null\
|
||||
&& cp "$CONFIG_FILE" "$BACKPACK_FILE"\
|
||||
&& echo "配置文件创建成功,开始启动 OpenClash ..." >$START_LOG\
|
||||
&& echo "${LOGTIME} Config Update Successful" >>$LOG_FILE\
|
||||
&& /etc/init.d/openclash restart 2>/dev/null
|
||||
echo "${LOGTIME} Config Update Successful" >>$LOG_FILE
|
||||
fi
|
||||
else
|
||||
echo "配置文件下载失败,请检查网络或稍后再试!" >$START_LOG
|
||||
echo "${LOGTIME} Config Update Error" >>$LOG_FILE
|
||||
#rm -rf /tmp/config.yaml 2>/dev/null
|
||||
rm -rf /tmp/config.yaml 2>/dev/null
|
||||
sleep 10
|
||||
echo "" >$START_LOG
|
||||
fi
|
||||
|
||||
@ -88,12 +88,12 @@ elif [ "$2" = 0 ]; then
|
||||
[ -f /etc/openclash/config.bak ] && {
|
||||
grep '##source:' "$4" 1>/dev/null
|
||||
if [ "$?" -eq "0" ]; then
|
||||
cp /etc/openclash/config.bak /etc/openclash/configrules.bak
|
||||
sed -i -n '/^Rule:/,$p' /etc/openclash/configrules.bak
|
||||
sed -i '/^Rule:/,$d' "$4"
|
||||
cat /etc/openclash/configrules.bak >> "$4"
|
||||
rm -rf /etc/openclash/configrules.bak
|
||||
fi
|
||||
cp /etc/openclash/config.bak /etc/openclash/configrules.bak
|
||||
sed -i -n '/^Rule:/,$p' /etc/openclash/configrules.bak
|
||||
sed -i '/^Rule:/,$d' "$4"
|
||||
cat /etc/openclash/configrules.bak >> "$4"
|
||||
rm -rf /etc/openclash/configrules.bak
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user