OpenClash: bump to v0.34.6

This commit is contained in:
CN_SZTL 2019-09-30 13:29:25 +08:00
parent b4507b0342
commit 042f2c7ae2
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
25 changed files with 401 additions and 296 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-openclash
PKG_VERSION:=0.34.4
PKG_VERSION:=0.34.6
PKG_RELEASE:=beta
PKG_MAINTAINER:=vernesong <https://github.com/vernesong/OpenClash>
@ -41,10 +41,10 @@ endef
define Package/$(PKG_NAME)/preinst
#!/bin/sh
if [ -f "/etc/config/openclash" ]; then
cp "/etc/config/openclash" "/tmp/openclash.bak" 2>/dev/null
cp "/etc/config/openclash_custom_rules.list" "/tmp/openclash_custom_rules.list.bak" 2>/dev/null
cp "/etc/config/openclash_custom_hosts.list" "/tmp/openclash_custom_hosts.list.bak" 2>/dev/null
cp "/etc/config/openclash_custom_fake_black.conf" "/tmp/openclash_custom_fake_black.conf.bak" 2>/dev/null
cp "/etc/config/openclash" "/tmp/openclash.bak" >/dev/null 2>&1
cp "/etc/config/openclash_custom_rules.list" "/tmp/openclash_custom_rules.list.bak" >/dev/null 2>&1
cp "/etc/config/openclash_custom_hosts.list" "/tmp/openclash_custom_hosts.list.bak" >/dev/null 2>&1
cp "/etc/config/openclash_custom_fake_black.conf" "/tmp/openclash_custom_fake_black.conf.bak" >/dev/null 2>&1
fi
endef
@ -61,31 +61,32 @@ uci set firewall.openclash.path=/var/etc/openclash.include >/dev/null 2>&1
uci set firewall.openclash.reload=1 >/dev/null 2>&1
uci commit firewall >/dev/null 2>&1
if [ -f "/tmp/openclash.bak" ]; then
mv "/tmp/openclash.bak" "/etc/config/openclash" 2>/dev/null
mv "/tmp/openclash_custom_rules.list.bak" "/etc/config/openclash_custom_rules.list" 2>/dev/null
mv "/tmp/openclash_custom_hosts.list.bak" "/etc/config/openclash_custom_hosts.list" 2>/dev/null
mv "/tmp/openclash_custom_fake_black.conf.bak" "/etc/config/openclash_custom_fake_black.conf" 2>/dev/null
mv "/tmp/openclash.bak" "/etc/config/openclash" >/dev/null 2>&1
mv "/tmp/openclash_custom_rules.list.bak" "/etc/config/openclash_custom_rules.list" >/dev/null 2>&1
mv "/tmp/openclash_custom_hosts.list.bak" "/etc/config/openclash_custom_hosts.list" >/dev/null 2>&1
mv "/tmp/openclash_custom_fake_black.conf.bak" "/etc/config/openclash_custom_fake_black.conf" >/dev/null 2>&1
fi
if [ -f "/tmp/config.yaml" ]; then
mv "/tmp/config.yaml" "/etc/openclash/config.yaml" 2>/dev/null
mv "/tmp/config.yaml" "/etc/openclash/config.yaml" >/dev/null 2>&1
elif [ -f "/tmp/config.yml" ]; then
mv "/tmp/config.yml" "/etc/openclash/config.yaml" 2>/dev/null
mv "/tmp/config.yml" "/etc/openclash/config.yaml" >/dev/null 2>&1
fi
uci set openclash.config.enable=0 2>/dev/null && uci commit openclash 2>/dev/null
chmod 0755 /etc/init.d/openclash 2>/dev/null
chmod -R 0755 /usr/share/openclash/ 2>/dev/null
uci set openclash.config.enable=0 >/dev/null 2>&1
uci commit openclash >/dev/null 2>&1
chmod 0755 /etc/init.d/openclash >/dev/null 2>&1
chmod -R 0755 /usr/share/openclash/ >/dev/null 2>&1
rm -rf /tmp/luci*
endef
define Package/$(PKG_NAME)/prerm
#!/bin/sh
if [ ! -f "/tmp/openclash_update.sh" ]; then
rm -rf /etc/openclash/clash 2>/dev/null
rm -rf /etc/openclash/clash >/dev/null 2>&1
fi
cp "/etc/config/openclash" "/tmp/openclash.bak" 2>/dev/null
cp "/etc/config/openclash_custom_rules.list" "/tmp/openclash_custom_rules.list.bak" 2>/dev/null
cp "/etc/config/openclash_custom_hosts.list" "/tmp/openclash_custom_hosts.list.bak" 2>/dev/null
cp "/etc/config/openclash_custom_fake_black.conf" "/tmp/openclash_custom_fake_black.conf.bak" 2>/dev/null
cp "/etc/config/openclash" "/tmp/openclash.bak" >/dev/null 2>&1
cp "/etc/config/openclash_custom_rules.list" "/tmp/openclash_custom_rules.list.bak" >/dev/null 2>&1
cp "/etc/config/openclash_custom_hosts.list" "/tmp/openclash_custom_hosts.list.bak" >/dev/null 2>&1
cp "/etc/config/openclash_custom_fake_black.conf" "/tmp/openclash_custom_fake_black.conf.bak" >/dev/null 2>&1
endef
define Package/$(PKG_NAME)/postrm
@ -94,21 +95,21 @@ if [ -f "/etc/openclash/config.yaml" ]; then
mv "/etc/openclash/config.yaml" "/tmp/config.yaml"
fi
if [ -f "/etc/openclash/clash" ]; then
rm -rf /etc/openclash/config.* 2>/dev/null
rm -rf /etc/openclash/config.* >/dev/null 2>&1
else
rm -rf /etc/openclash 2>/dev/null
rm -rf /etc/openclash >/dev/null 2>&1
fi
rm -rf /tmp/openclash.log 2>/dev/null
rm -rf /tmp/openclash_start.log 2>/dev/null
rm -rf /tmp/Proxy_Group 2>/dev/null
rm -rf /tmp/openclash_last_version 2>/dev/null
rm -rf /tmp/clash_last_version 2>/dev/null
rm -rf /etc/openclash/dnsmasq_fake_block.conf 2>/dev/null
rm -rf /tmp/openclash.log >/dev/null 2>&1
rm -rf /tmp/openclash_start.log >/dev/null 2>&1
rm -rf /tmp/Proxy_Group >/dev/null 2>&1
rm -rf /tmp/openclash_last_version >/dev/null 2>&1
rm -rf /tmp/clash_last_version >/dev/null 2>&1
rm -rf /etc/openclash/dnsmasq_fake_block.conf >/dev/null 2>&1
uci delete firewall.openclash >/dev/null 2>&1
uci commit firewall >/dev/null 2>&1
uci delete ucitrack.@openclash[-1] >/dev/null 2>&1
uci commit ucitrack >/dev/null 2>&1
rm -rf /tmp/luci*
rm -rf /tmp/luci*
endef
define Package/$(PKG_NAME)/install

View File

