From 85e97ca660619ea3678397ab9410e16e99c67b88 Mon Sep 17 00:00:00 2001 From: Mohd Husaam Mehdi Date: Wed, 8 Oct 2025 15:05:49 +0530 Subject: [PATCH] parental-control: improve bundle sync logic * handle the case when interface comes up after parental-control * handle the case when bundle size can't be fetched for some reason --- .../files/etc/init.d/parentalcontrol | 22 +++++++++++++++++++ .../files/lib/parentalcontrol/sync_bundles.sh | 18 ++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/parental-control/files/etc/init.d/parentalcontrol b/parental-control/files/etc/init.d/parentalcontrol index d096183fa..fc209204e 100755 --- a/parental-control/files/etc/init.d/parentalcontrol +++ b/parental-control/files/etc/init.d/parentalcontrol @@ -14,6 +14,7 @@ validate_global_section() { 'loglevel:uinteger:3' \ 'queue_num:uinteger:53' \ 'bundle_path:string' \ + 'default_wan_interface:string:wan' \ 'urlfilter:bool' } @@ -127,11 +128,19 @@ stop_service() { } reload_service() { + local arg="$1" + ret=$(ubus call service list '{"name":"parentalcontrol"}' | jsonfilter -qe '@.parentalcontrol.instances.parentalcontrol.running') if [ "$ret" != "true" ]; then stop start else + if [ "$arg" = "network" ]; then + pidof_sync="$(pidof sync_bundles.sh)" + [ -n "$pidof_sync" ] && kill "$pidof_sync" + sleep 5 + fi + configure_fw_rules copy_dhcp_leases ubus send parentalcontrol.reload @@ -139,6 +148,19 @@ reload_service() { } service_triggers() { + local enable urlfilter default_wan_interface + + validate_global_section || { + return 1 + } + + if [ "${urlfilter}" = "1" ] && [ "$enable" = "1" ] && [ -n "$default_wan_interface" ]; then + log "Adding interface trigger for $default_wan_interface" + procd_open_trigger + procd_add_interface_trigger "interface.*.up" "$default_wan_interface" /etc/init.d/parentalcontrol reload "network" + procd_close_trigger + fi + procd_add_reload_trigger "parentalcontrol" procd_add_reload_trigger "schedules" } diff --git a/parental-control/files/lib/parentalcontrol/sync_bundles.sh b/parental-control/files/lib/parentalcontrol/sync_bundles.sh index b58f85de4..a04ad95ca 100644 --- a/parental-control/files/lib/parentalcontrol/sync_bundles.sh +++ b/parental-control/files/lib/parentalcontrol/sync_bundles.sh @@ -161,7 +161,23 @@ handle_download_url() { # If the URL is HTTP, fetch the file size local bundle_file_size if echo "$sanitized_url" | grep -qE "^https?://"; then - bundle_file_size="$(curl -I "$sanitized_url" 2>&1 | grep -i 'content-length' | cut -d: -f2 | xargs)" + bundle_file_header="$(curl -Is --max-time 30 "$sanitized_url" 2>/var/log/urlfilter_curl_err.log)" + curl_rc=$? + + case $curl_rc in + 0) + # Success + ;; + 6|7|28|35|52|55|56) + log_info "handle_download_url: URL not reachable (curl rc=$curl_rc): ${sanitized_url}" + return 1 + ;; + *) + log_info "handle_download_url: unexpected curl rc=$curl_rc for ${sanitized_url}" + ;; + esac + + bundle_file_size="$(echo "$bundle_file_header" | grep -i 'content-length' | cut -d: -f2 | xargs)" [ -z "$bundle_file_size" ] && bundle_file_size=0 else # If it's a file:// URL, get the file size from the filesystem