summarylogtreecommitdiffstats
path: root/hostsblock-urlcheck.sh
blob: ff123483ab846837ba207672f074d727cc217b01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# DO NOT MODIFY THIS FILE. MODIFY SETTINGS VIA THE CONFIGURATION FILES IN
# /etc/hostsblock.conf

# GET OPTIONS
while getopts "v:f:h" _option; do
    case "$_option" in
        f)  [ "$OPTARG" != "" ] && _configfile="$OPTARG";;
        *)
            cat << EOF
Usage:
  $0 [ -f CONFIGFILE ] URL  - Check if URL and other urls contained therein are blocked

$0 will first verify that [url] is blocked or unblocked,
and then scan that url for further contained subdomains

Help Options:
  -h                            Show help options

Application Options:
  -f CONFIGFILE                 Specify an alternative configuration file (instead of /etc/hostsblock/hostsblock.conf)
EOF
            exit 1
        ;;
    esac
done

# SOURCE DEFAULT SETTINGS AND SUBROUTINES
if [ -f /usr/lib/hostsblock-common.sh ]; then
    source /usr/lib/hostsblock-common.sh
elif [ -f /usr/local/lib/hostsblock-common.sh ]; then
    source /usr/local/lib/hostsblock-common.sh
elif [ -f ./hostsblock-common.sh ]; then
    source ./hostsblock-common.sh
else
    echo "hostsblock.common.sh NOT FOUND. INSTALL IT TO /usr/lib/ OR /usr/local/lib/. EXITING..."
    exit 1
fi

_check_root
_check_depends curl grep sed tr
_source_configfile
_verbosity_check
_set_subprocess_verbosity

# MAIN ROUTINE
_changed=0
echo "Checking to see if url is blocked or unblocked..."
_check_url $(echo "$@" | sed -e "s/.*https*:\/\///g" -e "s/[\/?'\" :<>\(\)].*//g")
if [ $_changed == 1 ]; then
    if [ $verbosity -ge 5 ]; then
        postprocess
    else
        postprocess &>/dev/null
    fi
fi
read -p "Page domain verified. Scan the whole page for other domains for (un)blocking? [y/N] " a
if [[ $a == "y" || $a == "Y" ]]; then
    for LINE in `curl -L --location-trusted -s "$@" | tr ' ' '\n' | grep "https*:\/\/" | sed -e "s/.*https*:\/\/\(.*\)$/\1/g" -e "s/\//\n/g" | grep "\." |\
      grep -v "\"" | grep -v ")" | grep -v "(" | grep -v "\&" | grep -v "\?" | grep -v "<" | grep -v ">" | grep -v "'" | grep -v "_" |\
      grep -v "\.php$" | grep -v "\.html*$" | grep "[a-z]$" | sort -u | tr "\n" " "`; do
        _check_url "$LINE"
    done
    echo "Whole-page scan completed."
fi

if [ $_changed == 1 ]; then
    if [ $verbosity -ge 5 ]; then
        postprocess
    else
        postprocess &>/dev/null
    fi
fi