1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00
raspap-webgui/includes/adblock.php

63 lines
1.9 KiB
PHP
Raw Normal View History

2020-03-26 20:45:39 +01:00
<?php
require_once 'includes/status_messages.php';
require_once 'config.php';
/**
2020-03-27 14:02:21 +01:00
* Manages ad blocking (dnsmasq) configuration
2020-03-26 20:45:39 +01:00
*
*/
function DisplayAdBlockConfig()
{
$status = new StatusMessages();
$enabled = false;
2020-03-27 14:02:21 +01:00
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;
2020-03-27 14:02:21 +01:00
}
file_put_contents("/tmp/dnsmasqdata", $config);
system('sudo cp /tmp/dnsmasqdata '.RASPI_ADBLOCK_CONFIG, $return);
2020-03-27 14:02:21 +01:00
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');
}
2020-03-27 14:02:21 +01:00
}
}
2020-03-26 20:45:39 +01:00
exec('cat '. RASPI_ADBLOCK_CONFIG, $return);
$arrConf = ParseConfig($return);
if (sizeof($arrConf) > 0) {
$enabled = true;
}
2020-03-26 20:45:39 +01:00
exec('pidof dnsmasq | wc -l', $dnsmasq);
$dnsmasq_state = ($dnsmasq[0] > 0);
$serviceStatus = $dnsmasq_state && $enabled ? "up" : "down";
2020-03-27 14:02:21 +01:00
2020-03-26 20:45:39 +01:00
echo renderTemplate(
"adblock", compact(
"status",
2020-03-27 14:02:21 +01:00
"serviceStatus",
2020-03-27 15:32:27 +01:00
"dnsmasq_state",
"enabled"
2020-03-26 20:45:39 +01:00
)
);
}
2020-03-27 14:02:21 +01:00