Skip to content

Commit

Permalink
Merge pull request #1409 from RaspAP/maint/blocklists
Browse files Browse the repository at this point in the history
Replaces ad block no-tracking lists w/ new sources
  • Loading branch information
billz authored Oct 8, 2023
2 parents 2ac5f94 + a0ff530 commit 03118b9
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 26 deletions.
51 changes: 40 additions & 11 deletions ajax/adblock/update_blocklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,50 @@
require_once '../../includes/config.php';

if (isset($_POST['blocklist_id'])) {
$blocklist_id = $_POST['blocklist_id'];
$notracking_url = "https://raw.githubusercontent.com/notracking/hosts-blocklists/master/";
$blocklist_id = escapeshellcmd($_POST['blocklist_id']);

switch ($blocklist_id) {
case "notracking-hostnames":
$file = "hostnames.txt";
break;
case "notracking-domains":
$file = "domains.txt";
break;
case "StevenBlack/hosts \(default\)":
$list_url = "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts";
$dest_file = "hostnames.txt";
break;
case "badmojr/1Hosts \(Mini\)":
$list_url = "https://badmojr.github.io/1Hosts/mini/hosts.txt";
$dest_file = "hostnames.txt";
break;
case "badmojr/1Hosts \(Lite\)":
$list_url = "https://badmojr.github.io/1Hosts/Lite/hosts.txt";
$dest_file = "hostnames.txt";
break;
case "badmojr/1Hosts \(Pro\)":
$list_url = "https://badmojr.github.io/1Hosts/Pro/hosts.txt";
$dest_file = "hostnames.txt";
break;
case "badmojr/1Hosts \(Xtra\)":
$list_url = "https://badmojr.github.io/1Hosts/Xtra/hosts.txt";
$dest_file = "hostnames.txt";
break;
case "oisd/big \(default\)":
$list_url = "https://big.oisd.nl/dnsmasq";
$dest_file = "domains.txt";
break;
case "oisd/small":
$list_url = "https://small.oisd.nl/dnsmasq";
$dest_file = "domains.txt";
break;
case "oisd/nsfw":
$list_url = "https://nsfw.oisd.nl/dnsmasq";
$dest_file = "domains.txt";
break;
}
$blocklist = $notracking_url . $file;
$blocklist = $list_url . $dest_file;
$dest = substr($dest_file, 0, strrpos($dest_file, "."));

exec("sudo /etc/raspap/adblock/update_blocklist.sh $blocklist $file " .RASPI_ADBLOCK_LISTPATH, $return);
$jsonData = ['return'=>$return];
exec("sudo /etc/raspap/adblock/update_blocklist.sh $list_url $dest_file " .RASPI_ADBLOCK_LISTPATH, $return);
$jsonData = ['return'=>$return,'list'=>$dest];
echo json_encode($jsonData);
} else {
$jsonData = ['return'=>2,'output'=>['Error getting data']];
echo json_encode($jsonData);
}

5 changes: 3 additions & 2 deletions app/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ function setHardwareModeTooltip() {
* Interface elements are updated to indicate current progress, status.
*/
function updateBlocklist() {
var blocklist_id = $('#cbxblocklist').val();
var opt = $('#cbxblocklist option:selected');
var blocklist_id = opt.val();
var csrfToken = $('meta[name=csrf_token]').attr('content');
if (blocklist_id == '') { return; }
$('#cbxblocklist-status').find('i').removeClass('fas fa-check').addClass('fas fa-cog fa-spin');
Expand All @@ -451,7 +452,7 @@ function updateBlocklist() {
if (jsonData['return'] == '0') {
$('#cbxblocklist-status').find('i').removeClass('fas fa-cog fa-spin').addClass('fas fa-check');
$('#cbxblocklist-status').removeClass('check-progress').addClass('check-updated').delay(500).animate({ opacity: 1 }, 700);
$('#'+blocklist_id).text("Just now");
$('#blocklist-'+jsonData['list']).text("Just now");
}
})
}
Expand Down
19 changes: 15 additions & 4 deletions config/blocklists.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
"notracking/hosts-blocklist": [
"notracking-hostnames",
"notracking-domains"
]
"StevenBlack/hosts": [
"StevenBlack/hosts (default)"
],
"badmojr/hosts": [
"badmojr/1Hosts (Mini)",
"badmojr/1Hosts (Lite)",
"badmojr/1Hosts (Pro)",
"badmojr/1Hosts (Xtra)"
],
"OISD/domains": [
"oisd/big (default)",
"oisd/small",
"oisd/nsfw"
]
}

