686d0088cb4270f3af814aec454da5da784d8639
[project/luci.git] / applications / luci-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 chains[rule.chain] = true
24 targets[rule.target] = true
25 end
26
27
28 m = Map("luci_statistics")
29
30 -- collectd_iptables config section
31 s = m:section( NamedSection, "collectd_iptables", "luci_statistics" )
32
33 -- collectd_iptables.enable
34 enable = s:option( Flag, "enable" )
35 enable.default = 0
36
37
38 -- collectd_iptables_match config section (Chain directives)
39 rule = m:section( TypedSection, "collectd_iptables_match" )
40 rule.addremove = true
41 rule.anonymous = true
42
43
44 -- collectd_iptables_match.name
45 rule_table = rule:option( Value, "name" )
46
47 -- collectd_iptables_match.table
48 rule_table = rule:option( ListValue, "table" )
49 rule_table.default = "filter"
50 rule_table.rmempty = true
51 rule_table.optional = true
52 rule_table:value("")
53 rule_table:value("filter")
54 rule_table:value("nat")
55 rule_table:value("mangle")
56
57
58 -- collectd_iptables_match.chain
59 rule_chain = rule:option( ListValue, "chain" )
60 rule_chain.rmempty = true
61 rule_chain.optional = true
62 rule_chain:value("")
63
64 for chain, void in pairs( chains ) do
65 rule_chain:value( chain )
66 end
67
68
69 -- collectd_iptables_match.target
70 rule_target = rule:option( ListValue, "target" )
71 rule_target.rmempty = true
72 rule_target.optional = true
73 rule_target:value("")
74
75 for target, void in pairs( targets ) do
76 rule_target:value( target )
77 end
78
79
80 -- collectd_iptables_match.protocol
81 rule_protocol = rule:option( ListValue, "protocol" )
82 rule_protocol.rmempty = true
83 rule_protocol.optional = true
84 rule_protocol:value("")
85 rule_protocol:value("tcp")
86 rule_protocol:value("udp")
87 rule_protocol:value("icmp")
88
89 -- collectd_iptables_match.source
90 rule_source = rule:option( Value, "source" )
91 rule_source.default = "0.0.0.0/0"
92 rule_source.rmempty = true
93 rule_source.optional = true
94
95 -- collectd_iptables_match.destination
96 rule_destination = rule:option( Value, "destination" )
97 rule_destination.default = "0.0.0.0/0"
98 rule_destination.rmempty = true
99 rule_destination.optional = true
100
101 -- collectd_iptables_match.inputif
102 rule_inputif = rule:option( Value, "inputif" )
103 rule_inputif.rmempty = true
104 rule_inputif.optional = true
105
106 -- collectd_iptables_match.outputif
107 rule_outputif = rule:option( Value, "outputif" )
108 rule_outputif.rmempty = true
109 rule_outputif.optional = true
110
111 -- collectd_iptables_match.options
112 rule_options = rule:option( Value, "options" )
113 rule_options.rmempty = true
114 rule_options.optional = true
115
116 return m