update 2025-09-22 02:22:32

This commit is contained in:
actions-user
2025-09-22 02:22:32 +08:00
parent 1c1f19849a
commit 15511ccfc3
191 changed files with 1367 additions and 24039 deletions

View File

@ -1,96 +0,0 @@
#
# Copyright (C) 2015-2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v3.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=alist
PKG_VERSION:=3.53.0
PKG_WEB_VERSION:=3.53.0
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/AlistGo/alist/tar.gz/v$(PKG_VERSION)?
PKG_HASH:=eb54f08392feac9b313dbf2088fe83f637dd14c350f1d35ee4fa7c5a8f2959a5
PKG_LICENSE:=GPL-3.0
PKG_LICENSE_FILE:=LICENSE
PKG_MAINTAINER:=sbwml <admin@cooluc.com>
define Download/$(PKG_NAME)-web
FILE:=$(PKG_NAME)-web-$(PKG_WEB_VERSION).tar.gz
URL_FILE:=dist.tar.gz
URL:=https://github.com/AlistGo/alist-web/releases/download/$(PKG_WEB_VERSION)/
HASH:=755459065b69ceb353d46c5f51fa79c3ddefacdbd3a08894311190cebe8bb99e
endef
PKG_BUILD_DEPENDS:=golang/host
PKG_BUILD_PARALLEL:=1
PKG_USE_MIPS16:=0
PKG_BUILD_FLAGS:=no-mips16
GO_PKG:=github.com/AlistGo/alist
GO_PKG_LDFLAGS:= \
-X '$(GO_PKG)/v3/internal/conf.BuiltAt=$(shell date '+%Y-%m-%d %H:%M:%S %z')' \
-X '$(GO_PKG)/v3/internal/conf.GoVersion=$(shell $(STAGING_DIR_HOSTPKG)/bin/go version | sed 's/go version //')' \
-X '$(GO_PKG)/v3/internal/conf.GitAuthor=Xhofe <i@nn.ci>' \
-X '$(GO_PKG)/v3/internal/conf.GitCommit=tarball/$(shell echo $(PKG_HASH) | cut -c 1-7)' \
-X '$(GO_PKG)/v3/internal/conf.Version=v$(PKG_VERSION) (OpenWrt $(ARCH_PACKAGES))' \
-X '$(GO_PKG)/v3/internal/conf.WebVersion=$(PKG_WEB_VERSION)'
include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
define Package/$(PKG_NAME)
SECTION:=net
CATEGORY:=Network
SUBMENU:=Web Servers/Proxies
TITLE:=A file list program that supports multiple storage
URL:=https://alist.nn.ci/
DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle
endef
define Package/$(PKG_NAME)/conffiles
/etc/alist
/etc/config/alist
endef
define Package/$(PKG_NAME)/description
A file list program that supports multiple storage, powered by Gin and Solidjs.
endef
ifeq ($(ARCH),arm)
ARM_CPU_FEATURES:=$(word 2,$(subst +,$(space),$(call qstrip,$(CONFIG_CPU_TYPE))))
ifeq ($(ARM_CPU_FEATURES),)
TARGET_CFLAGS:=
TARGET_LDFLAGS:=
endif
endif
ifneq ($(CONFIG_USE_MUSL),)
TARGET_CFLAGS += -D_LARGEFILE64_SOURCE
endif
define Build/Prepare
$(call Build/Prepare/Default)
$(TAR) --strip-components=1 -C $(PKG_BUILD_DIR)/public/dist -xzf $(DL_DIR)/$(PKG_NAME)-web-$(PKG_WEB_VERSION).tar.gz
$(SED) 's_https://jsd.nn.ci/gh/alist-org/logo@main/logo.png_/assets/logo.png_g' $(PKG_BUILD_DIR)/public/dist/index.html
ifneq ($(CONFIG_ARCH_64BIT),y)
$(RM) -rf $(PKG_BUILD_DIR)/drivers/{lark,lark.go}
endif
endef
define Package/$(PKG_NAME)/install
$(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR))
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/alist $(1)/usr/bin
$(INSTALL_DIR) $(1)/etc/config $(1)/etc/init.d $(1)/etc/alist
$(INSTALL_CONF) $(CURDIR)/files/alist.config $(1)/etc/config/alist
$(INSTALL_BIN) $(CURDIR)/files/alist.init $(1)/etc/init.d/alist
$(INSTALL_DATA) $(CURDIR)/files/data.db $(1)/etc/alist/data.db
endef
$(eval $(call Download,$(PKG_NAME)-web))
$(eval $(call BuildPackage,$(PKG_NAME)))

View File

@ -1,10 +0,0 @@
<svg width="1252" height="1252" xmlns="http://www.w3.org/2000/svg" version="1.1">
<g>
<g id="#70c6beff">
<path id="svg_2" d="m634.37,138.38c11.88,-1.36 24.25,1.3 34.18,8.09c14.96,9.66 25.55,24.41 34.49,39.51c40.59,68.03 81.45,135.91 122.02,203.96c54.02,90.99 108.06,181.97 161.94,273.06c37.28,63 74.65,125.96 112.18,188.82c24.72,41.99 50.21,83.54 73.84,126.16c10.18,17.84 15.77,38.44 14.93,59.03c-0.59,15.92 -3.48,32.28 -11.84,46.08c-11.73,19.46 -31.39,33.2 -52.71,40.36c-11.37,4.09 -23.3,6.87 -35.43,6.89c-132.32,-0.05 -264.64,0.04 -396.95,0.03c-11.38,-0.29 -22.95,-1.6 -33.63,-5.72c-7.81,-3.33 -15.5,-7.43 -21.61,-13.42c-10.43,-10.32 -17.19,-24.96 -15.38,-39.83c0.94,-10.39 3.48,-20.64 7.76,-30.16c4.15,-9.77 9.99,-18.67 15.06,-27.97c22.13,-39.47 45.31,-78.35 69.42,-116.65c7.72,-12.05 14.44,-25.07 25.12,-34.87c11.35,-10.39 25.6,-18.54 41.21,-19.6c12.55,-0.52 24.89,3.82 35.35,10.55c11.8,6.92 21.09,18.44 24.2,31.88c4.49,17.01 -0.34,34.88 -7.55,50.42c-8.09,17.65 -19.62,33.67 -25.81,52.18c-1.13,4.21 -2.66,9.52 0.48,13.23c3.19,3 7.62,4.18 11.77,5.22c12,2.67 24.38,1.98 36.59,2.06c45,-0.01 90,0 135,0c8.91,-0.15 17.83,0.3 26.74,-0.22c6.43,-0.74 13.44,-1.79 18.44,-6.28c3.3,-2.92 3.71,-7.85 2.46,-11.85c-2.74,-8.86 -7.46,-16.93 -12.12,-24.89c-119.99,-204.91 -239.31,-410.22 -360.56,-614.4c-3.96,-6.56 -7.36,-13.68 -13.03,-18.98c-2.8,-2.69 -6.95,-4.22 -10.77,-3.11c-3.25,1.17 -5.45,4.03 -7.61,6.57c-5.34,6.81 -10.12,14.06 -14.51,21.52c-20.89,33.95 -40.88,68.44 -61.35,102.64c-117.9,198.43 -235.82,396.85 -353.71,595.29c-7.31,13.46 -15.09,26.67 -23.57,39.43c-7.45,10.96 -16.49,21.23 -28.14,27.83c-13.73,7.94 -30.69,11.09 -46.08,6.54c-11.23,-3.47 -22.09,-9.12 -30.13,-17.84c-10.18,-10.08 -14.69,-24.83 -14.17,-38.94c0.52,-14.86 5.49,-29.34 12.98,-42.1c71.58,-121.59 143.62,-242.92 215.93,-364.09c37.2,-62.8 74.23,-125.69 111.64,-188.36c37.84,-63.5 75.77,-126.94 113.44,-190.54c21.02,-35.82 42.19,-71.56 64.28,-106.74c6.79,-11.15 15.58,-21.15 26.16,-28.85c8.68,-5.92 18.42,-11 29.05,-11.94z" fill="#70c6be"/>
</g>
<g id="#1ba0d8ff">
<path id="svg_3" d="m628.35,608.38c17.83,-2.87 36.72,1.39 51.5,11.78c11.22,8.66 19.01,21.64 21.26,35.65c1.53,10.68 0.49,21.75 -3.44,31.84c-3.02,8.73 -7.35,16.94 -12.17,24.81c-68.76,115.58 -137.5,231.17 -206.27,346.75c-8.8,14.47 -16.82,29.47 -26.96,43.07c-7.37,9.11 -16.58,16.85 -27.21,21.89c-22.47,11.97 -51.79,4.67 -68.88,-13.33c-8.66,-8.69 -13.74,-20.63 -14.4,-32.84c-0.98,-12.64 1.81,-25.42 7.53,-36.69c5.03,-10.96 10.98,-21.45 17.19,-31.77c30.22,-50.84 60.17,-101.84 90.3,-152.73c41.24,-69.98 83.16,-139.55 124.66,-209.37c4.41,-7.94 9.91,-15.26 16.09,-21.9c8.33,-8.46 18.9,-15.3 30.8,-17.16z" fill="#1ba0d8"/>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -1,25 +0,0 @@
# Copyright (C) 2016 Openwrt.org
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-alist
PKG_VERSION:=1.0.13
PKG_RELEASE:=1
LUCI_TITLE:=LuCI support for alist
LUCI_DEPENDS:=+alist +luci-compat
define Package/$(PKG_NAME)/postinst
#!/bin/sh
[ -n "${IPKG_INSTROOT}" ] || {
( . /etc/uci-defaults/50-luci-alist ) && rm -f /etc/uci-defaults/50-luci-alist
exit 0
}
endef
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -1,50 +0,0 @@
module("luci.controller.alist", package.seeall)
function index()
if not nixio.fs.access("/etc/config/alist") then
return
end
local page = entry({"admin", "nas", "alist"}, alias("admin", "nas", "alist", "basic"), _("Alist"), 20)
page.dependent = true
page.acl_depends = { "luci-app-alist" }
entry({"admin", "nas"}, firstchild(), "NAS", 44).dependent = false
entry({"admin", "nas", "alist", "basic"}, cbi("alist/basic"), _("Basic Setting"), 1).leaf = true
entry({"admin", "nas", "alist", "log"}, cbi("alist/log"), _("Logs"), 2).leaf = true
entry({"admin", "nas", "alist", "alist_status"}, call("alist_status")).leaf = true
entry({"admin", "nas", "alist", "get_log"}, call("get_log")).leaf = true
entry({"admin", "nas", "alist", "clear_log"}, call("clear_log")).leaf = true
entry({"admin", "nas", "alist", "admin_info"}, call("admin_info")).leaf = true
end
function alist_status()
local sys = require "luci.sys"
local uci = require "luci.model.uci".cursor()
local port = tonumber(uci:get_first("alist", "alist", "port"))
local status = {
running = (sys.call("pidof alist >/dev/null") == 0),
port = (port or 5244)
}
luci.http.prepare_content("application/json")
luci.http.write_json(status)
end
function get_log()
luci.http.write(luci.sys.exec("cat /var/log/alist.log"))
end
function clear_log()
luci.sys.call("cat /dev/null > /var/log/alist.log")
end
function admin_info()
local random = luci.sys.exec("/usr/bin/alist --data $(uci -q get alist.@alist[0].data_dir) admin random 2>&1")
local username = string.match(random, "username: (%S+)")
local password = string.match(random, "password: (%S+)")
luci.http.prepare_content("application/json")
luci.http.write_json({username = username, password = password})
end

View File

@ -1,113 +0,0 @@
local m, s
m = Map("alist", translate("Alist"), translate("A file list program that supports multiple storage.") .. "<br/>" .. [[<a href="https://alist.nn.ci/zh/guide/drivers/local.html" target="_blank">]] .. translate("User Manual") .. [[</a>]])
m:section(SimpleSection).template = "alist/alist_status"
s = m:section(TypedSection, "alist")
s.addremove = false
s.anonymous = true
o = s:option(Flag, "enabled", translate("Enabled"))
o.rmempty = false
o = s:option(Value, "port", translate("Port"))
o.datatype = "and(port,min(1))"
o.rmempty = false
o.default = "5244"
o = s:option(Flag, "log", translate("Enable Logs"))
o.default = 1
o.rmempty = false
o = s:option(Flag, "ssl", translate("Enable SSL"))
o.rmempty=false
o = s:option(Value,"ssl_cert", translate("SSL cert"), translate("SSL certificate file path"))
o.datatype = "file"
o:depends("ssl", "1")
o = s:option(Value,"ssl_key", translate("SSL key"), translate("SSL key file path"))
o.datatype = "file"
o:depends("ssl", "1")
o = s:option(Flag, "mysql", translate("Enable Database"))
o.rmempty=false
o = s:option(ListValue, "mysql_type", translate("Database Type"))
o.datatype = "string"
o:value("mysql", translate("MySQL"))
o:value("postgres", translate("PostgreSQL"))
o.default = "mysql"
o:depends("mysql", "1")
o = s:option(Value,"mysql_host", translate("Database Host"))
o.datatype = "string"
o:depends("mysql", "1")
o = s:option(Value,"mysql_port", translate("Database Port"))
o.datatype = "and(port,min(1))"
o.default = "3306"
o:depends("mysql", "1")
o = s:option(Value,"mysql_username", translate("Database Username"))
o.datatype = "string"
o:depends("mysql", "1")
o = s:option(Value,"mysql_password", translate("Database Password"))
o.datatype = "string"
o.password = true
o:depends("mysql", "1")
o = s:option(Value,"mysql_database", translate("Database Name"))
o.datatype = "string"
o:depends("mysql", "1")
o = s:option(Value,"mysql_table_prefix", translate("Database Table Prefix"))
o.datatype = "string"
o.default = "x_"
o:depends("mysql", "1")
o = s:option(Value,"mysql_ssl_mode", translate("Database SSL Mode"))
o.datatype = "string"
o:depends("mysql", "1")
o = s:option(Value,"mysql_dsn", translate("Database DSN"))
o.datatype = "string"
o:depends("mysql", "1")
o = s:option(Flag, "allow_wan", translate("Allow Access From Internet"))
o.rmempty = false
o = s:option(Value, "site_url", translate("Site URL"), translate("When the web is reverse proxied to a subdirectory, this option must be filled out to ensure proper functioning of the web. Do not include '/' at the end of the URL"))
o.datatype = "string"
o = s:option(Value, "max_connections", translate("Max Connections"), translate("0 is unlimited, It is recommend to set a low number of concurrency (10-20) for poor performance device"))
o.datatype = "and(uinteger,min(0))"
o.default = "0"
o.rmempty = false
o = s:option(Value, "token_expires_in", translate("Login Validity Period (hours)"))
o.datatype = "and(uinteger,min(1))"
o.default = "48"
o.rmempty = false
o = s:option(Value, "delayed_start", translate("Delayed Start (seconds)"))
o.datatype = "and(uinteger,min(0))"
o.default = "0"
o.rmempty = false
o = s:option(Value, "data_dir", translate("Data directory"))
o.datatype = "string"
o.default = "/etc/alist"
o = s:option(Value, "temp_dir", translate("Cache directory"))
o.datatype = "string"
o.default = "/tmp/alist"
o.rmempty = false
o = s:option(Button, "admin_info", translate("Reset Password"))
o.rawhtml = true
o.template = "alist/admin_info"
return m

View File

@ -1,5 +0,0 @@
m = Map("alist")
m:append(Template("alist/alist_log"))
return m

View File

@ -1,26 +0,0 @@
<%+cbi/valueheader%>
<script type="text/javascript">//<![CDATA[
function admin_info(btn)
{
btn.disabled = true;
btn.value = '<%:Collecting data...%>';
XHR.get('<%=luci.dispatcher.build_url("admin", "nas", "alist", "admin_info")%>',
null,
function(x,rv)
{
var tb = document.getElementById('<%=self.option%>-status');
if (tb)
{
tb.innerHTML = "<%:Username:%>" + "<font color='green'>" + rv.username + "</font>";
tb.innerHTML += "<%:Password:%>" + "<font color='green'>" + rv.password + "</font>";
}
btn.disabled = false;
btn.value = '<%:Reset%>';
}
);
return false;
}
//]]></script>
<input type="button" class="btn cbi-button cbi-button-apply" value="<%:Reset%>" onclick="return admin_info(this)" />
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
<%+cbi/valuefooter%>

View File

