custom.lua 962 B

12345678910111213141516171819202122232425262728293031
  1. -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local fs = require "nixio.fs"
  4. local f = SimpleForm("firewall",
  5. translate("Firewall - Custom Rules"),
  6. translate("Custom rules allow you to execute arbitrary iptables commands \
  7. which are not otherwise covered by the firewall framework. \
  8. The commands are executed after each firewall restart, right after \
  9. the default ruleset has been loaded."))
  10. local o = f:field(Value, "_custom")
  11. o.template = "cbi/tvalue"
  12. o.rows = 20
  13. function o.cfgvalue(self, section)
  14. return fs.readfile("/etc/firewall.user")
  15. end
  16. function o.write(self, section, value)
  17. value = value:gsub("\r\n?", "\n")
  18. fs.writefile("/etc/firewall.user", value)
  19. require("luci.sys").call("/etc/init.d/firewall restart >/dev/null 2<&1")
  20. require("nixio").syslog('info', 'Restarting firewall on custom /etc/firewall.user change')
  21. end
  22. f.submit = translate("Restart Firewall")
  23. return f