summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-vpnbypass
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
parentf7120fb43a0e7ac840a815d0409240d557c47732 (diff)
luci-app-vpnbypass: better service control buttons
Signed-off-by: Stan Grishin <stangri@melmac.net>
Diffstat (limited to 'applications/luci-app-vpnbypass')
-rw-r--r--applications/luci-app-vpnbypass/Makefile2
-rw-r--r--applications/luci-app-vpnbypass/luasrc/controller/vpnbypass.lua19
-rw-r--r--applications/luci-app-vpnbypass/luasrc/model/cbi/vpnbypass.lua55
-rw-r--r--applications/luci-app-vpnbypass/luasrc/view/vpnbypass/buttons.htm53
-rw-r--r--applications/luci-app-vpnbypass/luasrc/view/vpnbypass/css.htm9
-rw-r--r--applications/luci-app-vpnbypass/luasrc/view/vpnbypass/js.htm60
-rw-r--r--applications/luci-app-vpnbypass/luasrc/view/vpnbypass/status-textarea.htm13
-rw-r--r--applications/luci-app-vpnbypass/luasrc/view/vpnbypass/status.htm10
8 files changed, 186 insertions, 35 deletions
diff --git a/applications/luci-app-vpnbypass/Makefile b/applications/luci-app-vpnbypass/Makefile
index 7c89090072..133c4bc33d 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 56221e043f..d034fce324 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 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"
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 0000000000..9f79b9b779
--- /dev/null
+++ b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/buttons.htm
@@ -0,0 +1,53 @@
+<%#
+ Copyright 2019 Stan Grishin <stangri@melmac.net>
+-%>
+
+<%-
+ 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%>
+
+<div class="cbi-value"><label class="cbi-value-title">Service Control</label>
+ <div class="cbi-value-field">
+ <input type="button" class="<%=btn_start_style%>" id="btn_start" name="start" value="<%:Start%>" onclick="button_action(this)" />
+ <span id="btn_start_spinner" class="btn_spinner"></span>
+ <input type="button" class="<%=btn_action_style%>" id="btn_action" name="action" value="<%:Reload%>" onclick="button_action(this)" />
+ <span id="btn_action_spinner" class="btn_spinner"></span>
+ <input type="button" class="<%=btn_stop_style%>" id="btn_stop" name="stop" value="<%:Stop%>" onclick="button_action(this)" />
+ <span id="btn_stop_spinner" class="btn_spinner"></span>
+ &nbsp;
+ &nbsp;
+ &nbsp;
+ &nbsp;
+ <input type="button" class="<%=btn_enable_style%>" id="btn_enable" name="enable" value="<%:Enable%>" onclick="button_action(this)" />
+ <span id="btn_enable_spinner" class="btn_spinner"></span>
+ <input type="button" class="<%=btn_disable_style%>" id="btn_disable" name="disable" value="<%:Disable%>" onclick="button_action(this)" />
+ <span id="btn_disable_spinner" class="btn_spinner"></span>
+ </div>
+</div>
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 0000000000..6fb3d51d3b
--- /dev/null
+++ b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/css.htm
@@ -0,0 +1,9 @@
+<style type="text/css">
+ .btn_spinner
+ {
+ display: inline-block;
+ width: 0px;
+ height: 16px;
+ margin: 0 0px;
+ }
+</style>
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 0000000000..76809e9387
--- /dev/null
+++ b/applications/luci-app-vpnbypass/luasrc/view/vpnbypass/js.htm
@@ -0,0 +1,60 @@
+
+<script type="text/javascript">
+//<![CDATA[
+ function button_action(action) {
+ var xhr = new XHR(false);
+ var btn_start = document.getElementById("btn_start");
+ var btn_action = document.getElementById("btn_action");
+ var btn_stop = document.getElementById("btn_stop");
+ var btn_enable = document.getElementById("btn_enable");
+ var btn_disable = document.getElementById("btn_disable");
+ var btn_spinner;
+ switch (action.name) {
+ case "start":
+ btn_spinner = document.getElementById("btn_start_spinner");
+ break;
+ case "action":
+ btn_spinner = document.getElementById("btn_action_spinner");
+ break;
+ case "stop":
+ btn_spinner = document.getElementById("btn_stop_spinner");
+ break;
+ case "enable":
+ btn_spinner = document.getElementById("btn_enable_spinner");
+ break;
+ case "disable":
+ btn_spinner = document.getElementById("btn_disable_spinner");
+ break;
+ }
+ btn_start.disabled = true;
+ btn_action.disabled = true;
+ btn_stop.disabled = true;
+ btn_enable.disabled = true;
+ btn_disable.disabled = true;
+ spinner(btn_spinner, 1);
+ xhr.get('<%=luci.dispatcher.build_url("admin", "services", "vpnbypass", "action")%>/' + action.name, null,
+ function (x) {
+ if (!x) {
+ return;
+ }
+ btn_start.disabled = false;
+ btn_action.disabled = false;
+ btn_stop.disabled = false;
+ btn_enable.disabled = false;
+ btn_disable.disabled = false;
+ spinner(btn_spinner, 0);
+ location.reload();
+ });
+}
+function spinner(element, state) {
+ if (state === 1) {
+ element.style.width = "16px";
+ element.innerHTML = '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" width="16" height="16" style="vertical-align:middle" />';
+ }
+ else {
+ element.style.width = "0px";
+ element.innerHTML = '';
+ }
+}
+//]]>
+</script>
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 0000000000..75243e3950
--- /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%>
+
+<textarea rows="<%=select(2, self:cfgvalue(section):gsub('\n', '\n'))%>"
+ style="border:none;box-shadow:none;background:transparent;font-weight:bold;line-height:20px;width:50em;padding:none;margin:6px;resize:none;overflow:hidden;"
+ disabled="disabled"><%=self:cfgvalue(section):gsub('\n', '\n')%>
+</textarea>
+
+<%+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 0000000000..c453428405
--- /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%>
+
+<input name="status" id="status" type="text" class="cbi-input-text" style="outline:none;border:none;box-shadow:none;background:transparent;font-weight:bold;line-height:30px;height:30px;width:50em;" value="<%=self:cfgvalue(section)%>" disabled="disabled" />
+
+<%+cbi/valuefooter%>