@ -1,35 +0,0 @@
<script type="text/javascript">
//<![CDATA[
function clear_log(btn) {
XHR.get('<%=url([[admin]], [[nas]], [[alist]], [[clear_log]])%>', null,
function(x, data) {
if(x && x.status == 200) {
var log_textarea = document.getElementById('log_textarea');
log_textarea.innerHTML = "";
log_textarea.scrollTop = log_textarea.scrollHeight;
}
location.reload();
}
);
}
var scrolled = false;
XHR.poll(2, '<%=url([[admin]], [[nas]], [[alist]], [[get_log]])%>', null,
function(x, data) {
if(x && x.status == 200) {
var log_textarea = document.getElementById('log_textarea');
var str = x.responseText;
var logs = str.replace(//g, "🔧");
log_textarea.innerHTML = logs;
if (!scrolled) {
log_textarea.scrollTop = log_textarea.scrollHeight;
scrolled = true;
}
}
}
);
//]]>
</script>
<fieldset class="cbi-section" id="_log_fieldset">
<input class="cbi-button cbi-input-remove" type="button" onclick="clear_log()" value="<%:Clear logs%>" style="margin-left: 10px; margin-top: 10px;">
<textarea id="log_textarea" class="cbi-input-textarea" style="width: calc(100% - 20px); height: 500px; margin: 10px;" data-update="change" rows="5" wrap="off" readonly="readonly"></textarea>
</fieldset>

View File

@ -1,36 +0,0 @@
<%
local uci = require 'luci.model.uci'.cursor()
ssl = uci:get_first('alist', 'alist', 'ssl')
if ssl == '1' then
protocol="https://"
else
protocol="http://"
end
%>
<script type="text/javascript">//<![CDATA[
XHR.poll(5, '<%=url("admin/nas/alist/alist_status")%>', null,
function(x, st)
{
var tb = document.getElementById('alist_status');
if (st && tb)
{
if (st.running)
{
tb.innerHTML = '<em style=\"color:green\"><b>Alist <%:RUNNING%></b></em>' + "<input class=\"cbi-button cbi-button-reload mar-10\" type=\"button\" value=\" <%:Open Web Interface%> \" onclick=\"window.open('<%=protocol%>" + window.location.hostname + ":" + st.port + "/')\"/>";
}
else
{
tb.innerHTML = '<em style=\"color:red\"><b>Alist <%:NOT RUNNING%></b></em>';
}
}
}
);
//]]></script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="alist_status">
<em><b><%:Collecting data...%></b></em>
</p>
</fieldset>

View File

@ -1,126 +0,0 @@
msgid "Alist"
msgstr "Alist 文件列表"
msgid "Open Web Interface"
msgstr "打开 Web 界面"
msgid "A file list program that supports multiple storage."
msgstr "一款支持多种存储的目录文件列表程序。"
msgid "Basic Setting"
msgstr "基本设置"
msgid "Logs"
msgstr "日志"
msgid "Enabled"
msgstr "启用"
msgid "Port"
msgstr "端口"
msgid "Enable SSL"
msgstr "启用 SSL"
msgid "SSL cert"
msgstr "SSL 证书"
msgid "SSL certificate file path"
msgstr "SSL 证书文件路径"
msgid "SSL key"
msgstr "SSL 密钥"
msgid "SSL key file path"
msgstr "SSL 密钥文件路径"
msgid "Data directory"
msgstr "数据目录"
msgid "Cache directory"
msgstr "缓存目录"
msgid "RUNNING"
msgstr "运行中"
msgid "NOT RUNNING"
msgstr "未运行"
msgid "Collecting data..."
msgstr "收集数据..."
msgid "NAS"
msgstr "网络存储"
msgid "User Manual"
msgstr "用户手册"
msgid "Allow Access From Internet"
msgstr "允许从外网访问"
msgid "Enable Logs"
msgstr "启用日志"
msgid "Clear logs"
msgstr "清空日志"
msgid "Reset Password"
msgstr "重置密码"
msgid "Reset"
msgstr "重置"
msgid "Username:"
msgstr "用户名:"
msgid "Password:"
msgstr "密码:"
msgid "Login Validity Period (hours)"
msgstr "登录有效期(小时)"
msgid "Max Connections"
msgstr "最大并发连接数"
msgid "0 is unlimited, It is recommend to set a low number of concurrency (10-20) for poor performance device"
msgstr "默认0不限制低性能设备建议设置较低的并发数10-20"
msgid "Site URL"
msgstr "站点 URL"
msgid "When the web is reverse proxied to a subdirectory, this option must be filled out to ensure proper functioning of the web. Do not include '/' at the end of the URL"
msgstr "Web 被反向代理到二级目录时,必须填写该选项以确保 Web 正常工作。URL 结尾请勿携带 '/'"
msgid "Delayed Start (seconds)"
msgstr "开机延时启动(秒)"
msgid "Enable Database"
msgstr "启用远程数据库"
msgid "Database Type"
msgstr "类型"
msgid "Database Host"
msgstr "主机"
msgid "Database Port"
msgstr "端口"
msgid "Database Username"
msgstr "用户名"
msgid "Database Password"
msgstr "密码"
msgid "Database Name"
msgstr "数据库名"
msgid "Database Table Prefix"
msgstr "数据库表前缀"
msgid "Database SSL Mode"
msgstr "SSL模式"
msgid "Database DSN"
msgstr "DSN"

View File

@ -1,11 +0,0 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@alist[-1]
add ucitrack alist
set ucitrack.@alist[-1].init=alist
commit ucitrack
EOF
rm -rf /tmp/luci-*
exit 0

View File

@ -1,11 +0,0 @@
{
"luci-app-alist": {
"description": "Grant UCI access for luci-app-alist",
"read": {
"uci": [ "alist" ]
},
"write": {
"uci": [ "alist" ]
}
}
}

View File

@ -1,165 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@ -1,170 +0,0 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-clash
PKG_VERSION:=v1.8.0
PKG_MAINTAINER:=frainzy1477
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=3. Applications
TITLE:=LuCI app for clash
DEPENDS:=+luci-base +wget +iptables +coreutils-base64 +coreutils +coreutils-nohup +bash +ipset +libustream-openssl +curl +jsonfilter +ca-bundle +iptables-mod-tproxy +kmod-tun
PKGARCH:=all
MAINTAINER:=frainzy1477
endef
define Package/$(PKG_NAME)/description
Luci Interface for clash.
endef
define Build/Prepare
po2lmo ${CURDIR}/po/zh-cn/clash.po ${CURDIR}/po/zh-cn/clash.zh-cn.lmo
endef
define Build/Configure
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
/etc/init.d/clash disable 2>/dev/null
if [ -z "$${IPKG_INSTROOT}" ]; then
rm -rf /tmp/dnsmasq.d/custom_list.conf 2>/dev/null
rm -rf /tmp/dnsmasq.clash 2>/dev/null
mv /etc/config/clash /etc/config/clash.bak 2>/dev/null
rm -rf /usr/lib/lua/luci/model/cbi/clash 2>/dev/null
rm -rf /usr/lib/lua/luci/view/clash 2>/dev/null
rm -rf /usr/share/clash/new_core_version 2>/dev/null
rm -rf /usr/share/clash/new_clashr_core_version 2>/dev/null
rm -rf /usr/share/clash/new_luci_version 2>/dev/null
rm -rf /usr/share/clash/web 2>/dev/null
mv /etc/clash/config/sub/config.yaml /etc/clash/clashbackup/config.bak1 2>/dev/null
mv /etc/clash/config/upload/config.yaml /etc/clash/clashbackup/config.bak2 2>/dev/null
mv /etc/clash/config/custom/config.yaml /etc/clash/clashbackup/config.bak3 2>/dev/null
mv /usr/share/clash/rule.yaml /etc/clash/clashbackup/rule.bak 2>/dev/null
fi
exit 0
endef
define Package/$(PKG_NAME)/postinst
#!/bin/sh
if [ -z "$${IPKG_INSTROOT}" ]; then
rm -rf /tmp/luci*
mv /etc/config/clash.bak /etc/config/clash 2>/dev/null
mv /etc/clash/clashbackup/config.bak1 /etc/clash/config/sub/config.yaml 2>/dev/null
mv /etc/clash/clashbackup/config.bak2 /etc/clash/config/upload/config.yaml 2>/dev/null
mv /etc/clash/clashbackup/config.bak3 /etc/clash/config/custom/config.yaml 2>/dev/null
mv /etc/clash/clashbackup/rule.bak /usr/share/clash/rule.yaml 2>/dev/null
/etc/init.d/clash disable 2>/dev/null
fi
/etc/init.d/clash disable 2>/dev/null
exit 0
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/model/cbi/clash/config
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/clash/dns
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/clash/client
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/clash/game
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/clash/geoip
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/clash/logs
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/clash/update
$(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)/usr/lib/lua/luci
$(INSTALL_DIR) $(1)/usr/share/
$(INSTALL_DIR) $(1)/usr/share/clash
$(INSTALL_DIR) $(1)/usr/share/rpcd
$(INSTALL_DIR) $(1)/usr/share/rpcd/acl.d
$(INSTALL_DIR) $(1)/usr/share/clash/rules
$(INSTALL_DIR) $(1)/usr/share/clash/rules/g_rules
$(INSTALL_DIR) $(1)/etc/clash/dashboard
$(INSTALL_DIR) $(1)/usr/share/clash/yacd
$(INSTALL_DIR) $(1)/etc/clash/clashtun
$(INSTALL_DIR) $(1)/etc/clash/dtun
$(INSTALL_DIR) $(1)/etc/clash/clashbackup
$(INSTALL_DIR) $(1)/usr/share/clash/create
$(INSTALL_DIR) $(1)/etc/clash/provider
$(INSTALL_DIR) $(1)/etc/clash/proxyprovider
$(INSTALL_DIR) $(1)/etc/clash/ruleprovider
$(INSTALL_DIR) $(1)/etc/clash/config
$(INSTALL_DIR) $(1)/etc/clash/config/sub
$(INSTALL_DIR) $(1)/etc/clash/config/upload
$(INSTALL_DIR) $(1)/etc/clash/config/custom
$(INSTALL_BIN) ./root/etc/init.d/clash $(1)/etc/init.d/clash
$(INSTALL_CONF) ./root/etc/config/clash $(1)/etc/config/clash
$(INSTALL_CONF) ./root/etc/clash/Country.mmdb $(1)/etc/clash
$(INSTALL_BIN) ./root/usr/share/clash/create/* $(1)/usr/share/clash/create
$(INSTALL_BIN) ./root/usr/share/clash/*.sh $(1)/usr/share/clash
$(INSTALL_BIN) ./root/usr/share/rpcd/acl.d/luci-app-clash.json $(1)/usr/share/rpcd/acl.d
$(INSTALL_BIN) ./root/usr/share/clash/rules/g_rules/Steam.rules $(1)/usr/share/clash/rules/g_rules
$(INSTALL_BIN) ./root//usr/share/clash/rules/rules.list $(1)/usr/share/clash/rules
$(INSTALL_BIN) ./root/usr/share/clash/luci_version $(1)/usr/share/clash
$(INSTALL_BIN) ./root/usr/share/clash/rule.yaml $(1)/usr/share/clash
$(INSTALL_BIN) ./root/usr/share/clash/server.list $(1)/usr/share/clash
$(INSTALL_BIN) ./root/usr/share/clash/clash_real.txt $(1)/usr/share/clash
$(INSTALL_BIN) ./root/usr/share/clash/logstatus_check $(1)/usr/share/clash
$(INSTALL_BIN) ./root/usr/share/clash/clash.txt $(1)/usr/share/clash
$(INSTALL_BIN) ./root/usr/share/clash/chinaipset.sh $(1)/usr/share/clash
$(INSTALL_BIN) ./root/usr/share/clash/china_ip.txt $(1)/usr/share/clash
$(CP) ./root/usr/share/clash/dashboard/* $(1)/etc/clash/dashboard
$(CP) ./root/usr/share/clash/yacd/* $(1)/usr/share/clash/yacd
chmod -R 755 $(1)/etc/clash/dashboard
chmod -R 755 $(1)/usr/share/clash/yacd
$(INSTALL_DATA) ./luasrc/clash.lua $(1)/usr/lib/lua/luci
$(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/model/cbi/clash/config/*.lua $(1)/usr/lib/lua/luci/model/cbi/clash/config
$(INSTALL_DATA) ./luasrc/model/cbi/clash/client/*.lua $(1)/usr/lib/lua/luci/model/cbi/clash/client
$(INSTALL_DATA) ./luasrc/model/cbi/clash/dns/*.lua $(1)/usr/lib/lua/luci/model/cbi/clash/dns
$(INSTALL_DATA) ./luasrc/model/cbi/clash/game/*.lua $(1)/usr/lib/lua/luci/model/cbi/clash/game
$(INSTALL_DATA) ./luasrc/model/cbi/clash/geoip/*.lua $(1)/usr/lib/lua/luci/model/cbi/clash/geoip
$(INSTALL_DATA) ./luasrc/model/cbi/clash/logs/*.lua $(1)/usr/lib/lua/luci/model/cbi/clash/logs
$(INSTALL_DATA) ./luasrc/model/cbi/clash/update/*.lua $(1)/usr/lib/lua/luci/model/cbi/clash/update
$(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
$(eval $(call BuildPackage,$(PKG_NAME)))

View File

@ -1,10 +0,0 @@
<h2 align="center">
<img src="https://cdn.jsdelivr.net/gh/Dreamacro/clash/docs/logo.png" alt="Clash" width="200">
<br>Luci App For Clash <br>
</h2>
<p align="center">
A rule based custom proxy client for Openwrt based on <a href="https://github.com/Dreamacro/clash" target="_blank">Clash</a>.
</p>
## License
Luci App For Clash - OpenWrt is released under the GPL v3.0 License - see detailed [LICENSE](https://github.com/frainzy1477/luci-app-clash/blob/master/LICENSE) .

View File

@ -1,244 +0,0 @@
--[[
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 io = require "io"
local os = require "os"
local ltn12 = require "luci.ltn12"
local fs = require "nixio.fs"
local nutil = require "nixio.util"
local type = type
--- LuCI filesystem library.
module "luci.clash"
--- Test for file access permission on given path.
-- @class function
-- @name access
-- @param str String value containing the path
-- @return Number containing the return code, 0 on sucess or nil on error
-- @return String containing the error description (if any)
-- @return Number containing the os specific errno (if any)
access = fs.access
--- Evaluate given shell glob pattern and return a table containing all matching
-- file and directory entries.
-- @class function
-- @name glob
-- @param filename String containing the path of the file to read
-- @return Table containing file and directory entries or nil if no matches
-- @return String containing the error description (if no matches)
-- @return Number containing the os specific errno (if no matches)
function glob(...)
local iter, code, msg = fs.glob(...)
if iter then
return nutil.consume(iter)
else
return nil, code, msg
end
end
--- Checks wheather the given path exists and points to a regular file.
-- @param filename String containing the path of the file to test
-- @return Boolean indicating wheather given path points to regular file
function isfile(filename)
return fs.stat(filename, "type") == "reg"
end
--- 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
function isdirectory(dirname)
return fs.stat(dirname, "type") == "dir"
end
--- Read the whole content of the given file into memory.
-- @param filename String containing the path of the file to read
-- @return String containing the file contents or nil on error
-- @return String containing the error message on error
readfile = fs.readfile
--- Write the contents of given string to given file.
-- @param filename String containing the path of the file to read
-- @param data String containing the data to write
-- @return Boolean containing true on success or nil on error
-- @return String containing the error message on error
writefile = fs.writefile
--- Copies a file.
-- @param source Source file
-- @param dest Destination
-- @return Boolean containing true on success or nil on error
copy = fs.datacopy
--- Renames a file.
-- @param source Source file
-- @param dest Destination
-- @return Boolean containing true on success or nil on error
rename = fs.move
--- Get the last modification time of given file path in Unix epoch format.
-- @param path String containing the path of the file or directory to read
-- @return Number containing the epoch time or nil on error
-- @return String containing the error description (if any)
-- @return Number containing the os specific errno (if any)
function mtime(path)
return fs.stat(path, "mtime")
end
--- Set the last modification time of given file path in Unix epoch format.
-- @param path String containing the path of the file or directory to read
-- @param mtime Last modification timestamp
-- @param atime Last accessed timestamp
-- @return 0 in case of success nil on error
-- @return String containing the error description (if any)
-- @return Number containing the os specific errno (if any)
function utime(path, mtime, atime)
return fs.utimes(path, atime, mtime)
end
--- Return the last element - usually the filename - from the given path with
-- the directory component stripped.
-- @class function
-- @name basename
-- @param path String containing the path to strip
-- @return String containing the base name of given path
-- @see dirname
basename = fs.basename
--- Return the directory component of the given path with the last element
-- stripped of.
-- @class function
-- @name dirname
-- @param path String containing the path to strip
-- @return String containing the directory component of given path
-- @see basename
dirname = fs.dirname
--- Return a table containing all entries of the specified directory.
-- @class function
-- @name dir
-- @param path String containing the path of the directory to scan
-- @return Table containing file and directory entries or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
function dir(...)
local iter, code, msg = fs.dir(...)
if iter then
local t = nutil.consume(iter)
t[#t+1] = "."
t[#t+1] = ".."
return t
else
return nil, code, msg
end
end
--- Create a new directory, recursively on demand.
-- @param path String with the name or path of the directory to create
-- @param recursive Create multiple directory levels (optional, default is true)
-- @return Number with the return code, 0 on sucess or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
function mkdir(path, recursive)
return recursive and fs.mkdirr(path) or fs.mkdir(path)
end
--- Remove the given empty directory.
-- @class function
-- @name rmdir
-- @param path String containing the path of the directory to remove
-- @return Number with the return code, 0 on sucess or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
rmdir = fs.rmdir
local stat_tr = {
reg = "regular",
dir = "directory",
lnk = "link",
chr = "character device",
blk = "block device",
fifo = "fifo",
sock = "socket"
}
--- Get information about given file or directory.
-- @class function
-- @name stat
-- @param path String containing the path of the directory to query
-- @return Table containing file or directory properties or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
function stat(path, key)
local data, code, msg = fs.stat(path)
if data then
data.mode = data.modestr
data.type = stat_tr[data.type] or "?"
end
return key and data and data[key] or data, code, msg
end
--- Set permissions on given file or directory.
-- @class function
-- @name chmod
-- @param path String containing the path of the directory
-- @param perm String containing the permissions to set ([ugoa][+-][rwx])
-- @return Number with the return code, 0 on sucess or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
chmod = fs.chmod
--- Create a hard- or symlink from given file (or directory) to specified target
-- file (or directory) path.
-- @class function
-- @name link
-- @param path1 String containing the source path to link
-- @param path2 String containing the destination path for the link
-- @param symlink Boolean indicating wheather to create a symlink (optional)
-- @return Number with the return code, 0 on sucess or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
function link(src, dest, sym)
return sym and fs.symlink(src, dest) or fs.link(src, dest)
end
--- Remove the given file.
-- @class function
-- @name unlink
-- @param path String containing the path of the file to remove
-- @return Number with the return code, 0 on sucess or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
unlink = fs.unlink
--- Retrieve target of given symlink.
-- @class function
-- @name readlink
-- @param path String containing the path of the symlink to read
-- @return String containing the link target or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
readlink = fs.readlink

View File

@ -1,442 +0,0 @@
module("luci.controller.clash", package.seeall)
local fs=require"nixio.fs"
local http=require"luci.http"
local uci=require"luci.model.uci".cursor()
function index()
if not nixio.fs.access("/etc/config/clash") then
return
end
local page = entry({"admin", "services", "clash"},alias("admin", "services", "clash", "overview"), _("Clash"), 1)
page.dependent = true
page.acl_depends = {"luci-app-clash"}
entry({"admin", "services", "clash", "overview"},cbi("clash/overview"),_("Overview"), 10).leaf = true
entry({"admin", "services", "clash", "client"},cbi("clash/client/client"),_("Client"), 20).leaf = true
entry({"admin", "services", "clash", "config"}, firstchild(),_("Config"), 25)
entry({"admin", "services", "clash", "config", "import"},cbi("clash/config/import"),_("Import Config"), 25).leaf = true
entry({"admin", "services", "clash", "config", "config"},cbi("clash/config/config"),_("Select Config"), 30).leaf = true
entry({"admin", "services", "clash", "config", "create"},cbi("clash/config/create"),_("Create Config"), 35).leaf = true
entry({"admin", "services", "clash", "proxyprovider"},cbi("clash/config/proxy_provider"), nil).leaf = true
entry({"admin", "services", "clash", "servers"},cbi("clash/config/servers-config"), nil).leaf = true
entry({"admin", "services", "clash", "ruleprovider"},cbi("clash/config/rule_provider"), nil).leaf = true
entry({"admin", "services", "clash", "rules"},cbi("clash/config/rules"), nil).leaf = true
entry({"admin", "services", "clash", "pgroups"},cbi("clash/config/groups"), nil).leaf = true
entry({"admin", "services", "clash", "rulemanager"},cbi("clash/config/ruleprovider_manager"), nil).leaf = true
entry({"admin", "services", "clash", "settings"}, firstchild(),_("Settings"), 40)
entry({"admin", "services", "clash", "settings", "port"},cbi("clash/dns/port"),_("Proxy Ports"), 60).leaf = true
entry({"admin", "services", "clash", "settings", "geoip"},cbi("clash/geoip/geoip"),_("Update GeoIP"), 80).leaf = true
entry({"admin", "services", "clash", "settings", "grules"},cbi("clash/game/game-settings"),_("Game Rules"), 91).dependent = false
entry({"admin", "services", "clash", "g-rules"},cbi("clash/game/game-rule"), nil).leaf = true
entry({"admin", "services", "clash", "settings", "other"},cbi("clash/other"),_("Other Settings"), 92).leaf = true
entry({"admin", "services", "clash", "ip-rules"},cbi("clash/config/ip-rules"), nil).leaf = true
entry({"admin", "services", "clash", "settings", "dns"},firstchild(),_("DNS Settings"), 65)
entry({"admin", "services", "clash", "settings", "dns", "dns"},cbi("clash/dns/dns"),_("Clash DNS"), 70).leaf = true
entry({"admin", "services", "clash", "settings", "dns", "advance"},cbi("clash/dns/advance"),_("Advance DNS"), 75).leaf = true
entry({"admin", "services", "clash", "update"},cbi("clash/update/update"),_("Update"), 45).leaf = true
entry({"admin", "services", "clash", "log"},cbi("clash/logs/log"),_("Log"), 50).leaf = true
entry({"admin","services","clash","check_status"},call("check_status")).leaf=true
entry({"admin", "services", "clash", "ping"}, call("act_ping")).leaf=true
entry({"admin", "services", "clash", "readlog"},call("action_read")).leaf=true
entry({"admin","services","clash", "status"},call("action_status")).leaf=true
entry({"admin", "services", "clash", "check"}, call("check_update_log")).leaf=true
entry({"admin", "services", "clash", "doupdate"}, call("do_update")).leaf=true
entry({"admin", "services", "clash", "start"}, call("do_start")).leaf=true
entry({"admin", "services", "clash", "stop"}, call("do_stop")).leaf=true
entry({"admin", "services", "clash", "reload"}, call("do_reload")).leaf=true
entry({"admin", "services", "clash", "geo"}, call("geoip_check")).leaf=true
entry({"admin", "services", "clash", "geoipupdate"}, call("geoip_update")).leaf=true
entry({"admin", "services", "clash", "check_geoip"}, call("check_geoip_log")).leaf=true
entry({"admin", "services", "clash", "corelog"},call("down_check")).leaf=true
entry({"admin", "services", "clash", "logstatus"},call("logstatus_check")).leaf=true
entry({"admin", "services", "clash", "conf"},call("action_conf")).leaf=true
entry({"admin", "services", "clash", "update_config"},call("action_update")).leaf=true
entry({"admin", "services", "clash", "game_rule"},call("action_update_rule")).leaf=true
entry({"admin", "services", "clash", "ruleproviders"},call("action_update_rule_providers")).leaf=true
entry({"admin", "services", "clash", "ping_check"},call("action_ping_status")).leaf=true
end
local fss = require "luci.clash"
local function download_rule_provider()
local filename = luci.http.formvalue("filename")
local status = luci.sys.call(string.format('/usr/share/clash/create/clash_rule_provider.sh "%s" >/dev/null 2>&1',filename))
return status
end
function action_update_rule_providers()
luci.http.prepare_content("application/json")
luci.http.write_json({
rulep = download_rule_provider();
})
end
local function uhttp_port()
local uhttp_port = luci.sys.exec("uci get uhttpd.main.listen_http |awk -F ':' '{print $NF}'")
if uhttp_port ~= "80" then
return ":" .. uhttp_port
end
end
local function download_rule()
local filename = luci.http.formvalue("filename")
local rule_file_dir="/usr/share/clash/rules/g_rules/" .. filename
luci.sys.call(string.format('sh /usr/share/clash/clash_game_rule.sh "%s" >/dev/null 2>&1',filename))
if not fss.isfile(rule_file_dir) then
return "0"
else
return "1"
end
end
function action_update_rule()
luci.http.prepare_content("application/json")
luci.http.write_json({
game_rule = download_rule()
})
end
function action_update()
luci.sys.exec("kill $(pgrep /usr/share/clash/update.sh) ; (bash /usr/share/clash/update.sh >/usr/share/clash/clash.txt 2>&1) &")
end
local function in_use()
return luci.sys.exec("uci get clash.config.config_type")
end
local function conf_path()
if nixio.fs.access(string.sub(luci.sys.exec("uci get clash.config.use_config"), 1, -2)) then
return fss.basename(string.sub(luci.sys.exec("uci get clash.config.use_config"), 1, -2))
else
return ""
end
end
local function typeconf()
return luci.sys.exec("uci get clash.config.config_type")
end
function action_conf()
luci.http.prepare_content("application/json")
luci.http.write_json({
conf_path = conf_path(),
typeconf = typeconf()
})
end
local function dash_port()
return luci.sys.exec("uci get clash.config.dash_port 2>/dev/null")
end
local function dash_pass()
return luci.sys.exec("uci get clash.config.dash_pass 2>/dev/null")
end
local function is_running()
return luci.sys.call("pidof clash >/dev/null") == 0
end
local function is_web()
return luci.sys.call("pidof clash >/dev/null") == 0
end
local function localip()
return luci.sys.exec("uci get network.lan.ipaddr")
end
local function check_version()
return luci.sys.exec("sh /usr/share/clash/check_luci_version.sh")
end
local function check_core()
return luci.sys.exec("sh /usr/share/clash/check_core_version.sh")
end
local function check_clashtun_core()
return luci.sys.exec("sh /usr/share/clash/check_clashtun_core_version.sh")
end
local function current_version()
return luci.sys.exec("sed -n 1p /usr/share/clash/luci_version")
end
local function new_version()
return luci.sys.exec("sed -n 1p /usr/share/clash/new_luci_version")
end
local function new_core_version()
return luci.sys.exec("sed -n 1p /usr/share/clash/new_core_version")
end
local function new_clashtun_core_version()
return luci.sys.exec("sed -n 1p /usr/share/clash/new_clashtun_core_version")
end
local function check_dtun_core()
return luci.sys.call(string.format("sh /usr/share/clash/check_dtun_core_version.sh"))
end
local function new_dtun_core()
return luci.sys.exec("sed -n 1p /usr/share/clash/new_clashdtun_core_version")
end
local function e_mode()
return luci.sys.exec("egrep '^ {0,}enhanced-mode' /etc/clash/config.yaml |grep enhanced-mode: |awk -F ': ' '{print $2}'")
end
local function clash_core()
if nixio.fs.access("/etc/clash/clash") then
local core=luci.sys.exec("/etc/clash/clash -v 2>/dev/null |awk -F ' ' '{print $2}'")
if core ~= "" then
return luci.sys.exec("/etc/clash/clash -v 2>/dev/null |awk -F ' ' '{print $2}'")
else
return luci.sys.exec("sed -n 1p /usr/share/clash/core_version")
end
else
return "0"
end
end
local function clashtun_core()
if nixio.fs.access("/etc/clash/clashtun/clash") then
local tun=luci.sys.exec("/etc/clash/clashtun/clash -v 2>/dev/null |awk -F ' ' '{print $2}'")
if tun ~= "" then
return luci.sys.exec("/etc/clash/clashtun/clash -v 2>/dev/null |awk -F ' ' '{print $2}'")
else
return luci.sys.exec("sed -n 1p /usr/share/clash/tun_version")
end
else
return "0"
end
end
local function dtun_core()
if nixio.fs.access("/etc/clash/dtun/clash") then
local tun=luci.sys.exec("/etc/clash/dtun/clash -v 2>/dev/null |awk -F ' ' '{print $2}'")
if tun ~= "" then
return luci.sys.exec("/etc/clash/dtun/clash -v 2>/dev/null |awk -F ' ' '{print $2}'")
else
return luci.sys.exec("sed -n 1p /usr/share/clash/dtun_core_version")
end
else
return "0"
end
end
local function readlog()
return luci.sys.exec("sed -n '$p' /usr/share/clash/clash_real.txt 2>/dev/null")
end
local function geo_data()
return os.date("%Y-%m-%d %H:%M:%S",fss.mtime("/etc/clash/Country.mmdb"))
end
local function downcheck()
if nixio.fs.access("/var/run/core_update_error") then
return "0"
elseif nixio.fs.access("/var/run/core_update") then
return "1"
elseif nixio.fs.access("/usr/share/clash/core_down_complete") then
return "2"
end
end
function action_read()
luci.http.prepare_content("application/json")
luci.http.write_json({
readlog = readlog();
})
end
function down_check()
luci.http.prepare_content("application/json")
luci.http.write_json({
downcheck = downcheck();
})
end
local function geoipcheck()
if nixio.fs.access("/var/run/geoip_update_error") then
return "0"
elseif nixio.fs.access("/var/run/geoip_update") then
return "1"
elseif nixio.fs.access("/var/run/geoip_down_complete") then
return "2"
end
end
function geoip_check()
luci.http.prepare_content("application/json")
luci.http.write_json({
geoipcheck = geoipcheck();
})
end
function check_status()
luci.http.prepare_content("application/json")
luci.http.write_json({
check_version = check_version(),
check_core = check_core(),
current_version = current_version(),
new_version = new_version(),
clash_core = clash_core(),
check_dtun_core = check_dtun_core(),
new_dtun_core = new_dtun_core(),
clashtun_core = clashtun_core(),
dtun_core = dtun_core(),
new_core_version = new_core_version(),
new_clashtun_core_version =new_clashtun_core_version(),
check_clashtun_core = check_clashtun_core(),
conf_path = conf_path(),
typeconf = typeconf()
})
end
function action_status()
luci.http.prepare_content("application/json")
luci.http.write_json({
web = is_web(),
clash = is_running(),
localip = localip(),
dash_port = dash_port(),
current_version = current_version(),
new_dtun_core = new_dtun_core(),
new_core_version = new_core_version(),
new_clashtun_core_version =new_clashtun_core_version(),
new_version = new_version(),
clash_core = clash_core(),
dtun_core = dtun_core(),
dash_pass = dash_pass(),
clashtun_core = clashtun_core(),
e_mode = e_mode(),
in_use = in_use(),
conf_path = conf_path(),
uhttp_port = uhttp_port(),
typeconf = typeconf()
})
end
function action_ping_status()
luci.http.prepare_content("application/json")
luci.http.write_json({
ping_enable = ping_enable()
})
end
function act_ping()
local e={}
e.index=luci.http.formvalue("index")
e.ping=luci.sys.exec("ping -c 1 -W 1 -w 5 %q 2>&1 | grep -o 'time=[0-9]*.[0-9]' | awk -F '=' '{print$2}'"%luci.http.formvalue("domain"))
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function geoip_update()
fs.writefile("/var/run/geoiplog","0")
luci.sys.exec("(rm /var/run/geoip_update_error ; touch /var/run/geoip_update ; sh /usr/share/clash/geoip.sh >/tmp/geoip_update.txt 2>&1 || touch /var/run/geoip_update_error ;rm /var/run/geoip_update) &")
end
function do_update()
fs.writefile("/var/run/clashlog","0")
luci.sys.exec("(rm /var/run/core_update_error ; touch /var/run/core_update ; sh /usr/share/clash/core_download.sh >/tmp/clash_update.txt 2>&1 || touch /var/run/core_update_error ;rm /var/run/core_update) &")
end
function do_start()
luci.sys.exec('uci set clash.config.enable="1" && uci commit clash')
luci.sys.exec("/etc/init.d/clash restart 2>&1 &")
end
function do_stop()
luci.sys.exec('uci set clash.config.enable="0" && uci commit clash')
luci.sys.exec("/etc/init.d/clash stop 2>&1 &")
end
function do_reload()
if luci.sys.call("pidof clash >/dev/null") == 0 then
luci.sys.exec("/etc/init.d/clash reload 2>&1 &")
end
end
function check_update_log()
luci.http.prepare_content("text/plain; charset=utf-8")
local fdp=tonumber(fs.readfile("/var/run/clashlog")) or 0
local f=io.open("/tmp/clash_update.txt", "r+")
f:seek("set",fdp)
local a=f:read(2048000) or ""
fdp=f:seek()
fs.writefile("/var/run/clashlog",tostring(fdp))
f:close()
if fs.access("/var/run/core_update") then
luci.http.write(a)
else
luci.http.write(a.."\0")
end
end
function check_geoip_log()
luci.http.prepare_content("text/plain; charset=utf-8")
local fdp=tonumber(fs.readfile("/var/run/geoiplog")) or 0
local f=io.open("/tmp/geoip_update.txt", "r+")
f:seek("set",fdp)
local a=f:read(2048000) or ""
fdp=f:seek()
fs.writefile("/var/run/geoiplog",tostring(fdp))
f:close()
if fs.access("/var/run/geoip_update") then
luci.http.write(a)
else
luci.http.write(a.."\0")
end
end
function logstatus_check()
luci.http.prepare_content("text/plain; charset=utf-8")
local fdp=tonumber(fs.readfile("/usr/share/clash/logstatus_check")) or 0
local f=io.open("/usr/share/clash/clash.txt", "r+")
f:seek("set",fdp)
local a=f:read(2048000) or ""
fdp=f:seek()
fs.writefile("/usr/share/clash/logstatus_check",tostring(fdp))
f:close()
if fs.access("/var/run/logstatus") then
luci.http.write(a)
else
luci.http.write(a.."\0")
end
end

View File

@ -1,56 +0,0 @@
local NXFS = require "nixio.fs"
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 fs = require "luci.clash"
local clash = "clash"
m = Map("clash")
s = m:section(TypedSection, "clash")
s.anonymous = true
m.pageaction = false
o = s:option(ListValue, "core", translate("Core"))
o.default = "clashcore"
if nixio.fs.access("/etc/clash/clash") then
o:value("1", translate("Clash"))
end
if nixio.fs.access("/etc/clash/clashtun/clash") then
o:value("3", translate("Clash(cTun)"))
end
if nixio.fs.access("/etc/clash/dtun/clash") then
o:value("4", translate("Clash(premium)"))
end
o = s:option(ListValue, "g_rules", translate("Game Rules"))
o.default = "0"
o:value("0", translate("Disable"))
o:value("1", translate("Enable"))
o.description = translate("Set rules under Setting=>Game Rules, will take effect when client start")
o = s:option(ListValue, "append_rules", translate("Append Customs Rules"))
o.default = "0"
o:value("0", translate("Disable"))
o:value("1", translate("Enable"))
o.description = translate("Set custom rules under Setting=>Others , will take effect when client start")
o = s:option(Button, "Apply")
o.title = luci.util.pcdata(translate("Save & Apply"))
o.inputtitle = translate("Save & Apply")
o.inputstyle = "apply"
o.write = function()
m.uci:commit("clash")
end
o = s:option(Button,"action")
o.title = translate("Operation")
o.template = "clash/start_stop"
return m

View File

@ -1,365 +0,0 @@
local NXFS = require "nixio.fs"
local SYS = require "luci.sys"
local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"
local uci = luci.model.uci.cursor()
local fs = require "luci.clash"
local http = luci.http
local clash = "clash"
c = Map("clash")
c.template="clash/conf"
m = Map("clash")
s = m:section(TypedSection, "clash")
m.pageaction = false
s.anonymous = true
s.addremove=false
local conf = string.sub(luci.sys.exec("uci get clash.config.use_config"), 1, -2)
sev = s:option(TextValue, "conf")
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,"apply")
o.inputtitle = translate("Save & Apply")
o.inputstyle = "reload"
o.write = function()
m.uci:commit("clash")
end
local e,a={}
for t,o in ipairs(fs.glob("/etc/clash/config/sub/*.yaml"))do
a=fs.stat(o)
if a then
e[t]={}
e[t].name=fs.basename(o)
e[t].mtime=os.date("%Y-%m-%d %H:%M:%S",a.mtime)
e[t].size=tostring(a.size)
e[t].remove1=0
e[t].enable=false
end
end
function IsYamlFile(e)
e=e or""
local e=string.lower(string.sub(e,-5,-1))
return e==".yaml"
end
f=Form("config_listst")
f.reset=false
f.submit=false
tb=f:section(Table,e, translate("Subcription Config List"))
nm=tb:option(DummyValue,"name",translate("File Name"))
mt=tb:option(DummyValue,"mtime",translate("Update Time"))
sz=tb:option(DummyValue,"size",translate("Size"))
btnis=tb:option(Button,"switch1",translate("Use Config"))
btnis.template="clash/other_button"
btnis.render=function(o,t,a)
if not e[t]then return false end
if IsYamlFile(e[t].name)then
a.display=""
else
a.display="none"
end
o.inputstyle="apply"
Button.render(o,t,a)
end
btnis.write=function(a,t)
luci.sys.exec(string.format('uci set clash.config.use_config="/etc/clash/config/sub/%s"',e[t].name ))
luci.sys.exec('uci set clash.config.config_type="1"')
luci.sys.exec('uci commit clash')
if luci.sys.call("pidof clash >/dev/null") == 0 then
SYS.call("/etc/init.d/clash restart >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
else
HTTP.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config","config"))
end
end
btnist=tb:option(Button,"update1",translate("Update"))
btnist.template="clash/other_button"
btnist.render=function(o,t,a)
if not e[t]then return false end
o.inputstyle="apply"
Button.render(o,t,a)
end
btnist.write=function(a,t)
luci.sys.exec(string.format('uci set clash.config.config_update_name="%s"',e[t].name))
luci.sys.exec('uci commit clash')
luci.sys.exec('bash /usr/share/clash/update.sh >>/usr/share/clash/clash.txt 2>&1 &')
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
end
btndl = tb:option(Button,"download1",translate("Download"))
btndl.template="clash/other_button"
btndl.render=function(e,t,a)
e.inputstyle="remove"
Button.render(e,t,a)
end
btndl.write = function (a,t)
local sPath, sFile, fd, block
sPath = "/etc/clash/config/sub/"..e[t].name
sFile = NXFS.basename(sPath)
if fs.isdirectory(sPath) then
fd = io.popen('yaml -C "%s" -cz .' % {sPath}, "r")
sFile = sFile .. ".yaml"
else
fd = nixio.open(sPath, "r")
end
if not fd then
return
end
HTTP.header('Content-Disposition', 'attachment; filename="%s"' % {sFile})
HTTP.prepare_content("application/octet-stream")
while true do
block = fd:read(nixio.const.buffersize)
if (not block) or (#block ==0) then
break
else
HTTP.write(block)
end
end
fd:close()
HTTP.close()
end
btnrm=tb:option(Button,"remove1",translate("Remove"))
btnrm.render=function(e,t,a)
e.inputstyle="remove"
Button.render(e,t,a)
end
btnrm.write=function(a,t)
local a=fs.unlink("/etc/clash/config/sub/"..fs.basename(e[t].name))
luci.sys.exec(string.format('uci set clash.config.config_name_remove="%s"',e[t].name))
luci.sys.exec('uci commit clash')
luci.sys.exec('bash /usr/share/clash/rmlist.sh 2>&1 &')
if a then table.remove(e,t)end
return a
end
local p,x={}
for q,v in ipairs(fs.glob("/etc/clash/config/upload/*.yaml"))do
x=fs.stat(v)
if x then
p[q]={}
p[q].name=fs.basename(v)
p[q].mtime=os.date("%Y-%m-%d %H:%M:%S",x.mtime)
p[q].size=tostring(x.size)
p[q].remove2=0
p[q].enable=false
end
end
fr=Form("config_list")
fr.reset=false
fr.submit=false
tb=fr:section(Table,p, translate("Upload Config List"))
nm=tb:option(DummyValue,"name",translate("File Name"))
mt=tb:option(DummyValue,"mtime",translate("Update Time"))
sz=tb:option(DummyValue,"size",translate("Size"))
function IsYamlFile(p)
p=p or""
local p=string.lower(string.sub(p,-5,-1))
return p==".yaml"
end
btniss=tb:option(Button,"switch2",translate("Use Config"))
btniss.template="clash/other_button"
btniss.render=function(v,q,x)
if not p[q]then return false end
if IsYamlFile(p[q].name)then
x.display=""
else
x.display="none"
end
v.inputstyle="apply"
Button.render(v,q,x)
end
btniss.write=function(x,q)
luci.sys.exec(string.format('uci set clash.config.use_config="/etc/clash/config/upload/%s"',p[q].name ))
luci.sys.exec('uci set clash.config.config_type="2"')
luci.sys.exec('uci commit clash')
if luci.sys.call("pidof clash >/dev/null") == 0 then
SYS.call("/etc/init.d/clash restart >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
else
HTTP.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config" ,"config"))
end
end
btndll = tb:option(Button,"download2",translate("Download"))
btndll.template="clash/other_button"
btndll.render=function(p,q,x)
p.inputstyle="remove"
Button.render(p,q,x)
end
btndll.write = function (x,q)
local sPath, sFile, fd, block
sPath = "/etc/clash/config/upload/"..p[q].name
sFile = NXFS.basename(sPath)
if fs.isdirectory(sPath) then
fd = io.popen('yaml -C "%s" -cz .' % {sPath}, "r")
sFile = sFile .. ".yaml"
else
fd = nixio.open(sPath, "r")
end
if not fd then
return
end
HTTP.header('Content-Disposition', 'attachment; filename="%s"' % {sFile})
HTTP.prepare_content("application/octet-stream")
while true do
block = fd:read(nixio.const.buffersize)
if (not block) or (#block ==0) then
break
else
HTTP.write(block)
end
end
fd:close()
HTTP.close()
end
btnrml=tb:option(Button,"remove2",translate("Remove"))
btnrml.render=function(p,q,x)
p.inputstyle="remove"
Button.render(p,q,x)
end
btnrml.write=function(x,q)
local x=fs.unlink("/etc/clash/config/upload/"..fs.basename(p[q].name))
luci.sys.exec(string.format('uci set clash.config.config_up_remove="%s"',p[q].name))
luci.sys.exec('uci commit clash')
luci.sys.exec('bash /usr/share/clash/uplist.sh 2>&1 &')
if x then table.remove(p,q)end
return x
end
local k,v={}
for c,z in ipairs(fs.glob("/etc/clash/config/custom/*.yaml"))do
v=fs.stat(z)
if v then
k[c]={}
k[c].name=fs.basename(z)
k[c].mtime=os.date("%Y-%m-%d %H:%M:%S",v.mtime)
k[c].size=tostring(v.size)
k[c].remove3=0
k[c].enable=false
end
end
fro=Form("config_listts")
fro.reset=false
fro.submit=false
tb=fro:section(Table,k,translate("Custom Config List"))
nm=tb:option(DummyValue,"name",translate("File Name"))
mt=tb:option(DummyValue,"mtime",translate("Update Time"))
sz=tb:option(DummyValue,"size",translate("Size"))
function IsYamlFile(k)
k=k or""
local k=string.lower(string.sub(k,-5,-1))
return k==".yaml"
end
btnisz=tb:option(Button,"switch3",translate("Use Config"))
btnisz.template="clash/other_button"
btnisz.render=function(z,c,v)
if not k[c]then return false end
if IsYamlFile(k[c].name)then
v.display=""
else
v.display="none"
end
z.inputstyle="apply"
Button.render(z,c,v)
end
btnisz.write=function(v,c)
luci.sys.exec(string.format('uci set clash.config.use_config="/etc/clash/config/custom/%s"',k[c].name ))
luci.sys.exec('uci set clash.config.config_type="3"')
luci.sys.exec('uci commit clash')
if luci.sys.call("pidof clash >/dev/null") == 0 then
SYS.call("/etc/init.d/clash restart >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
else
HTTP.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config", "config"))
end
end
btndlz = tb:option(Button,"download3",translate("Download"))
btndlz.template="clash/other_button"
btndlz.render=function(k,c,v)
k.inputstyle="remove"
Button.render(k,c,v)
end
btndlz.write = function (v,c)
local sPath, sFile, fd, block
sPath = "/etc/clash/config/custom/"..k[c].name
sFile = NXFS.basename(sPath)
if fs.isdirectory(sPath) then
fd = io.popen('yaml -C "%s" -cz .' % {sPath}, "r")
sFile = sFile .. ".yaml"
else
fd = nixio.open(sPath, "r")
end
if not fd then
return
end
HTTP.header('Content-Disposition', 'attachment; filename="%s"' % {sFile})
HTTP.prepare_content("application/octet-stream")
while true do
block = fd:read(nixio.const.buffersize)
if (not block) or (#block ==0) then
break
else
HTTP.write(block)
end
end
fd:close()
HTTP.close()
end
btnrmz=tb:option(Button,"remove3",translate("Remove"))
btnrmz.render=function(k,c,v)
k.inputstyle="remove"
Button.render(k,c,v)
end
btnrmz.write=function(v,c)
local v=fs.unlink("/etc/clash/config/custom/"..fs.basename(k[c].name))
luci.sys.exec(string.format('uci set clash.config.config_cus_remove="%s"',k[c].name))
luci.sys.exec('uci commit clash')
luci.sys.exec('/usr/share/clash/cuslist.sh 2>&1 &')
if v then table.remove(k,c)end
return v
end
return c,f,fr,fro,m

View File

@ -1,386 +0,0 @@
local clash = "clash"
local NXFS = require "nixio.fs"
local SYS = require "luci.sys"
local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"
local fs = require "luci.clash"
local uci = require "luci.model.uci".cursor()
local s, o, krk, z, r
local http = luci.http
font_blue = [[<font color="blue">]]
font_off = [[</font>]]
bold_on = [[<strong>]]
bold_off = [[</strong>]]
krk = Map(clash)
s = krk:section(TypedSection, "clash", translate("Create Config"))
s.anonymous = true
--krk.pageaction = false
o = s:option(Flag, "provider_config", translate("Enable Create"))
o.default = 1
o.description = translate("Enable to create configuration")
o = s:option(Flag, "prox", translate("Use Proxy"))
o.description = translate("Use Proxy")
o = s:option(Flag, "ppro", translate("Use Proxy Provider"))
o.description = translate("Use Proxy Provider")
o = s:option(Flag, "rulprp", translate("Use Rule Provider"))
o.description = translate("Use Rule Provider")
o:depends("orul", 0)
o = s:option(Flag, "rul", translate("Use Rules"))
o.description = translate("Use Rules")
o:depends("orul", 0)
o = s:option(Flag, "orul", translate("Use Other Rules"))
o.description = translate("Use Other Rules")
o:depends("rul", 0)
o = s:option(Flag, "script", translate("Use Script"))
o.description = translate("Use Script")
o:depends("rul", 1)
o:depends("rulprp", 1)
o = s:option(Value, "name_tag")
o.title = translate("Config Name")
o.rmempty = true
o.description = translate("Give a name for your config")
cc = s:option(Flag, "same_tag", translate("Force Same Name"))
cc.default = 1
cc.description = translate("Enable to overwrite config file")
o = s:option(Button,"Manager")
o.title = translate("Rule Providers Manager")
o.inputtitle = translate("Rule Providers Manager")
o.inputstyle = "reload"
o.write = function()
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash", "rulemanager"))
end
local t = {
{Creat_Config, Delete_Groups, Delete_ProxyPro, Delete_RulePro,Delete_Rules}
}
b = krk:section(Table, t)
o = b:option(Button,"Creat_Config")
o.inputtitle = translate("Create Config")
o.inputstyle = "apply"
o.write = function()
krk.uci:commit("clash")
luci.sys.call("bash /usr/share/clash/create/create.sh >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
end
o = b:option(Button,"Delete Severs")
o.inputtitle = translate("Delete Severs")
o.inputstyle = "reset"
o.write = function()
krk.uci:delete_all("clash", "servers", function(s) return true end)
krk.uci:commit("clash")
end
o = b:option(Button,"Delete_ProxyPro")
o.inputtitle = translate("Delete Proxy Provider")
o.inputstyle = "reset"
o.write = function()
krk.uci:delete_all("clash", "proxyprovider", function(s) return true end)
krk.uci:commit("clash")
end
o = b:option(Button,"Delete_RulePro")
o.inputtitle = translate("Delete Rule Provider")
o.inputstyle = "reset"
o.write = function()
krk.uci:delete_all("clash", "ruleprovider", function(s) return true end)
krk.uci:commit("clash")
end
o = b:option(Button,"Delete_Rules")
o.inputtitle = translate("Delete Rules")
o.inputstyle = "reset"
o.write = function()
krk.uci:delete_all("clash", "rules", function(s) return true end)
krk.uci:commit("clash")
end
o = b:option(Button,"Delete_Groups")
o.inputtitle = translate("Delete Groups")
o.inputstyle = "reset"
o.write = function()
krk.uci:delete_all("clash", "pgroups", function(s) return true end)
krk.uci:commit("clash")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config", "create"))
end
-- [[ Proxies ]]--
s = krk:section(TypedSection, "servers", translate("Proxies"))
s.anonymous = true
s.addremove = true
s.sortable = false
s.template = "cbi/tblsection"
s.extedit = luci.dispatcher.build_url("admin/services/clash/servers/%s")
function s.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(s.extedit % sid)
return
end
end
o = s:option(Flag, "enabled", translate("Enable"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
o = s:option(DummyValue, "type", translate("Type"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = s:option(DummyValue, "name", translate("Alias"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = s:option(DummyValue, "server", translate("Server Address"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = s:option(DummyValue, "port", translate("Server Port"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = s:option(DummyValue, "server" ,translate("Latency"))
o.template="clash/ping"
o.width="10%"
-- [[ Groups Manage ]]--
x = krk:section(TypedSection, "pgroups", translate("Policy Groups"))
x.description = font_blue..bold_on..translate(" https://lancellc.gitbook.io/clash/clash-config-file/proxy-groups")..bold_off..font_off..' '
x.anonymous = true
x.addremove = true
x.sortable = true
x.template = "cbi/tblsection"
x.extedit = luci.dispatcher.build_url("admin/services/clash/pgroups/%s")
function x.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(x.extedit % sid)
return
end
end
o = x:option(Flag, "enabled", translate("Enable"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
o = x:option(DummyValue, "type", translate("Group Type"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = x:option(DummyValue, "name", translate("Group Name"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
-- [[ Proxy-Provider Manage ]]--
z = krk:section(TypedSection, "proxyprovider", translate("Proxy Provider"))
z.description = font_blue..bold_on..translate(" https://lancellc.gitbook.io/clash/clash-config-file/proxy-provider")..bold_off..font_off..' '
z.anonymous = true
z.addremove = true
z.sortable = true
z.template = "cbi/tblsection"
z.extedit = luci.dispatcher.build_url("admin/services/clash/proxyprovider/%s")
function z.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(z.extedit % sid)
return
end
end
o = z:option(Flag, "enabled", translate("Enable"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
o = z:option(DummyValue, "name", translate("Provider Name"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = z:option(DummyValue, "type", translate("Provider Type"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
-- [[ Rule-Provider Manage ]]--
r = krk:section(TypedSection, "ruleprovider", translate("Rule Provider"))
r.description = font_blue..bold_on..translate(" https://lancellc.gitbook.io/clash/clash-config-file/rule-provider")..bold_off..font_off..' '
r.anonymous = true
r.addremove = true
r.sortable = true
r.template = "cbi/tblsection"
r.extedit = luci.dispatcher.build_url("admin/services/clash/ruleprovider/%s")
function r.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(r.extedit % sid)
return
end
end
o = r:option(Flag, "enabled", translate("Enable"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
o = r:option(DummyValue, "name", translate("Provider Name"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = r:option(DummyValue, "type", translate("Provider Type"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = r:option(DummyValue, "behavior", translate("Provider Behavior"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
-- [[ Rule Manage ]]--
q = krk:section(TypedSection, "rules", translate("Rules"))
q.description = font_blue..bold_on..translate(" https://lancellc.gitbook.io/clash/clash-config-file/rules")..bold_off..font_off..' '
q.anonymous = true
q.addremove = true
q.sortable = true
q.template = "cbi/tblsection"
q.extedit = luci.dispatcher.build_url("admin/services/clash/rules/%s")
function q.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(q.extedit % sid)
return
end
end
o = q:option(Flag, "enabled", translate("Enable"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
o = q:option(DummyValue, "type", translate("Rule Type"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = q:option(DummyValue, "rulename", translate("Description"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("-")
end
o = q:option(DummyValue, "rulegroups", translate("Groups"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
m = Map("clash")
y = m:section(TypedSection, "clash" , translate("Script"))
y.anonymous = true
y.addremove=false
local script="/usr/share/clash/create/script.yaml"
sev = y:option(TextValue, "scriptt")
sev.description =translate("NB: Set Clash Mode to Script if want to use")..font_blue..bold_on..translate(" https://lancellc.gitbook.io/clash/clash-config-file/script")..bold_off..font_off..' '
sev.rows = 10
sev.wrap = "off"
sev.cfgvalue = function(self, section)
return NXFS.readfile(script) or ""
end
sev.write = function(self, section, value)
NXFS.writefile(script, value:gsub("\r\n", "\n"))
end
l = Map("clash")
v = l:section(TypedSection, "clash" , translate("Other Rules"))
v.anonymous = true
v.addremove=false
o = v:option(Value, "rule_url")
o.title = translate("Custom Rule Url")
o.description = translate("Insert your custom rule Url and click download")
o.rmempty = true
o = v:option(Button,"rule_update")
o.title = translate("Download Rule")
o.inputtitle = translate("Download Rule")
o.description = translate("Download Rule")
o.inputstyle = "reload"
o.write = function()
uci:commit("clash")
luci.sys.call("bash /usr/share/clash/rule.sh >>/usr/share/clash/clash.txt >/dev/null 2>&1 &")
end
local rule = "/usr/share/clash/rule.yaml"
sev = v:option(TextValue, "rule")
sev.description = translate("NB: Attention to Proxy Group and Rule when making changes to this section")
sev.rows = 20
sev.wrap = "off"
sev.cfgvalue = function(self, section)
return NXFS.readfile(rule) or ""
end
sev.write = function(self, section, value)
NXFS.writefile(rule, value:gsub("\r\n", "\n"))
end
o = v:option(Button,"del_rule")
o.inputtitle = translate("Delete Rule")
o.write = function()
SYS.call("rm -rf /usr/share/clash/rule.yaml >/dev/null 2>&1 &")
end
krk:append(Template("clash/list"))
return krk,m,l

View File

@ -1,94 +0,0 @@
local m, s, o
local clash = "clash"
local uci = luci.model.uci.cursor()
local fs = require "nixio.fs"
local sys = require "luci.sys"
local sid = arg[1]
m = Map(clash, translate("Edit Group"))
m.pageaction = false
m.redirect = luci.dispatcher.build_url("admin/services/clash/config/create")
if m.uci:get(clash, sid) ~= "pgroups" then
luci.http.redirect(m.redirect)
return
end
-- [[ Groups Setting ]]--
s = m:section(NamedSection, sid, "pgroups")
s.anonymous = true
s.addremove = false
o = s:option(ListValue, "type", translate("Group Type"))
o.rmempty = true
o.description = translate("Choose The Operation Mode")
o:value("select", translate("Select"))
o:value("url-test", translate("URL-Test"))
o:value("fallback", translate("Fallback"))
o:value("load-balance", translate("Load-Balance"))
o:value("relay", translate("Relay"))
o = s:option(Value, "name", translate("Group Name"))
o.rmempty = false
o = s:option(Value, "test_url", translate("Test URL"))
o.default = "http://www.gstatic.com/generate_204"
o.rmempty = true
o:depends("type", "url-test")
o:depends("type", "fallback")
o:depends("type", "load-balance")
o = s:option(Value, "test_interval", translate("Test Interval(s)"))
o.default = "300"
o.rmempty = true
o:depends("type", "url-test")
o:depends("type", "fallback")
o:depends("type", "load-balance")
o = s:option(DynamicList, "other_group", translate("Other Group"))
o.rmempty = true
o.description = translate("Proxy Groups Must Exist In Rule")
o:value("ALL", translate("All Servers"))
uci:foreach("clash", "pgroups",
function(s)
if s.name ~= "" and s.name ~= nil and s.name ~= m.uci:get(clash, sid, "name") then
o:value(s.name)
end
end)
uci:foreach("clash", "servers",
function(s)
if s.name ~= "" and s.name ~= nil and s.name ~= m.uci:get(clash, sid, "name") then
o:value(s.name)
end
end)
o:value("DIRECT")
o:value("REJECT")
local t = {
{Apply, Return}
}
b = m:section(Table, t)
o = b:option(Button,"Apply")
o.inputtitle = translate("Save & Apply")
o.inputstyle = "apply"
o.write = function()
m.uci:commit("clash")
sys.call("/usr/share/clash/create/pgroups.sh start >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config", "create"))
end
o = b:option(Button,"Return")
o.inputtitle = translate("Back to Overview")
o.inputstyle = "reset"
o.write = function()
m.uci:revert(clash)
luci.http.redirect(m.redirect)
--luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config", "providers"))
end
return m

View File

@ -1,156 +0,0 @@
local NXFS = require "nixio.fs"
local SYS = require "luci.sys"
local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"
local uci = luci.model.uci.cursor()
local fs = require "luci.clash"
local http = luci.http
local clash = "clash"
kr = Map(clash)
s = kr:section(TypedSection, "clash", translate("Subscription Config"))
s.anonymous = true
kr.pageaction = false
o = s:option(ListValue, "subcri", translate("Subcription Type"))
o.default = clash
o:value("clash", translate("clash"))
o:value("ssr2clash", translate("ssr2clash"))
o:value("v2clash", translate("v2clash"))
o.description = translate("Select Subcription Type")
o = s:option(Value, "config_name")
o.title = translate("Config Name")
o.description = translate("Config Name. Do not use a config name that already exist")
o = s:option(Value, "clash_url")
o.title = translate("Subcription Url")
o.description = translate("Clash Subscription Address")
o.rmempty = true
o:depends("subcri", 'clash')
o = s:option(Button,"update")
o.title = translate("Download Config")
o.inputtitle = translate("Download Config")
o.inputstyle = "reload"
o.write = function()
kr.uci:commit("clash")
SYS.call("sh /usr/share/clash/clash.sh >>/usr/share/clash/clash.txt 2>&1 &")
SYS.call("sleep 1")
HTTP.redirect(DISP.build_url("admin", "services", "clash"))
end
o:depends("subcri", 'clash')
o = s:option(Value, "ssr_url")
o.title = translate("Subcription Url")
o.placeholder = translate("https://www.example.com/link/QkjokZXktyyr35gfj")
o.rmempty = true
o:depends("subcri", 'ssr2clash')
o = s:option(Button,"updatee")
o.title = translate("Download Config")
o.inputtitle = translate("Download Config")
o.inputstyle = "reload"
o.write = function()
kr.uci:commit("clash")
luci.sys.call("bash /usr/share/clash/clash.sh >>/usr/share/clash/clash.txt 2>&1 &")
HTTP.redirect(DISP.build_url("admin", "services", "clash"))
end
o:depends("subcri", 'ssr2clash')
o = s:option(Value, "v2_url")
o.title = translate("Subcription Url")
o.placeholder = translate("https://www.example.com/link/QkjokZXktyyr35gfj")
o.rmempty = true
o:depends("subcri", 'v2clash')
o = s:option(Button,"updateee")
o.title = translate("Download Config")
o.inputtitle = translate("Download Config")
o.inputstyle = "reload"
o.write = function()
kr.uci:commit("clash")
luci.sys.call("bash /usr/share/clash/clash.sh >>/usr/share/clash/clash.txt 2>&1 &")
HTTP.redirect(DISP.build_url("admin", "services", "clash"))
end
o:depends("subcri", 'v2clash')
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
ko = Map(clash)
ko.reset = false
ko.submit = false
sul =ko:section(TypedSection, "clash", translate("Upload Config"))
sul.anonymous = true
sul.addremove=false
o = sul:option(FileUpload, "")
--o.description = translate("NB: Only upload file with name .yaml.It recommended to rename each upload file name to avoid overwrite")
o.title = translate(" ")
o.template = "clash/clash_upload"
um = sul:option(DummyValue, "", nil)
um.template = "clash/clash_dvalue"
local dir, fd
dir = "/etc/clash/config/upload/"
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
local e=string.lower(string.sub(meta.file,-4,-1))
local yml2=string.lower(string.sub(meta.file,0,-5))
if e == '.yml' then
local yml=string.lower(string.sub(meta.file,0,-5))
local c=fs.rename(dir .. meta.file,"/etc/clash/config/upload/".. yml .. ".yaml")
um.value = translate("File saved to") .. ' "/etc/clash/config/upload/'..yml..'.yaml"'
else
um.value = translate("File saved to") .. ' "/etc/clash/config/upload/'..yml2..'yaml"'
end
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
return kr,ko

View File

@ -1,59 +0,0 @@
local m, s, o
local clash = "clash"
local uci = luci.model.uci.cursor()
local fs = require "nixio.fs"
local sys = require "luci.sys"
local sid = arg[1]
m = Map(clash, translate("Edit Custom Rule & Group"))
--m.pageaction = false
m.redirect = luci.dispatcher.build_url("admin/services/clash/settings/other")
if m.uci:get(clash, sid) ~= "addtype" then
luci.http.redirect(m.redirect)
return
end
s = m:section(NamedSection, sid, "addtype")
s.anonymous = true
s.addremove = false
o = s:option(ListValue, "type", translate("Rule Type"))
o.rmempty = false
o.description = translate("Choose Type")
o:value("DST-PORT", translate("DST-PORT"))
o:value("SRC-PORT", translate("SRC-PORT"))
o:value("SRC-IP-CIDR", translate("SRC-IP-CIDR"))
o:value("IP-CIDR", translate("IP-CIDR"))
o:value("IP-CIDR6", translate("IP-CIDR6"))
o:value("DOMAIN", translate("DOMAIN"))
o:value("DOMAIN-KEYWORD", translate("DOMAIN-KEYWORD"))
o:value("DOMAIN-SUFFIX", translate("DOMAIN-SUFFIX"))
o:value("GEOIP", translate("GEOIP"))
o = s:option(ListValue, "pgroup", translate("Select Proxy Group"))
uci:foreach("clash", "conf_groups",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
end
end)
o:value("DIRECT")
o:value("REJECT")
o.rmempty = false
o.description = translate("Select a policy group to add rule")
o = s:option(Value, "ipaaddr", translate("IP/Domain/Address/Keyword/Port"))
o.rmempty = false
o = s:option(Flag, "res", translate("No Resolve"))
o.default = 0
o:depends("type", "IP-CIDR")
o:depends("type", "IP-CIDR6")
o:depends("type", "GEOIP")
return m

View File

@ -1,160 +0,0 @@
local m, s, o
local clash = "clash"
local uci = luci.model.uci.cursor()
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"))
m.pageaction = false
m.redirect = luci.dispatcher.build_url("admin/services/clash/config/create")
if m.uci:get(clash, sid) ~= "proxyprovider" then
luci.http.redirect(m.redirect)
return
end
s = m:section(NamedSection, sid, "proxyprovider")
s.anonymous = true
s.addremove = false
o = s:option(ListValue, "type", translate("Provider Type"))
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/proxyprovider/"
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/proxyprovider/"'
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, "path", translate("Provider Path"))
o.description = translate("Upload Provider File If Empty")
local p,h={}
for t,f in ipairs(fss.glob("/etc/clash/proxyprovider/*"))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("./proxyprovider/"..p[t].name)
end
end
end
o.rmempty = true
o:depends("type", "file")
o = s:option(Value, "provider_url", translate("Provider URL"))
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 = true
o:depends("type", "http")
o = s:option(ListValue, "health_check", translate("Provider Health Check"))
o:value("false", translate("Disable"))
o:value("true", translate("Enable"))
o.default=true
o = s:option(Value, "health_check_url", translate("Health Check URL"))
o.default = "http://www.gstatic.com/generate_204"
o.rmempty = true
o = s:option(Value, "health_check_interval", translate("Health Check Interval"))
o.default = "300"
o.rmempty = true
o = s:option(DynamicList, "pgroups", translate("Policy Group"))
o.rmempty = true
m.uci:foreach("clash", "pgroups",
function(s)
if s.name ~= "" and s.name ~= nil and s.type ~= "relay" then
o:value(s.name)
end
end)
local t = {
{Apply, Return}
}
b = m:section(Table, t)
o = b:option(Button,"Apply")
o.inputtitle = translate("Save & Apply")
o.inputstyle = "apply"
o.write = function()
m.uci:commit("clash")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config", "create"))
end
o = b:option(Button,"Return")
o.inputtitle = translate("Back to Overview")
o.inputstyle = "reset"
o.write = function()
m.uci:revert(clash)
luci.http.redirect(m.redirect)
--luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config", "providers"))
end
return m

View File

@ -1,150 +0,0 @@
local m, s, o
local clash = "clash"
local uci = luci.model.uci.cursor()
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
function IsFile(e)
e=e or""
local e=string.lower(string.sub(e,-5,-1))
return e == ".list"
end
m = Map(clash, translate("Edit Rule Provider"))
m.pageaction = false
m.redirect = luci.dispatcher.build_url("admin/services/clash/config/create")
if m.uci:get(clash, sid) ~= "ruleprovider" then
luci.http.redirect(m.redirect)
return
end
s = m:section(NamedSection, sid, "ruleprovider")
s.anonymous = true
s.addremove = false
o = s:option(Value, "name", translate("Rule Provider Name"))
o.rmempty = false
o = s:option(ListValue, "type", translate("Provider Type"))
o.rmempty = false
o.description = translate("Provider Type")
o:value("http")
o:value("file")
o = s:option(ListValue, "behavior", translate("Provider Behavior"))
o.rmempty = false
o.description = translate("ipcidr # or domain")
o:value("ipcidr")
o:value("domain")
o:value("classical")
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/ruleprovider/"
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/ruleprovider/"'
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(ListValue, "path", translate("Provider Path"))
o.description = translate("Upload Provider File If Empty")
local p,h={}
for t,f in ipairs(fss.glob("/etc/clash/ruleprovider/*"))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) or IsFile(p[t].name) then
o:value("./ruleprovider/"..p[t].name)
end
end
end
o:depends("type", "file")
o = s:option(Value, "url", translate("Provider URL"))
o.description = translate("【HTTP】./hk.yaml")
o:depends("type", "http")
o = s:option(Value, "interval", translate("Provider Interval"))
o.default = "3600"
o:depends("type", "http")
local t = {
{Apply, Return}
}
b = m:section(Table, t)
o = b:option(Button,"Apply")
o.inputtitle = translate("Save & Apply")
o.inputstyle = "apply"
o.write = function()
m.uci:commit("clash")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config", "create"))
end
o = b:option(Button,"Return")
o.inputtitle = translate("Back to Overview")
o.inputstyle = "reset"
o.write = function()
m.uci:revert(clash)
luci.http.redirect(m.redirect)
--luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config", "providers"))
end
return m

View File

@ -1,96 +0,0 @@
local f, s, o
local clash = "clash"
local uci = luci.model.uci.cursor()
local fs = require "nixio.fs"
local sys = require "luci.sys"
local sid = arg[1]
local http = luci.http
local fss = require "luci.clash"
local NXFS = require "nixio.fs"
local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"
m = Map("clash", translate("Rule Providers List"))
m.reset = false
m.submit = false
local t = {
{Apply}
}
a = m:section(Table, t)
o = a:option(Button, "Apply")
o.inputtitle = translate("Back to Overview")
o.inputstyle = "reset"
o.write = function()
HTTP.redirect(DISP.build_url("admin", "services", "clash", "config", "create"))
end
sys.call("awk -F ',' '{print $4}' /usr/share/clash/create/rule_provider.list > /tmp/rule_providers 2>/dev/null")
file = io.open("/tmp/rule_providers", "r");
local e={},a,o,t
a=nixio.fs.access("/tmp/rule_providers")
if a then
for o in file:lines() do
table.insert(e,o)
end
for t,o in ipairs(e) do
e[t]={}
e[t].num=string.format(t)
e[t].name=string.sub(luci.sys.exec(string.format("grep -F ',%s' /usr/share/clash/create/rule_provider.list |awk -F ',' '{print $1}' 2>/dev/null",o)),1,-2)
e[t].behaviour=string.sub(luci.sys.exec(string.format("grep -F ',%s' /usr/share/clash/create/rule_provider.list |awk -F ',' '{print $2}' 2>/dev/null",o)),1,-2)
e[t].filename=string.sub(luci.sys.exec(string.format("grep -F '%s,' /usr/share/clash/create/rule_provider.list |awk -F ',' '{print $4}' 2>/dev/null",o)),1,-2)
if e[t].filename == "" then
e[t].filename=o
end
RULE_FILE="/etc/clash/ruleprovider/".. e[t].filename
if fss.mtime(RULE_FILE) then
e[t].mtime=os.date("%Y-%m-%d %H:%M:%S",fss.mtime(RULE_FILE))
else
e[t].mtime="/"
end
if fss.isfile(RULE_FILE) then
e[t].exist=translate("Exist")
else
e[t].exist=translate("Not Exist")
end
e[t].remove=0
end
end
file:close()
f=Form("filelist")
tb=f:section(Table,e)
nu=tb:option(DummyValue,"num",translate("Order Number"))
st=tb:option(DummyValue,"exist",translate("State"))
nm=tb:option(DummyValue,"name",translate("Rule Name"))
tp=tb:option(DummyValue,"behaviour",translate("Type"))
fm=tb:option(DummyValue,"filename",translate("File Name"))
mt=tb:option(DummyValue,"mtime",translate("Update Time"))
btnis=tb:option(DummyValue,"filename",translate("Download Rule"))
btnis.template="clash/rulep"
btnrm=tb:option(Button,"remove",translate("Remove"))
btnrm.render=function(e,t,a)
e.inputstyle="reset"
Button.render(e,t,a)
end
btnrm.write=function(a,t)
local a=fs.unlink("/etc/clash/ruleprovider/"..e[t].filename)
HTTP.redirect(luci.dispatcher.build_url("admin", "services", "clash", "rulemanager"))
end
return m, f

View File

@ -1,105 +0,0 @@
local m, s, o
local clash = "clash"
local uci = luci.model.uci.cursor()
local fs = require "nixio.fs"
local sys = require "luci.sys"
local sid = arg[1]
m = Map(clash, translate("Edit Rules"))
--m.pageaction = false
m.redirect = luci.dispatcher.build_url("admin/services/clash/config/create")
if m.uci:get(clash, sid) ~= "rules" then
luci.http.redirect(m.redirect)
return
end
s = m:section(NamedSection, sid, "rules")
s.anonymous = true
s.addremove = false
m.pageaction = false
o = s:option(ListValue, "type", translate("Rule Type"))
o.rmempty = false
o.description = translate("Choose Type")
o:value("RULE-SET", translate("RULE-SET"))
o:value("DST-PORT", translate("DST-PORT"))
o:value("SRC-PORT", translate("SRC-PORT"))
o:value("SRC-IP-CIDR", translate("SRC-IP-CIDR"))
o:value("IP-CIDR", translate("IP-CIDR"))
o:value("IP-CIDR6", translate("IP-CIDR6"))
o:value("DOMAIN", translate("DOMAIN"))
o:value("DOMAIN-KEYWORD", translate("DOMAIN-KEYWORD"))
o:value("DOMAIN-SUFFIX", translate("DOMAIN-SUFFIX"))
o:value("GEOIP", translate("GEOIP"))
o:value("MATCH", translate("MATCH"))
o = s:option(ListValue, "rulename", translate("Description"))
uci:foreach("clash", "ruleprovider",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
end
end)
o.description = translate("Select rule provider name")
o:depends("type", "RULE-SET")
o = s:option(ListValue, "rulegroups", translate("Select Proxy Group"))
uci:foreach("clash", "pgroups",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
end
end)
o:value("DIRECT")
o:value("REJECT")
o.description = translate("Select a policy group to add rule")
o = s:option(Value, "rulenamee", translate("Description"))
o:depends("type", "DST-PORT")
o:depends("type", "SRC-PORT")
o:depends("type", "SRC-IP-CIDR")
o:depends("type", "IP-CIDR")
o:depends("type", "DOMAIN")
o:depends("type", "DOMAIN-KEYWORD")
o:depends("type", "DOMAIN-SUFFIX")
o:depends("type", "GEOIP")
o:depends("type", "IP-CIDR6")
o = s:option(Flag, "res", translate("No Resolve"))
o.default = 0
o:depends("type", "IP-CIDR")
o:depends("type", "IP-CIDR6")
o:depends("type", "GEOIP")
local t = {
{Apply, Return}
}
b = m:section(Table, t)
o = b:option(Button,"Apply")
o.inputtitle = translate("Save & Apply")
o.inputstyle = "apply"
o.write = function()
m.uci:commit("clash")
sys.call("/usr/share/clash/create/rules.sh start >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config", "create"))
end
o = b:option(Button,"Return")
o.inputtitle = translate("Back to Overview")
o.inputstyle = "reset"
o.write = function()
m.uci:revert(clash)
luci.http.redirect(m.redirect)
--luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash", "config", "providers"))
end
return m

View File

@ -1,320 +0,0 @@
local m, s, o
local clash = "clash"
local uci = luci.model.uci.cursor()
local fs = require "nixio.fs"
local sys = require "luci.sys"
local sid = arg[1]
local uuid = luci.sys.exec("cat /proc/sys/kernel/random/uuid")
local server_table = {}
local encrypt_methods_ss = {
"rc4-md5",
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"aes-128-gcm",
"aes-192-gcm",
"aes-256-gcm",
"chacha20-ietf",
"xchacha20",
"chacha20-ietf-poly1305",
"xchacha20-ietf-poly1305",
}
local securitys = {
"auto",
"none",
"aes-128-gcm",
"chacha20-poly1305"
}
local encrypt_methods_ssr = {
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"rc4-md5",
"chacha20-ietf",
"xchacha20",
}
local protocol_ssr = {
"origin",
"auth_sha1_v4",
"auth_aes128_md5",
"auth_aes128_sha1",
"auth_chain_a",
"auth_chain_b",
}
local obfs_ssr_list = {
"plain",
"http_simple",
"http_post",
"tls1.2_ticket_auth",
"tls1.2_ticket_fastauth",
"random_head",
}
m = Map(clash, translate("Edit Server"))
m.redirect = luci.dispatcher.build_url("admin/services/clash/config/create")
if m.uci:get(clash, sid) ~= "servers" then
luci.http.redirect(m.redirect)
return
end
-- [[ Servers Setting ]]--
s = m:section(NamedSection, sid, "servers")
s.anonymous = true
s.addremove = false
o = s:option(DummyValue,"ssr_url",translate("Import config info"))
o.rawhtml = true
o.template = "clash/ssrurl"
o.value =sid
o = s:option(ListValue, "type", translate("Server Node Type"))
o:value("ss", translate("Shadowsocks"))
o:value("ssr", translate("ShadowsocksR"))
o:value("vmess", translate("Vmess"))
o:value("socks5", translate("Socks5"))
o:value("http", translate("HTTP(S)"))
o:value("snell", translate("Snell"))
o:value("trojan", translate("trojan"))
o.description = translate("Using incorrect encryption mothod may causes service fail to start")
o = s:option(Value, "name", translate("Alias"))
o.default = "Server"
o.rmempty = false
o = s:option(Value, "server", translate("Server Address"))
o.datatype = "host"
o.rmempty = false
o = s:option(Value, "port", translate("Server Port"))
o.datatype = "port"
o.rmempty = false
o = s:option(Value, "password", translate("Password"))
o.password = true
o.rmempty = true
o:depends("type", "ss")
o:depends("type", "ssr")
o:depends("type", "trojan")
o = s:option(Value, "psk", translate("Psk"))
o.rmempty = false
o:depends("type", "snell")
o = s:option(ListValue, "cipher", translate("Encrypt Method"))
for _, v in ipairs(encrypt_methods_ss) do o:value(v) end
o.rmempty = true
o:depends("type", "ss")
o = s:option(ListValue, "cipher_ssr", translate("Encrypt Method"))
for _, v in ipairs(encrypt_methods_ssr) do o:value(v) end
o.rmempty = true
o:depends("type", "ssr")
o = s:option(ListValue, "protocol", translate("Protocol"))
for _, v in ipairs(protocol_ssr) do o:value(v) end
o.rmempty = true
o:depends("type", "ssr")
o = s:option(Value, "protocolparam", translate("Protocol Param"))
o.rmempty = true
o:depends("type", "ssr")
o = s:option(ListValue, "obfs_ssr", translate("Obfs"))
for _, v in ipairs(obfs_ssr_list) do o:value(v) end
o.rmempty = true
o:depends("type", "ssr")
o = s:option(ListValue, "obfs_snell", translate("obfs-mode"))
o.rmempty = true
o.default = "none"
o:value("none")
o:value("tls")
o:value("http")
o:depends("type", "snell")
o = s:option(Value, "obfsparam", translate("Obfs Param"))
o.rmempty = true
o:depends("type", "ssr")
o = s:option(ListValue, "securitys", translate("Encrypt Method"))
for _, v in ipairs(securitys) do o:value(v, v:upper()) end
o.rmempty = true
o:depends("type", "vmess")
o = s:option(ListValue, "obfs", translate("obfs-mode"))
o.default = " "
o:value(" ", translate("none"))
o:value("tls")
o:value("http")
o:value("websocket", translate("websocket (ws)"))
o:depends("type", "ss")
o = s:option(ListValue, "obfs_vmess", translate("obfs-mode"))
o.default = "none"
o:value("none")
o:value("websocket", translate("websocket (ws)"))
o:value("http", translate("http"))
o:depends("type", "vmess")
o = s:option(Value, "host", translate("hosts"))
o.datatype = "host"
o.rmempty = true
o:depends("obfs", "tls")
o:depends("obfs", "http")
o:depends("obfs", "websocket")
o:depends("obfs_snell", "tls")
o:depends("obfs_snell", "http")
o = s:option(ListValue, "udp", translate("udp"))
o:value("true")
o:value("false")
o:depends("type", "ss")
o:depends("type", "ssr")
o:depends("type", "vmess")
o:depends("type", "socks5")
o:depends("type", "trojan")
o = s:option(ListValue, "tls_custom", translate("tls"))
o.default = "false"
o:value("true")
o:value("false")
o:depends("obfs", "websocket")
-- [[ WS部分 ]]--
-- WS路径
o = s:option(Value, "path", translate("Path"))
o.rmempty = true
o:depends("obfs", "websocket")
o:depends("obfs_vmess", "websocket")
o = s:option(DynamicList, "http_path", translate("path"))
o.rmempty = true
o:value("/")
o:value("/video")
o:depends("obfs_vmess", "http")
o = s:option(Value, "custom", translate("headers"))
o.rmempty = true
o:depends("obfs", "websocket")
o:depends("obfs_vmess", "websocket")
o = s:option(Value, "keep_alive", translate("keep-alive"))
o.rmempty = true
o.default = "true"
o:value("true")
o:value("false")
o:depends("obfs_vmess", "http")
o = s:option(ListValue, "mux", translate("Mux"))
o.default = "false"
o:value("true")
o:value("false")
o:depends("obfs", "websocket")
-- AlterId
o = s:option(Value, "alterId", translate("AlterId"))
o.datatype = "port"
o.default = 32
o.rmempty = true
o:depends("type", "vmess")
-- VmessId
o = s:option(Value, "uuid", translate("VmessId (UUID)"))
o.rmempty = true
o.default = uuid
o:depends("type", "vmess")
-- 验证用户名
o = s:option(Value, "auth_name", translate("Auth Username"))
o:depends("type", "socks5")
o:depends("type", "http")
o.rmempty = true
-- 验证密码
o = s:option(Value, "auth_pass", translate("Auth Password"))
o:depends("type", "socks5")
o:depends("type", "http")
o.rmempty = true
-- [[ skip-cert-verify ]]--
o = s:option(ListValue, "skip_cert_verify", translate("Skip Cert Verify"))
o.rmempty = true
o.default = "false"
o:value("true")
o:value("false")
o:depends("obfs", "websocket")
o:depends("type", "vmess")
o:depends("type", "socks5")
o:depends("type", "http")
o:depends("obfs_vmess", "none")
o:depends("type", "trojan")
o:depends("obfs_vmess", "websocket")
-- [[ TLS ]]--
o = s:option(ListValue, "tls", translate("TLS"))
o.rmempty = true
o.default = "false"
o:value("true")
o:value("false")
o:depends("obfs", "websocket")
o:depends("obfs_vmess", "none")
o:depends("obfs_vmess", "websocket")
o:depends("obfs_vmess", "http")
o:depends("type", "socks5")
o:depends("type", "http")
o = s:option(Value, "servername", translate("SNI"))
o.rmempty = true
o.datatype = "host"
o.placeholder = translate("example.com")
o:depends("obfs_vmess", "websocket")
-- [[ sni ]]--
o = s:option(Value, "sni", translate("sni"))
o.datatype = "host"
o.placeholder = translate("example.com")
o.rmempty = true
o:depends("type", "trojan")
-- [[ alpn ]]--
o = s:option(Flag, "alpn_h2", translate("alpn-h2"))
o:depends("type", "trojan")
o = s:option(Flag, "alpn_http", translate("alpn-http/1.1"))
o:depends("type", "trojan")
local apply = luci.http.formvalue("cbi.apply")
if apply then
m.uci:commit("clash")
end
return m

View File

@ -1,70 +0,0 @@
local NXFS = require "nixio.fs"
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 clash = "clash"
local http = luci.http
m = Map("clash")
s = m:section(TypedSection, "clash")
m.pageaction = false
s.anonymous = true
s.addremove=false
y = s:option(ListValue, "dnsforwader", translate("DNS Forwarding"))
y:value("0", translate("disabled"))
y:value("1", translate("enabled"))
y.description = translate("Set custom DNS forwarder in DHCP and DNS Settings and forward all dns traffic to clash")
y = s:option(ListValue, "dnscache", translate("DNS Cache"))
y:value("0", translate("disabled"))
y:value("1", translate("enabled"))
y.description = translate("Set to enable or disable dns cache")
y = s:option(ListValue, "access_control", translate("Access Control"))
y:value("0", translate("disabled"))
y:value("1", translate("Whitelist IPs"))
y:value("2", translate("Blacklist Ips"))
y.description = translate("Whitelist or Blacklist IPs to use Clash ( Only support enhanced-mode: redir-host )")
o = s:option(DynamicList, "proxy_lan_ips", translate("Proxy Lan List"))
o.datatype = "ipaddr"
o.description = translate("Only selected IPs will be proxied")
luci.ip.neighbors({ family = 4 }, function(entry)
if entry.reachable then
o:value(entry.dest:string())
end
end)
o:depends("access_control", 1)
o = s:option(DynamicList, "reject_lan_ips", translate("Bypass Lan List"))
o.datatype = "ipaddr"
o.description = translate("Selected IPs will not be proxied")
luci.ip.neighbors({ family = 4 }, function(entry)
if entry.reachable then
o:value(entry.dest:string())
end
end)
o:depends("access_control", 2)
o = s:option(Button, "Apply")
o.title = luci.util.pcdata(translate("Save & Apply"))
o.inputtitle = translate("Save & Apply")
o.inputstyle = "apply"
o.write = function()
m.uci:commit("clash")
if luci.sys.call("pidof clash >/dev/null") == 0 then
SYS.call("/etc/init.d/clash restart >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
else
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash" , "settings", "dns", "advance"))
end
end
return m

View File

@ -1,189 +0,0 @@
local NXFS = require "nixio.fs"
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 clash = "clash"
local http = luci.http
m = Map("clash")
s = m:section(TypedSection, "clash")
--m.pageaction = false
s.anonymous = true
s.addremove=false
y = s:option(Flag, "interf", translate("Interface Name"))
y.default = 1
y.description = translate("Enable Interface Name")
y = s:option(Value, "interf_name", translate("Set Interface Name"))
y.description = translate("Set Interface Name")
y:depends("interf", 1)
y = s:option(Flag, "tun_mode", translate("Tun Mode"))
y.default = 0
y.description = translate("Enable Tun and make sure you are using tun supported core")
y = s:option(ListValue, "stack", translate("Stack"))
y:value("system", translate("system"))
y:value("gvisor", translate("gvisor"))
y.description = translate("Select Stack Mode")
y:depends("tun_mode", 1)
y = s:option(Flag, "enable_dns", translate("Enable Clash DNS"))
y.default = 1
y.description = translate("Enable Clash DNS")
y = s:option(Value, "listen_port", translate("DNS Listen Port"))
y.description = translate("Set DNS Listen Port")
y.default = "5300"
y = s:option(DynamicList, "default_nameserver", translate("Default NameServer"))
y.description = translate("Default Nameserver List")
y = s:option(ListValue, "enhanced_mode", translate("Enhanced Mode"))
y:value("redir-host", translate("Redir Host"))
y:value("fake-ip", translate("Fake IP"))
y.description = translate("Select Enhanced Mode")
y = s:option(Value, "fake_ip_range", translate("Fake IP Range"))
y.description = translate("Set Fake IP Range")
y.default = "198.18.0.1/16"
y:depends("enhanced_mode", "fake-ip")
y = s:option(DynamicList, "fake_ip_filter", translate("Fake IP Filter"))
y.description = translate("Fake IP Filter List")
y.default = "*.lan"
y:depends("enhanced_mode", "fake-ip")
s = m:section(TypedSection, "dnshijack", translate("DNS Hijack"))
s.anonymous = true
s.addremove = true
s.sortable = false
s.template = "cbi/tblsection"
s.rmempty = false
o = s:option(Flag, "enabled", translate("Enable"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
o = s:option(ListValue, "type", translate("Protocol"))
o:value("none", translate("No Protocol"))
o:value("tcp://", translate("TCP"))
o:value("udp://", translate("UDP"))
o:value("tls://", translate("TLS"))
o:value("https://", translate("HTTPS"))
o.default = "none"
o.rempty = false
o = s:option(Value, "ip", translate("Address"))
o.placeholder = translate("Not Null")
o.datatype = "or(host, string)"
o.rmempty = true
o = s:option(Value, "port", translate("Port"))
o.datatype = "port"
o.rempty = true
s = m:section(TypedSection, "authentication", translate("Authentication"))
s.anonymous = true
s.addremove = true
s.sortable = false
s.template = "cbi/tblsection"
s.rmempty = false
o = s:option(Flag, "enabled", translate("Enable"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
o = s:option(Value, "username", translate("Username"))
o.placeholder = translate("Cannot be Empty")
o.rempty = true
o = s:option(Value, "password", translate("Password"))
o.placeholder = translate("Cannot be Empty")
o.rmempty = true
s = m:section(TypedSection, "hosts", translate("Hosts"))
s.anonymous = true
s.addremove = true
s.sortable = false
s.template = "cbi/tblsection"
s.rmempty = false
o = s:option(Flag, "enabled", translate("Enable"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
o = s:option(Value, "address", translate("Address"))
o.placeholder = translate("Cannot be Empty")
o.rempty = true
o = s:option(Value, "ip", translate("IP"))
o.placeholder = translate("Cannot be Empty")
o.rmempty = true
s = m:section(TypedSection, "dnsservers", translate("Nameservers & Fallback"))
s.anonymous = true
s.addremove = true
s.sortable = false
s.template = "cbi/tblsection"
s.rmempty = false
o = s:option(Flag, "enabled", translate("Enable"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
o = s:option(ListValue, "ser_type", translate("Type"))
o:value("nameserver", translate("NameServer"))
o:value("fallback", translate("FallBack"))
o = s:option(ListValue, "protocol", translate("Protocol"))
o:value("none", translate("No Protocol"))
o:value("tcp://", translate("TCP"))
o:value("udp://", translate("UDP"))
o:value("tls://", translate("TLS"))
o:value("https://", translate("HTTPS"))
o = s:option(Value, "ser_address", translate("Address"))
o.placeholder = translate("Not Empty")
o.rmempty = false
o = s:option(Value, "ser_port", translate("Port"))
local apply = luci.http.formvalue("cbi.apply")
if apply then
m.uci:commit("clash")
if luci.sys.call("pidof clash >/dev/null") == 0 then
SYS.call("/etc/init.d/clash restart >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
end
end
return m

View File

@ -1,117 +0,0 @@
local NXFS = require "nixio.fs"
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")
m.pageaction = false
s.anonymous = true
o = s:option(Value, "http_port")
o.title = translate("Http Port")
o.default = 7890
o.datatype = "port"
o.rmempty = false
o.description = translate("Http Port")
o = s:option(Value, "socks_port")
o.title = translate("Socks Port")
o.default = 7891
o.datatype = "port"
o.rmempty = false
o.description = translate("Socks Port")
o = s:option(Value, "redir_port")
o.title = translate("Redir Port")
o.default = 7892
o.datatype = "port"
o.rmempty = false
o.description = translate("Redir Port")
o = s:option(Value, "mixed_port")
o.title = translate("Mixed Port")
o.default = 7893
o.datatype = "port"
o.rmempty = false
o.description = translate("Mixed Port")
o = s:option(ListValue, "allow_lan")
o.title = translate("Allow Lan")
o.default = true
o.rmempty = false
o:value("true", "true")
o:value("false", "false")
o.description = translate("Allow Lan")
o = s:option(ListValue, "enable_ipv6")
o.title = translate("Enable IPv6")
o.default = false
o.rmempty = false
o:value("true", "true")
o:value("false", "false")
o.description = translate("Enable IPv6")
o = s:option(Value, "bind_addr")
o.title = translate("Bind Address")
o:value("*", translate("Bind All IP Addresses"))
luci.ip.neighbors({ family = 4 }, function(entry)
if entry.reachable then
o:value(entry.dest:string())
end
end)
luci.ip.neighbors({ family = 6 }, function(entry)
if entry.reachable then
o:value(entry.dest:string())
end
end)
o.description = translate("Bind Address")
o:depends("allow_lan", "true")
o = s:option(Value, "dash_port")
o.title = translate("Dashboard Port")
o.default = 9090
o.datatype = "port"
o.rmempty = false
o.description = translate("Dashboard Port")
o = s:option(Value, "dash_pass")
o.title = translate("Dashboard Secret")
o.default = 123456
o.rmempty = false
o.description = translate("Dashboard Secret")
o = s:option(ListValue, "p_mode", translate("Proxy Mode"))
o.description = translate("Choose proxy mode")
o:value("rule", translate("RULE"))
o:value("global", translate("GLOBAL"))
o:value("Script", translate("SCRIPT"))
o:value("direct", translate("DIRECT"))
o.default = "Rule"
o = s:option(ListValue, "level", translate("Log level"))
o.description = translate("Choose Log Level")
o:value("info", "info")
o:value("silent", "silent")
o:value("warning", "warning")
o:value("error", "error")
o:value("debug", "debug")
o = s:option(Button, "Apply")
o.title = luci.util.pcdata(translate("Save & Apply"))
o.inputtitle = translate("Save & Apply")
o.inputstyle = "apply"
o.write = function()
m.uci:commit("clash")
if luci.sys.call("pidof clash >/dev/null") == 0 then
SYS.call("/etc/init.d/clash restart >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
else
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash" , "settings", "port"))
end
end
return m

View File

@ -1,64 +0,0 @@
local m, s, o
local clash = "clash"
local uci = luci.model.uci.cursor()
--local fs = require "nixio.fs"
local sys = require "luci.sys"
local sid = arg[1]
local fs = require "luci.clash"
m = Map(clash, translate("Edit Game Rule & Group"))
--m.pageaction = false
m.redirect = luci.dispatcher.build_url("admin/services/clash/settings/grules")
if m.uci:get(clash, sid) ~= "game" then
luci.http.redirect(m.redirect)
return
end
function IsRuleFile(e)
e=e or""
local e=string.lower(string.sub(e,-6,-1))
return e==".rules"
end
-- [[ Groups Setting ]]--
s = m:section(NamedSection, sid, "game")
s.anonymous = true
s.addremove = false
o = s:option(Value, "tag")
o.title = translate("Rule Tag")
o.rmempty = false
o.description = translate("Give a special name for your rules")
---- Proxy Group
o = s:option(ListValue, "group", translate("Select Proxy Group"))
uci:foreach("clash", "conf_groups",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
end
end)
o:value("DIRECT")
o:value("REJECT")
o.rmempty = true
o.description = translate("Select a policy group to add rule")
---- rule name
o = s:option(DynamicList, "rule_name", translate("Game Rule's Name"))
local e,a={}
for t,f in ipairs(fs.glob("/usr/share/clash/rules/g_rules/*"))do
a=fs.stat(f)
if a then
e[t]={}
e[t].filename=fs.basename(f)
if IsRuleFile(e[t].filename) then
e[t].name=luci.sys.exec(string.format("grep -F '%s' /usr/share/clash/rules/rules.list | awk -F ',' '{print $2}'",e[t].filename))
o:value(e[t].filename)
end
end
end
o.rmempty = true
return m

View File

@ -1,179 +0,0 @@
local k, m, s, o, f
local clash = "clash"
local NXFS = require "nixio.fs"
local SYS = require "luci.sys"
local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"
local fs = require "luci.clash"
local uci = require "luci.model.uci".cursor()
font_red = [[<font color="red">]]
font_blue = [[<font color="blue">]]
font_off = [[</font>]]
bold_on = [[<strong>]]
bold_off = [[</strong>]]
m = Map(clash)
m.pageaction = false
m.description=''..font_red..bold_on..translate("Usage Steps:")..bold_off..font_off..' '
.."<br />"
..font_blue..bold_on..translate("1.Load Policy Group, make sure you have selected a config on config page")..bold_off..font_off..' '
.."<br />"
..font_blue..bold_on..translate("2.Download the game rules you want to use from the game rules list on this page")..bold_off..font_off..' '
.."<br />"
..font_blue..bold_on..translate("3. Make sure your game and servers support UDP")..bold_off..font_off..' '
.."<br />"
..font_blue..bold_on..translate("4.Click on ADD, Set the corresponding policy group of the downloaded game rules and save, recommended: FallBack")..bold_off..font_off..' '
.."<br />"
..font_blue..bold_on..translate("5.Select ClashTun Core type and start client")..bold_off..font_off..' '
SYS.call("awk -F ',' '{print $1}' /usr/share/clash/rules/rules.list > /tmp/rules_name 2>/dev/null")
file = io.open("/tmp/rules_name", "r");
r = m:section(TypedSection, "conf_groups", translate("Policy Groups"))
r.anonymous = true
r.addremove = false
r.sortable = false
r.template = "cbi/tblsection"
--r.extedit = luci.dispatcher.build_url("admin/services/clash/g-groups/%s")
function r.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(r.extedit % sid)
return
end
end
o = r:option(DummyValue, "type", translate("Group Type"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = r:option(DummyValue, "name", translate("Group Name"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
-- [[ Edit Game Rule ]] --
r = m:section(TypedSection, "game", translate("Game Rules & Groups"))
r.anonymous = true
r.addremove = true
r.sortable = false
r.template = "cbi/tblsection"
r.extedit = luci.dispatcher.build_url("admin/services/clash/g-rules/%s")
function r.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(r.extedit % sid)
return
end
end
o = r:option(DummyValue, "tag", translate("Game Rule Tag"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = r:option(DummyValue, "group", translate("Policy Groups"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
---- Rules List
local e={},a,o,t
a=nixio.fs.access("/tmp/rules_name")
if a then
for o in file:lines() do
table.insert(e,o)
end
for t,o in ipairs(e) do
e[t]={}
e[t].num=string.format(t)
e[t].name=o
e[t].filename=string.sub(luci.sys.exec(string.format("grep -F '%s,' /usr/share/clash/rules/rules.list |awk -F ',' '{print $3}' 2>/dev/null",e[t].name)),1,-2)
if e[t].filename == "" then
e[t].filename=string.sub(luci.sys.exec(string.format("grep -F '%s,' /usr/share/clash/rules/rules.list |awk -F ',' '{print $2}' 2>/dev/null",e[t].name)),1,-2)
end
RULE_FILE="/usr/share/clash/rules/g_rules/".. e[t].filename
if fs.mtime(RULE_FILE) then
e[t].mtime=os.date("%Y-%m-%d %H:%M:%S",fs.mtime(RULE_FILE))
else
e[t].mtime="/"
end
if fs.isfile(RULE_FILE) then
e[t].exist=translate("Exist")
else
e[t].exist=translate("Not Exist")
end
e[t].remove=0
end
end
file:close()
f=Form("filelist", translate("Game Rules List"))
tb=f:section(Table,e)
nu=tb:option(DummyValue,"num",translate("Order Number"))
st=tb:option(DummyValue,"exist",translate("State"))
--nm=tb:option(DummyValue,"name",translate("Rule Name"))
fm=tb:option(DummyValue,"filename",translate("File Name"))
mt=tb:option(DummyValue,"mtime",translate("Update Time"))
btnis=tb:option(DummyValue,"filename",translate("Download Rule"))
btnis.template="clash/game_rule"
btnrm=tb:option(Button,"remove",translate("Remove"))
btnrm.render=function(e,t,a)
e.inputstyle="reset"
Button.render(e,t,a)
end
btnrm.write=function(a,t)
local a=fs.unlink("/usr/share/clash/rules/g_rules/"..e[t].filename)
HTTP.redirect(luci.dispatcher.build_url("admin", "services", "clash", "settings", "grules"))
end
local t = {
{Load,Apply}
}
k = Form("apply")
k.reset = false
k.submit = false
s = k:section(Table, t)
o = s:option(Button, "Load")
o.inputtitle = translate("Load Groups")
o.inputstyle = "apply"
o.write = function()
m.uci:commit("clash")
luci.sys.call("bash /usr/share/clash/load_groups.sh >/dev/null 2>&1 &")
luci.sys.call("sleep 3")
HTTP.redirect(luci.dispatcher.build_url("admin", "services", "clash", "settings", "grules"))
end
o = s:option(Button, "Apply")
o.inputtitle = translate("Save & Apply")
o.inputstyle = "apply"
o.write = function()
m.uci:commit("clash")
if luci.sys.call("pidof clash >/dev/null") == 0 then
SYS.call("/etc/init.d/clash restart >/dev/null 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "clash"))
else
HTTP.redirect(luci.dispatcher.build_url("admin", "services", "clash", "settings", "grules"))
end
end
return m, k, f

View File

@ -1,143 +0,0 @@
local NXFS = require "nixio.fs"
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 clash = "clash"
local http = luci.http
font_red = [[<font color="red">]]
font_off = [[</font>]]
bold_on = [[<strong>]]
bold_off = [[</strong>]]
k = Map(clash)
k.reset = false
k.submit = false
s=k:section(TypedSection, "clash", translate("Local Update GeoIP"))
s.anonymous = true
s.addremove=false
o = s:option(FileUpload, "")
o.description = translate("NB: Upload GEOIP Database file Country.mmdb")
.."<br />"
..translate("https://github.com/Dreamacro/maxmind-geoip/releases")
.."<br />"
..translate("https://raw.githubusercontent.com/alecthw/mmdb_china_ip_list/release/Country.mmdb")
o.title = translate(" ")
o.template = "clash/clash_upload"
um = s:option(DummyValue, "", nil)
um.template = "clash/clash_dvalue"
local dir, fd
dir = "/etc/clash/"
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/"'
SYS.call("chmod + x /etc/clash/Country.mmdb")
if luci.sys.call("pidof clash >/dev/null") == 0 then
SYS.call("/etc/init.d/clash restart >/dev/null 2>&1 &")
end
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
m = Map("clash")
s = m:section(TypedSection, "clash" , translate("Online Update GeoIP"))
m.pageaction = false
s.anonymous = true
s.addremove=false
o = s:option(Flag, "auto_update_geoip", translate("Auto Update"))
o.description = translate("Auto Update GeoIP Database")
o = s:option(ListValue, "auto_update_geoip_time", translate("Update time (every day)"))
for t = 0,23 do
o:value(t, t..":00")
end
o.default=0
o.description = translate("GeoIP Update Time")
o = s:option(ListValue, "up_time", translate("Update Every (Week/Month)"))
o.rmempty = false
o.description = translate("Time For Update (Once a week/Month)")
o:value("weekly", translate("Weekly"))
o:value("monthly", translate("Monthly"))
o = s:option(ListValue, "geoip_update_day", translate("Update Day (Day of Week)"))
o:value("1", translate("Every Monday"))
o:value("2", translate("Every Tuesday"))
o:value("3", translate("Every Wednesday"))
o:value("4", translate("Every Thursday"))
o:value("5", translate("Every Friday"))
o:value("6", translate("Every Saturday"))
o:value("0", translate("Every Sunday"))
update_time = SYS.exec("ls -l --full-time /etc/clash/Country.mmdb|awk '{print $6,$7;}'")
o.description = translate("Update Time")..'- ' ..font_red..bold_on..update_time..bold_off..font_off..' '
o:depends("up_time", "weekly")
o = s:option(ListValue, "geo_update_week", translate("Update Day (Day of Month)"))
o:value("1", translate("Every 1st Day"))
o:value("7", translate("Every 7th Day"))
o:value("14", translate("Every 14th Day"))
o:value("21", translate("Every 21st Day"))
o:value("28", translate("Every 28th Day"))
update_time = SYS.exec("ls -l --full-time /etc/clash/Country.mmdb|awk '{print $6,$7;}'")
o.description = translate("Update Time")..'- ' ..font_red..bold_on..update_time..bold_off..font_off..' '
o:depends("up_time", "monthly")
o = s:option(ListValue, "geoip_source", translate("GeoIP Source"))
o:value("1", translate("MaxMind"))
o:value("2", translate("Github"))
o = s:option(Value, "license_key")
o.title = translate("License Key")
o.description = translate("MaxMind License Key")..translate(" https://www.maxmind.com/en/geolite2/signup")
o.rmempty = true
o:depends("geoip_source", "1")
o=s:option(Button,"update_geoip")
o.inputtitle = translate("Save & Apply")
o.title = luci.util.pcdata(translate("Save & Apply"))
o.inputstyle = "reload"
o.write = function()
m.uci:commit("clash")
end
o = s:option(Button,"download")
o.title = translate("Download")
o.template = "clash/geoip"
return m, k

View File

@ -1,50 +0,0 @@
local NXFS = require "nixio.fs"
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 fs = require "luci.clash"
local http = luci.http
m = Map("clash")
s = m:section(TypedSection, "clash")
m.pageaction = false
s.anonymous = true
s.addremove=false
log = s:option(TextValue, "clog")
log.template = "clash/status_log"
o = s:option(Button, "Download")
o.inputtitle = translate("Download logs")
o.inputstyle = "apply"
o.write = function ()
local sPath, sFile, fd, block
sPath = "/usr/share/clash/clash.txt"
sFile = NXFS.basename(sPath)
if fs.isdirectory(sPath) then
fd = io.popen('txt -C "%s" -cz .' % {sPath}, "r")
sFile = sFile .. ".txt"
else
fd = nixio.open(sPath, "r")
end
if not fd then
return
end
HTTP.header('Content-Disposition', 'attachment; filename="%s"' % {sFile})
HTTP.prepare_content("application/octet-stream")
while true do
block = fd:read(nixio.const.buffersize)
if (not block) or (#block ==0) then
break
else
HTTP.write(block)
end
end
fd:close()
HTTP.close()
end
return m

View File

@ -1,141 +0,0 @@
local NXFS = require "nixio.fs"
local SYS = require "luci.sys"
local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"
local uci = luci.model.uci.cursor()
local fs = require "luci.clash"
local http = luci.http
local clash = "clash"
kk = Map(clash)
s = kk:section(TypedSection, "clash", translate("Auto Update Config"))
s.anonymous = true
kk.pageaction = false
o = s:option(Flag, "auto_update", translate("Auto Update"))
o.description = translate("Auto Update Server subscription")
o = s:option(ListValue, "auto_update_time", translate("Update time (every day)"))
o:value("1", translate("Every Hour"))
o:value("6", translate("Every 6 Hours"))
o:value("12", translate("Every 12 Hours"))
o:value("24", translate("Every 24 Hours"))
o.description = translate("Daily Server subscription update time. Only update config in use")
o = s:option(Button, "Apply")
o.title = luci.util.pcdata(translate("Save & Apply"))
o.inputtitle = translate("Save & Apply")
o.inputstyle = "apply"
o.write = function()
kk.uci:commit("clash")
end
m = Map("clash")
s = m:section(TypedSection, "clash" , translate("Clear Clash Log"))
s.anonymous = true
o = s:option(Flag, "auto_clear_log", translate("Auto Clear Log"))
o.description = translate("Auto Clear Log")
o = s:option(ListValue, "clear_time", translate("Clear Time (Time of Day)"))
o:value("1", translate("Every Hour"))
o:value("6", translate("Every 6 Hours"))
o:value("12", translate("Every 12 Hours"))
o:value("24", translate("Every 24 Hours"))
o.description = translate("Clear Log Time")
o=s:option(Button,"clear_clear")
o.inputtitle = translate("Save & Apply")
o.title = luci.util.pcdata(translate("Save & Apply"))
o.inputstyle = "reload"
o.write = function()
m.uci:commit("clash")
end
w = Map("clash")
s = w:section(TypedSection, "clash" , translate("Load Groups"))
s.anonymous = true
o = s:option(Button, "Load")
o.inputtitle = translate("Load Groups")
o.title = translate("Load Groups")
o.inputstyle = "apply"
o.write = function()
w.uci:commit("clash")
luci.sys.call("bash /usr/share/clash/load_groups.sh >/dev/null 2>&1 &")
luci.sys.call("sleep 4")
HTTP.redirect(luci.dispatcher.build_url("admin", "services", "clash", "settings", "other"))
end
r = w:section(TypedSection, "conf_groups", translate("Policy Groups"))
r.anonymous = true
r.addremove = false
r.sortable = false
r.template = "cbi/tblsection"
function r.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(r.extedit % sid)
return
end
end
o = r:option(DummyValue, "type", translate("Group Type"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = r:option(DummyValue, "name", translate("Group Name"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
y = Map("clash")
x = y:section(TypedSection, "addtype", translate("Custom Rules"))
x.anonymous = true
x.addremove = true
x.sortable = false
x.template = "cbi/tblsection"
x.extedit = luci.dispatcher.build_url("admin/services/clash/ip-rules/%s")
function x.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(x.extedit % sid)
return
end
end
o = x:option(DummyValue, "type", translate("Rule Type"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = x:option(DummyValue, "ipaaddr", translate("IP/Domain/Address/Keyword/Port"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = x:option(DummyValue, "pgroup", translate("Policy Groups"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
return kk, m,w,y

View File

@ -1,13 +0,0 @@
local m
local sys = require "luci.sys"
local uci = luci.model.uci.cursor()
m = Map("clash")
m:section(SimpleSection).template = "clash/status"
m.pageaction = false
return m

View File

@ -1,147 +0,0 @@
local NXFS = require "nixio.fs"
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 m , r, k
local http = luci.http
font_red = [[<font color="red">]]
font_green = [[<font color="green">]]
font_off = [[</font>]]
bold_on = [[<strong>]]
bold_off = [[</strong>]]
ko = Map("clash")
ko.reset = false
ko.submit = false
sul =ko:section(TypedSection, "clash",translate("Manual Upload"))
sul.anonymous = true
sul.addremove=false
o = sul:option(FileUpload, "")
o.description =''..font_red..bold_on..translate("Manually download, unzip and rename clash core from links below and upload")..bold_off..font_off..' '
.."<br />"
..translatef("<a href=\"%s\" target=\"_blank\">" .. "Dreamacro clash core - clash</a>", translate("https://github.com/Dreamacro/clash/releases/latest"))
.."<br />"
..translatef("<a href=\"%s\" target=\"_blank\">" .. "Frainzy1477 clashr core - clash</a>", translate("https://github.com/frainzy1477/clash_dev/releases/latest"))
.."<br />"
..translatef("<a href=\"%s\" target=\"_blank\">" .. "comzyh clash tun core - clash(ctun)</a>", translate("https://github.com/comzyh/clash/releases/latest"))
.."<br />"
..translatef("<a href=\"%s\" target=\"_blank\">" .. "Dreamacro clash tun core - clash(premium)</a>", translate("https://github.com/Dreamacro/clash/releases/tag/premium"))
o.title = translate(" ")
o.template = "clash/upload_core"
um = sul:option(DummyValue, "", nil)
um.template = "clash/clash_dvalue"
local dir, fd,dtun,ctun,cssr
dir = "/etc/clash/"
dtun="/etc/clash/dtun/"
ctun="/etc/clash/clashtun/"
http.setfilehandler(
function(meta, chunk, eof)
local fp = HTTP.formvalue("file_type")
if not fd then
if not meta then return end
if fp == "clash" then
if meta and chunk then fd = nixio.open(dir .. meta.file, "w") end
elseif fp == "clashctun" then
if meta and chunk then fd = nixio.open(ctun .. meta.file, "w") end
elseif fp == "clashdtun" then
if meta and chunk then fd = nixio.open(dtun .. meta.file, "w") end
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
if fp == "clash" then
SYS.exec("chmod 755 /etc/clash/clash 2>&1 &")
SYS.exec("rm -rf /usr/share/clash/core_version 2>/dev/null && /etc/clash/clash -v | awk -F ' ' '{print $2}' >> /usr/share/clash/core_version 2>/dev/null")
um.value = translate("File saved to") .. ' "/etc/clash/'..meta.file..'"'
elseif fp == "clashctun" then
SYS.exec("chmod 755 /etc/clash/clashtun/clash 2>&1 &")
SYS.exec("rm -rf /usr/share/clash/tun_version 2>/dev/null && /etc/clash/clashtun/clash -v | awk -F ' ' '{print $2}' >> /usr/share/clash/tun_version 2>/dev/null")
um.value = translate("File saved to") .. ' "/etc/clash/clashtun/'..meta.file..'"'
elseif fp == "clashdtun" then
SYS.exec("chmod 755 /etc/clash/dtun/clash 2>&1 &")
SYS.exec("rm -rf /usr/share/clash/dtun_core_version 2>/dev/null && /etc/clash/dtun/clash -v | awk -F ' ' '{print $2}' >> /usr/share/clash/dtun_core_version 2>/dev/null")
um.value = translate("File saved to") .. ' "/etc/clash/dtun/'..meta.file..'"'
end
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
m = Map("clash")
m:section(SimpleSection).template = "clash/update"
m.pageaction = false
k = Map("clash")
s = k:section(TypedSection, "clash",translate("Download Online"))
s.anonymous = true
o = s:option(ListValue, "dcore", translate("Core Type"))
o.default = "clashcore"
o:value("1", translate("clash"))
o:value("3", translate("clash(ctun)"))
o:value("4", translate("clash(premium)"))
local cpu_model=SYS.exec("opkg status libc 2>/dev/null |grep 'Architecture' |awk -F ': ' '{print $2}' 2>/dev/null")
o = s:option(ListValue, "download_core", translate("Select Core"))
o.description = translate("CPU Model")..': '..font_green..bold_on..cpu_model..bold_off..font_off..' '
o:value("linux-386")
o:value("linux-amd64", translate("linux-amd64(x86-64)"))
o:value("linux-armv5")
o:value("linux-armv6")
o:value("linux-armv7")
o:value("linux-armv8")
o:value("linux-mips-hardfloat")
o:value("linux-mips-softfloat")
o:value("linux-mips64")
o:value("linux-mips64le")
o:value("linux-mipsle-softfloat")
o:value("linux-mipsle-hardfloat")
o=s:option(Button,"down_core")
o.inputtitle = translate("Save & Apply")
o.title = luci.util.pcdata(translate("Save & Apply"))
o.inputstyle = "reload"
o.write = function()
k.uci:commit("clash")
end
o = s:option(Button,"download")
o.title = translate("Download")
o.template = "clash/core_check"
return m, ko,k

View File

@ -1,9 +0,0 @@
<%+cbi/valueheader%>
<span style="color: red">
<%
local val = self:cfgvalue(section) or self.default or ""
write(pcdata(val))
%>
</span>
<%+cbi/valuefooter%>

View File

@ -1,6 +0,0 @@
<%+cbi/valueheader%>
<label class="cbi-value" style="display:inline-block;" for="ulfile"></label>
<input class="cbi-input-file" style="width: 80%" type="file" id="ulfile" name="ulfile" />
<input type="submit" style="width: 100%" class="cbi-button cbi-input-apply" name="upload" value="<%:Upload%>" />
<%+cbi/valuefooter%>

View File

@ -1,23 +0,0 @@
<fieldset class="cbi-section">
<p width="100%" align="center"><font color="blue"><b><%:CONFIG IN USE%>:</b> <b id="_conf_path"></b></font></p>
</fieldset>
<script type="text/javascript">//<![CDATA[
var conf_path = document.getElementById('_conf_path');
XHR.poll(1, '<%=luci.dispatcher.build_url("admin", "services", "clash", "conf")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
if(status.typeconf==1){
conf_path.innerHTML = status.conf_path ? '<b><font color="green"><%:SUBSCRIBE%> 【'+status.conf_path+'】</font></b>' : '<b><font color="red"><%:NOT SELECTED%></font></b>';
}
if(status.typeconf==2){
conf_path.innerHTML = status.conf_path ? '<b><font color="green"><%:UPLOAD%> 【'+status.conf_path+'】</font></b>' : '<b><font color="red"><%:NOT SELECTED%></font></b>';
}
if(status.typeconf==3){
conf_path.innerHTML = status.conf_path ? '<b><font color="green"><%:CUSTOM%> 【'+status.conf_path+'】</font></b>' : '<b><font color="red"><%:NOT SELECTED%></font></b>';
}
}
});
//]]></script>

View File

@ -1,71 +0,0 @@
<%+cbi/valueheader%>
<%local fs=require"nixio.fs"%>
<input type="button" class="cbi-button cbi-button-apply" id="apply_update_button" value="<%:Download%>" onclick=" return apply_update() "/>
<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[
function apply_update(){
XHR.get('<%=url([[admin]], [[services]], [[clash]], [[doupdate]])%>',null,function(x, data){}
);
poll_check();
return
}
function poll_check(){
var lv = document.getElementById('core_download');
lv.style.display="inline"
XHR.poll(2, '<%=url([[admin]], [[services]], [[clash]], [[check]])%>', null,
function(x, data) {
var lv = document.getElementById('core_download');
if (x.responseText && lv) {
lv.innerHTML += x.responseText;
lv.scrollTop = lv.scrollHeight;
}
}
);
}
XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "services", "clash", "corelog")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
if(status.downcheck==0||status.downcheck==2){
hide();
}
if(status.downcheck==1){
var btn = document.getElementById('apply_update_button');
btn.disabled = false;
btn.value = '<%:Download%>';
poll_check();
}
}
});
//]]>
function hide(){
$('#core_download').hide();
var btn = document.getElementById('apply_update_button');
btn.disabled = false;
btn.value = '<%:Download%>';
}
<% if fs.access("/var/run/core_update") then %>
var btn = document.getElementById('apply_update_button');
btn.disabled = true;
btn.value = '<%:Downloading...%>';
poll_check();
<%end%>
</script>
<%+cbi/valuefooter%>

View File

@ -1,38 +0,0 @@
<%+cbi/valueheader%>
<script type="text/javascript">//<![CDATA[
function act_download_rule(btn,filename)
{
btn.disabled = true;
btn.value = '<%:Downloading...%> ';
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "clash","game_rule")%>',
{
filename: filename
},
function(x,status)
{
if ( x && x.status == 200 ) {
if(status.game_rule=="0")
{
btn.value = '<%:Error%>';
}
else
{
btn.value = '<%:Successful%>';
window.location.reload();
}
}
else {
btn.value = '<%:Timeout%>';
}
}
);
btn.disabled = false;
return false;
}
//]]></script>
<input type="button" class="cbi-button cbi-input-reload" value="<%:Update Rule%>" onclick="return act_download_rule(this,'<%=self:cfgvalue(section)%>')" />
<%+cbi/valuefooter%>

View File

@ -1,72 +0,0 @@
<%+cbi/valueheader%>
<%local fs=require"nixio.fs"%>
<input type="button" class="cbi-button cbi-button-apply" id="apply_update_geoip" value="<%:Download%>" onclick=" return apply_update() "/>
<br /><br />
<textarea id="geoip_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[
function apply_update(){
XHR.get('<%=url([[admin]], [[services]], [[clash]], [[geoipupdate]])%>',null,function(x, data){}
);
poll_check();
return
}
function poll_check(){
var lv = document.getElementById('geoip_download');
lv.style.display="inline"
XHR.poll(2, '<%=url([[admin]], [[services]], [[clash]], [[check_geoip]])%>', null,
function(x, data) {
var lv = document.getElementById('geoip_download');
if (x.responseText && lv) {
lv.innerHTML += x.responseText;
lv.scrollTop = lv.scrollHeight;
}
}
);
}
XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "services", "clash", "geo")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
if(status.geoipcheck==0||status.geoipcheck==2){
hide();
}
if(status.geoipcheck==1){
var btn = document.getElementById('apply_update_geoip');
btn.disabled = false;
btn.value = '<%:Download%>';
poll_check();
}
}
});
//]]>
function hide(){
$('#geoip_download').hide();
var btn = document.getElementById('apply_update_geoip');
btn.disabled = false;
btn.value = '<%:Download%>';
}
<% if fs.access("/var/run/geoip_update") then %>
var btn = document.getElementById('apply_update_geoip');
btn.disabled = true;
btn.value = '<%:Downloading...%>';
poll_check();
<%end%>
</script>
<%+cbi/valuefooter%>

View File

@ -1,47 +0,0 @@
<%
local dsp = require "luci.dispatcher"
-%>
<script type="text/javascript">
//<![CDATA[
var pings = document.getElementsByClassName('ping');
for(var i = 0; i < pings.length; i++) {
XHR.get('<%=dsp.build_url("admin", "services", "clash", "ping")%>', {
index: i,
domain: pings[i].getAttribute("hint")
},
function(x, result) {
if (result.ping < 500) {
pings[result.index].innerHTML = (result.ping ? "<b><font color='#ee1010'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
}
if (result.ping < 200){
pings[result.index].innerHTML = (result.ping ? "<b><font color='#7acc03'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
}
if (result.ping < 100){
pings[result.index].innerHTML = (result.ping ? "<b><font color='#007e1a'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
}
}
);
XHR.poll(20,'<%=dsp.build_url("admin", "services", "clash", "ping")%>',{
index: i,
domain: pings[i].getAttribute("hint")
},
function(x, result) {
if (result.ping < 500) {
pings[result.index].innerHTML = (result.ping ? "<b><font color='#ee1010'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
}
if (result.ping < 200){
pings[result.index].innerHTML = (result.ping ? "<b><font color='#7acc03'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
}
if (result.ping < 100){
pings[result.index].innerHTML = (result.ping ? "<b><font color='#007e1a'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
}
}
);
}
//]]>
</script>

View File

@ -1,7 +0,0 @@
<%+cbi/valueheader%>
<% if self:cfgvalue(section) ~= false then %>
<input class="cbi-button cbi-input-<%=self.inputstyle or "button" %>" style="display: <%= display %>" type="submit"<%= attr("name", cbid) .. attr("id", cbid) .. attr("value", self.inputtitle or self.title)%> />
<% else %>
-
<% end %>
<%+cbi/valuefooter%>

View File

@ -1,5 +0,0 @@
<%+cbi/valueheader%>
<span class="ping" hint="<%=self:cfgvalue(section)%>"><%:Checking...%></span>
<%+cbi/valuefooter%>

View File

@ -1,41 +0,0 @@
<%+cbi/valueheader%>
<script type="text/javascript">//<![CDATA[
function act_download_rule(btn,filename)
{
btn.disabled = true;
btn.value = '<%:Downloading...%> ';
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "clash","ruleproviders")%>',
{
filename: filename
},
function(x,status)
{
if ( x && x.status == 200 ) {
if(status.rulep=="0")
{
btn.value = '<%:Error%>';
}
else if (status.rulep=="1")
{
btn.value = '<%:Successful%>';
window.location.reload();
}else if (status.rulep=="2")
{
btn.value = '<%:Not Updated%>';
}
}
else {
btn.value = '<%:Timeout%>';
}
}
);
btn.disabled = false;
return false;
}
//]]></script>
<input type="button" class="cbi-button cbi-input-reload" value="<%:Update Rule Providers%>" onclick="return act_download_rule(this,'<%=self:cfgvalue(section)%>')" />
<%+cbi/valuefooter%>

View File

@ -1,252 +0,0 @@
<%+cbi/valueheader%>
<script type="text/javascript">//<![CDATA[
function padright(str, cnt, pad) {
return str + Array(cnt + 1).join(pad);
}
function b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
function b64encutf8safe(str) {
return b64EncodeUnicode(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, '');
}
function b64DecodeUnicode(str) {
return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
function b64decutf8safe(str) {
var l;
str = str.replace(/-/g, "+").replace(/_/g, "/");
l = str.length;
l = (4 - l % 4) % 4;
if (l)
str = padright(str, l, "=");
return b64DecodeUnicode(str);
}
function b64encsafe(str) {
return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, '')
}
function b64decsafe(str) {
var l;
str = str.replace(/-/g, "+").replace(/_/g, "/");
l = str.length;
l = (4 - l % 4) % 4;
if (l)
str = padright(str, l, "=");
return atob(str);
}
function dictvalue(d, key) {
var v = d[key];
if (typeof (v) == 'undefined' || v == '')
return '';
return b64decsafe(v);
}
function import_ssr_url(btn, urlname, sid) {
var s = document.getElementById(urlname + '-status');
if (!s)
return false;
var ssrurl = prompt("ssr:// | ss:// | vmess:// | trojan://", "");
if (ssrurl == null || ssrurl == "") {
s.innerHTML = "<font color='red'><%:Operation Aborted%></font>";
return false;
}
s.innerHTML = "";
//var ssu = ssrurl.match(/ssr:\/\/([A-Za-z0-9_-]+)/i);
var ssu = ssrurl.split('://');
console.log(ssu.length);
if ((ssu[0] != "ssr" && ssu[0] != "ss" && ssu[0] != "vmess" && ssu[0] != "trojan") || ssu[1] == "") {
s.innerHTML = "<font color='red'><%:Invalid link%></font>";
return false;
}
var event = document.createEvent("HTMLEvents");
event.initEvent("change", true, true);
if (ssu[0] == "ssr") {
var sstr = b64decsafe(ssu[1]);
var ploc = sstr.indexOf("/?");
document.getElementById('cbid.clash.' + sid + '.type').value = "ssr";
document.getElementById('cbid.clash.' + sid + '.type').dispatchEvent(event);
var url0, param = "";
if (ploc > 0) {
url0 = sstr.substr(0, ploc);
param = sstr.substr(ploc + 2);
}
var ssm = url0.match(/^(.+):([^:]+):([^:]*):([^:]+):([^:]*):([^:]+)/);
if (!ssm || ssm.length < 7)
return false;
var pdict = {};
if (param.length > 2)
{
var a = param.split('&');
for (var i = 0; i < a.length; i++) {
var b = a[i].split('=');
pdict[decodeURIComponent(b[0])] = decodeURIComponent(b[1] || '');
}
}
document.getElementById('cbid.clash.' + sid + '.server').value = ssm[1];
document.getElementById('cbid.clash.' + sid + '.port').value = ssm[2];
document.getElementById('cbid.clash.' + sid + '.protocol').value = ssm[3];
document.getElementById('cbid.clash.' + sid + '.cipher_ssr').value = ssm[4];
document.getElementById('cbid.clash.' + sid + '.obfs_ssr').value = ssm[5];
document.getElementById('cbid.clash.' + sid + '.password').value = b64decsafe(ssm[6]);
document.getElementById('cbid.clash.' + sid + '.obfsparam').value = dictvalue(pdict, 'obfsparam');
document.getElementById('cbid.clash.' + sid + '.protocolparam').value = dictvalue(pdict, 'protoparam');
var rem = pdict['remarks'];
if (typeof (rem) != 'undefined' && rem != '' && rem.length > 0)
document.getElementById('cbid.clash.' + sid + '.name').value = b64decutf8safe(rem);
s.innerHTML = "<font color='green'><%:Import ShadowsocksR config info successful%></font>";
return false;
} else if (ssu[0] == "ss") {
var sipIndex = ssu[1].split("@");
var sstr = b64decsafe(sipIndex[0]);
var ssm = sstr.split(':');
var team = sipIndex[1].split(':');
//var obfs = port[1].split('=');
var temp = ssu[1].split("?");
if (temp[1]) {
var pluginInfo = decodeURIComponent(temp[1]);
}
document.getElementById('cbid.clash.' + sid + '.type').value = "ss";
document.getElementById('cbid.clash.' + sid + '.type').dispatchEvent(event);
document.getElementById('cbid.clash.' + sid + '.server').value = team[0];
document.getElementById('cbid.clash.' + sid + '.password').value = ssm[1];
document.getElementById('cbid.clash.' + sid + '.cipher').value = ssm[0];
if (temp[1]) {
var name = pluginInfo.split("#");
var port = team[1].split('?');
var obfslocal = name[0].split(';')
var obfs = obfslocal[1].split('=')
var obfshost = obfslocal[2].split('=')
document.getElementById('cbid.clash.' + sid + '.port').value = port[0];
document.getElementById('cbid.clash.' + sid + '.name').value = name[1];
document.getElementById('cbid.clash.' + sid + '.obfs').value = obfs[1];
document.getElementById('cbid.clash.' + sid + '.obfs').dispatchEvent(event);
document.getElementById('cbid.clash.' + sid + '.host').value = obfshost[1];
}
if (!temp[1]) {
var name2 = sipIndex[1].split('#');
var port = name2[0].split(':');
document.getElementById('cbid.clash.' + sid + '.port').value = port[1];
document.getElementById('cbid.clash.' + sid + '.name').value = name2[1];
document.getElementById('cbid.clash.' + sid + '.obfs').value = " ";
document.getElementById('cbid.clash.' + sid + '.obfs').dispatchEvent(event);
}
s.innerHTML = "<font color='green'><%:Import Shadowsocks config info successful%></font>";
return false;
} else if (ssu[0] == "trojan") {
var url0, param = "";
var ploc = ssu[1].indexOf("#");
if (ploc > 0) {
url0 = ssu[1].substr(0, ploc);
param = ssu[1].substr(ploc + 1);
} else {
url0 = ssu[1]
}
var sstr = url0;
var name = ssrurl.split('#');
document.getElementById('cbid.clash.' + sid + '.type').value = "trojan";
document.getElementById('cbid.clash.' + sid + '.type').dispatchEvent(event);
var team = sstr.split('@');
var password = team[0]
var serverPart = team[1].split(':');
var others = serverPart[1].split('?');
var port = others[0]
var queryParam = {}
if(others.length > 1) {
var queryParams = others[1]
var queryArray = queryParams.split('&')
for (i = 0; i < queryArray.length; i++) {
var params = queryArray[i].split('=');
queryParam[decodeURIComponent(params[0])] = decodeURIComponent(params[1] || '');
}
}
document.getElementById('cbid.clash.' + sid + '.name').value = name[1];
document.getElementById('cbid.clash.' + sid + '.server').value = serverPart[0];
document.getElementById('cbid.clash.' + sid + '.port').value = port;
document.getElementById('cbid.clash.' + sid + '.password').value = password;
document.getElementById('cbid.clash.' + sid + '.sni').value = serverPart[0];
document.getElementById('cbid.clash.' + sid + '.alpn_http').checked = true;
document.getElementById('cbid.clash.' + sid + '.alpn_h2').checked = false;
s.innerHTML = "<font color='green'><%:Import Trojan config info successful%></font>";
return false;
} else if (ssu[0] == "vmess") {
var sstr = b64DecodeUnicode(ssu[1]);
var ploc = sstr.indexOf("/?");
document.getElementById('cbid.clash.' + sid + '.type').value = "vmess";
document.getElementById('cbid.clash.' + sid + '.type').dispatchEvent(event);
var url0, param = "";
if (ploc > 0) {
url0 = sstr.substr(0, ploc);
param = sstr.substr(ploc + 2);
}
var ssm = JSON.parse(sstr);
document.getElementById('cbid.clash.' + sid + '.name').value = ssm.ps;
document.getElementById('cbid.clash.' + sid + '.server').value = ssm.add;
document.getElementById('cbid.clash.' + sid + '.port').value = ssm.port;
document.getElementById('cbid.clash.' + sid + '.alterId').value = ssm.aid;
document.getElementById('cbid.clash.' + sid + '.uuid').value = ssm.id;
if (ssm.net == "tcp") {
document.getElementById('cbid.clash.' + sid + '.obfs_vmess').value = "none";
document.getElementById('cbid.clash.' + sid + '.obfs_vmess').dispatchEvent(event);
if (ssm.tls == "tls" || ssm.tls == "1" || ssm.tls == "true") {
document.getElementById('cbid.clash.' + sid + '.tls').value = "true";
document.getElementById('cbid.clash.' + sid + '.tls').dispatchEvent(event);
}
}
if (ssm.net == "ws") {
document.getElementById('cbid.clash.' + sid + '.obfs_vmess').value = "websocket";
document.getElementById('cbid.clash.' + sid + '.obfs_vmess').dispatchEvent(event);
document.getElementById('cbid.clash.' + sid + '.path').value = ssm.path;
document.getElementById('cbid.clash.' + sid + '.custom').value = ssm.host;
if (ssm.tls == "tls" || ssm.tls == "1" || ssm.tls == "true") {
document.getElementById('cbid.clash.' + sid + '.tls').value = "true";
document.getElementById('cbid.clash.' + sid + '.tls').dispatchEvent(event);
}
}
if (ssm.net == "h2") {
document.getElementById('cbid.clash.' + sid + '.obfs_vmess').value = "http";
document.getElementById('cbid.clash.' + sid + '.obfs_vmess').dispatchEvent(event);
document.getElementById('cbid.clash.' + sid + '.http_path').value = ssm.path;
document.getElementById('cbid.clash.' + sid + '.keep_alive').checked = true;
document.getElementById('cbid.clash.' + sid + '.keep_alive').dispatchEvent(event);
if (ssm.tls == "tls" || ssm.tls == "1" || ssm.tls == "true") {
document.getElementById('cbid.clash.' + sid + '.tls').value = "true";
document.getElementById('cbid.clash.' + sid + '.tls').dispatchEvent(event);
}
}
s.innerHTML = "<font color='green'><%:Import V2ray config info successful%></font>";
return false;
}
}
//]]></script>
<input type="button" class="cbi-button cbi-button-apply" value="<%:Import config info%>" onclick="return import_ssr_url(this, '<%=self.option%>', '<%=self.value%>')" />
<span id="<%=self.option%>-status"></span>
<%+cbi/valuefooter%>

View File

@ -1,34 +0,0 @@
<%+cbi/valueheader%>
<input type="button" class="cbi-button cbi-button-apply" value="<%:Start%>" onclick=" return start() "/>
<input type="button" class="cbi-button cbi-button-apply" value="<%:Stop%>" onclick=" return stop() "/>
<input type="button" class="cbi-button cbi-button-apply" value="<%:Reload%>" onclick=" return reload() "/>
<script type="text/javascript">
//<![CDATA[
function start(){
XHR.get('<%=url([[admin]], [[services]], [[clash]], [[start]])%>',null,function(x, data){}
);
window.setTimeout("location.href='/cgi-bin/luci/admin/services/clash/'", 500);
return
}
function stop(){
XHR.get('<%=url([[admin]], [[services]], [[clash]], [[stop]])%>',null,function(x, data){}
);
window.setTimeout("location.href='/cgi-bin/luci/admin/services/clash/'", 500);
return
}
function reload(){
XHR.get('<%=url([[admin]], [[services]], [[clash]], [[reload]])%>',null,function(x, data){}
);
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

View File

@ -1,22 +0,0 @@
<%+cbi/valueheader%>
<textarea id="log" class="cbi-input-textarea" style="width: 100%;" data-update="change" rows="29" readonly="readonly" > </textarea>
<script type="text/javascript">//<![CDATA[
var lv = document.getElementById('log');
lv.style.display="inline"
XHR.poll(1, '<%=url([[admin]], [[services]], [[clash]], [[logstatus]])%>', null,
function(x, data) {
var lv = document.getElementById('log');
if (x.responseText && lv) {
lv.innerHTML += x.responseText;
lv.scrollTop = lv.scrollHeight;
}
}
);
//]]>
</script>
<%+cbi/valuefooter%>

View File

@ -1,6 +0,0 @@
<%+cbi/valueheader%>
<textarea class="cbi-input-textarea" style="width: 100%" rows="30" cols="45" data-update="change" <%= attr("name", cbid) .. attr("id", cbid) %>>
<%-=pcdata(self:cfgvalue(section))-%>
</textarea>
<%+cbi/valuefooter%>

View File

@ -1,94 +0,0 @@
<fieldset class="cbi-section">
<table width="100%" cellspacing="10">
<thead align="center">
<tr>
<th align="center"><%:App Name%></th>
<th align="center"><%:Installed Version%></th>
<th align="center"><%:New Version%></th>
</tr>
</thead>
<tbody>
<tr>
<td align="center" width="35%">clash</td> <td align="center" width="35%" id="_core"><%:Collecting data...%></td> <td width="35%" align="center" id="_corebutt"><font color="red"><%:Checking...%></font> </td>
</tr>
<tr>
<td align="center" width="35%">clash(ctun)</td> <td align="center" width="35%" id="_coretun"><%:Collecting data...%></td> <td width="35%" align="center" id="_coretunbutt"><font color="red"><%:Checking...%></font> </td>
</tr>
<tr>
<td align="center" width="35%">clash(premium)</td> <td align="center" width="35%" id="_coredtun"><%:Collecting data...%></td> <td width="35%" align="center" id="_coredtunbutt"><font color="red"><%:Checking...%></font> </td>
</tr>
<tr>
<td align="center" width="35%">luci-app-clash</td> <td align="center" width="35%" id="_version"><%:Collecting data...%> </td> <td width="35%" align="center" id="_versionbutt"><font color="red"><%:Checking...%></font> </td>
</tr>
</tbody>
</table>
</fieldset>
<script type="text/javascript">//<![CDATA[
var version = document.getElementById('_version');
var core = document.getElementById('_core');
var coretun = document.getElementById('_coretun');
var version_butt = document.getElementById('_versionbutt');
var core_butt = document.getElementById('_corebutt');
var corer_butt = document.getElementById('_corerbutt');
var coretun_butt = document.getElementById('_coretunbutt');
var coredtun = document.getElementById('_coredtun');
var coredtun_butt = document.getElementById('_coredtunbutt');
XHR.poll(1, '<%=luci.dispatcher.build_url("admin", "services", "clash", "status")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
if(status.clash_core==0){
core.innerHTML = status.clash_core ? '<b><font color="red"><%:Not Installed%></font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
}else{
core.innerHTML = status.clash_core ? '<b><font color="green">'+status.clash_core+'</font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
}
if(status.clashtun_core==0){
coretun.innerHTML = status.clashtun_core ? '<b><font color="red"><%:Not Installed%></font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
}else{
coretun.innerHTML = status.clashtun_core ? '<b><font color="green">'+status.clashtun_core+'</font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
}
if(status.dtun_core==0){
coredtun.innerHTML = status.dtun_core ? '<b><font color="red"><%:Not Installed%></font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
}else{
coredtun.innerHTML = status.dtun_core ? '<b><font color="green">'+status.dtun_core+'</font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
}
version.innerHTML = status.current_version ? '<b><font color="green">'+status.current_version+'</font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
}
});
XHR.poll(5,'<%=luci.dispatcher.build_url("admin", "services", "clash", "check_status")%>', null, function(x, status) {});
XHR.poll(1,'<%=luci.dispatcher.build_url("admin", "services", "clash", "status")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
version_butt.innerHTML = status.current_version ? '<b><font color="green">'+status.new_version+'</font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
core_butt.innerHTML = status.current_version ? '<b><font color="green">'+status.new_core_version+'</font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
coretun_butt.innerHTML = status.current_version ? '<b><font color="green">'+status.new_clashtun_core_version+'</font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
coredtun_butt.innerHTML = status.current_version ? '<b><font color="green">'+status.new_dtun_core+'</font> </b>' : '<em><b><font color="red"><%:Checking...%></font></b></em>';
}
});
//]]></script>

View File

@ -1,11 +0,0 @@
<%+cbi/valueheader%>
<select name="file_type" style="width:20%">&nbsp;&nbsp;&nbsp;
<option value="clash" selected="selected"><%:clash%></option>
<option value="clashctun"><%:clash(ctun)%></option>
<option value="clashdtun"><%:clash(premium)%></option>
</select>
<input class="cbi-input-file" style="width: 60%" type="file" id="ulfile" name="ulfile" />
<input type="submit" style="width: 100%" class="cbi-button cbi-input-apply" name="upload" value="<%:Upload%>" />
<%+cbi/valuefooter%>

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
zh-cn

View File

@ -1,116 +0,0 @@
config clash 'config'
option redir_port '7892'
option http_port '7890'
option socks_port '7891'
option mixed_port '7893'
option enable_ipv6 'false'
option tun_mode '0'
option enable '0'
option dash_port '9090'
option dash_pass '123456'
option auto_update '0'
option auto_update_time '0'
option level 'info'
option core '1'
option allow_lan 'true'
option bind_addr '*'
option dnsforwader '1'
option subcri 'clash'
option cusrule '0'
option dnscache '0'
option config_type '1'
option p_mode 'rule'
option auto_clear_log '1'
option auto_update '1'
option auto_update_time '12'
option clear_time '12'
option append_rules '0'
option enable_udp '0'
option dnscache '0'
option stack 'system'
option enhanced_mode 'fake-ip'
option fake_ip_range '198.18.0.1/16'
list fake_ip_filter '*.lan'
list fake_ip_filter 'localhost.ptlogin2.qq.com'
list defaul_nameserver '114.114.114.114'
list defaul_nameserver '8.8.8.8'
option listen_port '5300'
option interf '0'
option enable_dns '1'
config dnshijack
option enabled '1'
option ip '8.8.8.8'
option port '53'
option type 'tcp://'
config dnshijack
option enabled '1'
option ip '8.8.8.8'
option port '53'
option type 'udp://'
config hosts
option enabled '0'
option adress '*.clash.dev'
option ip '127.0.0.1'
config hosts
option enabled '0'
option adress 'alpha.clash.dev'
option ip '::1'
config dnsservers
option enabled '1'
option ser_type 'nameserver'
option ser_address '114.114.114.114'
option protocol 'udp://'
config dnsservers
option enabled '1'
option ser_port '853'
option protocol 'tls://'
option ser_type 'nameserver'
option ser_address '47.96.179.163'
config dnsservers
option enabled '1'
option ser_type 'nameserver'
option ser_address '118.89.110.78'
option ser_port '853'
option protocol 'tls://'
config dnsservers
option enabled '1'
option ser_type 'nameserver'
option ser_address '8.8.8.8'
option ser_port '53'
option protocol 'udp://'
config dnsservers
option enabled '1'
option ser_type 'nameserver'
option ser_address '1.1.1.1'
option ser_port '853'
option protocol 'tls://'
config dnsservers
option enabled '1'
option ser_type 'fallback'
option ser_address '114.114.114.114'
option protocol 'udp://'
config dnsservers
option enabled '1'
option ser_type 'fallback'
option ser_address '118.89.110.78'
option ser_port '853'
option protocol 'tls://'
config dnsservers
option enabled '1'
option ser_type 'fallback'
option ser_address '1.1.1.1'
option protocol 'tcp://'

View File

@ -1,974 +0,0 @@
#!/bin/sh /etc/rc.common
START=99
STOP=15
CLASH="/etc/clash/clash"
CLASHT="/etc/clash/clashtun/clash"
CLASHD="/etc/clash/dtun/clash"
CLASH_CONFIG="/etc/clash"
CRON_FILE="/etc/crontabs/root"
CONFIG_YAML="/etc/clash/config.yaml"
CONFIG_YAML_PATH=$(uci get clash.config.use_config 2>/dev/null)
CUSLIST="/tmp/dnsmasq.d/custom_list.conf"
CUSLITT="/tmp/dnsmasq.clash"
CUSLISTV="/var/dnsmasq.d/custom_list.conf"
CUSLITTV="/var/dnsmasq.clash"
REAL_LOG="/usr/share/clash/clash_real.txt"
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 delete dhcp.@dnsmasq[0].cachesize
rm -rf $CUSLIST $CUSLITT $CUSLISTV $CUSLITTV 2>/dev/null
uci commit dhcp
/etc/init.d/dnsmasq restart >/dev/null 2>&1
#===========================================================================================================================
}
add_cron(){
config_type=$(uci get clash.config.config_type 2>/dev/null)
#===========================================================================================================================
[ -z "$(grep -w "/usr/share/clash/clash-watchdog.sh" $CRON_FILE)" ] && echo "*/2 * * * * /usr/share/clash/clash-watchdog.sh" >> $CRON_FILE
#[ -z "$(grep -w "/usr/share/clash/kill_watchdog.sh" $CRON_FILE)" ] && echo "*/1 * * * * /usr/share/clash/kill_watchdog.sh" >> $CRON_FILE
clear=$(uci get clash.config.auto_clear_log 2>/dev/null)
if [ "${clear}" -eq 1 ]; then
[ -z "$(grep -w "/usr/share/clash/clash.txt" $CRON_FILE)" ] && echo "0 */$(uci get clash.config.clear_time 2>/dev/null) * * * echo '' >/usr/share/clash/clash.txt" >> $CRON_FILE
fi
auto=$(uci get clash.config.auto_update 2>/dev/null)
if [ "${auto}" -eq 1 ]; then
[ -z "$(grep -w "/usr/share/clash/update_all.sh" $CRON_FILE)" ] && echo "0 */$(uci get clash.config.auto_update_time 2>/dev/null) * * * bash /usr/share/clash/update_all.sh >/usr/share/clash/clash.txt 2>&1 &" >> $CRON_FILE
fi
auto_geoip=$(uci get clash.config.auto_update_geoip 2>/dev/null)
if [ "${auto_geoip}" -eq 1 ]; then
day=$(uci get clash.config.geoip_update_day 2>/dev/null)
week=$(uci get clash.config.geo_update_week 2>/dev/null)
if [ -z $week ];then
update_week="*"
else
update_week=$week
fi
if [ -z $day ];then
update_day="*"
else
update_day=$day
fi
[ -z "$(grep -w "/usr/share/clash/geoip.sh" $CRON_FILE)" ] && echo "0 $(uci get clash.config.auto_update_geoip_time 2>/dev/null) $update_week * $update_day /usr/share/clash/geoip.sh" >> $CRON_FILE
fi
crontab $CRON_FILE
#===========================================================================================================================
}
del_cron(){
#===========================================================================================================================
sed -i '/clash-watchdog.sh/d' $CRON_FILE
#sed -i '/kill_watchdog.sh/d' $CRON_FILE
sed -i '/update_all.sh/d' $CRON_FILE
sed -i '/clash.txt/d' $CRON_FILE
sed -i '/geoip.sh/d' $CRON_FILE
/etc/init.d/cron restart
#===========================================================================================================================
}
select_config(){
#===========================================================================================================================
config_type=$(uci get clash.config.config_type 2>/dev/null)
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Checking Config file" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "正在检查配置文件" >$REAL_LOG
fi
if [ -f $CONFIG_YAML_PATH ] && [ "$(ls -l $CONFIG_YAML_PATH|awk '{print int($5)}')" -ne 0 ];then
cp $CONFIG_YAML_PATH $CONFIG_YAML 2>/dev/null
elif [ ! -f "$CONFIG_YAML_PATH" ] && [ ! -f "$CONFIG_YAML" ];then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "No config found" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "找不到配置文件" >$REAL_LOG
fi
sleep 5
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
elif [ "$(ls -l $CONFIG_YAML_PATH|awk '{print int($5)}')" -eq 0 ] && [ "$(ls -l $CONFIG_YAML|awk '{print int($5)}')" -eq 0 ];then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Your Config File is Empty" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "你的config.yaml有问题还是为了空" >$REAL_LOG
fi
sleep 5
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
fi
#===========================================================================================================================
}
yml_change() {
#===========================================================================================================================
sh /usr/share/clash/yum_change.sh 2>/dev/null
#===========================================================================================================================
}
game_rules() {
#===========================================================================================================================
sh /usr/share/clash/game.sh 2>/dev/null
#===========================================================================================================================
}
ip_rules() {
#===========================================================================================================================
sh /usr/share/clash/iprules.sh 2>/dev/null
#===========================================================================================================================
}
yml_dns_change(){
#===========================================================================================================================
dns_port=$(grep "^ \{0,\}listen:" /etc/clash/config.yaml |awk -F ':' '{print $3}' 2>/dev/null)
dnsforwader=$(uci get clash.config.dnsforwader 2>/dev/null)
dnscache=$(uci get clash.config.dnscache 2>/dev/null)
if [ "${dns_port}" -eq 53 ]; then
sed -i 's/^0.0.0.0:53/0.0.0.0:5300/g' $CONFIG_YAML
fi
if [ "$dnsforwader" -ne 0 ]; then
if [ "${dns_port}" -eq 53 ]; then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Setting dns forwarder" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "设置dns转发器" >$REAL_LOG
fi
uci del_list dhcp.@dnsmasq[0].server=127.0.0.1#$dns_port >/dev/null 2>&1
uci add_list dhcp.@dnsmasq[0].server=127.0.0.1#5300 >/dev/null 2>&1
uci delete dhcp.@dnsmasq[0].resolvfile
uci set dhcp.@dnsmasq[0].noresolv=1
uci commit dhcp
if [ "$dnscache" -eq 0 ];then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Disabling dns cache" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "禁用dns缓存" >$REAL_LOG
fi
uci set dhcp.@dnsmasq[0].cachesize=0
uci commit dhcp
fi
else
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Setting dns forwarder" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "设置dns转发器" >$REAL_LOG
fi
uci del_list dhcp.@dnsmasq[0].server=127.0.0.1#$dns_port >/dev/null 2>&1
uci add_list dhcp.@dnsmasq[0].server=127.0.0.1#$dns_port >/dev/null 2>&1
uci delete dhcp.@dnsmasq[0].resolvfile
uci set dhcp.@dnsmasq[0].noresolv=1
uci commit dhcp
if [ "$dnscache" -eq 0 ];then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Disabling dns cache" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "禁用dns缓存" >$REAL_LOG
fi
uci set dhcp.@dnsmasq[0].cachesize=0
uci commit dhcp
fi
fi
elif [ "$dnsforwader" -ne 1 ]; then
if [ "$dnscache" -eq 0 ];then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Disabling dns cache" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "禁用dns缓存" >$REAL_LOG
fi
uci set dhcp.@dnsmasq[0].cachesize=0
uci commit dhcp
fi
fi
#===========================================================================================================================
}
check(){
sed -i 's/^Proxy Group:/proxy-groups:/g' "$CONFIG_YAML"
sed -i 's/^proxy-provider:/proxy-providers:/g' "$CONFIG_YAML"
sed -i 's/^Proxy:/proxies:/g' "$CONFIG_YAML"
sed -i 's/^Rule:/rules:/g' "$CONFIG_YAML"
sed -i 's/^rule-provider:/rule-providers:/g' "$CONFIG_YAML"
}
rules(){
#===========================================================================================================================
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)
#fake_ip_range=$(uci get clash.config.fake_ip_range 2>/dev/null)
ipv6=$(uci get clash.config.enable_ipv6 2>/dev/null)
core=$(uci get clash.config.core 2>/dev/null)
tun_mode=$(uci get clash.config.tun_mode 2>/dev/null)
#lan_ip=$(uci get network.lan.ipaddr 2>/dev/null |awk -F '/' '{print $1}' 2>/dev/null)
wan=$(ifconfig | grep 'inet addr' | awk '{print $2}' | cut -d: -f2 2>/dev/null)
ip6=$(ifconfig | grep 'inet6 addr' | awk '{print $3}' 2>/dev/null)
enable_udp=$(uci get clash.config.enable_udp 2>/dev/null)
fake_ip=$(egrep '^ {0,}enhanced-mode' /etc/clash/config.yaml |grep enhanced-mode: |awk -F ': ' '{print $2}')
PROXY_FWMARK="0x162"
PROXY_ROUTE_TABLE="0x162"
PROXY_BYPASS_USER="root"
dnsforwader=$(uci get clash.config.dnsforwader 2>/dev/null)
redir_host=$(egrep '^ {0,}enhanced-mode' /etc/clash/config.yaml |grep enhanced-mode: |awk -F ': ' '{print $2}')
if [ "$redir_host" == "redir-host" ];then
if [ "$(uci get clash.config.access_control 2>/dev/null)" = "1" ] && [ -n "$(uci get clash.config.proxy_lan_ips 2>/dev/null)" ]; then
proxy_ips=$(uci get clash.config.proxy_lan_ips)
ipset -! -R <<-EOF
create proxy_lan hash:net
$(for ip in $proxy_ips; do echo "add proxy_lan $ip"; done)
EOF
elif [ "$(uci get clash.config.access_control 2>/dev/null)" = "2" ] && [ -n "$(uci get clash.config.reject_lan_ips 2>/dev/null)" ]; then
reject_ips=$(uci get clash.config.reject_lan_ips)
ipset -! -R <<-EOF
create reject_lan hash:net
$(for ip in $reject_ips; do echo "add reject_lan $ip"; done)
EOF
fi
fi
ipset create localnetwork hash:net
ipset add localnetwork 127.0.0.0/8
ipset add localnetwork 10.0.0.0/8
ipset add localnetwork 169.254.0.0/16
ipset add localnetwork 192.168.0.0/16
ipset add localnetwork 224.0.0.0/4
ipset add localnetwork 240.0.0.0/4
ipset add localnetwork 172.16.0.0/12
if [ -n "$wan" ]; then
for wan_ip4s in $wan; do
ipset add localnetwork "$wan_ip4s" 2>/dev/null
done
fi
sh /usr/share/clash/chinaipset.sh >/dev/null 2>&1
if [ "$(iptables -t nat -nL PREROUTING --line-number |grep "udp dpt:53" |grep "0.0.0.0/0 \{0,\}0.0.0.0/0" |wc -l)" -gt 1 ] && [ "$dnsforwader" -eq "1" ]; then
pre_lines=$(iptables -nvL PREROUTING -t nat |sed 1,2d |sed -n '/0.0.0.0\/0 \{0,\}0.0.0.0\/0 \{0,\}udp dpt:53/=' 2>/dev/null |sort -rn)
for pre_line in $pre_lines; do
iptables -t nat -D PREROUTING "$pre_line" >/dev/null 2>&1
done
# iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53 >/dev/null 2>&1
sleep 2
fi
if [ -z "$(uci get firewall.clash 2>/dev/null)" ] || [ -z "$(uci get ucitrack.@clash[-1].init 2>/dev/null)" ]; then
uci delete ucitrack.@clash[-1] >/dev/null 2>&1
uci add ucitrack clash >/dev/null 2>&1
uci set ucitrack.@clash[-1].init=clash >/dev/null 2>&1
uci commit ucitrack >/dev/null 2>&1
uci delete firewall.clash >/dev/null 2>&1
uci set firewall.clash=include >/dev/null 2>&1
uci set firewall.clash.type=script >/dev/null 2>&1
uci set firewall.clash.path=/var/etc/clash.include >/dev/null 2>&1
uci set firewall.clash.reload=1 >/dev/null 2>&1
fi
if [ "$(uci get firewall.@defaults[0].forward)" != "ACCEPT" ]; then
uci set firewall.@defaults[0].forward=ACCEPT >/dev/null 2>&1
uci commit firewall >/dev/null 2>&1
/etc/init.d/firewall restart >/dev/null 2>&1
fi
mkdir -p /var/etc
cat > "/var/etc/clash.include" <<-EOF
/etc/init.d/clash reload >/dev/null 2>&1
EOF
if [ "${core}" -eq 1 ] || [ "${core}" -eq 2 ];then
iptables -t nat -N clash
iptables -t nat -F clash
iptables -t nat -A clash -m set --match-set localnetwork dst -j RETURN
iptables -t nat -A clash -m set --match-set reject_lan src -j RETURN
iptables -t nat -A clash -m set ! --match-set proxy_lan src -j RETURN
iptables -t nat -A clash -m set --match-set china dst -j RETURN
iptables -t nat -A clash -p tcp -j REDIRECT --to-ports "${redir_port}"
iptables -t nat -I PREROUTING -p tcp -d 8.8.8.8 -j REDIRECT --to-ports "${redir_port}"
iptables -t nat -I PREROUTING -p tcp -d 8.8.4.4 -j REDIRECT --to-ports "${redir_port}"
iptables -t nat -A PREROUTING -p tcp -j clash
ip rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE"
ip route add local 0.0.0.0/0 dev lo table "$PROXY_ROUTE_TABLE"
iptables -t mangle -N clash
iptables -t mangle -A clash -m set --match-set localnetwork dst -j RETURN
iptables -t mangle -A clash -m set --match-set reject_lan src -j RETURN
iptables -t mangle -A clash -m set ! --match-set proxy_lan src -j RETURN
iptables -t mangle -A clash -m set --match-set china dst -j RETURN
iptables -t mangle -A clash -p udp -j TPROXY --on-port "${redir_port}" --tproxy-mark "$PROXY_FWMARK"
iptables -t mangle -A PREROUTING -p udp -j clash
if [ "${fake_ip}" == "fake-ip" ];then
iptables -t nat -N clash_output
iptables -t nat -F clash_output
iptables -t nat -A clash_output -m set --match-set localnetwork dst -j RETURN
fake_ip_range=$(egrep '^ {0,}fake-ip-range' /etc/clash/config.yaml |grep fake-ip-range: |awk -F ': ' '{print $2}')
if [ ! -z "${fake_ip_range}" ];then
iptables -t nat -A clash_output -p tcp -d $fake_ip_range -j REDIRECT --to-ports "${redir_port}"
else
iptables -t nat -A clash_output -p tcp -d 198.18.0.0/16 -j REDIRECT --to-ports "${redir_port}"
fi
iptables -t nat -A OUTPUT -p tcp -j clash_output
fi
if [ "${ipv6}" == "true" ]; then
ip6tables -t nat -N clash
if [ -n "${ip6}" ]; then
for lan_ip6s in $ip6; do
ip6tables -t nat -A clash -d "$lan_ip6s" -j RETURN 2>/dev/null
done
fi
ip6tables -t nat -A clash -p tcp -j REDIRECT --to-ports "$proxy_port"
ip6tables -t nat -A PREROUTING -p tcp -j clash
fi
elif [ "${core}" -eq 3 ] || [ "${core}" -eq 4 ];then
natr=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/tcp dpt:53/=' | sort -r)
for natx in $natr; do
iptables -t nat -D PREROUTING $natx >/dev/null 2>&1
done
TUN_DEVICE=$(egrep '^ {0,}device-url:' /etc/clash/config.yaml |grep device-url: |awk -F '//' '{print $2}')
if [ -z $TUN_DEVICE ];then
TUN_DEVICE_NAME="clash0"
else
TUN_DEVICE_NAME=$TUN_DEVICE
fi
if [ "${core}" -eq 3 ];then
ip tuntap add user root mode tun $TUN_DEVICE_NAME
ip link set $TUN_DEVICE_NAME up
ip route replace default dev $TUN_DEVICE_NAME table "$PROXY_ROUTE_TABLE"
elif [ "${core}" -eq 4 ];then
TUN_WAIT=0
while ( [ -n "$(pidof clash)" ] && [ -z "$(ip route list |grep utun)" ] && [ "$TUN_WAIT" -le 3 ] )
do
TUN_WAIT=$(expr "$TUN_WAIT" + 1)
sleep 2
done
ip route replace default dev utun table "$PROXY_ROUTE_TABLE"
fi
ip rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE"
iptables -t mangle -N clash
iptables -t mangle -F clash
iptables -t mangle -A clash -m set --match-set localnetwork dst -j RETURN
iptables -t mangle -A clash -m set --match-set china dst -j RETURN
if [ "${fake_ip}" == "fake-ip" ];then
iptables -t mangle -A clash -d 198.18.0.0/16 -j MARK --set-mark "$PROXY_FWMARK"
fi
iptables -t mangle -I OUTPUT -j clash
#iptables -t mangle -I PREROUTING -m set ! --match-set localnetwork dst -j MARK --set-mark "$PROXY_FWMARK"
#iptables -t mangle -I PREROUTING -m set ! --match-set china dst -j MARK --set-mark "$PROXY_FWMARK"
iptables -t mangle -I PREROUTING -m set ! --match-set localnetwork dst -m set ! --match-set china dst -j MARK --set-mark "$PROXY_FWMARK"
iptables -t mangle -I PREROUTING -m set --match-set reject_lan src -j RETURN >/dev/null 2>&1
iptables -t mangle -I PREROUTING -m set ! --match-set proxy_lan src -j RETURN >/dev/null 2>&1
#iptables -t nat -I PREROUTING -p tcp --dport 53 -j ACCEPT
if [ "${fake_ip}" == "fake-ip" ];then
fake_ip_range=$(egrep '^ {0,}fake-ip-range' /etc/clash/config.yaml |grep fake-ip-range: |awk -F ': ' '{print $2}')
if [ ! -z "${fake_ip_range}" ];then
iptables -t nat -A OUTPUT -p tcp -d $fake_ip_range -j REDIRECT --to-ports "${redir_port}"
else
iptables -t nat -A OUTPUT -p tcp -d 198.18.0.1/16 -j REDIRECT --to-ports "${redir_port}"
fi
fi
fi
#===========================================================================================================================
}
custom_list() {
sh /usr/share/clash/list.sh >/dev/null 2>&1
}
restore() {
sh /usr/share/clash/restore.sh >/dev/null 2>&1
}
start(){
#===========================================================================================================================
lang=$(uci get luci.main.lang 2>/dev/null)
enable=$(uci get clash.config.enable 2>/dev/null)
core=$(uci get clash.config.core 2>/dev/null)
mode=$(uci get clash.config.mode 2>/dev/null)
tun_mode=$(uci get clash.config.tun_mode 2>/dev/null)
if [ -f /etc/clash/config.yaml ];then
rm -rf /etc/clash/config.yaml >/dev/null 2>&1
fi
if [ "${enable}" -eq 1 ]; then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Starting Client" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "启动客户端" >$REAL_LOG
fi
sleep 1
select_config >/dev/null 2>&1
sleep 1
if [ "${core}" -eq 1 ] && [ ! -f /etc/clash/clash ]; then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo " $(date "+%Y-%m-%d %H:%M:%S") - clash core not found, download and install clash from update page " >> /usr/share/clash/clash.txt
echo "clash core not found, download and install clash from update page" >> $REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo " $(date "+%Y-%m-%d %H:%M:%S") - 找不到/etc/clash/clash,请从更新页下载clash内核" >> /usr/share/clash/clash.txt
echo "找不到/etc/clash/clash,请从更新页下载clash内核" >> $REAL_LOG
fi
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
elif [ "${core}" -eq 3 ] && [ ! -f /etc/clash/clashtun/clash ]; then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo " $(date "+%Y-%m-%d %H:%M:%S") - clash Tun core not found in /etc/clash/clashtun/clash " >> /usr/share/clash/clash.txt
echo "clash Tun core not found in /etc/clash/clashtun/clash" >> $REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo " $(date "+%Y-%m-%d %H:%M:%S") - 找不到/etc/clash/clashtun/clash, clash Tun内核" >> /usr/share/clash/clash.txt
echo "找不到/etc/clash/clashtun/clash, clash Tun内核" >> $REAL_LOG
fi
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
elif [ "${core}" -eq 4 ] && [ ! -f /etc/clash/dtun/clash ]; then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo " $(date "+%Y-%m-%d %H:%M:%S") - clash Tun core not found in /etc/clash/dtun/clash " >> /usr/share/clash/clash.txt
echo "clash Tun core not found in /etc/clash/dtun/clash" >> $REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo " $(date "+%Y-%m-%d %H:%M:%S") - 找不到/usr/bin/clash clash Tun" >> /usr/share/clash/clash.txt
echo "找不到/etc/clash/dtun/clash,clash Tun" >> $REAL_LOG
fi
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
else
if [ -f $CONFIG_YAML ] && [ "$(ls -l $CONFIG_YAML|awk '{print int($5)}')" -ne 0 ] ; then
check >/dev/null 2>&1
custom_list >/dev/null 2>&1
if [ "$core" -eq 4 ] || [ "$core" -eq 3 ];then
if [ $tun_mode -eq 0 ];then
uci set clash.config.tun_mode="1" && uci set clash.config.stack="system" && uci commit clash
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Enabling TUN" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "启用TUN" >$REAL_LOG
fi
fi
fi
sleep 1
enable_dns=$(uci get clash.config.enable_dns 2>/dev/null)
if [ -z "$(grep "^ {0,}listen:" /etc/clash/config.yaml)" ] || [ -z "$(grep "^ {0,}enhanced-mode:" /etc/clash/config.yaml)" ] || [ -z "$(grep "^ {0,}dns:" /etc/clash/config.yaml)" ];then
if [ $enable_dns -eq 0 ];then
uci set clash.config.enable_dns="1" && uci commit clash
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Enabling Custom Dns" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "启用自定义DNS" >$REAL_LOG
fi
fi
fi
if [ ! -z "$(egrep '^ {0,}rule-providers:' "/etc/clash/config.yaml")" ] && [ "$(uci get clash.config.core)" -ne 4 ];then
if [ -f /etc/clash/dtun/clash ];then
uci set clash.config.core="4" && uci commit clash
sleep 1
else
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Your Current Config only support Clash Core(dtun)" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "你在使用配置不支持Clash内核仅支持Clash(dtun)h内核" >$REAL_LOG
fi
remove_mark >/dev/null 2>&1
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
fi
fi
if [ ! -z "$(egrep '^ {0,}script:' "/etc/clash/config.yaml")" ] && [ "$(uci get clash.config.core)" -ne 4 ];then
if [ -f /etc/clash/dtun/clash ];then
uci set clash.config.core="4" && uci commit clash
sleep 1
else
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Your Current Config only support Clash Core(dtun)" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "你在使用配置不支持Clash内核仅支持Clash(dtun)h内核" >$REAL_LOG
fi
remove_mark >/dev/null 2>&1
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
fi
fi
if [ ! -z "$(egrep '^ {0,}script:' "/etc/clash/config.yaml")" ] && [ "$(uci get clash.config.p_mode 2>/dev/null)" != "Script" ];then
uci set clash.config.p_mode="Script"&& uci commit clash
elif [ "$(uci get clash.config.p_mode)" == "Script" ] && [ -z "$(egrep '^ {0,}script:' "/etc/clash/config.yaml")" ];then
uci set clash.config.p_mode="rule" && uci commit clash
fi
sleep 1
yml_change >/dev/null 2>&1
if [ ! -f /etc/clash/Country.mmdb ];then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Cannot find Country.mmdb" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "找不到Country.mmdb" >$REAL_LOG
fi
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
fi
if [ ! -f /etc/clash/config.yaml ];then
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Cannot find config.yaml" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "找不到config.yaml" >$REAL_LOG
fi
remove_mark >/dev/null 2>&1
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
fi
yml_dns_change >/dev/null 2>&1
game_rules >/dev/null 2>&1
ip_rules >/dev/null 2>&1
if [ "$(uci get clash.config.core)" -eq 1 ];then
nohup $CLASH -d "$CLASH_CONFIG" > /usr/share/clash/clash.txt 2>&1 &
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Clash Core Started Successfully " >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "Clash 计划任务,启动进程守护程序..." >$REAL_LOG
fi
elif [ "$(uci get clash.config.core)" -eq 3 ];then
nohup $CLASHT -d "$CLASH_CONFIG" > /usr/share/clash/clash.txt 2>&1 &
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Clash Core Started Successfully " >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "Clash 计划任务,启动进程守护程序..." >$REAL_LOG
fi
elif [ "$(uci get clash.config.core)" -eq 4 ];then
nohup $CLASHD -d "$CLASH_CONFIG" > /usr/share/clash/clash.txt 2>&1 &
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Clash Core Started Successfully " >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "Clash 计划任务,启动进程守护程序..." >$REAL_LOG
fi
fi
ln -s /usr/share/clash/yacd /www/luci-static/yacd 2>/dev/null
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Setting up clash iptables rules" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "设置 Clash iptables" >$REAL_LOG
fi
rules >/dev/null 2>&1
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Restarting Dnsmasq " >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "重启 Dnsmasq 程序" >$REAL_LOG
fi
/etc/init.d/dnsmasq restart >/dev/null 2>&1
restore >/dev/null 2>&1
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Setting Cron Job" >$REAL_LOG
add_cron
elif [ "${lang}" == "zh_cn" ];then
echo "设置Cron" >$REAL_LOG
add_cron
fi
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Clash Started Successfully " >$REAL_LOG
sleep 1
echo "Clash is Running " >$REAL_LOG
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "Clash 启动成功,请等待服务器上线!" >$REAL_LOG
sleep 1
echo "Clash运行中" >$REAL_LOG
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
fi
if ! pidof clash >/dev/null; then
remove_mark 2>/dev/null
kill -9 `pidof clash|sed "s/$//g"` 2>/dev/null
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
fi
else
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo " $(date "+%Y-%m-%d %H:%M:%S") - problem with config.yaml, config.yaml is either empty or not found " >> /usr/share/clash/clash.txt
echo " problem with config file " >$REAL_LOG
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo " $(date "+%Y-%m-%d %H:%M:%S") - 你的config.yaml有问题还是为了空 0kb " >> /usr/share/clash/clash.txt
echo " 你的config.yaml有问题还是为了空 0kb " >$REAL_LOG
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
fi
fi
fi
else
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Enable Client and Start Client Again" >$REAL_LOG
echo " $(date "+%Y-%m-%d %H:%M:%S") - Enable Client and Start Client Again" >>/usr/share/clash/clash.txt
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "启用客户端并重新启动客户端" >$REAL_LOG
echo " $(date "+%Y-%m-%d %H:%M:%S") - 启用客户端并重新启动客户端" >>/usr/share/clash/clash.txt
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
fi
fi
#===========================================================================================================================
}
remove_mark(){
rm -rf /var/etc/clash.include 2>/dev/null
core=$(uci get clash.config.core 2>/dev/null)
ipv6=$(uci get clash.config.enable_ipv6 2>/dev/null)
dns_port=$(grep "^ \{0,\}listen:" $CONFIG_YAML |awk -F ':' '{print $3}' 2>/dev/null)
PROXY_FWMARK="0x162" 2>/dev/null
PROXY_ROUTE_TABLE="0x162" 2>/dev/null
ip rule del fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
ip route del local 0.0.0.0/0 dev lo table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
TUN_DEVICE=$(egrep '^ {0,}device-url:' /etc/clash/config.yaml |grep device-url: |awk -F '//' '{print $2}')
if [ -z $TUN_DEVICE ];then
TUN_DEVICE_NAME="clash0"
else
TUN_DEVICE_NAME=$TUN_DEVICE
fi
if [ "${core}" -eq 3 ];then
ip link set dev $TUN_DEVICE_NAME down 2>/dev/null
ip tuntap del $TUN_DEVICE_NAME mode tun 2>/dev/null
ip route del default dev $TUN_DEVICE_NAME table "$PROXY_ROUTE_TABLE" 2>/dev/null
fi
ip route del default dev utun table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
#ip rule del fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" 2>/dev/null
ip rule del fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
mangle=$(iptables -nvL OUTPUT -t mangle | sed 1,2d | sed -n '/clash/=' | sort -r)
for mangles in $mangle; do
iptables -t mangle -D OUTPUT $mangles 2>/dev/null
done
pre=$(iptables -nvL PREROUTING -t mangle | sed 1,2d | sed -n '/! match-set localnetwork dst MARK set 0x162/=' | sort -r)
for prer in $pre; do
iptables -t mangle -D PREROUTING $prer 2>/dev/null
done
pre1=$(iptables -nvL PREROUTING -t mangle | sed 1,2d | sed -n '/! match-set china dst MARK set 0x162/=' | sort -r)
for prer in $pre1; do
iptables -t mangle -D PREROUTING $prer 2>/dev/null
done
pre_lines=$(iptables -nvL PREROUTING -t nat |sed 1,2d |sed -n '/8\.8\./=' 2>/dev/null |sort -rn)
for pre_line in $pre_lines; do
iptables -t nat -D PREROUTING "$pre_line" >/dev/null 2>&1
done
# iptables -t nat -D PREROUTING -p tcp --dport 53 -j ACCEPT >/dev/null 2>&1
# iptables -t nat -D PREROUTING -p udp --dport 53 -j DNAT --to "127.0.0.1:$dns_port"
if [ "${ipv6}" == "true" ]; then
ip6tables -t mangle -D PREROUTING -j MARK --set-mark "$PROXY_FWMARK" 2>/dev/null
fi
iptables -t mangle -F clash 2>/dev/null
iptables -t mangle -X clash 2>/dev/null
iptables -t nat -F clash_output >/dev/null 2>&1
iptables -t nat -X clash_output >/dev/null 2>&1
ipset -! flush proxy_lan >/dev/null 2>&1
ipset -! flush reject_lan >/dev/null 2>&1
ipset destroy reject_lan >/dev/null 2>&1
ipset destroy proxy_lan >/dev/null 2>&1
ipset -! flush china >/dev/null 2>&1
ipset destroy china >/dev/null 2>&1
proxy_lan=$(iptables -nvL PREROUTING -t mangle | sed 1,2d | sed -n '/! match-set proxy_lan src/=' | sort -r)
for natx in $proxy_lan; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
reject_lan=$(iptables -nvL PREROUTING -t mangle | sed 1,2d | sed -n '/match-set reject_lan src/=' | sort -r)
for natx in $reject_lan; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
proxy_lann=$(iptables -nvL clash -t nat | sed 1,2d | sed -n '/! match-set proxy_lan src/=' | sort -r)
for natx in $proxy_lann; do
iptables -t nat -D PREROUTING $natx >/dev/null 2>&1
done
reject_lann=$(iptables -nvL clash -t nat | sed 1,2d | sed -n '/match-set reject_lan src/=' | sort -r)
for natx in $reject_lann; do
iptables -t nat -D PREROUTING $natx >/dev/null 2>&1
done
proxy_lannn=$(iptables -nvL clash -t nat | sed 1,2d | sed -n '/! match-set proxy_lan src/=' | sort -r)
for natx in $proxy_lannn; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
reject_lannn=$(iptables -nvL clash -t nat | sed 1,2d | sed -n '/match-set reject_lan src/=' | sort -r)
for natx in $reject_lannn; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
iptables -t nat -D OUTPUT -p tcp -j clash_output >/dev/null 2>&1
china_lan2=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/match-set china/=' | sort -r)
for natx in $china_lan2; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
china_lan3$(iptables -nvL PREROUTING -t mangle | sed 1,2d | sed -n '/match-set china/=' | sort -r)
for natx in $china_lan3; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
ipset destroy localnetwork 2>/dev/null
nat_indexs=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/clash/=' | sort -r)
for nat_index in $nat_indexs; do
iptables -t nat -D PREROUTING $nat_index >/dev/null 2>&1
iptables -t nat -F clash >/dev/null 2>&1
iptables -t nat -X clash >/dev/null 2>&1
iptables -t mangle -F clash >/dev/null 2>&1
iptables -t mangle -D PREROUTING -p udp -j clash >/dev/null 2>&1
iptables -t mangle -X clash >/dev/null 2>&1
done
nat=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/tcp dpt:53/=' | sort -r)
for natx in $nat; do
iptables -t nat -D PREROUTING $natx >/dev/null 2>&1
done
ip6tables -t mangle -F clash >/dev/null 2>&1
ip6tables -t mangle -D PREROUTING -p udp -j clash >/dev/null 2>&1
ip6tables -t mangle -X clash >/dev/null 2>&1
out_linese=$(iptables -nvL OUTPUT -t mangle |sed 1,2d |sed -n '/198.18.0.1\/16/=' 2>/dev/null |sort -rn)
for out_linee in $out_linese; do
iptables -t mangle -D OUTPUT "$out_linee" >/dev/null 2>&1
done
out_linesee=$(iptables -nvL OUTPUT -t mangle |sed 1,2d |sed -n '/198.18.0.0\/16/=' 2>/dev/null |sort -rn)
for out_linees in $out_linesee; do
iptables -t mangle -D OUTPUT "$out_linees" >/dev/null 2>&1
done
nat_indexs=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/clash/=' | sort -r)
for nat_index in $nat_indexs; do
iptables -t nat -D PREROUTING $nat_index >/dev/null 2>&1
done
fake=$(iptables -nvL OUTPUT -t nat |sed 1,2d |sed -n '/198.18.0.0\/16/=' |sort -r)
for fake in $fake; do
iptables -t nat -D OUTPUT $fake >/dev/null 2>&1
done
fake2=$(iptables -nvL OUTPUT -t nat |sed 1,2d |sed -n '/198.18.0.1\/16/=' |sort -r)
for fake2 in $fake2; do
iptables -t nat -D OUTPUT $fake2 >/dev/null 2>&1
done
iptables -t nat -I PREROUTING -p tcp --dport 53 -j ACCEPT
revert_dns >/dev/null 2>&1
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Restarting Dnsmasq " >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "重启 Dnsmasq 程序" >$REAL_LOG
fi
}
stop(){
#===========================================================================================================================
lang=$(uci get luci.main.lang 2>/dev/null)
tun_mode=$(uci get clash.config.tun_mode 2>/dev/null)
#ipv6=$(uci get clash.config.enable_ipv6 2>/dev/null)
core=$(uci get clash.config.core 2>/dev/null)
LIST="/usr/share/clash/server.list"
sed -i '/#START/,/#END/d' "$LIST" 2>/dev/null
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Stopping Client..." >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "正在停止客户端..." >$REAL_LOG
fi
sleep 1
remove_mark >/dev/null 2>&1
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Removing clash iptables rules" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "删除clash iptables规则" >$REAL_LOG
fi
bash /usr/share/clash/backup.sh >/dev/null 2>&1
kill -9 `pidof clash|sed "s/$//g"` 2>/dev/null
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Clash Core Stoped Successfully " >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "Clash 停止进程守护程序" >$REAL_LOG
fi
rm -rf /www/luci-static/yacd 2>/dev/null
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo "Deleting Cron Job" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo "删除Cron" >$REAL_LOG
fi
del_cron >/dev/null 2>&1
sleep 1
echo "" >/usr/share/clash/clash.txt >/dev/null 2>&1
echo "0" > /usr/share/clash/logstatus_check >/dev/null 2>&1
if [ "${lang}" == "en" ] || [ $lang == "auto" ];then
echo " $(date "+%Y-%m-%d %H:%M:%S") - CLIENT IS DISABLED " >> /usr/share/clash/clash.txt
echo "Client is Disabled " >$REAL_LOG
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
elif [ "${lang}" == "zh_cn" ];then
echo " $(date "+%Y-%m-%d %H:%M:%S") - 客户端被禁用 " >> /usr/share/clash/clash.txt
echo "客户端被禁用 " >$REAL_LOG
sleep 1
echo "Clash for OpenWRT" >$REAL_LOG
fi
if pidof clash >/dev/null; then
kill $(pidof clash) >/dev/null 2>&1 || kill -9 $(ps | grep clash | grep -v grep | awk '{print $1}') >/dev/null 2>&1
fi
#===========================================================================================================================
}
restart(){
#===========================================================================================================================
if pidof clash >/dev/null; then
stop >/dev/null 2>&1
start >/dev/null 2>&1
echo "Clash Successfully Restarted"
else
start >/dev/null 2>&1
echo "Clash Successfully Started"
fi
#===========================================================================================================================
}
reload()
{
if pidof clash >/dev/null; then
remove_mark 2>/dev/null
yml_dns_change 2>/dev/null
rules 2>/dev/null
echo "Clash for OpenWRT" >$REAL_LOG
echo "Clash Reload Completed"
fi
}

