mirror of
https://github.com/pi-hole/web.git
synced 2025-12-23 12:18:26 +00:00
This makes the web interface add wildcards in the same way as the CLI. Signed-off-by: Mark Drobnak <mark.drobnak@gmail.com>
66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
/* Pi-hole: A black hole for Internet advertisements
|
|
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
* Network-wide ad blocking via your own hardware.
|
|
*
|
|
* This file is copyright under the latest version of the EUPL.
|
|
* Please see LICENSE file for your rights under this license. */
|
|
|
|
function is_valid_domain_name($domain_name)
|
|
{
|
|
return (preg_match("/^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$/i", $domain_name) && // Valid chars check
|
|
preg_match("/^.{1,253}$/", $domain_name) && // Overall length check
|
|
preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name)); // Length of each label
|
|
}
|
|
|
|
function checkfile($filename) {
|
|
if(is_readable($filename))
|
|
{
|
|
return $filename;
|
|
}
|
|
else
|
|
{
|
|
// substitute dummy file
|
|
return "/dev/null";
|
|
}
|
|
}
|
|
|
|
// Credit: http://php.net/manual/en/function.hash-equals.php#119576
|
|
if(!function_exists('hash_equals')) {
|
|
function hash_equals($known_string, $user_string) {
|
|
$ret = 0;
|
|
|
|
if (strlen($known_string) !== strlen($user_string)) {
|
|
$user_string = $known_string;
|
|
$ret = 1;
|
|
}
|
|
|
|
$res = $known_string ^ $user_string;
|
|
|
|
for ($i = strlen($res) - 1; $i >= 0; --$i) {
|
|
$ret |= ord($res[$i]);
|
|
}
|
|
|
|
return !$ret;
|
|
}
|
|
}
|
|
|
|
function add_regex($regex, $mode=FILE_APPEND, $append="\n")
|
|
{
|
|
global $regexfile;
|
|
if(file_put_contents($regexfile, $regex.$append, $mode) === FALSE)
|
|
{
|
|
$err = error_get_last()["message"];
|
|
echo "Unable to add regex \"".htmlspecialchars($regex)."\" to ${regexfile}<br>Error message: $err";
|
|
}
|
|
else
|
|
{
|
|
// Send SIGHUP to pihole-FTL using a frontend command
|
|
// to force reloading of the regex domains
|
|
// This will also wipe the resolver's cache
|
|
echo exec("sudo pihole restartdns reload");
|
|
}
|
|
}
|
|
|
|
?>
|