diff --git a/admin_bans.php b/admin_bans.php index 7af299a..ce2cfea 100644 --- a/admin_bans.php +++ b/admin_bans.php @@ -269,10 +269,26 @@ } require PUN_ROOT.'include/email.php'; - if ($ban_email != '' && !is_valid_email($ban_email)) + if ($ban_email != '') { - if (!preg_match('%^[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,63})$%', $ban_email)) + $domain = false === strpos($ban_email, '@'); + $ban_email_cl = $domain && '.' === $ban_email[0] + ? substr($ban_email, 1) + : $ban_email; + + if (!is_valid_email($ban_email_cl) && !is_valid_email('test@' . $ban_email_cl)) message($lang_admin_bans['Invalid e-mail message']); + + $match = $_POST['mode'] == 'edit' ? intval($_POST['ban_id']) : -1; + $match = is_banned_email(($domain ? '.' : '') . $ban_email_cl, $match); + + if (false !== $match) + { + if (true === $match) + message(sprintf($lang_admin_bans['Duplicate e-mail message'], $ban_email)); + else + message(sprintf($lang_admin_bans['Duplicate domain message'], $match)); + } } if ($ban_expire != '' && $ban_expire != 'Never') diff --git a/include/email.php b/include/email.php index 3031508..bfceea8 100644 --- a/include/email.php +++ b/include/email.php @@ -31,7 +31,7 @@ function is_valid_email($email) // // Check if $email is banned // -function is_banned_email($email) +function is_banned_email($email, $id = false) { global $pun_bans; @@ -39,18 +39,20 @@ function is_banned_email($email) { if (empty($cur_ban['email'])) { continue; + } elseif (false !== $id && $cur_ban['id'] == $id) { + continue; } if (false === strpos($cur_ban['email'], '@')) { $len = strlen($cur_ban['email']); if ($cur_ban['email'][0] == '.') { if (substr($email, -$len) == $cur_ban['email']) { - return true; + return false === $id ? true : $cur_ban['email']; } } else { $tmp = substr($email, -1-$len); if ($tmp == '.'.$cur_ban['email'] || $tmp == '@'.$cur_ban['email']) { - return true; + return false === $id ? true : $cur_ban['email']; } } } else if ($email == $cur_ban['email']) { diff --git a/lang/English/admin_bans.php b/lang/English/admin_bans.php index 7c5bee8..32472b9 100644 --- a/lang/English/admin_bans.php +++ b/lang/English/admin_bans.php @@ -11,6 +11,8 @@ 'Cannot ban guest message' => 'The guest user cannot be banned.', 'Invalid IP message' => 'You entered an invalid IP/IP-range.', 'Invalid e-mail message' => 'The email address (e.g. user@domain.com) or partial email address domain (e.g. domain.com) you entered is invalid.', +'Duplicate domain message' => 'The domain %s has already been banned.', +'Duplicate e-mail message' => 'The email address %s has already been banned.', 'Invalid date message' => 'You entered an invalid expire date.', 'Invalid date reasons' => 'The format should be YYYY-MM-DD and the date must be at least one day in the future.', 'Ban added redirect' => 'Ban added. Redirecting …' , diff --git a/lang/Russian/admin_bans.php b/lang/Russian/admin_bans.php index 6922eb0..18062ff 100644 --- a/lang/Russian/admin_bans.php +++ b/lang/Russian/admin_bans.php @@ -11,6 +11,8 @@ 'Cannot ban guest message' => 'Гостя нельзя забанить.', 'Invalid IP message' => 'Вы ввели неверный IP или IP-диапазон.', 'Invalid e-mail message' => 'Email (т.е. user@domain.com) или доменная часть (т.е. domain.com) введена неверно.', +'Duplicate domain message' => 'Домен %s уже забанен.', +'Duplicate e-mail message' => 'Email %s уже забанен.', 'Invalid date message' => 'Вы ввели неправильную дату окончания.', 'Invalid date reasons' => 'Дата должна быть в формате YYYY-MM-DD и должна быть не ранее, чем завтрашнее число.', 'Ban added redirect' => 'Бан добавлен. Переадресация …' ,