luci-app-clash: sync source

This commit is contained in:
CN_SZTL 2019-08-02 23:44:54 +08:00
parent be73fa2bab
commit 1bdfedba56
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
11 changed files with 141 additions and 97 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-clash
PKG_VERSION:=0.30.0
PKG_VERSION:=0.31.0
PKG_RELEASE:=1
PKG_MAINTAINER:=frainzy1477
@ -11,7 +11,7 @@ include $(INCLUDE_DIR)/package.mk
define Package/luci-app-clash
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=3. Applications
SUBMENU:=2. Services
TITLE:=LuCI app for clash
DEPENDS:=+bash +coreutils-nohup +wget
PKGARCH:=all
@ -38,18 +38,14 @@ define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/clash
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/view/clash
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/clash
$(INSTALL_DIR) $(1)/www
$(INSTALL_DIR) $(1)/usr/share/clash
$(INSTALL_DIR) $(1)/usr/share/clash/web
$(INSTALL_DIR) $(1)/usr/share/clash/dashboard
@ -68,8 +64,8 @@ define Package/$(PKG_NAME)/install
$(INSTALL_BIN) ./root/usr/share/clash/clash_version $(1)/usr/share/clash/
$(INSTALL_BIN) ./root/usr/share/clash/check_version.sh $(1)/usr/share/clash/
$(INSTALL_BIN) ./root/usr/share/clash/web/* $(1)/usr/share/clash/web
$(INSTALL_BIN) ./root/usr/share/clash/web/* $(1)/usr/share/clash/web
$(INSTALL_BIN) ./root/usr/share/clash/dashboard/index.html $(1)/usr/share/clash/dashboard/
$(INSTALL_BIN) ./root/usr/share/clash/dashboard/main.d32d2df9dcc55f57282d.css $(1)/usr/share/clash/dashboard/
$(INSTALL_BIN) ./root/usr/share/clash/dashboard/img/33343e6117c37aaef8886179007ba6b5.png $(1)/usr/share/clash/dashboard/img/
@ -78,11 +74,8 @@ define Package/$(PKG_NAME)/install
$(INSTALL_BIN) ./root/usr/share/clash/dashboard/js/bundle.d32d2df9dcc55f57282d.min.js $(1)/usr/share/clash/dashboard/js/
$(INSTALL_DATA) ./luasrc/controller/*.lua $(1)/usr/lib/lua/luci/controller/
$(INSTALL_DATA) ./luasrc/model/cbi/clash/*.lua $(1)/usr/lib/lua/luci/model/cbi/clash/
$(INSTALL_DATA) ./luasrc/view/clash/* $(1)/usr/lib/lua/luci/view/clash/
$(INSTALL_DATA) ./po/zh-cn/clash.zh-cn.lmo $(1)/usr/lib/lua/luci/i18n/
endef

View File

@ -3,20 +3,17 @@ 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()
ful = Form("upload", nil)
ful.reset = false
ful.submit = false
m = Map("clash")
s = m:section(TypedSection, "clash")
s.anonymous = true
o = s:option( Flag, "enable")
o.title = translate("Enable")
o.default = 0
o.rmempty = false
o.description = translate("Enable Client")
o = s:option(Flag, "auto_update", translate("Auto Update"))
o.rmempty = false
o.description = translate("Auto Update Server subscription")
@ -46,8 +43,11 @@ o.rmempty = true
o = s:option(Button,"update")
o.title = translate("Update Subcription")
o.inputtitle = translate("Update")
o.description = translate("Update Config")
o.inputstyle = "reload"
o.write = function()
os.execute("sed -i '/enable/d' /etc/config/clash")
uci:commit("clash")
os.execute("mv /etc/clash/config.yaml /etc/clash/config.bak")
os.execute("rm -rf /tmp/clash.log")
SYS.call("bash /usr/share/clash/clash.sh >>/tmp/clash.log 2>&1 &")
@ -55,11 +55,28 @@ o.write = function()
end
local apply = luci.http.formvalue("cbi.apply")
if apply then
SYS.call("/etc/init.d/clash restart >/dev/null 2>&1 &")
o = s:option(Button,"enable")
o.title = translate("Start Client")
o.inputtitle = translate("Start Client")
o.description = translate("Enable/Start/Restart Client")
o.inputstyle = "apply"
o.write = function()
uci:set("clash", "config", "enable", 1)
uci:commit("clash")
SYS.call("/etc/init.d/clash restart >/dev/null 2>&1 &")
end
return m
o = s:option(Button,"disable")
o.title = translate("Stop Client")
o.inputtitle = translate("Stop Client")
o.description = translate("Disable/Stop Client")
o.inputstyle = "reset"
o.write = function()
uci:set("clash", "config", "enable", 0)
uci:commit("clash")
SYS.call("/etc/init.d/clash stop >/dev/null 2>&1 &")
end
return m, ful

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 http = luci.http

View File

@ -4,6 +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()
m = Map("clash")
s = m:section(TypedSection, "clash")

View File

@ -4,6 +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()
ful = Form("upload", nil)
ful.reset = false

View File

@ -3,7 +3,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()
m = Map("clash")
s = m:section(TypedSection, "clash")

View File

@ -1,3 +1,17 @@
msgid "Update Config"
msgstr "更新配置"
msgid "Enable/Start/Restart Client"
msgstr "启用/启动/重新启动客户端"
msgid "Disable/Stop Client"
msgstr "禁用/停止客户端"
msgid "Stop Client"
msgstr "停用客户端"
msgid "Start Client"
msgstr "启用客户端"
msgid "enabled"
msgstr "启用"
@ -231,4 +245,4 @@ msgid "Server Subscription Address"
msgstr "服务器订阅地址"
msgid "Changes to config file must be made from source"
msgstr "必须从源文件更改配置文件"
msgstr "必须从源文件更改配置文件"

View File

@ -2,8 +2,8 @@ config clash 'config'
option redir_port '7892'
option http_port '7890'
option socks_port '7891'
option enable '0'
option mode '0'
option enable '0'
option dash_port '9191'
option dash_pass '123456'
option auto_update '0'

View File

@ -3,9 +3,13 @@
START=99
STOP=15
CLASH="/etc/clash/clash"
CLASH_CONFIG="/etc/clash"
CRON_FILE="/etc/crontabs/root"
CONFIG_YAML="/etc/clash/config.yaml"
CONFIG_YAML_OLD="/etc/clash/config.yml"
revert_dns() {
#===========================================================================================================================
@ -27,7 +31,6 @@ add_cron(){
auto=$(uci get clash.config.auto_update 2>/dev/null)
if [ $auto -eq 1 ]; then
[ -z "$(grep -w "/usr/share/clash/clash.sh" $CRON_FILE)" ] && echo "0 $(uci get clash.config.auto_update_time 2>/dev/null) * * * /usr/share/clash/clash.sh" >> $CRON_FILE
[ -z "$(grep -w "/etc/init.d/clash" $CRON_FILE)" ] && echo "05 0 * * * /etc/init.d/clash restart" >> $CRON_FILE
fi
crontab $CRON_FILE
#===========================================================================================================================
@ -54,52 +57,52 @@ yml_change(){
subtype=$(uci get clash.config.subcri 2>/dev/null)
if [ $mode -eq 1 ]; then
sed -i "/Proxy:/i\#clash-openwrt" /etc/clash/config.yaml
sed -i "/#clash-openwrt/a\#=============" /etc/clash/config.yaml
sed -i "/#=============/a\ " /etc/clash/config.yaml
sed -i '1,/#clash-openwrt/d' /etc/clash/config.yaml
sed -i "/Proxy:/i\#clash-openwrt" $CONFIG_YAML
sed -i "/#clash-openwrt/a\#=============" $CONFIG_YAML
sed -i "/#=============/a\ " $CONFIG_YAML
sed -i '1,/#clash-openwrt/d' $CONFIG_YAML
mv /etc/clash/config.yaml /etc/clash/dns.yaml
cat /usr/share/clash/dns.yaml /etc/clash/dns.yaml > /etc/clash/config.yaml
cat /usr/share/clash/dns.yaml /etc/clash/dns.yaml > $CONFIG_YAML
rm -rf /etc/clash/dns.yaml
sed -i "1i\port: ${http_port}" /etc/clash/config.yaml
sed -i "2i\socks-port: ${socks_port}" /etc/clash/config.yaml
sed -i "3i\redir-port: ${redir_port}" /etc/clash/config.yaml
sed -i "4i\allow-lan: true" /etc/clash/config.yaml
sed -i "5i\mode: Rule" /etc/clash/config.yaml
sed -i "6i\log-level: ${log_level}" /etc/clash/config.yaml
sed -i "7i\external-controller: 0.0.0.0:${dash_port}" /etc/clash/config.yaml
sed -i "8i\secret: '${da_password}'" /etc/clash/config.yaml
sed -i "9i\external-ui: "/usr/share/clash/dashboard"" /etc/clash/config.yaml
sed -i "10i\ " /etc/clash/config.yaml
sed -i "11i\ " /etc/clash/config.yaml
sed -i '/#=============/ d' /etc/clash/config.yaml
sed -i "1i\port: ${http_port}" $CONFIG_YAML
sed -i "2i\socks-port: ${socks_port}" $CONFIG_YAML
sed -i "3i\redir-port: ${redir_port}" $CONFIG_YAML
sed -i "4i\allow-lan: true" $CONFIG_YAML
sed -i "5i\mode: Rule" $CONFIG_YAML
sed -i "6i\log-level: ${log_level}" $CONFIG_YAML
sed -i "7i\external-controller: 0.0.0.0:${dash_port}" $CONFIG_YAML
sed -i "8i\secret: '${da_password}'" $CONFIG_YAML
sed -i "9i\external-ui: "/usr/share/clash/dashboard"" $CONFIG_YAML
sed -i "10i\ " $CONFIG_YAML
sed -i "11i\ " $CONFIG_YAML
sed -i '/#=============/ d' $CONFIG_YAML
else
if [ $subtype=="v2rayn2clash" ] || [ $subtype=="surge2clash" ];then
sed -i "/Proxy:/i\#clash-openwrt" /etc/clash/config.yaml
sed -i "/#clash-openwrt/a\#=============" /etc/clash/config.yaml
sed -i "/#=============/a\ " /etc/clash/config.yaml
sed -i '1,/#clash-openwrt/d' /etc/clash/config.yaml
mv /etc/clash/config.yaml /etc/clash/dns.yaml
cat /usr/share/clash/dns.yaml /etc/clash/dns.yaml > /etc/clash/config.yaml
if [ $subtype == "v2rayn2clash" ];then
sed -i "/Proxy:/i\#clash-openwrt" $CONFIG_YAML
sed -i "/#clash-openwrt/a\#=============" $CONFIG_YAML
sed -i "/#=============/a\ " $CONFIG_YAML
sed -i '1,/#clash-openwrt/d' $CONFIG_YAML
mv $CONFIG_YAML /etc/clash/dns.yaml
cat /usr/share/clash/dns.yaml /etc/clash/dns.yaml > $CONFIG_YAML
rm -rf /etc/clash/dns.yaml
else
sed -i "/dns:/i\#clash-openwrt" /etc/clash/config.yaml
sed -i "/#clash-openwrt/a\#=============" /etc/clash/config.yaml
sed -i '1,/#clash-openwrt/d' /etc/clash/config.yaml
sed -i "/dns:/i\#clash-openwrt" $CONFIG_YAML
sed -i "/#clash-openwrt/a\#=============" $CONFIG_YAML
sed -i '1,/#clash-openwrt/d' $CONFIG_YAML
fi
sed -i "1i\port: ${http_port}" /etc/clash/config.yaml
sed -i "2i\socks-port: ${socks_port}" /etc/clash/config.yaml
sed -i "3i\redir-port: ${redir_port}" /etc/clash/config.yaml
sed -i "4i\allow-lan: true" /etc/clash/config.yaml
sed -i "5i\mode: Rule" /etc/clash/config.yaml
sed -i "6i\log-level: ${log_level}" /etc/clash/config.yaml
sed -i "7i\external-controller: 0.0.0.0:${dash_port}" /etc/clash/config.yaml
sed -i "8i\secret: '${da_password}'" /etc/clash/config.yaml
sed -i "9i\external-ui: "/usr/share/clash/dashboard"" /etc/clash/config.yaml
sed -i "10i\ " /etc/clash/config.yaml
sed -i "11i\ " /etc/clash/config.yaml
sed -i '/#=============/ d' /etc/clash/config.yaml
sed -i "1i\port: ${http_port}" $CONFIG_YAML
sed -i "2i\socks-port: ${socks_port}" $CONFIG_YAML
sed -i "3i\redir-port: ${redir_port}" $CONFIG_YAML
sed -i "4i\allow-lan: true" $CONFIG_YAML
sed -i "5i\mode: Rule" $CONFIG_YAML
sed -i "6i\log-level: ${log_level}" $CONFIG_YAML
sed -i "7i\external-controller: 0.0.0.0:${dash_port}" $CONFIG_YAML
sed -i "8i\secret: '${da_password}'" $CONFIG_YAML
sed -i "9i\external-ui: "/usr/share/clash/dashboard"" $CONFIG_YAML
sed -i "10i\ " $CONFIG_YAML
sed -i "11i\ " $CONFIG_YAML
sed -i '/#=============/ d' $CONFIG_YAML
fi
#===========================================================================================================================
@ -110,12 +113,12 @@ fi
yml_dns_change(){
#===========================================================================================================================
dns_port=$(grep listen: /etc/clash/config.yaml |awk -F ':' '{print $3}' |tr -cd "[0-9]")
dns_port=$(grep listen: $CONFIG_YAML |awk -F ':' '{print $3}' |tr -cd "[0-9]")
dnsforwader=$(uci get clash.config.dnsforwader 2>/dev/null)
if [ $dns_port -eq 53 ]; then
sed -i '/listen:/ d' /etc/clash/config.yaml
sed -i "/nameserver:/i\ listen: 0.0.0.0:5300" /etc/clash/config.yaml
sed -i '/listen:/ d' $CONFIG_YAML
sed -i "/nameserver:/i\ listen: 0.0.0.0:5300" $CONFIG_YAML
fi
if [ $dnsforwader -eq 1 ]; then
@ -171,7 +174,7 @@ rules(){
lan_ip=$(uci get network.lan.ipaddr 2>/dev/null)
lanac=$(uci get clash.config.rejectlan 2>/dev/null)
lan=$(uci get clash.config.proxylan 2>/dev/null)
dns_port=$(grep listen: /etc/clash/config.yaml |awk -F ':' '{print $3}' |tr -cd "[0-9]")
dns_port=$(grep listen: $CONFIG_YAML |awk -F ':' '{print $3}' |tr -cd "[0-9]")
redir_port=$(uci get clash.config.redir_port 2>/dev/null)
iptables -t nat -N clash_tcp
@ -185,8 +188,11 @@ rules(){
iptables -t nat -A clash_tcp -d 224.0.0.0/4 -j RETURN
iptables -t nat -A clash_tcp -d 240.0.0.0/4 -j RETURN
iptables -t nat -A clash_tcp -d $lan_ip -j RETURN
iptables -t nat -A clash_tcp -p tcp --dport 22 -j ACCEPT
iptables -t nat -A clash_udp -p udp -j REDIRECT --to-ports $dns_port
iptables -t nat -A clash_udp -p udp -j REDIRECT --to-ports $dns_port
if [ $lanac -eq 1 ]; then
iptables -t nat -A clash_tcp -p tcp -m set --match-set clash_lan src -j RETURN
iptables -t nat -A clash_tcp -p tcp -j REDIRECT --to-ports $redir_port
@ -195,7 +201,9 @@ rules(){
else
iptables -t nat -A clash_tcp -p tcp -j REDIRECT --to-ports $redir_port
fi
iptables -t nat -I PREROUTING 1 -p udp --dport 53 -j clash_udp
iptables -t nat -A PREROUTING -p tcp -j clash_tcp
@ -206,10 +214,10 @@ rules(){
yml_yaml(){
#===========================================================================================================================
subscribe_url=$(uci get clash.config.subscribe_url 2>/dev/null)
size=$(ls -l /etc/clash/config.yaml|awk '{print $5}')
if [ -f /etc/clash/config.yml ] && [ ! -f /etc/clash/config.yaml ] || [ -f /etc/clash/config.yml ] && [ -f /etc/clash/config.yaml ] && [ $size -eq 0 ];then
mv /etc/clash/config.yml /etc/clash/config.yaml
elif [ ! -f /etc/clash/config.yaml ] && [ $subscribe_url ];then
size=$(ls -l $CONFIG_YAML|awk '{print int($5/1024)}')
if [ -f $CONFIG_YAML_OLD ] && [ ! -f $CONFIG_YAML ] || [ -f $CONFIG_YAML_OLD ] && [ -f $CONFIG_YAML ] && [ $size -eq 0 ];then
mv $CONFIG_YAML_OLD $CONFIG_YAML
elif [ ! -f $CONFIG_YAML ] && [ $subscribe_url ];then
sh /usr/share/clash/clash.sh >>/tmp/clash.log >/dev/null 2>&1
fi
#===========================================================================================================================
@ -222,7 +230,7 @@ if pidof clash >/dev/null; then
fi
enable=$(uci get clash.config.enable 2>/dev/null)
yml_yaml
size=$(ls -l /etc/clash/config.yaml|awk '{print $5}')
size=$(ls -l $CONFIG_YAML|awk '{print int($5/1024)}')
lan=$(uci get clash.config.proxylan 2>/dev/null)
lanac=$(uci get clash.config.rejectlan 2>/dev/null)
@ -269,10 +277,8 @@ else
fi
else
echo "===============================$(date "+%Y-%m-%d %H:%M:%S") CLIENT IS DISABLED =====================================" >> /tmp/clash.log
fi
fi
#===========================================================================================================================
}
@ -306,10 +312,11 @@ stop(){
rm -rf /www/clash 2> /dev/null
del_cron
rm -rf /tmp/clash.log
echo "===============================$(date "+%Y-%m-%d %H:%M:%S") CLIENT IS DISABLED =====================================" >> /tmp/clash.log
#===========================================================================================================================
}
@ -318,8 +325,7 @@ restart(){
#===========================================================================================================================
if pidof clash >/dev/null; then
stop
sleep 2
stop
start
else
start

View File

@ -3,28 +3,40 @@ subscribe_url=$(uci get clash.config.subscribe_url 2>/dev/null)
subtype=$(uci get clash.config.subcri 2>/dev/null)
urlv2ray=$(uci get clash.config.v2ray 2>/dev/null)
urlsurge=$(uci get clash.config.surge 2>/dev/null)
enable=$(uci get clash.config.enable 2>/dev/null)
CONFIG_YAML="/etc/clash/config.yaml"
CONFIG_YAML_TEMP="/etc/clash/server.yaml"
CONFIG_YAML_RULE="/usr/share/clash/rule.yaml"
if pidof clash >/dev/null; then
/etc/init.d/clash stop 2>/dev/null
fi
rm -rf /etc/clash/config.bak 2> /dev/null
if [ $subtype == "clash" ];then
wget-ssl --user-agent="User-Agent: Mozilla" $subscribe_url -O 2>&1 >1 /etc/clash/config.yaml
wget-ssl --timeout=30 --tries=2 --user-agent="User-Agent: Mozilla" $subscribe_url -O 2>&1 >1 $CONFIG_YAML
elif [ $subtype == "v2rayn2clash" ];then
wget-ssl --user-agent="User-Agent: Mozilla" $urlv2ray.$subscribe_url -O 2>&1 >1 /etc/clash/server.yaml
if [ -f /etc/clash/server.yaml ];then
sed -i '/Rule:/,$d' /etc/clash/server.yaml
cat /etc/clash/server.yaml /usr/share/clash/rule.yaml > /etc/clash/config.yaml
wget-ssl --timeout=30 --tries=2 --user-agent="User-Agent: Mozilla" $urlv2ray.$subscribe_url -O 2>&1 >1 $CONFIG_YAML_TEMP
if [ -f $CONFIG_YAML_TEMP ];then
sed -i '/Rule:/,$d' $CONFIG_YAML_TEMP
cat $CONFIG_YAML_TEMP $CONFIG_YAML_RULE > $CONFIG_YAML
fi
elif [ $subtype == "surge2clash" ];then
wget-ssl --user-agent="User-Agent: Mozilla" $urlsurge.$subscribe_url -O 2>&1 >1 /etc/clash/server.yaml
if [ -f /etc/clash/server.yaml ];then
sed -i '/Rule:/,$d' /etc/clash/server.yaml
cat /etc/clash/server.yaml /usr/share/clash/rule.yaml > /etc/clash/config.yaml
wget-ssl --timeout=30 --tries=2 --user-agent="User-Agent: Mozilla" $urlsurge.$subscribe_url -O 2>&1 >1 $CONFIG_YAML
fi
rm -rf $CONFIG_YAML_TEMP 2> /dev/null
uci set clash.config.enable=1 2> /dev/null
uci commit clash 2> /dev/null
/etc/init.d/clash restart 2>/dev/null
else
rm -rf /etc/clash/config.bak 2> /dev/null
if [ $subtype == "clash" ];then
wget-ssl --timeout=30 --tries=2 --user-agent="User-Agent: Mozilla" $subscribe_url -O 2>&1 >1 $CONFIG_YAML
elif [ $subtype == "v2rayn2clash" ];then
wget-ssl --timeout=30 --tries=2 --user-agent="User-Agent: Mozilla" $urlv2ray.$subscribe_url -O 2>&1 >1 $CONFIG_YAML_TEMP
if [ -f $CONFIG_YAML_TEMP ];then
sed -i '/Rule:/,$d' $CONFIG_YAML_TEMP
cat $CONFIG_YAML_TEMP $CONFIG_YAML_RULE > $CONFIG_YAML
fi
rm -rf /etc/clash/server.yaml 2> /dev/null
if [ $enable -eq 1 ]; then
[ "$?" -eq "0" ] && /etc/init.d/clash restart 2>/dev/null
elif [ $subtype == "surge2clash" ];then
wget-ssl --timeout=30 --tries=2 --user-agent="User-Agent: Mozilla" $urlsurge.$subscribe_url -O 2>&1 >1 $CONFIG_YAML
fi
rm -rf $CONFIG_YAML_TEMP 2> /dev/null
fi