diff options
Diffstat (limited to 'applications/luci-app-mwan3/luasrc')
5 files changed, 86 insertions, 33 deletions
diff --git a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua index ca39c9bf30..c24beda281 100644 --- a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua +++ b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua @@ -29,6 +29,8 @@ function index() entry({"admin", "network", "mwan", "configuration"}, alias("admin", "network", "mwan", "configuration", "interface"), _("Configuration"), 20) + entry({"admin", "network", "mwan", "configuration", "globals"}, + cbi("mwan/globalsconfig"),_("Globals"), 5).leaf = true entry({"admin", "network", "mwan", "configuration", "interface"}, arcombine(cbi("mwan/interface"), cbi("mwan/interfaceconfig")), _("Interfaces"), 10).leaf = true diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/advanced_hotplugscript.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/advanced_hotplugscript.lua index 0e7b8b11d0..1b97080216 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/advanced_hotplugscript.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/advanced_hotplugscript.lua @@ -1,55 +1,40 @@ -- ------ hotplug script configuration ------ -- fs = require "nixio.fs" -sys = require "luci.sys" ut = require "luci.util" -script = "/etc/hotplug.d/iface/16-mwancustom" -scriptBackup = "/etc/hotplug.d/iface/16-mwancustombak" - -if luci.http.formvalue("cbid.luci.1._restorebak") then -- restore button has been clicked - luci.http.redirect(luci.dispatcher.build_url("admin/network/mwan/advanced/hotplugscript") .. "?restore=yes") -elseif luci.http.formvalue("restore") == "yes" then -- restore script from backup - os.execute("cp -f " .. scriptBackup .. " " .. script) -end - +script = "/etc/mwan3.user" m5 = SimpleForm("luci", nil) m5:append(Template("mwan/advanced_hotplugscript")) -- highlight current tab f = m5:section(SimpleSection, nil, - translate("This section allows you to modify the contents of /etc/hotplug.d/iface/16-mwancustom<br />" .. - "This is useful for running system commands and/or scripts based on interface ifup or ifdown hotplug events<br /><br />" .. + translate("This section allows you to modify the content of \"/etc/mwan3.user\".<br />" .. + "The file is also preserved during sysupgrade.<br />" .. + "<br />" .. "Notes:<br />" .. - "The first line of the script must be "#!/bin/sh" without quotes<br />" .. - "Lines beginning with # are comments and are not executed<br /><br />" .. - "Available variables:<br />" .. - "$ACTION is the hotplug event (ifup, ifdown)<br />" .. - "$INTERFACE is the interface name (wan1, wan2, etc.)<br />" .. - "$DEVICE is the device name attached to the interface (eth0.1, eth1, etc.)")) - - -restore = f:option(Button, "_restorebak", translate("Restore default hotplug script")) - restore.inputtitle = translate("Restore...") - restore.inputstyle = "apply" + "This file is interpreted as a shell script.<br />" .. + "The first line of the script must be "#!/bin/sh" without quotes.<br />" .. + "Lines beginning with # are comments and are not executed.<br />" .. + "Put your custom mwan3 action here, they will<br />" .. + "be executed with each netifd hotplug interface event<br />" .. + "on interfaces for which mwan3 is enabled.<br />" .. + "<br />" .. + "There are three main environment variables that are passed to this script.<br />" .. + "<br />" .. + "$ACTION Either \"ifup\" or \"ifdown\"<br />" .. + "$INTERFACE Name of the interface which went up or down (e.g. \"wan\" or \"wwan\")<br />" .. + "$DEVICE Physical device name which interface went up or down (e.g. \"eth0\" or \"wwan0\")<br />" .. + "<br />")) t = f:option(TextValue, "lines") t.rmempty = true t.rows = 20 - function t.cfgvalue() - local hps = fs.readfile(script) - if not hps or hps == "" then -- if script does not exist or is blank restore from backup - sys.call("cp -f " .. scriptBackup .. " " .. script) - return fs.readfile(script) - else - return hps - end + return fs.readfile(script) end - function t.write(self, section, data) -- format and write new data to script return fs.writefile(script, ut.trim(data:gsub("\r\n", "\n")) .. "\n") end - return m5 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua new file mode 100644 index 0000000000..919ed46cd4 --- /dev/null +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua @@ -0,0 +1,40 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2017 Florian Eckert <fe@dev.tdt.de> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- + +local net = require "luci.model.network".init() + +m = Map("mwan3") + +s = m:section(NamedSection, "globals", "globals", translate("Globals mwan3 options")) +n = s:option(ListValue, "local_source", + translate("Local source interface"), + translate("Use the IP address of this interface as source IP address for traffic initiated by the router itself")) +n:value("none") +n.default = "none" +for _, net in ipairs(net:get_networks()) do + if net:name() ~= "loopback" then + n:value(net:name()) + end +end +n.rmempty = false + +mask = s:option( + Value, + "mmx_mask", + translate("Firewall mask"), + translate("Enter value in hex, starting with <code>0x</code>")) +mask.datatype = "hex(4)" +mask.default = "0xff00" + +return m diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua index aeabc63616..c8c122ad48 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua @@ -147,6 +147,16 @@ track_ip = mwan_interface:option(DummyValue, "track_ip", translate("Tracking IP" end end +track_method = mwan_interface:option(DummyValue, "track_method", translate("Tracking method")) + track_method.rawhtml = true + function track_method.cfgvalue(self, s) + if tracked then + return self.map:get(s, "track_method") or "—" + else + return "—" + end + end + reliability = mwan_interface:option(DummyValue, "reliability", translate("Tracking reliability")) reliability.rawhtml = true function reliability.cfgvalue(self, s) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua index 2b46376399..0318091d6c 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua @@ -102,6 +102,12 @@ enabled = mwan_interface:option(ListValue, "enabled", translate("Enabled")) enabled:value("1", translate("Yes")) enabled:value("0", translate("No")) +initial_state = mwan_interface:option(ListValue, "initial_state", translate("Initial state"), + translate("Expect interface state on up event")) + initial_state.default = "online" + initial_state:value("online", translate("Online")) + initial_state:value("offline", translate("Offline")) + family = mwan_interface:option(ListValue, "family", translate("Internet Protocol")) family.default = "ipv4" family:value("ipv4", translate("IPv4")) @@ -111,6 +117,12 @@ track_ip = mwan_interface:option(DynamicList, "track_ip", translate("Tracking ho translate("This hostname or IP address will be pinged to determine if the link is up or down. Leave blank to assume interface is always online")) track_ip.datatype = "host" +track_method = mwan_interface:option(ListValue, "track_method", translate("Tracking method")) + track_method.default = "ping" + track_method:value("ping") + track_method:value("arping") + track_method:value("httping") + reliability = mwan_interface:option(Value, "reliability", translate("Tracking reliability"), translate("Acceptable values: 1-100. This many Tracking IP addresses must respond for the link to be deemed up")) reliability.datatype = "range(1, 100)" @@ -183,6 +195,10 @@ failure = mwan_interface:option(Value, "failure_interval", translate("Failure in failure:value("1800", translatef("%d minutes", 30)) failure:value("3600", translatef("%d hour", 1)) +keep_failure = mwan_interface:option(Flag, "keep_failure_interval", translate("Keep failure interval"), + translate("Keep ping failure interval during failure state")) + keep_failure.default = keep_failure.disabled + recovery = mwan_interface:option(Value, "recovery_interval", translate("Recovery interval"), translate("Ping interval during failure recovering")) recovery.default = "5" |