From 26dc8d92da8857b7e7376032a4aa6b73d3407b7a Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 31 Mar 2020 21:54:46 +0000 Subject: [PATCH] Ad block installer option (beta) --- config/config.php | 1 + includes/defaults.php | 1 + installers/common.sh | 49 ++++++++++++++++++++++++++++++++++++++++++ installers/raspbian.sh | 3 +++ 4 files changed, 54 insertions(+) diff --git a/config/config.php b/config/config.php index 7d58e4ce..2ea9b748 100755 --- a/config/config.php +++ b/config/config.php @@ -30,6 +30,7 @@ define('RASPI_WIFICLIENT_ENABLED', true); define('RASPI_HOTSPOT_ENABLED', true); define('RASPI_NETWORK_ENABLED', true); define('RASPI_DHCP_ENABLED', true); +define('RASPI_ADBLOCK_ENABLED', false); define('RASPI_OPENVPN_ENABLED', false); define('RASPI_TORPROXY_ENABLED', false); define('RASPI_CONFAUTH_ENABLED', true); diff --git a/includes/defaults.php b/includes/defaults.php index 6d6c7e61..ad8b806f 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -31,6 +31,7 @@ $defaults = [ 'RASPI_HOTSPOT_ENABLED' => true, 'RASPI_NETWORK_ENABLED' => true, 'RASPI_DHCP_ENABLED' => true, + 'RASPI_ADBLOCK_ENABLED' => false, 'RASPI_OPENVPN_ENABLED' => false, 'RASPI_TORPROXY_ENABLED' => false, 'RASPI_CONFAUTH_ENABLED' => true, diff --git a/installers/common.sh b/installers/common.sh index 73adf9ef..cf3ec8f7 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -165,6 +165,54 @@ function _create_lighttpd_scripts() { sudo chmod 750 "$raspap_dir/lighttpd/"*.sh || _install_error "Unable to change file permissions" } +# Prompt to install adblock +function _prompt_install_adblock() { + if [ "$install_adblock" == 1 ]; then + _install_log "Configure ad blocking (Beta)" + echo -n "Download blocklists and enable ad blocking? [Y/n]: " + if [ "$assume_yes" == 0 ]; then + read answer < /dev/tty + if [ "$answer" != "${answer#[Nn]}" ]; then + echo -e + else + _install_adblock + fi + fi + fi +} + +# Download notracking adblock lists and enable option +function _install_adblock() { + _install_log "Creating ad block base configuration (Beta)" + notracking_url="https://raw.githubusercontent.com/notracking/hosts-blocklists/master/" + if [ ! -d "$raspap_dir/adblock" ]; then + echo "Creating $raspap_dir/adblock" + sudo mkdir -p "$raspap_dir/adblock" + fi + if [ ! -f /tmp/hostnames.txt ]; then + echo "Fetching latest hostnames list" + wget ${notracking_url}hostnames.txt -O /tmp/hostnames.txt || _install_error "Unable to download notracking hostnames" + fi + if [ ! -f /tmp/domains.txt ]; then + echo "Fetching latest domains list" + wget ${notracking_url}domains.txt -O /tmp/domains.txt || _install_error "Unable to download notracking domains" + fi + echo "Adding blocklists to $raspap_dir/adblock" + sudo cp /tmp/hostnames.txt $raspap_dir/adblock || _install_error "Unable to move notracking hostnames" + sudo cp /tmp/domains.txt $raspap_dir/adblock || _install_error "Unable to move notracking domains" + + echo "Moving and setting permissions for blocklist update script" + sudo cp "$webroot_dir/installers/"update_blocklist.sh "$raspap_dir/adblock" || _install_error "Unable to move blocklist update script" + + # Make blocklists and update script writable by www-data group + sudo chown -c root:"$raspap_user" "$raspap_dir/adblock/"*.* || _install_error "Unable to change owner/group" + sudo chmod 750 "$raspap_dir/adblock/"*.sh || install_error "Unable to change file permissions" + + echo "Enabling ad blocking management option" + sudo sed -i "s/\('RASPI_ADBLOCK_ENABLED', \)false/\1true/g" "$webroot_dir/includes/config.php" || _install_error "Unable to modify config.php" + echo "Done." +} + # Prompt to install openvpn function _prompt_install_openvpn() { _install_log "Setting up OpenVPN support" @@ -456,6 +504,7 @@ function _install_raspap() { _default_configuration _configure_networking _prompt_install_openvpn + _prompt_install_adblock _patch_system_files _install_complete } diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 57cc458a..5f45f4bf 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -62,6 +62,9 @@ while :; do ovpn_option="$2" shift ;; + -a|--adblock) + install_adblock=1 + ;; -c|--cert|--certificate) install_cert=1 ;;