@ -21,13 +21,13 @@ HOSTS_FILE="/etc/config/openclash_custom_hosts.list"
add_cron()
{
[ -z "$(grep "openclash.sh" "$CRON_FILE")" ] && {
[ -z "$(grep "openclash.sh" "$CRON_FILE" 2>/dev/null)" ] && {
[ "$(uci get openclash.config.auto_update 2>/dev/null)" -eq 1 ] && echo "0 $(uci get openclash.config.auto_update_time 2>/dev/null) * * $(uci get openclash.config.config_update_week_time 2>/dev/null) /usr/share/openclash/openclash.sh" >> $CRON_FILE
}
[ -z "$(grep "openclash_rule.sh" "$CRON_FILE")" ] && {
[ -z "$(grep "openclash_rule.sh" "$CRON_FILE" 2>/dev/null)" ] && {
[ "$(uci get openclash.config.other_rule_auto_update 2>/dev/null)" -eq 1 ] && echo "0 $(uci get openclash.config.other_rule_update_day_time 2>/dev/null) * * $(uci get openclash.config.other_rule_update_week_time 2>/dev/null) /usr/share/openclash/openclash_rule.sh" >> $CRON_FILE
}
[ -z "$(grep "openclash_ipdb.sh" "$CRON_FILE")" ] && {
[ -z "$(grep "openclash_ipdb.sh" "$CRON_FILE" 2>/dev/null)" ] && {
[ "$(uci get openclash.config.geo_auto_update 2>/dev/null)" -eq 1 ] && echo "0 $(uci get openclash.config.geo_update_day_time 2>/dev/null) * * $(uci get openclash.config.geo_update_week_time 2>/dev/null) /usr/share/openclash/openclash_ipdb.sh" >> $CRON_FILE
}
crontab $CRON_FILE
@ -43,17 +43,19 @@ del_cron()
}
change_dns() {
uci del dhcp.@dnsmasq[-1].server >/dev/null 2>&1
uci add_list dhcp.@dnsmasq[0].server=127.0.0.1#"$dns_port"
uci delete dhcp.@dnsmasq[0].resolvfile
uci set dhcp.@dnsmasq[0].noresolv=1
uci set dhcp.@dnsmasq[0].cachesize=0
uci commit dhcp
}
revert_dns() {
dns_port=$(uci get openclash.config.dns_port 2>/dev/null)
uci del_list dhcp.@dnsmasq[0].server=127.0.0.1#"$dns_port" >/dev/null 2>&1
uci del dhcp.@dnsmasq[-1].server >/dev/null 2>&1
uci set dhcp.@dnsmasq[0].resolvfile=/tmp/resolv.conf.auto
uci set dhcp.@dnsmasq[0].noresolv=0
uci delete dhcp.@dnsmasq[0].cachesize
uci commit dhcp
rm -rf /tmp/dnsmasq.d/dnsmasq_openclash.conf >/dev/null 2>&1
}
@ -79,6 +81,9 @@ yml_check()
if [ ! -f "$4" ]; then
cp "$3" "$4"
fi
#替换tab
sed -i 's/\t/ /g' "$3" 2>/dev/null
#自定义DNS还原
if [ "$(grep -c '##Custom DNS##' "$3")" -gt 0 ] && [ "$2" = 0 ] && [ -f "$4" ]; then
@ -235,14 +240,20 @@ yml_dns_custom()
sed -i "/^ \{0,\}nameserver:/c\ nameserver:" "$2" 2>/dev/null
sed -i "/^ \{0,\}fallback:/c\ fallback:" "$2" 2>/dev/null
fi
#fallback-filter
if [ ! -z "$(grep '^ \{0,\}fallback:' $2)" ]; then
if [ -z "$(grep '^ \{0,\}fallback-filter:' $2)" ]; then
sed -i '/OpenClash-General-Settings/i\ fallback-filter:' "$2" 2>/dev/null
sed -i '/OpenClash-General-Settings/i\ geoip: true' "$2" 2>/dev/null
sed -i '/OpenClash-General-Settings/i\ ipcidr:' "$2" 2>/dev/null
sed -i '/OpenClash-General-Settings/i\ - 240.0.0.0/4' "$2" 2>/dev/null
awk '/^ {0,}fallback:/,/OpenClash-General-Settings/{print}' "$2" |sed '1d' |sed '$d' >/tmp/fallback.cache 2>/dev/null
sed -i '/fallback:/,$d' "$2" 2>/dev/null
echo " fallback:" >>"$2"
sed -i '/ fallback:/a\ - 240.0.0.0/4' "$2" 2>/dev/null
sed -i '/ fallback:/a\ ipcidr:' "$2" 2>/dev/null
sed -i '/ fallback:/a\ geoip: true' "$2" 2>/dev/null
sed -i '/ fallback:/a\ fallback-filter:' "$2" 2>/dev/null
sed -i '/ fallback:/r/tmp/fallback.cache' "$2" 2>/dev/null
rm -rf /tmp/fallback.cache 2>/dev/null
echo "#===================== OpenClash-General-Settings =====================#" >>"$2"
else
if [ -z "$(grep '^ fallback-filter:' $2)" ]; then
sed -i "/fallback-filter:/c\ fallback-filter:" "$2" 2>/dev/null
@ -261,15 +272,13 @@ yml_dns_custom()
sed -i '/^ \{0,\}ipcidr:/,/OpenClash-General-Settings/ {s/^ \{0,\}- / - /}' "$2" 2>/dev/null #修改参数空格
fi
else #删除fallback-filter
if [ ! -z "$(grep '^ \{0,\}ipcidr:' $2)" ]; then
sed -i '/^ \{0,\}ipcidr:/,/OpenClash-General-Settings/ {/^ \{0,\}-/d}' "$2" 2>/dev/null
if [ ! -z "$(grep '^ \{0,\}fallback-filter:' $2)" ]; then
sed -i '/fallback-filter:/,$d' "$2" 2>/dev/null
echo "#===================== OpenClash-General-Settings =====================#" >>"$2"
fi
if [ ! -z "$(grep "^ \{0,1\}- " $2)" ]; then
sed -i "s/^ \{0,\}- / - /" "$2" 2>/dev/null #添加参数空格
fi
sed -i '/fallback-filter:/d' "$2" 2>/dev/null
sed -i '/geoip:/d' "$2" 2>/dev/null
sed -i '/ipcidr:/d' "$2" 2>/dev/null
fi
}
@ -320,7 +329,6 @@ if [ ! -f "$CONFIG_FILE" ] && [ -f "$BACKUP_FILE" ]; then
cp $BACKUP_FILE $CONFIG_FILE
fi
echo "OpenClash 开始启动..." >$START_LOG
enable=$(uci get openclash.config.enable 2>/dev/null)
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
@ -330,6 +338,7 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
nohup /usr/share/openclash/openclash_core.sh &
exit 0
}
echo "OpenClash 开始启动..." >$START_LOG
echo "第一步: 获取配置..." >$START_LOG
en_mode=$(uci get openclash.config.en_mode 2>/dev/null)
enable_custom_dns=$(uci get openclash.config.enable_custom_dns 2>/dev/null)
@ -361,10 +370,10 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
yml_auth_custom "$CONFIG_FILE"
yml_cut "$CHANGE_FILE" "$RULE_FILE" "$DNS_FILE" "$CONFIG_FILE" "$PROXY_FILE"
yml_dns_custom "$enable_custom_dns" "$DNS_FILE"
sh /usr/share/openclash/yml_change.sh "$LOGTIME" "$en_mode" "$enable_custom_dns" "$da_password" "$cn_port" "$proxy_port" "$CHANGE_FILE" "$ipv6_enable" "$http_port" "$socks_port" "$lan_ip" "$HOSTS_FILE" &
sh /usr/share/openclash/yml_change.sh "$LOGTIME" "$en_mode" "$enable_custom_dns" "$da_password" "$cn_port" "$proxy_port" "$CHANGE_FILE" "$ipv6_enable" "$http_port" "$socks_port" "$lan_ip" &
sh /usr/share/openclash/yml_rules_change.sh "$LOGTIME" "$rule_source" "$enable_custom_clash_rules" "$RULE_FILE" &
wait
cat $CHANGE_FILE $DNS_FILE $PROXY_FILE $RULE_FILE > $CONFIG_FILE 2>/dev/null
cat "$CHANGE_FILE" "$DNS_FILE" "$PROXY_FILE" "$RULE_FILE" >$CONFIG_FILE 2>/dev/null
rm -rf /tmp/yaml_* 2>/dev/null
echo "第四步: DNS设置检查..." >$START_LOG
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
@ -393,33 +402,30 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
uci set firewall.openclash.reload=1 >/dev/null 2>&1
uci commit firewall >/dev/null 2>&1
fi
mkdir -p /var/etc
mkdir -p /var/etc
cat > "/var/etc/openclash.include" <<-EOF
iptables -t nat -N openclash
iptables -t nat -A openclash -d 0.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 10.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 127.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 169.254.0.0/16 -j RETURN
iptables -t nat -A openclash -d 172.16.0.0/12 -j RETURN
iptables -t nat -A openclash -d 192.168.0.0/16 -j RETURN
iptables -t nat -A openclash -d 224.0.0.0/4 -j RETURN
iptables -t nat -A openclash -d 240.0.0.0/4 -j RETURN
iptables -t nat -A openclash -p tcp --dport 22 -j ACCEPT
iptables -t nat -A openclash -p tcp -j REDIRECT --to-ports "$proxy_port"
iptables -t nat -A PREROUTING -p tcp -j openclash
iptables -t nat -A OUTPUT -p tcp -d 198.18.0.1/16 -j REDIRECT --to-ports "$proxy_port"
/etc/init.d/openclash restart
EOF
iptables -t nat -N openclash
iptables -t nat -A openclash -d 0.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 10.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 127.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 169.254.0.0/16 -j RETURN
iptables -t nat -A openclash -d 172.16.0.0/12 -j RETURN
iptables -t nat -A openclash -d 192.168.0.0/16 -j RETURN
iptables -t nat -A openclash -d 224.0.0.0/4 -j RETURN
iptables -t nat -A openclash -d 240.0.0.0/4 -j RETURN
iptables -t nat -A openclash -p tcp -j REDIRECT --to-ports "$proxy_port"
iptables -t nat -A PREROUTING -p tcp -j openclash
iptables -t nat -A OUTPUT -p tcp -d 198.18.0.0/16 -j REDIRECT --to-ports "$proxy_port"
if [ "$ipv6_enable" -eq 1 ]; then
cat >> "/var/etc/openclash.include" <<-EOF
ip6tables -t nat -N openclash
ip6tables -t nat -A openclash -p tcp -j REDIRECT --to-ports "$proxy_port"
ip6tables -t nat -A PREROUTING -p tcp -j openclash
EOF
ip6tables -t nat -N openclash
ip6tables -t nat -A openclash -p tcp -j REDIRECT --to-ports "$proxy_port"
ip6tables -t nat -A PREROUTING -p tcp -j openclash
fi
/etc/init.d/firewall restart >/dev/null 2>&1
/etc/init.d/miniupnpd restart >/dev/null 2>&1
echo "第八步: 重启 Dnsmasq 程序..." >$START_LOG
if [ "$(iptables -t nat -nL PREROUTING --line-number |grep dpt:53 |wc -l)" -gt 2 ]; then
@ -485,27 +491,50 @@ else
echo "${LOGTIME} Config Not Found" >> $LOG_FILE
sleep 5
echo "" >$START_LOG
else
echo "错误: 请从 OpenClash 客户端界面启动程序!" >$START_LOG
echo "${LOGTIME} OpenClash Must Be Start From The Luci Page" >> $LOG_FILE
sleep 5
echo "" >$START_LOG
fi
fi
}
stop()
{
#禁止多个实例
status=$(ps|grep -c /etc/init.d/openclash)
[ "$status" -gt "3" ] && exit 0
echo "OpenClash 开始关闭..." >$START_LOG
echo "第一步: 删除 OpenClash 防火墙规则..." >$START_LOG
rm -rf /var/etc/openclash.include 2>/dev/null
/etc/init.d/firewall restart >/dev/null 2>&1
/etc/init.d/miniupnpd restart >/dev/null 2>&1
#ipv4
iptables -t nat -F openclash >/dev/null 2>&1
nat_clashs=$(iptables -nvL PREROUTING -t nat |sed 1,2d |sed -n '/openclash/=' |sort -r)
for nat_clash in $nat_clashs; do
iptables -t nat -D PREROUTING "$nat_clash" >/dev/null 2>&1
done
iptables -t nat -X openclash >/dev/null 2>&1
out_lines=$(iptables -nvL OUTPUT -t nat |sed 1,2d |sed -n '/198.18.0.0\/16/=' 2>/dev/null |sort -r)
for out_line in $out_lines; do
iptables -t nat -D OUTPUT "$out_line" >/dev/null 2>&1
done
#ipv6
ip6tables -t nat -F openclash >/dev/null 2>&1
nat6_clashs=$(ip6tables -nvL PREROUTING -t nat 2>/dev/null | sed 1,2d | sed -n '/openclash/=' |sort -r)
for nat6_clash in $nat6_clashs; do
ip6tables -t nat -D PREROUTING "$nat6_clash" >/dev/null 2>&1
done
ip6tables -t nat -X openclash >/dev/null 2>&1
echo "第二步: 关闭 OpenClash 守护程序..." >$START_LOG
kill -9 "$(ps |grep openclash_watchdog.sh |grep -v grep |awk '{print $1}')" >/dev/null 2>&1
watchdog_pids=$(ps |grep openclash_watchdog.sh |grep -v grep |awk '{print $1}' 2>/dev/null)
for watchdog_pid in $watchdog_pids; do
kill -9 "$watchdog_pid" >/dev/null 2>&1
done
echo "第三步: 关闭 Clash 主程序..." >$START_LOG
kill -9 "$(pidof clash|sed 's/$//g')" 2>/dev/null

File diff suppressed because one or more lines are too long

View File

@ -37,7 +37,7 @@ local function is_web()
end
local function is_watchdog()
return luci.sys.exec("ps |grep openclash_watchdog.sh |grep -v grep 2>/dev/null")
return luci.sys.exec("ps |grep openclash_watchdog.sh |grep -v grep 2>/dev/null |sed -n 1p")
end
local function config_check()
@ -141,11 +141,11 @@ local function startlog()
end
local function coremodel()
local coremodel = luci.sys.exec("cat /proc/cpuinfo |grep 'cpu model' 2>/dev/null |awk -F ': ' '{print $2}' 2>/dev/null")
if (coremodel ~= "") then
return coremodel
else
local coremodel = luci.sys.exec("cat /proc/cpuinfo |grep 'cpu model' 2>/dev/null |awk -F ': ' '{print $2}' 2>/dev/null")
if not coremodel or coremodel == "" then
return luci.sys.exec("opkg status libc 2>/dev/null |grep 'Architecture' |awk -F ': ' '{print $2}' 2>/dev/null")
else
return coremodel
end
end
@ -252,10 +252,10 @@ function action_update()
coremodel = coremodel(),
coremodel2 = coremodel2(),
corecv = corecv(),
corelv = corelv(),
opcv = opcv(),
corever = corever(),
upchecktime = upchecktime(),
corelv = corelv(),
oplv = oplv();
})
end