View File

@ -1,21 +0,0 @@
#!/bin/sh
. /lib/functions.sh
CURL_GROUP_CACHE="/etc/clash/clashbackup/clash_gorup.json"
CURL_NOW_CACHE="/etc/clash/clashbackup/clash_now.json"
CURL_CACHE="/etc/clash/clashbackup/clash_curl.json"
HISTORY_PATH="/etc/clash/clashbackup/history"
SECRET=$(uci get clash.config.dash_pass 2>/dev/null)
LAN_IP=$(uci get network.lan.ipaddr 2>/dev/null |awk -F '/' '{print $1}' 2>/dev/null)
PORT=$(uci get clash.config.dash_port 2>/dev/null)
curl -m 5 --retry 2 -w %{http_code}"\n" -H "Authorization: Bearer ${SECRET}" -H "Content-Type:application/json" -X GET http://"$LAN_IP":"$PORT"/proxies > "$CURL_CACHE" 2>/dev/null
if [ "$(sed -n '$p' "$CURL_CACHE" 2>/dev/null)" = "200" ]; then
if [ ! -d /etc/clash/clashbackup ];then
mkdir -p /etc/clash/clashbackup 2>/dev/null
fi
cat "$CURL_CACHE" |jsonfilter -e '@["proxies"][@.type="Selector"]["name"]' > "$CURL_GROUP_CACHE" 2>/dev/null
cat "$CURL_CACHE" |jsonfilter -e '@["proxies"][@.type="Selector"]["now"]' > "$CURL_NOW_CACHE" 2>/dev/null
awk 'NR==FNR{a[i]=$0;i++}NR>FNR{print a[j]"#*#"$0;j++}' "$CURL_GROUP_CACHE" "$CURL_NOW_CACHE" > "$HISTORY_PATH" 2>/dev/null
fi
rm -rf /etc/clash/clashbackup/clash_*.json 2>/dev/null

