diff -r a2b20a832447 -r 01955bf53f96 plugins/SpecialAdmin.php --- a/plugins/SpecialAdmin.php Sat Sep 08 15:06:28 2007 -0400 +++ b/plugins/SpecialAdmin.php Sat Sep 08 22:58:38 2007 -0400 @@ -860,19 +860,31 @@ // We need to update group memberships if ( $old_level == USER_LEVEL_ADMIN ) { + $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","u_from_admin",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($_POST['new_username']) . '");'); + if ( !$q ) + $db->_die(); $session->remove_user_from_group($user_id, GROUP_ID_ADMIN); } else if ( $old_level == USER_LEVEL_MOD ) { + $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","u_from_mod",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($_POST['new_username']) . '");'); + if ( !$q ) + $db->_die(); $session->remove_user_from_group($user_id, GROUP_ID_MOD); } if ( $new_level == USER_LEVEL_ADMIN ) { + $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","u_to_admin",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($_POST['new_username']) . '");'); + if ( !$q ) + $db->_die(); $session->add_user_to_group($user_id, GROUP_ID_ADMIN, false); } else if ( $new_level == USER_LEVEL_MOD ) { + $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES("security","u_to_mod",UNIX_TIMESTAMP(),"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '","' . $db->escape($_POST['new_username']) . '");'); + if ( !$q ) + $db->_die(); $session->add_user_to_group($user_id, GROUP_ID_MOD, false); } } @@ -2064,12 +2076,66 @@ } if(isset($_POST['create']) && !defined('ENANO_DEMO_MODE')) { - $q = 'INSERT INTO '.table_prefix.'banlist(ban_type,ban_value,reason,is_regex) VALUES( ' . $db->escape($_POST['type']) . ', \'' . $db->escape($_POST['value']) . '\', \''.$db->escape($_POST['reason']).'\''; - if(isset($_POST['regex'])) $q .= ', 1'; - else $q .= ', 0'; - $q .= ');'; - $e = $db->sql_query($q); - if(!$e) $db->_die('The banlist could not be updated.'); + $type = intval($_POST['type']); + $value = trim($_POST['value']); + if ( !in_array($type, array(BAN_IP, BAN_USER, BAN_EMAIL)) ) + { + echo '
Hacking attempt.
'; + } + else if ( empty($value) ) + { + echo '
Please enter something to ban.
'; + } + else + { + $entries = array(); + $input = explode(',', $_POST['value']); + $error = false; + foreach ( $input as $entry ) + { + $entry = trim($entry); + if ( empty($entry) ) + { + echo '
Malformed entry.
'; + $error = true; + break; + } + if ( $type == BAN_IP ) + { + // parse a range of addresses + $range = parse_ip_range($entry); + if ( !$range ) + { + $error = true; + echo '
Malformed IP address expression.
'; + break; + } + foreach ($range as $ip) + { + $entries[] = $ip; + } + } + else + { + $entries[] = $entry; + } + } + if ( !$error ) + { + $regex = ( isset($_POST['regex']) ) ? '1' : '0'; + $to_insert = array(); + $reason = $db->escape($_POST['reason']); + foreach ( $entries as $entry ) + { + $entry = $db->escape($entry); + $to_insert[] = "($type, '$entry', '$reason', $regex)"; + } + $q = 'INSERT INTO '.table_prefix."banlist(ban_type, ban_value, reason, is_regex)\n VALUES" . implode(",\n ", $to_insert) . ';'; + @set_time_limit(0); + $e = $db->sql_query($q); + if(!$e) $db->_die('The banlist could not be updated.'); + } + } } else if ( isset($_POST['create']) && defined('ENANO_DEMO_MODE') ) { @@ -2077,25 +2143,29 @@ } $q = $db->sql_query('SELECT ban_id,ban_type,ban_value,is_regex FROM '.table_prefix.'banlist ORDER BY ban_type;'); if(!$q) $db->_die('The banlist data could not be selected.'); - echo ''; + echo '
+
'; echo ''; - if($db->numrows() < 1) echo ''; + if($db->numrows() < 1) echo ''; + $cls = 'row2'; while($r = $db->fetchrow()) { + $cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; if($r['ban_type']==BAN_IP) $t = 'IP address'; elseif($r['ban_type']==BAN_USER) $t = 'Username'; elseif($r['ban_type']==BAN_EMAIL) $t = 'E-mail address'; if($r['is_regex']) $g = 'Yes'; else $g = 'No'; - echo ''; + echo ''; } $db->free_result(); - echo '
TypeValueRegular Expression
No ban rules yet.No ban rules yet.
'.$t.''.$r['ban_value'].''.$g.'Delete
'.$t.''.$r['ban_value'].''.$g.'Delete
'; + echo ''; echo '

Create new ban rule

'; echo '
'; ?> Type:
Rule:
- Reason to show to the banned user:
+ You can ban multiple IP addresses, users, or e-mail addresses by separating entries with a single comma (User1,User2). Do not put a space after the comma. For IP addresses, you may specify ranges like 172|192.168.4-30|90-167.1-90, which will turn into 172 and 192 . 168 . 4-30 and 90-167 . 1 - 90, which matches 18,899 IP addresses. Don't specify large ranges (like the example one here) at once or you risk temporarily (~60sec) overloading the server.
+ Reason to show to the banned user:
(advanced users only)