mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Merge branch 'master' into feature/wireguard
This commit is contained in:
@@ -11,6 +11,7 @@ function DisplayAdBlockConfig()
|
||||
{
|
||||
$status = new StatusMessages();
|
||||
$enabled = false;
|
||||
$custom_enabled = false;
|
||||
|
||||
if (!RASPI_MONITOR_ENABLED) {
|
||||
if (isset($_POST['saveadblocksettings'])) {
|
||||
@@ -20,13 +21,39 @@ function DisplayAdBlockConfig()
|
||||
} elseif ($_POST['adblock-enable'] == "0") {
|
||||
$config = null;
|
||||
}
|
||||
file_put_contents("/tmp/dnsmasqdata", $config);
|
||||
system('sudo cp /tmp/dnsmasqdata '.RASPI_ADBLOCK_CONFIG, $return);
|
||||
if ($_POST['adblock-custom-enable'] == "1") {
|
||||
// validate custom hosts input
|
||||
$lines = preg_split('/\r\n|\n|\r/', trim($_POST['adblock-custom-hosts']));
|
||||
if (!in_array("", $lines, true)) {
|
||||
foreach ($lines as $line) {
|
||||
$ip_host = preg_split('/\s+/', $line);
|
||||
$index++;
|
||||
if (!filter_var($ip_host[0], FILTER_VALIDATE_IP)) {
|
||||
$errors .= _('Invalid custom IP address found on line '.$index);
|
||||
break;
|
||||
}
|
||||
if (!validate_host($ip_host[1])) {
|
||||
$errors .= _('Invalid custom host found on line '.$index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
file_put_contents("/tmp/dnsmasq_custom", $_POST['adblock-custom-hosts'].PHP_EOL);
|
||||
system("sudo cp /tmp/dnsmasq_custom " .RASPI_ADBLOCK_LISTPATH .'custom.txt', $return);
|
||||
$config.= 'addn-hosts=' .RASPI_ADBLOCK_LISTPATH .'custom.txt'.PHP_EOL;
|
||||
$custom_enabled = true;
|
||||
}
|
||||
|
||||
if ($return == 0) {
|
||||
$status->addMessage('Adblock configuration updated successfully', 'success');
|
||||
if (empty($errors)) {
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
$status->addMessage('Adblock configuration failed to be updated.', 'danger');
|
||||
$status->addMessage($errors, 'danger');
|
||||
}
|
||||
} elseif (isset($_POST['restartadblock']) || isset($_POST['startadblock'])) {
|
||||
exec('sudo /bin/systemctl restart dnsmasq.service', $dnsmasq, $return);
|
||||
@@ -53,7 +80,8 @@ function DisplayAdBlockConfig()
|
||||
"status",
|
||||
"serviceStatus",
|
||||
"dnsmasq_state",
|
||||
"enabled"
|
||||
"enabled",
|
||||
"custom_enabled"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@@ -477,5 +477,9 @@ function validateCidr($cidr)
|
||||
return $netmask <= 128;
|
||||
}
|
||||
return false;
|
||||
|
||||
// Validates a host or FQDN
|
||||
function validate_host($host) {
|
||||
return preg_match('/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i', $host);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user