View File

@ -1,13 +0,0 @@
#!/bin/sh
new_clashtun_core_version=`wget -qO- "https://hub.fastgit.org/comzyh/clash/tags"| grep "/comzyh/clash/releases/"| head -n 1| awk -F "/tag/" '{print $2}'| sed 's/\">//g'`
if [ "$?" -eq "0" ]; then
rm -rf /usr/share/clash/new_clashtun_core_version
if [ $new_clashtun_core_version ]; then
echo $new_clashtun_core_version > /usr/share/clash/new_clashtun_core_version 2>&1 & >/dev/null
elif [ $new_clashtun_core_version =="" ]; then
echo 0 > /usr/share/clash/new_clashtun_core_version 2>&1 & >/dev/null
fi
fi

View File

@ -1,12 +0,0 @@
#!/bin/sh
new_core_version=`wget -qO- "https://hub.fastgit.org/Dreamacro/clash/tags"| grep "/Dreamacro/clash/releases/"| head -n 1| awk -F "/tag/" '{print $2}'| sed 's/\">//g'`
if [ "$?" -eq "0" ]; then
rm -rf /usr/share/clash/new_core_version
if [ $new_core_version ]; then
echo $new_core_version > /usr/share/clash/new_core_version 2>&1 & >/dev/null
elif [ $new_core_version =="" ]; then
echo 0 > /usr/share/clash/new_core_version 2>&1 & >/dev/null
fi
fi

