From 4b1e0830b6df6c66ed0f980b46779858a4f78cd4 Mon Sep 17 00:00:00 2001 From: Pdboy Sir <63764630+sirpdboy@users.noreply.github.com> Date: Fri, 15 Mar 2024 16:58:51 +0800 Subject: [PATCH] =?UTF-8?q?up=20=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=87=AA=E5=8A=A8=E6=98=A0=E5=B0=84=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- luci-app-socat/Makefile | 7 +- .../luasrc/model/cbi/socat/config.lua | 2 +- .../luasrc/model/cbi/socat/index.lua | 2 +- .../luasrc/view/socat/list_status.htm | 2 +- luci-app-socat/po/zh-cn/socat.po | 53 +++++++++++++++ luci-app-socat/po/zh_Hans/socat.po | 53 +++++++++++++++ luci-app-socat/root/etc/init.d/luci_socat | 68 +++++++------------ .../root/etc/uci-defaults/luci-app-socat | 12 +--- 8 files changed, 136 insertions(+), 63 deletions(-) create mode 100644 luci-app-socat/po/zh-cn/socat.po create mode 100644 luci-app-socat/po/zh_Hans/socat.po diff --git a/luci-app-socat/Makefile b/luci-app-socat/Makefile index 2d8ab4a..9e61052 100644 --- a/luci-app-socat/Makefile +++ b/luci-app-socat/Makefile @@ -6,8 +6,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-socat -PKG_VERSION:=20221101 -PKG_RELEASE:=4 +PKG_VERSION:=1.0 +PKG_RELEASE:=6 PKG_MAINTAINER:=Lienol @@ -15,9 +15,6 @@ LUCI_TITLE:=LuCI support for Socat LUCI_DEPENDS:=+socat LUCI_PKGARCH:=all -define Package/$(PKG_NAME)/conffiles -/etc/config/socat -endef include $(TOPDIR)/feeds/luci/luci.mk diff --git a/luci-app-socat/luasrc/model/cbi/socat/config.lua b/luci-app-socat/luasrc/model/cbi/socat/config.lua index afbc084..0a04ce6 100644 --- a/luci-app-socat/luasrc/model/cbi/socat/config.lua +++ b/luci-app-socat/luasrc/model/cbi/socat/config.lua @@ -34,7 +34,7 @@ o.datatype = "portrange" o.rmempty = false o:depends("protocol", "port_forwards") -o = s:option(Flag, "reuseaddr", "reuseaddr", translate("Bind to a port local")) +o = s:option(Flag, "reuseaddr", translate("REUSEADDR"), translate("Bind to a port local")) o.default = "1" o.rmempty = false diff --git a/luci-app-socat/luasrc/model/cbi/socat/index.lua b/luci-app-socat/luasrc/model/cbi/socat/index.lua index 90107a6..7475963 100644 --- a/luci-app-socat/luasrc/model/cbi/socat/index.lua +++ b/luci-app-socat/luasrc/model/cbi/socat/index.lua @@ -3,7 +3,7 @@ local e = luci.model.uci.cursor() m = Map("socat") m.title = translate("Socat") -m.description = translate("Socat is a versatile networking tool named after 'Socket CAT', which can be regarded as an N-fold enhanced version of NetCat") +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 diff --git a/luci-app-socat/luasrc/view/socat/list_status.htm b/luci-app-socat/luasrc/view/socat/list_status.htm index 2757757..8ffac82 100644 --- a/luci-app-socat/luasrc/view/socat/list_status.htm +++ b/luci-app-socat/luasrc/view/socat/list_status.htm @@ -10,7 +10,7 @@ }, function(x, result) { _status[result.index].setAttribute("style","font-weight:bold;"); - _status[result.index].setAttribute("style",result.status ? "color:green":"color:red"); + _status[result.index].setAttribute("color",result.status ? "green":"red"); _status[result.index].innerHTML = (result.status ? '✓' : 'X'); } ); diff --git a/luci-app-socat/po/zh-cn/socat.po b/luci-app-socat/po/zh-cn/socat.po new file mode 100644 index 0000000..5c4dd2e --- /dev/null +++ b/luci-app-socat/po/zh-cn/socat.po @@ -0,0 +1,53 @@ +msgid "Socat" +msgstr "端口转发" + +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 "打开防火墙端口" diff --git a/luci-app-socat/po/zh_Hans/socat.po b/luci-app-socat/po/zh_Hans/socat.po new file mode 100644 index 0000000..72f73ce --- /dev/null +++ b/luci-app-socat/po/zh_Hans/socat.po @@ -0,0 +1,53 @@ +msgid "Socat" +msgstr "端口转发" + +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 "打开防火墙端口" diff --git a/luci-app-socat/root/etc/init.d/luci_socat b/luci-app-socat/root/etc/init.d/luci_socat index 1e08cf1..91ca061 100644 --- a/luci-app-socat/root/etc/init.d/luci_socat +++ b/luci-app-socat/root/etc/init.d/luci_socat @@ -7,43 +7,26 @@ CONFIG=socat CONFIG_PATH=/var/etc/$CONFIG add_rule() { - iptables -N SOCAT - iptables -I INPUT -j SOCAT - ip6tables -N SOCAT - ip6tables -I INPUT -j SOCAT + 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() { - iptables -D INPUT -j SOCAT 2>/dev/null - iptables -F SOCAT 2>/dev/null - iptables -X SOCAT 2>/dev/null - ip6tables -D INPUT -j SOCAT 2>/dev/null - ip6tables -F SOCAT 2>/dev/null - ip6tables -X SOCAT 2>/dev/null -} - -gen_include() { - echo '#!/bin/sh' > /var/etc/$CONFIG.include - extract_rules() { - local _ipt="iptables" - [ "$1" == "6" ] && _ipt="ip6tables" - - echo "*$2" - ${_ipt}-save -t $2 | grep "SOCAT" | \ - sed -e "s/^-A \(INPUT\)/-I \1 1/" - echo 'COMMIT' - } - cat <<-EOF >> /var/etc/$CONFIG.include - iptables-save -c | grep -v "SOCAT" | iptables-restore -c - iptables-restore -n <<-EOT - $(extract_rules 4 filter) - EOT - ip6tables-save -c | grep -v "SOCAT" | ip6tables-restore -c - ip6tables-restore -n <<-EOT - $(extract_rules 6 filter) - EOT - EOF - return 0 + uci -q delete firewall.socat + uci commit firewall + /etc/init.d/firewall reload >/dev/null 2>&1 } run_service() { @@ -81,19 +64,14 @@ run_service() { fi [ "$firewall_accept" == "1" ] && { - if [ -z "$family" ] || [ "$family" == "6" ]; then - ip6tables -A SOCAT -p $proto --dport $listen_port -m comment --comment "$remarks" -j ACCEPT - fi - if [ -z "$family" ] || [ "$family" == "4" ]; then - iptables -A SOCAT -p $proto --dport $listen_port -m comment --comment "$remarks" -j ACCEPT - fi + echo $listen_port >> /var/etc/$CONFIG.port } } stop_service() { - ps -w | grep "$CONFIG_PATH/" | grep -v "grep" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 & + 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.include + rm -rf $CONFIG_PATH /var/etc/$CONFIG.port } start() { @@ -102,10 +80,10 @@ start() { stop_service else mkdir -p $CONFIG_PATH - add_rule + rm -f /var/etc/$CONFIG.port config_load $CONFIG - config_foreach run_service "config" -T - gen_include + config_foreach run_service "config" + add_rule fi } diff --git a/luci-app-socat/root/etc/uci-defaults/luci-app-socat b/luci-app-socat/root/etc/uci-defaults/luci-app-socat index 431f875..f7fabb3 100644 --- a/luci-app-socat/root/etc/uci-defaults/luci-app-socat +++ b/luci-app-socat/root/etc/uci-defaults/luci-app-socat @@ -1,19 +1,11 @@ #!/bin/sh -uci -q batch <<-EOF >/dev/null - delete firewall.socat - set firewall.socat=include - set firewall.socat.type=script - set firewall.socat.path=/var/etc/socat.include - set firewall.socat.reload=1 -EOF - uci -q batch <<-EOF >/dev/null delete ucitrack.@socat[-1] add ucitrack socat - set ucitrack.@socat[-1].init=socat + set ucitrack.@socat[-1].init=luci_socat commit ucitrack EOF -rm -rf /tmp/luci-*cache +rm -rf /tmp/luci-* exit 0