From 3494663c15c520670a512e23e1a5a0100e6301c4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 4 Jan 2018 11:57:41 -0500 Subject: [PATCH] Add allowed_domain generic function --- include/network.php | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/include/network.php b/include/network.php index 16c8185e1a..2f8b24b8b6 100644 --- a/include/network.php +++ b/include/network.php @@ -613,24 +613,37 @@ function allowed_email($email) return false; } - $str_allowed = Config::get('system', 'allowed_email'); - if (! $str_allowed) { - return true; - } + $str_allowed = Config::get('system', 'allowed_email', ''); + $allowed = explode(',', $str_allowed); - $found = false; + return allowed_domain($domain, $allowed); +} - $fnmatch = function_exists('fnmatch'); - $allowed = explode(',', $str_allowed); +/** + * Checks for the existence of a domain in a domain list + * + * If strict is not set, an empty domain list counts as found + * + * @brief Checks for the existence of a domain in a domain list + * @param string $domain + * @param array $domain_list + * @param bool $strict + * @return boolean + */ +function allowed_domain($domain, array $domain_list, $strict = false) +{ + $found = false; - if (count($allowed)) { - foreach ($allowed as $a) { - $pat = strtolower(trim($a)); - if (($fnmatch && fnmatch($pat, $domain)) || ($pat == $domain)) { + if (count($domain_list)) { + foreach ($domain_list as $item) { + $pat = strtolower(trim($item)); + if (fnmatch($pat, $domain) || ($pat == $domain)) { $found = true; break; } } + } elseif(!$strict) { + $found = true; } return $found; } -- 2.39.5