View File

@ -1,12 +0,0 @@
#!/bin/sh
new_clashdtun_core_version=`wget -qO- "https://hub.fastgit.org/Dreamacro/clash/releases/tag/premium"| grep "/download/premium/"| head -n1| awk -F " " '{print $2}'| awk -F "-" '{print $4}'| sed "s/.gz\"//g"`
sleep 2
if [ "$?" -eq "0" ]; then
rm -rf /usr/share/clash/new_clashdtun_core_version
if [ $new_clashdtun_core_version ]; then
echo $new_clashdtun_core_version > /usr/share/clash/new_clashdtun_core_version 2>&1 & >/dev/null
elif [ $new_clashdtun_core_version =="" ]; then
echo 0 > /usr/share/clash/new_clashdtun_core_version 2>&1 & >/dev/null
fi
fi

View File

@ -1,12 +0,0 @@
#!/bin/sh
new_version=`curl -sL "https://hub.fastgit.org/hubbylei/luci-app-clash/tags"| grep "/hubbylei/luci-app-clash/releases/"| head -n 1| awk -F "/tag/" '{print $2}'| sed 's/\">//g'`
if [ "$?" -eq "0" ]; then
rm -rf /usr/share/clash/new_luci_version
if [ $new_version ]; then
echo $new_version > /usr/share/clash/new_luci_version 2>&1 & >/dev/null
elif [ $new_version =="" ]; then
echo 0 > /usr/share/clash/new_luci_version 2>&1 & >/dev/null
fi
fi

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +0,0 @@
echo "create china hash:net family inet hashsize 1024 maxelem 65536" > /tmp/china.ipset
awk '!/^$/&&!/^#/{printf("add china %s'" "'\n",$0)}' /usr/share/clash/china_ip.txt >> /tmp/china.ipset
ipset -! flush china
ipset -! restore < /tmp/china.ipset 2>/dev/null
rm -f /tmp/china.ipset