View File

@ -5,6 +5,7 @@ local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"
local fs = require "luci.openclash"
local uci = require("luci.model.uci").cursor()
local CHIF = "0"
ful = SimpleForm("upload", translate("Server Configuration"), nil)
@ -113,14 +114,16 @@ o = a:option(Button, "Commit")
o.inputtitle = translate("Commit Configurations")
o.inputstyle = "apply"
o.write = function()
SYS.call("uci commit openclash")
uci:commit("openclash")
end
o = a:option(Button, "Apply")
o.inputtitle = translate("Apply Configurations")
o.inputstyle = "apply"
o.write = function()
SYS.call("uci set openclash.config.enable=1 && uci commit openclash && /etc/init.d/openclash restart >/dev/null 2>&1 &")
uci:set("openclash", "config", "enable", 1)
uci:commit("openclash")
SYS.call("/etc/init.d/openclash restart >/dev/null 2>&1 &")
HTTP.redirect(DISP.build_url("admin", "services", "openclash"))
end

View File

@ -1,5 +1,3 @@
-- Copyright (C) 2017 yushi studio <ywb94@qq.com> github.com/ywb94
-- Licensed to the public under the GNU General Public License v3.
local m, s, o
local openclash = "openclash"
@ -69,7 +67,7 @@ o = a:option(Button,"Commit")
o.inputtitle = translate("Commit Configurations")
o.inputstyle = "apply"
o.write = function()
uci:commit(openclash, sid)
m.uci:commit(openclash)
sys.call("/usr/share/openclash/yml_groups_name_ch.sh start")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "openclash", "servers"))
end
@ -78,7 +76,7 @@ o = a:option(Button,"Back")
o.inputtitle = translate("Back Configurations")
o.inputstyle = "reset"
o.write = function()
uci:revert(openclash, sid)
m.uci:revert(openclash)
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "openclash", "servers"))
end

View File

@ -1,5 +1,3 @@
-- Copyright (C) 2017 yushi studio <ywb94@qq.com> github.com/ywb94
-- Licensed to the public under the GNU General Public License v3.
local m, s, o
local openclash = "openclash"
@ -10,7 +8,7 @@ local sid = arg[1]
local uuid = luci.sys.exec("cat /proc/sys/kernel/random/uuid")
local encrypt_methods_ss = {
-- stream
"rc4-md5",
"aes-128-cfb",
@ -80,7 +78,7 @@ o.rmempty = true
o:depends("type", "ss")
o = s:option(ListValue, "securitys", translate("Encrypt Method"))
for _, v in ipairs(securitys) do o:value(v, v:upper()) end
for _, v in ipairs(securitys) do o:value(v) end
o.rmempty = true
o:depends("type", "vmess")
@ -152,8 +150,16 @@ o:depends("type", "socks5")
o:depends("type", "http")
o.rmempty = true
-- [[ MUX ]]--
o = s:option(ListValue, "mux", translate("mux"))
o.rmempty = true
o.default = "false"
o:value("true")
o:value("false")
o:depends("obfs", "websocket")
-- [[ skip-cert-verify ]]--
o = s:option(ListValue, "skip_cert_verify", translate("Skip Cert Verify"))
o = s:option(ListValue, "skip_cert_verify", translate("Skip-Cert-Verify"))
o.rmempty = true
o.default = "false"
o:value("true")
@ -177,7 +183,7 @@ o:depends("type", "http")
o = s:option(DynamicList, "groups", translate("Proxy Group"))
o.description = translate("No Need Set when Config Create, The added Proxy Groups Must Exist")
o.rmempty = true
uci:foreach("openclash", "groups",
m.uci:foreach("openclash", "groups",
function(s)
o:value(s.name)
end)
@ -191,16 +197,16 @@ o = a:option(Button,"Commit")
o.inputtitle = translate("Commit Configurations")
o.inputstyle = "apply"
o.write = function()
uci:commit(openclash, sid)
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "openclash", "servers"))
m.uci:commit(openclash)
luci.http.redirect(m.redirect)
end
o = a:option(Button,"Back")
o.inputtitle = translate("Back Configurations")
o.inputstyle = "reset"
o.write = function()
uci:revert(openclash, sid)
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "openclash", "servers"))
m.uci:revert(openclash)
luci.http.redirect(m.redirect)
end
return m

View File

@ -32,26 +32,17 @@ o = a:option(Button, "Commit")
o.inputtitle = translate("Commit Configurations")
o.inputstyle = "apply"
o.write = function()
uci:commit("openclash")
m.uci:set("openclash", "config", "enable", 0)
m.uci:commit("openclash")
end
o = a:option(Button, "Apply")
o.inputtitle = translate("Apply Configurations")
o.inputstyle = "apply"
o.write = function()
uci:set("openclash", "config", "enable", 1)
uci:commit("openclash")
local refresh_config = uci:get("openclash", "config", "create_config")
if (refresh_config == "1") then
luci.sys.call("/usr/share/openclash/yml_proxys_set.sh >/dev/null 2>&1")
uci:delete_all("openclash", "servers", function(s) return true end)
uci:delete_all("openclash", "groups", function(s) return true end)
luci.sys.call("/usr/share/openclash/yml_groups_get.sh >/dev/null 2>&1")
luci.sys.call("/etc/init.d/openclash restart >/dev/null 2>&1 &")
else
luci.sys.call("/usr/share/openclash/yml_proxys_set.sh >/dev/null 2>&1")
luci.sys.call("/etc/init.d/openclash restart >/dev/null 2>&1 &")
end
m.uci:set("openclash", "config", "enable", 0)
m.uci:commit("openclash")
luci.sys.call("/usr/share/openclash/yml_proxys_set.sh >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "openclash"))
end
@ -64,18 +55,19 @@ o = b:option(Button,"Load_Config")
o.inputtitle = translate("Load Config")
o.inputstyle = "apply"
o.write = function()
uci:delete_all("openclash", "servers", function(s) return true end)
uci:delete_all("openclash", "groups", function(s) return true end)
luci.sys.call("sh /usr/share/openclash/yml_groups_get.sh 2>/dev/null")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "openclash", "servers"))
m.uci:set("openclash", "config", "enable", 0)
m.uci:commit("openclash")
luci.sys.call("sh /usr/share/openclash/yml_groups_get.sh 2>/dev/null &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "openclash"))
end
o = b:option(Button,"Delete_Severs")
o.inputtitle = translate("Delete Severs")
o.inputstyle = "reset"
o.write = function()
uci:delete_all("openclash", "servers", function(s) return true end)
luci.sys.call("uci commit openclash")
m.uci:set("openclash", "config", "enable", 0)
m.uci:delete_all("openclash", "servers", function(s) return true end)
m.uci:commit("openclash")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "openclash", "servers"))
end
@ -83,8 +75,9 @@ o = b:option(Button,"Delete_Groups")
o.inputtitle = translate("Delete Groups")
o.inputstyle = "reset"
o.write = function()
uci:delete_all("openclash", "groups", function(s) return true end)
luci.sys.call("uci commit openclash")
m.uci:set("openclash", "config", "enable", 0)
m.uci:delete_all("openclash", "groups", function(s) return true end)
m.uci:commit("openclash")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "openclash", "servers"))
end

View File

