Skip to content

Commit

Permalink
Check for duplicates when banning
Browse files Browse the repository at this point in the history
  • Loading branch information
MioVisman committed Jan 9, 2019
1 parent c649ab9 commit f5cc3c9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
20 changes: 18 additions & 2 deletions admin_bans.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 5 additions & 3 deletions include/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,28 @@ 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;

foreach ($pun_bans as $cur_ban)
{
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']) {
Expand Down
2 changes: 2 additions & 0 deletions lang/English/admin_bans.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 …' ,
Expand Down
2 changes: 2 additions & 0 deletions lang/Russian/admin_bans.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => 'Бан добавлен. Переадресация …' ,
Expand Down

0 comments on commit f5cc3c9

Please sign in to comment.