View File

@ -1,304 +0,0 @@
#!/bin/sh
CORETYPE=$(uci get clash.config.core 2>/dev/null)
CONFIG_YAML_PATH=$(uci get clash.config.use_config 2>/dev/null)
CONFIG_YAML="/etc/clash/config.yaml"
url=$(uci get clash.config.clash_url)
MODELTYPE=$(uci get clash.config.download_core)
if [ "$CORETYPE" -eq "1" ];then
CORE_PATH="/etc/clash/clash"
elif [ "$CORETYPE" -eq "3" ];then
CORE_PATH="/etc/clash/clashtun/clash"
elif [ "$CORETYPE" -eq "4" ];then
CORE_PATH="/etc/clash/dtun/clash"
fi
dcore(){
echo '' >/tmp/clash_update.txt 2>/dev/null
if [ -f /usr/share/clash/core_down_complete ];then
rm -rf /usr/share/clash/core_down_complete 2>/dev/null
fi
if [ "$CORETYPE" -eq "4" ];then
if [ -f /usr/share/clash/download_dtun_version ];then
rm -rf /usr/share/clash/download_dtun_version
fi
new_clashdtun_core_version=`wget -qO- "https://hub.fastgit.org/Dreamacro/clash/releases/tag/premium"| grep "/download/premium/"| head -n 1| awk -F " " '{print $2}'| awk -F "-" '{print $4}'| sed "s/.gz\"//g"`
if [ ${new_clashdtun_core_version} ]; then
echo ${new_clashdtun_core_version} > /usr/share/clash/download_dtun_version 2>&1 & >/dev/null
elif [ ${new_clashdtun_core_version} =="" ]; then
echo 0 > /usr/share/clash/download_dtun_version 2>&1 & >/dev/null
fi
sleep 5
if [ -f /usr/share/clash/download_dtun_version ];then
CLASHDTUNC=$(sed -n 1p /usr/share/clash/download_dtun_version 2>/dev/null)
fi
fi
if [ "$CORETYPE" -eq "3" ];then
if [ -f /usr/share/clash/download_tun_version ];then
rm -rf /usr/share/clash/download_tun_version
fi
new_clashtun_core_version=`wget -qO- "https://hub.fastgit.org/comzyh/clash/tags"| grep "/comzyh/clash/releases/"| head -n 1| awk -F "/tag/" '{print $2}'| sed 's/\">//g'`
if [ ${new_clashtun_core_version} ]; then
echo ${new_clashtun_core_version} > /usr/share/clash/download_tun_version 2>&1 & >/dev/null
elif [ ${new_clashtun_core_version} =="" ]; then
echo 0 > /usr/share/clash/download_tun_version 2>&1 & >/dev/null
fi
sleep 5
if [ -f /usr/share/clash/download_tun_version ];then
CLASHTUN=$(sed -n 1p /usr/share/clash/download_tun_version 2>/dev/null)
fi
fi
if [ "$CORETYPE" -eq "1" ];then
if [ -f /usr/share/clash/download_core_version ];then
rm -rf /usr/share/clash/download_core_version
fi
new_clashr_core_version=`wget -qO- "https://hub.fastgit.org/Dreamacro/clash/tags"| grep "/Dreamacro/clash/releases/"| head -n 1| awk -F "/tag/" '{print $2}'| sed 's/\">//g'`
if [ ${new_clashr_core_version} ]; then
echo ${new_clashr_core_version} > /usr/share/clash/download_core_version 2>&1 & >/dev/null
elif [ ${new_clashr_core_version} =="" ]; then
echo 0 > /usr/share/clash/download_core_version 2>&1 & >/dev/null
fi
sleep 5
if [ -f /usr/share/clash/download_core_version ];then
CLASHVER=$(sed -n 1p /usr/share/clash/download_core_version 2>/dev/null)
fi
fi
if [ -f /tmp/clash.gz ];then
rm -rf /tmp/clash.gz >/dev/null 2>&1
fi
if [ "$CORETYPE" -eq "1" ];then
wget --no-check-certificate https://hub.fastgit.org/Dreamacro/clash/releases/download/"$CLASHVER"/clash-"$MODELTYPE"-"$CLASHVER".gz -O 2>&1 >1 /tmp/clash.gz
elif [ "$CORETYPE" -eq "3" ];then
wget --no-check-certificate https://hub.fastgit.org/comzyh/clash/releases/download/"$CLASHTUN"/clash-"$MODELTYPE"-"$CLASHTUN".gz -O 2>&1 >1 /tmp/clash.gz
elif [ "$CORETYPE" -eq "4" ];then
wget --no-check-certificate https://hub.fastgit.org/Dreamacro/clash/releases/download/premium/clash-"$MODELTYPE"-"$CLASHDTUNC".gz -O 2>&1 >1 /tmp/clash.gz
fi
if [ "$?" -eq "0" ] && [ "$(ls -l /tmp/clash.gz |awk '{print int($5)}')" -ne "0" ]; then
gunzip /tmp/clash.gz >/dev/null 2>&1\
&& rm -rf /tmp/clash.gz >/dev/null 2>&1\
&& chmod 755 /tmp/clash\
&& chown root:root /tmp/clash
if [ "$CORETYPE" -eq "1" ];then
rm -rf /etc/clash/clash >/dev/null 2>&1
mv /tmp/clash /etc/clash/clash >/dev/null 2>&1
rm -rf /usr/share/clash/core_version >/dev/null 2>&1
mv /usr/share/clash/download_core_version /usr/share/clash/core_version >/dev/null 2>&1
elif [ "$CORETYPE" -eq "3" ];then
rm -rf /etc/clash/clashtun/clash >/dev/null 2>&1
mv /tmp/clash /etc/clash/clashtun/clash >/dev/null 2>&1
rm -rf /usr/share/clash/tun_version >/dev/null 2>&1
mv /usr/share/clash/download_tun_version /usr/share/clash/tun_version >/dev/null 2>&1
tun=$(sed -n 1p /usr/share/clash/tun_version 2>/dev/null)
sed -i "s/${tun}/v${tun}/g" /usr/share/clash/tun_version 2>&1
elif [ "$CORETYPE" -eq "4" ];then
rm -rf /etc/clash/dtun/clash >/dev/null 2>&1
mv /tmp/clash /etc/clash/dtun/clash >/dev/null 2>&1
rm -rf /usr/share/clash/dtun_version >/dev/null 2>&1
mv /usr/share/clash/download_dtun_version /usr/share/clash/dtun_version >/dev/null 2>&1
dtun=$(sed -n 1p /usr/share/clash/dtun_version 2>/dev/null)
sed -i "s/${dtun}/v${dtun}/g" /usr/share/clash/dtun_version 2>&1leep 2
fi
touch /usr/share/clash/core_down_complete >/dev/null 2>&1
sleep 2
rm -rf /var/run/core_update >/dev/null 2>&1
echo "" > /tmp/clash_update.txt >/dev/null 2>&1
fi
}
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 delete dhcp.@dnsmasq[0].cachesize
rm -rf $CUSLIST $CUSLITT $CUSLISTV $CUSLITTV 2>/dev/null
uci commit dhcp
/etc/init.d/dnsmasq restart >/dev/null 2>&1
}
remove_mark(){
rm -rf /var/etc/clash.include 2>/dev/null
core=$(uci get clash.config.core 2>/dev/null)
ipv6=$(uci get clash.config.enable_ipv6 2>/dev/null)
dns_port=$(grep "^ \{0,\}listen:" $CONFIG_YAML |awk -F ':' '{print $3}' 2>/dev/null)
PROXY_FWMARK="0x162" 2>/dev/null
PROXY_ROUTE_TABLE="0x162" 2>/dev/null
ip rule del fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
ip route del local 0.0.0.0/0 dev lo table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
TUN_DEVICE=$(egrep '^ {0,}device-url:' /etc/clash/config.yaml |grep device-url: |awk -F '//' '{print $2}')
if [ -z $TUN_DEVICE ];then
TUN_DEVICE_NAME="clash0"
else
TUN_DEVICE_NAME=$TUN_DEVICE
fi
if [ "${core}" -eq 3 ];then
ip link set dev $TUN_DEVICE_NAME down 2>/dev/null
ip tuntap del $TUN_DEVICE_NAME mode tun 2>/dev/null
ip route del default dev $TUN_DEVICE_NAME table "$PROXY_ROUTE_TABLE" 2>/dev/null
fi
ip route del default dev utun table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
ip rule del fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
mangle=$(iptables -nvL OUTPUT -t mangle | sed 1,2d | sed -n '/clash/=' | sort -r)
for mangles in $mangle; do
iptables -t mangle -D OUTPUT $mangles 2>/dev/null
done
pre=$(iptables -nvL PREROUTING -t mangle | sed 1,2d | sed -n '/! match-set localnetwork dst MARK set 0x162/=' | sort -r)
for prer in $pre; do
iptables -t mangle -D PREROUTING $prer 2>/dev/null
done
pre1=$(iptables -nvL PREROUTING -t mangle | sed 1,2d | sed -n '/! match-set china dst MARK set 0x162/=' | sort -r)
for prer in $pre1; do
iptables -t mangle -D PREROUTING $prer 2>/dev/null
done
pre_lines=$(iptables -nvL PREROUTING -t nat |sed 1,2d |sed -n '/8\.8\./=' 2>/dev/null |sort -rn)
for pre_line in $pre_lines; do
iptables -t nat -D PREROUTING "$pre_line" >/dev/null 2>&1
done
iptables -t nat -D PREROUTING -p tcp --dport 53 -j ACCEPT >/dev/null 2>&1
iptables -t nat -D PREROUTING -p udp --dport 53 -j DNAT --to "127.0.0.1:$dns_port"
if [ "${ipv6}" == "true" ]; then
ip6tables -t mangle -D PREROUTING -j MARK --set-mark "$PROXY_FWMARK" 2>/dev/null
fi
iptables -t mangle -F clash 2>/dev/null
iptables -t mangle -X clash 2>/dev/null
iptables -t nat -F clash_output >/dev/null 2>&1
iptables -t nat -X clash_output >/dev/null 2>&1
ipset -! flush proxy_lan >/dev/null 2>&1
ipset -! flush reject_lan >/dev/null 2>&1
ipset destroy reject_lan >/dev/null 2>&1
ipset destroy proxy_lan >/dev/null 2>&1
ipset -! flush china >/dev/null 2>&1
ipset destroy china >/dev/null 2>&1
proxy_lan=$(iptables -nvL PREROUTING -t mangle | sed 1,2d | sed -n '/! match-set proxy_lan src/=' | sort -r)
for natx in $proxy_lan; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
reject_lan=$(iptables -nvL PREROUTING -t mangle | sed 1,2d | sed -n '/match-set reject_lan src/=' | sort -r)
for natx in $reject_lan; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
proxy_lann=$(iptables -nvL clash -t nat | sed 1,2d | sed -n '/! match-set proxy_lan src/=' | sort -r)
for natx in $proxy_lann; do
iptables -t nat -D PREROUTING $natx >/dev/null 2>&1
done
reject_lann=$(iptables -nvL clash -t nat | sed 1,2d | sed -n '/match-set reject_lan src/=' | sort -r)
for natx in $reject_lann; do
iptables -t nat -D PREROUTING $natx >/dev/null 2>&1
done
proxy_lannn=$(iptables -nvL clash -t nat | sed 1,2d | sed -n '/! match-set proxy_lan src/=' | sort -r)
for natx in $proxy_lannn; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
reject_lannn=$(iptables -nvL clash -t nat | sed 1,2d | sed -n '/match-set reject_lan src/=' | sort -r)
for natx in $reject_lannn; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
iptables -t nat -D OUTPUT -p tcp -j clash_output >/dev/null 2>&1
china_lan2=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/match-set china/=' | sort -r)
for natx in $china_lan2; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
china_lan3$(iptables -nvL PREROUTING -t mangle | sed 1,2d | sed -n '/match-set china/=' | sort -r)
for natx in $china_lan3; do
iptables -t mangle -D PREROUTING $natx >/dev/null 2>&1
done
ipset destroy localnetwork 2>/dev/null
nat_indexs=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/clash/=' | sort -r)
for nat_index in $nat_indexs; do
iptables -t nat -D PREROUTING $nat_index >/dev/null 2>&1
iptables -t nat -F clash >/dev/null 2>&1
iptables -t nat -X clash >/dev/null 2>&1
iptables -t mangle -F clash >/dev/null 2>&1
iptables -t mangle -D PREROUTING -p udp -j clash >/dev/null 2>&1
iptables -t mangle -X clash >/dev/null 2>&1
done
nat=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/tcp dpt:53/=' | sort -r)
for natx in $nat; do
iptables -t nat -D PREROUTING $natx >/dev/null 2>&1
done
ip6tables -t mangle -F clash >/dev/null 2>&1
ip6tables -t mangle -D PREROUTING -p udp -j clash >/dev/null 2>&1
ip6tables -t mangle -X clash >/dev/null 2>&1
out_linese=$(iptables -nvL OUTPUT -t mangle |sed 1,2d |sed -n '/198.18.0.1\/16/=' 2>/dev/null |sort -rn)
for out_linee in $out_linese; do
iptables -t mangle -D OUTPUT "$out_linee" >/dev/null 2>&1
done
out_linesee=$(iptables -nvL OUTPUT -t mangle |sed 1,2d |sed -n '/198.18.0.0\/16/=' 2>/dev/null |sort -rn)
for out_linees in $out_linesee; do
iptables -t mangle -D OUTPUT "$out_linees" >/dev/null 2>&1
done
nat_indexs=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/clash/=' | sort -r)
for nat_index in $nat_indexs; do
iptables -t nat -D PREROUTING $nat_index >/dev/null 2>&1
done
fake=$(iptables -nvL OUTPUT -t nat |sed 1,2d |sed -n '/198.18.0.0\/16/=' |sort -r)
for fake in $fake; do
iptables -t nat -D OUTPUT $fake >/dev/null 2>&1
done
fake2=$(iptables -nvL OUTPUT -t nat |sed 1,2d |sed -n '/198.18.0.1\/16/=' |sort -r)
for fake2 in $fake2; do
iptables -t nat -D OUTPUT $fake2 >/dev/null 2>&1
done
iptables -t nat -I PREROUTING -p tcp --dport 53 -j ACCEPT
revert_dns >/dev/null 2>&1
}
if [ ! $(pidof clash) ]; then
remove_mark
sleep 5
wget --no-check-certificate --user-agent="Clash/OpenWRT" ${url} -O 2>&1 >1 ${CONFIG_YAML_PATH}
if [ ! -f ${CORE_PATH} ];then
dcore
fi
/etc/init.d/clash restart 2>/dev/null
fi

