🐶 Sync 2025-11-02 14:26:26

This commit is contained in:
actions-user
2025-11-02 14:26:26 +08:00
parent 64bcc56c2a
commit ac011db799
1557 changed files with 746465 additions and 0 deletions

20
luci-app-socat/Makefile Normal file
View File

@@ -0,0 +1,20 @@
# Copyright (C) 2020 Lienol <lawlienol@gmail.com>
#
# This is free software, licensed under the GNU General Public License v3.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-socat
PKG_VERSION:=1.0
PKG_RELEASE:=6
PKG_MAINTAINER:=Lienol <lawlienol@gmail.com>
LUCI_TITLE:=LuCI support for Socat
LUCI_DEPENDS:=+socat
LUCI_PKGARCH:=all
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@@ -0,0 +1,21 @@
-- Copyright 2020 Lienol <lawlienol@gmail.com>
module("luci.controller.socat", package.seeall)
function index()
if not nixio.fs.access("/etc/config/socat") then
return
end
entry({"admin", "network", "socat"}, alias("admin", "network", "socat", "index"), _("Socat"), 100).dependent = true
entry({"admin", "network", "socat", "index"}, cbi("socat/index")).leaf = true
entry({"admin", "network", "socat", "config"}, cbi("socat/config")).leaf = true
entry({"admin", "network", "socat", "status"}, call("act_status")).leaf = true
end
function act_status()
local e = {}
e.index = luci.http.formvalue("index")
e.status = luci.sys.call(string.format("busybox ps -w | grep -v 'grep' | grep '/var/etc/socat/%s' >/dev/null", luci.http.formvalue("id"))) == 0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end

View File

@@ -0,0 +1,82 @@
local d = require "luci.dispatcher"
m = Map("socat", translate("Socat Config"))
m.redirect = d.build_url("admin", "network", "socat")
s = m:section(NamedSection, arg[1], "config", "")
s.addremove = false
s.dynamic = false
o = s:option(Flag, "enable", translate("Enable"))
o.default = "1"
o.rmempty = false
o = s:option(Value, "remarks", translate("Remarks"))
o.default = translate("Remarks")
o.rmempty = false
o = s:option(ListValue, "protocol", translate("Protocol"))
o:value("port_forwards", translate("Port Forwards"))
o = s:option(ListValue, "family", translate("Restrict to address family"))
o:value("", translate("IPv4 and IPv6"))
o:value("4", translate("IPv4 only"))
o:value("6", translate("IPv6 only"))
o:depends("protocol", "port_forwards")
o = s:option(ListValue, "proto", translate("Protocol"))
o:value("tcp", "TCP")
o:value("udp", "UDP")
o:depends("protocol", "port_forwards")
o = s:option(Value, "listen_port", translate("Listen port"))
o.datatype = "portrange"
o.rmempty = false
o:depends("protocol", "port_forwards")
o = s:option(Flag, "reuseaddr", translate("REUSEADDR"), translate("Bind to a port local"))
o.default = "1"
o.rmempty = false
o = s:option(ListValue, "dest_proto", translate("Destination Protocol"))
o:value("tcp4", "IPv4-TCP")
o:value("udp4", "IPv4-UDP")
o:value("tcp6", "IPv6-TCP")
o:value("udp6", "IPv6-UDP")
o:depends("protocol", "port_forwards")
dest_ipv4 = s:option(Value, "dest_ipv4", translate("Destination address"))
luci.sys.net.ipv4_hints(function(ip, name)
dest_ipv4:value(ip, "%s (%s)" %{ ip, name })
end)
function dest_ipv4.cfgvalue(self, section)
return m:get(section, "dest_ip")
end
function dest_ipv4.write(self, section, value)
m:set(section, "dest_ip", value)
end
dest_ipv4:depends("dest_proto", "tcp4")
dest_ipv4:depends("dest_proto", "udp4")
dest_ipv6 = s:option(Value, "dest_ipv6", translate("Destination address"))
luci.sys.net.ipv6_hints(function(ip, name)
dest_ipv6:value(ip, "%s (%s)" %{ ip, name })
end)
function dest_ipv6.cfgvalue(self, section)
return m:get(section, "dest_ip")
end
function dest_ipv6.write(self, section, value)
m:set(section, "dest_ip", value)
end
dest_ipv6:depends("dest_proto", "tcp6")
dest_ipv6:depends("dest_proto", "udp6")
o = s:option(Value, "dest_port", translate("Destination port"))
o.datatype = "portrange"
o.rmempty = false
o = s:option(Flag, "firewall_accept", translate("Open firewall port"))
o.default = "1"
o.rmempty = false
return m

