luci-app-bcp38: added bcp38 application
[project/luci.git] / applications / luci-app-bcp38 / luasrc / model / cbi / bcp38.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2014 Toke Høiland-Jørgensen <toke@toke.dk>
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 wa = require "luci.tools.webadmin"
16 local net = require "luci.model.network".init()
17 local ifaces = net:get_interfaces()
18
19 m = Map("bcp38", translate("BCP38"),
20         translate("This function blocks packets with private address destinations " ..
21                 "from going out onto the internet as per " ..
22                 "<a href=\"http://tools.ietf.org/html/bcp38\">BCP 38</a>. " ..
23                 "For IPv6, only source specific default routes are installed, so " ..
24                 "no BCP38 firewall routes are needed."))
25
26 s = m:section(TypedSection, "bcp38", translate("BCP38 config"))
27 s.anonymous = true
28 -- BASIC
29 e = s:option(Flag, "enabled", translate("Enable"))
30 e.rmempty = false
31
32 a = s:option(Flag, "detect_upstream", translate("Auto-detect upstream IP"),
33                                 translate("Attempt to automatically detect if the upstream IP " ..
34                                         "will be blocked by the configuration, and add an exception if it will. " ..
35                                         "If this does not work correctly, you can add exceptions manually below."))
36 a.rmempty = false
37
38 n = s:option(ListValue, "interface", translate("Interface name"), translate("Interface to apply the blocking to " ..
39                                                         "(should be the upstream WAN interface)."))
40 for _, iface in ipairs(ifaces) do
41      if iface:is_up() then
42         n:value(iface:name())
43      end
44 end
45 n.rmempty = false
46
47 ma = s:option(DynamicList, "match",
48         translate("Blocked IP ranges"))
49
50 ma.datatype = "ip4addr"
51
52 nm = s:option(DynamicList, "nomatch",
53         translate("Allowed IP ranges"), translate("Takes precedence over blocked ranges. "..
54                                                   "Use to whitelist your upstream network if you're behind a double NAT " ..
55                                                   "and the auto-detection doesn't work."))
56
57 nm.datatype = "ip4addr"
58
59
60 return m