Bläddra i källkod

Add luci-app-bcp38 package

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
Toke Høiland-Jørgensen 10 år sedan
förälder
incheckning
27a37bfbf9

+ 57
- 0
net/luci-app-bcp38/Makefile Visa fil

@@ -0,0 +1,57 @@
1
+#
2
+# Copyright (C) 2010 OpenWrt.org
3
+#
4
+# This is free software, licensed under the GNU General Public License v2.
5
+# See /LICENSE for more information.
6
+#
7
+
8
+include $(TOPDIR)/rules.mk
9
+
10
+PKG_NAME:=luci-app-bcp38
11
+PKG_VERSION:=2
12
+PKG_RELEASE:=1
13
+PKG_LICENSE:=Apache-2.0
14
+LUCI_DIR:=/usr/lib/lua/luci
15
+
16
+include $(INCLUDE_DIR)/package.mk
17
+
18
+define Package/luci-app-bcp38
19
+  SECTION:=luci
20
+  CATEGORY:=LuCI
21
+  TITLE:=BCP38 LuCI interface
22
+  MAINTAINER:=Toke Høiland-Jørgensen <toke@toke.dk>
23
+  PKGARCH:=all
24
+  DEPENDS:= lua luci-base +bcp38
25
+  SUBMENU:=3. Applications
26
+endef
27
+
28
+define Package/luci-app-bcp38/description
29
+	Control BCP38 subnet blocking
30
+endef
31
+
32
+define Build/Compile
33
+endef
34
+
35
+define Build/Configure
36
+endef
37
+
38
+define Package/luci-app-bcp38/install
39
+	$(INSTALL_DIR) $(1)$(LUCI_DIR)/controller $(1)$(LUCI_DIR)/model/cbi
40
+	$(INSTALL_DATA) ./files/bcp38-controller.lua $(1)$(LUCI_DIR)/controller/bcp38.lua
41
+	$(INSTALL_DATA) ./files/bcp38-cbi.lua $(1)$(LUCI_DIR)/model/cbi/bcp38.lua
42
+	$(INSTALL_DIR) $(1)/etc/uci-defaults
43
+	$(INSTALL_BIN) ./files/uci-defaults-bcp38 $(1)/etc/uci-defaults/luci-bcp38
44
+endef
45
+
46
+define Package/luci-app-bcp38/postinst
47
+#!/bin/sh
48
+[ -x /etc/uci-defaults/luci-bcp38 ] && /etc/uci-defaults/luci-bcp38 || exit 0
49
+endef
50
+
51
+define Package/luci-app-bcp38/postrm
52
+#!/bin/sh
53
+uci delete ucitrack.@bcp38[0]
54
+uci commit
55
+endef
56
+
57
+$(eval $(call BuildPackage,luci-app-bcp38))

+ 58
- 0
net/luci-app-bcp38/files/bcp38-cbi.lua Visa fil

@@ -0,0 +1,58 @@
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
+
24
+s = m:section(TypedSection, "bcp38", translate("BCP38 config"))
25
+s.anonymous = true
26
+-- BASIC
27
+e = s:option(Flag, "enabled", translate("Enable"))
28
+e.rmempty = false
29
+
30
+a = s:option(Flag, "detect_upstream", translate("Auto-detect upstream IP"),
31
+				translate("Attempt to automatically detect if the upstream IP " ..
32
+					"will be blocked by the configuration, and add an exception if it will. " ..
33
+					"If this does not work correctly, you can add exceptions manually below."))
34
+a.rmempty = false
35
+
36
+n = s:option(ListValue, "interface", translate("Interface name"), translate("Interface to apply the blocking to " ..
37
+							"(should be the upstream WAN interface)."))
38
+for _, iface in ipairs(ifaces) do
39
+     if iface:is_up() then
40
+	n:value(iface:name())
41
+     end
42
+end
43
+n.rmempty = false
44
+
45
+ma = s:option(DynamicList, "match",
46
+	translate("Blocked IP ranges"))
47
+
48
+ma.datatype = "ip4addr"
49
+
50
+nm = s:option(DynamicList, "nomatch",
51
+	translate("Allowed IP ranges"), translate("Takes precedence over blocked ranges. "..
52
+						  "Use to whitelist your upstream network if you're behind a double NAT " ..
53
+						  "and the auto-detection doesn't work."))
54
+
55
+nm.datatype = "ip4addr"
56
+
57
+
58
+return m

+ 7
- 0
net/luci-app-bcp38/files/bcp38-controller.lua Visa fil

@@ -0,0 +1,7 @@
1
+module("luci.controller.bcp38", package.seeall)
2
+
3
+function index()
4
+	entry({"admin", "network", "firewall", "bcp38"},
5
+		cbi("bcp38"),
6
+		_("BCP38"), 50).dependent = false
7
+end

+ 11
- 0
net/luci-app-bcp38/files/uci-defaults-bcp38 Visa fil

@@ -0,0 +1,11 @@
1
+#!/bin/sh
2
+
3
+uci -q batch <<-EOF >/dev/null
4
+	delete ucitrack.@bcp38[-1]
5
+	add ucitrack bcp38
6
+        add_list ucitrack.@bcp38[0].affects=firewall
7
+	commit ucitrack
8
+EOF
9
+
10
+rm -f /tmp/luci-indexcache
11
+exit 0