From: Stan Grishin Date: Sun, 20 Oct 2019 22:42:59 +0000 (-0700) Subject: luci-app-vpnbypass: better service control buttons X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=refs%2Fpull%2F3224%2Fhead;p=oweals%2Fluci.git luci-app-vpnbypass: better service control buttons Signed-off-by: Stan Grishin --- diff --git a/applications/luci-app-vpnbypass/Makefile b/applications/luci-app-vpnbypass/Makefile index 7c8909007..133c4bc33 100644 --- a/applications/luci-app-vpnbypass/Makefile +++ b/applications/luci-app-vpnbypass/Makefile @@ -10,7 +10,7 @@ LUCI_TITLE:=VPN Bypass Web UI LUCI_DESCRIPTION:=Provides Web UI for VPNBypass service. LUCI_DEPENDS:=+luci-mod-admin-full +vpnbypass LUCI_PKGARCH:=all -PKG_RELEASE:=11 +PKG_RELEASE:=12 include ../../luci.mk diff --git a/applications/luci-app-vpnbypass/luasrc/controller/vpnbypass.lua b/applications/luci-app-vpnbypass/luasrc/controller/vpnbypass.lua index 56221e043..d034fce32 100644 --- a/applications/luci-app-vpnbypass/luasrc/controller/vpnbypass.lua +++ b/applications/luci-app-vpnbypass/luasrc/controller/vpnbypass.lua @@ -6,5 +6,24 @@ function index() else entry({"admin", "services", "vpnbypass"}, cbi("vpnbypass"), _("VPN Bypass")) end + entry({"admin", "services", "vpnbypass", "action"}, call("vpnbypass_action"), nil).leaf = true end end + +function vpnbypass_action(name) + local packageName = "vpnbypass" + if name == "start" then + luci.sys.init.start(packageName) + elseif name == "action" then + luci.util.exec("/etc/init.d/" .. packageName .. " reload >/dev/null 2>&1") + luci.util.exec("/etc/init.d/dnsmasq restart >/dev/null 2>&1") + elseif name == "stop" then + luci.sys.init.stop(packageName) + elseif name == "enable" then + luci.util.exec("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) + end + luci.http.prepare_content("text/plain") + luci.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 e3c5753f4..8d3ef2b8e 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" diff --git a/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/buttons.htm b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/buttons.htm new file mode 100644 index 000000000..9f79b9b77 --- /dev/null +++ b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/buttons.htm @@ -0,0 +1,53 @@ +<%# + Copyright 2019 Stan Grishin +-%> + +<%- + local packageName = "vpnbypass" + local tmpfsStatus = "Stopped" + local enabledFlag = luci.model.uci.cursor():get(packageName, "config", "enabled") + if luci.sys.call("iptables -t mangle -L | grep -q " .. packageName:upper()) == 0 then + tmpfsStatus = "Running" + end + + if tmpfsStatus == "Stopped" then + btn_start_style = "cbi-button cbi-button-apply important" + btn_action_style = "cbi-button cbi-button-apply important" + btn_stop_style = "cbi-button cbi-button-reset -disabled" + else + btn_start_style = "cbi-button cbi-button-apply -disabled" + btn_action_style = "cbi-button cbi-button-apply important" + btn_stop_style = "cbi-button cbi-button-reset important" + end + if enabledFlag ~= "1" then + btn_start_style = "cbi-button cbi-button-apply -disabled" + btn_action_style = "cbi-button cbi-button-apply -disabled" + btn_enable_style = "cbi-button cbi-button-apply important" + btn_disable_style = "cbi-button cbi-button-reset -disabled" + else + btn_enable_style = "cbi-button cbi-button-apply -disabled" + btn_disable_style = "cbi-button cbi-button-reset important" + end +-%> + +<%+vpnbypass/css%> +<%+vpnbypass/js%> + +
+
+ + + + + + +   +   +   +   + + + + +
+
diff --git a/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/css.htm b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/css.htm new file mode 100644 index 000000000..6fb3d51d3 --- /dev/null +++ b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/css.htm @@ -0,0 +1,9 @@ + diff --git a/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/js.htm b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/js.htm new file mode 100644 index 000000000..76809e938 --- /dev/null +++ b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/js.htm @@ -0,0 +1,60 @@ + + diff --git a/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/status-textarea.htm b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/status-textarea.htm new file mode 100644 index 000000000..75243e395 --- /dev/null +++ b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/status-textarea.htm @@ -0,0 +1,13 @@ +<%# +Copyright 2017-2019 Stan Grishin (stangri@melmac.net) +This is free software, licensed under the Apache License, Version 2.0 +-%> + +<%+cbi/valueheader%> + + + +<%+cbi/valuefooter%> diff --git a/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/status.htm b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/status.htm new file mode 100644 index 000000000..c45342840 --- /dev/null +++ b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/status.htm @@ -0,0 +1,10 @@ +<%# +Copyright 2017-2018 Dirk Brenken (dev@brenken.org) +This is free software, licensed under the Apache License, Version 2.0 +-%> + +<%+cbi/valueheader%> + + + +<%+cbi/valuefooter%>