summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua
diff options
context:
space:
mode:
authorStan Grishin <stangri@melmac.net>2019-10-20 15:42:08 -0700
committerStan Grishin <stangri@melmac.net>2019-10-20 15:42:08 -0700
commitcaade389a879dccd8f84886c77fcdea98718db12 (patch)
treee24972f6c9bd48d26ef840285c3e06970ab9623b /applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua
parentf7120fb43a0e7ac840a815d0409240d557c47732 (diff)
luci-app-vpnbypass: better service control buttons
Signed-off-by: Stan Grishin <stangri@melmac.net>
Diffstat (limited to 'applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua')
-rw-r--r--applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua55
1 files changed, 21 insertions, 34 deletions
diff --git a/applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua b/applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua
index e3c5753f4c..8d3ef2b8ee 100644
--- a/applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua
+++ b/applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua
@@ -1,45 +1,32 @@
local readmeURL = "https://github.com/openwrt/packages/blob/master/net/vpnbypass/files/README.md"
-
-m = Map("vpnbypass", translate("VPN Bypass Settings"))
-
-h = m:section(NamedSection, "config", "vpnbypass", translate("Service Status"))
-local packageName = "vpnbypass"
local uci = require "luci.model.uci".cursor()
local sys = require "luci.sys"
-local http = require "luci.http"
-local dispatcher = require "luci.dispatcher"
local util = require "luci.util"
-en = h:option(Button, "__toggle")
-if enabledFlag ~= "1" then
- en.title = translate("Service is disabled/stopped")
- en.inputtitle = translate("Enable/Start")
- en.inputstyle = "apply important"
-else
- en.title = translate("Service is enabled/started")
- en.inputtitle = translate("Stop/Disable")
- en.inputstyle = "reset important"
+local packageName = "vpnbypass"
+
+m = Map("vpnbypass", translate("VPN Bypass Settings"))
+
+local tmpfsVersion = tostring(util.trim(sys.exec("opkg list-installed " .. packageName .. " | awk '{print $3}'")))
+if not tmpfsVersion or tmpfsVersion == "" then
+ tmpfsStatusCode = -1
+ tmpfsVersion = ""
+ tmpfsStatus = packageName .. " " .. translate("is not installed or not found")
+else
+ tmpfsVersion = " [" .. packageName .. " " .. tmpfsVersion .. "]"
end
-function en.write()
- enabledFlag = enabledFlag == "1" and "0" or "1"
- uci:set(packageName, "config", "enabled", enabledFlag)
- uci:save(packageName)
- uci:commit(packageName)
- if enabledFlag == "0" then
- sys.init.stop(packageName)
- sys.init.disable(packageName)
- else
- sys.init.enable(packageName)
- sys.init.start(packageName)
- end
- if dispatcher.lookup("admin/vpn") then
- http.redirect(dispatcher.build_url("admin", "vpn", packageName))
- else
- http.redirect(dispatcher.build_url("admin", "services", packageName))
- end
+local tmpfsStatus = "Stopped"
+if sys.call("iptables -t mangle -L | grep -q VPNBYPASS") == 0 then
+ tmpfsStatus = "Running"
end
-s = m:section(NamedSection, "config", "vpnbypass", translate("VPN Bypass Rules"))
+h = m:section(NamedSection, "config", packageName, translate("Service Status") .. tmpfsVersion)
+ss = h:option(DummyValue, "_dummy", translate("Service Status"))
+ss.template = packageName .. "/status"
+ss.value = tmpfsStatus
+buttons = h:option(DummyValue, "_dummy")
+buttons.template = packageName .. "/buttons"
+s = m:section(NamedSection, "config", "vpnbypass", translate("VPN Bypass Rules"))
-- Local Ports
p1 = s:option(DynamicList, "localport", translate("Local Ports to Bypass"), translate("Local ports to trigger VPN Bypass"))
p1.datatype = "portrange"