raspap-webgui-mirror/includes/adblock.php

61 lines
1.8 KiB
PHP
Raw Normal View History

2020-03-26 19:45:39 +00:00
<?php
require_once 'includes/status_messages.php';
require_once 'config.php';
/**
2020-03-27 13:02:21 +00:00
* Manages ad blocking (dnsmasq) configuration
2020-03-26 19:45:39 +00:00
*
*/
function DisplayAdBlockConfig()
{
$status = new StatusMessages();
2020-03-27 13:02:21 +00:00
exec('cat '. RASPI_DNSMASQ_CONFIG, $return);
$arrConf = ParseConfig($return);
if (!RASPI_MONITOR_ENABLED) {
if (isset($_POST['saveadblocksettings'])) {
if ($_POST['adblock-enable'] == "1") {
2020-03-27 14:32:27 +00:00
$arrConf['conf-file'] = RASPI_ADBLOCK_LISTPATH .'domains.txt';
$arrConf['addn-hosts'] = RASPI_ADBLOCK_LISTPATH .'hostnames.txt';
2020-03-27 13:02:21 +00:00
} else {
unset($arrConf['conf-file']);
unset($arrConf['addn-hosts']);
}
$config = array_map(function($value, $key) {
2020-03-27 14:32:27 +00:00
if (is_bool($value)) {
return $key;
} else {
return $key.'='.$value;
}
2020-03-27 13:02:21 +00:00
}, array_values($arrConf), array_keys($arrConf));
$config = implode(PHP_EOL, $config);
$config = $config . PHP_EOL;
file_put_contents("/tmp/dnsmasqdata", $config);
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_CONFIG, $return);
if ($return == 0) {
$status->addMessage('Adblock configuration updated successfully', 'success');
} else {
$status->addMessage('Adblock configuration failed to be updated.', 'danger');
}
}
}
2020-03-26 19:45:39 +00:00
exec('pidof dnsmasq | wc -l', $dnsmasq);
$dnsmasq_state = ($dnsmasq[0] > 0);
$serviceStatus = $dnsmasq_state ? "up" : "down";
2020-03-27 13:02:21 +00:00
2020-03-26 19:45:39 +00:00
echo renderTemplate(
"adblock", compact(
"status",
2020-03-27 13:02:21 +00:00
"serviceStatus",
2020-03-27 14:32:27 +00:00
"dnsmasq_state",
2020-03-27 13:02:21 +00:00
"arrConf"
2020-03-26 19:45:39 +00:00
)
);
}
2020-03-27 13:02:21 +00:00