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