Merge pull request #1614 from dibdot/adblock
[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 Either \"ifup\" or \"ifdown\"<br />" ..
27         "$INTERFACE Name of the interface which went up or down (e.g. \"wan\" or \"wwan\")<br />" ..
28         "$DEVICE Physical device name which interface went up or down (e.g. \"eth0\" or \"wwan0\")<br />" ..
29         "<br />"))
30
31 t = f:option(TextValue, "lines")
32 t.rmempty = true
33 t.rows = 20
34 function t.cfgvalue()
35         return fs.readfile(script)
36 end
37 function t.write(self, section, data)
38         return fs.writefile(script, ut.trim(data:gsub("\r\n", "\n")) .. "\n")
39 end
40
41 return m5