diff --git a/config.php.in b/config.php.in index 07857d0d..fdabe487 100644 --- a/config.php.in +++ b/config.php.in @@ -34,6 +34,8 @@ $config['TITLE_PREFIX'] = ''; $config['CUSTOM_PRE_AUTH_FUNCTION'] = ''; $config['CUSTOM_EMAIL_QUERY_FUNCTION'] = ''; +$config['DOMAIN_REGEX'] = '/^[a-zA-Z0-9]+[a-zA-Z0-9-_\.]{0,}\.[a-zA-Z0-9]{2,20}$/'; + $config['BOOTSTRAP_THEME'] = '-cosmo'; $config['DEFAULT_LANG'] = 'en'; diff --git a/webui/system/misc.php b/webui/system/misc.php index 29820fe9..879d8a19 100644 --- a/webui/system/misc.php +++ b/webui/system/misc.php @@ -145,13 +145,12 @@ function checkemail($email, $domains) { function validemail($email = '') { - if($email == '') { return 0; } + if($email == '' || !strchr($email, '@')) { return 0; } - if(preg_match("/@local$/", $email)) { return 1; } + $arr = explode("@", $email); - if(preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,10})$/', $email)) { - return 1; - } + // This is a pretty relaxed formula making sure we have something as the local part + if(count($arr) == 2 && strlen($arr[0]) >= 1 && validdomain($arr[1])) { return 1; } return 0; } @@ -173,7 +172,7 @@ function checkdomain($domain, $domains) { function validdomain($domain = '') { - if(preg_match("/@?local$/", $domain) || preg_match('/^[a-zA-Z0-9]+[a-zA-Z0-9-_\.]{0,}\.[a-zA-Z0-9]{2,10}$/', $domain)) { + if(preg_match("/@?local$/", $domain) || preg_match(DOMAIN_REGEX, $domain)) { return 1; } diff --git a/webui/tests/MiscTest.php b/webui/tests/MiscTest.php new file mode 100644 index 00000000..41b05825 --- /dev/null +++ b/webui/tests/MiscTest.php @@ -0,0 +1,45 @@ +assertEquals($result, $expected_result); + } +}