mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
save cnf to 090_adblock.conf, start/restart actions
This commit is contained in:
parent
9d5e2ee666
commit
0b475ff56d
@ -10,48 +10,50 @@ require_once 'config.php';
|
|||||||
function DisplayAdBlockConfig()
|
function DisplayAdBlockConfig()
|
||||||
{
|
{
|
||||||
$status = new StatusMessages();
|
$status = new StatusMessages();
|
||||||
exec('cat '. RASPI_DNSMASQ_CONFIG, $return);
|
$enabled = false;
|
||||||
$arrConf = ParseConfig($return);
|
|
||||||
|
|
||||||
if (!RASPI_MONITOR_ENABLED) {
|
if (!RASPI_MONITOR_ENABLED) {
|
||||||
if (isset($_POST['saveadblocksettings'])) {
|
if (isset($_POST['saveadblocksettings'])) {
|
||||||
if ($_POST['adblock-enable'] == "1") {
|
if ($_POST['adblock-enable'] == "1") {
|
||||||
$arrConf['conf-file'] = RASPI_ADBLOCK_LISTPATH .'domains.txt';
|
$config = 'conf-file=' .RASPI_ADBLOCK_LISTPATH .'domains.txt'.PHP_EOL;
|
||||||
$arrConf['addn-hosts'] = RASPI_ADBLOCK_LISTPATH .'hostnames.txt';
|
$config.= 'addn-hosts=' .RASPI_ADBLOCK_LISTPATH .'hostnames.txt'.PHP_EOL;
|
||||||
} else {
|
} elseif ($_POST['adblock-enable'] == "0") {
|
||||||
unset($arrConf['conf-file']);
|
$config = null;
|
||||||
unset($arrConf['addn-hosts']);
|
|
||||||
}
|
}
|
||||||
$config = array_map(function($value, $key) {
|
|
||||||
if (is_bool($value)) {
|
|
||||||
return $key;
|
|
||||||
} else {
|
|
||||||
return $key.'='.$value;
|
|
||||||
}
|
|
||||||
}, array_values($arrConf), array_keys($arrConf));
|
|
||||||
$config = implode(PHP_EOL, $config);
|
|
||||||
$config = $config . PHP_EOL;
|
|
||||||
file_put_contents("/tmp/dnsmasqdata", $config);
|
file_put_contents("/tmp/dnsmasqdata", $config);
|
||||||
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_CONFIG, $return);
|
system('sudo cp /tmp/dnsmasqdata '.RASPI_ADBLOCK_CONFIG, $return);
|
||||||
|
|
||||||
if ($return == 0) {
|
if ($return == 0) {
|
||||||
$status->addMessage('Adblock configuration updated successfully', 'success');
|
$status->addMessage('Adblock configuration updated successfully', 'success');
|
||||||
} else {
|
} else {
|
||||||
$status->addMessage('Adblock configuration failed to be updated.', 'danger');
|
$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);
|
exec('pidof dnsmasq | wc -l', $dnsmasq);
|
||||||
$dnsmasq_state = ($dnsmasq[0] > 0);
|
$dnsmasq_state = ($dnsmasq[0] > 0);
|
||||||
$serviceStatus = $dnsmasq_state ? "up" : "down";
|
$serviceStatus = $dnsmasq_state && $enabled ? "up" : "down";
|
||||||
|
|
||||||
echo renderTemplate(
|
echo renderTemplate(
|
||||||
"adblock", compact(
|
"adblock", compact(
|
||||||
"status",
|
"status",
|
||||||
"serviceStatus",
|
"serviceStatus",
|
||||||
"dnsmasq_state",
|
"dnsmasq_state",
|
||||||
"arrConf"
|
"enabled"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user