mirror of
https://github.com/coolsnowwolf/luci
synced 2025-01-09 09:17:27 +08:00
luci-app-socat: tidy up code
This commit is contained in:
parent
d46b2b17d9
commit
35d103c750
@ -5,11 +5,19 @@
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-socat
|
||||
PKG_VERSION:=20200824
|
||||
PKG_RELEASE:=4
|
||||
|
||||
PKG_MAINTAINER:=Lienol <lawlienol@gmail.com>
|
||||
|
||||
LUCI_TITLE:=LuCI support for Socat
|
||||
LUCI_DEPENDS:=+socat
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_RELEASE:=3
|
||||
PKG_DATE:=20200824
|
||||
|
||||
define Package/$(PKG_NAME)/conffiles
|
||||
/etc/config/socat
|
||||
endef
|
||||
|
||||
include ../../luci.mk
|
||||
|
||||
|
@ -1,19 +1,21 @@
|
||||
-- Copyright 2020 Lienol <lawlienol@gmail.com>
|
||||
module("luci.controller.socat", package.seeall)
|
||||
local http = require "luci.http"
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/socat") then return end
|
||||
if not nixio.fs.access("/etc/config/socat") then
|
||||
return
|
||||
end
|
||||
|
||||
entry({"admin", "network", "socat"}, cbi("socat/index"), _("Socat"), 100)
|
||||
entry({"admin", "network", "socat", "config"}, cbi("socat/config")).leaf = true
|
||||
entry({"admin", "network", "socat", "status"}, call("status")).leaf = true
|
||||
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 status()
|
||||
local e = {}
|
||||
e.index = luci.http.formvalue("index")
|
||||
e.status = luci.sys.call(string.format("ps -w | grep -v 'grep' | grep '/var/etc/socat/%s' >/dev/null", luci.http.formvalue("id"))) == 0
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(e)
|
||||
function act_status()
|
||||
local e = {}
|
||||
e.index = luci.http.formvalue("index")
|
||||
e.status = luci.sys.call(string.format("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
|
||||
|
@ -1,7 +1,9 @@
|
||||
local d = require "luci.dispatcher"
|
||||
local e = luci.model.uci.cursor()
|
||||
|
||||
m = Map("socat", translate("Socat"), translate("Socat is a versatile networking tool named after 'Socket CAT', which can be regarded as an N-fold enhanced version of NetCat"))
|
||||
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")
|
||||
|
||||
s = m:section(NamedSection, "global", "global")
|
||||
s.anonymous = true
|
||||
@ -16,20 +18,20 @@ 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
|
||||
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))
|
||||
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"))
|
||||
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"))
|
||||
@ -44,23 +46,23 @@ 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
|
||||
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
|
||||
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"))
|
||||
@ -72,5 +74,5 @@ o.default = "1"
|
||||
o.rmempty = false
|
||||
|
||||
m:append(Template("socat/list_status"))
|
||||
return m
|
||||
|
||||
return m
|
||||
|
@ -16,4 +16,4 @@
|
||||
);
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
</script>
|
||||
|
@ -1,3 +1,3 @@
|
||||
<%+cbi/valueheader%>
|
||||
<font class="_status" hint="<%=self:cfgvalue(section)%>">--</font>
|
||||
<%+cbi/valuefooter%>
|
||||
<%+cbi/valuefooter%>
|
||||
|
1
applications/luci-app-socat/po/zh_Hans
Symbolic link
1
applications/luci-app-socat/po/zh_Hans
Symbolic link
@ -0,0 +1 @@
|
||||
zh-cn
|
@ -116,4 +116,4 @@ stop() {
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user