Check for empty strings

This commit is contained in:
billz 2020-09-20 09:42:13 +01:00
parent 9b02fc5b27
commit 3c5737224e
1 changed files with 13 additions and 11 deletions

View File

@ -24,19 +24,21 @@ function DisplayAdBlockConfig()
if ($_POST['adblock-custom-enable'] == "1") { if ($_POST['adblock-custom-enable'] == "1") {
// validate custom hosts input // validate custom hosts input
$lines = preg_split('/\r\n|\n|\r/', trim($_POST['adblock-custom-hosts'])); $lines = preg_split('/\r\n|\n|\r/', trim($_POST['adblock-custom-hosts']));
foreach ($lines as $line) { if (!in_array("", $lines, true)) {
$ip_host = preg_split('/\s+/', $line); foreach ($lines as $line) {
$index++; $ip_host = preg_split('/\s+/', $line);
if (!filter_var($ip_host[0], FILTER_VALIDATE_IP)) { $index++;
$errors .= _('Invalid custom IP address found on line '.$index); if (!filter_var($ip_host[0], FILTER_VALIDATE_IP)) {
break; $errors .= _('Invalid custom IP address found on line '.$index);
} break;
if (!validate_host($ip_host[1])) { }
$errors .= _('Invalid custom host found on line '.$index); if (!validate_host($ip_host[1])) {
break; $errors .= _('Invalid custom host found on line '.$index);
break;
}
} }
} }
file_put_contents("/tmp/dnsmasq_custom", $_POST['adblock-custom-hosts']); file_put_contents("/tmp/dnsmasq_custom", $_POST['adblock-custom-hosts'].PHP_EOL);
system("sudo cp /tmp/dnsmasq_custom " .RASPI_ADBLOCK_LISTPATH .'custom.txt', $return); system("sudo cp /tmp/dnsmasq_custom " .RASPI_ADBLOCK_LISTPATH .'custom.txt', $return);
$config.= 'addn-hosts=' .RASPI_ADBLOCK_LISTPATH .'custom.txt'.PHP_EOL; $config.= 'addn-hosts=' .RASPI_ADBLOCK_LISTPATH .'custom.txt'.PHP_EOL;
$custom_enabled = true; $custom_enabled = true;