@ -4,7 +4,7 @@ local SYS = require "luci.sys"
local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"
local uci = require("luci.model.uci").cursor()
local uci = require "luci.model.uci".cursor()
m = Map("openclash", translate("Global Settings(Will Modify The Config File Or Subscribe According To The Settings On This Page)"))
m.pageaction = false
@ -103,8 +103,8 @@ o:depends("dns_advanced_setting", "1")
o.inputtitle = translate("Check And Update")
o.inputstyle = "reload"
o.write = function()
uci:set("openclash", "config", "enable", 1)
uci:commit("openclash")
m.uci:set("openclash", "config", "enable", 1)
m.uci:commit("openclash")
SYS.call("sh /usr/share/openclash/openclash_fake_block.sh && /etc/init.d/openclash restart >/dev/null 2>&1 &")
HTTP.redirect(DISP.build_url("admin", "services", "openclash"))
end
@ -141,10 +141,8 @@ o:value("lhie1", translate("lhie1 Rules"))
o:value("ConnersHua", translate("ConnersHua Rules"))
o:value("ConnersHua_return", translate("ConnersHua Return Rules"))
SYS.call("awk '/Proxy Group:/,/Rule:/{print}' /etc/openclash/config.yaml 2>/dev/null |egrep '^ {0,}-' |grep name: |awk -F 'name: ' '{print $2}' |sed 's/,.*//' |sed 's/\"//g' >/tmp/Proxy_Group 2>&1")
SYS.call("echo 'DIRECT' >>/tmp/Proxy_Group")
SYS.call("echo 'REJECT' >>/tmp/Proxy_Group")
file = io.open("/tmp/Proxy_Group", "r");
SYS.call("/usr/share/openclash/yml_groups_name_get.sh 2>/dev/null")
file = io.open("/tmp/Proxy_Group", "r");
o = s:taboption("rules", ListValue, "GlobalTV", translate("GlobalTV"))
o:depends("rule_source", "lhie1")
@ -241,8 +239,8 @@ o.title = translate("Update Subcription")
o.inputtitle = translate("Check And Update")
o.inputstyle = "reload"
o.write = function()
uci:set("openclash", "config", "enable", 1)
uci:commit("openclash")
m.uci:set("openclash", "config", "enable", 1)
m.uci:commit("openclash")
SYS.call("rm -rf /etc/openclash/config.bak 2>/dev/null")
SYS.call("sh /usr/share/openclash/openclash.sh >/dev/null 2>&1 &")
HTTP.redirect(DISP.build_url("admin", "services", "openclash"))
@ -277,8 +275,8 @@ o.inputtitle = translate("Check And Update")
o.description = translate("Other Rules Update(Only in Use)")
o.inputstyle = "reload"
o.write = function()
uci:set("openclash", "config", "enable", 1)
uci:commit("openclash")
m.uci:set("openclash", "config", "enable", 1)
m.uci:commit("openclash")
SYS.call("sh /usr/share/openclash/openclash_rule.sh >/dev/null 2>&1 &")
HTTP.redirect(DISP.build_url("admin", "services", "openclash"))
end
@ -311,8 +309,8 @@ o.title = translate("Update GEOIP Database")
o.inputtitle = translate("Check And Update")
o.inputstyle = "reload"
o.write = function()
uci:set("openclash", "config", "enable", 1)
uci:commit("openclash")
m.uci:set("openclash", "config", "enable", 1)
m.uci:commit("openclash")
SYS.call("sh /usr/share/openclash/openclash_ipdb.sh >/dev/null 2>&1 &")
HTTP.redirect(DISP.build_url("admin", "services", "openclash"))
end
@ -456,15 +454,15 @@ o = a:option(Button, "Commit")
o.inputtitle = translate("Commit Configurations")
o.inputstyle = "apply"
o.write = function()
uci:commit("openclash")
m.uci:commit("openclash")
end
o = a:option(Button, "Apply")
o.inputtitle = translate("Apply Configurations")
o.inputstyle = "apply"
o.write = function()
uci:set("openclash", "config", "enable", 1)
uci:commit("openclash")
m.uci:set("openclash", "config", "enable", 1)
m.uci:commit("openclash")
SYS.call("/etc/init.d/openclash restart >/dev/null 2>&1 &")
HTTP.redirect(DISP.build_url("admin", "services", "openclash"))
end

View File

@ -1,39 +1,11 @@
--[[
LuCI - Filesystem tools
Description:
A module offering often needed filesystem manipulation functions
FileId:
$Id$
License:
Copyright 2008 Steven Barth <steven@midlink.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]--
local fs = require "nixio.fs"
local type = type
--- LuCI filesystem library.
module "luci.openclash"
--- Checks wheather the given path exists and points to a directory.
-- @param dirname String containing the path of the directory to test
-- @return Boolean indicating wheather given path points to directory
--- LuCI filesystem library.
function isdirectory(dirname)
return fs.stat(dirname, "type") == "dir"
end

View File

@ -14,10 +14,10 @@
var binupdate = document.getElementById('_binupdate');
var openupdate = document.getElementById('_openupdate');
var github = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABiCAMAAACRZYZ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3FpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTQyIDc5LjE2MDkyNCwgMjAxNy8wNy8xMy0wMTowNjozOSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1Y2NjZGI4My1kMGJiLWExNDUtYmYyNy03ZmRkMTJmY2EwYTQiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RENEOUYxRjE5RjJDMTFFOUEwNjVGMTc0MUI4MUNFQzgiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RENEOUYxRjA5RjJDMTFFOUEwNjVGMTc0MUI4MUNFQzgiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIChXaW5kb3dzKSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjVjY2NkYjgzLWQwYmItYTE0NS1iZjI3LTdmZGQxMmZjYTBhNCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo1Y2NjZGI4My1kMGJiLWExNDUtYmYyNy03ZmRkMTJmY2EwYTQiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz4s6CIvAAACdlBMVEX+/v78/PzExMT9/f35+fn19fX4+Pj6+vrX19fy8vL7+/sICAjr6+vq6urd3d3x8fFDQ0Obm5vw8PDc3Nz29vYoKCi5ubnn5+cPDw/h4eHY2NiOjo6Dg4NLS0vs7OxFRUXv7+/t7e3u7u4vLy8JCQkQEBANDQ0DAwMGBgYEBARpaWnBwcGvr6/39/fQ0NDNzc3IyMh8fHy7u7uEhISjo6MrKytgYGCGhoZ6enqZmZnS0tI0NDShoaGxsbFlZWUgICAWFhYlJSVMTEwsLCwKCgo6OjqUlJQcHBwaGhr09PQpKSldXV2fn5+4uLiQkJACAgLo6Ojp6elGRkba2tqWlpYBAQHZ2dmnp6fFxcWSkpKurq5KSkqysrI9PT0FBQWYmJhnZ2e9vb1zc3NERETz8/N4eHh+fn5mZmbHx8eIiIiKioq1tbVhYWGoqKhXV1cTExMeHh6srKxqamqLi4ukpKTb29sqKirCwsKmpqbOzs5aWlo8PDyMjIzV1dWdnZ2zs7OFhYXl5eUXFxd0dHQHBweenp7W1tZ9fX0iIiLg4OAtLS2NjY3AwMCgoKCJiYmwsLCPj4/U1NRWVlYRERFPT0+Hh4dsbGxvb2/Pz8/Dw8MdHR0uLi5NTU2+vr4fHx/R0dE5OTm/v7+ioqJQUFDGxsbJyckUFBTKyso2NjZRUVEZGRmtra3i4uImJiZSUlLe3t6CgoJUVFRtbW3Ly8sYGBjMzMwwMDDT09NJSUkkJCRISEi2trZkZGRBQUEMDAy6uro/Pz9/f39ra2sODg4nJycSEhJ7e3s7OzsVFRVycnIyMjJcXFxbW1t2dnYbGxv///8AAAD///9H5/bkAAAA0nRSTlP//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wD8iKrvAAAFUElEQVR42qya90PbOBTHZRKTQQgBMgoByipll00H0E1bRhfr2l6v+7r3uLbXvXvd19t777333svqf3SpTRzbT4ptyd/fkJ7ex9iK9PSe0B2L8lxeVx//qKO4PdJ3qHhXbXzlloOi1bHIilFJxs2X92CgT1adimY7Awnc2JyFqare0RbjhbhfWVuDTTT54RaRAyKunI0taVZbOSNk44k/sGVV7y9jgKDBSdiW7tsp2IWMhrBtffaxLYjnCmbS1LB1yOm5mFFnCq1C7sUcyrUEQfdjLvX4zSHuVZhTh3LMIA2/YG5VlaWHlE/ATuhyOognCzujHDpE+NIhBv6ugQaR5mPHdMZFgWzCDupNMmQQO6pcEiSgt/nzrM2XF9r0r74hCCFot87iSUmS3Ld2WSXU3nInBjTpG/0AslVvIEiyShdbQUxbpFgL+uYdRshSff8bUlKebjPEmEc1Xq7vmW6ALNB3D0gpuZuVtpn/nHq7zhsMBt8vzOgu6uhTWvtFjWm9YU9GOsjXhqfLl7QqmPve4OkGJOmVGVvXE5mua1pmcNOrhbiMcY9PYlKm8VW6NZBc0MkG8Rv9XExBwAPgTDaIABz5VMhh7NB/AiEfJCGuSvgADn0T5avchUyBXV42yFLoqXscMgd2tbJB2qCnhxSISPoZCywMRPKULUNIYVYNG2QhwdViGfIgocfP9rpcBFcLpATER+gYkhgVIDiLJSCvw+ZnJGath962JyDXsVO/d8oLW5uAwE9yVuLQMeBuD0JhGM8FeCBhwiRG+aBtgsQleJadgurgcYkPcgI4vIHGIJgPEgQOr6Mf4Svkg5QCh/3oqFPLPH25D6HVoC3MBxEmGx0+jS45tSuqEPCb+A/NchriP2d0uBvB89siTsgSo8OfURU8ijn94avQJKencA5cQgib2Tt8kGyYDUMR0HaVD3IcOJyJJoK2Ij7INeBwBtoH2tr5IMXAYTEiHKU8PAzXCPD3GDoJIYU8EEIQuQYdgY0dPBBCIiuKYk6Fj/TIy4tchKivix1yDyHNKqI7RwlsxAyphs7mJ0KilwiQ86yMBwjOWhOQUVIozrgS+0m+mhIQoYrQsYTthf1KchW+G9VvJuF/YKCgOSRPG+Sjw6fEZMYM2/NYWE10FJUhrnnknEmJPUYJJX+ZqZwZt9KSPzYWMc80WpJq/GCqyYh89XeF1qLF4onL0zJCyyHlJ5MF6p6yLDFA1KV6egOmMwAFhul5qtlqRuLzZNP38ihxg9bsdq83jzoJBN+Fm2mLOXUqRFJLGQPKczcbTOctf6QREi5MDFWaJNwSp1I1S5Q6pLxWKo//0Gid5SKsuOYFqVe1STXNTi9T0IiVsNJlxuiTtJA8TY/8zIYD2EXyJxkwgRToc5CtqZ5v5fH9OusyMkRMz/jGkOjUxsTKHv+XtihKm8dPpS2luox54QLNR1amf48mPKNN4X3pIEdgGn0byHYNfaH8+fuBBhokNw3jcUKuXmpXuyvU4Lnx6vFYuvxElM54SyJVHdwpgzyr62IGHeIj109Sn+USR3BiSKGDclMqcfAT73+yl14425naGEUuyLF0JcB4yu5aHjvkt/TFzBXaROj6w1u83iHvs80v2oN0mpVlD5BGFdmCPGpeYI7aiShJkJNWSuWF52ClzQbkCWv1+DwQpK2xDAmVWL6+0GUYOmwVEkc2LmIE9SWwFdYgFQft3fZAe7UxwhVLkHrB9uWYnHiN+RTWnEc6y5iu+WwcTkbJtTTI9nGDyv0FzBeWysdekH2M0iBKor+iq5zr6hVq7Iw8t42+eDW9G5n6vGDi5H8BBgCTacDsFxo/3wAAAABJRU5ErkJggg=="
Dreamacro.innerHTML = '<img src="https://avatars3.githubusercontent.com/u/8615343?s=460&v=4" alt="Dreamacro" width="30" onerror="return imgerrorfun()" onclick="return Dreamacro_rediret()" />';
vernesong.innerHTML = '<img src="https://avatars2.githubusercontent.com/u/42875168?s=460&v=4" alt="vernesong" width="30" onerror="return imgerrorfun()" onclick="return vernesong_rediret()" />';
frainzy1477.innerHTML = '<img src="https://avatars2.githubusercontent.com/u/49537471?s=460&v=4" alt="frainzy1477" width="30" onerror="return imgerrorfun()" onclick="return frainzy1477_rediret()" />';
SukkaW.innerHTML = '<img src="https://avatars0.githubusercontent.com/u/40715044?s=460&v=4" alt="SukkaW" width="30" onerror="return imgerrorfun()" onclick="return SukkaW_rediret()" />';
Dreamacro.innerHTML = '<img src="https://avatars3.githubusercontent.com/u/8615343?s=460&v=4" alt="Dreamacro" width="30" onerror="return imgerrorfun(this,this.src)" onclick="return Dreamacro_rediret()" />';
vernesong.innerHTML = '<img src="https://avatars2.githubusercontent.com/u/42875168?s=460&v=4" alt="vernesong" width="30" onerror="return imgerrorfun(this,this.src)" onclick="return vernesong_rediret()" />';
frainzy1477.innerHTML = '<img src="https://avatars2.githubusercontent.com/u/49537471?s=460&v=4" alt="frainzy1477" width="30" onerror="return imgerrorfun(this,this.src)" onclick="return frainzy1477_rediret()" />';
SukkaW.innerHTML = '<img src="https://avatars0.githubusercontent.com/u/40715044?s=460&v=4" alt="SukkaW" width="30" onerror="return imgerrorfun(this,this.src)" onclick="return SukkaW_rediret()" />';
binupdate.innerHTML = '<img src="'+github+'" alt="binupdate" width="30" height="30" onclick="return binupdate_rediret()" />';
openupdate.innerHTML = '<img src="'+github+'" alt="openupdate" width="30" height="30" onclick="return openupdate_rediret()" />';
@ -52,10 +52,10 @@
window.open(url6);
}
function imgerrorfun(){
var img=event.srcElement;
img.src=github;
img.onerror=null;
function imgerrorfun(imgobj,imgSrc){
setTimeout(function(){
imgobj.src=imgSrc;
},1000*5);
}
//]]></script>

View File

@ -11,13 +11,13 @@
</td></tr>
<tr><td colspan="4" width="100%">
<p align="center">
<img id="star" src="https://img.shields.io/badge/Star--lightgrey?logo=github&style=social" alt="star" onclick="return homepage()" />
<img id="star" src="https://img.shields.io/badge/Star--lightgrey?logo=github&style=social" alt="star" onerror="return imgerrorfuns(this,this.src)" onclick="return homepage()" />
&nbsp;&nbsp;&nbsp;
<img id="wiki" src="https://img.shields.io/badge/Tutorials--lightgrey?logo=Wikipedia&style=social" alt="Wiki" onclick="return wikipage()" />
<img id="wiki" src="https://img.shields.io/badge/Tutorials--lightgrey?logo=Wikipedia&style=social" alt="Wiki" onerror="return imgerrorfuns(this,this.src)" onclick="return wikipage()" />
&nbsp;&nbsp;&nbsp;
<img id="telegram" src="https://img.shields.io/badge/Telegram--lightgrey?logo=Telegram&style=social" alt="Telegram" onclick="return telegrampage()" />
<img id="telegram" src="https://img.shields.io/badge/Telegram--lightgrey?logo=Telegram&style=social" alt="Telegram" onerror="return imgerrorfuns(this,this.src)" onclick="return telegrampage()" />
&nbsp;&nbsp;&nbsp;
<img id="sponsor" src="https://img.shields.io/badge/Sponsor--lightgrey?logo=ko-fi&style=social" alt="Sponsor" onclick="return sponsorpage()" />
<img id="sponsor" src="https://img.shields.io/badge/Sponsor--lightgrey?logo=ko-fi&style=social" alt="Sponsor" onerror="return imgerrorfuns(this,this.src)" onclick="return sponsorpage()" />
</p>
</td></tr>
<tr><td width="100%" colspan="4">
@ -125,13 +125,13 @@
}
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "currentversion")%>', status.currentversion, function(x, status) {
if ( x && x.status == 200 ) {
clashversion.innerHTML = '<img id="currenntver" src="'+status.currentversion+'" alt="currentversion" width="181px" onload="return clashversion_check()" onclick="return go_update()">';
}
});
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "currentversion")%>', status.currentversion, function(x, status) {
if ( x && x.status == 200 ) {
clashversion.innerHTML = '<img id="currenntver" src="'+status.currentversion+'" alt="currentversion" width="181px" onload="return clashversion_check()" onclick="return go_update()">';
}
});
function clashversion_check()
function clashversion_check()
{
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "lastversion")%>', status.lastversion, function(x, status) {
if ( x && x.status == 200 ) {
@ -143,18 +143,23 @@ function clashversion_check()
});
}
function clashversion_error()
function clashversion_error()
{
clashversion.innerHTML = '<img id="currenntver" src="'+status.currentversion+'" alt="currentversion" width="181px" onclick="return go_update()">';
clashversion.innerHTML = '<img id="currenntver" src="'+status.currentversion+'" alt="currentversion" width="181px" onclick="return go_update()">';
}
function go_update()
function imgerrorfuns(imgobj,imgSrc){
setTimeout(function(){
imgobj.src=imgSrc;
},1000*5);
}
function go_update()
{
url4='https://github.com/vernesong/OpenClash/releases';
window.open(url4);
url4='https://github.com/vernesong/OpenClash/releases';
window.open(url4);
}
var startlog = document.getElementById('_clashstart');

