diff --git a/urlfilter/Config.in b/urlfilter/Config.in new file mode 100644 index 000000000..e3492bb57 --- /dev/null +++ b/urlfilter/Config.in @@ -0,0 +1,13 @@ +if PACKAGE_urlfilter + +menu "Configuration" + +config URLFILTER_INCLUDE_BUNDLES + bool "Include default bundle files" + default n + help + Set this option to include bundle files by default, + they are also included in the UCI, urlfilter + still needs to be enabled though. +endmenu +endif diff --git a/urlfilter/Makefile b/urlfilter/Makefile index c9612f616..d0dfc83f6 100644 --- a/urlfilter/Makefile +++ b/urlfilter/Makefile @@ -5,13 +5,13 @@ include $(TOPDIR)/rules.mk PKG_NAME:=urlfilter -PKG_VERSION:=2.0.4 +PKG_VERSION:=3.0.0 LOCAL_DEV:=0 ifneq ($(LOCAL_DEV),1) PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://dev.iopsys.eu/network/urlfilter.git -PKG_SOURCE_VERSION:=2782ec1d3b1bbdfd0a5bd55100bed4c846aafc45 +PKG_SOURCE_VERSION:=c11f0f5bc0f73545cbc791e03b4db3b98a6b2b23 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz PKG_MIRROR_HASH:=skip endif @@ -26,15 +26,22 @@ define Package/urlfilter SECTION:=utils CATEGORY:=Utilities TITLE:=URL filter - DEPENDS:=+libuci +libcurl +libnetfilter-queue +libnfnetlink +iptables-mod-nfqueue +libpthread +libubox +ubus +conntrack + DEPENDS:=+libuci +libnetfilter-queue +libnfnetlink +iptables-mod-nfqueue +libpthread +libubox +ubus +conntrack +libbbfdm-api +libcurl +cmph endef define Package/urlfilter/description Enables filtering of packets on the basis of URL and source MAC address. endef +define Package/$(PKG_NAME)/config + source "$(SOURCE)/Config.in" +endef + TARGET_CFLAGS += \ - -D_GNU_SOURCE + -D_GNU_SOURCE + +TARGET_LDFLAGS += \ + -lcmph ifeq ($(LOCAL_DEV),1) define Build/Prepare @@ -56,12 +63,18 @@ define Package/urlfilter/install $(INSTALL_BIN) ./files/etc/init.d/urlfilter $(1)/etc/init.d/ $(INSTALL_DIR) $(1)/etc/config - $(INSTALL_DATA) ./files/etc/config/parentalcontrol $(1)/etc/config/ + $(INSTALL_DATA) ./files/etc/config/parentalcontrol $(1)/etc/config/parentalcontrol $(INSTALL_DIR) $(1)/etc/uci-defaults $(INSTALL_DATA) ./files/etc/uci-defaults/95-firewall_parentalcontrol.ucidefaults $(1)/etc/uci-defaults/ $(INSTALL_DATA) ./files/etc/uci-defaults/95-migrate_urlfilter.ucidefaults $(1)/etc/uci-defaults/ +ifeq ($(CONFIG_URLFILTER_INCLUDE_BUNDLES),y) + $(INSTALL_DIR) $(1)/etc/urlfilter + $(INSTALL_DATA) ./files/etc/urlfilter/urlbundles.tar.xz $(1)/etc/urlfilter/ +else +endif + $(BBFDM_INSTALL_CORE_PLUGIN) ./files/etc/urlfilter/X_IOPSYS_EU_ParentalControl.json $(1) parental_control endef diff --git a/urlfilter/files/etc/config/parentalcontrol b/urlfilter/files/etc/config/parentalcontrol index 4a865e011..cb4b46b7e 100644 --- a/urlfilter/files/etc/config/parentalcontrol +++ b/urlfilter/files/etc/config/parentalcontrol @@ -1,2 +1,2 @@ -config globals globals +config globals 'globals' option enable 0 diff --git a/urlfilter/files/etc/init.d/urlfilter b/urlfilter/files/etc/init.d/urlfilter index b2aeb88e1..b34a56e1b 100755 --- a/urlfilter/files/etc/init.d/urlfilter +++ b/urlfilter/files/etc/init.d/urlfilter @@ -10,6 +10,8 @@ PROG=/usr/sbin/urlfilter start_service() { if [ "$(uci -q get parentalcontrol.globals.enable)" == "1" ]; then + process_default_bundles + procd_open_instance urlfilter procd_set_param command ${PROG} procd_set_param respawn @@ -30,6 +32,8 @@ start_service() { } stop_service() { + # remove default bundles + remove_default_bundles # remove urlfilter daemon rules remove_iptables_nfqueue_rules # remove internet_access and profile_bedtime_schedule rules diff --git a/urlfilter/files/etc/urlfilter/X_IOPSYS_EU_ParentalControl.json b/urlfilter/files/etc/urlfilter/X_IOPSYS_EU_ParentalControl.json index 075a6df69..f086a16c9 100644 --- a/urlfilter/files/etc/urlfilter/X_IOPSYS_EU_ParentalControl.json +++ b/urlfilter/files/etc/urlfilter/X_IOPSYS_EU_ParentalControl.json @@ -35,6 +35,30 @@ } ] }, + "DefaultBundles": { + "type": "string", + "read": true, + "write": false, + "protocols": [ + "cwmp", + "usp" + ], + "description": "Comma separated list of default bundles", + "list": { + "datatype": "string" + }, + "mapping": [ + { + "type" : "ubus", + "ubus" : { + "object" : "urlfilter", + "method" : "default_bundles", + "args" : {}, + "key" : "default_bundles" + } + } + ] + }, "ProfileNumberOfEntries": { "type": "unsignedInt", "read": true, @@ -417,12 +441,15 @@ "flags": [ "Reference" ], - "description": "Reference to URLBundle which has list of URLs defined based on Category", + "list": { + "datatype": "string" + }, + "description": "Comma separated list of references to URLBundle objects", "mapping": [ { "data": "@Parent", "type": "uci_sec", - "key": "profile_urlbundle", + "list": "profile_urlbundle", "linker_obj": "Device.{BBF_VENDOR_PREFIX}ParentalControl.URLBundle.*.Name" } ] @@ -441,7 +468,7 @@ "list": { "datatype": "string" }, - "description": "Comma separated list of references to the Schedules object", + "description": "Comma separated list of references to the Schedules objects", "mapping": [ { "data": "@Parent", diff --git a/urlfilter/files/etc/urlfilter/urlbundles.tar.xz b/urlfilter/files/etc/urlfilter/urlbundles.tar.xz new file mode 100644 index 000000000..b8a508cb5 Binary files /dev/null and b/urlfilter/files/etc/urlfilter/urlbundles.tar.xz differ diff --git a/urlfilter/files/lib/parentalcontrol/parentalcontrol.sh b/urlfilter/files/lib/parentalcontrol/parentalcontrol.sh index 3cd7ac25b..9555c1bbe 100644 --- a/urlfilter/files/lib/parentalcontrol/parentalcontrol.sh +++ b/urlfilter/files/lib/parentalcontrol/parentalcontrol.sh @@ -13,6 +13,28 @@ IP_RULE="" ACL_FILE="" parentalcontrol_ipv4_forward="" parentalcontrol_ipv6_forward="" +default_bundle_dir="/tmp/urlfilter/default/" +bundle_archive="/etc/urlfilter/urlbundles.tar.xz" + +process_default_bundles() { + if [ -s "$bundle_archive" ]; then + if mkdir -p "$default_bundle_dir"; then + if tar -xJf "$bundle_archive" -C "$default_bundle_dir"; then + logger -t urlfilter "default bundles placed at $default_bundle_dir" + else + logger -t urlfilter "default bundles could not be placed at $default_bundle_dir" + fi + else + logger -t urlfilter "could not create directory: $default_bundle_dir" + fi + else + logger -t urlfilter "default bundles not available" + fi +} + +remove_default_bundles() { + rm -rf "$default_bundle_dir" +} # Function to calculate UTC time and relative day get_relative_day() {