Просмотр файла admin/admin_user_ban.php

Размер файла: 11.6Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. define('IN_PHPBB', 1);
  7.  
  8. if ( !empty($setmodules) )
  9. {
  10. $filename = basename(__FILE__);
  11. $module['Users']['Ban_Management'] = $filename;
  12.  
  13. return;
  14. }
  15.  
  16. $phpbb_root_path = './../';
  17. require($phpbb_root_path . 'extension.inc');
  18. require('./pagestart.' . $phpEx);
  19.  
  20. if ( isset($HTTP_POST_VARS['submit']) )
  21. {
  22. $user_bansql = '';
  23. $email_bansql = '';
  24. $ip_bansql = '';
  25.  
  26. $user_list = array();
  27. if ( !empty($HTTP_POST_VARS['username']) )
  28. {
  29. $this_userdata = get_userdata($HTTP_POST_VARS['username'], true);
  30. if( !$this_userdata )
  31. {
  32. message_die(GENERAL_MESSAGE, $lang['No_user_id_specified'] );
  33. }
  34.  
  35. $user_list[] = $this_userdata['user_id'];
  36. }
  37.  
  38. $ip_list = array();
  39. if ( isset($HTTP_POST_VARS['ban_ip']) )
  40. {
  41. $ip_list_temp = explode(',', $HTTP_POST_VARS['ban_ip']);
  42.  
  43. for($i = 0; $i < count($ip_list_temp); $i++)
  44. {
  45. if ( preg_match('/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})[ ]*\-[ ]*([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/', trim($ip_list_temp[$i]), $ip_range_explode) )
  46. {
  47.  
  48. $ip_1_counter = $ip_range_explode[1];
  49. $ip_1_end = $ip_range_explode[5];
  50.  
  51. while ( $ip_1_counter <= $ip_1_end )
  52. {
  53. $ip_2_counter = ( $ip_1_counter == $ip_range_explode[1] ) ? $ip_range_explode[2] : 0;
  54. $ip_2_end = ( $ip_1_counter < $ip_1_end ) ? 254 : $ip_range_explode[6];
  55.  
  56. if ( $ip_2_counter == 0 && $ip_2_end == 254 )
  57. {
  58. $ip_2_counter = 255;
  59. $ip_2_fragment = 255;
  60.  
  61. $ip_list[] = encode_ip("$ip_1_counter.255.255.255");
  62. }
  63.  
  64. while ( $ip_2_counter <= $ip_2_end )
  65. {
  66. $ip_3_counter = ( $ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1] ) ? $ip_range_explode[3] : 0;
  67. $ip_3_end = ( $ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end ) ? 254 : $ip_range_explode[7];
  68.  
  69. if ( $ip_3_counter == 0 && $ip_3_end == 254 )
  70. {
  71. $ip_3_counter = 255;
  72. $ip_3_fragment = 255;
  73.  
  74. $ip_list[] = encode_ip("$ip_1_counter.$ip_2_counter.255.255");
  75. }
  76.  
  77. while ( $ip_3_counter <= $ip_3_end )
  78. {
  79. $ip_4_counter = ( $ip_3_counter == $ip_range_explode[3] && $ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1] ) ? $ip_range_explode[4] : 0;
  80. $ip_4_end = ( $ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end ) ? 254 : $ip_range_explode[8];
  81.  
  82. if ( $ip_4_counter == 0 && $ip_4_end == 254 )
  83. {
  84. $ip_4_counter = 255;
  85. $ip_4_fragment = 255;
  86.  
  87. $ip_list[] = encode_ip("$ip_1_counter.$ip_2_counter.$ip_3_counter.255");
  88. }
  89.  
  90. while ( $ip_4_counter <= $ip_4_end )
  91. {
  92. $ip_list[] = encode_ip("$ip_1_counter.$ip_2_counter.$ip_3_counter.$ip_4_counter");
  93. $ip_4_counter++;
  94. }
  95. $ip_3_counter++;
  96. }
  97. $ip_2_counter++;
  98. }
  99. $ip_1_counter++;
  100. }
  101. }
  102. else if ( preg_match('/^([\w\-_]\.?){2,}$/is', trim($ip_list_temp[$i])) )
  103. {
  104. $ip = gethostbynamel(trim($ip_list_temp[$i]));
  105.  
  106. for($j = 0; $j < count($ip); $j++)
  107. {
  108. if ( !empty($ip[$j]) )
  109. {
  110. $ip_list[] = encode_ip($ip[$j]);
  111. }
  112. }
  113. }
  114. else if ( preg_match('/^([0-9]{1,3})\.([0-9\*]{1,3})\.([0-9\*]{1,3})\.([0-9\*]{1,3})$/', trim($ip_list_temp[$i])) )
  115. {
  116. $ip_list[] = encode_ip(str_replace('*', '255', trim($ip_list_temp[$i])));
  117. }
  118. }
  119. }
  120.  
  121. $email_list = array();
  122. if ( isset($HTTP_POST_VARS['ban_email']) )
  123. {
  124. $email_list_temp = explode(',', $HTTP_POST_VARS['ban_email']);
  125.  
  126. for($i = 0; $i < count($email_list_temp); $i++)
  127. {
  128.  
  129. if (preg_match('/^(([a-z0-9&\'\.\-_\+])|(\*))+@(([a-z0-9\-])|(\*))+\.([a-z0-9\-]+\.)*?[a-z]+$/is', trim($email_list_temp[$i])))
  130. {
  131. $email_list[] = trim($email_list_temp[$i]);
  132. }
  133. }
  134. }
  135.  
  136. $sql = "SELECT *
  137. FROM " . BANLIST_TABLE;
  138. if ( !($result = $db->sql_query($sql)) )
  139. {
  140. message_die(GENERAL_ERROR, "Couldn't obtain banlist information", "", __LINE__, __FILE__, $sql);
  141. }
  142.  
  143. $current_banlist = $db->sql_fetchrowset($result);
  144. $db->sql_freeresult($result);
  145.  
  146. $kill_session_sql = '';
  147. for($i = 0; $i < count($user_list); $i++)
  148. {
  149. $in_banlist = false;
  150. for($j = 0; $j < count($current_banlist); $j++)
  151. {
  152. if ( $user_list[$i] == $current_banlist[$j]['ban_userid'] )
  153. {
  154. $in_banlist = true;
  155. }
  156. }
  157.  
  158. if ( !$in_banlist )
  159. {
  160. $kill_session_sql .= ( ( $kill_session_sql != '' ) ? ' OR ' : '' ) . "session_user_id = " . $user_list[$i];
  161.  
  162. $sql = "INSERT INTO " . BANLIST_TABLE . " (ban_userid)
  163. VALUES (" . $user_list[$i] . ")";
  164. if ( !$db->sql_query($sql) )
  165. {
  166. message_die(GENERAL_ERROR, "Couldn't insert ban_userid info into database", "", __LINE__, __FILE__, $sql);
  167. }
  168. }
  169. }
  170.  
  171. for($i = 0; $i < count($ip_list); $i++)
  172. {
  173. $in_banlist = false;
  174. for($j = 0; $j < count($current_banlist); $j++)
  175. {
  176. if ( $ip_list[$i] == $current_banlist[$j]['ban_ip'] )
  177. {
  178. $in_banlist = true;
  179. }
  180. }
  181.  
  182. if ( !$in_banlist )
  183. {
  184. if ( preg_match('/(ff\.)|(\.ff)/is', chunk_split($ip_list[$i], 2, '.')) )
  185. {
  186. $kill_ip_sql = "session_ip LIKE '" . str_replace('.', '', preg_replace('/(ff\.)|(\.ff)/is', '%', chunk_split($ip_list[$i], 2, "."))) . "'";
  187. }
  188. else
  189. {
  190. $kill_ip_sql = "session_ip = '" . $ip_list[$i] . "'";
  191. }
  192.  
  193. $kill_session_sql .= ( ( $kill_session_sql != '' ) ? ' OR ' : '' ) . $kill_ip_sql;
  194.  
  195. $sql = "INSERT INTO " . BANLIST_TABLE . " (ban_ip)
  196. VALUES ('" . $ip_list[$i] . "')";
  197. if ( !$db->sql_query($sql) )
  198. {
  199. message_die(GENERAL_ERROR, "Couldn't insert ban_ip info into database", "", __LINE__, __FILE__, $sql);
  200. }
  201. }
  202. }
  203.  
  204. if ( $kill_session_sql != '' )
  205. {
  206. $sql = "DELETE FROM " . SESSIONS_TABLE . "
  207. WHERE $kill_session_sql";
  208. if ( !$db->sql_query($sql) )
  209. {
  210. message_die(GENERAL_ERROR, "Couldn't delete banned sessions from database", "", __LINE__, __FILE__, $sql);
  211. }
  212. }
  213.  
  214. for($i = 0; $i < count($email_list); $i++)
  215. {
  216. $in_banlist = false;
  217. for($j = 0; $j < count($current_banlist); $j++)
  218. {
  219. if ( $email_list[$i] == $current_banlist[$j]['ban_email'] )
  220. {
  221. $in_banlist = true;
  222. }
  223. }
  224.  
  225. if ( !$in_banlist )
  226. {
  227. $sql = "INSERT INTO " . BANLIST_TABLE . " (ban_email)
  228. VALUES ('" . str_replace("\'", "''", $email_list[$i]) . "')";
  229. if ( !$db->sql_query($sql) )
  230. {
  231. message_die(GENERAL_ERROR, "Couldn't insert ban_email info into database", "", __LINE__, __FILE__, $sql);
  232. }
  233. }
  234. }
  235.  
  236. $where_sql = '';
  237.  
  238. if ( isset($HTTP_POST_VARS['unban_user']) )
  239. {
  240. $user_list = $HTTP_POST_VARS['unban_user'];
  241.  
  242. for($i = 0; $i < count($user_list); $i++)
  243. {
  244. if ( $user_list[$i] != -1 )
  245. {
  246. $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . intval($user_list[$i]);
  247. }
  248. }
  249. }
  250.  
  251. if ( isset($HTTP_POST_VARS['unban_ip']) )
  252. {
  253. $ip_list = $HTTP_POST_VARS['unban_ip'];
  254.  
  255. for($i = 0; $i < count($ip_list); $i++)
  256. {
  257. if ( $ip_list[$i] != -1 )
  258. {
  259. $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . str_replace("\'", "''", $ip_list[$i]);
  260. }
  261. }
  262. }
  263.  
  264. if ( isset($HTTP_POST_VARS['unban_email']) )
  265. {
  266. $email_list = $HTTP_POST_VARS['unban_email'];
  267.  
  268. for($i = 0; $i < count($email_list); $i++)
  269. {
  270. if ( $email_list[$i] != -1 )
  271. {
  272. $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . str_replace("\'", "''", $email_list[$i]);
  273. }
  274. }
  275. }
  276.  
  277. if ( $where_sql != '' )
  278. {
  279. $sql = "DELETE FROM " . BANLIST_TABLE . "
  280. WHERE ban_id IN ($where_sql)";
  281. if ( !$db->sql_query($sql) )
  282. {
  283. message_die(GENERAL_ERROR, "Couldn't delete ban info from database", "", __LINE__, __FILE__, $sql);
  284. }
  285. }
  286.  
  287. $message = $lang['Ban_update_sucessful'] . '<br /><br />' . sprintf($lang['Click_return_banadmin'], '<a href="' . append_sid("admin_user_ban.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
  288.  
  289. message_die(GENERAL_MESSAGE, $message);
  290.  
  291. }
  292. else
  293. {
  294. $template->set_filenames(array(
  295. 'body' => 'admin/user_ban_body.tpl')
  296. );
  297.  
  298. $template->assign_vars(array(
  299. 'L_BAN_TITLE' => $lang['Ban_control'],
  300. 'L_BAN_EXPLAIN' => $lang['Ban_explain'],
  301. 'L_BAN_EXPLAIN_WARN' => $lang['Ban_explain_warn'],
  302. 'L_IP_OR_HOSTNAME' => $lang['IP_hostname'],
  303. 'L_EMAIL_ADDRESS' => $lang['Email_address'],
  304. 'L_SUBMIT' => $lang['Submit'],
  305. 'L_RESET' => $lang['Reset'],
  306.  
  307. 'S_BANLIST_ACTION' => append_sid("admin_user_ban.$phpEx"))
  308. );
  309.  
  310. $template->assign_vars(array(
  311. 'L_BAN_USER' => $lang['Ban_username'],
  312. 'L_BAN_USER_EXPLAIN' => $lang['Ban_username_explain'],
  313. 'L_BAN_IP' => $lang['Ban_IP'],
  314. 'L_BAN_IP_EXPLAIN' => $lang['Ban_IP_explain'],
  315. 'L_BAN_EMAIL' => $lang['Ban_email'],
  316. 'L_BAN_EMAIL_EXPLAIN' => $lang['Ban_email_explain'])
  317. );
  318.  
  319. $userban_count = 0;
  320. $ipban_count = 0;
  321. $emailban_count = 0;
  322.  
  323. $sql = "SELECT b.ban_id, u.user_id, u.username
  324. FROM " . BANLIST_TABLE . " b, " . USERS_TABLE . " u
  325. WHERE u.user_id = b.ban_userid
  326. AND b.ban_userid <> 0
  327. AND u.user_id <> " . ANONYMOUS . "
  328. ORDER BY u.user_id ASC";
  329. if ( !($result = $db->sql_query($sql)) )
  330. {
  331. message_die(GENERAL_ERROR, 'Could not select current user_id ban list', '', __LINE__, __FILE__, $sql);
  332. }
  333.  
  334. $user_list = $db->sql_fetchrowset($result);
  335. $db->sql_freeresult($result);
  336.  
  337. $select_userlist = '';
  338. for($i = 0; $i < count($user_list); $i++)
  339. {
  340. $select_userlist .= '<option value="' . $user_list[$i]['ban_id'] . '">' . $user_list[$i]['username'] . '</option>';
  341. $userban_count++;
  342. }
  343.  
  344. if( $select_userlist == '' )
  345. {
  346. $select_userlist = '<option value="-1">' . $lang['No_banned_users'] . '</option>';
  347. }
  348.  
  349. $select_userlist = '<select name="unban_user[]" multiple="multiple" size="5">' . $select_userlist . '</select>';
  350.  
  351. $sql = "SELECT ban_id, ban_ip, ban_email
  352. FROM " . BANLIST_TABLE;
  353. if ( !($result = $db->sql_query($sql)) )
  354. {
  355. message_die(GENERAL_ERROR, 'Could not select current ip ban list', '', __LINE__, __FILE__, $sql);
  356. }
  357.  
  358. $banlist = $db->sql_fetchrowset($result);
  359. $db->sql_freeresult($result);
  360.  
  361. $select_iplist = '';
  362. $select_emaillist = '';
  363.  
  364. for($i = 0; $i < count($banlist); $i++)
  365. {
  366. $ban_id = $banlist[$i]['ban_id'];
  367.  
  368. if ( !empty($banlist[$i]['ban_ip']) )
  369. {
  370. $ban_ip = str_replace('255', '*', decode_ip($banlist[$i]['ban_ip']));
  371. $select_iplist .= '<option value="' . $ban_id . '">' . $ban_ip . '</option>';
  372. $ipban_count++;
  373. }
  374. else if ( !empty($banlist[$i]['ban_email']) )
  375. {
  376. $ban_email = $banlist[$i]['ban_email'];
  377. $select_emaillist .= '<option value="' . $ban_id . '">' . $ban_email . '</option>';
  378. $emailban_count++;
  379. }
  380. }
  381.  
  382. if ( $select_iplist == '' )
  383. {
  384. $select_iplist = '<option value="-1">' . $lang['No_banned_ip'] . '</option>';
  385. }
  386.  
  387. if ( $select_emaillist == '' )
  388. {
  389. $select_emaillist = '<option value="-1">' . $lang['No_banned_email'] . '</option>';
  390. }
  391.  
  392. $select_iplist = '<select name="unban_ip[]" multiple="multiple" size="5">' . $select_iplist . '</select>';
  393. $select_emaillist = '<select name="unban_email[]" multiple="multiple" size="5">' . $select_emaillist . '</select>';
  394.  
  395. $template->assign_vars(array(
  396. 'L_UNBAN_USER' => $lang['Unban_username'],
  397. 'L_UNBAN_USER_EXPLAIN' => $lang['Unban_username_explain'],
  398. 'L_UNBAN_IP' => $lang['Unban_IP'],
  399. 'L_UNBAN_IP_EXPLAIN' => $lang['Unban_IP_explain'],
  400. 'L_UNBAN_EMAIL' => $lang['Unban_email'],
  401. 'L_UNBAN_EMAIL_EXPLAIN' => $lang['Unban_email_explain'],
  402. 'L_USERNAME' => $lang['Username'],
  403. 'L_LOOK_UP' => $lang['Look_up_User'],
  404. 'L_FIND_USERNAME' => $lang['Find_username'],
  405.  
  406. 'U_SEARCH_USER' => append_sid("./../search.$phpEx?mode=searchuser"),
  407. 'S_UNBAN_USERLIST_SELECT' => $select_userlist,
  408. 'S_UNBAN_IPLIST_SELECT' => $select_iplist,
  409. 'S_UNBAN_EMAILLIST_SELECT' => $select_emaillist,
  410. 'S_BAN_ACTION' => append_sid("admin_user_ban.$phpEx"))
  411. );
  412. }
  413.  
  414. $template->pparse('body');
  415.  
  416. include('./page_footer_admin.'.$phpEx);
  417.  
  418. ?>