Changeset 8117
- Timestamp:
- 12/20/11 04:14:54 (17 months ago)
- Location:
- luci/trunk/applications/luci-firewall/luasrc
- Files:
-
- 5 modified
-
model/cbi/firewall/forward-details.lua (modified) (4 diffs)
-
model/cbi/firewall/forwards.lua (modified) (3 diffs)
-
model/cbi/firewall/rule-details.lua (modified) (6 diffs)
-
model/cbi/firewall/rules.lua (modified) (7 diffs)
-
tools/firewall.lua (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
luci/trunk/applications/luci-firewall/luasrc/model/cbi/firewall/forward-details.lua
r8108 r8117 15 15 local sys = require "luci.sys" 16 16 local dsp = require "luci.dispatcher" 17 local ft = require "luci.tools.firewall" 18 19 local m, s, o 17 20 18 21 arg[1] = arg[1] or "" … … 30 33 return 31 34 else 32 local name = m:get(arg[1], " _name")35 local name = m:get(arg[1], "name") or m:get(arg[1], "_name") 33 36 if not name or #name == 0 then 34 37 name = translate("(Unnamed Entry)") … … 57 60 s.addremove = false 58 61 59 s:tab("general", translate("General Settings"))60 s:tab("advanced", translate("Advanced Settings"))62 ft.opt_enabled(s, Button) 63 ft.opt_name(s, Value, translate("Name")) 61 64 62 name = s:taboption("general", Value, "_name", translate("Name"))63 name.rmempty = true64 name.size = 1065 65 66 src = s:taboption("advanced", Value, "src", translate("Source zone")) 67 src.nocreate = true 68 src.default = "wan" 69 src.template = "cbi/firewall_zonelist" 66 o = s:option(Value, "proto", translate("Protocol")) 67 o:value("tcp udp", "TCP+UDP") 68 o:value("tcp", "TCP") 69 o:value("udp", "UDP") 70 o:value("icmp", "ICMP") 70 71 71 proto = s:taboption("general", Value, "proto", translate("Protocol")) 72 proto.optional = true 73 proto:value("tcp udp", "TCP+UDP") 74 proto:value("tcp", "TCP") 75 proto:value("udp", "UDP") 76 proto:value("icmp", "ICMP") 77 78 function proto.cfgvalue(...) 72 function o.cfgvalue(...) 79 73 local v = Value.cfgvalue(...) 80 74 if not v or v == "tcpudp" then … … 84 78 end 85 79 86 dport = s:taboption("general", Value, "src_dport", translate("External port"), 80 81 o = s:option(Value, "src", translate("Source zone")) 82 o.nocreate = true 83 o.default = "wan" 84 o.template = "cbi/firewall_zonelist" 85 86 87 o = s:option(DynamicList, "src_mac", 88 translate("Source MAC address"), 89 translate("Only match incoming traffic from these MACs.")) 90 o.rmempty = true 91 o.datatype = "macaddr" 92 o.placeholder = translate("any") 93 94 95 o = s:option(Value, "src_ip", 96 translate("Source IP address"), 97 translate("Only match incoming traffic from this IP or range.")) 98 o.rmempty = true 99 o.datatype = "neg(ip4addr)" 100 o.placeholder = translate("any") 101 102 103 o = s:option(Value, "src_port", 104 translate("Source port"), 105 translate("Only match incoming traffic originating from the given source port or port range on the client host")) 106 o.rmempty = true 107 o.datatype = "portrange" 108 o.placeholder = translate("any") 109 110 111 o = s:option(Value, "src_dip", 112 translate("External IP address"), 113 translate("Only match incoming traffic directed at the given IP address.")) 114 115 o.rmempty = true 116 o.datatype = "ip4addr" 117 o.placeholder = translate("any") 118 119 120 o = s:option(Value, "src_dport", translate("External port"), 87 121 translate("Match incoming traffic directed at the given " .. 88 122 "destination port or port range on this host")) 89 dport.datatype = "portrange"123 o.datatype = "portrange" 90 124 91 to = s:taboption("general", Value, "dest_ip", translate("Internal IP address"), 92 translate("Redirect matched incoming traffic to the specified " .. 93 "internal host")) 94 to.datatype = "ip4addr" 125 126 127 o = s:option(Value, "dest", translate("Internal zone")) 128 o.nocreate = true 129 o.default = "lan" 130 o.template = "cbi/firewall_zonelist" 131 132 133 o = s:option(Value, "dest_ip", translate("Internal IP address"), 134 translate("Redirect matched incoming traffic to the specified \ 135 internal host")) 136 o.datatype = "ip4addr" 95 137 for i, dataset in ipairs(sys.net.arptable()) do 96 to:value(dataset["IP address"])138 o:value(dataset["IP address"]) 97 139 end 98 140 99 toport = s:taboption("general", Value, "dest_port", translate("Internal port (optional)"),100 translate("Redirect matched incoming traffic to the given port on " ..101 "the internal host"))102 toport.optional = true103 toport.placeholder = "0-65535"104 toport.datatype = "portrange"105 141 106 dest = s:taboption("advanced", Value, "dest", translate("Destination zone")) 107 dest.nocreate = true 108 dest.default = "lan" 109 dest.template = "cbi/firewall_zonelist" 142 o = s:option(Value, "dest_port", 143 translate("Internal port"), 144 translate("Redirect matched incoming traffic to the given port on \ 145 the internal host")) 146 o.placeholder = translate("any") 147 o.datatype = "portrange" 110 148 111 src_dip = s:taboption("advanced", Value, "src_dip",112 translate("Intended destination address"),113 translate("Only match incoming traffic directed at the given IP address."))114 149 115 src_dip.optional = true 116 src_dip.datatype = "ip4addr" 117 src_dip.placeholder = translate("any") 118 119 src_mac = s:taboption("advanced", DynamicList, "src_mac", 120 translate("Source MAC address"), 121 translate("Only match incoming traffic from these MACs.")) 122 src_mac.optional = true 123 src_mac.datatype = "macaddr" 124 src_mac.placeholder = translate("any") 125 126 src_ip = s:taboption("advanced", Value, "src_ip", 127 translate("Source IP address"), 128 translate("Only match incoming traffic from this IP or range.")) 129 src_ip.optional = true 130 src_ip.datatype = "neg(ip4addr)" 131 src_ip.placeholder = translate("any") 132 133 sport = s:taboption("advanced", Value, "src_port", 134 translate("Source port"), 135 translate("Only match incoming traffic originating from the given source port or port range on the client host")) 136 sport.optional = true 137 sport.datatype = "portrange" 138 sport.placeholder = translate("any") 139 140 reflection = s:taboption("advanced", Flag, "reflection", translate("Enable NAT Loopback")) 141 reflection.rmempty = true 142 reflection.default = reflection.enabled 143 reflection:depends({ target = "DNAT", src = wan_zone }) 144 reflection.cfgvalue = function(...) 150 o = s:option(Flag, "reflection", translate("Enable NAT Loopback")) 151 o.rmempty = true 152 o.default = o.enabled 153 o:depends("src", wan_zone) 154 o.cfgvalue = function(...) 145 155 return Flag.cfgvalue(...) or "1" 146 156 end 147 157 158 159 s:option(Value, "extra", 160 translate("Extra arguments"), 161 translate("Passes additional arguments to iptables. Use with care!")) 162 163 148 164 return m -
luci/trunk/applications/luci-firewall/luasrc/model/cbi/firewall/forwards.lua
r8112 r8117 50 50 self.map:set(created, "dest_ip", a) 51 51 self.map:set(created, "dest_port", i) 52 self.map:set(created, " _name",n)52 self.map:set(created, "name", n) 53 53 end 54 54 … … 72 72 end 73 73 74 name = s:option(DummyValue, "_name", translate("Name")) 75 function name.cfgvalue(self, s) 76 return self.map:get(s, "_name") or "-" 77 end 74 75 ft.opt_name(s, DummyValue, translate("Name")) 76 78 77 79 78 proto = s:option(DummyValue, "proto", translate("Protocol")) … … 132 131 end 133 132 133 ft.opt_enabled(s, Flag, translate("Enable")).width = "1%" 134 134 135 return m -
luci/trunk/applications/luci-firewall/luasrc/model/cbi/firewall/rule-details.lua
r8108 r8117 18 18 local nxo = require "nixio" 19 19 20 local ft = require "luci.tools.firewall" 20 21 local nw = require "luci.model.network" 21 22 local m, s, o, k, v … … 47 48 elseif rule_type == "redirect" then 48 49 49 local name = m:get(arg[1], " _name")50 local name = m:get(arg[1], "name") or m:get(arg[1], "_name") 50 51 if not name or #name == 0 then 51 52 name = translate("(Unnamed SNAT)") … … 77 78 78 79 79 o = s:option(Value, "_name", translate("Name")) 80 o.rmempty = true 81 o.size = 10 80 ft.opt_enabled(s, Button) 81 ft.opt_name(s, Value, translate("Name")) 82 82 83 83 … … 116 116 o = s:option(Value, "src_ip", translate("Source IP address")) 117 117 o.rmempty = true 118 o.datatype = "neg(ip 4addr)"118 o.datatype = "neg(ipaddr)" 119 119 o.placeholder = translate("any") 120 120 … … 177 177 178 178 179 s:option(Value, "extra", 180 translate("Extra arguments"), 181 translate("Passes additional arguments to iptables. Use with care!")) 182 183 179 184 -- 180 185 -- Rule 181 186 -- 182 187 else 188 local name = m:get(arg[1], "name") or m:get(arg[1], "_name") 189 if not name or #name == 0 then 190 name = translate("(Unnamed Rule)") 191 end 192 193 m.title = "%s - %s" %{ translate("Firewall - Traffic Rules"), name } 194 195 183 196 s = m:section(NamedSection, arg[1], "rule", "") 184 197 s.anonymous = true 185 198 s.addremove = false 186 199 187 s:option(Value, "_name", translate("Name").." "..translate("(optional)")) 200 ft.opt_enabled(s, Button) 201 ft.opt_name(s, Value, translate("Name")) 188 202 189 203 … … 296 310 o:value("REJECT", translate("reject")) 297 311 o:value("NOTRACK", translate("don't track")) 312 313 314 s:option(Value, "extra", 315 translate("Extra arguments"), 316 translate("Passes additional arguments to iptables. Use with care!")) 298 317 end 299 318 -
luci/trunk/applications/luci-firewall/luasrc/model/cbi/firewall/rules.lua
r8112 r8117 60 60 self.map:set(created, "proto", (i_p ~= "other") and i_p or "all") 61 61 self.map:set(created, "dest_port", i_e) 62 self.map:set(created, " _name",i_n)62 self.map:set(created, "name", i_n) 63 63 64 64 if i_p ~= "other" and i_e and #i_e > 0 then … … 72 72 self.map:set(created, "src", f_s) 73 73 self.map:set(created, "dest", f_d) 74 self.map:set(created, " _name",f_n)74 self.map:set(created, "name", f_n) 75 75 end 76 76 … … 83 83 end 84 84 85 name = s:option(DummyValue, "_name", translate("Name")) 86 function name.cfgvalue(self, s) 87 return self.map:get(s, "_name") or "-" 88 end 85 ft.opt_name(s, DummyValue, translate("Name")) 89 86 90 87 family = s:option(DummyValue, "family", translate("Family")) … … 170 167 end 171 168 end 169 170 ft.opt_enabled(s, Flag, translate("Enable")).width = "1%" 172 171 173 172 … … 211 210 self.map:set(created, "src_dip", a) 212 211 self.map:set(created, "src_dport", p) 213 self.map:set(created, " _name",n)212 self.map:set(created, "name", n) 214 213 end 215 214 … … 226 225 end 227 226 228 name = s:option(DummyValue, "_name", translate("Name")) 229 function name.cfgvalue(self, s) 230 return self.map:get(s, "_name") or "-" 231 end 227 ft.opt_name(s, DummyValue, translate("Name")) 232 228 233 229 proto = s:option(DummyValue, "proto", translate("Protocol")) … … 286 282 end 287 283 284 ft.opt_enabled(s, Flag, translate("Enable")).width = "1%" 285 288 286 289 287 return m -
luci/trunk/applications/luci-firewall/luasrc/tools/firewall.lua
r8112 r8117 228 228 end 229 229 end 230 231 232 function opt_enabled(s, t, ...) 233 if t == luci.cbi.Button then 234 local o = s:option(t, "__enabled") 235 function o.render(self, section) 236 if self.map:get(section, "enabled") ~= "0" then 237 self.title = translate("Rule is enabled") 238 self.inputtitle = translate("Disable") 239 self.inputstyle = "reset" 240 else 241 self.title = translate("Rule is disabled") 242 self.inputtitle = translate("Enable") 243 self.inputstyle = "apply" 244 end 245 t.render(self, section) 246 end 247 function o.write(self, section, value) 248 if self.map:get(section, "enabled") ~= "0" then 249 self.map:set(section, "enabled", "0") 250 else 251 self.map:del(section, "enabled") 252 end 253 end 254 return o 255 else 256 local o = s:option(t, "enabled", ...) 257 o.enabled = "" 258 o.disabled = "0" 259 o.default = o.enabled 260 return o 261 end 262 end 263 264 function opt_name(s, t, ...) 265 local o = s:option(t, "name", ...) 266 267 function o.cfgvalue(self, section) 268 return self.map:get(section, "name") or 269 self.map:get(section, "_name") or "-" 270 end 271 272 function o.write(self, section, value) 273 if value ~= "-" then 274 self.map:set(section, "name", value) 275 self.map:del(section, "_name") 276 else 277 self:remove(section) 278 end 279 end 280 281 function o.remove(self, section) 282 self.map:del(section, "name") 283 self.map:del(section, "_name") 284 end 285 286 return o 287 end
