Packages/luci-app-socat/luasrc/controller/socat.lua
2024-12-04 10:15:35 +08:00

20 lines
792 B
Lua

-- 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
entry({"admin", "network", "socat"}, cbi("socat/index"), _("Socat"), 100).acl_depends = { "luci-app-socat" }
entry({"admin", "network", "socat", "config"}, cbi("socat/config")).leaf = true
entry({"admin", "network", "socat", "status"}, call("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)
end