#!/bin/sh # adblock cgi remote script - dns based ad/abuse domain blocking # Copyright (c) 2026 Dirk Brenken # This is free software, licensed under the GNU General Public License v3. # (s)hellcheck exceptions # shellcheck disable=all # load relevant uci options # nft_remote="$(uci -q get adblock.global.adb_nftremote)" nft_macremote="$(uci -q get adblock.global.adb_nftmacremote)" nft_remotetimeout="$(uci -q get adblock.global.adb_nftremotetimeout)" nft_authorized="0" # parse query # query_str="${QUERY_STRING}" query_mac="$(printf "%s" "${query_str}" | sed -n 's/.*mac=\([^&]*\).*/\1/p' 2>/dev/null)" query_mode="$(printf "%s" "${query_str}" | sed -n 's/.*mode=\([^&]*\).*/\1/p' 2>/dev/null)" # determine MAC if not provided # if [ -z "${query_mac}" ]; then query_ip="${REMOTE_ADDR}" query_mac="$(ip neigh show 2>/dev/null | awk -v ip="${query_ip}" '$1==ip {print $5; exit}' 2>/dev/null)" fi # validate MAC address # printf '%s\n' "${query_mac}" | grep -Eq '^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$' 2>/dev/null \ && query_mac="$(printf '%s\n' "${query_mac}" | awk '{ print tolower($0) }' 2>/dev/null)" \ || query_mac="" # validate mode # [ "${query_mode}" = "renew" ] || query_mode="" # output header and start html # printf "%s\n\n" "Content-Type: text/html" printf "%s\n" "