View File

@@ -0,0 +1,78 @@
local d = require "luci.dispatcher"
local e = luci.model.uci.cursor()
m = Map("socat")
m.title = translate("Socat")
m.description = translate("Socat is a relay for bidirectional data transfer between two independent data channels.")
s = m:section(NamedSection, "global", "global")
s.anonymous = true
s.addremove = false
o = s:option(Flag, "enable", translate("Enable"))
o.rmempty = false
s = m:section(TypedSection, "config", translate("Port Forwards"))
s.anonymous = true
s.addremove = true
s.template = "cbi/tblsection"
s.extedit = d.build_url("admin", "network", "socat", "config", "%s")
function s.filter(e, t)
if m:get(t, "protocol") == "port_forwards" then
return true
end
end
function s.create(e, t)
local uuid = string.gsub(luci.sys.exec("echo -n $(cat /proc/sys/kernel/random/uuid)"), "-", "")
t = uuid
TypedSection.create(e, t)
luci.http.redirect(e.extedit:format(t))
end
function s.remove(e, t)
e.map.proceed = true
e.map:del(t)
luci.http.redirect(d.build_url("admin", "network", "socat"))
end
o = s:option(Flag, "enable", translate("Enable"))
o.width = "5%"
o.rmempty = false
o = s:option(DummyValue, "status", translate("Status"))
o.template = "socat/status"
o.value = translate("Collecting data...")
o = s:option(DummyValue, "remarks", translate("Remarks"))
o = s:option(DummyValue, "family", translate("Listen Protocol"))
o.cfgvalue = function(t, n)
local listen = Value.cfgvalue(t, n) or ""
local protocol = (m:get(n, "proto") or ""):upper()
if listen == "" then
return protocol
else
return "IPv" .. listen .. "-" .. protocol
end
end
o = s:option(DummyValue, "listen_port", translate("Listen port"))
o = s:option(DummyValue, "dest_proto", translate("Destination Protocol"))
o.cfgvalue = function(t, n)
local listen = Value.cfgvalue(t, n)
local protocol = listen:sub(0, #listen - 1):upper()
local ip_type = "IPv" .. listen:sub(#listen)
return ip_type .. "-" .. protocol
end
o = s:option(DummyValue, "dest_ip", translate("Destination address"))
o = s:option(DummyValue, "dest_port", translate("Destination port"))
o = s:option(Flag, "firewall_accept", translate("Open firewall port"))
o.default = "1"
o.rmempty = false
m:append(Template("socat/list_status"))
return m

View File

@@ -0,0 +1,19 @@
<script type="text/javascript">
//<![CDATA[
var _status = document.getElementsByClassName('_status');
for(var i = 0; i < _status.length; i++) {
var id = _status[i].parentElement.parentElement.parentElement.id;
id = id.substr(id.lastIndexOf("-") + 1);
XHR.poll(1,'<%=url([[admin]], [[network]], [[socat]], [[status]])%>', {
index: i,
id: id
},
function(x, result) {
_status[result.index].setAttribute("style","font-weight:bold;");
_status[result.index].setAttribute("color",result.status ? "green":"red");
_status[result.index].innerHTML = (result.status ? '✓' : 'X');
}
);
}
//]]>
</script>

View File

@@ -0,0 +1,3 @@
<%+cbi/valueheader%>
<font class="_status" hint="<%=self:cfgvalue(section)%>">--</font>
<%+cbi/valuefooter%>

1
luci-app-socat/po/zh-cn Symbolic link
View File

@@ -0,0 +1 @@
zh_Hans

View File

@@ -0,0 +1,53 @@
msgid "Socat"
msgstr "Socat"
msgid "Socat is a relay for bidirectional data transfer between two independent data channels."
msgstr "Socat 是用于在两个独立数据通道之间进行双向数据传输的中继器。"
msgid "Socat Config"
msgstr "Socat 配置"
msgid "Status"
msgstr "状态"
msgid "Enabled"
msgstr "启用"
msgid "Remarks"
msgstr "备注"
msgid "Protocol"
msgstr "协议"
msgid "IPv6 Only"
msgstr "仅 IPv6"
msgid "When checked, only IPv6 ports are listen for, otherwise IPv4 will also be listened for."
msgstr "当勾选时,仅监听 IPv6否则将会同时监听 IPv4。"
msgid "Port Forwards"
msgstr "端口转发"
msgid "Listen Protocol"
msgstr "监听协议"
msgid "Listen port"
msgstr "监听端口"
msgid "REUSEADDR"
msgstr "地址重用"
msgid "Bind to a port local"
msgstr "绑定到本地端口"
msgid "Destination Protocol"
msgstr "目标协议"
msgid "Destination address"
msgstr "目标地址"
msgid "Destination port"
msgstr "目标端口"
msgid "Open firewall port"
msgstr "打开防火墙端口"

View File

@@ -0,0 +1,104 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2020 Lienol <lawlienol@gmail.com>
START=99
CONFIG=socat
CONFIG_PATH=/var/etc/$CONFIG
add_rule() {
accept_port=$(cat /var/etc/$CONFIG.port | tr "\n" " ")
if [ "$accept_port" ]; then
uci -q delete firewall.socat
uci set firewall.socat=rule
uci set firewall.socat.name="socat"
uci set firewall.socat.target="ACCEPT"
uci set firewall.socat.src="wan"
uci set firewall.socat.dest_port="$accept_port"
uci set firewall.socat.enabled="1"
uci commit firewall
/etc/init.d/firewall reload >/dev/null 2>&1
else
del_rule
fi
}
del_rule() {
uci -q delete firewall.socat
uci commit firewall
/etc/init.d/firewall reload >/dev/null 2>&1
}
run_service() {
config_get enable $1 enable
[ "$enable" = "0" ] && return 0
config_get remarks $1 remarks
config_get protocol $1 protocol
config_get family $1 family
config_get proto $1 proto
config_get listen_port $1 listen_port
config_get reuseaddr $1 reuseaddr
config_get dest_proto $1 dest_proto
config_get dest_ip $1 dest_ip
config_get dest_port $1 dest_port
config_get firewall_accept $1 firewall_accept
ln -s /usr/bin/socat ${CONFIG_PATH}/$1
if [ "$reuseaddr" == "1" ]; then
reuseaddr=",reuseaddr"
else
reuseaddr=""
fi
if [ "$family" == "6" ]; then
ipv6only_params=",ipv6-v6only"
else
ipv6only_params=""
fi
# 端口转发
if [ "$protocol" == "port_forwards" ]; then
listen=${proto}${family}
[ "$family" == "" ] && listen=${proto}6
${CONFIG_PATH}/$1 ${listen}-listen:${listen_port}${ipv6only_params}${reuseaddr},fork ${dest_proto}:${dest_ip}:${dest_port} >/dev/null 2>&1 &
fi
[ "$firewall_accept" == "1" ] && {
echo $listen_port >> /var/etc/$CONFIG.port
}
}
stop_service() {
busybox ps -w | grep "$CONFIG_PATH/" | grep -v "grep" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
del_rule
rm -rf $CONFIG_PATH /var/etc/$CONFIG.port
}
start() {
[ -f "/etc/config/socat" ] && [ $(grep -c global /etc/config/socat) -eq 0 ] && {
uci add socat global
uci rename socat.@global[0]='global'
uci set socat.global.enable="$(grep -q "enable '1'" /etc/config/socat && echo '1' || echo '0')"
uci commit socat
}
enable=$(uci -q get $CONFIG.@global[0].enable)
if [ "$enable" = "0" ];then
stop_service
else
mkdir -p $CONFIG_PATH
rm -f /var/etc/$CONFIG.port
config_load $CONFIG
config_foreach run_service "config"
add_rule
fi
}
stop() {
stop_service
}
reload_service() {
stop
sleep 1
start
}

View File

@@ -0,0 +1,13 @@
#!/bin/sh
[ -f "/etc/config/ucitrack" ] && {
uci -q batch <<-EOF >/dev/null
delete ucitrack.@socat[-1]
add ucitrack socat
set ucitrack.@socat[-1].init=luci_socat
commit ucitrack
EOF
}
rm -rf /tmp/luci-*cache*
exit 0

View File

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

View File

@@ -0,0 +1,4 @@
{
"config": "socat",
"init": "luci_socat"
}