From d13040ed0ecd30f2a6500edd18f190427d16cffe Mon Sep 17 00:00:00 2001 From: Vivek Kumar Dutta Date: Mon, 8 Dec 2025 11:06:16 +0530 Subject: [PATCH 1/2] parental-control: read urlbundle definition from json --- parental-control/Makefile | 10 +-- .../etc/parentalcontrol/url_bundles.json | 76 +++++++++++++++++++ .../parentalcontrol}/urlbundle_override.json | 0 .../50-parental_control_add_bundles | 43 ----------- .../files/lib/parentalcontrol/sync_bundles.sh | 29 ++++--- 5 files changed, 95 insertions(+), 63 deletions(-) create mode 100644 parental-control/files/etc/parentalcontrol/url_bundles.json rename parental-control/files/{ => etc/parentalcontrol}/urlbundle_override.json (100%) delete mode 100644 parental-control/files/etc/uci-defaults/50-parental_control_add_bundles diff --git a/parental-control/Makefile b/parental-control/Makefile index 258005409..121f91956 100644 --- a/parental-control/Makefile +++ b/parental-control/Makefile @@ -5,13 +5,13 @@ include $(TOPDIR)/rules.mk PKG_NAME:=parental-control -PKG_VERSION:=1.4.4 +PKG_VERSION:=1.4.5 LOCAL_DEV:=0 ifneq ($(LOCAL_DEV),1) PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://dev.iopsys.eu/network/parental-control.git -PKG_SOURCE_VERSION:=d0eabdda9790d1df3cec30589c97214731108367 +PKG_SOURCE_VERSION:=0aa48d99ff0e45111bc27f78df35159252164a78 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz PKG_MIRROR_HASH:=skip endif @@ -27,7 +27,7 @@ define Package/parental-control CATEGORY:=Utilities TITLE:=URL filter DEPENDS:=+libuci +libnetfilter-queue +libnfnetlink +iptables-mod-nfqueue +libpthread - DEPENDS+=+libubox +ubus +conntrack +libcurl +cmph + DEPENDS+=+libubox +ubus +conntrack +libcurl +cmph +libjson-c DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service endef @@ -87,8 +87,8 @@ define Package/parental-control/install $(INSTALL_DATA) ./files/etc/uci-defaults/40-parental_control_update_bundle_path $(1)/etc/uci-defaults/ ifeq ($(CONFIG_PARENTAL_CONTROL_URLFILTERING),y) - $(INSTALL_DATA) ./files/etc/uci-defaults/50-parental_control_add_bundles $(1)/etc/uci-defaults/ - $(CP) ./files/urlbundle_override.json $(1)/etc/parentalcontrol/ + $(INSTALL_DATA) ./files/etc/parentalcontrol/url_bundles.json $(1)/etc/parentalcontrol/ + $(INSTALL_DATA) ./files/etc/parentalcontrol/urlbundle_override.json $(1)/etc/parentalcontrol/ else $(BBFDM_INSTALL_MS_PLUGIN) -v ${VENDOR_PREFIX} ./files/urlbundle_override.json $(1) parentalcontrol $(INSTALL_DATA) ./files/etc/uci-defaults/50-parental_control_disable_urlfilter $(1)/etc/uci-defaults/ diff --git a/parental-control/files/etc/parentalcontrol/url_bundles.json b/parental-control/files/etc/parentalcontrol/url_bundles.json new file mode 100644 index 000000000..b54e681cf --- /dev/null +++ b/parental-control/files/etc/parentalcontrol/url_bundles.json @@ -0,0 +1,76 @@ +{ + "urlBundles": [ + { + "url": "https://blocklistproject.github.io/Lists/alt-version/abuse-nl.txt", + "name": "Abuse" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/ads-nl.txt", + "name": "Ads" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/crypto-nl.txt", + "name": "Crypto" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/drugs-nl.txt", + "name": "Drugs" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/everything-nl.txt", + "name": "Everything else" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/facebook-nl.txt", + "name": "Facebook/Instagram" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/fraud-nl.txt", + "name": "Fraud" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/gambling-nl.txt", + "name": "Gambling" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/malware-nl.txt", + "name": "Malware" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/phishing-nl.txt", + "name": "Phishing" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/piracy-nl.txt", + "name": "Piracy" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/porn-nl.txt", + "name": "Porn" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/ransomware-nl.txt", + "name": "Ransomware" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/redirect-nl.txt", + "name": "Redirect" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/scam-nl.txt", + "name": "Scam" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/tiktok-nl.txt", + "name": "TikTok" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/torrent-nl.txt", + "name": "Torrent" + }, + { + "url": "https://blocklistproject.github.io/Lists/alt-version/tracking-nl.txt", + "name": "Tracking" + } + ] +} diff --git a/parental-control/files/urlbundle_override.json b/parental-control/files/etc/parentalcontrol/urlbundle_override.json similarity index 100% rename from parental-control/files/urlbundle_override.json rename to parental-control/files/etc/parentalcontrol/urlbundle_override.json diff --git a/parental-control/files/etc/uci-defaults/50-parental_control_add_bundles b/parental-control/files/etc/uci-defaults/50-parental_control_add_bundles deleted file mode 100644 index dcbe1bab5..000000000 --- a/parental-control/files/etc/uci-defaults/50-parental_control_add_bundles +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -[ ! -f "/etc/config/parentalcontrol" ] && exit 0 - -COUNT=1 - -add_urlbundle() -{ - local name url - - url="${1}"; shift - name="$*" - - uci -q set parentalcontrol.urlbundle_${COUNT}=urlbundle - uci -q set parentalcontrol.urlbundle_${COUNT}.name="${name}" - uci -q set parentalcontrol.urlbundle_${COUNT}.download_url="${url}" - - COUNT="$((COUNT+1))" -} - -urlfilter="$(uci -q get parentalcontrol.globals.urlfilter)" -if [ "${urlfilter}" -eq "1" ]; then - add_urlbundle "https://blocklistproject.github.io/Lists/alt-version/abuse-nl.txt" "Abuse" - add_urlbundle "https://blocklistproject.github.io/Lists/alt-version/ads-nl.txt" "Ads" - add_urlbundle "https://blocklistproject.github.io/Lists/alt-version/crypto-nl.txt" "Crypto" - add_urlbundle "https://blocklistproject.github.io/Lists/alt-version/drugs-nl.txt" "Drugs" - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/everything-nl.txt' "Everything else" - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/facebook-nl.txt' 'Facebook/Instagram' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/fraud-nl.txt' 'Fraud' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/gambling-nl.txt' 'Gambling' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/malware-nl.txt' 'Malware' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/phishing-nl.txt' 'Phishing' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/piracy-nl.txt' 'Piracy' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/porn-nl.txt' 'Porn' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/ransomware-nl.txt' 'Ransomware' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/redirect-nl.txt' 'Redirect' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/scam-nl.txt' 'Scam' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/tiktok-nl.txt' 'TikTok' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/torrent-nl.txt' 'Torrent' - add_urlbundle 'https://blocklistproject.github.io/Lists/alt-version/tracking-nl.txt' 'Tracking' -fi - -exit 0 diff --git a/parental-control/files/lib/parentalcontrol/sync_bundles.sh b/parental-control/files/lib/parentalcontrol/sync_bundles.sh index a04ad95ca..03562e4c6 100644 --- a/parental-control/files/lib/parentalcontrol/sync_bundles.sh +++ b/parental-control/files/lib/parentalcontrol/sync_bundles.sh @@ -1,10 +1,12 @@ #!/bin/sh . /lib/functions.sh +. /usr/share/libubox/jshn.sh LOCKFILE="/tmp/sync_bundles.lock" log_level="$(uci -q get parentalcontrol.globals.loglevel)" log_level="${log_level:-1}" +URLBUNDLE_JSON="/etc/parentalcontrol/url_bundles.json" DEBUG=0 log_err() { @@ -294,30 +296,27 @@ handle_filter_for_bundles() { fi check_bundle_exists() { - local enable download_url name cfg + local enable url name - cfg="$1" - config_get name "$cfg" name - config_get_bool enable "$cfg" enable 1 - config_get download_url "$cfg" download_url + json_select "${2}" + + json_get_var name name + json_get_var url url + json_get_var enable enable + enable="${enable:-1}" if [ "${enable}" -eq 0 ]; then log_info "Skipping bundle ${name} not enabled" return 0 fi - handle_download_url "$download_url" "$name" - local exit_status=$? - if [ "$exit_status" -eq 1 ]; then - uci -q set "parentalcontrol.${cfg}.status"="Error" - else - uci -q set "parentalcontrol.${cfg}.status"="" - fi - - uci commit parentalcontrol + handle_download_url "${url}" "${name}" } - config_foreach check_bundle_exists urlbundle + json_init + json_load_file "${URLBUNDLE_JSON}" + + json_for_each_item check_bundle_exists "urlBundles" } # Open file descriptor 200 for locking From e9b11c717bc4f3bc38e97f38d4c92527a0e6e140 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Dutta Date: Mon, 8 Dec 2025 11:06:16 +0530 Subject: [PATCH 2/2] parental-control: read urlbundle definition from json --- parental-control/Makefile | 2 +- .../files/lib/parentalcontrol/sync_bundles.sh | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/parental-control/Makefile b/parental-control/Makefile index 121f91956..9c18b03eb 100644 --- a/parental-control/Makefile +++ b/parental-control/Makefile @@ -11,7 +11,7 @@ LOCAL_DEV:=0 ifneq ($(LOCAL_DEV),1) PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://dev.iopsys.eu/network/parental-control.git -PKG_SOURCE_VERSION:=0aa48d99ff0e45111bc27f78df35159252164a78 +PKG_SOURCE_VERSION:=11777ff069888fc543c2501110313b654bbbfbc9 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz PKG_MIRROR_HASH:=skip endif diff --git a/parental-control/files/lib/parentalcontrol/sync_bundles.sh b/parental-control/files/lib/parentalcontrol/sync_bundles.sh index 03562e4c6..b9d0e13fa 100644 --- a/parental-control/files/lib/parentalcontrol/sync_bundles.sh +++ b/parental-control/files/lib/parentalcontrol/sync_bundles.sh @@ -87,6 +87,7 @@ update_bundle_file_from_url() { local success=0 while [ $attempt -le 3 ]; do if curl -s -o "$temp_file" "$download_url"; then + log_info "Download successful for $download_url" success=1 break else @@ -220,24 +221,33 @@ cleanup_bundle_files() { # Collect all download_url entries using config_foreach local urls="" get_download_url() { - local section="$1" - config_get url "$section" download_url - config_get_bool enable "$1" enable 1 + local enable url + + json_select "${2}" + + json_get_var url url + json_get_var enable enable + enable="${enable:-1}" if [ "${enable}" -eq 0 ]; then - # bundle is disabled + log_info "get_download_url: Skipping bundle ${name} not enabled" + json_select .. return 0 fi + url="${url#file://}" url="${url#https://}" url="${url#http://}" url="${url##*/}" # Get everything after the last '/' urls="$urls $url" + json_select .. } - config_load parentalcontrol - config_foreach get_download_url urlbundle + json_init + json_load_file "${URLBUNDLE_JSON}" + + json_for_each_item get_download_url "urlBundles" # Loop through all files in the directory for file in "$dir"/*; do @@ -306,11 +316,13 @@ handle_filter_for_bundles() { enable="${enable:-1}" if [ "${enable}" -eq 0 ]; then - log_info "Skipping bundle ${name} not enabled" + log_info "check_bundle_exists: Skipping bundle ${name} not enabled" + json_select .. return 0 fi handle_download_url "${url}" "${name}" + json_select .. } json_init