View File

@ -1,125 +0,0 @@
#!/bin/bash /etc/rc.common
clash_url=$(uci get clash.config.clash_url 2>/dev/null)
ssr_url=$(uci get clash.config.ssr_url 2>/dev/null)
v2_url=$(uci get clash.config.v2_url 2>/dev/null)
config_name=$(uci get clash.config.config_name 2>/dev/null)
subtype=$(uci get clash.config.subcri 2>/dev/null)
REAL_LOG="/usr/share/clash/clash_real.txt"
lang=$(uci get luci.main.lang 2>/dev/null)
CONFIG_YAML="/etc/clash/config/sub/${config_name}.yaml"
if [ $config_name == "" ] || [ -z $config_name ];then
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Tag Your Config" >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "标记您的配置" >$REAL_LOG
fi
sleep 5
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
fi
if [ ! -f "/etc/clash/clashbackup/confit_list.conf" ];then
touch /etc/clash/clashbackup/confit_list.conf
fi
check_name=$(grep -F "${config_name}.yaml" "/etc/clash/clashbackup/confit_list.conf")
if [ ! -z $check_name ];then
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Config with same name exist, please rename and download again" >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "已存在同名配置,请重命名名配置重新下载" >$REAL_LOG
fi
sleep 5
echo "Clash for OpenWRT" >$REAL_LOG
exit 0
else
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Downloading Configuration..." >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "开始下载配置" >$REAL_LOG
fi
sleep 1
if [ "$subtype" = "clash" ];then
wget -c4 --no-check-certificate --user-agent="Clash/OpenWRT" "$clash_url" -O 2>&1 >1 $CONFIG_YAML
if [ "$?" -eq "0" ]; then
echo "${config_name}.yaml#$clash_url#$subtype" >>/etc/clash/clashbackup/confit_list.conf
fi
fi
if [ "$subtype" = "ssr2clash" ];then
wget -c4 --no-check-certificate --user-agent="Clash/OpenWRT" "https://gfwsb.114514.best/sub?target=clashr&url=$ssr_url" -O 2>&1 >1 $CONFIG_YAML
if [ "$?" -eq "0" ]; then
echo "${config_name}.yaml#$ssr_url#$subtype" >>/etc/clash/clashbackup/confit_list.conf
CONFIG_YAMLL="/tmp/conf"
da_password=$(uci get clash.config.dash_pass 2>/dev/null)
redir_port=$(uci get clash.config.redir_port 2>/dev/null)
http_port=$(uci get clash.config.http_port 2>/dev/null)
socks_port=$(uci get clash.config.socks_port 2>/dev/null)
dash_port=$(uci get clash.config.dash_port 2>/dev/null)
bind_addr=$(uci get clash.config.bind_addr 2>/dev/null)
allow_lan=$(uci get clash.config.allow_lan 2>/dev/null)
log_level=$(uci get clash.config.level 2>/dev/null)
p_mode=$(uci get clash.config.p_mode 2>/dev/null)
sed -i "/^Proxy:/i\#clash-openwrt" $CONFIG_YAML 2>/dev/null
sed -i '1,/#clash-openwrt/d' $CONFIG_YAML 2>/dev/null
cat /usr/share/clash/dns.yaml $CONFIG_YAML > $CONFIG_YAMLL 2>/dev/null
mv $CONFIG_YAMLL $CONFIG_YAML 2>/dev/null
sed -i "1i\#****CLASH-CONFIG-START****#" $CONFIG_YAML 2>/dev/null
sed -i "2i\port: ${http_port}" $CONFIG_YAML 2>/dev/null
sed -i "/port: ${http_port}/a\socks-port: ${socks_port}" $CONFIG_YAML 2>/dev/null
sed -i "/socks-port: ${socks_port}/a\redir-port: ${redir_port}" $CONFIG_YAML 2>/dev/null
sed -i "/redir-port: ${redir_port}/a\allow-lan: ${allow_lan}" $CONFIG_YAML 2>/dev/null
if [ $allow_lan == "true" ]; then
sed -i "/allow-lan: ${allow_lan}/a\bind-address: \"${bind_addr}\"" $CONFIG_YAML 2>/dev/null
sed -i "/bind-address: \"${bind_addr}\"/a\mode: ${p_mode}" $CONFIG_YAML 2>/dev/null
sed -i "/mode: ${p_mode}/a\log-level: ${log_level}" $CONFIG_YAML 2>/dev/null
sed -i "/log-level: ${log_level}/a\external-controller: 0.0.0.0:${dash_port}" $CONFIG_YAML 2>/dev/null
sed -i "/external-controller: 0.0.0.0:${dash_port}/a\secret: \"${da_password}\"" $CONFIG_YAML 2>/dev/null
sed -i "/secret: \"${da_password}\"/a\external-ui: \"/usr/share/clash/dashboard\"" $CONFIG_YAML 2>/dev/null
else
sed -i "/allow-lan: ${allow_lan}/a\mode: Rule" $CONFIG_YAML 2>/dev/null
sed -i "/mode: Rule/a\log-level: ${log_level}" $CONFIG_YAML 2>/dev/null
sed -i "/log-level: ${log_level}/a\external-controller: 0.0.0.0:${dash_port}" $CONFIG_YAML 2>/dev/null
sed -i "/external-controller: 0.0.0.0:${dash_port}/a\secret: \"${da_password}\"" $CONFIG_YAML 2>/dev/null
sed -i "/secret: \"${da_password}\"/a\external-ui: \"/usr/share/clash/dashboard\"" $CONFIG_YAML 2>/dev/null
fi
sleep 1
fi
fi
if [ "$subtype" = "v2clash" ];then
wget -c4 --no-check-certificate --user-agent="Clash/OpenWRT" "https://tgbot.lbyczf.com/v2rayn2clash?url=$v2_url" -O 2>&1 >1 $CONFIG_YAML
if [ "$?" -eq "0" ]; then
echo "${config_name}.yaml#$v2_url#$subtype" >>/etc/clash/clashbackup/confit_list.conf
fi
fi
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Downloading Configuration 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
fi

View File

@ -1,78 +0,0 @@
#!/bin/bash /etc/rc.common
. /lib/functions.sh
RULE_FILE_NAME="$1"
RULE_FILE_ENNAME=$(grep -F $RULE_FILE_NAME /usr/share/clash/rules/rules.list |awk -F ',' '{print $3}' 2>/dev/null)
if [ ! -z "$RULE_FILE_ENNAME" ]; then
DOWNLOAD_PATH=$(grep -F $RULE_FILE_NAME /usr/share/clash/rules/rules.list |awk -F ',' '{print $2}' 2>/dev/null)
else
DOWNLOAD_PATH=$RULE_FILE_NAME
fi
RULE_FILE_DIR="/usr/share/clash/rules/g_rules/$RULE_FILE_NAME"
TMP_RULE_DIR="/tmp/$RULE_FILE_NAME"
LOG_FILE="/usr/share/clash/clash.txt"
REAL_LOG="/usr/share/clash/clash_real.txt"
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Updating 【$RULE_FILE_NAME】 Rule..." >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "开始下载【$RULE_FILE_NAME】规则..." >$REAL_LOG
fi
wget --no-check-certificate -c4 https://raw.githubusercontent.com/FQrabbit/SSTap-Rule/master/rules/"$DOWNLOAD_PATH" -O 2>&1 >1 "$TMP_RULE_DIR"
if [ "$?" -eq "0" ] && [ "$(ls -l $TMP_RULE_DIR |awk '{print $5}')" -ne 0 ]; then
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "$RULE_FILE_NAME】 Downloaded successfully. Checking whether the rule version is updated.." >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "$RULE_FILE_NAME】规则下载成功,检查规则版本是否更新..." >$REAL_LOG
fi
cmp -s $TMP_RULE_DIR $RULE_FILE_DIR
if [ "$?" -ne "0" ]; then
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Rule version has been updated. Start to replace the old rule version.." >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "规则版本有更新,开始替换旧规则版本..." >$REAL_LOG
fi
mv $TMP_RULE_DIR $RULE_FILE_DIR >/dev/null 2>&1
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Delete download cache" >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "删除下载缓存..." >$REAL_LOG
fi
rm -rf $TMP_RULE_DIR >/dev/null 2>&1
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Rule File【$RULE_FILE_NAME】 Download Successful" >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "$RULE_FILE_NAME】规则更新成功!" >$REAL_LOG
fi
sleep 2
echo "Clash for OpenWRT" >$REAL_LOG
else
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Updated Rule File【$RULE_FILE_NAME】 No Change, Do Nothing" >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "$RULE_FILE_NAME】规则版本没有更新,停止继续操作..." >$REAL_LOG
fi
rm -rf $TMP_RULE_DIR >/dev/null 2>&1
sleep 2
echo "Clash for OpenWRT" >$REAL_LOG
fi
else
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Rule File【$RULE_FILE_NAME】 Download Error" >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "$RULE_FILE_NAME】规则下载失败,请检查网络或稍后再试!" >$REAL_LOG
fi
rm -rf $TMP_RULE_DIR >/dev/null 2>&1
sleep 2
echo "Clash for OpenWRT" >$REAL_LOG
fi

View File

@ -1 +0,0 @@
Clash for OpenWRT

View File

@ -1,190 +0,0 @@
#!/bin/sh
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
LOG_FILE="/tmp/clash_update.txt"
MODELTYPE=$(uci get clash.config.download_core 2>/dev/null)
CORETYPE=$(uci get clash.config.dcore 2>/dev/null)
CORE=$(uci get clash.config.core 2>/dev/null)
lang=$(uci get luci.main.lang 2>/dev/null)
if [ -f /tmp/clash.gz ];then
rm -rf /tmp/clash.gz >/dev/null 2>&1
fi
echo '' >/tmp/clash_update.txt 2>/dev/null
if [ -f /usr/share/clash/core_down_complete ];then
rm -rf /usr/share/clash/core_down_complete 2>/dev/null
fi
if [ $CORETYPE -eq 4 ];then
if [ -f /usr/share/clash/download_dtun_version ];then
rm -rf /usr/share/clash/download_dtun_version
fi
if [ $lang == "zh_cn" ];then
echo " ${LOGTIME} - 正在检查最新版本。。" >$LOG_FILE
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo " ${LOGTIME} - Checking latest version.." >$LOG_FILE
fi
new_clashdtun_core_version=`wget -qO- "https://hub.fastgit.org/Dreamacro/clash/releases/tag/premium"| grep "/download/premium/"| head -n 1| awk -F " " '{print $2}'| awk -F "-" '{print $4}'| sed "s/.gz\"//g"`
if [ $new_clashdtun_core_version ]; then
echo $new_clashdtun_core_version > /usr/share/clash/download_dtun_version 2>&1 & >/dev/null
elif [ $new_clashdtun_core_version =="" ]; then
echo 0 > /usr/share/clash/download_dtun_version 2>&1 & >/dev/null
fi
sleep 5
if [ -f /usr/share/clash/download_dtun_version ];then
CLASHDTUNC=$(sed -n 1p /usr/share/clash/download_dtun_version 2>/dev/null)
fi
fi
if [ $CORETYPE -eq 3 ];then
if [ -f /usr/share/clash/download_tun_version ];then
rm -rf /usr/share/clash/download_tun_version
fi
if [ $lang == "zh_cn" ];then
echo " ${LOGTIME} - 正在检查最新版本。。" >$LOG_FILE
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo " ${LOGTIME} - Checking latest version.." >$LOG_FILE
fi
new_clashtun_core_version=`wget -qO- "https://hub.fastgit.org/comzyh/clash/tags"| grep "/comzyh/clash/releases/"| head -n 1| awk -F "/tag/" '{print $2}'| sed 's/\">//g'`
if [ $new_clashtun_core_version ]; then
echo $new_clashtun_core_version > /usr/share/clash/download_tun_version 2>&1 & >/dev/null
elif [ $new_clashtun_core_version =="" ]; then
echo 0 > /usr/share/clash/download_tun_version 2>&1 & >/dev/null
fi
sleep 5
if [ -f /usr/share/clash/download_tun_version ];then
CLASHTUN=$(sed -n 1p /usr/share/clash/download_tun_version 2>/dev/null)
fi
fi
if [ $CORETYPE -eq 1 ];then
if [ -f /usr/share/clash/download_core_version ];then
rm -rf /usr/share/clash/download_core_version
fi
if [ $lang == "zh_cn" ];then
echo " ${LOGTIME} - 正在检查最新版本。。" >$LOG_FILE
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo " ${LOGTIME} - Checking latest version.." >$LOG_FILE
fi
new_clashr_core_version=`wget -qO- "https://hub.fastgit.org/Dreamacro/clash/tags"| grep "/Dreamacro/clash/releases/"| head -n 1| awk -F "/tag/" '{print $2}'| sed 's/\">//g'`
if [ $new_clashr_core_version ]; then
echo $new_clashr_core_version > /usr/share/clash/download_core_version 2>&1 & >/dev/null
elif [ $new_clashr_core_version =="" ]; then
echo 0 > /usr/share/clash/download_core_version 2>&1 & >/dev/null
fi
sleep 5
if [ -f /usr/share/clash/download_core_version ];then
CLASHVER=$(sed -n 1p /usr/share/clash/download_core_version 2>/dev/null)
fi
fi
sleep 2
update(){
if [ -f /tmp/clash.gz ];then
rm -rf /tmp/clash.gz >/dev/null 2>&1
fi
if [ $lang == "zh_cn" ];then
echo " ${LOGTIME} - 开始下载 Clash 内核..." >$LOG_FILE
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo " ${LOGTIME} - Starting Clash Core download" >$LOG_FILE
fi
if [ $CORETYPE -eq 1 ];then
wget --no-check-certificate https://hub.fastgit.org/Dreamacro/clash/releases/download/"$CLASHVER"/clash-"$MODELTYPE"-"$CLASHVER".gz -O 2>&1 >1 /tmp/clash.gz
elif [ $CORETYPE -eq 3 ];then
wget --no-check-certificate https://hub.fastgit.org/comzyh/clash/releases/download/"$CLASHTUN"/clash-"$MODELTYPE"-"$CLASHTUN".gz -O 2>&1 >1 /tmp/clash.gz
elif [ $CORETYPE -eq 4 ];then
wget --no-check-certificate https://hub.fastgit.org/Dreamacro/clash/releases/download/premium/clash-"$MODELTYPE"-"$CLASHDTUNC".gz -O 2>&1 >1 /tmp/clash.gz
fi
if [ "$?" -eq "0" ] && [ "$(ls -l /tmp/clash.gz |awk '{print int($5)}')" -ne 0 ]; then
if [ $lang == "zh_cn" ];then
echo " ${LOGTIME} - 开始解压缩文件" >$LOG_FILE
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo " ${LOGTIME} - Beginning to unzip file" >$LOG_FILE
fi
gunzip /tmp/clash.gz >/dev/null 2>&1\
&& rm -rf /tmp/clash.gz >/dev/null 2>&1\
&& chmod 755 /tmp/clash\
&& chown root:root /tmp/clash
if [ $lang == "zh_cn" ];then
echo " ${LOGTIME} - 完成下载内核,正在更新..." >$LOG_FILE
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo " ${LOGTIME} - Successfully downloaded core, updating now..." >$LOG_FILE
fi
if [ $CORETYPE -eq 1 ];then
rm -rf /etc/clash/clash >/dev/null 2>&1
mv /tmp/clash /etc/clash/clash >/dev/null 2>&1
rm -rf /usr/share/clash/core_version >/dev/null 2>&1
mv /usr/share/clash/download_core_version /usr/share/clash/core_version >/dev/null 2>&1
if [ $lang == "zh_cn" ];then
echo " ${LOGTIME} - Clash内核更新成功" >$LOG_FILE
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo " ${LOGTIME} - Clash Core Update Successful" >$LOG_FILE
fi
elif [ $CORETYPE -eq 3 ];then
rm -rf /etc/clash/clashtun/clash >/dev/null 2>&1
mv /tmp/clash /etc/clash/clashtun/clash >/dev/null 2>&1
rm -rf /usr/share/clash/tun_version >/dev/null 2>&1
mv /usr/share/clash/download_tun_version /usr/share/clash/tun_version >/dev/null 2>&1
tun=$(sed -n 1p /usr/share/clash/tun_version 2>/dev/null)
sed -i "s/${tun}/v${tun}/g" /usr/share/clash/tun_version 2>&1
if [ $lang == "zh_cn" ];then
echo " ${LOGTIME} - ClashTun内核更新成功" >$LOG_FILE
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo " ${LOGTIME} - ClashTun Core Update Successful" >>$LOG_FILE
fi
elif [ $CORETYPE -eq 4 ];then
rm -rf /etc/clash/dtun/clash >/dev/null 2>&1
mv /tmp/clash /etc/clash/dtun/clash >/dev/null 2>&1
rm -rf /usr/share/clash/dtun_version >/dev/null 2>&1
mv /usr/share/clash/download_dtun_version /usr/share/clash/dtun_version >/dev/null 2>&1
dtun=$(sed -n 1p /usr/share/clash/dtun_version 2>/dev/null)
sed -i "s/${dtun}/v${dtun}/g" /usr/share/clash/dtun_version 2>&1
if [ $lang == "zh_cn" ];then
echo " ${LOGTIME} - ClashDTun内核更新成功" >$LOG_FILE
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo " ${LOGTIME} - ClashDTun Core Update Successful" >>$LOG_FILE
fi
fi
sleep 2
touch /usr/share/clash/core_down_complete >/dev/null 2>&1
sleep 2
rm -rf /var/run/core_update >/dev/null 2>&1
echo "" > /tmp/clash_update.txt >/dev/null 2>&1
else
if [ $lang == "zh_cn" ];then
echo " ${LOGTIME} - 核心程序下载失败,请检查网络或稍后再试!" >$LOG_FILE
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo " ${LOGTIME} - Core Update Error" >$LOG_FILE
fi
rm -rf /tmp/clash.tar.gz >/dev/null 2>&1
echo "" > /tmp/clash_update.txt >/dev/null 2>&1
fi
if pidof clash >/dev/null; then
if [ $CORETYPE == $CORE ];then
/etc/init.d/clash restart >/dev/null
fi
fi
}
if [ $CORETYPE -eq 1 ] || [ $CORETYPE -eq 3 ] || [ $CORETYPE -eq 4 ]; then
update
fi

View File

