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