Rework LuCI build system
[project/luci.git] / applications / luci-app-statistics / luasrc / model / cbi / luci_statistics / iptables.lua
1 --[[
2
3 Luci configuration model for statistics - collectd iptables plugin configuration
4 (c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
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
16 require("luci.sys.iptparser")
17
18 ip = luci.sys.iptparser.IptParser()
19 chains  = { }
20 targets = { }
21
22 for i, rule in ipairs( ip:find() ) do 
23         if rule.chain and rule.target then
24                 chains[rule.chain] = true
25                 targets[rule.target] = true
26         end
27 end
28
29
30 m = Map("luci_statistics",
31         translate("Iptables Plugin Configuration"),
32         translate(
33                 "The iptables plugin will monitor selected firewall rules and " ..
34                 "collect informations about processed bytes and packets per rule."
35         ))
36
37 -- collectd_iptables config section
38 s = m:section( NamedSection, "collectd_iptables", "luci_statistics" )
39
40 -- collectd_iptables.enable
41 enable = s:option( Flag, "enable", translate("Enable this plugin") )
42 enable.default = 0
43
44
45 -- collectd_iptables_match config section (Chain directives)
46 rule = m:section( TypedSection, "collectd_iptables_match",
47         translate("Add matching rule"),
48         translate(
49                 "Here you can define various criteria by which the monitored " ..
50                 "iptables rules are selected."
51         ))
52 rule.addremove = true
53 rule.anonymous = true
54
55
56 -- collectd_iptables_match.name
57 rule_table = rule:option( Value, "name",
58         translate("Name of the rule"), translate("max. 16 chars") )
59
60 -- collectd_iptables_match.table
61 rule_table = rule:option( ListValue, "table", translate("Table") )
62 rule_table.default  = "filter"
63 rule_table.rmempty  = true
64 rule_table.optional = true
65 rule_table:value("")
66 rule_table:value("filter")
67 rule_table:value("nat")
68 rule_table:value("mangle")
69
70
71 -- collectd_iptables_match.chain
72 rule_chain = rule:option( ListValue, "chain", translate("Chain") )
73 rule_chain.rmempty  = true
74 rule_chain.optional = true
75 rule_chain:value("")
76
77 for chain, void in pairs( chains ) do
78         rule_chain:value( chain )
79 end
80
81
82 -- collectd_iptables_match.target
83 rule_target = rule:option( ListValue, "target", translate("Action (target)") )
84 rule_target.rmempty  = true
85 rule_target.optional = true
86 rule_target:value("")
87
88 for target, void in pairs( targets ) do
89         rule_target:value( target )
90 end
91
92
93 -- collectd_iptables_match.protocol
94 rule_protocol = rule:option( ListValue, "protocol", translate("Network protocol") )
95 rule_protocol.rmempty  = true
96 rule_protocol.optional = true
97 rule_protocol:value("")
98 rule_protocol:value("tcp")
99 rule_protocol:value("udp")
100 rule_protocol:value("icmp")
101
102 -- collectd_iptables_match.source
103 rule_source = rule:option( Value, "source", translate("Source ip range") )
104 rule_source.default  = "0.0.0.0/0"
105 rule_source.rmempty  = true
106 rule_source.optional = true
107
108 -- collectd_iptables_match.destination
109 rule_destination = rule:option( Value, "destination", translate("Destination ip range") )
110 rule_destination.default  = "0.0.0.0/0"
111 rule_destination.rmempty  = true
112 rule_destination.optional = true
113
114 -- collectd_iptables_match.inputif
115 rule_inputif = rule:option( Value, "inputif",
116         translate("Incoming interface"), translate("e.g. br-lan") )
117 rule_inputif.rmempty  = true
118 rule_inputif.optional = true
119
120 -- collectd_iptables_match.outputif
121 rule_outputif = rule:option( Value, "outputif",
122         translate("Outgoing interface"), translate("e.g. br-ff") )
123 rule_outputif.rmempty  = true
124 rule_outputif.optional = true
125
126 -- collectd_iptables_match.options
127 rule_options = rule:option( Value, "options",
128         translate("Options"), translate("e.g. reject-with tcp-reset") )
129 rule_options.rmempty  = true
130 rule_options.optional = true
131
132 return m