9b53a8a62f83efc05444d2160c0904cba8b36ca2
[project/luci.git] / applications / luci-app-firewall / luasrc / model / cbi / firewall / custom.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14
15 local fs = require "nixio.fs"
16
17 local f = SimpleForm("firewall",
18         translate("Firewall - Custom Rules"),
19         translate("Custom rules allow you to execute arbritary iptables commands \
20                 which are not otherwise covered by the firewall framework. \
21                 The commands are executed after each firewall restart, right after \
22                 the default ruleset has been loaded."))
23
24 local o = f:field(Value, "_custom")
25
26 o.template = "cbi/tvalue"
27 o.rows = 20
28
29 function o.cfgvalue(self, section)
30         return fs.readfile("/etc/firewall.user")
31 end
32
33 function o.write(self, section, value)
34         value = value:gsub("\r\n?", "\n")
35         fs.writefile("/etc/firewall.user", value)
36 end
37
38 return f