View File

@ -29,6 +29,8 @@
var ma_op_up = document.getElementById('ma_op_up');
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "update")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
cpu_model.innerHTML = status.coremodel ? "<b><font color=green>"+status.coremodel+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
cpu_model2.innerHTML = status.coremodel2 ? "<b><font color=green>"+status.coremodel2+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
if ( status.corever != "0\n" && status.corever != "" ) {
core_version.innerHTML = "<b><font color=green>"+status.corever+"</font></b>";
}
@ -41,8 +43,6 @@
else {
checktime.innerHTML = "<b><font color=red><%:查询更新失败%></font></b>";
}
cpu_model.innerHTML = status.coremodel ? "<b><font color=green>"+status.coremodel+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
cpu_model2.innerHTML = status.coremodel2 ? "<b><font color=green>"+status.coremodel2+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
if ( status.corecv == "0" ) {
core_cv.innerHTML = "<b><font color=red><%:File Not Exist%></font></b>";
}
@ -74,8 +74,10 @@
}
});
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "openclash", "update")%>', null, function(x, status) {
XHR.poll(6, '<%=luci.dispatcher.build_url("admin", "services", "openclash", "update")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
cpu_model.innerHTML = status.coremodel ? "<b><font color=green>"+status.coremodel+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
cpu_model2.innerHTML = status.coremodel2 ? "<b><font color=green>"+status.coremodel2+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
if ( status.corever != "0\n" && status.corever != "" ) {
core_version.innerHTML = "<b><font color=green>"+status.corever+"</font></b>";
}
@ -88,8 +90,6 @@
else {
checktime.innerHTML = "<b><font color=red><%:查询更新失败%></font></b>";
}
cpu_model.innerHTML = status.coremodel ? "<b><font color=green>"+status.coremodel+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
cpu_model2.innerHTML = status.coremodel2 ? "<b><font color=green>"+status.coremodel2+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
if ( status.corecv == "0" ) {
core_cv.innerHTML = "<b><font color=red><%:File Not Exist%></font></b>";
}

View File

@ -1,9 +1,9 @@
#!/bin/sh
CKTIME=$(date "+%Y-%m-%d-%H")
LAST_OPVER="/tmp/clash_last_version"
version_url="https://github.com/vernesong/OpenClash/raw/master/core_version"
version_url="https://raw.githubusercontent.com/vernesong/OpenClash/master/core_version"
if [ "$CKTIME" != "$(grep "CheckTime" $LAST_OPVER 2>/dev/null |awk -F ':' '{print $2}')" ]; then
wget-ssl --no-check-certificate --quiet --timeout=5 --tries=2 "$version_url" -O $LAST_OPVER
wget-ssl --no-check-certificate --quiet --timeout=10 --tries=2 "$version_url" -O $LAST_OPVER
if [ "$?" -eq "0" ] && [ "$(ls -l $LAST_OPVER 2>/dev/null |awk '{print int($5)}')" -gt 0 ]; then
echo "CheckTime:$CKTIME" >>$LAST_OPVER
else

View File

@ -1,4 +1,7 @@
#!/bin/sh
#!/bin/bash
status=$(ps|grep -c /usr/share/openclash/openclash.sh)
[ "$status" -gt "3" ] && exit 0
START_LOG="/tmp/openclash_start.log"
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
CONFIG_FILE="/etc/openclash/config.yaml"
@ -6,6 +9,10 @@ LOG_FILE="/tmp/openclash.log"
BACKPACK_FILE="/etc/openclash/config.bak"
URL_TYPE=$(uci get openclash.config.config_update_url_type 2>/dev/null)
subscribe_url=$(uci get openclash.config.subscribe_url 2>/dev/null)
en_mode=$(uci get openclash.config.en_mode 2>/dev/null)
config_dawnload()
{
if [ "$URL_TYPE" == "V2ray" ]; then
echo "开始下载v2ray配置文件..." >$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'`
@ -18,7 +25,10 @@ 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 ] && [ "$(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
}
config_su_check()
{
echo "配置文件下载成功,检查是否有更新..." >$START_LOG
if [ -f "$CONFIG_FILE" ]; then
cmp -s "$BACKPACK_FILE" /tmp/config.yaml
@ -44,10 +54,46 @@ if [ "$?" -eq "0" ] && [ "$(ls -l /tmp/config.yaml |awk '{print int($5/1024)}')"
&& echo "${LOGTIME} Config Update Successful" >>$LOG_FILE\
&& /etc/init.d/openclash restart 2>/dev/null
fi
else
}
config_error()
{
echo "配置文件下载失败,请检查网络或稍后再试!" >$START_LOG
echo "${LOGTIME} Config Update Error" >>$LOG_FILE
rm -rf /tmp/config.yaml 2>/dev/null
sleep 10
sleep 5
echo "" >$START_LOG
}
config_dawnload
if [ "$?" -eq "0" ] && [ "$(ls -l /tmp/config.yaml |awk '{print int($5/1024)}')" -ne 0 ]; then
config_su_check
else
if pidof clash >/dev/null; then
echo "配置文件下载失败,尝试不使用代理下载配置文件..." >$START_LOG
if [ "$en_mode" = "fake-ip"]; then
resolve_sub_ips=$(nslookup "$subscribe_url" 114.114.114.114 |grep Address |awk -F ': ' '{print $2}')
else
resolve_sub_ips=$(nslookup "$subscribe_url" 127.0.0.1 |grep Address |awk -F ': ' '{print $2}')
fi
for resolve_sub_ip in $resolve_sub_ips; do
iptables -t nat -I openclash -d "$resolve_sub_ip" -j RETURN >/dev/null 2>&1
done
config_dawnload
if [ "$?" -eq "0" ] && [ "$(ls -l /tmp/config.yaml |awk '{print int($5/1024)}')" -ne 0 ]; then
config_su_check
else
config_error
fi
for resolve_sub_ip in $resolve_sub_ips; do
iptables -t nat -D openclash -d "$resolve_sub_ip" -j RETURN >/dev/null 2>&1
done
else
config_error
fi
fi

View File

@ -1,7 +1,7 @@
#!/bin/sh
CKTIME=$(date "+%Y-%m-%d-%H")
LAST_OPVER="/tmp/openclash_last_version"
version_url="https://github.com/vernesong/OpenClash/raw/master/version"
version_url="https://raw.githubusercontent.com/vernesong/OpenClash/master/version"
if [ "$CKTIME" != "$(grep "CheckTime" $LAST_OPVER 2>/dev/null |awk -F ':' '{print $2}')" ]; then
wget-ssl --no-check-certificate --quiet --timeout=10 --tries=2 "$version_url" -O $LAST_OPVER
if [ "$?" -eq "0" ] && [ "$(ls -l $LAST_OPVER 2>/dev/null |awk '{print int($5)}')" -gt 0 ]; then

View File

@ -1,21 +1,24 @@
#!/bin/sh
status=$(ps|grep -c openclash_watchdog.sh)
[ "$status" -gt "3" ] && echo "another clash_watchdog.sh is running,exit "
[ "$status" -gt "3" ] && exit 0
enable_redirect_dns=$(uci get openclash.config.enable_redirect_dns 2>/dev/null)
dns_port=$(uci get openclash.config.dns_port 2>/dev/null)
while :;
do
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
enable=$(uci get openclash.config.enable)
if [ "$enable" -eq 1 ]; then
if ! pidof clash >/dev/null; then
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
echo "${LOGTIME} Watchdog: OpenClash Problem, Restart " >>/tmp/openclash.log
/etc/init.d/openclash restart
nohup /etc/init.d/openclash restart &
exit 0
fi
else
exit 0
fi
## Log File Size Manage:
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
LOGSIZE=`ls -l /tmp/openclash.log |awk '{print int($5/1024)}'`
if [ "$LOGSIZE" -gt 90 ]; then
echo "[$LOGTIME] Watchdog: Size Limit, Clean Up All Log Records." > /tmp/openclash.log
@ -25,9 +28,24 @@ fi
zone_line=`iptables -t nat -nL PREROUTING --line-number |grep "zone" 2>/dev/null |awk '{print $1}' 2>/dev/null |awk 'END {print}'`
op_line=`iptables -t nat -nL PREROUTING --line-number |grep "openclash" 2>/dev/null |awk '{print $1}' 2>/dev/null |head -1`
if [ "$zone_line" -gt "$op_line" ]; then
/etc/init.d/firewall restart >/dev/null 2>&1
/etc/init.d/miniupnpd restart >/dev/null 2>&1
echo "[$LOGTIME] Watchdog: Restart Firewall For Enable Redirect." > /tmp/openclash.log
nohup /etc/init.d/openclash restart &
echo "[$LOGTIME] Watchdog: Restart For Enable Firewall Redirect." >> /tmp/openclash.log
exit 0
fi
## DNS转发劫持
if [ "$enable_redirect_dns" != "0" ]; then
if [ -z "$(uci get dhcp.@dnsmasq[0].server 2>/dev/null |grep "$dns_port")" ] || [ ! -z "$(uci get dhcp.@dnsmasq[0].server 2>/dev/null |awk -F ' ' '{print $2}')" ]; then
echo "[$LOGTIME] Watchdog: Force Reset DNS Hijack." >> /tmp/openclash.log
uci del dhcp.@dnsmasq[-1].server >/dev/null 2>&1
uci add_list dhcp.@dnsmasq[0].server=127.0.0.1#"$dns_port"
uci delete dhcp.@dnsmasq[0].resolvfile
uci set dhcp.@dnsmasq[0].noresolv=1
uci set dhcp.@dnsmasq[0].cachesize=0
uci commit dhcp
/etc/init.d/dnsmasq restart >/dev/null 2>&1
fi
fi
sleep 60
done 2>/dev/null

View File

@ -1,5 +1,18 @@
#!/bin/sh
#删除旧hosts配置
hostlen=$(sed -n '/hosts:/=' "$7" 2>/dev/null)
dnslen=$(sed -n '/dns:/=' "$7" 2>/dev/null)
dnsheadlen=$(expr "$dnslen" - 1)
if [ ! -z "$hostlen" ] && [ "$hostlen" -gt "$dnslen" ]; then
sed -i '/^ \{0,\}hosts:/,$d' "$7" 2>/dev/null
elif [ ! -z "$hostlen" ]; then
sed -i '/##Custom HOSTS##/,/##Custom HOSTS END##/d' "$7" 2>/dev/null
if [ -z "$(awk '/^ {0,}hosts:/,/^dns:/{print}' "$7" 2>/dev/null |awk -F ':' '{print $2}' 2>/dev/null)" ]; then
sed -i "/${hostlen}p/,/${dnsheadlen}p/d" "$7" 2>/dev/null
sed -i '/^ \{0,\}hosts:/d' "$7" 2>/dev/null
fi
fi
if [ -z "$(grep '^ enhanced-mode: $2' "$7")" ]; then
if [ ! -z "$(grep "^ \{0,\}enhanced-mode:" "$7")" ]; then
sed -i "/^ \{0,\}enhanced-mode:/c\ enhanced-mode: ${2}" "$7"
@ -125,33 +138,17 @@
fi
#添加自定义Hosts设置
if [ "$2" = "redir-host" ]; then
if [ -z "$(grep '^ \{0,\}hosts:' $7)" ]; then
sed -i '/^dns:/i\hosts:' "$7" 2>/dev/null
else
if [ ! -z "$(grep '^ \{1,\}hosts:' $7)" ]; then
sed -i '/^ \{1,\}hosts:/d' "$7" 2>/dev/null
sed -i '/^dns:/i\hosts:' "$7" 2>/dev/null
fi
fi
sed -i "s/^ \{0,\}/ /" "$12" 2>/dev/null #修改参数空格
sed -i "1i\##Custom HOSTS##" "$12" 2>/dev/null
echo "##Custom HOSTS END##" >>"$12" 2>/dev/null
sed -i '/##Custom HOSTS##/,/##Custom HOSTS END##/d' "$7" 2>/dev/null
sed -i '/^hosts:/r/etc/config/openclash_custom_hosts.list' "$7" 2>/dev/null
sed -i '/##Custom HOSTS##/d' "$12" 2>/dev/null
sed -i '/##Custom HOSTS END##/d' "$12" 2>/dev/null
else
sed -i '/##Custom HOSTS##/,/##Custom HOSTS END##/d' "$7" 2>/dev/null
sed -i '/^ *$/d' "$7" 2>/dev/null #删除空行
hostlen=$(sed -n '/hosts:/=' "$7" 2>/dev/null)
lasthlen=$(sed -n '$=' "$7" 2>/dev/null) #兼容旧版本
dnslen=$(sed -n '/dns:/=' "$7" 2>/dev/null)
if [ "$hostlen" = "$lasthlen" ] && [ ! -z "$hostlen" ]; then
sed -i '/^ \{0,\}hosts:/d' "$7" 2>/dev/null
fi
if [ "$hostlen" = "$(expr $dnslen - 1)" ] && [ ! -z "$hostlen" ]; then
sed -i '/^ \{0,\}hosts:/d' "$7" 2>/dev/null
fi
fi
if [ "$2" = "redir-host" ]; then
if [ -z "$(grep '^ \{0,\}hosts:' $7)" ]; then
sed -i '/^dns:/i\hosts:' "$7" 2>/dev/null
else
if [ ! -z "$(grep '^ \{1,\}hosts:' $7)" ]; then
sed -i "/^ \{0,\}hosts:/c\hosts:" "$7"
fi
fi
sed -i '/^hosts:/a\##Custom HOSTS END##' "$7" 2>/dev/null
sed -i '/^hosts:/a\##Custom HOSTS##' "$7" 2>/dev/null
sed -i '/##Custom HOSTS##/r/etc/config/openclash_custom_hosts.list' "$7" 2>/dev/null
sed -i "/^hosts:/,/^dns:/ {s/^ \{0,\}'/ '/}" "$7" 2>/dev/null #修改参数空格
fi

View File

@ -1,15 +1,24 @@
#!/bin/sh
#!/bin/bash
status=$(ps|grep -c /usr/share/openclash/yml_groups_get.sh)
[ "$status" -gt "3" ] && exit 0
START_LOG="/tmp/openclash_start.log"
CFG_FILE="/etc/config/openclash"
if [ ! -f "/etc/openclash/config.yml" ] && [ ! -f "/etc/openclash/config.yaml" ]; then
exit 0
elif [ ! -f "/etc/openclash/config.yaml" ] && [ "$(ls -l /etc/openclash/config.yml 2>/dev/null |awk '{print int($5/1024)}')" -gt 0 ]; then
mv "/etc/openclash/config.yml" "/etc/openclash/config.yaml"
fi
awk '/Proxy Group:/,/Rule:/{print}' /etc/openclash/config.yaml 2>/dev/null >/tmp/yaml_group.yaml 2>&1
awk '/Proxy Group:/,/Rule:/{print}' /etc/openclash/config.yaml 2>/dev/null |egrep '^ {0,}-' |grep name: |awk -F 'name: ' '{print $2}' |sed 's/,.*//' |sed 's/\"//g' >/tmp/Proxy_Group 2>&1
echo "开始更新策略组配置..." >$START_LOG
while ( [ ! -z "$(grep "config groups" "$CFG_FILE")" ] || [ ! -z "$(grep "config servers" "$CFG_FILE")" ] )
do
uci delete openclash.@groups[0] 2>/dev/null
uci delete openclash.@servers[0] 2>/dev/null
uci commit openclash
done
awk '/Proxy Group:/,/Rule:/{print}' /etc/openclash/config.yaml 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\t/ /g' 2>/dev/null >/tmp/yaml_group.yaml 2>&1
awk '/Proxy Group:/,/Rule:/{print}' /etc/openclash/config.yaml 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\t/ /g' 2>/dev/null |grep name: 2>/dev/null |awk -F 'name:' '{print $2}' 2>/dev/null |sed 's/,.*//' 2>/dev/null |sed 's/^ \{0,\}//' 2>/dev/null |sed 's/ \{0,\}$//' 2>/dev/null |sed 's/ \{0,\}\}\{0,\}$//g' 2>/dev/null >/tmp/Proxy_Group 2>&1
echo "DIRECT" >>/tmp/Proxy_Group
echo "REJECT" >>/tmp/Proxy_Group
count=1
@ -19,6 +28,11 @@ group_file="/tmp/yaml_group.yaml"
line=$(sed -n '/name:/=' $group_file)
num=$(grep -c "name:" $group_file)
cfg_get()
{
echo "$(grep "$1" "$2" 2>/dev/null |awk -v tag=$1 'BEGIN{FS=tag} {print $2}' 2>/dev/null |sed 's/,.*//' 2>/dev/null |sed 's/^ \{0,\}//g' 2>/dev/null |sed 's/ \{0,\}$//g' 2>/dev/null |sed 's/ \{0,\}\}\{0,\}$//g' 2>/dev/null)"
}
for n in $line
do
single_group="/tmp/group_$file_count.yaml"
@ -38,15 +52,15 @@ do
startLine=$(expr "$endLine" + 1)
#type
group_type=$(grep "type:" $single_group |awk -F 'type:' '{print $2}' |sed 's/,.*//' |sed 's/\"//g' |sed 's/^ \{0,\}//g')
group_type="$(cfg_get "type:" "$single_group")"
#name
group_name=$(grep "name:" $single_group |awk -F 'name:' '{print $2}' |sed 's/,.*//' |sed 's/\"//g' |sed 's/^ \{0,\}//g')
group_name="$(cfg_get "name:" "$single_group")"
#test_url
group_test_url=$(grep "url:" $single_group |awk -F 'url:' '{print $2}' |sed 's/,.*//' |sed 's/\"//g' |sed 's/^ \{0,\}//g' |sed 's/ \{0,\}$//g' 2>/dev/null |sed 's/ \{0,\}\}$//g' 2>/dev/null)
group_test_url="$(cfg_get "url:" "$single_group")"
#test_interval
group_test_interval=$(grep "interval:" $single_group |awk -F 'interval:' '{print $2}' |sed 's/,.*//' |sed 's/\"//g' |sed 's/^ \{0,\}//g' |sed 's/ \{0,\}$//g' 2>/dev/null |sed 's/ \{0,\}\}$//g' 2>/dev/null)
group_test_interval="$(cfg_get "interval:" "$single_group")"
echo "正在读取【$group_type】-【$group_name】策略组配置..." >$START_LOG
name=openclash
uci_name_tmp=$(uci add $name groups)
@ -66,19 +80,19 @@ do
continue
fi
group_name1=$(echo "$line" |grep "^ \{0,\}-" 2>/dev/null |awk -F '^ \{0,\}- ' '{print $2}' 2>/dev/null |grep -v "name:" 2>/dev/null |sed 's/\"//g')
group_name2=$(echo "$line" |awk -F 'proxies: \\[' '{print $2}' 2>/dev/null |sed 's/].*//' 2>/dev/null |sed 's/^ \{0,\}//' 2>/dev/null |sed 's/ \{0,\}$//' 2>/dev/null |sed 's/ \{0,\}, \{0,\}/#,#/g' 2>/dev/null |sed 's/,\t/#,#/g' 2>/dev/null |sed 's/\"//g' 2>/dev/null)
group_name1=$(echo "$line" |grep -v "name:" 2>/dev/null |grep "^ \{0,\}-" 2>/dev/null |awk -F '^ \{0,\}-' '{print $2}' 2>/dev/null |sed 's/^ \{0,\}//' 2>/dev/null |sed 's/ \{0,\}$//' 2>/dev/null)
group_name2=$(echo "$line" |awk -F 'proxies: \\[' '{print $2}' 2>/dev/null |sed 's/].*//' 2>/dev/null |sed 's/^ \{0,\}//' 2>/dev/null |sed 's/ \{0,\}$//' 2>/dev/null |sed 's/ \{0,\}, \{0,\}/#,#/g' 2>/dev/null)
if [ -z "$group_name1" ] && [ -z "$group_name2" ]; then
continue
elif [ ! -z "$group_name1" ] && [ -z "$group_name2" ]; then
if [ ! -z "$(grep "$group_name1" $match_group_file)" ] && [ "$group_name1" != "$group_name" ]; then
if [ ! -z "$(grep -F "$group_name1" $match_group_file)" ] && [ "$group_name1" != "$group_name" ]; then
${uci_add}other_group="$group_name1"
fi
elif [ -z "$group_name1" ] && [ ! -z "$group_name2" ]; then
group_num=$(expr $(echo "$group_name2" |grep -c "#,#") + 1)
if [ "$group_num" -le 1 ]; then
if [ ! -z "$(grep "$group_name2" $match_group_file)" ] && [ "$group_name2" != "$group_name" ]; then
if [ ! -z "$(grep -F "$group_name2" $match_group_file)" ] && [ "$group_name2" != "$group_name" ]; then
${uci_add}other_group="$group_name2"
fi
else
@ -86,7 +100,7 @@ do
while [[ "$group_nums" -le "$group_num" ]]
do
other_group_name=$(echo "$group_name2" |awk -v t="${group_nums}" -F '#,#' '{print $t}' 2>/dev/null)
if [ ! -z "$(grep "$other_group_name" $match_group_file)" ] && [ "$other_group_name" != "$group_name" ]; then
if [ ! -z "$(grep -F "$other_group_name" $match_group_file 2>/dev/null)" ] && [ "$other_group_name" != "$group_name" ]; then
${uci_add}other_group="$other_group_name"
fi
group_nums=$(expr "$group_nums" + 1)
@ -101,4 +115,4 @@ do
done
uci commit openclash
/usr/share/openclash/yml_proxys_get.sh
/usr/share/openclash/yml_proxys_get.sh

View File

@ -0,0 +1,10 @@
#!/bin/sh
if [ -f "/etc/openclash/config.yaml" ]; then
awk '/Proxy Group:/,/Rule:/{print}' /etc/openclash/config.yaml 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed 's/\t/ /g' 2>/dev/null |grep name: |awk -F 'name:' '{print $2}' |sed 's/,.*//' |sed 's/^ \{0,\}//' 2>/dev/null |sed 's/ \{0,\}$//' 2>/dev/null |sed 's/ \{0,\}\}\{0,\}$//g' 2>/dev/null >/tmp/Proxy_Group 2>&1
echo 'DIRECT' >>/tmp/Proxy_Group
echo 'REJECT' >>/tmp/Proxy_Group
else
echo '读取错误,配置文件异常!' >/tmp/Proxy_Group
exit 0
fi

View File

@ -57,6 +57,8 @@ yml_groups_set()
return
fi
echo "正在写入【$type】-【$name】策略组到配置文件..." >$START_LOG
echo "- name: $name" >>$GROUP_FILE
echo " type: $type" >>$GROUP_FILE
echo " proxies:" >>$GROUP_FILE
@ -84,7 +86,7 @@ create_config=$(uci get openclash.config.create_config 2>/dev/null)
if [ "$create_config" = "0" ]; then
if [ -z "$(grep "^ \{0,\}Proxy:" /etc/openclash/config.yaml)" ] || [ -z "$(grep "^ \{0,\}Proxy Group:" /etc/openclash/config.yaml)" ]; then
echo "未找到配置文件开始使用ConnersHua规则创建..." >$START_LOG
echo "配置文件不完整开始使用ConnersHua规则创建..." >$START_LOG
uci set openclash.config.create_config=1
uci set openclash.config.rule_sources="ConnersHua"
uci set openclash.config.rule_source="ConnersHua"
@ -98,4 +100,4 @@ if [ "$create_config" = "0" ]; then
fi
fi
echo "配置文件策略组创建完成!" >$START_LOG
echo "配置文件策略组写入完成!" >$START_LOG

View File

@ -2,13 +2,17 @@
status=$(ps|grep -c /usr/share/openclash/yml_proxys_get.sh)
[ "$status" -gt "3" ] && exit 0
START_LOG="/tmp/openclash_start.log"
if [ ! -f "/etc/openclash/config.yml" ] && [ ! -f "/etc/openclash/config.yaml" ]; then
exit 0
elif [ ! -f "/etc/openclash/config.yaml" ] && [ "$(ls -l /etc/openclash/config.yml 2>/dev/null |awk '{print int($5/1024)}')" -gt 0 ]; then
mv "/etc/openclash/config.yml" "/etc/openclash/config.yaml"
fi
awk '/^ {0,}Proxy:/,/^ {0,}Proxy Group:/{print}' /etc/openclash/config.yaml 2>/dev/null >/tmp/yaml_proxy.yaml 2>&1
echo "开始更新服务器节点配置..." >$START_LOG
awk '/^ {0,}Proxy:/,/^ {0,}Proxy Group:/{print}' /etc/openclash/config.yaml 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\t/ /g' 2>/dev/null >/tmp/yaml_proxy.yaml 2>&1
server_file="/tmp/yaml_proxy.yaml"
single_server="/tmp/servers.yaml"
@ -19,13 +23,7 @@ num=$(grep -c "^ \{0,\}-" $server_file)
cfg_get()
{
echo "$(grep "$1" $single_server |awk -v tag=$1 'BEGIN{FS=tag} {print $2}' |sed 's/,.*//' |sed 's/\"//g' |sed 's/^ \{0,\}//g' |sed 's/ \{0,\}$//g' 2>/dev/null |sed 's/ \{0,\}\}$//g' 2>/dev/null)"
}
cfg_get_host()
{
echo "$(grep "$1" $single_server |awk -v tag=$1 'BEGIN{FS=tag} {print $2}' |sed 's/}.*//' |sed 's/,.*//' |sed 's/\"//g' |sed 's/^ \{0,\}//g' |sed 's/ \{0,\}$//g')"
echo "$(grep "$1" $single_server 2>/dev/null |awk -v tag=$1 'BEGIN{FS=tag} {print $2}' 2>/dev/null |sed 's/,.*//' 2>/dev/null |sed 's/^ \{0,\}//g' 2>/dev/null |sed 's/ \{0,\}$//g' 2>/dev/null |sed 's/ \{0,\}\}\{0,\}$//g' 2>/dev/null)"
}
for n in $line
@ -73,10 +71,12 @@ do
tls="$(cfg_get "tls:")"
#skip-cert-verify:
verify="$(cfg_get "skip-cert-verify:")"
#mux:
mux="$(cfg_get "mux:")"
#host:
host="$(cfg_get "host:")"
#Host:
Host="$(cfg_get_host "Host:")"
Host="$(cfg_get "Host:")"
#path:
path="$(cfg_get "path:")"
#ws-path:
@ -92,6 +92,8 @@ do
#username
username="$(cfg_get "username:")"
echo "正在读取【$server_type】-【$server_name】服务器节点配置..." >$START_LOG
name=openclash
uci_name_tmp=$(uci add $name servers)
@ -118,6 +120,7 @@ do
${uci_set}skip_cert_verify="$verify"
${uci_set}path="$path"
[ -z "$path" ] && ${uci_set}path="$ws_path"
${uci_set}mux="$mux"
${uci_set}custom="$headers"
[ -z "$headers" ] && ${uci_set}custom="$Host"
@ -134,19 +137,18 @@ do
${uci_set}password="$password"
fi
server_name_change=$(echo "$server_name" |sed 's/\\/#d#/g' 2>/dev/null |sed 's/ /#spas#/g' |sed 's/\t/#tab#/g' 2>/dev/null) #替换斜杠和空格
for ((i=1;i<=$group_num;i++)) #循环加入策略组
do
single_group="/tmp/group_$i.yaml"
sed -i -e 's/\\/#d#/g' -e 's/ /#spas#/g' -e 's/\t/#tab#/g' "$single_group" 2>/dev/null #替换斜杠和空格
if [ ! -z "$(grep "$server_name_change" "$single_group")" ]; then
group_name=$(grep "name:" $single_group |sed 's/#d#/\\/g' |sed 's/#spas#/ /g' |sed 's/#tab#/ /g' |awk -F 'name: ' '{print $2}' |sed 's/,.*//' 2>/dev/null |sed 's/\"//g' 2>/dev/null)
if [ ! -z "$(grep -F "$server_name" "$single_group")" ]; then
group_name=$(grep "name:" $single_group 2>/dev/null |awk -F 'name:' '{print $2}' 2>/dev/null |sed 's/,.*//' 2>/dev/null |sed 's/^ \{0,\}//g' 2>/dev/null |sed 's/ \{0,\}$//g' 2>/dev/null)
${uci_add}groups="$group_name"
fi
done
done
echo "配置文件读取完成!" >$START_LOG
sleep 3
echo "" >$START_LOG
uci commit openclash
rm -rf /tmp/servers.yaml 2>/dev/null
rm -rf /tmp/yaml_proxy.yaml 2>/dev/null

View File

@ -5,7 +5,6 @@ status=$(ps|grep -c /usr/share/openclash/yml_proxys_set.sh)
START_LOG="/tmp/openclash_start.log"
SERVER_FILE="/tmp/yaml_servers.yaml"
#写入服务器节点到配置文件
yml_servers_set()
{
@ -22,6 +21,7 @@ yml_servers_set()
config_get "obfs" "$section" "obfs" ""
config_get "obfs_vmess" "$section" "obfs_vmess" ""
config_get "host" "$section" "host" ""
config_get "mux" "$section" "mux" ""
config_get "custom" "$section" "custom" ""
config_get "tls" "$section" "tls" ""
config_get "skip_cert_verify" "$section" "skip_cert_verify" ""
@ -36,6 +36,10 @@ yml_servers_set()
return
fi
if [ -z "$name" ]; then
return
fi
if [ -z "$server" ]; then
return
fi
@ -48,6 +52,8 @@ yml_servers_set()
return
fi
echo "正在写入【$type】-【$name】节点到配置文件..." >$START_LOG
if [ "$obfs" != "none" ]; then
if [ "$obfs" = "websocket" ]; then
obfss="plugin: v2ray-plugin"
@ -131,6 +137,11 @@ EOF
if [ ! -z "$path" ]; then
cat >> "$SERVER_FILE" <<-EOF
$path
EOF
fi
if [ ! -z "$mux" ]; then
cat >> "$SERVER_FILE" <<-EOF
mux: $mux
EOF
fi
if [ ! -z "$custom" ]; then
@ -160,7 +171,7 @@ config_foreach yml_servers_set "servers"
echo "Proxy Group:" >>$SERVER_FILE
rule_sources=$(uci get openclash.config.rule_sources 2>/dev/null)
create_config=$(uci get openclash.config.create_config 2>/dev/null)
egrep '^ {0,}-' $SERVER_FILE |grep name: |awk -F 'name: ' '{print $2}' |sed 's/,.*//' >/tmp/Proxy_Server 2>&1
egrep '^ {0,}-' $SERVER_FILE |grep name: |awk -F 'name: ' '{print $2}' |sed 's/,.*//' 2>/dev/null >/tmp/Proxy_Server 2>&1
sed -i "s/^ \{0,\}/ - /" /tmp/Proxy_Server 2>/dev/null #添加参数
@ -310,18 +321,21 @@ uci set openclash.config.Others="Others"
fi
if [ "$create_config" != "0" ]; then
echo "Rule:" >>$SERVER_FILE
uci commit openclash
echo "服务器节点写入配置文件完成,开始更新配置文件..." >$START_LOG
cat "$SERVER_FILE" > "/etc/openclash/config.yaml" 2>/dev/null
/usr/share/openclash/yml_groups_get.sh >/dev/null 2>&1
else
echo "正在更新配置文件服务器节点信息..." >$START_LOG
/usr/share/openclash/yml_groups_set.sh
echo "正在更新配置文件..." >$START_LOG
/usr/share/openclash/yml_groups_set.sh >/dev/null 2>&1
sed -i '/^ \{0,\}Proxy:/i\#change server#' "/etc/openclash/config.yaml" 2>/dev/null
sed -i '/^ \{0,\}Proxy:/,/^ \{0,\}Rule:/d' "/etc/openclash/config.yaml" 2>/dev/null
sed -i '/#change server#/r/tmp/yaml_servers.yaml' "/etc/openclash/config.yaml" 2>/dev/null
sed -i '/Proxy Group:/r/tmp/yaml_groups.yaml' "/etc/openclash/config.yaml" 2>/dev/null
sed -i '/#change server#/d' "/etc/openclash/config.yaml" 2>/dev/null
fi
echo "配置文件更新完成!" >$START_LOG
echo "配置文件服务器节点写入完成!" >$START_LOG
rm -rf $SERVER_FILE 2>/dev/null
rm -rf /tmp/Proxy_Server 2>/dev/null
rm -rf /tmp/yaml_groups.yaml 2>/dev/null
uci set openclash.config.enable=1 2>/dev/null
/etc/init.d/openclash restart >/dev/null 2>&1

View File

@ -95,13 +95,13 @@ elif [ "$2" = 0 ]; then
}
fi
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
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
[ "$3" = 1 ] && {
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/config/openclash_custom_rules.list' "$4" 2>/dev/null
sed -i "s/^ \{0,\}- /- /" "$4" 2>/dev/null #修改参数空格
sed -i "s/^\t\{0,\}- /- /" "$4" 2>/dev/null #修改参数tab
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/config/openclash_custom_rules.list' "$4" 2>/dev/null
sed -i "s/^ \{0,\}-/-/" "$4" 2>/dev/null #修改参数空格
sed -i "s/^\t\{0,\}-/-/" "$4" 2>/dev/null #修改参数tab
}

View File

@ -163,7 +163,7 @@ msgstr "IPV6类型DNS解析"
msgid "Force Enable to Resolve ipv6 DNS Requests"
msgstr ""
"允许解析IPV6类型的DNS请求如果您没有公网IPV6地址但开启了IPV6的DHCP服务客户端连接可能会出现异常"
"固件须配置好IPV6的NAT如果您没有公网IPV6地址但开启了IPV6的DHCP服务客户端连接可能会出现异常"
msgid "Rules Setting"
msgstr "规则设置(访问控制)"
@ -383,7 +383,7 @@ msgid "Chose to Download"
msgstr "选择内核编译版本"
msgid "Select Based On Your CPU Model For Core Update, Wrong Version Will Not Work"
msgstr "请根据CPU架构选择以便下载、更新对应内核,错误的版本将不能正常运行"
msgstr "请根据处理器架构选择以便下载、更新对应内核,错误的版本将不能正常运行"
msgid "Update Core File"
msgstr "更新内核"
@ -474,9 +474,6 @@ msgstr "登录用户名"
msgid "Auth Password"
msgstr "登录密码"
msgid "Skip Cert Verify"
msgstr "忽略许可验证skip-cert-verify"
msgid "None"
msgstr "未配置"