luci-app-mwan3: change hotplug script to mwan3.user
Replace old "/etc/hotplug.d/iface/16-mwancustom" edit possibility with the new "/etc/mwan3.user" hotplug script. Which will also be saved during sysupgrade. Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
parent
3d338ee3e6
commit
10992d6b10
1 changed files with 18 additions and 33 deletions
|
@ -1,55 +1,40 @@
|
||||||
-- ------ hotplug script configuration ------ --
|
-- ------ hotplug script configuration ------ --
|
||||||
|
|
||||||
fs = require "nixio.fs"
|
fs = require "nixio.fs"
|
||||||
sys = require "luci.sys"
|
|
||||||
ut = require "luci.util"
|
ut = require "luci.util"
|
||||||
|
|
||||||
script = "/etc/hotplug.d/iface/16-mwancustom"
|
script = "/etc/mwan3.user"
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
m5 = SimpleForm("luci", nil)
|
m5 = SimpleForm("luci", nil)
|
||||||
m5:append(Template("mwan/advanced_hotplugscript")) -- highlight current tab
|
m5:append(Template("mwan/advanced_hotplugscript")) -- highlight current tab
|
||||||
|
|
||||||
f = m5:section(SimpleSection, nil,
|
f = m5:section(SimpleSection, nil,
|
||||||
translate("This section allows you to modify the contents of /etc/hotplug.d/iface/16-mwancustom<br />" ..
|
translate("This section allows you to modify the content of \"/etc/mwan3.user\".<br />" ..
|
||||||
"This is useful for running system commands and/or scripts based on interface ifup or ifdown hotplug events<br /><br />" ..
|
"The file is also preserved during sysupgrade.<br />" ..
|
||||||
|
"<br />" ..
|
||||||
"Notes:<br />" ..
|
"Notes:<br />" ..
|
||||||
"The first line of the script must be "#!/bin/sh" without quotes<br />" ..
|
"This file is interpreted as a shell script.<br />" ..
|
||||||
"Lines beginning with # are comments and are not executed<br /><br />" ..
|
"The first line of the script must be "#!/bin/sh" without quotes.<br />" ..
|
||||||
"Available variables:<br />" ..
|
"Lines beginning with # are comments and are not executed.<br />" ..
|
||||||
"$ACTION is the hotplug event (ifup, ifdown)<br />" ..
|
"Put your custom mwan3 action here, they will<br />" ..
|
||||||
"$INTERFACE is the interface name (wan1, wan2, etc.)<br />" ..
|
"be executed with each netifd hotplug interface event<br />" ..
|
||||||
"$DEVICE is the device name attached to the interface (eth0.1, eth1, etc.)"))
|
"on interfaces for which mwan3 is enabled.<br />" ..
|
||||||
|
"<br />" ..
|
||||||
|
"There are three main environment variables that are passed to this script.<br />" ..
|
||||||
restore = f:option(Button, "_restorebak", translate("Restore default hotplug script"))
|
"<br />" ..
|
||||||
restore.inputtitle = translate("Restore...")
|
"$ACTION Either \"ifup\" or \"ifdown\"<br />" ..
|
||||||
restore.inputstyle = "apply"
|
"$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 = f:option(TextValue, "lines")
|
||||||
t.rmempty = true
|
t.rmempty = true
|
||||||
t.rows = 20
|
t.rows = 20
|
||||||
|
|
||||||
function t.cfgvalue()
|
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)
|
return fs.readfile(script)
|
||||||
else
|
|
||||||
return hps
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function t.write(self, section, data) -- format and write new data to script
|
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")
|
return fs.writefile(script, ut.trim(data:gsub("\r\n", "\n")) .. "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return m5
|
return m5
|
||||||
|
|
Loading…
Reference in a new issue