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