Merge pull request #1818 from dibdot/lxc_fix
[project/luci.git] / applications / luci-app-mwan3 / luasrc / model / cbi / mwan / notify.lua
1 -- Copyright 2014 Aedan Renner <chipdankly@gmail.com>
2 -- Copyright 2018 Florian Eckert <fe@dev.tdt.de>
3 -- Licensed to the public under the GNU General Public License v2.
4
5 local fs = require "nixio.fs"
6 local ut = require "luci.util"
7 script = "/etc/mwan3.user"
8
9
10 m5 = SimpleForm("luci", translate("MWAN - Notification"))
11
12 f = m5:section(SimpleSection, nil,
13         translate("This section allows you to modify the content of \"/etc/mwan3.user\".<br />" ..
14         "The file is also preserved during sysupgrade.<br />" ..
15         "<br />" ..
16         "Notes:<br />" ..
17         "This file is interpreted as a shell script.<br />" ..
18         "The first line of the script must be &#34;#!/bin/sh&#34; without quotes.<br />" ..
19         "Lines beginning with # are comments and are not executed.<br />" ..
20         "Put your custom mwan3 action here, they will<br />" ..
21         "be executed with each netifd hotplug interface event<br />" ..
22         "on interfaces for which mwan3 is enabled.<br />" ..
23         "<br />" ..
24         "There are three main environment variables that are passed to this script.<br />" ..
25         "<br />" ..
26         "$ACTION <br />" ..
27         "* \"ifup\" Is called by netifd and mwan3track <br />" ..
28         "* \"ifdown\" Is called by netifd and mwan3track <br />" ..
29         "* \"connected\" Is only called by mwan3track if tracking was successful <br />" ..
30         "* \"disconnected\" Is only called by mwan3track if tracking has failed <br />" ..
31         "$INTERFACE Name of the interface which went up or down (e.g. \"wan\" or \"wwan\")<br />" ..
32         "$DEVICE Physical device name which interface went up or down (e.g. \"eth0\" or \"wwan0\")<br />" ..
33         "<br />"))
34
35 t = f:option(TextValue, "lines")
36 t.rmempty = true
37 t.rows = 20
38 function t.cfgvalue()
39         return fs.readfile(script)
40 end
41 function t.write(self, section, data)
42         return fs.writefile(script, ut.trim(data:gsub("\r\n", "\n")) .. "\n")
43 end
44
45 return m5