summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-vpn-policy-routing/luasrc
diff options
context:
space:
mode:
Diffstat (limited to 'applications/luci-app-vpn-policy-routing/luasrc')
-rw-r--r--applications/luci-app-vpn-policy-routing/luasrc/controller/vpn-policy-routing.lua2
-rw-r--r--applications/luci-app-vpn-policy-routing/luasrc/model/cbi/vpn-policy-routing.lua80
-rw-r--r--applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/buttons.htm84
3 files changed, 98 insertions, 68 deletions
diff --git a/applications/luci-app-vpn-policy-routing/luasrc/controller/vpn-policy-routing.lua b/applications/luci-app-vpn-policy-routing/luasrc/controller/vpn-policy-routing.lua
index 0c8c31e7b7..f4af659aad 100644
--- a/applications/luci-app-vpn-policy-routing/luasrc/controller/vpn-policy-routing.lua
+++ b/applications/luci-app-vpn-policy-routing/luasrc/controller/vpn-policy-routing.lua
@@ -12,7 +12,7 @@ function vpn_policy_routing_action(name)
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/" .. packageName .. " restart >/dev/null 2>&1")
elseif name == "stop" then
luci.sys.init.stop(packageName)
elseif name == "enable" then
diff --git a/applications/luci-app-vpn-policy-routing/luasrc/model/cbi/vpn-policy-routing.lua b/applications/luci-app-vpn-policy-routing/luasrc/model/cbi/vpn-policy-routing.lua
index 95d42945eb..6259e82915 100644
--- a/applications/luci-app-vpn-policy-routing/luasrc/model/cbi/vpn-policy-routing.lua
+++ b/applications/luci-app-vpn-policy-routing/luasrc/model/cbi/vpn-policy-routing.lua
@@ -20,30 +20,36 @@ if ubusStatus and ubusStatus[packageName] and
ubusStatus[packageName]["instances"]["main"]["data"] and
ubusStatus[packageName]["instances"]["main"]["data"]["status"] and
ubusStatus[packageName]["instances"]["main"]["data"]["status"][1] then
- pkgGateways = ubusStatus[packageName]["instances"]["main"]["data"]["status"][1]["gateway"]
- pkgGateways = pkgGateways and pkgGateways:gsub('\\n', '\n')
- pkgGateways = pkgGateways and pkgGateways:gsub('\\033%[0;32m%[\\xe2\\x9c\\x93%]\\033%[0m', '✓')
- pkgErrors = ubusStatus[packageName]["instances"]["main"]["data"]["status"][1]["error"]
- pkgErrors = pkgErrors and pkgErrors:gsub('\\n', '\n')
- pkgErrors = pkgErrors and pkgErrors:gsub('\\033%[0;31mERROR\\033%[0m: ', '')
- pkgWarnings = ubusStatus[packageName]["instances"]["main"]["data"]["status"][1]["warning"]
- pkgWarnings = pkgWarnings and pkgWarnings:gsub('\\n', '\n')
- pkgWarnings = pkgWarnings and pkgWarnings:gsub('\\033%[0;33mWARNING\\033%[0m: ', '')
- pkgMode = ubusStatus[packageName]["instances"]["main"]["data"]["status"][1]["mode"]
+ serviceGateways = ubusStatus[packageName]["instances"]["main"]["data"]["status"][1]["gateway"]
+ serviceGateways = serviceGateways and serviceGateways:gsub('\\n', '\n')
+ serviceGateways = serviceGateways and serviceGateways:gsub('\\033%[0;32m%[\\xe2\\x9c\\x93%]\\033%[0m', '✓')
+ serviceErrors = ubusStatus[packageName]["instances"]["main"]["data"]["status"][1]["error"]
+ serviceErrors = serviceErrors and serviceErrors:gsub('\\n', '\n')
+ serviceErrors = serviceErrors and serviceErrors:gsub('\\033%[0;31mERROR\\033%[0m: ', '')
+ serviceWarnings = ubusStatus[packageName]["instances"]["main"]["data"]["status"][1]["warning"]
+ serviceWarnings = serviceWarnings and serviceWarnings:gsub('\\n', '\n')
+ serviceWarnings = serviceWarnings and serviceWarnings:gsub('\\033%[0;33mWARNING\\033%[0m: ', '')
+ serviceMode = ubusStatus[packageName]["instances"]["main"]["data"]["status"][1]["mode"]
end
-local pkgVersion = tostring(util.trim(sys.exec("opkg list-installed " .. packageName .. " | awk '{print $3}'")))
-if not pkgVersion or pkgVersion == "" then
- pkgVersion = ""
- pkgStatus, pkgStatusLabel = "NotFound", packageName .. " " .. translate("is not installed or not found")
+local serviceRunning, statusText = false, nil
+local packageVersion = tostring(util.trim(sys.exec("opkg list-installed " .. packageName .. " | awk '{print $3}'")))
+if not packageVersion or packageVersion == "" then
+ packageVersion = ""
+ statusText = packageName .. " " .. translate("is not installed or not found")
else
- pkgVersion = " [" .. packageName .. " " .. pkgVersion .. "]"
-end
-local pkgStatus, pkgStatusLabel = "Stopped", translate("Stopped")
+ packageVersion = " [" .. packageName .. " " .. packageVersion .. "]"
+end
if sys.call("iptables -t mangle -L | grep -q VPR_PREROUTING") == 0 then
- pkgStatus, pkgStatusLabel = "Running", translate("Running")
- if pkgMode and pkgMode == "strict" then
- pkgStatusLabel = pkgStatusLabel .. " " .. translate("(strict mode)")
+ serviceRunning = true
+ statusText = translate("Running")
+ if serviceMode and serviceMode == "strict" then
+ statusText = statusText .. " (" .. translate("strict mode") .. ")"
+ end
+else
+ statusText = translate("Stopped")
+ if uci:get(packageName, "config", "enabled") ~= "1" then
+ statusText = statusText .. " (" .. translate("disabled") .. ")"
end
end
@@ -74,8 +80,8 @@ if (type(lanIPAddr) == "table") then
lanIPAddr = lanIPAddr[i]
break
end
- lanIPAddr = string.match(lanIPAddr,"[0-9.]+")
-end
+ lanIPAddr = lanIPAddr:match("[0-9.]+")
+end
if lanIPAddr and lanNetmask then
laPlaceholder = ip.new(lanIPAddr .. "/" .. lanNetmask )
end
@@ -114,27 +120,29 @@ end
m = Map("vpn-policy-routing", translate("VPN and WAN Policy-Based Routing"))
-h = m:section(NamedSection, "config", packageName, translate("Service Status") .. pkgVersion)
+h = m:section(NamedSection, "config", packageName, translate("Service Status") .. packageVersion)
status = h:option(DummyValue, "_dummy", translate("Service Status"))
status.template = "vpn-policy-routing/status"
-status.value = pkgStatusLabel
-if pkgStatus:match("Running") and pkgGateways and pkgGateways ~= "" then
+status.value = statusText
+if serviceRunning and serviceGateways and serviceGateways ~= "" then
gateways = h:option(DummyValue, "_dummy", translate("Service Gateways"))
gateways.template = packageName .. "/status-gateways"
- gateways.value = pkgGateways
+ gateways.value = serviceGateways
end
-if pkgErrors and pkgErrors ~= "" then
+if serviceErrors and serviceErrors ~= "" then
errors = h:option(DummyValue, "_dummy", translate("Service Errors"))
errors.template = packageName .. "/status-textarea"
- errors.value = pkgErrors
+ errors.value = serviceErrors
end
-if pkgWarnings and pkgWarnings ~= "" then
+if serviceWarnings and serviceWarnings ~= "" then
warnings = h:option(DummyValue, "_dummy", translate("Service Warnings"))
warnings.template = packageName .. "/status-textarea"
- warnings.value = pkgWarnings
+ warnings.value = serviceWarnings
+end
+if packageVersion ~= "" then
+ buttons = h:option(DummyValue, "_dummy")
+ buttons.template = packageName .. "/buttons"
end
-buttons = h:option(DummyValue, "_dummy")
-buttons.template = packageName .. "/buttons"
-- General Options
config = m:section(NamedSection, "config", "vpn-policy-routing", translate("Configuration"))
@@ -208,7 +216,7 @@ icmp:value("", translate("No Change"))
icmp:value("wan", translate("WAN"))
uci:foreach("network", "interface", function(s)
local name=s['.name']
- if is_supported_interface(s) then icmp:value(name, string.upper(name)) end
+ if is_supported_interface(s) then icmp:value(name, name:upper()) end
end)
icmp.rmempty = true
@@ -338,10 +346,10 @@ gw.rmempty = false
uci:foreach("network", "interface", function(s)
local name=s['.name']
if is_wan(name) then
- gw:value(name, string.upper(name))
+ gw:value(name, name:upper())
if not gw.default then gw.default = name end
elseif is_supported_interface(s) then
- gw:value(name, string.upper(name))
+ gw:value(name, name:upper())
end
end)
@@ -351,7 +359,7 @@ dscp = m:section(NamedSection, "config", "vpn-policy-routing", translate("DSCP T
uci:foreach("network", "interface", function(s)
local name=s['.name']
if is_supported_interface(s) then
- local x = dscp:option(Value, name .. "_dscp", string.upper(name) .. " " .. translate("DSCP Tag"))
+ local x = dscp:option(Value, name .. "_dscp", name:upper() .. " " .. translate("DSCP Tag"))
x.rmempty = true
x.datatype = "range(1,63)"
end
diff --git a/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/buttons.htm b/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/buttons.htm
index a9c473c751..37a0b9a414 100644
--- a/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/buttons.htm
+++ b/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/buttons.htm
@@ -1,55 +1,77 @@
-<%#
- Copyright 2019 Stan Grishin <stangri@melmac.net>
--%>
+<%# Copyright 2020 Stan Grishin <stangri@melmac.net> -%>
+
+<%+vpn-policy-routing/css%>
+<%+vpn-policy-routing/js%>
<%-
local packageName = "vpn-policy-routing"
- local enabledFlag = luci.model.uci.cursor():get(packageName, "config", "enabled")
- if nixio.fs.access("/var/run/" .. packageName .. ".json") then
- tmpfs = luci.jsonc.parse(luci.util.trim(luci.sys.exec("cat /var/run/" .. packageName .. ".json")))
- end
- local pkgStatus, pkgStatusLabel = "Stopped", translate("Stopped")
+ local serviceRunning, serviceEnabled = false, false;
if luci.sys.call("iptables -t mangle -L | grep -q VPR_PREROUTING") == 0 then
- pkgStatus, pkgStatusLabel = "Running", translate("Running")
+ serviceRunning = true
+ end
+ if luci.model.uci.cursor():get(packageName, "config", "enabled") == "1" then
+ serviceEnabled = true
end
- if pkgStatus == "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"
+
+ if serviceEnabled then
+ btn_start_status = true
+ btn_action_status = true
+ btn_stop_status = true
+ btn_enable_status = false
+ btn_disable_status = true
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"
+ btn_start_status = false
+ btn_action_status = false
+ btn_stop_status = false
+ btn_enable_status = true
+ btn_disable_status = false
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"
+ if serviceRunning then
+ btn_start_status = false
+ btn_action_status = true
+ btn_stop_status = true
else
- btn_enable_style = "cbi-button cbi-button-apply -disabled"
- btn_disable_style = "cbi-button cbi-button-reset important"
+ btn_action_status = false
+ btn_stop_status = false
end
-%>
-<%+vpn-policy-routing/css%>
-<%+vpn-policy-routing/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)" />
+ <input type="button" class="cbi-button cbi-button-apply" 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)" />
+ <input type="button" class="cbi-button cbi-button-apply" id="btn_action" name="action" value="<%:Restart%>"
+ 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)" />
+ <input type="button" class="cbi-button cbi-button-reset" 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)" />
+ <input type="button" class="cbi-button cbi-button-apply" 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)" />
+ <input type="button" class="cbi-button cbi-button-reset" id="btn_disable" name="disable" value="<%:Disable%>"
+ onclick="button_action(this)" />
<span id="btn_disable_spinner" class="btn_spinner"></span>
</div>
</div>
+
+<%-if not btn_start_status then%>
+<script type="text/javascript">document.getElementById("btn_start").disabled = true;</script>
+<%-end%>
+<%-if not btn_action_status then%>
+<script type="text/javascript">document.getElementById("btn_action").disabled = true;</script>
+<%-end%>
+<%-if not btn_stop_status then%>
+<script type="text/javascript">document.getElementById("btn_stop").disabled = true;</script>
+<%-end%>
+<%-if not btn_enable_status then%>
+<script type="text/javascript">document.getElementById("btn_enable").disabled = true;</script>
+<%-end%>
+<%-if not btn_disable_status then%>
+<script type="text/javascript">document.getElementById("btn_disable").disabled = true;</script>
+<%-end%>