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
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
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"
--- /dev/null
+<%#
+ 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>
+
+
+
+
+ <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>
--- /dev/null
+<style type="text/css">
+ .btn_spinner
+ {
+ display: inline-block;
+ width: 0px;
+ height: 16px;
+ margin: 0 0px;
+ }
+</style>
--- /dev/null
+
+<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>
--- /dev/null
+<%#
+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%>
--- /dev/null
+<%#
+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%>