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.lua24
-rw-r--r--applications/luci-app-vpn-policy-routing/luasrc/model/cbi/vpn-policy-routing.lua18
-rw-r--r--applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status-gateways.htm6
3 files changed, 34 insertions, 14 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 2daac795d..53c0991c6 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
@@ -3,25 +3,31 @@ function index()
if nixio.fs.access("/etc/config/vpn-policy-routing") then
local e = entry({"admin", "vpn"}, firstchild(), _("VPN"), 60)
e.dependent = false
-
- entry({"admin", "vpn", "vpn-policy-routing"}, cbi("vpn-policy-routing"), _("VPN Policy Routing")).acl_depends = { "luci-app-vpn-policy-routing" }
+ e.acl_depends = { "luci-app-vpn-policy-routing" }
+ entry({"admin", "vpn", "vpn-policy-routing"}, cbi("vpn-policy-routing"), _("VPN Policy Routing"))
entry({"admin", "vpn", "vpn-policy-routing", "action"}, call("vpn_policy_routing_action"), nil).leaf = true
end
end
function vpn_policy_routing_action(name)
local packageName = "vpn-policy-routing"
+ local http = require "luci.http"
+ local sys = require "luci.sys"
+ local uci = require "luci.model.uci".cursor()
+ local util = require "luci.util"
if name == "start" then
- luci.sys.init.start(packageName)
+ sys.init.start(packageName)
elseif name == "action" then
- luci.util.exec("/etc/init.d/" .. packageName .. " restart >/dev/null 2>&1")
+ util.exec("/etc/init.d/" .. packageName .. " restart >/dev/null 2>&1")
elseif name == "stop" then
- luci.sys.init.stop(packageName)
+ sys.init.stop(packageName)
elseif name == "enable" then
- luci.util.exec("uci set " .. packageName .. ".config.enabled=1; uci commit " .. packageName)
+ 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)
+ uci:set(packageName, "config", "enabled", "0")
+ uci:commit(packageName)
end
- luci.http.prepare_content("text/plain")
- luci.http.write("0")
+ http.prepare_content("text/plain")
+ http.write("0")
end
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 692c771a4..61c16b1ef 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
@@ -13,6 +13,20 @@ local dispatcher = require "luci.dispatcher"
local enabledFlag = uci:get(packageName, "config", "enabled")
local enc
+function getPackageVersion()
+ local opkgFile = "/usr/lib/opkg/status"
+ local line
+ local flag = false
+ for line in io.lines(opkgFile) do
+ if flag then
+ return line:match('[%d%.$-]+') or ""
+ elseif line:find("Package: " .. packageName:gsub("%-", "%%%-")) then
+ flag = true
+ end
+ end
+ return ""
+end
+
local ubusStatus = util.ubus("service", "list", { name = packageName })
if ubusStatus and ubusStatus[packageName] and
ubusStatus[packageName]["instances"] and
@@ -33,7 +47,7 @@ if ubusStatus and ubusStatus[packageName] and
end
local serviceRunning, statusText = false, nil
-local packageVersion = tostring(util.trim(sys.exec("opkg list-installed " .. packageName .. " | awk '{print $3}'"))) or ""
+local packageVersion = getPackageVersion()
if packageVersion == "" then
statusText = translatef("%s is not installed or not found", packageName)
end
@@ -78,7 +92,7 @@ if (type(lanIPAddr) == "table") then
break
end
lanIPAddr = lanIPAddr:match("[0-9.]+")
-end
+end
if lanIPAddr and lanNetmask then
laPlaceholder = ip.new(lanIPAddr .. "/" .. lanNetmask )
end
diff --git a/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status-gateways.htm b/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status-gateways.htm
index 710587ad8..4f7790698 100644
--- a/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status-gateways.htm
+++ b/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status-gateways.htm
@@ -1,5 +1,5 @@
<%#
-Copyright 2017-2019 Stan Grishin (stangri@melmac.net)
+Copyright 2017-2020 Stan Grishin (stangri@melmac.net)
This is free software, licensed under the Apache License, Version 2.0
-%>
@@ -11,8 +11,8 @@ This is free software, licensed under the Apache License, Version 2.0
</textarea>
<div>
-<%- local readmeURL = "https://github.com/openwrt/packages/tree/master/net/vpn-policy-routing/files/README.md" -%>
-<%=translatef("Checkmark represents the default gateway. See the %sREADME%s for details.", "<a href=\"" .. readmeURL .. "#a-word-about-default-routing" .. "\" target=\"_blank\">", "</a>")%>
+ <%- local readmeURL = "https://github.com/openwrt/packages/tree/master/net/vpn-policy-routing/files/README.md" -%>
+ <%=translatef("The %s represents the default gateway. See the %sREADME%s for details.", "<strong>✓</strong>", "<a href=\"" .. readmeURL .. "#a-word-about-default-routing" .. "\" target=\"_blank\">", "</a>")%>
</div>
<%+cbi/valuefooter%> \ No newline at end of file