From 129f6404217fa4fc939b241c9ddccc994a6836cd Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Sat, 18 Mar 2023 16:32:14 +0100 Subject: [PATCH] Fixed #1285 to support newer top level domain names (TLD) as well Signed-off-by: Janos SUTO --- config.php.in | 2 ++ webui/system/misc.php | 11 +++++----- webui/tests/MiscTest.php | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 webui/tests/MiscTest.php 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); + } +}