diff options
Diffstat (limited to 'applications/luci-app-vpn-policy-routing/luasrc')
6 files changed, 91 insertions, 56 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 2daac795dd..53c0991c6d 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 692c771a43..82d90e9bf8 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 @@ -1,6 +1,5 @@ -local readmeURL = "https://github.com/openwrt/packages/tree/master/net/vpn-policy-routing/files/README.md" - local packageName = "vpn-policy-routing" +local readmeURL = "https://docs.openwrt.melmac.net/" .. packageName .. "/" local uci = require "luci.model.uci".cursor() local sys = require "luci.sys" local util = require "luci.util" @@ -13,6 +12,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 +46,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 +91,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 @@ -128,16 +141,16 @@ if serviceRunning and serviceGateways and serviceGateways ~= "" then end if serviceErrors and serviceErrors ~= "" then errors = h:option(DummyValue, "_dummy", translate("Service Errors")) - errors.template = packageName .. "/status-textarea" + errors.template = packageName .. "/status" errors.value = serviceErrors end if serviceWarnings and serviceWarnings ~= "" then warnings = h:option(DummyValue, "_dummy", translate("Service Warnings")) - warnings.template = packageName .. "/status-textarea" + warnings.template = packageName .. "/status" warnings.value = serviceWarnings end if packageVersion ~= "" then - buttons = h:option(DummyValue, "_dummy") + buttons = h:option(DummyValue, "_dummy", translate("Service Control")) buttons.template = packageName .. "/buttons" end @@ -161,18 +174,11 @@ se:value("0", translate("Do not enforce policies when their gateway is down")) se:value("1", translate("Strictly enforce policies when their gateway is down")) se.default = 1 -dest_ipset = config:taboption("basic", ListValue, "dest_ipset", translate("The ipset option for remote policies"), +resolver_ipset = config:taboption("basic", ListValue, "resolver_ipset", translate("Use resolver's ipset for domains"), translatef("Please check the %sREADME%s before changing this option.", "<a href=\"" .. readmeURL .. "#service-configuration-settings" .. "\" target=\"_blank\">", "</a>")) -dest_ipset:value("", translate("Disabled")) -dest_ipset:value("ipset", translate("Use ipset command")) -dest_ipset:value("dnsmasq.ipset", translate("Use DNSMASQ ipset")) -dest_ipset.default = "" -dest_ipset.rmempty = true - -src_ipset = config:taboption("basic", ListValue, "src_ipset", translate("The ipset option for local policies"), - translatef("Please check the %sREADME%s before changing this option.", "<a href=\"" .. readmeURL .. "#service-configuration-settings" .. "\" target=\"_blank\">", "</a>")) -src_ipset:value("0", translate("Disabled")) -src_ipset:value("1", translate("Use ipset command")) +resolver_ipset:value("none", translate("Disabled")) +resolver_ipset:value("dnsmasq.ipset", translate("DNSMASQ ipset")) +resolver_ipset.default = "dnsmasq.ipset" ipv6 = config:taboption("basic", ListValue, "ipv6_enabled", translate("IPv6 Support")) ipv6:value("0", translate("Disabled")) @@ -192,15 +198,23 @@ timeout = config:taboption("advanced", Value, "boot_timeout", translate("Boot Ti timeout.optional = false timeout.rmempty = true +dest_ipset = config:taboption("advanced", ListValue, "dest_ipset", translate("The ipset option for remote policies"), + translatef("Please check the %sREADME%s before changing this option.", "<a href=\"" .. readmeURL .. "#service-configuration-settings" .. "\" target=\"_blank\">", "</a>")) +dest_ipset:value("0", translate("Disabled")) +dest_ipset:value("1", translate("Use ipset command")) +dest_ipset.default = "0" + +src_ipset = config:taboption("advanced", ListValue, "src_ipset", translate("The ipset option for local policies"), + translatef("Please check the %sREADME%s before changing this option.", "<a href=\"" .. readmeURL .. "#service-configuration-settings" .. "\" target=\"_blank\">", "</a>")) +src_ipset:value("0", translate("Disabled")) +src_ipset:value("1", translate("Use ipset command")) +src_ipset.default = "0" + insert = config:taboption("advanced", ListValue, "iptables_rule_option", translate("IPTables rule option"), translate("Select Append for -A and Insert for -I.")) insert:value("append", translate("Append")) insert:value("insert", translate("Insert")) insert.default = "append" -iprule = config:taboption("advanced", ListValue, "iprule_enabled", translate("IP Rules Support"), translate("Add an ip rule, not an iptables entry for policies with just the local address. Use with caution to manipulte policies priorities.")) -iprule:value("0", translate("Disabled")) -iprule:value("1", translate("Enabled")) - icmp = config:taboption("advanced", ListValue, "icmp_interface", translate("Default ICMP Interface"), translate("Force the ICMP protocol interface.")) icmp:value("", translate("No Change")) icmp:value("wan", translate("WAN")) @@ -210,12 +224,6 @@ uci:foreach("network", "interface", function(s) end) icmp.rmempty = true -append_local = config:taboption("advanced", Value, "append_src_rules", translate("Append local IP Tables rules"), translate("Special instructions to append iptables rules for local IPs/netmasks/devices.")) -append_local.rmempty = true - -append_remote = config:taboption("advanced", Value, "append_dest_rules", translate("Append remote IP Tables rules"), translate("Special instructions to append iptables rules for remote IPs/netmasks.")) -append_remote.rmempty = true - wantid = config:taboption("advanced", Value, "wan_tid", translate("WAN Table ID"), translate("Starting (WAN) Table ID number for tables created by the service.")) wantid.rmempty = true wantid.placeholder = "201" @@ -248,12 +256,15 @@ webui_chain_column = config:taboption("webui", ListValue, "webui_chain_column", webui_chain_column:value("0", translate("Disabled")) webui_chain_column:value("1", translate("Enabled")) +webui_show_ignore_target = config:taboption("webui", ListValue, "webui_show_ignore_target", translate("Add IGNORE Target"), translate("Adds `IGNORE` to the list of interfaces for policies, allowing you to skip further processing by VPN Policy Routing.")) +webui_show_ignore_target:value("0", translate("Disabled")) +webui_show_ignore_target:value("1", translate("Enabled")) + webui_sorting = config:taboption("webui", ListValue, "webui_sorting", translate("Show Up/Down Buttons"), translate("Shows the Up/Down buttons for policies, allowing you to move a policy up or down in the list.")) webui_sorting:value("0", translate("Disabled")) webui_sorting:value("1", translate("Enabled")) webui_sorting.default = "1" - -- Policies p = m:section(TypedSection, "policy", translate("Policies"), translate("Comment, interface and at least one other field are required. Multiple local and remote addresses/devices/domains and ports can be space separated. Placeholders below represent just the format/syntax and will not be used if fields are left blank.")) p.template = "cbi/tblsection" @@ -342,6 +353,10 @@ uci:foreach("network", "interface", function(s) gw:value(name, name:upper()) end end) +enc = tonumber(uci:get("vpn-policy-routing", "config", "webui_show_ignore_target")) +if enc and enc ~= 0 then + gw:value("ignore", "IGNORE") +end dscp = m:section(NamedSection, "config", "vpn-policy-routing", translate("DSCP Tagging"), translatef("Set DSCP tags (in range between 1 and 63) for specific interfaces. See the %sREADME%s for details.", "<a href=\"" .. readmeURL .. "#dscp-tag-based-policies" .. "\" target=\"_blank\">", "</a>")) 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 37a0b9a414..8a64698b6c 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 @@ -5,11 +5,13 @@ <%- local packageName = "vpn-policy-routing" + local uci = require "luci.model.uci".cursor() + local sys = require "luci.sys" local serviceRunning, serviceEnabled = false, false; - if luci.sys.call("iptables -t mangle -L | grep -q VPR_PREROUTING") == 0 then + if sys.call("iptables -t mangle -L | grep -q VPR_PREROUTING") == 0 then serviceRunning = true end - if luci.model.uci.cursor():get(packageName, "config", "enabled") == "1" then + if uci:get(packageName, "config", "enabled") == "1" then serviceEnabled = true end @@ -36,29 +38,29 @@ end -%> -<div class="cbi-value"><label class="cbi-value-title">Service Control</label> +<%+cbi/valueheader%> <div class="cbi-value-field"> - <input type="button" class="cbi-button cbi-button-apply" id="btn_start" name="start" value="<%:Start%>" + <input type="button" class="btn 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="cbi-button cbi-button-apply" id="btn_action" name="action" value="<%:Restart%>" + <input type="button" class="btn 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="cbi-button cbi-button-reset" id="btn_stop" name="stop" value="<%:Stop%>" + <input type="button" class="btn 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> - <input type="button" class="cbi-button cbi-button-apply" id="btn_enable" name="enable" value="<%:Enable%>" + <input type="button" class="btn 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="cbi-button cbi-button-reset" id="btn_disable" name="disable" value="<%:Disable%>" + <input type="button" class="btn 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> +<%+cbi/valuefooter%> <%-if not btn_start_status then%> <script type="text/javascript">document.getElementById("btn_start").disabled = true;</script> 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 710587ad82..377cfeeaac 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,18 +1,18 @@ <%# -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 -%> <%+cbi/valueheader%> -<textarea rows="<%=select(2, self:cfgvalue(section):gsub('\n', '\n'))%>" - style="outline:none;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> +<div style="font-weight:bold;"> + <%=self:cfgvalue(section):gsub('\n', '<br />' )%> +</div> +<br /> <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://docs.openwrt.melmac.net/vpn-policy-routing/" -%> + <%=translatef("The %s indicates 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 diff --git a/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status-service.htm b/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status-service.htm new file mode 100644 index 0000000000..c453428405 --- /dev/null +++ b/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status-service.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%> diff --git a/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status.htm b/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status.htm index c453428405..4a93564614 100644 --- a/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status.htm +++ b/applications/luci-app-vpn-policy-routing/luasrc/view/vpn-policy-routing/status.htm @@ -1,10 +1,12 @@ <%# -Copyright 2017-2018 Dirk Brenken (dev@brenken.org) +Copyright 2017-2019 Stan Grishin (stangri@melmac.net) 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" /> +<div style="font-weight:bold;"> + <%=self:cfgvalue(section):gsub('\n', '<br />' )%> +</div> <%+cbi/valuefooter%> |