diff options
author | Stan Grishin <stangri@melmac.net> | 2020-09-21 18:33:51 +0000 |
---|---|---|
committer | Stan Grishin <stangri@melmac.net> | 2020-09-21 18:33:51 +0000 |
commit | 053e3952f02319ae5e0d8668cf67ce8c4a8c7f6d (patch) | |
tree | 9d60e1d969d516c0117591a5064d1a9263b89ce3 /applications/luci-app-vpnbypass/luasrc | |
parent | 073b9ba3bdc932d28dbc49fb005e13bea494e610 (diff) |
luci-app-vpnbypass: ACL update
Signed-off-by: Stan Grishin <stangri@melmac.net>
Diffstat (limited to 'applications/luci-app-vpnbypass/luasrc')
-rw-r--r-- | applications/luci-app-vpnbypass/luasrc/controller/vpnbypass.lua | 26 | ||||
-rw-r--r-- | applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua | 18 |
2 files changed, 32 insertions, 12 deletions
diff --git a/applications/luci-app-vpnbypass/luasrc/controller/vpnbypass.lua b/applications/luci-app-vpnbypass/luasrc/controller/vpnbypass.lua index 0de6ff648..057aee787 100644 --- a/applications/luci-app-vpnbypass/luasrc/controller/vpnbypass.lua +++ b/applications/luci-app-vpnbypass/luasrc/controller/vpnbypass.lua @@ -3,26 +3,32 @@ function index() if nixio.fs.access("/etc/config/vpnbypass") then local e = entry({"admin", "vpn"}, firstchild(), _("VPN"), 60) e.dependent = false - - entry({"admin", "vpn", "vpnbypass"}, cbi("vpnbypass"), _("VPN Bypass")).acl_depends = { "luci-app-vpnbypass" } + e.acl_depends = { "luci-app-vpnbypass" } + entry({"admin", "vpn", "vpnbypass"}, cbi("vpnbypass"), _("VPN Bypass")) entry({"admin", "vpn", "vpnbypass", "action"}, call("vpnbypass_action"), nil).leaf = true end end function vpnbypass_action(name) local packageName = "vpnbypass" + local http = require "luci.http" + local sys = require "luci.sys" + local uci = require "luci.model.uci".cursor() + local util = require "luci.util" if name == "start" then - luci.sys.init.start(packageName) + sys.init.start(packageName) elseif name == "action" then - luci.util.exec("/etc/init.d/" .. packageName .. " restart >/dev/null 2>&1") - luci.util.exec("/etc/init.d/dnsmasq restart >/dev/null 2>&1") + util.exec("/etc/init.d/" .. packageName .. " restart >/dev/null 2>&1") + util.exec("/etc/init.d/dnsmasq restart >/dev/null 2>&1") elseif name == "stop" then - luci.sys.init.stop(packageName) + sys.init.stop(packageName) elseif name == "enable" then - luci.util.exec("uci set " .. packageName .. ".config.enabled=1; uci commit " .. packageName) + uci:set(packageName, "config", "enabled", "1") + uci:commit(packageName) elseif name == "disable" then - luci.util.exec("uci set " .. packageName .. ".config.enabled=0; uci commit " .. packageName) + uci:set(packageName, "config", "enabled", "0") + uci:commit(packageName) end - luci.http.prepare_content("text/plain") - luci.http.write("0") + http.prepare_content("text/plain") + http.write("0") end diff --git a/applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua b/applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua index 8a70bd1bb..ed9599c90 100644 --- a/applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua +++ b/applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua @@ -4,8 +4,22 @@ local sys = require "luci.sys" local util = require "luci.util" local packageName = "vpnbypass" -local packageVersion, statusText = nil, nil -packageVersion = tostring(util.trim(sys.exec("opkg list-installed " .. packageName .. " | awk '{print $3}'"))) or "" +function getPackageVersion() + local opkgFile = "/usr/lib/opkg/status" + local line + local flag = false + for line in io.lines(opkgFile) do + if flag then + return line:match('[%d%.$-]+') or "" + elseif line:find("Package: " .. packageName:gsub("%-", "%%%-")) then + flag = true + end + end + return "" +end + +local packageVersion = getPackageVersion() +local statusText = nil if packageVersion == "" then statusText = translatef("%s is not installed or not found", packageName) end |