@ -1,48 +0,0 @@
#!/bin/sh
RULE_FILE_NAME="$1"
if [ -z "$(grep ",$RULE_FILE_NAME" /usr/share/clash/create/rule_provider.list 2>/dev/null)" ]; then
DOWNLOAD_PATH=$(grep -F "$RULE_FILE_NAME" /usr/share/clash/create/rule_provider.list |awk -F ',' '{print $3$4}' 2>/dev/null)
else
DOWNLOAD_PATH=$(grep -F ",$RULE_FILE_NAME" /usr/share/clash/create/rule_provider.list |awk -F ',' '{print $3$4}' 2>/dev/null)
fi
RULE_FILE_DIR="/etc/clash/ruleprovider/$RULE_FILE_NAME"
TMP_RULE_DIR="/tmp/$RULE_FILE_NAME"
LOG_FILE="/usr/share/clash/clash.txt"
REAL_LOG="/usr/share/clash/clash_real.txt"
url="https://cdn.jsdelivr.net/gh/$DOWNLOAD_PATH"
behavior=$(grep -F $RULE_FILE_NAME /usr/share/clash/create/rule_provider.list |awk -F ',' '{print $2}' 2>/dev/null)
namee=$(grep -F ",$RULE_FILE_NAME" /usr/share/clash/create/rule_provider.list |awk -F ',' '{print $4}' | awk -F '.' '{print $1}' 2>/dev/null)
path="./ruleprovider/"$RULE_FILE_NAME""
curl -sL --connect-timeout 5 --retry 2 https://cdn.jsdelivr.net/gh/"$DOWNLOAD_PATH" -o "$TMP_RULE_DIR" >/dev/null 2>&1
if [ "$?" -eq "0" ] && [ -s "$TMP_RULE_DIR" ] && [ -z "$(grep "404: Not Found" "$TMP_RULE_DIR")" ]; then
cmp -s $TMP_RULE_DIR $RULE_FILE_DIR
if [ "$?" -ne "0" ]; then
mv $TMP_RULE_DIR $RULE_FILE_DIR >/dev/null 2>&1\
&& rm -rf $TMP_RULE_DIR >/dev/null 2>&1
name=clash
uci_name_tmp=$(uci add $name ruleprovider)
uci_set="uci -q set $name.$uci_name_tmp."
uci_add="uci -q add_list $name.$uci_name_tmp."
${uci_set}type="http"
${uci_set}name="$namee"
${uci_set}path="$path"
${uci_set}behavior="$behavior"
${uci_set}url="$url"
${uci_set}interval="86400"
uci commit clash
return 1
else
rm -rf $TMP_RULE_DIR >/dev/null 2>&1
return 2
fi
else
rm -rf $TMP_RULE_DIR >/dev/null 2>&1
return 0
fi

File diff suppressed because it is too large Load Diff

View File

@ -1,46 +0,0 @@
#!/bin/sh /etc/rc.common
. /lib/functions.sh
cfg_groups_set()
{
CFG_FILE="/etc/config/clash"
local section="$1"
config_get "name" "$section" "name" ""
config_get "old_name_cfg" "$section" "old_name_cfg" ""
config_get "old_name" "$section" "old_name" ""
if [ -z "$name" ]; then
return
fi
if [ -z "$old_name_cfg" ]; then
uci set clash."$section".old_name_cfg="$name"
uci commit clash
fi
if [ -z "$old_name" ]; then
uci set clash."$section".old_name="$name"
uci commit clash
fi
if [ "$name" != "$old_name_cfg" ] && [ ! -z "$old_name_cfg" ]; then
sed -i "s/old_name_cfg \'${old_name_cfg}\'/old_name_cfg \'${name}\'/g" $CFG_FILE 2>/dev/null
sed -i "s/groups \'${old_name_cfg}/groups \'${name}/g" $CFG_FILE 2>/dev/null
sed -i "s/other_group \'${old_name_cfg}/other_group \'${name}/g" $CFG_FILE 2>/dev/null
sed -i "s/new_servers_group \'${old_name_cfg}/new_servers_group \'${name}/g" $CFG_FILE 2>/dev/null
sed -i "s/relay_groups \'${old_name_cfg}/relay_groups \'${name}/g" $CFG_FILE 2>/dev/null
config_load "clash"
fi
}
start(){
status=$(ps|grep -c /usr/share/clash/create/pgroups.sh)
[ "$status" -gt "3" ] && exit 0
config_load "clash"
config_foreach cfg_groups_set "pgroups"
}
start

View File

@ -1,76 +0,0 @@
All-4,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,All-4.yaml
BBC-iPlayer,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,BBC-iPlayer.yaml
Bahamut,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,Bahamut.yaml
DAZN,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,DAZN.yaml
DisneyPlus,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,DisneyPlus.yaml
FOX,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,FOX.yaml
HBO-GO-HKG,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,HBO-GO-HKG.yaml
HBO,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,HBO.yaml
HWTV,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,HWTV.yaml
Hulu-JPN,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,Hulu-JPN.yaml
Hulu,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,Hulu.yaml
ITV,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,ITV.yaml
KKTV,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,KKTV.yaml
LINE-TV,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,LINE-TV.yaml
LiTV,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,LiTV.yaml
My5,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,My5.yaml
Netflix,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,Netflix.yaml
Now-E,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,Now-E.yaml
PBS,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,PBS.yaml
Pornhub,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,Pornhub.yaml
Prime-Video,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,Prime-Video.yaml
TaiwanGood,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,TaiwanGood.yaml
TikTok,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,TikTok.yaml
ViuTV,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,ViuTV.yaml
YouTube,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,YouTube.yaml
encoreTVB,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,encoreTVB.yaml
myTV-SUPER,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,myTV-SUPER.yaml
niconico,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Video/,niconico.yaml
Himalaya,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Podcast/,Himalaya.yaml
Deezer,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Music/,Deezer.yaml
Instagram,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Music/,Instagram.yaml
JOOX,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Music/,JOOX.yaml
KKBOX,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Music/,KKBOX.yaml
Pandora,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Music/,Pandora.yaml
SoundCloud,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Music/,SoundCloud.yaml
Spotify,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Music/,Spotify.yaml
TIDAL,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Music/,TIDAL.yaml
Twitch,classical,frainzy1477/clashrules@master/Clash/RuleSet/StreamingMedia/Live/,Twitch.yaml
Advertising,classical,frainzy1477/clashrules@master/Clash/RuleSet/Guard/,Advertising.yaml
Hijacking,classical,frainzy1477/clashrules@master/Clash/RuleSet/Guard/,Hijacking.yaml
Privacy,classical,frainzy1477/clashrules@master/Clash/RuleSet/Guard/,Privacy.yaml
ChinaIP,ipcidr,frainzy1477/clashrules@master/Clash/RuleSet/Extra/,ChinaIP.yaml
IPBlackhole,ipcidr,frainzy1477/clashrules@master/Clash/RuleSet/Extra/,IP-Blackhole.yaml
PayPal,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/,PayPal.yaml
Scholar,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/,Scholar.yaml
AppStore,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,AppStore.yaml
Apple,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,Apple.yaml
AppStoreConnect,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,AppStoreConnect.yaml
Apple-FindMy,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,FindMy.yaml
Apple-Mail,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,Mail.yaml
Apple-Music,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,Music.yaml
Apple-News,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,News.yaml
Apple-Siri,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,Siri.yaml
Apple-SoftwareUpdate,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,SoftwareUpdate.yaml
Apple-TV,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,TV.yaml
Apple-TestFlight,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,TestFlight.yaml
Apple-iCloud,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Apple/,iCloud.yaml
Steam,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Game/,Steam.yaml
Blizzard,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Game/,Blizzard.yaml
GoogleDrive,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Google/,GoogleDrive.yaml
GoogleSearch,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Google/,GoogleSearch.yaml
OneDrive,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Microsoft/,OneDrive.yaml
Telegram,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Telegram/,Telegram.yaml
TelegramNL,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Telegram/,TelegramNL.yaml
TelegramSG,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Telegram/,TelegramSG.yaml
TelegramUS,classical,frainzy1477/clashrules@master/Clash/RuleSet/Extra/Telegram/,TelegramUS.yaml
广告IP合集,ipcidr,frainzy1477/Clash-Ruleset@master/,Reject_IP.yaml
广告(域名合集,domain,frainzy1477/Clash-Ruleset@master/,Reject_Domain.yaml
网易云音乐域名,domain,frainzy1477/Clash-Ruleset@master/,Netease_Music_Domains.yaml
苹果服务合集,domain,frainzy1477/Clash-Ruleset@master/,Apple_Domain.yaml
国外流媒体IP合集,ipcidr,frainzy1477/Clash-Ruleset@master/,Stream_IP.yaml
国外流媒体(域名合集,domain,frainzy1477/Clash-Ruleset@master/,Stream_Domain.yaml
国外IP代理合集,ipcidr,frainzy1477/Clash-Ruleset@master/,Global_IP.yaml
国外域名代理合集,domain,frainzy1477/Clash-Ruleset@master/,Global_Domain.yaml
国内IP合集,ipcidr,frainzy1477/Clash-Ruleset@master/,Domestic_IP.yaml
国内常用域名,domain,frainzy1477/Clash-Ruleset@master/,Domestic_Domain.yaml

View File

@ -1,30 +0,0 @@
#!/bin/sh /etc/rc.common
. /lib/functions.sh
rules_set()
{
CFG_FILE="/etc/config/clash"
local section="$1"
config_get "type" "$section" "type" ""
config_get "rulename" "$section" "rulename" ""
config_get "rulenamee" "$section" "rulenamee" ""
if [ -z "$type" ]; then
return
fi
if [ -z "$rulename" ]; then
uci set clash."$section".rulename="$rulenamee"
uci commit clash
fi
}
start(){
config_load "clash"
config_foreach rules_set "rules"
}
start

View File

@ -1,12 +0,0 @@
script:
code: |
def main(ctx, metadata):
ip = metadata["dst_ip"] = ctx.resolve_ip(metadata["host"])
if ip == "":
return "DIRECT"
code = ctx.geoip(ip)
if code == "LAN" or code == "CN":
return "DIRECT"
return "Proxy" # default policy for requests which are not matched by any other script

View File

@ -1,11 +0,0 @@
#!/bin/bash /etc/rc.common
. /lib/functions.sh
name=$(uci get clash.config.config_cus_remove 2>/dev/null)
check_match_name=$(grep -F "$name" "/etc/clash/clashbackup/create_list.conf")
line_no=$(grep -n "$check_match_name" /etc/clash/clashbackup/create_list.conf |awk -F ':' '{print $1}')
if [ ! -z $check_match_name ];then
sed -i "${line_no}d" /etc/clash/clashbackup/create_list.conf
rm -rf /etc/clash/config/custom/${name}
sed -i '/^$/d' /etc/clash/clashbackup/create_list.conf
fi

View File

@ -1 +0,0 @@
clash.razord.top

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

File diff suppressed because one or more lines are too long

View File

@ -1,20 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/Dreamacro/clash/docs/logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#f4f5f6" />
<meta name="description" content="Clash web port" />
<!--meta name="external-controller" content="http://secret@example.com:9090"-->
<title>Clash</title>
<script type="module" crossorigin src="./assets/index.65038aa0.js"></script>
<link rel="modulepreload" href="./assets/vendor.ca041cc5.js">
<link rel="stylesheet" href="./assets/index.c7a648b5.css">
<link rel="manifest" href="./manifest.webmanifest"><script>if('serviceWorker' in navigator) {window.addEventListener('load', () => {navigator.serviceWorker.register('./sw.js', { scope: './' })})}</script></head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>

View File

@ -1 +0,0 @@
{"name":"Clash Dashboard","short_name":"Clash Dashboard","start_url":"/","display":"standalone","background_color":"#ffffff","lang":"en","scope":"./","icons":[{"src":"//cdn.jsdelivr.net/gh/Dreamacro/clash-dashboard/src/assets/Icon.png","sizes":"512x512","type":"image/png"}]}

View File

@ -1 +0,0 @@
if(!self.define){const e=e=>{"require"!==e&&(e+=".js");let s=Promise.resolve();return r[e]||(s=new Promise((async s=>{if("document"in self){const r=document.createElement("script");r.src=e,document.head.appendChild(r),r.onload=s}else importScripts(e),s()}))),s.then((()=>{if(!r[e])throw new Error(`Module ${e} didnt register its module`);return r[e]}))},s=(s,r)=>{Promise.all(s.map(e)).then((e=>r(1===e.length?e[0]:e)))},r={require:Promise.resolve(s)};self.define=(s,i,t)=>{r[s]||(r[s]=Promise.resolve().then((()=>{let r={};const n={uri:location.origin+s.slice(1)};return Promise.all(i.map((s=>{switch(s){case"exports":return r;case"module":return n;default:return e(s)}}))).then((e=>{const s=t(...e);return r.default||(r.default=s),r}))})))}}define("./sw.js",["./workbox-0c0655d9"],(function(e){"use strict";self.addEventListener("message",(e=>{e.data&&"SKIP_WAITING"===e.data.type&&self.skipWaiting()})),e.precacheAndRoute([{url:"assets/index.65038aa0.js",revision:"11d48371eb55942ea8665cc2b7ebb232"},{url:"assets/index.c7a648b5.css",revision:"9712522fe980e09bf1d10f2564e50812"},{url:"assets/vendor.ca041cc5.js",revision:"dbe6a643df33c4994e57ed615148ec93"},{url:"index.html",revision:"0b0a322dd9fffeb1b556f7d535c3fb38"},{url:"manifest.webmanifest",revision:"d3dd1da0aa7614180924343e65244285"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))}));

File diff suppressed because one or more lines are too long

View File

@ -1,31 +0,0 @@
#!/bin/sh /etc/rc.common
. /lib/functions.sh
cfg_groups_set()
{
CFG_FILE="/etc/config/clash"
local section="$1"
config_get "name" "$section" "name" ""
config_get "old_name_cfg" "$section" "old_name_cfg" ""
config_get "old_name" "$section" "old_name" ""
if [ -z "$name" ]; then
return
fi
if [ "$name" != "$old_name_cfg" ]; then
sed -i "s/\'${old_name_cfg}\'/\'${name}\'/g" $CFG_FILE 2>/dev/null
sed -i "s/old_name \'${name}\'/old_name \'${old_name}\'/g" $CFG_FILE 2>/dev/null
config_load "clash"
fi
}
start(){
status=$(ps|grep -c /usr/share/clash/game-groups.sh)
[ "$status" -gt "3" ] && exit 0
config_load "clash"
config_foreach cfg_groups_set "conf_groups"
}

View File

@ -1,103 +0,0 @@
#!/bin/bash /etc/rc.common
. /lib/functions.sh
GROUP_FILE="/tmp/yaml_group.yaml"
GAME_RULE_FILE="/tmp/yaml_game_rule_group.yaml"
game_rules=$(uci get clash.config.g_rules 2>/dev/null)
CUSTOM_RULE_FILE="/tmp/ipadd.conf"
RULE="/tmp/rules_conf.yaml"
CLASH="/tmp/conf.yaml"
CONFIG_YAML="/etc/clash/config.yaml"
CLASH_CONFIG="/tmp/config.yaml"
if [ "${game_rules}" -eq 1 ];then
if [ -f $CLASH_CONFIG ];then
rm -rf $CLASH_CONFIG 2>/dev/null
fi
cp $CONFIG_YAML $CLASH_CONFIG 2>/dev/null
if [ ! -z "$(grep "^Rule:" "$CLASH_CONFIG")" ]; then
sed -i "/^Rule:/i\#RULESTART#" $CLASH_CONFIG 2>/dev/null
elif [ ! -z "$(grep "^rules:" "$CLASH_CONFIG")" ]; then
sed -i "/^rules:/i\#RULESTART#" $CLASH_CONFIG 2>/dev/null
fi
sed -i -e "\$a#RULEEND#" $CLASH_CONFIG 2>/dev/null
awk '/#RULESTART#/,/#RULEEND#/{print}' "$CLASH_CONFIG" 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed 's/\t/ /g' 2>/dev/null |grep - |awk -F '- ' '{print "- "$2}' | sed 's/^ \{0,\}//' 2>/dev/null |sed 's/ \{0,\}$//' 2>/dev/null >$RULE 2>&1
sed -i '/#RULESTART#/,/#RULEEND#/d' "$CLASH_CONFIG" 2>/dev/null
sed -i -e "\$a " $CLASH_CONFIG 2>/dev/null
sed -i "1i\rules:" $RULE 2>/dev/null
cat $CLASH_CONFIG $RULE >$CLASH 2>/dev/null
mv $CLASH $CLASH_CONFIG 2>/dev/null
rm -rf $RULE 2>/dev/null
get_rule_file()
{
if [ -z "$1" ]; then
return
fi
GAME_RULE_FILE_NAME=$(grep -F $1 /usr/share/clash/rules/rules.list |awk -F ',' '{print $3}' 2>/dev/null)
if [ -z "$GAME_RULE_FILE_NAME" ]; then
GAME_RULE_FILE_NAME=$(grep -F $1 /usr/share/clash/rules/rules.list |awk -F ',' '{print $2}' 2>/dev/null)
fi
GAME_RULE_PATH="/usr/share/clash/rules/g_rules/$GAME_RULE_FILE_NAME"
sed '/^#/d' $GAME_RULE_PATH 2>/dev/null |sed '/^ *$/d' |awk '{print "- IP-CIDR,"$0}' |awk -v tag="$2" '{print $0","'tag'""}' >> $GAME_RULE_FILE 2>/dev/null
set_rule_file=1
}
yml_game_rule_get()
{
local section="$1"
config_get "group" "$section" "group" ""
if [ -f $GAME_RULE_FILE ];then
rm -rf $GAME_RULE_FILE 2>/dev/null
fi
if [ -z "$group" ]; then
return
fi
config_list_foreach "$section" "rule_name" get_rule_file "$group"
}
config_load "clash"
config_foreach yml_game_rule_get "game"
if [ -f $GAME_RULE_FILE ];then
sed -i -e "\$a#GAMERULEEND#" $GAME_RULE_FILE 2>/dev/null
sed -i '/#GAMERULESTART#/,/#GAMERULEEND#/d' "$CLASH_CONFIG" 2>/dev/null
if [ ! -z "$(grep "^ \{0,\}- GEOIP" "$CLASH_CONFIG")" ]; then
sed -i '1,/^ \{0,\}- GEOIP,/{/^ \{0,\}- GEOIP,/s/^ \{0,\}- GEOIP,/#GAMERULESTART#\n&/}' "$CLASH_CONFIG" 2>/dev/null
elif [ ! -z "$(grep "^ \{0,\}- MATCH," "$CLASH_CONFIG")" ]; then
sed -i '1,/^ \{0,\}- MATCH,/{/^ \{0,\}- MATCH,/s/^ \{0,\}- MATCH,/#GAMERULESTART#\n&/}' "$CLASH_CONFIG" 2>/dev/null
else
echo "#GAMERULESTART#" >> "$CLASH_CONFIG" 2>/dev/null
fi
sed -i '/GAMERULESTART/r/tmp/yaml_game_rule_group.yaml' "$CLASH_CONFIG" 2>/dev/null
mv $CLASH_CONFIG $CONFIG_YAML 2>/dev/null
fi
rm -rf $GAME_RULE_FILE 2>/dev/null
else
sed -i '/#GAMERULESTART#/,/#GAMERULEEND#/d' "$CONFIG_YAML" 2>/dev/null
rm -rf $GAME_RULE_FILE 2>/dev/null
fi

View File

@ -1,34 +0,0 @@
#!/bin/sh
Key=$(uci get clash.config.license_key 2>/dev/null)
geoip_source=$(uci get clash.config.geoip_source 2>/dev/null)
if [ -f /var/run/geoip_down_complete ];then
rm -rf /var/run/geoip_down_complete 2>/dev/null
fi
echo '' >/tmp/geoip_update.txt 2>/dev/null
if [ $geoip_source == 1 ];then
wget -c4 --no-check-certificate --timeout=300 --user-agent="Mozilla" "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key="$Key"&suffix=tar.gz" -O /tmp/ipdb.tar.gz
if [ "$?" -eq "0" ]; then
tar zxvf /tmp/ipdb.tar.gz -C /tmp\
&& rm -rf /tmp/ipdb.tar.gz >/dev/null 2>&1\
&& mv /tmp/GeoLite2-Country_*/GeoLite2-Country.mmdb /etc/clash/Country.mmdb\
&& rm -rf /tmp/GeoLite2-Country_* >/dev/null 2>&1
fi
else
rm -rf /etc/clash/Country.mmdb
wget -c4 --no-check-certificate --timeout=300 --user-agent="Mozilla" https://cdn.jsdelivr.net/gh/alecthw/mmdb_china_ip_list@release/Country.mmdb -O /etc/clash/Country.mmdb
fi
sleep 2
touch /var/run/geoip_down_complete >/dev/null 2>&1
sleep 2
rm -rf /var/run/geoip_update >/dev/null 2>&1
echo "" > /tmp/geoip_update.txt >/dev/null 2>&1
if pidof clash >/dev/null; then
/etc/init.d/clash restart 2>/dev/null
fi

View File

@ -1,45 +0,0 @@
#!/bin/sh /etc/rc.common
. /lib/functions.sh
cfg_groups_set()
{
CFG_FILE="/etc/config/clash"
local section="$1"
config_get "name" "$section" "name" ""
config_get "old_name_cfg" "$section" "old_name_cfg" ""
config_get "old_name" "$section" "old_name" ""
if [ -z "$name" ]; then
return
fi
if [ -z "$old_name_cfg" ]; then
uci set clash."$section".old_name_cfg="$name"
uci commit clash
fi
if [ -z "$old_name" ]; then
uci set clash."$section".old_name="$name"
uci commit clash
fi
if [ "$name" != "$old_name_cfg" ] && [ ! -z "$old_name_cfg" ]; then
sed -i "s/old_name_cfg \'${old_name_cfg}\'/old_name_cfg \'${name}\'/g" $CFG_FILE 2>/dev/null
sed -i "s/groups \'${old_name_cfg}/groups \'${name}/g" $CFG_FILE 2>/dev/null
sed -i "s/other_group \'${old_name_cfg}/other_group \'${name}/g" $CFG_FILE 2>/dev/null
sed -i "s/new_servers_group \'${old_name_cfg}/new_servers_group \'${name}/g" $CFG_FILE 2>/dev/null
sed -i "s/relay_groups \'${old_name_cfg}/relay_groups \'${name}/g" $CFG_FILE 2>/dev/null
config_load "clash"
fi
}
start(){
status=$(ps|grep -c /usr/share/clash/groups.sh)
[ "$status" -gt "3" ] && exit 0
config_load "clash"
config_foreach cfg_groups_set "groups"
}

View File

@ -1,93 +0,0 @@
#!/bin/bash /etc/rc.common
. /lib/functions.sh
CUSTOM_RULE_FILE="/tmp/ipadd.conf"
RULE="/tmp/rules_conf.yaml"
CLASH="/tmp/conf.yaml"
CONFIG_YAML="/etc/clash/config.yaml"
CLASH_CONFIG="/tmp/config.yaml"
append=$(uci get clash.config.append_rules 2>/dev/null)
if [ "${append}" -eq 1 ];then
if [ -f $CLASH_CONFIG ];then
rm -rf $CLASH_CONFIG 2>/dev/null
fi
cp $CONFIG_YAML $CLASH_CONFIG 2>/dev/null
if [ ! -z "$(grep "^Rule:" "$CLASH_CONFIG")" ]; then
sed -i "/^Rule:/i\#RULESTART#" $CLASH_CONFIG 2>/dev/null
elif [ ! -z "$(grep "^rules:" "$CLASH_CONFIG")" ]; then
sed -i "/^rules:/i\#RULESTART#" $CLASH_CONFIG 2>/dev/null
fi
sed -i -e "\$a#RULEEND#" $CLASH_CONFIG 2>/dev/null
awk '/#RULESTART#/,/#RULEEND#/{print}' "$CLASH_CONFIG" 2>/dev/null |sed "s/\'//g" 2>/dev/null |sed 's/\"//g' 2>/dev/null |sed 's/\t/ /g' 2>/dev/null |grep '^ \{0,\}- '|awk -F '- ' '{print "- "$2}' | sed 's/^ \{0,\}//' 2>/dev/null |sed 's/ \{0,\}$//' 2>/dev/null >$RULE 2>&1
sed -i '/#RULESTART#/,/#RULEEND#/d' "$CLASH_CONFIG" 2>/dev/null
sed -i -e "\$a " $CLASH_CONFIG 2>/dev/null
sed -i "1i\rules:" $RULE 2>/dev/null
cat $CLASH_CONFIG $RULE >$CLASH 2>/dev/null
mv $CLASH $CLASH_CONFIG 2>/dev/null
rm -rf $RULE 2>/dev/null
if [ -f $CUSTOM_RULE_FILE ];then
rm -rf $CUSTOM_RULE_FILE 2>/dev/null
fi
ipadd()
{
local section="$1"
config_get "pgroup" "$section" "pgroup" ""
config_get "ipaaddr" "$section" "ipaaddr" ""
config_get "type" "$section" "type" ""
config_get "res" "$section" "res" ""
if [ -z "$type" ]; then
return
fi
if [ -z "$pgroup" ]; then
return
fi
if [ "${res}" -eq 1 ];then
echo "- $type,$ipaaddr,$pgroup,no-resolve">>/tmp/ipadd.conf
else
echo "- $type,$ipaaddr,$pgroup">>/tmp/ipadd.conf
fi
}
config_load clash
config_foreach ipadd "addtype"
if [ -f $CUSTOM_RULE_FILE ];then
sed -i -e "\$a#CUSTOMRULEEND#" $CUSTOM_RULE_FILE 2>/dev/null
sed -i '/#CUSTOMRULESTART#/,/#CUSTOMRULEEND#/d' "$CLASH_CONFIG" 2>/dev/null
if [ ! -z "$(grep "^ \{0,\}rules:" "$CLASH_CONFIG")" ]; then
sed -i '/rules:/a\#CUSTOMRULESTART#' "$CLASH_CONFIG" 2>/dev/null
else
echo "#CUSTOMRULESTART#" >> "$CLASH_CONFIG" 2>/dev/null
fi
sed -i '/CUSTOMRULESTART/r/tmp/ipadd.conf' "$CLASH_CONFIG" 2>/dev/null
mv $CLASH_CONFIG $CONFIG_YAML 2>/dev/null
fi
else
sed -i '/#CUSTOMRULESTART#/,/#CUSTOMRULEEND#/d' "$CONFIG_YAML" 2>/dev/null
fi

View File

@ -1,19 +0,0 @@
#!/bin/sh
enable=$(uci get clash.config.enable 2>/dev/null)
if [ "${enable}" -eq "0" ];then
if [ -f /tmp/watchlist ];then
rm -rf /tmp/watchlist
fi
line=$(ps | grep -n 'clash-watchdog.sh'|awk -F ':' '{print $2}' |awk -F ' ' '{print $1}'>/tmp/watchlist)
line_no=$(grep -n '' /tmp/watchlist|awk -F ':' '{print $1}')
num=$(grep -c '' /tmp/watchlist| awk '{print $1}')
nums=1
while [[ $nums -le $num ]]
do
kill -9 $(sed -n "$nums"p /tmp/watchlist| awk '{print $1}') >/dev/null 2>&1
nums=$(( $nums + 1))
done
fi

View File

@ -1,156 +0,0 @@
#!/bin/bash /etc/rc.common
. /lib/functions.sh
lang=$(uci get luci.main.lang 2>/dev/null)
load="/tmp/config.yaml"
CONFIG_YAML_PATH=$(uci get clash.config.use_config 2>/dev/null)
if [ -f $CONFIG_YAML_PATH ] && [ "$(ls -l $CONFIG_YAML_PATH|awk '{print int($5)}')" -ne 0 ];then
cp $CONFIG_YAML_PATH $load 2>/dev/null
fi
if [ ! -f $load ] || [ "$(ls -l $load|awk '{print int($5)}')" -eq 0 ]; then
exit 0
fi
CFG_FILE="/etc/config/clash"
REAL_LOG="/usr/share/clash/clash_real.txt"
rm -rf /tmp/Proxy_Group /tmp/group_*.yaml /tmp/yaml_group.yaml 2>/dev/null
if [ $lang == "zh_cn" ];then
echo "开始更新策略组配置..." >$REAL_LOG
elif [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Start updating policy group config" >$REAL_LOG
fi
sed -i 's/^Proxy Group:/proxy-groups:/g' "$load"
sed -i 's/^proxy-provider:/proxy-providers:/g' "$load"
sed -i 's/^Proxy:/proxies:/g' "$load"
sed -i 's/^Rule:/rules:/g' "$load"
sed -i 's/^rule-provider:/rule-providers:/g' "$load"
group_len=$(sed -n '/^ \{0,\}proxy-groups:/=' "$load" 2>/dev/null)
provider_len=$(sed -n '/^ \{0,\}proxy-providers:/=' "$load" 2>/dev/null)
if [ "$provider_len" -ge "$group_len" ]; then
awk '/proxies:/,/proxy-providers:/{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-providers://g" /tmp/Proxy_Group 2>&1
else
awk '/proxies:/,/rules:/{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
if [ "$?" -eq "0" ]; then
echo 'DIRECT' >>/tmp/Proxy_Group
echo 'REJECT' >>/tmp/Proxy_Group
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
group_len=$(sed -n '/^ \{0,\}proxy-groups:/=' "$load" 2>/dev/null)
provider_len=$(sed -n '/^ \{0,\}proxy-providers:/=' "$load" 2>/dev/null)
ruleprovider_len=$(sed -n '/^ \{0,\}rule-providers:/=' "$load" 2>/dev/null)
if [ "$provider_len" -ge "$group_len" ]; then
awk '/proxy-groups:/,/proxy-providers:/{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-providers://g" /tmp/yaml_group.yaml 2>&1
elif [ "$ruleprovider_len" -ge "$group_len" ]; then
awk '/proxy-groups:/,/rule-providers:/{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/rule-providers://g" /tmp/yaml_group.yaml 2>&1
else
awk '/proxy-groups:/,/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
#######READ GROUPS START
if [ -f /tmp/yaml_group.yaml ];then
while [[ "$( grep -c "config conf_groups" $CFG_FILE )" -ne 0 ]]
do
uci delete clash.@conf_groups[0] && uci commit clash >/dev/null 2>&1
done
count=1
file_count=1
match_group_file="/tmp/Proxy_Group"
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"
[ "$count" -eq 1 ] && {
startLine="$n"
}
count=$(expr "$count" + 1)
if [ "$count" -gt "$num" ]; then
endLine=$(sed -n '$=' $group_file)
else
endLine=$(expr $(echo "$line" | sed -n "${count}p") - 1)
fi
sed -n "${startLine},${endLine}p" $group_file >$single_group
startLine=$(expr "$endLine" + 1)
#type
group_type="$(cfg_get "type:" "$single_group")"
#name
group_name="$(cfg_get "name:" "$single_group")"
#test_url
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Now Reading 【$group_type】-【$group_name】 Policy Group..." >$REAL_LOG
elif [ $lang == "zh_cn" ];then
echo "正在读取【$group_type】-【$group_name】策略组配置..." >$REAL_LOG
fi
name=clash
uci_name_tmp=$(uci add $name conf_groups)
uci_set="uci -q set $name.$uci_name_tmp."
uci_add="uci -q add_list $name.$uci_name_tmp."
${uci_set}name="$group_name"
${uci_set}type="$group_type"
file_count=$(( $file_count + 1))
done
uci commit clash
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "Reading Policy Group 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
rm -rf /tmp/Proxy_Group /tmp/group_*.yaml /tmp/yaml_group.yaml $load 2>/dev/null
fi
#######READ GROUPS END

View File

@ -1 +0,0 @@
v1.8.0

View File

@ -1,31 +0,0 @@
#!/bin/sh /etc/rc.common
if [ -f /etc/clash/clashbackup/history ];then
HISTORY_PATH="/etc/clash/clashbackup/history"
SECRET=$(uci get clash.config.dash_pass 2>/dev/null)
LAN_IP=$(uci get network.lan.ipaddr 2>/dev/null |awk -F '/' '{print $1}' 2>/dev/null)
PORT=$(uci get clash.config.dash_port 2>/dev/null)
urlencode() {
local data
if [ "$#" != 1 ]; then
return 1
fi
data=$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "$1" "")
if [ ! -z "$data" ]; then
echo "${data##/?}"
fi
return 0
}
cat $HISTORY_PATH |while read line
do
if [ -z "$(echo $line |grep "#*#")" ]; then
continue
else
GORUP_NAME=$(urlencode "$(echo $line |awk -F '#*#' '{print $1}')")
NOW_NAME=$(echo $line |awk -F '#*#' '{print $3}')
curl -H "Authorization: Bearer ${SECRET}" -H "Content-Type:application/json" -X PUT -d '{"name":"'"$NOW_NAME"'"}' http://"$LAN_IP":"$PORT"/proxies/"$GORUP_NAME" >/dev/null 2>&1
fi
done >/dev/null 2>&1
curl -m 5 --retry 2 -H "Authorization: Bearer ${SECRET}" -H "Content-Type:application/json" -X DELETE http://"$LAN_IP":"$PORT"/connections >/dev/null 2>&1
fi

View File

@ -1,13 +0,0 @@
#!/bin/bash /etc/rc.common
. /lib/functions.sh
name=$(uci get clash.config.config_name_remove 2>/dev/null)
check_match_name=$(grep -F "$name" "/etc/clash/clashbackup/confit_list.conf")
line_no=$(grep -n "$check_match_name" /etc/clash/clashbackup/confit_list.conf |awk -F ':' '{print $1}')
if [ ! -z $check_match_name ];then
sed -i "${line_no}d" /etc/clash/clashbackup/confit_list.conf
rm -rf /etc/clash/config/sub/${name}
sed -i '/^$/d' /etc/clash/clashbackup/confit_list.conf
rm -rf /etc/clash/config/sub/${name}
fi

Some files were not shown because too many files have changed in this diff Show More