This commit is contained in:
billz 2020-03-26 19:45:39 +00:00
parent 6f503d8b53
commit ae26f948a4
7 changed files with 147 additions and 0 deletions

5
config/blocklists.json Normal file
View file

@ -0,0 +1,5 @@
{
"notracking/hosts-blocklist": [
"notracking-master"
]
}

View file

@ -30,6 +30,7 @@ define('RASPI_WIFICLIENT_ENABLED', true);
define('RASPI_HOTSPOT_ENABLED', true); define('RASPI_HOTSPOT_ENABLED', true);
define('RASPI_NETWORK_ENABLED', true); define('RASPI_NETWORK_ENABLED', true);
define('RASPI_DHCP_ENABLED', true); define('RASPI_DHCP_ENABLED', true);
define('RASPI_ADBLOCK_ENABLED', true);
define('RASPI_OPENVPN_ENABLED', false); define('RASPI_OPENVPN_ENABLED', false);
define('RASPI_TORPROXY_ENABLED', false); define('RASPI_TORPROXY_ENABLED', false);
define('RASPI_CONFAUTH_ENABLED', true); define('RASPI_CONFAUTH_ENABLED', true);

35
includes/adblock.php Normal file
View file

@ -0,0 +1,35 @@
<?php
require_once 'includes/status_messages.php';
require_once 'app/lib/system.php';
require_once 'config.php';
/**
*
*
*/
function DisplayAdBlockConfig()
{
$status = new StatusMessages();
$system = new System();
exec('pidof dnsmasq | wc -l', $dnsmasq);
$dnsmasq_state = ($dnsmasq[0] > 0);
$serviceStatus = $dnsmasq_state ? "up" : "down";
echo renderTemplate(
"adblock", compact(
"status",
"serviceStatus"
)
);
}
/**
* BZ: todo
*
*/
function SaveAdBlockConfig()
{
}

View file

@ -31,6 +31,7 @@ $defaults = [
'RASPI_HOTSPOT_ENABLED' => true, 'RASPI_HOTSPOT_ENABLED' => true,
'RASPI_NETWORK_ENABLED' => true, 'RASPI_NETWORK_ENABLED' => true,
'RASPI_DHCP_ENABLED' => true, 'RASPI_DHCP_ENABLED' => true,
'RASPI_ADBLOCK_ENABLED' => true,
'RASPI_OPENVPN_ENABLED' => false, 'RASPI_OPENVPN_ENABLED' => false,
'RASPI_TORPROXY_ENABLED' => false, 'RASPI_TORPROXY_ENABLED' => false,
'RASPI_CONFAUTH_ENABLED' => true, 'RASPI_CONFAUTH_ENABLED' => true,

View file

@ -352,6 +352,12 @@ function dnsServers()
return (array) $data; return (array) $data;
} }
function blocklistProviders()
{
$data = json_decode(file_get_contents("./config/blocklists.json"));
return (array) $data;
}
function optionsForSelect($options) function optionsForSelect($options)
{ {
$html = ""; $html = "";

View file

@ -31,6 +31,7 @@ require_once 'includes/authenticate.php';
require_once 'includes/admin.php'; require_once 'includes/admin.php';
require_once 'includes/dhcp.php'; require_once 'includes/dhcp.php';
require_once 'includes/hostapd.php'; require_once 'includes/hostapd.php';
require_once 'includes/adblock.php';
require_once 'includes/system.php'; require_once 'includes/system.php';
require_once 'includes/sysstats.php'; require_once 'includes/sysstats.php';
require_once 'includes/configure_client.php'; require_once 'includes/configure_client.php';
@ -137,6 +138,11 @@ $bridgedEnabled = $arrHostapdConf['BridgedEnable'];
<?php if (RASPI_DHCP_ENABLED && !$bridgedEnabled) : ?> <?php if (RASPI_DHCP_ENABLED && !$bridgedEnabled) : ?>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="index.php?page=dhcpd_conf"><i class="fas fa-exchange-alt fa-fw mr-2"></i><span class="nav-label"><?php echo _("DHCP Server"); ?></a> <a class="nav-link" href="index.php?page=dhcpd_conf"><i class="fas fa-exchange-alt fa-fw mr-2"></i><span class="nav-label"><?php echo _("DHCP Server"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_ADBLOCK_ENABLED) : ?>
<li class="nav-item">
<a class="nav-link" href="index.php?page=adblock_conf"><i class="far fa-hand-paper fa-fw mr-2"></i><span class="nav-label"><?php echo _("Ad Blocking"); ?></a>
</li> </li>
<?php endif; ?> <?php endif; ?>
<?php if (RASPI_NETWORK_ENABLED) : ?> <?php if (RASPI_NETWORK_ENABLED) : ?>
@ -239,6 +245,9 @@ $bridgedEnabled = $arrHostapdConf['BridgedEnable'];
case "hostapd_conf": case "hostapd_conf":
DisplayHostAPDConfig(); DisplayHostAPDConfig();
break; break;
case "adblock_conf":
DisplayAdBlockConfig();
break;
case "openvpn_conf": case "openvpn_conf":
DisplayOpenVPNConfig(); DisplayOpenVPNConfig();
break; break;

90
templates/adblock.php Executable file
View file

@ -0,0 +1,90 @@
<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 _("Logfile output"); ?></a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<!-- 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 $conf['adblock-enable'] ? ' 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 class="mb-3">
<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="form-group col-md-6">
<select class="custom-select custom-select-sm js-field-preset" data-field-preset-target="#add-dhcp-upstream-server-field">
<option value=""><?php echo _("Choose a blocklist provider") ?></option>
<option disabled="disabled"></option>
<?php echo optionsForSelect(blocklistProviders()) ?>
</select>
</div>
</div>
</div>
</div><!-- /.row -->
</div><!-- /.tab-pane | advanded tab -->
<!-- logging tab -->
<div class="tab-pane fade" id="adblocklogfileoutput">
<h4 class="mt-3"><?php echo _("Blocklist log"); ?></h4>
<div class="row">
<div class="form-group col-md-8">
<?php
echo '<textarea class="logoutput"></textarea>';
?>
</div>
</div>
</div>
<?php if (!RASPI_MONITOR_ENABLED) : ?>
<input type="submit" class="btn btn-outline btn-primary" name="SaveAdBlockSettings" value="Save settings" />
<?php if ($openvpnstatus[0] == 0) {
echo '<input type="submit" class="btn btn-success" name="StartOpenVPN" value="Start Ad Blocking" />' , PHP_EOL;
} else {
echo '<input type="submit" class="btn btn-warning" name="StopOpenVPN" value="Stop Ad Blocking" />' , PHP_EOL;
}
?>
<?php endif ?>
</form>
</div>
</div><!-- /.card-body -->
<div class="card-footer"><?php echo _("Information provided by adblock"); ?></div>
</div><!-- /.card -->
</div><!-- /.col-lg-12 -->
</div><!-- /.row -->