2 changes: 1 addition & 1 deletion includes/adblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function DisplayAdBlockConfig()
$handle = fopen(RASPI_DHCPCD_LOG, "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
if (preg_match('/(0.0.0.0)/', $line)) {
if (preg_match('/(is 0.0.0.0)|(using only locally-known addresses)/', $line)) {
$adblock_log .= $line;
}
}
Expand Down
11 changes: 6 additions & 5 deletions installers/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ readonly raspap_sysctl="/etc/sysctl.d/90_raspap.conf"
readonly raspap_network="$raspap_dir/networking/"
readonly raspap_router="/etc/lighttpd/conf-available/50-raspap-router.conf"
readonly rulesv4="/etc/iptables/rules.v4"
readonly notracking_url="https://raw.githubusercontent.com/notracking/hosts-blocklists/master/"
readonly blocklist_hosts="https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
readonly blocklist_domains="https://big.oisd.nl/dnsmasq"
webroot_dir="/var/www/html"

if [ "$insiders" == 1 ]; then
Expand Down Expand Up @@ -338,7 +339,7 @@ function _install_lighttpd_configs() {

# Prompt to install ad blocking
function _prompt_install_adblock() {
_install_log "Configure ad blocking (Beta)"
_install_log "Configure ad blocking"
echo -n "Install ad blocking and enable list management? [Y/n]: "
if [ "$assume_yes" == 0 ]; then
read answer < /dev/tty
Expand All @@ -354,7 +355,7 @@ function _prompt_install_adblock() {
fi
}

# Download notracking adblock lists and enable option
# Download adblock lists and enable option
function _install_adblock() {
_install_log "Creating ad blocking base configuration (Beta)"
if [ ! -d "$raspap_dir/adblock" ]; then
Expand All @@ -363,12 +364,12 @@ function _install_adblock() {
fi
if [ ! -f /tmp/hostnames.txt ]; then
echo "Fetching latest hostnames list"
wget ${notracking_url}hostnames.txt -q --show-progress --progress=bar:force -O /tmp/hostnames.txt 2>&1 \
wget ${blocklist_hosts} -q --show-progress --progress=bar:force -O /tmp/hostnames.txt 2>&1 \
|| _install_status 1 "Unable to download notracking hostnames"
fi
if [ ! -f /tmp/domains.txt ]; then
echo "Fetching latest domains list"
wget ${notracking_url}domains.txt -q --show-progress --progress=bar:force -O /tmp/domains.txt 2>&1 \
wget ${blocklist_domains} -q --show-progress --progress=bar:force -O /tmp/domains.txt 2>&1 \
|| _install_status 1 "Unable to download notracking domains"
fi
echo "Adding blocklists to $raspap_dir/adblock"
Expand Down
2 changes: 1 addition & 1 deletion installers/update_blocklist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ update_url=$1
file=$2
destination=$3

wget -q ${update_url} -O ${destination}${file} &> /dev/null
wget -q --no-use-server-timestamps ${update_url} -O ${destination}${file} &> /dev/null

echo "$?"

4 changes: 2 additions & 2 deletions templates/adblock/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<div class="row">
<div class="col-md-12">
<p id="blocklist-updated">
<div><small><?php echo _("Hostnames blocklist last updated") ?>: <span class="font-weight-bold" id="notracking-hostnames">
<div><small><?php echo _("Hostnames blocklist last updated") ?>: <span class="font-weight-bold" id="blocklist-hostnames">
<?php echo blocklistUpdated('hostnames.txt') ?></span></small></div>
<div><small><?php echo _("Domains blocklist last updated") ?>: <span class="font-weight-bold" id="notracking-domains">
<div><small><?php echo _("Domains blocklist last updated") ?>: <span class="font-weight-bold" id="blocklist-domains">
<?php echo blocklistUpdated('domains.txt') ?></b></small></div>
</p>
<div class="input-group col-md-12 mb-4">
Expand Down

0 comments on commit 03118b9

Please sign in to comment.