notify.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. local fs = require "nixio.fs"
  5. local ut = require "luci.util"
  6. script = "/etc/mwan3.user"
  7. m5 = SimpleForm("luci", translate("MWAN - Notification"))
  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 <br />" ..
  23. "* \"ifup\" Is called by netifd and mwan3track <br />" ..
  24. "* \"ifdown\" Is called by netifd and mwan3track <br />" ..
  25. "* \"connected\" Is only called by mwan3track if tracking was successful <br />" ..
  26. "* \"disconnected\" Is only called by mwan3track if tracking has failed <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. 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)
  37. return fs.writefile(script, ut.trim(data:gsub("\r\n", "\n")) .. "\n")
  38. end
  39. return m5