diff options
Diffstat (limited to 'net/simple-adblock/files/simple-adblock.init')
-rw-r--r-- | net/simple-adblock/files/simple-adblock.init | 159 |
1 files changed, 87 insertions, 72 deletions
diff --git a/net/simple-adblock/files/simple-adblock.init b/net/simple-adblock/files/simple-adblock.init index 883a6e921..69a1ff6af 100644 --- a/net/simple-adblock/files/simple-adblock.init +++ b/net/simple-adblock/files/simple-adblock.init @@ -3,12 +3,16 @@ # shellcheck disable=SC2039,SC1091 PKG_VERSION='dev-test' -export START=94 -export USE_PROCD=1 -export LC_ALL=C +# shellcheck disable=SC2034 +START=94 +# shellcheck disable=SC2034 +USE_PROCD=1 +LC_ALL=C -export EXTRA_COMMANDS='check dl killcache sizes show' -export EXTRA_HELP=' check Checks if specified domain is found in current blacklist +# shellcheck disable=SC2034 +EXTRA_COMMANDS='check dl killcache sizes show' +# shellcheck disable=SC2034 +EXTRA_HELP=' check Checks if specified domain is found in current block-list dl Force-downloads all enabled block-list sizes Displays the file-sizes of enabled block-lists show Shows the service last-run status' @@ -44,23 +48,12 @@ readonly sharedMemoryError="/dev/shm/$packageName-error" readonly sharedMemoryOutput="/dev/shm/$packageName-output" readonly hostsFilter='/localhost/d;/^#/d;/^[^0-9]/d;s/^0\.0\.0\.0.//;s/^127\.0\.0\.1.//;s/[[:space:]]*#.*$//;s/[[:cntrl:]]$//;s/[[:space:]]//g;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/\./!d;/^$/d;/[^[:alnum:]_.-]/d;' readonly domainsFilter='/^#/d;s/[[:space:]]*#.*$//;s/[[:space:]]*$//;s/[[:cntrl:]]$//;/[[:space:]]/d;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/\./!d;/^$/d;/[^[:alnum:]_.-]/d;' -readonly checkmark='\xe2\x9c\x93' -readonly xmark='\xe2\x9c\x97' readonly _OK_='\033[0;32m\xe2\x9c\x93\033[0m' readonly _FAIL_='\033[0;31m\xe2\x9c\x97\033[0m' readonly __OK__='\033[0;32m[\xe2\x9c\x93]\033[0m' readonly __FAIL__='\033[0;31m[\xe2\x9c\x97]\033[0m' readonly _ERROR_='\033[0;31mERROR\033[0m' -readonly messageSuccess='Success' -readonly messageFail='Fail' -readonly messageDownloading='Downloading' -readonly messageReloading='Reloading' -readonly messageRestarting='Restarting' -readonly messageStarting='Starting' -readonly messageForceReloading='Force-Reloading' -readonly messageProcessing='Processing' -readonly messageStopped='Stopped' getStatusText() { local _ret case "$1" in @@ -70,6 +63,7 @@ getStatusText() { statusRestarting) _ret="Restarting";; statusForceReloading) _ret="Force Reloading";; statusDownloading) _ret="Downloading";; + statusProcessing) _ret="Processing";; statusError) _ret="Error";; statusWarning) _ret="Warning";; statusFail) _ret="Fail";; @@ -85,14 +79,14 @@ getErrorText() { errorSharedMemory) _ret="failed to access shared memory";; errorSorting) _ret="failed to sort data file";; errorOptimization) _ret="failed to optimize data file";; - errorWhitelistProcessing) _ret="failed to process whitelist";; + errorAllowListProcessing) _ret="failed to process allow-list";; errorDataFileFormatting) _ret="failed to format data file";; errorMovingDataFile) _ret="failed to move data file '${A_TMP}' to '${outputFile}'";; errorCreatingCompressedCache) _ret="failed to create compressed cache";; errorRemovingTempFiles) _ret="failed to remove temporary files";; errorRestoreCompressedCache) _ret="failed to unpack compressed cache";; errorRestoreCache) _ret="failed to move '$outputCache' to '$outputFile'";; - errorOhSnap) _ret="failed to create blocklist or restart DNS resolver";; + errorOhSnap) _ret="failed to create block-list or restart DNS resolver";; errorStopping) _ret="failed to stop $serviceName";; errorDNSReload) _ret="failed to reload/restart DNS resolver";; errorDownloadingList) _ret="failed to download";; @@ -108,8 +102,8 @@ output_ok() { output 1 "$_OK_"; output 2 "$__OK__\\n"; } output_okn() { output 1 "$_OK_\\n"; output 2 "$__OK__\\n"; } output_fail() { output 1 "$_FAIL_"; output 2 "$__FAIL__\\n"; } output_failn() { output 1 "$_FAIL_\\n"; output 2 "$__FAIL__\\n"; } -# str_replace() { printf "%b" "$1" | sed -e "s/$(printf "%b" "$2")/$(printf "%b" "$3")/g"; } -# str_contains() { test "$1" != "$(str_replace "$1" "$2" '')"; } +str_replace() { printf "%b" "$1" | sed -e "s/$(printf "%b" "$2")/$(printf "%b" "$3")/g"; } +str_contains() { test "$1" != "$(str_replace "$1" "$2" '')"; } compare_versions() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; } is_chaos_calmer() { ubus -S call system board | grep -q 'Chaos Calmer'; } is_ipset_procd() { compare_versions "$(sed -ne 's/^Version: //p' /usr/lib/opkg/info/firewall.control)" "2019-09-18"; } @@ -139,13 +133,33 @@ output() { fi } -export serviceEnabled forceDNS parallelDL debug allowIDN compressedCache -export targetDNS bootDelay dlTimeout curlRetry verbosity=1 led dnsInstance -export whitelist_domains blacklist_domains -export whitelist_domains_urls blacklist_domains_urls blacklist_hosts_urls -export wan_if wan_gw wanphysdev dl_command serviceStatus dl_flag -export outputFilter outputFilterIPv6 outputFile outputGzip outputCache ipv6Enabled -export is_ssl_supported +serviceEnabled=1 +forceDNS=1 +parallelDL=1 +debug=0 +compressedCache=0 +ipv6Enabled=0 +bootDelay=120 +dlTimeout=20 +curlRetry=3 +verbosity=2 +led='' +targetDNS=dnsmasq.servers +dnsInstance=0 +allowed_domains='' +blocked_domains='' +allowed_domains_urls='' +blocked_domains_urls='' +blocked_hosts_urls='' +dl_command='' +dl_flag='' +outputFilter='' +outputFilterIPv6='' +outputFile='' +outputGzip='' +outputCache='' +isSSLSupported='' +allowIDN=0 load_package_config() { config_load "$packageName" @@ -162,11 +176,11 @@ load_package_config() { config_get led 'config' 'led' config_get targetDNS 'config' 'dns' 'dnsmasq.servers' config_get dnsInstance 'config' 'dns_instance' '0' - config_get whitelist_domains 'config' 'whitelist_domain' - config_get blacklist_domains 'config' 'blacklist_domain' - config_get whitelist_domains_urls 'config' 'whitelist_domains_url' - config_get blacklist_domains_urls 'config' 'blacklist_domains_url' - config_get blacklist_hosts_urls 'config' 'blacklist_hosts_url' + config_get allowed_domains 'config' 'allowed_domain' + config_get allowed_domains_urls 'config' 'allowed_domains_url' + config_get blocked_domains 'config' 'blocked_domain' + config_get blocked_domains_urls 'config' 'blocked_domains_url' + config_get blocked_hosts_urls 'config' 'blocked_hosts_url' if [ "$targetDNS" != 'dnsmasq.addnhosts' ] && [ "$targetDNS" != 'dnsmasq.conf' ] && \ [ "$targetDNS" != 'dnsmasq.servers' ] && [ "$targetDNS" != 'unbound.adb_list' ] && \ @@ -249,13 +263,14 @@ load_package_config() { || grep -q "libustream-mbedtls" /usr/lib/opkg/status \ || grep -q "libustream-openssl" /usr/lib/opkg/status \ || grep -q "libustream-wolfssl" /usr/lib/opkg/status; then - is_ssl_supported=1 + isSSLSupported=1 else - unset is_ssl_supported + unset isSSLSupported fi } is_enabled() { + wan_if=''; wan_gw=''; load_package_config if [ "$debug" -ne 0 ]; then @@ -457,7 +472,7 @@ tmpfs() { stats) printf "%b" "$stats"; return;; triggers) - curReload="$parallelDL $debug $dlTimeout $whitelist_domains $blacklist_domains $whitelist_domains_urls $blacklist_domains_urls $blacklist_hosts_urls $targetDNS" + curReload="$parallelDL $debug $dlTimeout $allowed_domains $blocked_domains $allowed_domains_urls $blocked_domains_urls $blocked_hosts_urls $targetDNS" curRestart="$compressedCache $forceDNS $led" if [ ! -s "$jsonFile" ]; then ret='on_boot' @@ -513,7 +528,7 @@ tmpfs() { stats) stats="$value";; triggers) - readReload="$parallelDL $debug $dlTimeout $whitelist_domains $blacklist_domains $whitelist_domains_urls $blacklist_domains_urls $blacklist_hosts_urls $targetDNS" + readReload="$parallelDL $debug $dlTimeout $allowed_domains $blocked_domains $allowed_domains_urls $blocked_domains_urls $blocked_hosts_urls $targetDNS" readRestart="$compressedCache $forceDNS $led" ;; esac @@ -678,7 +693,7 @@ process_url() { else type='Allowed'; D_TMP="$A_TMP"; fi - if [ "${1:0:5}" == "https" ] && [ -z "$is_ssl_supported" ]; then + if [ "${1:0:5}" == "https" ] && [ -z "$isSSLSupported" ]; then output 1 "$_FAIL_" output 2 "[DL] $type $label $__FAIL__\\n" echo "errorNoSSLSupport|${1}" >> "$sharedMemoryError" @@ -710,7 +725,7 @@ process_url() { download_lists() { local hf w_filter j=0 R_TMP - tmpfs set message "${messageDownloading}..." + tmpfs set message "$(getStatusText "statusDownloading")..." tmpfs set status "statusDownloading" rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip" @@ -725,8 +740,8 @@ download_lists() { touch $A_TMP; touch $B_TMP; output 1 'Downloading lists ' rm -f "$sharedMemoryError" - if [ -n "$blacklist_hosts_urls" ]; then - for hf in ${blacklist_hosts_urls}; do + if [ -n "$blocked_hosts_urls" ]; then + for hf in ${blocked_hosts_urls}; do if [ "$parallelDL" -gt 0 ]; then process_url "$hf" 'hosts' 'blocked' & else @@ -734,8 +749,8 @@ download_lists() { fi done fi - if [ -n "$blacklist_domains_urls" ]; then - for hf in ${blacklist_domains_urls}; do + if [ -n "$blocked_domains_urls" ]; then + for hf in ${blocked_domains_urls}; do if [ "$parallelDL" -gt 0 ]; then process_url "$hf" 'domains' 'blocked' & else @@ -743,8 +758,8 @@ download_lists() { fi done fi - if [ -n "$whitelist_domains_urls" ]; then - for hf in ${whitelist_domains_urls}; do + if [ -n "$allowed_domains_urls" ]; then + for hf in ${allowed_domains_urls}; do if [ "$parallelDL" -gt 0 ]; then process_url "$hf" 'domains' 'allowed' & else @@ -761,16 +776,16 @@ download_lists() { rm -f "$sharedMemoryError" fi - [ -n "$blacklist_domains" ] && for hf in ${blacklist_domains}; do echo "$hf" | sed "$domainsFilter" >> $B_TMP; done - whitelist_domains="${whitelist_domains} + [ -n "$blocked_domains" ] && for hf in ${blocked_domains}; do echo "$hf" | sed "$domainsFilter" >> $B_TMP; done + allowed_domains="${allowed_domains} $(cat $A_TMP)" - [ -n "$whitelist_domains" ] && for hf in ${whitelist_domains}; do hf="$(echo "$hf" | sed 's/\./\\./g')"; w_filter="$w_filter/^${hf}$/d;/\\.${hf}$/d;"; done + [ -n "$allowed_domains" ] && for hf in ${allowed_domains}; do hf="$(echo "$hf" | sed 's/\./\\./g')"; w_filter="$w_filter/^${hf}$/d;/\\.${hf}$/d;"; done [ ! -s "$B_TMP" ] && return 1 output 1 'Processing downloads ' output 2 'Sorting combined list ' - tmpfs set message "$messageProcessing: sorting combined list" + tmpfs set message "$(getStatusText "statusProcessing"): sorting combined list" if [ "$allowIDN" -gt 0 ]; then if sort -u "$B_TMP" > "$A_TMP"; then output_ok @@ -793,7 +808,7 @@ $(cat $A_TMP)" [ "$targetDNS" = 'unbound.adb_list' ]; then # TLD optimization written by Dirk Brenken (dev@brenken.org) output 2 'Optimizing combined list ' - tmpfs set message "$messageProcessing: optimizing combined list" + tmpfs set message "$(getStatusText "statusProcessing"): optimizing combined list" # sed -E 'G;:t;s/(.*)(\.)(.*)(\n)(.*)/\1\4\5\2\3/;tt;s/(.*)\n(\.)(.*)/\3\2\1/' is actually slower than awk if awk -F "." '{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "$A_TMP" > "$B_TMP"; then if sort "$B_TMP" > "$A_TMP"; then @@ -828,17 +843,17 @@ $(cat $A_TMP)" mv "$A_TMP" "$B_TMP" fi - output 2 'Whitelisting domains ' - tmpfs set message "$messageProcessing: whitelisting domains" + output 2 'Allowing domains ' + tmpfs set message "$(getStatusText "statusProcessing"): allowing domains" if sed -i "$w_filter" "$B_TMP"; then output_ok else output_failn - tmpfs add error "errorWhitelistProcessing" + tmpfs add error "errorAllowListProcessing" fi output 2 'Formatting merged file ' - tmpfs set message "$messageProcessing: formatting merged file" + tmpfs set message "$(getStatusText "statusProcessing"): formatting merged file" if [ -z "$outputFilterIPv6" ]; then if sed "$outputFilter" "$B_TMP" > "$A_TMP"; then output_ok @@ -863,23 +878,23 @@ $(cat $A_TMP)" case "$targetDNS" in dnsmasq.addnhosts) output 2 'Creating DNSMASQ addnhosts file ' - tmpfs set message "$messageProcessing: creating DNSMASQ addnhosts file" + tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ addnhosts file" ;; dnsmasq.conf) output 2 'Creating DNSMASQ config file ' - tmpfs set message "$messageProcessing: creating DNSMASQ config file" + tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ config file" ;; dnsmasq.ipset) output 2 'Creating DNSMASQ ipset file ' - tmpfs set message "$messageProcessing: creating DNSMASQ ipset file" + tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ ipset file" ;; dnsmasq.servers) output 2 'Creating DNSMASQ servers file ' - tmpfs set message "$messageProcessing: creating DNSMASQ servers file" + tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ servers file" ;; unbound.adb_list) output 2 'Creating Unbound adb_list file ' - tmpfs set message "$messageProcessing: creating Unbound adb_list file" + tmpfs set message "$(getStatusText "statusProcessing"): creating Unbound adb_list file" ;; esac if mv "$A_TMP" "$outputFile"; then @@ -890,7 +905,7 @@ $(cat $A_TMP)" fi if [ "$compressedCache" -gt 0 ]; then output 2 'Creating compressed cache ' - tmpfs set message "$messageProcessing: creating compressed cache" + tmpfs set message "$(getStatusText "statusProcessing"): creating compressed cache" if cacheOps 'createGzip'; then output_ok else @@ -901,7 +916,7 @@ $(cat $A_TMP)" rm -f "$outputGzip" fi output 2 'Removing temporary files ' - tmpfs set message "$messageProcessing: removing temporary files" + tmpfs set message "$(getStatusText "statusProcessing"): removing temporary files" rm -f "/tmp/${packageName}_tmp.*" "$A_TMP" "$B_TMP" "$outputCache" || j=1 if [ $j -eq 0 ]; then output_ok @@ -1173,7 +1188,7 @@ check() { local string="$1" local c="$(grep -c "$string" "$outputFile")" if [ ! -s "$outputFile" ]; then - echo "No blacklist ('$outputFile') found." + echo "No block-list ('$outputFile') found." elif [ -z "$string" ]; then echo "Usage: /etc/init.d/${packageName} check string" elif [ "$c" -gt 0 ]; then @@ -1195,7 +1210,7 @@ check() { grep "$string" "$outputFile" | sed 's|^local-zone: "||;s|" static$||;';; esac else - echo "The $string is not found in current blacklist ('$outputFile')." + echo "The $string is not found in current block-list ('$outputFile')." fi } @@ -1204,39 +1219,39 @@ sizes() { load_package_config echo "# $(date)" - for i in $blacklist_domains_urls; do + for i in $blocked_domains_urls; do [ "${i//melmac}" != "$i" ] && continue if $dl_command "$i" $dl_flag /tmp/sast 2>/dev/null && [ -s /tmp/sast ]; then echo "# File size: $(du -sh /tmp/sast | awk '{print $1}')" if compare_versions "$(du -sk /tmp/sast)" "500"; then - echo "# blocklist too big for most routers" + echo "# block-list too big for most routers" elif compare_versions "$(du -sk /tmp/sast)" "100"; then - echo "# blocklist may be too big for some routers" + echo "# block-list may be too big for some routers" fi rm -rf /tmp/sast - echo " list blacklist_domains_url '$i'" + echo " list blocked_domains_url '$i'" echo "" else echo "# site was down on last check" - echo "# list blacklist_domains_url '$i'" + echo "# list blocked_domains_url '$i'" echo "" fi done - for i in $blacklist_hosts_urls; do + for i in $blocked_hosts_urls; do if $dl_command "$i" $dl_flag /tmp/sast 2>/dev/null && [ -s /tmp/sast ]; then echo "# File size: $(du -sh /tmp/sast | awk '{print $1}')" if compare_versions "$(du -sk /tmp/sast)" "500"; then - echo "# blocklist too big for most routers" + echo "# block-list too big for most routers" elif compare_versions "$(du -sk /tmp/sast)" "100"; then - echo "# blocklist may be too big for some routers" + echo "# block-list may be too big for some routers" fi rm -rf /tmp/sast - echo " list blacklist_hosts_url '$i'" + echo " list blocked_hosts_url '$i'" echo "" else echo "# site was down on last check" - echo "# list blacklist_hosts_url '$i'" + echo "# list blocked_hosts_url '$i'" echo "" fi done |