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