Browse Source
Merge pull request #543 from billz/feature/notracking
Merge pull request #543 from billz/feature/notracking
Enable ad / tracker blocking with host blocklistsl10n_master
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 411 additions and 2 deletions
-
24ajax/adblock/update_blocklist.php
-
14app/css/custom.css
-
14app/css/hackernews.css
-
14app/css/lightsout.css
-
22app/js/custom.js
-
6config/blocklists.json
-
2config/config.php
-
60includes/adblock.php
-
2includes/defaults.php
-
47includes/functions.php
-
9index.php
-
21installers/update_blocklist.sh
-
BINlocale/en_US/LC_MESSAGES/messages.mo
-
43locale/en_US/LC_MESSAGES/messages.po
-
52templates/adblock.php
-
43templates/adblock/general.php
-
25templates/adblock/logging.php
-
15templates/adblock/stats.php
@ -0,0 +1,24 @@ |
|||
<?php |
|||
|
|||
require '../../includes/csrf.php'; |
|||
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/"; |
|||
|
|||
switch ($blocklist_id) { |
|||
case "notracking-hostnames": |
|||
$file = "hostnames.txt"; |
|||
break; |
|||
case "notracking-domains": |
|||
$file = "domains.txt"; |
|||
break; |
|||
} |
|||
$blocklist = $notracking_url . $file; |
|||
|
|||
exec("sudo /etc/raspap/adblock/update_blocklist.sh $blocklist $file " .RASPI_ADBLOCK_LISTPATH, $return); |
|||
$jsonData = ['return'=>$return]; |
|||
echo json_encode($jsonData); |
|||
} |
|||
|
@ -0,0 +1,6 @@ |
|||
{ |
|||
"notracking/hosts-blocklist": [ |
|||
"notracking-hostnames", |
|||
"notracking-domains" |
|||
] |
|||
} |
@ -0,0 +1,60 @@ |
|||
<?php |
|||
|
|||
require_once 'includes/status_messages.php'; |
|||
require_once 'config.php'; |
|||
|
|||
/** |
|||
* Manages ad blocking (dnsmasq) configuration |
|||
* |
|||
*/ |
|||
function DisplayAdBlockConfig() |
|||
{ |
|||
$status = new StatusMessages(); |
|||
$enabled = false; |
|||
|
|||
if (!RASPI_MONITOR_ENABLED) { |
|||
if (isset($_POST['saveadblocksettings'])) { |
|||
if ($_POST['adblock-enable'] == "1") { |
|||
$config = 'conf-file=' .RASPI_ADBLOCK_LISTPATH .'domains.txt'.PHP_EOL; |
|||
$config.= 'addn-hosts=' .RASPI_ADBLOCK_LISTPATH .'hostnames.txt'.PHP_EOL; |
|||
} elseif ($_POST['adblock-enable'] == "0") { |
|||
$config = null; |
|||
} |
|||
file_put_contents("/tmp/dnsmasqdata", $config); |
|||
system('sudo cp /tmp/dnsmasqdata '.RASPI_ADBLOCK_CONFIG, $return); |
|||
|
|||
if ($return == 0) { |
|||
$status->addMessage('Adblock configuration updated successfully', 'success'); |
|||
} else { |
|||
$status->addMessage('Adblock configuration failed to be updated.', 'danger'); |
|||
} |
|||
} elseif (isset($_POST['restartadblock']) || isset($_POST['startadblock'])) { |
|||
exec('sudo /bin/systemctl restart dnsmasq.service', $dnsmasq, $return); |
|||
if ($return == 0) { |
|||
$status->addMessage('Adblock restart successful', 'success'); |
|||
} else { |
|||
$status->addMessage('Adblock failed to restart.', 'danger'); |
|||
} |
|||
} |
|||
} |
|||
|
|||
exec('cat '. RASPI_ADBLOCK_CONFIG, $return); |
|||
$arrConf = ParseConfig($return); |
|||
if (sizeof($arrConf) > 0) { |
|||
$enabled = true; |
|||
} |
|||
|
|||
exec('pidof dnsmasq | wc -l', $dnsmasq); |
|||
$dnsmasq_state = ($dnsmasq[0] > 0); |
|||
$serviceStatus = $dnsmasq_state && $enabled ? "up" : "down"; |
|||
|
|||
echo renderTemplate( |
|||
"adblock", compact( |
|||
"status", |
|||
"serviceStatus", |
|||
"dnsmasq_state", |
|||
"enabled" |
|||
) |
|||
); |
|||
} |
|||
|
@ -0,0 +1,21 @@ |
|||
#!/bin/bash |
|||
# |
|||
# |
|||
# @author billz |
|||
# license: GNU General Public License v3.0 |
|||
|
|||
# Exit on error |
|||
set -o errexit |
|||
# Exit on error inside functions |
|||
set -o errtrace |
|||
# Turn on traces, disabled by default |
|||
#set -o xtrace |
|||
|
|||
update_url=$1 |
|||
file=$2 |
|||
destination=$3 |
|||
|
|||
wget -q ${update_url} -O ${destination}${file} &> /dev/null |
|||
|
|||
echo "$?" |
|||
|
@ -0,0 +1,52 @@ |
|||
<?php ob_start() ?>
|
|||
<?php if (!RASPI_MONITOR_ENABLED) : ?>
|
|||
<input type="submit" class="btn btn-outline btn-primary" name="saveadblocksettings" value="<?php echo _("Save settings"); ?>"> |
|||
<?php if ($dnsmasq_state) : ?>
|
|||
<input type="submit" class="btn btn-warning" name="restartadblock" value="<?php echo _("Restart Ad Blocking"); ?>"> |
|||
<?php else : ?>
|
|||
<input type="submit" class="btn btn-success" name="startadblock" value="<?php echo _("Start Ad Blocking"); ?>"> |
|||
<?php endif ?>
|
|||
<?php endif ?>
|
|||
<?php $buttons = ob_get_clean(); ob_end_clean() ?>
|
|||
|
|||
<div class="row"> |
|||
<div class="col-lg-12"> |
|||
<div class="card"> |
|||
<div class="card-header"> |
|||
<div class="row"> |
|||
<div class="col"> |
|||
<i class="far fa-hand-paper mr-2"></i><?php echo _("Ad Blocking"); ?>
|
|||
</div> |
|||
<div class="col"> |
|||
<button class="btn btn-light btn-icon-split btn-sm service-status float-right"> |
|||
<span class="icon text-gray-600"><i class="fas fa-circle service-status-<?php echo $serviceStatus ?>"></i></span> |
|||
<span class="text service-status">adblock <?php echo _($serviceStatus) ?></span>
|
|||
</button> |
|||
</div> |
|||
</div><!-- /.row --> |
|||
</div><!-- /.card-header --> |
|||
<div class="card-body"> |
|||
<?php $status->showMessages(); ?>
|
|||
<form role="form" action="?page=adblock_conf" enctype="multipart/form-data" method="POST"> |
|||
<?php echo CSRFTokenFieldTag() ?>
|
|||
<!-- Nav tabs --> |
|||
<ul class="nav nav-tabs"> |
|||
<li class="nav-item"><a class="nav-link active" id="clienttab" href="#adblocklistsettings" data-toggle="tab"><?php echo _("Blocklist settings"); ?></a></li>
|
|||
<li class="nav-item"><a class="nav-link" id="logoutputtab" href="#adblocklogfileoutput" data-toggle="tab"><?php echo _("Logging"); ?></a></li>
|
|||
</ul> |
|||
|
|||
<!-- Tab panes --> |
|||
<div class="tab-content"> |
|||
<?php echo renderTemplate("adblock/general", $__template_data) ?>
|
|||
<?php echo renderTemplate("adblock/stats", $__template_data) ?>
|
|||
<?php echo renderTemplate("adblock/logging", $__template_data) ?>
|
|||
</div><!-- /.tab-content --> |
|||
|
|||
<?php echo $buttons ?>
|
|||
</form> |
|||
</div><!-- /.card-body --> |
|||
<div class="card-footer"><?php echo _("Information provided by adblock"); ?></div>
|
|||
</div><!-- /.card --> |
|||
</div><!-- /.col-lg-12 --> |
|||
</div><!-- /.row --> |
|||
|
@ -0,0 +1,43 @@ |
|||
<!-- blocklist settings tab --> |
|||
<div class="tab-pane active" id="adblocklistsettings"> |
|||
<div class="row"> |
|||
<div class="col-md-6"> |
|||
<h4 class="mt-3"><?php echo _("Blocklist settings"); ?></h4>
|
|||
<div class="input-group"> |
|||
<input type="hidden" name="adblock-enable" value="0"> |
|||
<div class="custom-control custom-switch"> |
|||
<input class="custom-control-input" id="adblock-enable" type="checkbox" name="adblock-enable" value="1" <?php echo $enabled ? ' checked="checked"' : "" ?> aria-describedby="adblock-description">
|
|||
<label class="custom-control-label" for="adblock-enable"><?php echo _("Enable blocklists") ?></label>
|
|||
</div> |
|||
<p id="adblock-description"> |
|||
<small><?php echo _("Enable this option if you want RaspAP to <b>block DNS requests for ads, tracking and other virtual garbage</b>. Blocklists are gathered from multiple, actively maintained sources and automatically updated, cleaned, optimized and moderated on a daily basis.") ?></small>
|
|||
<div> |
|||
<small class="text-muted"><?php echo _("This option adds <code>conf-file</code> and <code>addn-hosts</code> to the dnsmasq configuration.") ?></small>
|
|||
</div> |
|||
</p> |
|||
</div> |
|||
<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">
|
|||
<?php echo blocklistUpdated('hostnames.txt') ?></span></small></div>
|
|||
<div><small><?php echo _("Domains blocklist last updated") ?>: <span class="font-weight-bold" id="notracking-domains">
|
|||
<?php echo blocklistUpdated('domains.txt') ?></b></small></div>
|
|||
</p> |
|||
<div class="input-group col-md-12 mb-4"> |
|||
<select class="custom-select custom-select-sm" id="cbxblocklist" onchange="clearBlocklistStatus()"> |
|||
<option value=""><?php echo _("Choose a blocklist provider") ?></option>
|
|||
<option disabled="disabled"></option> |
|||
<?php echo optionsForSelect(blocklistProviders()) ?>
|
|||
</select> |
|||
<div class="input-group-append"> |
|||
<button class="btn btn-sm btn-outline-secondary rounded-right" type="button" onclick="updateBlocklist()"><?php echo _("Update now"); ?></button>
|
|||
<span id="cbxblocklist-status" class="input-group-addon check-hidden ml-2 mt-1"><i class="fas fa-check"></i></span> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div><!-- /.row --> |
|||
</div><!-- /.tab-pane | advanded tab --> |
|||
|
@ -0,0 +1,25 @@ |
|||
<!-- logging tab --> |
|||
<div class="tab-pane fade" id="adblocklogfileoutput"> |
|||
<h4 class="mt-3"><?php echo _("Logging"); ?></h4>
|
|||
<div class="row"> |
|||
<div class="form-group col-md-8"> |
|||
<?php |
|||
$log = ''; |
|||
exec('sudo chmod o+r /tmp/dnsmasq.log'); |
|||
$handle = fopen("/tmp/dnsmasq.log", "r"); |
|||
if ($handle) { |
|||
while (($line = fgets($handle)) !== false) { |
|||
if (preg_match('/(0.0.0.0)/', $line)){ |
|||
$log.=$line; |
|||
} |
|||
} |
|||
} else { |
|||
$log = "Unable to open log file"; |
|||
} |
|||
fclose($handle); |
|||
echo '<textarea class="logoutput">'.htmlspecialchars($log, ENT_QUOTES).'</textarea>'; |
|||
?>
|
|||
</div> |
|||
</div> |
|||
</div><!-- /.tab-pane --> |
|||
|
@ -0,0 +1,15 @@ |
|||
<!-- statistics tab --> |
|||
<div class="tab-pane fade" id="adblockstats"> |
|||
<h4 class="mt-3"><?php echo _("Statistics"); ?></h4>
|
|||
<div class="row"> |
|||
<div class="form-group col-md-8"> |
|||
<?php |
|||
/* |
|||
* BZ todo: implement basic stats |
|||
* |
|||
*/ |
|||
?>
|
|||
</div> |
|||
</div> |
|||
</div><!-- /.tab-pane --> |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue