Skip to content

Commit f5cc3c9

Browse files
committed
Check for duplicates when banning
1 parent c649ab9 commit f5cc3c9

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

admin_bans.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,26 @@
269269
}
270270

271271
require PUN_ROOT.'include/email.php';
272-
if ($ban_email != '' && !is_valid_email($ban_email))
272+
if ($ban_email != '')
273273
{
274-
if (!preg_match('%^[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,63})$%', $ban_email))
274+
$domain = false === strpos($ban_email, '@');
275+
$ban_email_cl = $domain && '.' === $ban_email[0]
276+
? substr($ban_email, 1)
277+
: $ban_email;
278+
279+
if (!is_valid_email($ban_email_cl) && !is_valid_email('test@' . $ban_email_cl))
275280
message($lang_admin_bans['Invalid e-mail message']);
281+
282+
$match = $_POST['mode'] == 'edit' ? intval($_POST['ban_id']) : -1;
283+
$match = is_banned_email(($domain ? '.' : '') . $ban_email_cl, $match);
284+
285+
if (false !== $match)
286+
{
287+
if (true === $match)
288+
message(sprintf($lang_admin_bans['Duplicate e-mail message'], $ban_email));
289+
else
290+
message(sprintf($lang_admin_bans['Duplicate domain message'], $match));
291+
}
276292
}
277293

278294
if ($ban_expire != '' && $ban_expire != 'Never')

include/email.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,28 @@ function is_valid_email($email)
3131
//
3232
// Check if $email is banned
3333
//
34-
function is_banned_email($email)
34+
function is_banned_email($email, $id = false)
3535
{
3636
global $pun_bans;
3737

3838
foreach ($pun_bans as $cur_ban)
3939
{
4040
if (empty($cur_ban['email'])) {
4141
continue;
42+
} elseif (false !== $id && $cur_ban['id'] == $id) {
43+
continue;
4244
}
4345

4446
if (false === strpos($cur_ban['email'], '@')) {
4547
$len = strlen($cur_ban['email']);
4648
if ($cur_ban['email'][0] == '.') {
4749
if (substr($email, -$len) == $cur_ban['email']) {
48-
return true;
50+
return false === $id ? true : $cur_ban['email'];
4951
}
5052
} else {
5153
$tmp = substr($email, -1-$len);
5254
if ($tmp == '.'.$cur_ban['email'] || $tmp == '@'.$cur_ban['email']) {
53-
return true;
55+
return false === $id ? true : $cur_ban['email'];
5456
}
5557
}
5658
} else if ($email == $cur_ban['email']) {

lang/English/admin_bans.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
'Cannot ban guest message' => 'The guest user cannot be banned.',
1212
'Invalid IP message' => 'You entered an invalid IP/IP-range.',
1313
'Invalid e-mail message' => 'The email address (e.g. [email protected]) or partial email address domain (e.g. domain.com) you entered is invalid.',
14+
'Duplicate domain message' => 'The domain %s has already been banned.',
15+
'Duplicate e-mail message' => 'The email address %s has already been banned.',
1416
'Invalid date message' => 'You entered an invalid expire date.',
1517
'Invalid date reasons' => 'The format should be YYYY-MM-DD and the date must be at least one day in the future.',
1618
'Ban added redirect' => 'Ban added. Redirecting …' ,

lang/Russian/admin_bans.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
'Cannot ban guest message' => 'Гостя нельзя забанить.',
1212
'Invalid IP message' => 'Вы ввели неверный IP или IP-диапазон.',
1313
'Invalid e-mail message' => 'Email (т.е. [email protected]) или доменная часть (т.е. domain.com) введена неверно.',
14+
'Duplicate domain message' => 'Домен %s уже забанен.',
15+
'Duplicate e-mail message' => 'Email %s уже забанен.',
1416
'Invalid date message' => 'Вы ввели неправильную дату окончания.',
1517
'Invalid date reasons' => 'Дата должна быть в формате YYYY-MM-DD и должна быть не ранее, чем завтрашнее число.',
1618
'Ban added redirect' => 'Бан добавлен. Переадресация …' ,

0 commit comments

Comments
 (0)