init version

This commit is contained in:
lmq8267
2024-06-11 21:56:49 +08:00
committed by sijie.sun
commit e18ee8e5b5
11 changed files with 850 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
#
# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org>
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
PKG_VERSION:=1.0.0
PKG_RELEASE:=
LUCI_TITLE:=LuCI support for EasyTier
LUCI_DEPENDS:=
LUCI_PKGARCH:=all
PKG_NAME:=luci-app-easytier
define Package/$(PKG_NAME)/prerm
#!/bin/sh
if [ -f /etc/config/easytier ] ; then
echo "备份easytier配置文件/etc/config/easytier到/tmp/easytier_backup"
echo "不重启设备之前再次安装luci-app-easytier 配置不丢失,不用重新配置"
mv -f /etc/config/easytier /tmp/easytier_backup
fi
endef
define Package/$(PKG_NAME)/postinst
#!/bin/sh
chmod +x /etc/init.d/easytier
if [ -f /tmp/easytier_backup ] ; then
echo "发现easytier备份配置文件/tmp/easytier_backup,开始恢复到/etc/config/easytier"
mv -f /tmp/easytier_backup /etc/config/easytier
echo "请前往 VPN - EasyTier 界面进行重启插件"
fi
endef
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature
+69
View File
@@ -0,0 +1,69 @@
module("luci.controller.easytier", package.seeall)
function index()
if not nixio.fs.access("/etc/config/easytier") then
return
end
entry({"admin", "vpn", "easytier"}, alias("admin", "vpn", "easytier", "easytier"),_("EasyTier"), 46).dependent = true
entry({"admin", "vpn", "easytier", "easytier"}, cbi("easytier"),_("EasyTier"), 47).leaf = true
entry({"admin", "vpn", "easytier", "easytier_log"}, form("easytier_log"),_("日志"), 48).leaf = true
entry({"admin", "vpn", "easytier", "get_log"}, call("get_log")).leaf = true
entry({"admin", "vpn", "easytier", "clear_log"}, call("clear_log")).leaf = true
entry({"admin", "vpn", "easytier", "status"}, call("act_status")).leaf = true
end
function act_status()
local e = {}
local sys = require "luci.sys"
e.crunning = luci.sys.call("pgrep easytier-core >/dev/null") == 0
local tagfile = io.open("/tmp/easytier_time", "r")
if tagfile then
local tagcontent = tagfile:read("*all")
tagfile:close()
if tagcontent and tagcontent ~= "" then
os.execute("start_time=$(cat /tmp/easytier_time) && time=$(($(date +%s)-start_time)) && day=$((time/86400)) && [ $day -eq 0 ] && day='' || day=${day}天 && time=$(date -u -d @${time} +'%H小时%M分%S秒') && echo $day $time > /tmp/command_easytier 2>&1")
local command_output_file = io.open("/tmp/command_easytier", "r")
if command_output_file then
e.etsta = command_output_file:read("*all")
command_output_file:close()
end
end
end
local command2 = io.popen('test ! -z "`pidof easytier-core`" && (top -b -n1 | grep -E "$(pidof easytier-core)" 2>/dev/null | grep -v grep | awk \'{for (i=1;i<=NF;i++) {if ($i ~ /easytier-core/) break; else cpu=i}} END {print $cpu}\')')
e.etcpu = command2:read("*all")
command2:close()
local command3 = io.popen("test ! -z `pidof easytier-core` && (cat /proc/$(pidof easytier-core | awk '{print $NF}')/status | grep -w VmRSS | awk '{printf \"%.2f MB\", $2/1024}')")
e.etram = command3:read("*all")
command3:close()
local command8 = io.popen("([ -s /tmp/easytiernew.tag ] && cat /tmp/easytiernew.tag ) || ( curl -L -k -s --connect-timeout 3 --user-agent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36' https://api.github.com/repos/EasyTier/EasyTier/releases/latest | grep tag_name | sed 's/[^0-9.]*//g' >/tmp/easytiernew.tag && cat /tmp/easytiernew.tag )")
e.etnewtag = command8:read("*all")
command8:close()
local command9 = io.popen("([ -s /tmp/easytier.tag ] && cat /tmp/easytier.tag ) || ( echo `$(uci -q get easytier.@easytier[0].easytierbin) -V | sed 's/[^0-9.]*//g'` > /tmp/easytier.tag && cat /tmp/easytier.tag && [ ! -s /tmp/easytier.tag ] && echo '' >> /tmp/easytier.tag && cat /tmp/easytier.tag )")
e.ettag = command9:read("*all")
command9:close()
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function get_log()
local log = ""
local files = {"/tmp/easytier.log"}
for i, file in ipairs(files) do
if luci.sys.call("[ -f '" .. file .. "' ]") == 0 then
log = log .. luci.sys.exec("cat " .. file)
end
end
luci.http.write(log)
end
function clear_log()
luci.sys.call("echo '' >/tmp/easytier.log")
end
+346
View File
@@ -0,0 +1,346 @@
local fs = require "luci.fs"
local http = luci.http
local nixio = require "nixio"
m = Map("easytier")
m.description = translate('一个简单、安全、去中心化的内网穿透 VPN 组网方案,使用 Rust 语言和 Tokio 框架实现。 项目地址:<a href="https://github.com/EasyTier/EasyTier">github.com/EasyTier/EasyTier</a>&nbsp;&nbsp;<a href="http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=jhP2Z4UsEZ8wvfGPLrs0VwLKn_uz0Q_p&authKey=OGKSQLfg61YPCpVQuvx%2BxE7hUKBVBEVi9PljrDKbHlle6xqOXx8sOwPPTncMambK&noverify=0&group_code=949700262">QQ群</a>')
-- easytier
m:section(SimpleSection).template = "easytier/easytier_status"
s=m:section(TypedSection, "easytier", translate("EasyTier配置"))
s.addremove=false
s.anonymous=true
s:tab("general", translate("基本设置"))
s:tab("infos", translate("连接信息"))
s:tab("upload", translate("上传程序"))
switch = s:taboption("general",Flag, "enabled", translate("Enable"))
switch.rmempty = false
btncq = s:taboption("general", Button, "btncq", translate("重启"))
btncq.inputtitle = translate("重启")
btncq.description = translate("在没有修改参数的情况下快速重新启动一次")
btncq.inputstyle = "apply"
btncq:depends("enabled", "1")
btncq.write = function()
os.execute("/etc/init.d/easytier restart &")
end
network_name = s:taboption("general", Value, "network_name", translate("网络名称"),
translate("用于识别此 VPN 网络的网络名称(这是 --network-name 参数)"))
network_name.password = true
network_name.placeholder = "test"
network_secret = s:taboption("general", Value, "network_secret", translate("网络密钥"),
translate("用于验证此节点是否属于 VPN 网络的网络密钥(这是 --network-secret 参数)"))
network_secret.password = true
network_secret.placeholder = "test"
mode = s:taboption("general",ListValue, "mode", translate("接口模式"),
translate("不指定ip地址将不会建立tun网卡,单纯作为服务器运行"))
mode:value("不指定")
mode:value("自动分配")
mode:value("静态指定")
ipaddr = s:taboption("general",Value, "ipaddr", translate("接口IP地址"),
translate("此 VPN 节点的 IPv4 地址,如果为空,此节点将仅转发数据包,不会创建 TUN 设备 (这是 -i 参数)"))
ipaddr.optional = false
ipaddr.datatype = "ip4addr"
ipaddr.placeholder = "10.0.0.1"
ipaddr:depends("mode", "静态指定")
peeradd = s:taboption("general",DynamicList, "peeradd", translate("对等节点"),
translate("初始连接的对等节点 (这是 -p 参数)"))
peeradd.placeholder = "udp://22.1.1.1:11010"
external_node = s:taboption("general", Value, "external_node", translate("共享节点地址"),
translate("使用公共共享节点来发现对等节点 (这是 -e 参数)"))
external_node.placeholder = "tcp://easytier.public.kkrainbow.top:11010"
external_node.password = true
proxy_network = s:taboption("general",DynamicList, "proxy_network", translate("代理网络"),
translate("将本地网络导出到 VPN 中的其他对等点 (这是 -n 参数)"))
rpc_portal = s:taboption("general", Value, "rpc_portal", translate("门户地址端口"),
translate("用于管理的 RPC 门户地址。0 表示随机端口,12345 表示监听本地主机的 12345 端口,0.0.0.0:12345 表示在所有接口上监听 12345 端口。默认值为 0,首选 15888 (这是 -r 参数)"))
rpc_portal.placeholder = "0"
rpc_portal.datatype = "range(1,65535)"
listenermode = s:taboption("general",ListValue, "listenermode", translate("监听模式"))
listenermode:value("OFF")
listenermode:value("ON")
listeners = s:taboption("general",Value, "listeners", translate("监听端口"),
translate("接受连接的监听器,只需要填端口号:11010,表示 tcp/udp 将在 11010 上监听,ws/wg 将在 11011 上监听,wss 将在 11012 上监听"))
listeners.datatype = "range(1,65535)"
listeners.placeholder = "11010"
listeners:depends("listenermode", "ON")
local model = fs.readfile("/proc/device-tree/model") or ""
local hostname = fs.readfile("/proc/sys/kernel/hostname") or ""
model = model:gsub("\n", "")
hostname = hostname:gsub("\n", "")
local device_name = (model ~= "" and model) or (hostname ~= "" and hostname) or "OpenWrt"
device_name = device_name:gsub(" ", "_")
desvice_name = s:taboption("general", Value, "desvice_name", translate("主机名"),
translate("用于标识此设备的主机名 (这是 --hostname 参数)"))
desvice_name.placeholder = device_name
desvice_name.default = device_name
instance_name = s:taboption("general",Value, "instance_name", translate("实例名称"),
translate("用于在同一台机器中标识此 VPN 节点的实例名称 (这是 --instance-name 参数)"))
instance_name.placeholder = "default"
vpn_portal = s:taboption("general",Value, "vpn_portal", translate("VPN门户URL"),
translate("定义 VPN 门户的 URL,允许其他 VPN 客户端连接。<br> 示例:wg://0.0.0.0:11010/10.14.14.0/24,表示 VPN 门户是一个在 vpn.example.com:11010 上监听的 WireGuard 服务器,并且 VPN 客户端位于 10.14.14.0/24 网络中(这是 --vpn-portal 参数)"))
vpn_portal.placeholder = "wg://0.0.0.0:11010/10.14.14.0/24"
mtu = s:taboption("general",Value, "mtu", translate("MTU"),
translate("TUN 设备的 MTU,默认值为非加密时的 1420,加密时为 1400"))
mtu.datatype = "range(1,1500)"
mtu.placeholder = "1400"
default_protocol = s:taboption("general",Value, "default_protocol", translate("默认协议"),
translate("连接对等节点时使用的默认协议(这是 --default-protocol 参数)"))
disable_encryption = s:taboption("general",Flag, "disable_encryption", translate("禁用加密"),
translate("禁用对等节点通信的加密,若关闭加密则其他节点也必须关闭加密 (这是 -u 参数)"))
multi_thread = s:taboption("general",Flag, "multi_thread", translate("启用多线程"),
translate("使用多线程运行时,默认为单线程 (这是 --multi-thread 参数)"))
disable_ipv6 = s:taboption("general",Flag, "disable_ipv6", translate("禁用ipv6"),
translate("禁用ipv6 (这是 --disable-ipv6 参数)"))
latency_first = s:taboption("general",Flag, "latency_first", translate("启用延迟优先"),
translate("优先考虑延迟? (这是 --latency-first 参数)"))
exit_node = s:taboption("general",Flag, "exit_node", translate("启用出口节点"),
translate("允许此节点成为出口节点 (这是 --enable-exit-node 参数)"))
exit_nodes = s:taboption("general",Value, "exit_nodes", translate("出口节点地址"),
translate("转发所有流量的出口节点,虚拟 IPv4 地址,优先级由列表顺序确定(这是 --exit-nodes 参数)"))
exit_nodes:depends("exit_node", "1")
log = s:taboption("general",Flag, "log", translate("启用日志"),
translate("运行日志在/tmp/easytier.log,可在上方日志查看"))
log.rmempty = false
check = s:taboption("general",Flag, "check", translate("通断检测"),
translate("开启通断检测后,可以指定对端的设备IP,当所有指定的IP都ping不通时将会重启vnt程序"))
checkip=s:taboption("general",DynamicList,"checkip",translate("检测IP"),
translate("确保这里的对端设备IP地址填写正确且可访问,若填写错误将会导致无法ping通,程序反复重启"))
checkip.rmempty = true
checkip.datatype = "ip4addr"
checkip:depends("check", "1")
checktime = s:taboption("general",ListValue, "checktime", translate("间隔时间 (分钟)"),
translate("检测间隔的时间,每隔多久检测指定的IP通断一次"))
for s=1,60 do
checktime:value(s)
end
checktime:depends("check", "1")
local process_status = luci.sys.exec("ps | grep easytier-core| grep -v grep")
btn1 = s:taboption("infos", Button, "btn1")
btn1.inputtitle = translate("peer信息")
btn1.description = translate("点击按钮刷新,查看peer信息")
btn1.inputstyle = "apply"
btn1.write = function()
if process_status ~= "" then
luci.sys.call("$(dirname $(uci -q get easytier.@easytier[0].easytierbin))/easytier-cli peer >/tmp/easytier-cli_peer")
else
luci.sys.call("echo '错误:程序未运行!请启动程序后重新点击刷新' >/tmp/easytier-cli_peer")
end
end
btn1info = s:taboption("infos", DummyValue, "btn1info")
btn1info.rawhtml = true
btn1info.cfgvalue = function(self, section)
local content = nixio.fs.readfile("/tmp/easytier-cli_peer") or ""
return string.format("<pre>%s</pre>", luci.util.pcdata(content))
end
btn2 = s:taboption("infos", Button, "btn2")
btn2.inputtitle = translate("connector信息")
btn2.description = translate("点击按钮刷新,查看connector信息")
btn2.inputstyle = "apply"
btn2.write = function()
if process_status ~= "" then
luci.sys.call("$(dirname $(uci -q get easytier.@easytier[0].easytierbin))/easytier-cli connector >/tmp/easytier-cli_connector")
else
luci.sys.call("echo '错误:程序未运行!请启动程序后重新点击刷新' >/tmp/easytier-cli_connector")
end
end
btn2info = s:taboption("infos", DummyValue, "btn2info")
btn2info.rawhtml = true
btn2info.cfgvalue = function(self, section)
local content = nixio.fs.readfile("/tmp/easytier-cli_connector") or ""
return string.format("<pre>%s</pre>", luci.util.pcdata(content))
end
btn3 = s:taboption("infos", Button, "btn3")
btn3.inputtitle = translate("stun信息")
btn3.description = translate("点击按钮刷新,查看stun信息")
btn3.inputstyle = "apply"
btn3.write = function()
if process_status ~= "" then
luci.sys.call("$(dirname $(uci -q get easytier.@easytier[0].easytierbin))/easytier-cli stun >/tmp/easytier-cli_stun")
else
luci.sys.call("echo '错误:程序未运行!请启动程序后重新点击刷新' >/tmp/easytier-cli_stun")
end
end
btn3info = s:taboption("infos", DummyValue, "btn3info")
btn3info.rawhtml = true
btn3info.cfgvalue = function(self, section)
local content = nixio.fs.readfile("/tmp/easytier-cli_stun") or ""
return string.format("<pre>%s</pre>", luci.util.pcdata(content))
end
btn4 = s:taboption("infos", Button, "btn4")
btn4.inputtitle = translate("route信息")
btn4.description = translate("点击按钮刷新,查看route信息")
btn4.inputstyle = "apply"
btn4.write = function()
if process_status ~= "" then
luci.sys.call("$(dirname $(uci -q get easytier.@easytier[0].easytierbin))/easytier-cli route >/tmp/easytier-cli_route")
else
luci.sys.call("echo '错误:程序未运行!请启动程序后重新点击刷新' >/tmp/easytier-cli_route")
end
end
btn4info = s:taboption("infos", DummyValue, "btn4info")
btn4info.rawhtml = true
btn4info.cfgvalue = function(self, section)
local content = nixio.fs.readfile("/tmp/easytier-cli_route") or ""
return string.format("<pre>%s</pre>", luci.util.pcdata(content))
end
btn6 = s:taboption("infos", Button, "btn6")
btn6.inputtitle = translate("peer-center信息")
btn6.description = translate("点击按钮刷新,查看peer-center信息")
btn6.inputstyle = "apply"
btn6.write = function()
if process_status ~= "" then
luci.sys.call("$(dirname $(uci -q get easytier.@easytier[0].easytierbin))/easytier-cli peer-center >/tmp/easytier-cli_peer-center")
else
luci.sys.call("echo '错误:程序未运行!请启动程序后重新点击刷新' >/tmp/easytier-cli_peer-center")
end
end
btn6info = s:taboption("infos", DummyValue, "btn6info")
btn6info.rawhtml = true
btn6info.cfgvalue = function(self, section)
local content = nixio.fs.readfile("/tmp/easytier-cli_peer-center") or ""
return string.format("<pre>%s</pre>", luci.util.pcdata(content))
end
btn7 = s:taboption("infos", Button, "btn7")
btn7.inputtitle = translate("vpn-portal信息")
btn7.description = translate("点击按钮刷新,查看vpn-portal信息")
btn7.inputstyle = "apply"
btn7.write = function()
if process_status ~= "" then
luci.sys.call("$(dirname $(uci -q get easytier.@easytier[0].easytierbin))/easytier-cli vpn-portal >/tmp/easytier-cli_vpn-portal")
else
luci.sys.call("echo '错误:程序未运行!请启动程序后重新点击刷新' >/tmp/easytier-cli_vpn-portal")
end
end
btn7info = s:taboption("infos", DummyValue, "btn7info")
btn7info.rawhtml = true
btn7info.cfgvalue = function(self, section)
local content = nixio.fs.readfile("/tmp/easytier-cli_vpn-portal") or ""
return string.format("<pre>%s</pre>", luci.util.pcdata(content))
end
btn5 = s:taboption("infos", Button, "btn5")
btn5.inputtitle = translate("本机启动参数")
btn5.description = translate("点击按钮刷新,查看本机完整启动参数")
btn5.inputstyle = "apply"
btn5.write = function()
if process_status ~= "" then
luci.sys.call("echo $(cat /proc/$(pidof easytier-core)/cmdline | awk '{print $1}') >/tmp/easytier_cmd")
else
luci.sys.call("echo '错误:程序未运行!请启动程序后重新点击刷新' >/tmp/easytier_cmd")
end
end
btn5cmd = s:taboption("infos", DummyValue, "btn5cmd")
btn5cmd.rawhtml = true
btn5cmd.cfgvalue = function(self, section)
local content = nixio.fs.readfile("/tmp/easytier_cmd") or ""
return string.format("<pre>%s</pre>", luci.util.pcdata(content))
end
btnrm = s:taboption("infos", Button, "btnrm")
btnrm.inputtitle = translate("检测更新")
btnrm.description = translate("点击按钮开始检测更新,上方状态栏显示")
btnrm.inputstyle = "apply"
btnrm.write = function()
os.execute("rm -rf /tmp/easytier*.tag /tmp/easytier*.newtag /tmp/easytier-core_*")
end
easytierbin = s:taboption("upload", Value, "easytierbin", translate("easytier-core程序路径"),
translate("自定义easytier-core的存放路径,确保填写完整的路径及名称,若指定的路径可用空间不足将会自动移至/tmp/easytier-core"))
easytierbin.placeholder = "/tmp/vnt-cli"
local upload = s:taboption("upload", FileUpload, "upload_file")
upload.optional = true
upload.default = ""
upload.template = "easytier/other_upload"
upload.description = translate("可直接上传二进制程序easytier-core和easytier-cli或者以.zip结尾的压缩包,上传新版本会自动覆盖旧版本,下载地址:<a href='https://github.com/EasyTier/EasyTier/releases' target='_blank'>github.com/EasyTier/EasyTier</a><br>上传的文件将会保存在/tmp文件夹里,如果自定义了程序路径那么启动程序时将会自动移至自定义的路径<br>")
local um = s:taboption("upload",DummyValue, "", nil)
um.template = "easytier/other_dvalue"
local dir, fd, chunk
dir = "/tmp/"
nixio.fs.mkdir(dir)
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("错误:上传失败!")
return
end
end
if chunk and fd then
fd:write(chunk)
end
if eof and fd then
fd:close()
fd = nil
um.value = translate("文件已上传至") .. ' "/tmp/' .. meta.file .. '"'
if string.sub(meta.file, -4) == ".zip" then
local file_path = dir .. meta.file
os.execute("unzip -q " .. file_path .. " -d " .. dir)
if nixio.fs.access("/tmp/easytier-cli") then
um.value = um.value .. "\n" .. translate("-程序/tmp/easytier-cli上传成功,重启一次插件才生效")
end
if nixio.fs.access("/tmp/easytier-core") then
um.value = um.value .. "\n" .. translate("-程序/tmp/easytier-core上传成功,重启一次插件才生效")
end
end
os.execute("chmod a+x /tmp/easytier-core")
os.execute("chmod a+x /tmp/easytier-cli")
end
end
)
if luci.http.formvalue("upload") then
local f = luci.http.formvalue("ulfile")
end
return m
+5
View File
@@ -0,0 +1,5 @@
f = SimpleForm("easytier")
f.reset = false
f.submit = false
f:append(Template("easytier/easytier_log"))
return f
+33
View File
@@ -0,0 +1,33 @@
<%
local dsp = require "luci.dispatcher"
-%>
<script type="text/javascript">
//<![CDATA[
function clearlog(btn) {
XHR.get('<%=dsp.build_url("admin/vpn/easytier/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;
}
}
);
}
XHR.poll(2, '<%=dsp.build_url("admin/vpn/easytier/get_log")%>', null,
function(x, data) {
if(x && x.status == 200 && document.getElementById("checkbox1").checked == true) {
var log_textarea = document.getElementById('log_textarea');
log_textarea.innerHTML = x.responseText;
log_textarea.scrollTop = log_textarea.scrollHeight;
}
}
);
//]]>
</script>
<fieldset class="cbi-section" id="_log_fieldset">
<input type="checkbox" id="checkbox1" style="vertical-align:middle;height: auto;"checked><%:自动刷新%></input>
<input class="cbi-button cbi-input-remove" type="button" onclick="clearlog()" value="<%:清除日志%>" />
<textarea id="log_textarea" class="cbi-input-textarea" style="width: 100%;margin-top: 10px;" data-update="change" rows="30" wrap="off" readonly="readonly"></textarea>
</fieldset>
+23
View File
@@ -0,0 +1,23 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(3, '<%=url([[admin]], [[vpn]], [[easytier]], [[status]])%>', null,
function(x, data) {
var st = document.getElementById('easytier_status');
if (data && st) {
var clientStatus = data.crunning ? "<span style='color:green;'> 运行中</span><img src='https://www.right.com.cn/forum/data/attachment/album/202401/30/081238k459q2d5klacs8rk.gif' width='30px' alt=''>" : "<span style='color:red;'> 未运行</span>";
var etstaContent = data.crunning ? "已运行:" + "<span style='color:#DA70D6;'>" + data.etsta + "</span>" : "";
var etcpuContent = data.crunning ? "<br>" + "CPU占用:" + "<span style='color:#6A5ACD;'>" + data.etcpu + "</span>" : "";
var etramContent = data.crunning ? "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + "&nbsp;&nbsp;&nbsp;&nbsp;内存占用:" + "<span style='color:#0000CD;'>" + data.etram + "</span>" : "";
var ettagContent = data.crunning ? "<br>" + "当前版本:" + "<span style='color:#CD853F;'>" + data.ettag + "</span>" : "";
var etnewtagContent = data.crunning ? "&nbsp;&nbsp;&nbsp;&nbsp;" + "&nbsp;&nbsp;&nbsp;最新版本:" + "<span style='color:#FFA500;'>" + data.etnewtag + "</span>" : "";
st.innerHTML = "<em><b>easytier-core " + clientStatus + etstaContent + etcpuContent + etramContent + ettagContent + etnewtagContent + "</b></em>";
}
}
);
//]]>
</script>
<fieldset class="cbi-section">
<p id="easytier_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>
+8
View File
@@ -0,0 +1,8 @@
<%+cbi/valueheader%>
<span style="color: red">
<%
local val = self:cfgvalue(section) or self.default or ""
write(pcdata(val))
%>
</span>
<%+cbi/valuefooter%>
+5
View File
@@ -0,0 +1,5 @@
<%+cbi/valueheader%>
<label class="cbi-value" style="display:inline-block; width: 130px" for="ulfile"><%:上传程序:%></label>
<input class="cbi-input-file" style="width: 400px" type="file" id="ulfile" name="ulfile" />
<input type="submit" class="cbi-button cbi-input-apply" name="upload" value="<%:Upload%>" />
<%+cbi/valuefooter%>
+4
View File
@@ -0,0 +1,4 @@
config easytier
option enabled '0'
option easytierbin '/usr/bin/easytier-core'
+307
View File
@@ -0,0 +1,307 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2008-2020 OpenWrt.org
START=99
USE_PROCD=1
size="$(df -k | awk '/\/overlay$/ {sub(/K$/, "", $4); print $4}')"
check () {
if [ ! -z "$checkip" ] ; then
echo ' ' >/tmp/easytier_check
cat > /tmp/easytier_check<<'EOF'
#!/bin/sh
time="$(($(uci -q get easytier.@easytier[0].checktime) * 60))"
if [ -z "$time" ] ;then
time=120
uci -q set easytier.@easytier[0].checktime=2
uci commit easytier
fi
while true; do
if [ "$(uci -q get easytier.@easytier[0].enabled)" = "1" ] ; then
ping -c 3 223.5.5.5 -w 5 >/dev/null 2>&1
if [ "$?" == "0" ]; then
if [ ! -z "$(uci -q get easytier.@easytier[0].checkip)" ] ; then
online=""
for ip in $(uci -q get easytier.@easytier[0].checkip); do
ms=`echo $(ping -4 $ip -c 2 -w 4 -q) | awk -F '/' '{print $4}'`
[ ! -z "$ms" ] && echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 通断检测:${ip} 延迟:${ms}ms " >>/tmp/easytier.log && online=1
[ -z "$ms" ] && echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 通断检测:${ip} 网络中断 " >>/tmp/easytier.log
done
[ "$online" != "1" ] && echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 通断检测:$(uci -q get easytier.@easytier[0].checkip) 所有指定IP皆无法ping通,重新启动程序! " >>/tmp/easytier.log && /etc/init.d/easytier restart
fi
else
echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 通断检测:检测到互联网未能成功访问,跳过检测 " >>/tmp/easytier.log
fi
else
echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 通断检测:程序已关闭,退出检测 " >>/tmp/easytier.log
/etc/init.d/easytier restart
break
fi
sleep $((time))
[ "$(du -k /log/easytier.log | cut -f1)" = "1000" ] && echo " " >/tmp/easytier.log
done
EOF
chmod +x /tmp/easytier_check
/tmp/easytier_check &
fi
}
start_et() {
local cfg="$1"
local enabled easytierbin
config_get_bool enabled "$cfg" 'enabled' '0'
[ "$enabled" = "1" ] || return 1
config_get easytierbin "$cfg" 'easytierbin' '/tmp/easytier-core'
echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : easytier-core_${cpucore}开始启动" >>/tmp/easytier.log
#test -z "`opkg list-installed|grep kmod-tun`" && echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 缺少kmod-tun插件" >>/tmp/easytier.log
path=$(dirname "$easytierbin")
if [ -f /tmp/easytier-core ] || [ -f /tmp/easytier-cli ] && [ "${path:0:4}" != "/tmp" ] ;then
chmod +x /tmp/easytier-core 2>/dev/null
chmod +x /tmp/easytier-cli 2>/dev/null
echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 找到上传的程序/tmp/easytier-core,替换为$easytierbin " >>/tmp/easytier.log
upsize="$(du -k /tmp/easytier-core | cut -f1)"
result=$(expr $size - $upsize)
if [ $(($(/tmp/easytier-core -h | wc -l))) -gt 3 ] && [ "$result" -gt 2000 ] ; then
mv -f /tmp/easytier-core "$easytierbin" 2>/dev/null
mv -f /tmp/easytier-cli "${path}/easytier-cli" 2>/dev/null
else
echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 无法替换,上传的程序不完整或自定义路径的可用空间不足,当前空间剩余${size}kb" >>/tmp/easytier.log
fi
fi
if [ ! -f "$easytierbin" ] && [ "$size" -lt 4000 ] ; then
echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 自定义程序路径的可用空间不足,当前可用空间剩余${size}kb,自动切换为内存/tmp/easytier-core" >>/tmp/easytier.log
sed -i "/easytierbin/c option easytierbin '/tmp/easytier-core' " /etc/config/easytier
easytierbin=/tmp/easytier-core
fi
if [ $(($($easytierbin -h | wc -l))) -lt 3 ] || [ ! -f "$easytierbin" ] ; then
newtag="$( curl --connect-timeout 3 --user-agent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36' https://api.github.com/repos/EasyTier/EasyTier/releases/latest 2>&1 | grep 'tag_name' | cut -d\" -f4 )"
[ -z "$newtag"] && newtag=v1.1.0
echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 未找到程序 $easytierbin 开始在线下载${newtag},下载较慢耐心等候" >>/tmp/easytier.log
mkdir -p "$path"
curl -L -k -s -o /tmp/easytier.zip --connect-timeout 10 --retry 3 "http://gh.ddlc.top/https://github.com/EasyTier/EasyTier/releases/download/${newtag}/easytier-${core_url}-${newtag}.zip" || curl -L -k -s -o /tmp/easytier.zip --connect-timeout 10 --retry 3 "https://hub.gitmirror.com/https://github.com/EasyTier/EasyTier/releases/download/${newtag}/easytier-${core_url}-${newtag}.zip" || curl -L -k -s -o /tmp/easytier.zip --connect-timeout 10 --retry 3 "https://github.com/EasyTier/EasyTier/releases/download/${newtag}/easytier-${core_url}-${newtag}.zip"
unzip -q -o /tmp/easytier.zip -d $path
chmod +x "$easytierbin"
if [ $(($($easytierbin -h | wc -l))) -gt 3 ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : ${easytierbin} 下载成功" >>/tmp/easytier.log
else
uci -q set easytier.@easytier[0].enabled=0
uci commit easytier
echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : $easytierbin 下载失败,请手动下载上传程序,程序退出" >>/tmp/easytier.log
return 1
fi
fi
chmod +x "$easytierbin"
ver="$($easytierbin -h | grep version | awk -F ':' {'print $2'})"
[ ! -z "$ver" ] && echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : ${easytierbin}当前版本号-${ver} " >>/tmp/easytier.log
killall easytier_check >/dev/null 2>&1
killall easytier-core >/dev/null 2>&1
killall -9 easytier-core >/dev/null 2>&1
local network_name network_secret mode ipaddr peeradd external_node rpc_portal listenermode
local listeners desvice_name instance_name vpn_portal mtu default_protocol disable_encryption
local multi_thread disable_ipv6 latency_first exit_node exit_nodes log check checkip proxy_network
config_get network_name "$cfg" 'network_name'
config_get network_secret "$cfg" 'network_secret'
config_get mode "$cfg" 'mode'
config_get ipaddr "$cfg" 'ipaddr'
config_get external_node "$cfg" 'external_node'
config_get proxy_network "$cfg" 'proxy_network'
config_get rpc_portal "$cfg" 'rpc_portal'
config_get listenermode "$cfg" 'listenermode'
config_get listeners "$cfg" 'listeners'
config_get desvice_name "$cfg" 'desvice_name'
config_get instance_name "$cfg" 'instance_name'
config_get vpn_portal "$cfg" 'vpn_portal'
config_get mtu "$cfg" 'mtu' '1400'
config_get default_protocol "$cfg" 'default_protocol'
config_get_bool disable_encryption "$cfg" 'disable_encryption' '0'
config_get_bool multi_thread "$cfg" 'multi_thread' '0'
config_get_bool disable_ipv6 "$cfg" 'disable_ipv6' '0'
config_get_bool latency_first "$cfg" 'latency_first' '0'
config_get_bool exit_node "$cfg" 'exit_node' '0'
config_get exit_nodes "$cfg" 'exit_nodes'
config_get_bool log "$cfg" 'log' '0'
config_get_bool check "$cfg" 'check' '0'
config_get checkip "$cfg" 'checkip'
procd_open_instance "easytier"
procd_set_param command "$easytierbin"
[ -z "$network_name" ] || procd_append_param command --network-name "$network_name"
[ -z "$network_secret" ] || procd_append_param command --network-secret "$network_secret"
[ "$mode" = "静态指定" ] && [ ! -z "$ipaddr" ] && procd_append_param command -i "$ipaddr"
[ "$mode" = "自动分配" ] && procd_append_param command -d
if [ ! -z "$peeradd" ] ; then
if [[ "$(grep "list peeradd" /etc/config/easytier | awk '{print $3}' | wc -l ) " -eq 1 ]]; then
procd_append_param command -p "$peeradd"
else
for peeraddr in $(cat /etc/config/easytier | grep 'list peeradd' | awk -F 'list peeradd' '{print $2}' | sed "s/'/\n/g" | tr -d " ' "); do
procd_append_param command -p "$peeraddr"
done
fi
fi
if [ ! -z "$proxy_network" ] ; then
if [[ "$(grep "list proxy_network" /etc/config/easytier | awk '{print $3}' | wc -l ) " -eq 1 ]]; then
procd_append_param command -n "$proxy_network"
else
for proxy_networks in $(cat /etc/config/easytier | grep 'list proxy_network' | awk -F 'list proxy_network' '{print $2}' | sed "s/'/\n/g" | tr -d " ' "); do
procd_append_param command -n "$proxy_networks"
done
fi
fi
[ -z "$external_node" ] || procd_append_param command -e "$external_node"
[ -z "$rpc_portal" ] || procd_append_param command -r "$rpc_portal"
[ "$listenermode" = "ON" ] && [ ! -z "$listeners" ] && procd_append_param command -l "$listeners"
[ "$listenermode" = "OFF" ] && procd_append_param command --no-listener
[ -z "$desvice_name" ] || procd_append_param command --hostname "$desvice_name"
[ -z "$instance_name" ] || procd_append_param command -m "$instance_name"
[ -z "$vpn_portal" ] || procd_append_param command --vpn-portal "$vpn_portal"
[ -z "$mtu" ] || procd_append_param command --mtu "$mtu"
[ -z "$default_protocol" ] || procd_append_param command --default-protocol "$default_protocol"
[ "$disable_encryption" = "0" ] || procd_append_param command -u
[ "$multi_thread" = "0" ] || procd_append_param command --multi-thread
[ "$disable_ipv6" = "0" ] || procd_append_param command --disable-ipv6
[ "$latency_first" = "0" ] || procd_append_param command --latency-first
[ "$exit_node" = "0" ] || procd_append_param command --enable-exit-node
[ -z "$exit_nodes" ] || procd_append_param command --exit-nodes "$exit_nodes"
[ "$log" = "1" ] && procd_append_param command --file-log-level "info"
[ "$log" = "1" ] && procd_append_param command --file-log-dir "/tmp"
[ "$log" = "0" ] && procd_append_param command --file-log-level "off"
[ ! -z "$instance_name" ] && ln -sf /tmp/easytier-${instance_name}.${date_time} /tmp/easytier.log
procd_set_param limits core="unlimited"
procd_set_param limits nofile="1000000 1000000"
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param respawn
procd_close_instance
if [ ! -z "$listeners" ] ; then
tcpudp_port="$listeners"
wgws_port=$((tcpudp_port + 1))
wss_port=$((tcpudp_port + 2))
uci -q delete firewall.easytier_tcp_udp
uci set firewall.easytier_tcp_udp=rule
uci set firewall.easytier_tcp_udp.name="easytier_tcp_udp"
uci set firewall.easytier_tcp_udp.target="ACCEPT"
uci set firewall.easytier_tcp_udp.src="wan"
uci set firewall.easytier_tcp_udp.proto="all"
uci set firewall.easytier_tcp_udp.dest_port="$tcpudp_port"
uci set firewall.easytier_tcp_udp.enabled="1"
uci -q delete firewall.easytier_wss
uci set firewall.easytier_wss=rule
uci set firewall.easytier_wss.name="easytier_wss"
uci set firewall.easytier_wss.target="ACCEPT"
uci set firewall.easytier_wss.src="wan"
uci set firewall.easytier_wss.proto="all"
uci set firewall.easytier_wss.dest_port="$wss_port"
uci set firewall.easytier_wss.enabled="1"
uci -q delete firewall.easytier_wg_ws
uci set firewall.easytier_wg_ws=rule
uci set firewall.easytier_wg_ws.name="easytier_wg_ws"
uci set firewall.easytier_wg_ws.target="ACCEPT"
uci set firewall.easytier_wg_ws.src="wan"
uci set firewall.easytier_wg_ws.proto="all"
uci set firewall.easytier_wg_ws.dest_port="$wgws_port"
uci set firewall.easytier_wg_ws.enabled="1"
fi
if [ -z "$(uci -q get network.EasyTier)" ]; then
uci set network.EasyTier='interface'
uci set network.EasyTier.device=tun0
uci set network.EasyTier.ifname=tun0
fi
if [ -z "$(uci -q get firewall.easytierzone)" ]; then
uci set firewall.easytierzone='zone'
uci set firewall.easytierzone.input='ACCEPT'
uci set firewall.easytierzone.output='ACCEPT'
uci set firewall.easytierzone.forward='ACCEPT'
uci set firewall.easytierzone.masq='1'
uci set firewall.easytierzone.mtu_fix='1'
uci set firewall.easytierzone.name='EasyTier'
uci set firewall.easytierzone.network='EasyTier'
fi
uci set firewall.easytierfwlan=forwarding
uci set firewall.easytierfwlan.dest='lan'
uci set firewall.easytierfwlan.src='EasyTier'
uci set firewall.easytierfwwan=forwarding
uci set firewall.easytierfwwan.dest='wan'
uci set firewall.easytierfwwan.src='EasyTier'
uci set firewall.lanfweasytier=forwarding
uci set firewall.lanfweasytier.dest='EasyTier'
uci set firewall.lanfweasytier.src='lan'
uci set firewall.wanfweasytier=forwarding
uci set firewall.wanfweasytier.dest='EasyTier'
uci set firewall.wanfweasytier.src='wan'
[ -n "$(uci changes network)" ] && uci commit network && /etc/init.d/network reload >/dev/null 2>&1
[ -n "$(uci changes firewall)" ] && uci commit firewall && /etc/init.d/firewall reload >/dev/null 2>&1
#sysctl -w net.ipv4.ip_forward=1 >/dev/null 2>&1
[ ! -z "$checkip" ] && check
echo `date +%s` > /tmp/easytier_time
}
start_service() {
config_load 'easytier'
date_time=$(TZ='Asia/Shanghai' date +'%Y-%m-%d')
ins_name=$(uci -q set easytier.@easytier[0].instance_name)
if [ ! -z "$ins_name" ] ; then
touch /tmp/easytier-${ins_name}.${date_time}
ln -sf /tmp/easytier-${ins_name}.${date_time} /tmp/easytier.log
else
touch /tmp/easytier-default.${date_time}
ln -sf /tmp/easytier-default.${date_time} /tmp/easytier.log
fi
cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="arm" ; core_url="arm-unknown-linux-musleabi"
[ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && [ ! -d /jffs/clash ] && cpucore="armv7" ; core_url="armv7-unknown-linux-musleabi"
[ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="aarch64" ; core_url="aarch64-unknown-linux-musl"
[ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="i386" ; core_url=""
[ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="x86_64" ; core_url="x86_64-unknown-linux-musl"
if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ] ; then
mipstype=$(echo -n I | hexdump -o 2>/dev/null | awk '{ print substr($2,6,1); exit}')
[ "$mipstype" = "0" ] && cpucore="mips" ; core_url="mips-unknown-linux-musl" || cpucore="mipsle" ; core_url="mipsel-unknown-linux-musl"
fi
#test -z "`opkg list-installed|grep curl`" && echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 缺少curl插件" >>/tmp/easytier.log
#test -z "`opkg list-installed|grep luci-lib-fs`" && echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 缺少luci-lib-fs插件" >>/tmp/easytier.log
#test -z "`opkg list-installed|grep unzip`" && echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 缺少unzip插件" >>/tmp/easytier.log
config_foreach start_et 'easytier'
}
stop_service() {
killall easytier_check >/dev/null 2>&1
killall easytier-core >/dev/null 2>&1
killall -9 easytier-core >/dev/null 2>&1
uci -q delete network.EasyTier >/dev/null 2>&1
uci -q delete firewall.easytierzone >/dev/null 2>&1
uci -q delete firewall.easytierfwlan >/dev/null 2>&1
uci -q delete firewall.easytierfwwan >/dev/null 2>&1
uci -q delete firewall.lanfweasytier >/dev/null 2>&1
uci -q delete firewall.wanfweasytier >/dev/null 2>&1
uci -q delete firewall.easytier_tcp_udp >/dev/null 2>&1
uci -q delete firewall.easytier_wg_ws >/dev/null 2>&1
uci -q delete firewall.easytier_wg_wss >/dev/null 2>&1
[ -n "$(uci changes network)" ] && uci commit network && /etc/init.d/network reload >/dev/null 2>&1
[ -n "$(uci changes firewall)" ] && uci commit firewall && /etc/init.d/firewall reload >/dev/null 2>&1
rm -rf /tmp/easytier-cli_peer /tmp/easytier-cli_connector /tmp/easytier-cli_stun /tmp/easytier-cli_route >/dev/null 2>&1
rm -rf /tmp/easytier-cli_peer-center /tmp/easytier-cli_vpn-portal /tmp/easytier_cmd >/dev/null 2>&1
rm -rf /tmp/easytier-*.* /tmp/easytier.log >/dev/null 2>&1
rm -rf /tmp/easytiernew.tag /tmp/easytier.tag >/dev/null 2>&1
echo "$(date '+%Y-%m-%d %H:%M:%S') easytier : 停止运行" >>/tmp/easytier.log
}
reload_service() {
stop
start
}
service_triggers() {
procd_add_reload_trigger "eaytier"
procd_add_interface_trigger "interface.*.up" wan /etc/init.d/easytier reload
}
+11
View File
@@ -0,0 +1,11 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@easytier[-1]
add ucitrack easytier
set ucitrack.@easytier[-1].init=easytier
commit ucitrack
EOF
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache
exit 0