urlfilter: add default bundles and support to read them

This commit is contained in:
Mohd Husaam Mehdi 2024-10-22 13:51:33 +05:30
parent 40bd23290f
commit c088fd5959
7 changed files with 88 additions and 9 deletions

13
urlfilter/Config.in Normal file
View file

@ -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

View file

@ -5,13 +5,13 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=urlfilter PKG_NAME:=urlfilter
PKG_VERSION:=2.0.4 PKG_VERSION:=3.0.0
LOCAL_DEV:=0 LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1) ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/network/urlfilter.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_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip PKG_MIRROR_HASH:=skip
endif endif
@ -26,16 +26,23 @@ define Package/urlfilter
SECTION:=utils SECTION:=utils
CATEGORY:=Utilities CATEGORY:=Utilities
TITLE:=URL filter 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 endef
define Package/urlfilter/description define Package/urlfilter/description
Enables filtering of packets on the basis of URL and source MAC address. Enables filtering of packets on the basis of URL and source MAC address.
endef endef
define Package/$(PKG_NAME)/config
source "$(SOURCE)/Config.in"
endef
TARGET_CFLAGS += \ TARGET_CFLAGS += \
-D_GNU_SOURCE -D_GNU_SOURCE
TARGET_LDFLAGS += \
-lcmph
ifeq ($(LOCAL_DEV),1) ifeq ($(LOCAL_DEV),1)
define Build/Prepare define Build/Prepare
$(CP) -rf ./urlfilter/* $(PKG_BUILD_DIR)/ $(CP) -rf ./urlfilter/* $(PKG_BUILD_DIR)/
@ -56,12 +63,18 @@ define Package/urlfilter/install
$(INSTALL_BIN) ./files/etc/init.d/urlfilter $(1)/etc/init.d/ $(INSTALL_BIN) ./files/etc/init.d/urlfilter $(1)/etc/init.d/
$(INSTALL_DIR) $(1)/etc/config $(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_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-firewall_parentalcontrol.ucidefaults $(1)/etc/uci-defaults/
$(INSTALL_DATA) ./files/etc/uci-defaults/95-migrate_urlfilter.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 $(BBFDM_INSTALL_CORE_PLUGIN) ./files/etc/urlfilter/X_IOPSYS_EU_ParentalControl.json $(1) parental_control
endef endef

View file

@ -1,2 +1,2 @@
config globals globals config globals 'globals'
option enable 0 option enable 0

View file

@ -10,6 +10,8 @@ PROG=/usr/sbin/urlfilter
start_service() { start_service() {
if [ "$(uci -q get parentalcontrol.globals.enable)" == "1" ]; then if [ "$(uci -q get parentalcontrol.globals.enable)" == "1" ]; then
process_default_bundles
procd_open_instance urlfilter procd_open_instance urlfilter
procd_set_param command ${PROG} procd_set_param command ${PROG}
procd_set_param respawn procd_set_param respawn
@ -30,6 +32,8 @@ start_service() {
} }
stop_service() { stop_service() {
# remove default bundles
remove_default_bundles
# remove urlfilter daemon rules # remove urlfilter daemon rules
remove_iptables_nfqueue_rules remove_iptables_nfqueue_rules
# remove internet_access and profile_bedtime_schedule rules # remove internet_access and profile_bedtime_schedule rules

View file

@ -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": { "ProfileNumberOfEntries": {
"type": "unsignedInt", "type": "unsignedInt",
"read": true, "read": true,
@ -417,12 +441,15 @@
"flags": [ "flags": [
"Reference" "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": [ "mapping": [
{ {
"data": "@Parent", "data": "@Parent",
"type": "uci_sec", "type": "uci_sec",
"key": "profile_urlbundle", "list": "profile_urlbundle",
"linker_obj": "Device.{BBF_VENDOR_PREFIX}ParentalControl.URLBundle.*.Name" "linker_obj": "Device.{BBF_VENDOR_PREFIX}ParentalControl.URLBundle.*.Name"
} }
] ]
@ -441,7 +468,7 @@
"list": { "list": {
"datatype": "string" "datatype": "string"
}, },
"description": "Comma separated list of references to the Schedules object", "description": "Comma separated list of references to the Schedules objects",
"mapping": [ "mapping": [
{ {
"data": "@Parent", "data": "@Parent",

Binary file not shown.

View file

@ -13,6 +13,28 @@ IP_RULE=""
ACL_FILE="" ACL_FILE=""
parentalcontrol_ipv4_forward="" parentalcontrol_ipv4_forward=""
parentalcontrol_ipv6_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 # Function to calculate UTC time and relative day
get_relative_day() { get_relative_day() {