luci-app-clash: sync with upstream source
This commit is contained in:
parent
1adbf37842
commit
8b4d90a1f0
@ -1,7 +1,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-clash
|
||||
PKG_VERSION:=1.4.5
|
||||
PKG_VERSION:=1.4.6
|
||||
PKG_MAINTAINER:=frainzy1477
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ define Package/luci-app-clash
|
||||
CATEGORY:=LuCI
|
||||
SUBMENU:=3. Applications
|
||||
TITLE:=LuCI app for clash
|
||||
DEPENDS:=+luci +luci-base +wget +iptables +coreutils-base64 +coreutils +coreutils-nohup +bash +ipset +libustream-openssl +libopenssl +openssl-util +kmod-tun
|
||||
DEPENDS:=+luci +luci-base +wget +iptables +coreutils-base64 +coreutils +coreutils-nohup +bash +ipset +libustream-openssl +libopenssl +openssl-util
|
||||
PKGARCH:=all
|
||||
MAINTAINER:=frainzy1477
|
||||
endef
|
||||
@ -22,8 +22,7 @@ define Package/luci-app-clash/description
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
chmod 777 -R ${CURDIR}/tools/po2lmo
|
||||
${CURDIR}/tools/po2lmo/src/po2lmo ${CURDIR}/po/zh-cn/clash.po ${CURDIR}/po/zh-cn/clash.zh-cn.lmo
|
||||
po2lmo ${CURDIR}/po/zh-cn/clash.po ${CURDIR}/po/zh-cn/clash.zh-cn.lmo
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
@ -32,91 +31,61 @@ endef
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/conffiles
|
||||
/etc/config/clash
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/prerm
|
||||
#!/bin/sh
|
||||
# check if we are on real system
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
echo "Removing rc.d symlink for clash"
|
||||
/etc/init.d/clash disable
|
||||
/etc/init.d/clash stop
|
||||
echo "Removing firewall rule for clash"
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete firewall.clash
|
||||
commit firewall
|
||||
EOF
|
||||
fi
|
||||
|
||||
exit 0
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/preinst
|
||||
#!/bin/sh
|
||||
|
||||
[ -z "$${IPKG_INSTROOT}" ] && exit 0
|
||||
|
||||
mkdir -p /usr/share/clashbackup 2>/dev/null
|
||||
|
||||
if [ -f "/tmp/dnsmasq.d/custom_list.conf" ]; then
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
rm -rf /tmp/dnsmasq.d/custom_list.conf 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -d "/tmp/dnsmasq.clash" ]; then
|
||||
rm -rf /tmp/dnsmasq.clash 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f "/etc/config/clash" ]; then
|
||||
mv /etc/config/clash /etc/config/clash.bak 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -d "/usr/lib/lua/luci/model/cbi/clash" ]; then
|
||||
rm -rf /usr/lib/lua/luci/model/cbi/clash 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -d "/usr/lib/lua/luci/view/clash" ]; then
|
||||
rm -rf /usr/lib/lua/luci/view/clash 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f /usr/share/clash/new_core_version ]; then
|
||||
rm -rf /usr/share/clash/new_core_version 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f /usr/share/clash/new_clashr_core_version ]; then
|
||||
rm -rf /usr/share/clash/new_clashr_core_version 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f /usr/share/clash/new_luci_version ]; then
|
||||
rm -rf /usr/share/clash/new_luci_version 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -d /usr/share/clash/web ]; then
|
||||
rm -rf /usr/share/clash/web 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f /usr/share/clash/config/sub/config.yaml ];then
|
||||
mv /usr/share/clash/config/sub/config.yaml /usr/share/clashbackup/config.bak1 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f /usr/share/clash/config/upload/config.yaml ];then
|
||||
mv /usr/share/clash/config/upload/config.yaml /usr/share/clashbackup/config.bak2 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f /usr/share/clash/config/custom/config.yaml ];then
|
||||
mv /usr/share/clash/config/custom/config.yaml /usr/share/clashbackup/config.bak3 2>/dev/null
|
||||
fi
|
||||
|
||||
exit 0
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/postinst
|
||||
#!/bin/sh
|
||||
|
||||
[ -z "$${IPKG_INSTROOT}" ] && exit 0
|
||||
|
||||
rm -rf /tmp/luci*
|
||||
|
||||
if [ -f "/etc/config/clash.bak" ]; then
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
rm -rf /tmp/luci*
|
||||
mv /etc/config/clash.bak /etc/config/clash 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f /usr/share/clashbackup/config.bak1 ];then
|
||||
mv /usr/share/clashbackup/config.bak1 /usr/share/clash/config/sub/config.yaml 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f /usr/share/clashbackup/config.bak2 ];then
|
||||
mv /usr/share/clashbackup/config.bak2 /usr/share/clash/config/upload/config.yaml 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f /usr/share/clashbackup/config.bak3 ];then
|
||||
mv /usr/share/clashbackup/config.bak3 /usr/share/clash/config/custom/config.yaml 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/clash" ]; then
|
||||
/etc/init.d/clash disable 2>/dev/null
|
||||
fi
|
||||
|
||||
mkdir -p /etc/clash/clashtun 2>/dev/null
|
||||
exit 0
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
@ -134,6 +103,9 @@ define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/share/clash/dashboard
|
||||
$(INSTALL_DIR) $(1)/usr/share/clash/dashboard/img
|
||||
$(INSTALL_DIR) $(1)/usr/share/clash/dashboard/js
|
||||
$(INSTALL_DIR) $(1)/etc/clash/clashtun
|
||||
$(INSTALL_DIR) $(1)/usr/share/clashbackup
|
||||
$(INSTALL_DIR) $(1)/etc/clash/provider
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/share/clash/config
|
||||
$(INSTALL_DIR) $(1)/usr/share/clash/config/sub
|
||||
|
||||
@ -64,8 +64,5 @@ o.title = translate("Action")
|
||||
o.template = "clash/start_stop"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return m
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ o.description = translate("Download Rule")
|
||||
o.inputstyle = "reload"
|
||||
o.write = function()
|
||||
uci:commit("clash")
|
||||
SYS.call("sh /usr/share/clash/rule.sh >>/tmp/clash.txt 2>&1 &")
|
||||
luci.sys.call("bash /usr/share/clash/rule.sh >>/tmp/clash.txt >/dev/null 2>&1 &")
|
||||
HTTP.redirect(DISP.build_url("admin", "services", "clash", "servers"))
|
||||
end
|
||||
|
||||
@ -90,7 +90,7 @@ o.inputtitle = translate("Load Config")
|
||||
o.inputstyle = "apply"
|
||||
o.write = function()
|
||||
krk.uci:commit("clash")
|
||||
luci.sys.call("sh /usr/share/clash/load.sh >/dev/null 2>&1 &")
|
||||
luci.sys.call("bash /usr/share/clash/load.sh >/dev/null 2>&1 &")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
|
||||
end
|
||||
|
||||
@ -99,7 +99,7 @@ o.inputtitle = translate("Create Config")
|
||||
o.inputstyle = "apply"
|
||||
o.write = function()
|
||||
krk.uci:commit("clash")
|
||||
luci.sys.call("sh /usr/share/clash/proxy.sh >/dev/null 2>&1 &")
|
||||
luci.sys.call("bash /usr/share/clash/proxy.sh >/dev/null 2>&1 &")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
|
||||
end
|
||||
|
||||
@ -202,10 +202,7 @@ function o.cfgvalue(...)
|
||||
return Value.cfgvalue(...) or translate("None")
|
||||
end
|
||||
|
||||
o = s:option(DummyValue, "path", translate("Provider Path"))
|
||||
function o.cfgvalue(...)
|
||||
return Value.cfgvalue(...) or translate("None")
|
||||
end
|
||||
|
||||
|
||||
|
||||
r = krk:section(TypedSection, "groups", translate("Policy Groups"))
|
||||
|
||||
@ -19,13 +19,14 @@ s.addremove=false
|
||||
|
||||
local conf = "/usr/share/clash/config/custom/config.yaml"
|
||||
sev = s:option(TextValue, "conf")
|
||||
sev.readonly=true
|
||||
--sev.readonly=true
|
||||
sev.rows = 20
|
||||
sev.wrap = "off"
|
||||
sev.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(conf) or ""
|
||||
end
|
||||
sev.write = function(self, section, value)
|
||||
NXFS.writefile(conf, value:gsub("\r\n", "\n"))
|
||||
end
|
||||
|
||||
|
||||
|
||||
@ -97,6 +97,9 @@ o:value("3", translate("Redir-Host(comzyh Tun)"))
|
||||
o.description = translate("Select Tun Mode, Enable Tun custom DNS and make sure you are using tun supported core")
|
||||
o:depends("mode", 0)
|
||||
|
||||
|
||||
|
||||
|
||||
md = s:option(Flag, "mode", translate("Custom DNS"))
|
||||
md.default = 1
|
||||
md.rmempty = false
|
||||
@ -117,6 +120,53 @@ end
|
||||
o.description = translate("NB: press ENTER to create a blank line at the end of input.")
|
||||
o:depends("mode", 1)
|
||||
|
||||
|
||||
local dns1 = "/usr/share/clash/tundns_1.yaml"
|
||||
o = s:option(TextValue, "dns1",translate("Modify Tun DNS"))
|
||||
o.template = "clash/tvalue"
|
||||
o.rows = 26
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(dns1) or ""
|
||||
end
|
||||
o.write = function(self, section, value)
|
||||
NXFS.writefile(dns1, value:gsub("\r\n", "\n"))
|
||||
end
|
||||
o.description = translate("NB: press ENTER to create a blank line at the end of input.")
|
||||
o:depends("tun_mode", 1)
|
||||
|
||||
|
||||
local dns2 = "/usr/share/clash/tundns_2.yaml"
|
||||
o = s:option(TextValue, "dns2",translate("Modify Tun DNS"))
|
||||
o.template = "clash/tvalue"
|
||||
o.rows = 26
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(dns2) or ""
|
||||
end
|
||||
o.write = function(self, section, value)
|
||||
NXFS.writefile(dns2, value:gsub("\r\n", "\n"))
|
||||
end
|
||||
o.description = translate("NB: press ENTER to create a blank line at the end of input.")
|
||||
o:depends("tun_mode", 2)
|
||||
|
||||
|
||||
|
||||
local dns3 = "/usr/share/clash/tundns_3.yaml"
|
||||
o = s:option(TextValue, "dns3",translate("Modify Tun DNS"))
|
||||
o.template = "clash/tvalue"
|
||||
o.rows = 26
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(dns3) or ""
|
||||
end
|
||||
o.write = function(self, section, value)
|
||||
NXFS.writefile(dns3, value:gsub("\r\n", "\n"))
|
||||
end
|
||||
o.description = translate("NB: press ENTER to create a blank line at the end of input.")
|
||||
o:depends("tun_mode", 3)
|
||||
|
||||
|
||||
o = s:option(Button, "Apply")
|
||||
o.title = translate("Save & Apply")
|
||||
o.inputtitle = translate("Save & Apply")
|
||||
|
||||
@ -6,6 +6,19 @@ local ipkg = require("luci.model.ipkg")
|
||||
local fs = require "nixio.fs"
|
||||
local sys = require "luci.sys"
|
||||
local sid = arg[1]
|
||||
local http = luci.http
|
||||
local fss = require "luci.clash"
|
||||
|
||||
function IsYamlFile(e)
|
||||
e=e or""
|
||||
local e=string.lower(string.sub(e,-5,-1))
|
||||
return e == ".yaml"
|
||||
end
|
||||
function IsYmlFile(e)
|
||||
e=e or""
|
||||
local e=string.lower(string.sub(e,-4,-1))
|
||||
return e == ".yml"
|
||||
end
|
||||
|
||||
|
||||
m = Map(clash, translate("Edit Proxy Provider"))
|
||||
@ -20,25 +33,87 @@ s.anonymous = true
|
||||
s.addremove = false
|
||||
|
||||
o = s:option(ListValue, "type", translate("Provider Type"))
|
||||
o.rmempty = true
|
||||
o.rmempty = false
|
||||
o.description = translate("Provider Type")
|
||||
o:value("http")
|
||||
o:value("file")
|
||||
|
||||
o = s:option(FileUpload, "",translate("Upload Provider File"))
|
||||
o.title = translate("Provider File")
|
||||
o.template = "clash/clash_upload"
|
||||
o:depends("type", "file")
|
||||
um = s:option(DummyValue, "", nil)
|
||||
um.template = "clash/clash_dvalue"
|
||||
|
||||
local dir, fd
|
||||
dir = "/etc/clash/provider/"
|
||||
http.setfilehandler(
|
||||
function(meta, chunk, eof)
|
||||
if not fd then
|
||||
if not meta then return end
|
||||
|
||||
if meta and chunk then fd = nixio.open(dir .. meta.file, "w") end
|
||||
|
||||
if not fd then
|
||||
um.value = translate("upload file error.")
|
||||
return
|
||||
end
|
||||
end
|
||||
if chunk and fd then
|
||||
fd:write(chunk)
|
||||
end
|
||||
if eof and fd then
|
||||
fd:close()
|
||||
fd = nil
|
||||
um.value = translate("File saved to") .. ' "/etc/clash/provider/"'
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
if luci.http.formvalue("upload") then
|
||||
local f = luci.http.formvalue("ulfile")
|
||||
if #f <= 0 then
|
||||
um.value = translate("No specify upload file.")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
o = s:option(Value, "name", translate("Provider Name"))
|
||||
o.rmempty = false
|
||||
|
||||
|
||||
o = s:option(ListValue, "pathh", translate("Provider Path"))
|
||||
o.description = translate("Upload Provider File If Empty")
|
||||
local p,h={}
|
||||
for t,f in ipairs(fss.glob("/etc/clash/provider/*"))do
|
||||
h=fss.stat(f)
|
||||
if h then
|
||||
p[t]={}
|
||||
p[t].name=fss.basename(f)
|
||||
if IsYamlFile(p[t].name) or IsYmlFile(p[t].name) then
|
||||
o:value("./provider/"..p[t].name)
|
||||
end
|
||||
end
|
||||
end
|
||||
o.rmempty = true
|
||||
o:depends("type", "file")
|
||||
|
||||
|
||||
o = s:option(Value, "path", translate("Provider Path"))
|
||||
o.description = translate("【HTTP】./hk.yaml or 【File】/etc/clash/hk.yaml")
|
||||
o.rmempty = false
|
||||
o.description = translate("./hk.yaml")
|
||||
o.rmempty = true
|
||||
o:depends("type", "http")
|
||||
|
||||
|
||||
o = s:option(Value, "provider_url", translate("Provider URL"))
|
||||
o.rmempty = false
|
||||
o.description = translate("【HTTP】./hk.yaml")
|
||||
o.rmempty = true
|
||||
o:depends("type", "http")
|
||||
|
||||
o = s:option(Value, "provider_interval", translate("Provider Interval"))
|
||||
o.default = "3600"
|
||||
o.rmempty = false
|
||||
o.rmempty = true
|
||||
o:depends("type", "http")
|
||||
|
||||
o = s:option(ListValue, "health_check", translate("Provider Health Check"))
|
||||
@ -48,11 +123,11 @@ o.default=true
|
||||
|
||||
o = s:option(Value, "health_check_url", translate("Health Check URL"))
|
||||
o.default = "http://www.gstatic.com/generate_204"
|
||||
o.rmempty = false
|
||||
o.rmempty = true
|
||||
|
||||
o = s:option(Value, "health_check_interval", translate("Health Check Interval"))
|
||||
o.default = "300"
|
||||
o.rmempty = false
|
||||
o.rmempty = true
|
||||
|
||||
o = s:option(DynamicList, "groups", translate("Policy Group"))
|
||||
o.rmempty = true
|
||||
|
||||
@ -18,13 +18,14 @@ s.addremove=false
|
||||
|
||||
local conf = "/usr/share/clash/config/sub/config.yaml"
|
||||
sev = s:option(TextValue, "conf")
|
||||
sev.readonly=true
|
||||
--sev.readonly=true
|
||||
sev.rows = 20
|
||||
sev.wrap = "off"
|
||||
sev.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(conf) or ""
|
||||
end
|
||||
sev.write = function(self, section, value)
|
||||
NXFS.writefile(conf, value:gsub("\r\n", "\n"))
|
||||
end
|
||||
|
||||
|
||||
|
||||
@ -18,13 +18,14 @@ s.addremove=false
|
||||
|
||||
local conf = "/usr/share/clash/config/upload/config.yaml"
|
||||
sev = s:option(TextValue, "conf")
|
||||
sev.readonly=true
|
||||
--sev.readonly=true
|
||||
sev.rows = 20
|
||||
sev.wrap = "off"
|
||||
sev.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(conf) or ""
|
||||
end
|
||||
sev.write = function(self, section, value)
|
||||
NXFS.writefile(conf, value:gsub("\r\n", "\n"))
|
||||
end
|
||||
|
||||
o = s:option(Button,"configrm")
|
||||
@ -34,3 +35,5 @@ o.write = function()
|
||||
end
|
||||
|
||||
return m
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<%local fs=require"nixio.fs"%>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<input type="button" class="cbi-button cbi-button-apply" id="apply_update_button" value="<%:Download%>" onclick=" return apply_update() "/>
|
||||
<br><br>
|
||||
<br /><br />
|
||||
<textarea id="core_download" class="cbi-input-textarea" style="width: 100%;display:none" data-update="change" rows="10" cols="100" readonly="readonly" > </textarea>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
<input type="button" class="cbi-button cbi-button-apply" value="<%:Start Client%>" onclick=" return start() "/>
|
||||
<input type="button" class="cbi-button cbi-button-apply" style="background-color:#ea4368;" value="<%:Stop Client%>" onclick=" return stop() "/>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
|
||||
function start(){
|
||||
XHR.get('<%=url([[admin]], [[services]], [[clash]], [[start]])%>',null,function(x, data){}
|
||||
@ -18,6 +19,7 @@ function stop(){
|
||||
window.setTimeout("location.href='/cgi-bin/luci/admin/services/clash/'", 500);
|
||||
return
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
<%+cbi/valuefooter%>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -90,7 +90,7 @@ function version_check(btn)
|
||||
|
||||
else if(status.new_version==0)
|
||||
{
|
||||
version_butt.innerHTML ='<center><input type="button" class="cbi-button cbi-button-reset" value="<%:Error Occu"red" |Return%>" onclick="return check_return(this)"/></center>';
|
||||
version_butt.innerHTML ='<center><input type="button" class="cbi-button cbi-button-reset" value="<%:Error Occured |Return%>" onclick="return check_return(this)"/></center>';
|
||||
|
||||
}
|
||||
else if(status.current_version >= status.new_version)
|
||||
@ -114,7 +114,7 @@ function core_check(btn)
|
||||
|
||||
else if(status.new_core_version==0)
|
||||
{
|
||||
core_butt.innerHTML ='<center><input type="button" class="cbi-button cbi-button-reset" value="<%:Error Occu"red" |Return%>" onclick="return core_return(this)"/></center>';
|
||||
core_butt.innerHTML ='<center><input type="button" class="cbi-button cbi-button-reset" value="<%:Error Occured |Return%>" onclick="return core_return(this)"/></center>';
|
||||
|
||||
}
|
||||
else if(status.clash_core >= status.new_core_version)
|
||||
@ -137,7 +137,7 @@ function clashr_core_check(btn)
|
||||
|
||||
else if(status.new_clashr_core_version==0)
|
||||
{
|
||||
corer_butt.innerHTML ='<center><input type="button" class="cbi-button cbi-button-reset" value="<%:Error Occu"red" |Return%>" onclick="return clashr_core_return(this)"/></center>';
|
||||
corer_butt.innerHTML ='<center><input type="button" class="cbi-button cbi-button-reset" value="<%:Error Occured |Return%>" onclick="return clashr_core_return(this)"/></center>';
|
||||
|
||||
}
|
||||
else if(status.clashr_core >= status.new_clashr_core_version)
|
||||
|
||||
@ -661,3 +661,15 @@ msgstr "Tun模式DNS"
|
||||
|
||||
msgid "Select Tun Mode, Enable Tun custom DNS and make sure you are using tun supported core"
|
||||
msgstr "选择Tun模式,启用Tun自定义DNS,并确保使用支持的Tun内核"
|
||||
|
||||
msgid "Upload Provider File"
|
||||
msgstr "上传代理集文件"
|
||||
|
||||
msgid "Upload Provider File If Empty"
|
||||
msgstr "上传代理集文件(如果为空)"
|
||||
|
||||
msgid "Provider File"
|
||||
msgstr "代理集文件"
|
||||
|
||||
msgid "Modify Tun DNS"
|
||||
msgstr "修改Tun DNS"
|
||||
@ -25,7 +25,6 @@ revert_dns() {
|
||||
dns_port=$(grep "^ \{0,\}listen:" $CONFIG_YAML |awk -F ':' '{print $3}' 2>/dev/null)
|
||||
uci del_list dhcp.@dnsmasq[0].server=127.0.0.1#$dns_port >/dev/null 2>&1
|
||||
uci set dhcp.@dnsmasq[0].noresolv=0
|
||||
uci set dhcp.@dnsmasq[0].resolvfile=/tmp/resolv.conf.auto
|
||||
uci delete dhcp.@dnsmasq[0].cachesize
|
||||
rm -rf $CUSLIST $CUSLITT $CUSLISTV $CUSLITTV 2>/dev/null
|
||||
uci commit dhcp
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
#!/bin/bash /etc/rc.common
|
||||
. /lib/functions.sh
|
||||
|
||||
lang=$(uci get luci.main.lang 2>/dev/null)
|
||||
@ -6,6 +6,7 @@ loadgroups=$(uci get clash.config.loadgroups 2>/dev/null)
|
||||
loadservers=$(uci get clash.config.loadservers 2>/dev/null)
|
||||
load_from=$(uci get clash.config.loadfrom 2>/dev/null)
|
||||
|
||||
run_load(){
|
||||
|
||||
if [ "$load_from" == "sub" ];then
|
||||
load="/usr/share/clash/config/sub/config.yaml"
|
||||
@ -13,21 +14,19 @@ elif [ "$load_from" == "upl" ];then
|
||||
load="/usr/share/clash/config/upload/config.yaml"
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -f $load ] && [ ! -f $load ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
CFG_FILE="/etc/config/clash"
|
||||
REAL_LOG="/usr/share/clash/clash_real.txt"
|
||||
|
||||
|
||||
rm -rf /tmp/group_*.yaml /tmp/yaml_group.yaml /tmp/Proxy_Group
|
||||
rm -rf /tmp/Proxy_Group /tmp/servers.yaml /tmp/yaml_proxy.yaml /tmp/group_*.yaml /tmp/yaml_group.yaml /tmp/match_servers.list /tmp/yaml_provider.yaml /tmp/provider.yaml /tmp/provider_gen.yaml /tmp/provider_che.yaml /tmp/match_provider.list 2>/dev/null
|
||||
|
||||
|
||||
if [ $loadgroups -eq 1 ];then
|
||||
|
||||
|
||||
|
||||
if [ ! -f $load ] && [ ! -f $load ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ $lang == "zh_cn" ];then
|
||||
echo "开始更新策略组配置..." >$REAL_LOG
|
||||
elif [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
@ -35,7 +34,7 @@ fi
|
||||
fi
|
||||
|
||||
sleep 3
|
||||
if [ -f "$load" ]; then
|
||||
|
||||
[ ! -z "$(grep "^ \{0,\}'Proxy':" "$load")" ] || [ ! -z "$(grep '^ \{0,\}"Proxy":' "$load")" ] && {
|
||||
sed -i "/^ \{0,\}\'Proxy\':/c\Proxy:" "$load"
|
||||
sed -i '/^ \{0,\}\"Proxy\":/c\Proxy:' "$load"
|
||||
@ -67,6 +66,7 @@ if [ -f "$load" ]; then
|
||||
provider_len=$(sed -n '/^ \{0,\}proxy-provider:/=' "$load" 2>/dev/null)
|
||||
if [ "$provider_len" -ge "$group_len" ]; then
|
||||
awk '/Proxy:/,/proxy-provider:/{print}' "$load" 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
|
||||
sed -i "s/proxy-provider://g" /tmp/Proxy_Group 2>&1
|
||||
else
|
||||
awk '/Proxy:/,/Rule:/{print}' "$load" 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
|
||||
fi
|
||||
@ -83,34 +83,8 @@ if [ -f "$load" ]; then
|
||||
echo '读取错误,配置文件异常!' >/tmp/Proxy_Group
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
echo "Read error, configuration file exception!" >/tmp/Proxy_Group
|
||||
elif [ $lang == "zh_cn" ];then
|
||||
echo '读取错误,配置文件异常!' >/tmp/Proxy_Group
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
[ ! -z "$(grep "Read error" /tmp/Proxy_Group)"] && {
|
||||
echo "Read error, configuration file exception!" >$REAL_LOG
|
||||
uci commit clash
|
||||
sleep 5
|
||||
echo "" >$REAL_LOG
|
||||
exit 0
|
||||
}
|
||||
elif [ $lang == "zh_cn" ];then
|
||||
[ ! -z "$(grep "读取错误" /tmp/Proxy_Group)"] && {
|
||||
echo "读取错误,配置文件异常!" >$REAL_LOG
|
||||
uci commit clash
|
||||
sleep 5
|
||||
echo "" >$REAL_LOG
|
||||
exit 0
|
||||
}
|
||||
fi
|
||||
|
||||
|
||||
|
||||
#awk '/Proxy Group:/,/Rule:/{print}' $load 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
|
||||
|
||||
@ -118,34 +92,20 @@ group_len=$(sed -n '/^ \{0,\}Proxy Group:/=' "$load" 2>/dev/null)
|
||||
provider_len=$(sed -n '/^ \{0,\}proxy-provider:/=' "$load" 2>/dev/null)
|
||||
if [ "$provider_len" -ge "$group_len" ]; then
|
||||
awk '/Proxy Group:/,/proxy-provider:/{print}' "$load" 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
|
||||
sed -i "s/proxy-provider://g" /tmp/yaml_group.yaml 2>&1
|
||||
else
|
||||
awk '/Proxy Group:/,/Rule:/{print}' "$load" 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
|
||||
fi
|
||||
|
||||
if [ -f /tmp/yaml_group.yaml ] && [ "$(ls -l /tmp/yaml_group.yaml | awk '{print int($5)}')" -eq 0 ];then
|
||||
|
||||
if [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
echo "No policy group found. Aborting Operation .." >$REAL_LOG
|
||||
sleep 5
|
||||
echo "Clash for OpenWRT" >$REAL_LOG
|
||||
elif [ $lang == "zh_cn" ];then
|
||||
echo "找不到策略组。中止操作..." >$REAL_LOG
|
||||
sleep 5
|
||||
echo "Clash for OpenWRT" >$REAL_LOG
|
||||
fi
|
||||
exit 0
|
||||
else
|
||||
#######READ GROUPS START
|
||||
if [ $loadgroups -eq 1 ];then
|
||||
|
||||
if [ -f /tmp/yaml_group.yaml ];then
|
||||
while [[ "$( grep -c "config groups" $CFG_FILE )" -ne 0 ]]
|
||||
do
|
||||
uci delete clash.@groups[0] && uci commit clash >/dev/null 2>&1
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -161,6 +121,8 @@ 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"
|
||||
@ -275,18 +237,19 @@ uci commit clash
|
||||
|
||||
|
||||
awk '/^ {0,}Rule:/,/^ {0,}##END/{print}' $load 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\t/ /g' 2>/dev/null >/tmp/rule.yaml 2>&1
|
||||
rm -rf /usr/shar/clash/custom_rule.yaml 2>/dev/null
|
||||
mv /tmp/rule.yaml /usr/share/clash/custom_rule.yaml 2>/dev/null
|
||||
rm -rf /tmp/rule.yaml 2>&1
|
||||
rm -rf /usr/shar/clash/custom_rule.yaml 2>/dev/null
|
||||
mv /tmp/rule.yaml /usr/share/clash/custom_rule.yaml 2>/dev/null
|
||||
rm -rf /tmp/rule.yaml 2>&1
|
||||
|
||||
fi
|
||||
|
||||
fi
|
||||
#######READ GROUPS END
|
||||
|
||||
|
||||
#awk '/^ {0,}Proxy:/,/^ {0,}Proxy Group:/{print}' $load 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
|
||||
|
||||
|
||||
rm -rf /tmp/servers.yaml /tmp/yaml_proxy.yaml /tmp/yaml_provider.yaml 2>/dev/null
|
||||
if [ $loadservers -eq 1 ];then
|
||||
|
||||
|
||||
proxy_len=$(sed -n '/^ \{0,\}Proxy:/=' $load 2>/dev/null)
|
||||
group_len=$(sed -n '/^ \{0,\}Proxy Group:/=' "$load" 2>/dev/null)
|
||||
@ -295,12 +258,18 @@ provider_len=$(sed -n '/^ \{0,\}proxy-provider:/=' $load 2>/dev/null)
|
||||
if [ ! -z "$provider_len" ] && [ "$provider_len" -ge "$proxy_len" ] && [ "$provider_len" -le "$group_len" ]; then
|
||||
awk '/^ {0,}Proxy:/,/^ {0,}proxy-provider:/{print}' "$load" 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
|
||||
awk '/^ {0,}proxy-provider:/,/^ {0,}Proxy Group:/{print}' "$load" 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\t/ /g' 2>/dev/null >/tmp/yaml_provider.yaml 2>&1
|
||||
sed -i "s/Proxy Group://g" /tmp/yaml_provider.yaml 2>&1
|
||||
sed -i "s/proxy-provider://g" /tmp/yaml_proxy.yaml 2>&1
|
||||
elif [ ! -z "$provider_len" ] && [ "$provider_len" -le "$proxy_len" ]; then
|
||||
awk '/^ {0,}Proxy:/,/^ {0,}Proxy Group:/{print}' "$load" 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
|
||||
awk '/^ {0,}proxy-provider:/,/^ {0,}Proxy:/{print}' "$load" 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\t/ /g' 2>/dev/null >/tmp/yaml_provider.yaml 2>&1
|
||||
sed -i "s/Proxy://g" /tmp/yaml_provider.yaml 2>&1
|
||||
sed -i "s/Proxy Group://g" /tmp/yaml_proxy.yaml 2>&1
|
||||
elif [ ! -z "$provider_len" ] && [ "$provider_len" -ge "$group_len" ]; then
|
||||
awk '/^ {0,}Proxy:/,/^ {0,}Proxy Group:/{print}' "$load" 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
|
||||
awk '/^ {0,}proxy-provider:/,/^ {0,}Rule:/{print}' "$load" 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\t/ /g' 2>/dev/null >/tmp/yaml_provider.yaml 2>&1
|
||||
awk '/^ {0,}Proxy:/,/^ {0,}Proxy Group:/{print}' "$load" 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
|
||||
awk '/^ {0,}proxy-provider:/,/^ {0,}Rule:/{print}' "$load" 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\t/ /g' 2>/dev/null >/tmp/yaml_provider.yaml 2>&1
|
||||
sed -i "s/Rule://g" /tmp/yaml_provider.yaml 2>&1
|
||||
sed -i "s/Proxy Group://g" /tmp/yaml_proxy.yaml 2>&1
|
||||
else
|
||||
awk '/^ {0,}Proxy:/,/^ {0,}Proxy Group:/{print}' "$load" 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
|
||||
fi
|
||||
@ -312,41 +281,12 @@ single_provider_gen="/tmp/provider_gen.yaml"
|
||||
single_provider_che="/tmp/provider_che.yaml"
|
||||
provider_file="/tmp/yaml_provider.yaml"
|
||||
group_num=$(grep -c "name:" /tmp/yaml_group.yaml)
|
||||
|
||||
|
||||
|
||||
if [ $loadservers -eq 1 ];then
|
||||
|
||||
while [[ "$( grep -c "config servers" $CFG_FILE )" -ne 0 ]]
|
||||
do
|
||||
uci delete clash.@servers[0] && uci commit clash >/dev/null 2>&1
|
||||
done
|
||||
|
||||
|
||||
|
||||
if [ -f /tmp/yaml_proxy.yaml ] && [ "$(ls -l /tmp/yaml_proxy.yaml | awk '{print int($5)}')" -eq 0 ];then
|
||||
|
||||
if [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
echo "No proxies found. Aborting Operation .." >$REAL_LOG
|
||||
sleep 5
|
||||
echo "Clash for OpenWRT" >$REAL_LOG
|
||||
elif [ $lang == "zh_cn" ];then
|
||||
echo "找不到代理。中止操作..." >$REAL_LOG
|
||||
sleep 5
|
||||
echo "Clash for OpenWRT" >$REAL_LOG
|
||||
fi
|
||||
exit 0
|
||||
else
|
||||
while [[ "$( grep -c "config servers" $CFG_FILE )" -ne 0 ]]
|
||||
do
|
||||
uci delete clash.@servers[0] && uci commit clash >/dev/null 2>&1
|
||||
done
|
||||
|
||||
fi
|
||||
match_servers="/tmp/match_servers.list"
|
||||
|
||||
server_file="/tmp/yaml_proxy.yaml"
|
||||
single_server="/tmp/servers.yaml"
|
||||
|
||||
|
||||
line=$(sed -n '/^ \{0,\}-/=' $server_file)
|
||||
num=$(grep -c "^ \{0,\}-" $server_file)
|
||||
count=1
|
||||
@ -359,13 +299,22 @@ provider_num=$(grep -c "^ \{0,\}type:" $provider_file)
|
||||
provider_count=1
|
||||
|
||||
|
||||
|
||||
|
||||
cfg_get()
|
||||
{
|
||||
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)"
|
||||
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)"
|
||||
}
|
||||
|
||||
cfg_gett()
|
||||
{
|
||||
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)"
|
||||
}
|
||||
#######READ SERVERS START
|
||||
if [ -f /tmp/yaml_proxy.yaml ];then
|
||||
while [[ "$( grep -c "config servers" $CFG_FILE )" -ne 0 ]]
|
||||
do
|
||||
uci delete clash.@servers[0] && uci commit clash >/dev/null 2>&1
|
||||
done
|
||||
|
||||
|
||||
|
||||
for n in $line
|
||||
@ -386,63 +335,63 @@ do
|
||||
startLine=$(expr "$endLine" + 1)
|
||||
|
||||
#type
|
||||
server_type="$(cfg_get "type:")"
|
||||
server_type="$(cfg_gett "type:")"
|
||||
#name
|
||||
server_name="$(cfg_get "name:")"
|
||||
server_name="$(cfg_gett "name:")"
|
||||
#server
|
||||
server="$(cfg_get "server:")"
|
||||
server="$(cfg_gett "server:")"
|
||||
#port
|
||||
port="$(cfg_get "port:")"
|
||||
port="$(cfg_gett "port:")"
|
||||
#cipher
|
||||
cipher="$(cfg_get "cipher:")"
|
||||
cipher="$(cfg_gett "cipher:")"
|
||||
#password
|
||||
password="$(cfg_get "password:")"
|
||||
password="$(cfg_gett "password:")"
|
||||
#protocol
|
||||
protocol="$(cfg_get "protocol:")"
|
||||
protocol="$(cfg_gett "protocol:")"
|
||||
#protocolparam
|
||||
protocolparam="$(cfg_get "protocolparam:")"
|
||||
protocolparam="$(cfg_gett "protocolparam:")"
|
||||
#obfsparam
|
||||
obfsparam="$(cfg_get "obfsparam:")"
|
||||
obfsparam="$(cfg_gett "obfsparam:")"
|
||||
#udp
|
||||
udp="$(cfg_get "udp:")"
|
||||
udp="$(cfg_gett "udp:")"
|
||||
#plugin:
|
||||
plugin="$(cfg_get "plugin:")"
|
||||
plugin="$(cfg_gett "plugin:")"
|
||||
#plugin-opts:
|
||||
plugin_opts="$(cfg_get "plugin-opts:")"
|
||||
plugin_opts="$(cfg_gett "plugin-opts:")"
|
||||
#obfs:
|
||||
obfs="$(cfg_get "obfs:")"
|
||||
obfs="$(cfg_gett "obfs:")"
|
||||
#obfs-host:
|
||||
obfs_host="$(cfg_get "obfs-host:")"
|
||||
obfs_host="$(cfg_gett "obfs-host:")"
|
||||
#psk:
|
||||
psk="$(cfg_get "psk:")"
|
||||
psk="$(cfg_gett "psk:")"
|
||||
#mode:
|
||||
mode="$(cfg_get "mode:")"
|
||||
mode="$(cfg_gett "mode:")"
|
||||
#tls:
|
||||
tls="$(cfg_get "tls:")"
|
||||
tls="$(cfg_gett "tls:")"
|
||||
#skip-cert-verify:
|
||||
verify="$(cfg_get "skip-cert-verify:")"
|
||||
verify="$(cfg_gett "skip-cert-verify:")"
|
||||
#mux:
|
||||
mux="$(cfg_get "mux:")"
|
||||
mux="$(cfg_gett "mux:")"
|
||||
#host:
|
||||
host="$(cfg_get "host:")"
|
||||
host="$(cfg_gett "host:")"
|
||||
#Host:
|
||||
Host="$(cfg_get "Host:")"
|
||||
Host="$(cfg_gett "Host:")"
|
||||
#path:
|
||||
path="$(cfg_get "path:")"
|
||||
path="$(cfg_gett "path:")"
|
||||
#ws-path:
|
||||
ws_path="$(cfg_get "ws-path:")"
|
||||
ws_path="$(cfg_gett "ws-path:")"
|
||||
#headers_custom:
|
||||
headers="$(cfg_get "custom:")"
|
||||
headers="$(cfg_gett "custom:")"
|
||||
#uuid:
|
||||
uuid="$(cfg_get "uuid:")"
|
||||
uuid="$(cfg_gett "uuid:")"
|
||||
#alterId:
|
||||
alterId="$(cfg_get "alterId:")"
|
||||
alterId="$(cfg_gett "alterId:")"
|
||||
#network
|
||||
network="$(cfg_get "network:")"
|
||||
network="$(cfg_gett "network:")"
|
||||
#username
|
||||
username="$(cfg_get "username:")"
|
||||
username="$(cfg_gett "username:")"
|
||||
#tls_custom:
|
||||
tls_custom="$(cfg_get "tls:")"
|
||||
tls_custom="$(cfg_gett "tls:")"
|
||||
|
||||
|
||||
if [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
@ -532,34 +481,60 @@ do
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
sleep 2
|
||||
|
||||
uci commit clash
|
||||
|
||||
if [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
|
||||
if [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
echo "Reading Server Completed" >$REAL_LOG
|
||||
sleep 2
|
||||
echo "Clash for OpenWRT" >$REAL_LOG
|
||||
elif [ $lang == "zh_cn" ];then
|
||||
elif [ $lang == "zh_cn" ];then
|
||||
echo "读取代理配置完成" >$REAL_LOG
|
||||
sleep 2
|
||||
echo "Clash for OpenWRT" >$REAL_LOG
|
||||
fi
|
||||
|
||||
fi
|
||||
fi
|
||||
#######READ SERVERS END
|
||||
|
||||
#######READ PROVIDER START
|
||||
|
||||
if [ -f /tmp/yaml_provider.yaml ];then
|
||||
|
||||
while [[ "$( grep -c "config provider" $CFG_FILE )" -ne 0 ]]
|
||||
do
|
||||
uci delete clash.@provider[0] && uci commit clash 2>/dev/null
|
||||
done
|
||||
|
||||
|
||||
|
||||
echo "" >"$match_provider"
|
||||
provider_nums=0
|
||||
config_load "clash"
|
||||
config_foreach yml_provider_name_get "provider"
|
||||
|
||||
|
||||
yml_provider_name_get()
|
||||
{
|
||||
local section="$1"
|
||||
config_get "name" "$section" "name" ""
|
||||
[ ! -z "$name" ] && {
|
||||
echo "$provider_nums"."$name" >>"$match_provider"
|
||||
}
|
||||
provider_nums=$(( $provider_nums + 1 ))
|
||||
}
|
||||
|
||||
|
||||
|
||||
if [ -f /tmp/yaml_provider.yaml ] && [ "$(ls -l /tmp/yaml_provider.yaml | awk '{print int($5)}')" -eq 0 ];then
|
||||
|
||||
cfg_new_provider_groups_get()
|
||||
{
|
||||
if [ -z "$1" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
${uci_add}groups="${1}"
|
||||
}
|
||||
|
||||
|
||||
while [[ "$( grep -c "config provider" $CFG_FILE )" -ne 0 ]]
|
||||
do
|
||||
uci delete clash.@provider[0] && uci commit clash 2>/dev/null
|
||||
done
|
||||
|
||||
|
||||
for n in $provider_line
|
||||
@ -590,7 +565,7 @@ do
|
||||
|
||||
#path
|
||||
provider_path="$(cfg_get "path:" "$single_provider_gen")"
|
||||
|
||||
|
||||
#gen_url
|
||||
provider_gen_url="$(cfg_get "url:" "$single_provider_gen")"
|
||||
|
||||
@ -606,16 +581,13 @@ do
|
||||
#che_interval
|
||||
provider_che_interval="$(cfg_get "interval:" "$single_provider_che")"
|
||||
|
||||
|
||||
|
||||
if [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
echo "Now Reading 【$provider_name】 Proxy Provider..." >$REAL_LOG
|
||||
echo "Now Reading 【$provider_type】-【$server_name】 Proxy-Provider..." >$REAL_LOG
|
||||
elif [ $lang == "zh_cn" ];then
|
||||
echo "正在读取【$provider_name】代理集配置..." >$REAL_LOG
|
||||
echo "正在读取【$provider_type】-【$provider_name】代理集配置..." >$START_LOG
|
||||
fi
|
||||
|
||||
provider_nums=$(grep -Fw "$provider_name" "$match_provider" |awk -F '.' '{print $1}')
|
||||
|
||||
|
||||
name=clash
|
||||
uci_name_tmp=$(uci add $name provider)
|
||||
uci_set="uci -q set $name.$uci_name_tmp."
|
||||
@ -629,8 +601,10 @@ do
|
||||
${uci_set}health_check_url="$provider_che_url"
|
||||
${uci_set}health_check_interval="$provider_che_interval"
|
||||
|
||||
for ((i=1;i<=${group_num};i++))
|
||||
do
|
||||
|
||||
if [ ! -z "$(grep "config groups" "$CFG_FILE")" ]; then
|
||||
for ((i=1;i<=$group_num;i++))
|
||||
do
|
||||
single_group="/tmp/group_$i.yaml"
|
||||
use_line=$(sed -n '/^ \{0,\}use:/=' $single_group)
|
||||
proxies_line=$(sed -n '/^ \{0,\}proxies:/=' $single_group)
|
||||
@ -645,35 +619,36 @@ do
|
||||
${uci_add}groups="$group_name"
|
||||
fi
|
||||
elif [ ! -z "$use_line" ] && [ -z "$proxies_line" ]; then
|
||||
if [ ! -z "$(grep -F "$provider_name" $single_group)" ]; then
|
||||
if [ ! -z "$(grep -F "$provider_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
|
||||
fi
|
||||
fi
|
||||
done
|
||||
uci commit clash
|
||||
done
|
||||
fi
|
||||
|
||||
uci commit clash
|
||||
done
|
||||
|
||||
|
||||
if [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
echo "Reading Proxy Provider Completed" >$REAL_LOG
|
||||
sleep 2
|
||||
echo "Clash for OpenWRT" >$REAL_LOG
|
||||
elif [ $lang == "zh_cn" ];then
|
||||
echo "读取代理集配置完成" >$REAL_LOG
|
||||
sleep 2
|
||||
echo "Clash for OpenWRT" >$REAL_LOG
|
||||
fi
|
||||
#######READ PROVIDER END
|
||||
fi
|
||||
fi
|
||||
rm -rf /tmp/Proxy_Group /tmp/servers.yaml /tmp/yaml_proxy.yaml /tmp/group_*.yaml /tmp/yaml_group.yaml /tmp/match_servers.list /tmp/yaml_provider.yaml /tmp/provider.yaml /tmp/provider_gen.yaml /tmp/provider_che.yaml /tmp/match_provider.list 2>/dev/null
|
||||
|
||||
/usr/share/clash/proxy.sh >/dev/null 2>&1
|
||||
|
||||
yml_provider_name_get()
|
||||
{
|
||||
local section="$1"
|
||||
config_get "name" "$section" "name" ""
|
||||
[ ! -z "$name" ] && {
|
||||
echo "$provider_nums"."$name" >>"$match_provider"
|
||||
}
|
||||
provider_nums=$(( $provider_nums + 1 ))
|
||||
}
|
||||
|
||||
run_load >/dev/null 2>&1
|
||||
|
||||
echo "" >"$match_provider"
|
||||
provider_nums=0
|
||||
config_load "clash"
|
||||
config_foreach yml_provider_name_get "provider"
|
||||
|
||||
fi
|
||||
|
||||
/usr/share/clash/proxy.sh 2>/dev/null
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
1.4.5
|
||||
1.4.6
|
||||
|
||||
@ -1,10 +1,18 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
#!/bin/bash /etc/rc.common
|
||||
. /lib/functions.sh
|
||||
|
||||
REAL_LOG="/usr/share/clash/clash_real.txt"
|
||||
lang=$(uci get luci.main.lang 2>/dev/null)
|
||||
config_type=$(uci get clash.config.config_type 2>/dev/null)
|
||||
create=$(uci get clash.config.create 2>/dev/null)
|
||||
load_from=$(uci get clash.config.loadfrom 2>/dev/null)
|
||||
|
||||
|
||||
if [ "$load_from" == "sub" ];then
|
||||
load="/usr/share/clash/config/sub/config.yaml"
|
||||
elif [ "$load_from" == "upl" ];then
|
||||
load="/usr/share/clash/config/upload/config.yaml"
|
||||
fi
|
||||
|
||||
|
||||
if [ "${create}" -eq 1 ];then
|
||||
@ -15,6 +23,8 @@ if [ "${create}" -eq 1 ];then
|
||||
echo "开始创建自定义配置..." >$REAL_LOG
|
||||
fi
|
||||
sleep 1
|
||||
|
||||
|
||||
CONFIG_YAML_RULE="/usr/share/clash/custom_rule.yaml"
|
||||
SERVER_FILE="/tmp/servers.yaml"
|
||||
CONFIG_YAML="/usr/share/clash/config/custom/config.yaml"
|
||||
@ -26,6 +36,8 @@ CFG_FILE="/etc/config/clash"
|
||||
DNS_FILE="/usr/share/clash/dns.yaml"
|
||||
PROVIDER_FILE="/tmp/yaml_provider.yaml"
|
||||
|
||||
|
||||
|
||||
servcount=$( grep -c "config servers" $CFG_FILE 2>/dev/null)
|
||||
gcount=$( grep -c "config groups" $CFG_FILE 2>/dev/null)
|
||||
if [ $servcount -eq 0 ] || [ $gcount -eq 0 ];then
|
||||
@ -51,13 +63,19 @@ yml_proxy_provider_set()
|
||||
config_get "type" "$section" "type" ""
|
||||
config_get "name" "$section" "name" ""
|
||||
config_get "path" "$section" "path" ""
|
||||
config_get "pathh" "$section" "pathh" ""
|
||||
config_get "provider_url" "$section" "provider_url" ""
|
||||
config_get "provider_interval" "$section" "provider_interval" ""
|
||||
config_get "health_check" "$section" "health_check" ""
|
||||
config_get "health_check_url" "$section" "health_check_url" ""
|
||||
config_get "health_check_interval" "$section" "health_check_interval" ""
|
||||
|
||||
|
||||
if [ "$type" == "http" ];then
|
||||
ppath="path: $path"
|
||||
elif [ "$type" == "file" ];then
|
||||
ppath="path: $pathh"
|
||||
fi
|
||||
|
||||
|
||||
if [ -z "$type" ]; then
|
||||
return
|
||||
@ -66,26 +84,19 @@ yml_proxy_provider_set()
|
||||
if [ -z "$name" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -z "$path" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
if [ -z "$health_check" ]; then
|
||||
return
|
||||
fi
|
||||
if [ $lang == "en" ] || [ $lang == "auto" ];then
|
||||
echo "Now Reading 【$type】-【$name】 Proxy Provider ..." >$REAL_LOG
|
||||
elif [ $lang == "zh_cn" ];then
|
||||
echo "正在写入【$type】-【$name】代理集到配置文件【$CONFIG_NAME】..." >$REAL_LOG
|
||||
fi
|
||||
|
||||
|
||||
echo "$name" >> /tmp/Proxy_Provider
|
||||
|
||||
cat >> "$PROVIDER_FILE" <<-EOF
|
||||
$name:
|
||||
type: $type
|
||||
path: $path
|
||||
$ppath
|
||||
EOF
|
||||
if [ ! -z "$provider_url" ]; then
|
||||
cat >> "$PROVIDER_FILE" <<-EOF
|
||||
@ -457,8 +468,8 @@ yml_groups_set()
|
||||
fi
|
||||
|
||||
if [ "$name" != "$old_name" ]; then
|
||||
sed -i "s/,${old_name}$/,${name}#d/g" $CONFIG_FILE 2>/dev/null
|
||||
sed -i "s/:${old_name}$/:${name}#d/g" $CONFIG_FILE 2>/dev/null
|
||||
sed -i "s/,${old_name}$/,${name}#d/g" $load 2>/dev/null
|
||||
sed -i "s/:${old_name}$/:${name}#d/g" $load 2>/dev/null
|
||||
sed -i "s/\'${old_name}\'/\'${name}\'/g" $CFG_FILE 2>/dev/null
|
||||
config_load "clash"
|
||||
fi
|
||||
@ -590,12 +601,6 @@ fi
|
||||
|
||||
fi
|
||||
rm -rf $SERVER_FILE
|
||||
rm -rf /tmp/match_servers.list 2>/dev/null
|
||||
rm -rf /tmp/yaml_provider.yaml 2>/dev/null
|
||||
rm -rf /tmp/provider.yaml 2>/dev/null
|
||||
rm -rf /tmp/provider_gen.yaml 2>/dev/null
|
||||
rm -rf /tmp/provider_che.yaml 2>/dev/null
|
||||
rm -rf /tmp/match_provider.list 2>/dev/null
|
||||
|
||||
fi
|
||||
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user