Merge pull request #980 from NvrBst/pull-request-upnp_description
[project/luci.git] / applications / luci-app-mwan3 / luasrc / model / cbi / mwan / advanced_hotplugscript.lua
1 -- ------ hotplug script configuration ------ --
2
3 fs = require "nixio.fs"
4 ut = require "luci.util"
5
6 script = "/etc/mwan3.user"
7
8 m5 = SimpleForm("luci", nil)
9         m5:append(Template("mwan/advanced_hotplugscript")) -- highlight current tab
10
11 f = m5:section(SimpleSection, nil,
12         translate("This section allows you to modify the content of \"/etc/mwan3.user\".<br />" ..
13         "The file is also preserved during sysupgrade.<br />" ..
14         "<br />" ..
15         "Notes:<br />" ..
16         "This file is interpreted as a shell script.<br />" ..
17         "The first line of the script must be &#34;#!/bin/sh&#34; without quotes.<br />" ..
18         "Lines beginning with # are comments and are not executed.<br />" ..
19         "Put your custom mwan3 action here, they will<br />" ..
20         "be executed with each netifd hotplug interface event<br />" ..
21         "on interfaces for which mwan3 is enabled.<br />" ..
22         "<br />" ..
23         "There are three main environment variables that are passed to this script.<br />" ..
24         "<br />" ..
25         "$ACTION Either \"ifup\" or \"ifdown\"<br />" ..
26         "$INTERFACE Name of the interface which went up or down (e.g. \"wan\" or \"wwan\")<br />" ..
27         "$DEVICE Physical device name which interface went up or down (e.g. \"eth0\" or \"wwan0\")<br />" ..
28         "<br />"))
29
30 t = f:option(TextValue, "lines")
31         t.rmempty = true
32         t.rows = 20
33         function t.cfgvalue()
34                 return fs.readfile(script)
35         end
36         function t.write(self, section, data) -- format and write new data to script
37                 return fs.writefile(script, ut.trim(data:gsub("\r\n", "\n")) .. "\n")
38         end
39
40 return m5