Skip to content

Commit

Permalink
Add luci-app-bcp38 package
Browse files Browse the repository at this point in the history
  • Loading branch information
tohojo committed Mar 20, 2014
1 parent e7b96f2 commit 426a56a
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
64 changes: 64 additions & 0 deletions luci/luci-app-bcp38/Makefile
@@ -0,0 +1,64 @@
#
# Copyright (C) 2010 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-bcp38
PKG_VERSION:=1
PKG_RELEASE:=1
LUCI_DIR:=/usr/lib/lua/luci

include $(INCLUDE_DIR)/package.mk

define Package/luci-app-bcp38
SECTION:=luci
CATEGORY:=LuCI
TITLE:=BCP38 LuCI interface
MAINTAINER:=Toke Høiland-Jørgensen <toke@toke.dk>
PKGARCH:=all
DEPENDS:= lua luci-lib-core +bcp38
SUBMENU:=3. Applications
endef

define Package/luci-app-bcp38/description
Control BCP38 subnet blocking
endef

define Build/Compile
endef

define Build/Configure
endef

define Package/luci-app-bcp38/install
$(INSTALL_DIR) $(1)$(LUCI_DIR)/controller $(1)$(LUCI_DIR)/model/cbi
$(INSTALL_DATA) ./files/bcp38-controller.lua $(1)$(LUCI_DIR)/controller/bcp38.lua
$(INSTALL_DATA) ./files/bcp38-cbi.lua $(1)$(LUCI_DIR)/model/cbi/bcp38.lua
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/uci-defaults-bcp38 $(1)/etc/uci-defaults/luci-bcp38
endef

define Package/luci-app-bcp38/postinst
#!/bin/sh
which uci > /dev/null || exit 0
uci -q get ucitrack.@bcp38[0] > /dev/null || {
uci add ucitrack bcp38 > /dev/null
uci add_list ucitrack.@bcp38[0].affects=firewall
uci commit
}
endef

define Package/luci-app-bcp38/postrm
#!/bin/sh
which uci > /dev/null || exit 0
uci -q get ucitrack.@bcp38[0] > /dev/null && {
uci delete ucitrack.@bcp38[0]
uci commit
}
endef

$(eval $(call BuildPackage,luci-app-bcp38))
44 changes: 44 additions & 0 deletions luci/luci-app-bcp38/files/bcp38-cbi.lua
@@ -0,0 +1,44 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id$
]]--

local wa = require "luci.tools.webadmin"
local fs = require "nixio.fs"
local net = require "luci.model.network".init()
local ifaces = net:get_interfaces()
local path = "/usr/lib/sqm"

m = Map("bcp38", translate("BCP38"),
translate("This function blocks packets with private address destinations " ..
"from going out onto the internet as per " ..
"<abbr title=\"Best Current Practice\">BCP</abbr> 38."))

s = m:section(TypedSection, "bcp38", translate("BCP38 config"))
s.anonymous = true
-- BASIC
e = s:option(Flag, "enabled", translate("Enable"))
e.rmempty = false

ma = s:option(DynamicList, "match",
translate("Blocked IP ranges"))

ma.datatype = "ip4addr"

nm = s:option(DynamicList, "nomatch",
translate("Allowed IP ranges"), translate("Takes precedence over blocked ranges. "..
"Use to whitelist your upstream network if you're behind a double NAT."))

nm.datatype = "ip4addr"


return m
7 changes: 7 additions & 0 deletions luci/luci-app-bcp38/files/bcp38-controller.lua
@@ -0,0 +1,7 @@
module("luci.controller.bcp38", package.seeall)

function index()
entry({"admin", "network", "firewall", "bcp38"},
cbi("bcp38"),
_("BCP38"), 50).dependent = false
end
11 changes: 11 additions & 0 deletions luci/luci-app-bcp38/files/uci-defaults-bcp38
@@ -0,0 +1,11 @@
#!/bin/sh

uci -q batch <<-EOF >/dev/null
delete ucitrack.@bcp38[-1]
add ucitrack bcp38
add_list ucitrack.@bcp38[0].affects=firewall
commit ucitrack
EOF

rm -f /tmp/luci-indexcache
exit 0

0 comments on commit 426a56a

Please sign in to comment.