PageRenderTime 62ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 1ms

/forum/toolkit.php

https://bitbucket.org/publicwhip/publicwhip-v1
PHP | 9557 lines | 4487 code | 4340 blank | 730 comment | 973 complexity | b98b336b5cbd297f796aac673ee913d7 MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // PHPBB Admin ToolKit, v2.1b - Starfoxtj (starfoxtj@yahoo.com)
  3. // Copyright 2007 - Starfoxtj
  4. // This script is NOT released under the GPL:
  5. /*****************************************************************************************************
  6. By using this script you agree to the following:
  7. 1. You may modify any portion of this script for personal/business use. This includes changing the
  8. look, style, messages, functions, behavior etc. Note that any modifications outside of the standard
  9. configuration options may negatively affect the security of this script if the modification is not
  10. written properly and securely.
  11. Note: If the script has been modified, I ask that you at least retain the toolkit name, and
  12. my name (Starfoxtj), as a link to: http://starfoxtj.no-ip.com/phpbb/uploadtoolkit on the header
  13. or footer of every page. You are not required to list this information, but by removing it you may
  14. be forfeiting your support for this product. (Similar to the phpbb copyright agreement)
  15. 2. Ownership of this script remains with Starfoxtj regardless of how this script was acquired.
  16. 3. You may NOT sell any portion of this script, even if it is contained within another package
  17. without prior consent from Starfoxtj.
  18. 4. You may NOT hold Starfoxtj liable for any direct or indirect consequences of using this script.
  19. Many hours have been spent ensuring that this script is as secure as possible. However nothing
  20. can be 100% guaranteed.
  21. If a security hole has been found, please contact me immediately at: starfoxtj@yahoo.com
  22. 5. You MAY distribute this script stand alone, or with another package without any prior permission
  23. at no charge. You may NOT however, distribute this script if any modifications have been made
  24. without the consent of Starfoxtj. Meaning, only the unmodified original may be freely distributed
  25. (at no charge).
  26. I personally recommended you only download this script from:
  27. http://starfoxtj.no-ip.com/phpbb/toolkit
  28. If the script was downloaded form another location, it IS possible that it may have been altered.
  29. ******************************************************************************************************/
  30. // You may set a password here if you would rather not use the toolkit_config.php
  31. $use_toolkit_config_file = 'yes'; // Change this to 'No' to set the password in the toolkit.php itself like in previous releases
  32. $use_hashed_in_file_passwords = 'no'; // Change this if you want to use hashed admin/mod passwords specified in the toolkit (the toolkit_config.php file will use hashed passwords regardless)
  33. $adminpassword = 'ENTER_ADMIN_PASSWORD_HERE'; // Note: I HIGHLY recommend using a password at least 16 characters long!
  34. $modpassword = 'ENTER_MOD_PASSWORD_HERE'; // Leave blank to disable mod login
  35. // Option 1: Allow Mods to Ban/UnBan Users?
  36. $modban = 'yes'; // 'yes' : 'no'
  37. // Option 2: Allow Mods to Change User Post Count?
  38. $modpost = 'no'; // 'yes' : 'no'
  39. // Option 3: Allow Mods to Change User Ranks?
  40. $modrank = 'yes'; // 'yes' : 'no'
  41. // Option 4: Allow Mods to Delete Users?
  42. $moddelete = 'no'; // 'yes' : 'no'
  43. // Option 5: Update check URLs
  44. // Note: To disable checking for updates for phpbb, set the phpbb URL to 'none'
  45. // Note: To disable checking for updates for this toolkit, set the toolkit URL to 'none'
  46. // The default phpbb url is: http://www.phpbb.com/updatecheck/20x.txt
  47. // The default toolkit url is: http://starfoxtj.no-ip.com/phpBB/toolkit/updatecheck/2.x.txt
  48. $update_url['phpbb'] = 'http://www.phpbb.com/updatecheck/20x.txt';
  49. $update_url['toolkit'] = 'http://starfoxtj.no-ip.com/phpBB/toolkit/updatecheck/2.x.txt';
  50. // Lets begin the coding!
  51. //
  52. // (CHANGE INFORMATION AFTER THIS LINE WITH CAUTION!)
  53. //
  54. //
  55. //
  56. session_start();
  57. $_SESSION['toolkitversion'] = '2.1b';
  58. $_SESSION['toolkit_title'] = '<b><a href="index.php"><font size="5" color="#000000">PHPBB Admin ToolKit '.$_SESSION['toolkitversion'].'</b></font></a><font size="5"> - <a href="http://starfoxtj.no-ip.com/phpbb/toolkit" target="_blank">Starfoxtj</a></font>';
  59. $_SESSION['toolkit_title_nversion'] = '<b><a href="index.php"><font size="5" color="#000000">PHPBB Admin ToolKit</b></font></a><font size="5"> - <a href="http://starfoxtj.no-ip.com/phpbb/toolkit" target="_blank">Starfoxtj</a></font>';
  60. $_SESSION['copyrightfooter'] = '<br /><center><hr width="90%"><font size="2">PHPBB Admin ToolKit '.$_SESSION['toolkitversion'].' Š 2007 - <a href="mailto:starfoxtj@yahoo.com">Starfoxtj</a></font></center>';
  61. $phpbb_root_path = './';
  62. // Set global information and start db access
  63. if( file_exists( 'config.php' ) )
  64. {
  65. include( 'config.php' );
  66. if( $dbms == 'mysql' || $dbms == 'mysql4' )
  67. {
  68. $db = @mysql_connect("$dbhost", "$dbuser", "$dbpasswd")
  69. or die( 'Could not connect to database: '.mysql_error() );
  70. @mysql_select_db($dbname)
  71. or die( 'Could not select database: '.mysql_error() );
  72. }
  73. else
  74. {
  75. die( 'This toolkit is only compatible with MySQL databases.' );
  76. }
  77. }
  78. // Define Some Variables
  79. $index = $_SERVER['PHP_SELF'];
  80. $domain = $_SERVER['SERVER_NAME'];
  81. $full_domain = 'http://'.$domain;
  82. if( file_exists( 'config.php' ) )
  83. {
  84. $phpbb_auth_access = $table_prefix."auth_access";
  85. $phpbb_config = $table_prefix."config";
  86. $phpbb_banlist = $table_prefix."banlist";
  87. $phpbb_users = $table_prefix."users";
  88. $phpbb_ranks = $table_prefix."ranks";
  89. $phpbb_vote_voters = $table_prefix."vote_voters";
  90. $phpbb_user_group = $table_prefix."user_group";
  91. $phpbb_groups = $table_prefix."groups";
  92. $phpbb_posts = $table_prefix."posts";
  93. $phpbb_posts_text = $table_prefix."posts_text";
  94. $phpbb_topics = $table_prefix."topics";
  95. $phpbb_forums = $table_prefix."forums";
  96. $phpbb_themes = $table_prefix."themes";
  97. $phpbb_themes_name = $table_prefix."themes_name";
  98. $phpbb_sessions = $table_prefix."sessions";
  99. $phpbb_sessions_keys = $table_prefix."sessions_keys";
  100. $phpbb_topics_watch = $table_prefix."topics_watch";
  101. $phpbb_privmsgs = $table_prefix."privmsgs";
  102. $phpbb_privmsgs_text = $table_prefix."privmsgs_text";
  103. $phpbb_version_result = mysql_query("SELECT * FROM $phpbb_config WHERE config_name='version'")
  104. or die( 'MySQL Error: '.mysql_error() );
  105. $myrow_phpbb_version = mysql_fetch_array($phpbb_version_result);
  106. $phpbb_version = $myrow_phpbb_version['config_value'];
  107. }
  108. $script_folder = substr( $index, 1, -(strlen( end( explode( '/', $index ) ) ) + 1 ) );
  109. // Set the errors to only display one of each error
  110. if( isset( $_SESSION['errors']['index'] ) )
  111. {
  112. $_SESSION['errors']['index'] = array_unique( $_SESSION['errors']['index'] );
  113. }
  114. if( isset( $_SESSION['errors']['edituser'] ) )
  115. {
  116. $_SESSION['errors']['edituser'] = array_unique( $_SESSION['errors']['edituser'] );
  117. }
  118. if( isset( $_SESSION['errors']['config'] ) )
  119. {
  120. $_SESSION['errors']['config'] = array_unique( $_SESSION['errors']['config'] );
  121. }
  122. /////////////////////////////////////////
  123. //
  124. // Check and Create config.php
  125. //
  126. if( !file_exists( 'config.php' ) )
  127. { //-.2-a
  128. if( isset( $_POST['configphp_setup'] ) )
  129. { //-.1-a.1
  130. if( $_POST['dbhost'] == '' ||
  131. $_POST['dbuser'] == '' ||
  132. $_POST['dbpasswd'] == '' ||
  133. $_POST['dbname'] == '' )
  134. {
  135. $_SESSION['configphp_error'] = '<b>Error:</b> All fields must be filled in.';
  136. header( "Location: $index" );
  137. die();
  138. }
  139. @chmod( "../$script_folder", 0777 )
  140. or die( "Could not CHMOD $script_folder folder to create config.php!<br />
  141. You can either change the CHMOD settings manually to 777, or create the config.php file by copying the following information
  142. into notepad and specifying the database settings. Then save it as \"config.php\" and upload it to your $script_folder folder.<br /><br />
  143. Note: This assumes you are using MySQL4, if you are using MySQL3, replace \"mysql4\" with \"mysql\".<br /><br />
  144. <table border=\"0\" width=\"400\" cellpadding=\"5\"; style=\"border-top: black 1px solid; border-right: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid\" bgcolor=\"#f5f5f5\">
  145. <tr>
  146. <td>
  147. <b>&lt;?php<br /><br />
  148. // phpBB 2.x auto-generated config file<br />
  149. // Do not change anything in this file!<br /><br />
  150. \$dbms = 'mysql4';<br /><br />
  151. \$dbhost = '<font color=\"#ff0000\">Your Host</font>';<br />
  152. \$dbname = '<font color=\"#ff0000\">Your Database Name</font>';<br />
  153. \$dbuser = '<font color=\"#ff0000\">Your Username</font>';<br />
  154. \$dbpasswd = '<font color=\"#ff0000\">Your Password</font>';<br /><br />
  155. \$table_prefix = 'phpbb_';<br /><br />
  156. define('PHPBB_INSTALLED', true);<br /><br />
  157. ?&gt;</b>
  158. </td>
  159. </tr>
  160. </table>" );
  161. @touch( 'config.php' )
  162. or die( "Could not create config.php!<br />
  163. You can either change the CHMOD settings manually to 777, or create the config.php file by copying the following information
  164. into notepad and specifying the database settings. Then save it as \"config.php\" and upload it to your $script_folder folder.<br /><br />
  165. Note: This assumes you are using MySQL4, if you are using MySQL3, replace \"mysql4\" with \"mysql\".<br /><br />
  166. <table border=\"0\" width=\"400\" cellpadding=\"5\"; style=\"border-top: black 1px solid; border-right: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid\" bgcolor=\"#f5f5f5\">
  167. <tr>
  168. <td>
  169. <b>&lt;?php<br /><br />
  170. // phpBB 2.x auto-generated config file<br />
  171. // Do not change anything in this file!<br /><br />
  172. \$dbms = 'mysql4';<br /><br />
  173. \$dbhost = '<font color=\"#ff0000\">Your Host</font>';<br />
  174. \$dbname = '<font color=\"#ff0000\">Your Database Name</font>';<br />
  175. \$dbuser = '<font color=\"#ff0000\">Your Username</font>';<br />
  176. \$dbpasswd = '<font color=\"#ff0000\">Your Password</font>';<br /><br />
  177. \$table_prefix = 'phpbb_';<br /><br />
  178. define('PHPBB_INSTALLED', true);<br /><br />
  179. ?&gt;</b>
  180. </td>
  181. </tr>
  182. </table>" );
  183. $fp = fopen( 'config.php', "w" )
  184. or die ("The file config.php exists but could not be opened. Check the file permissions." );
  185. $dbms = $_POST['dbms'];
  186. $dbhost = $_POST['dbhost'];
  187. $dbuser = $_POST['dbuser'];
  188. $dbpasswd = $_POST['dbpasswd'];
  189. $dbname = $_POST['dbname'];
  190. $table_prefix = $_POST['table_prefix'];
  191. fwrite( $fp, "<?php
  192. // phpBB 2.x auto-generated config file
  193. // Do not change anything in this file!
  194. \$dbms = '$dbms';
  195. \$dbhost = '$dbhost';
  196. \$dbname = '$dbname';
  197. \$dbuser = '$dbuser';
  198. \$dbpasswd = '$dbpasswd';
  199. \$table_prefix = '$table_prefix';
  200. define('PHPBB_INSTALLED', true);
  201. ?>" );
  202. fclose( $fp );
  203. chmod( "../$script_folder", 0755 );
  204. header( "Location: $index" );
  205. die();
  206. } //-.1-a.1
  207. else
  208. { //-.1-a.2
  209. session_destroy();
  210. ?>
  211. <html>
  212. <head>
  213. <title>PHPBB Admin ToolKit v<?php echo $_SESSION['toolkitversion']; ?></title>
  214. <SCRIPT LANGUAGE="JavaScript">
  215. function placeFocus() {
  216. if (document.forms.length > 0) {
  217. var field = document.forms[0];
  218. for (i = 1; i < field.length; i++) {
  219. if ((field.elements[i].name == "dbhost") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
  220. document.forms[0].elements[i].focus();
  221. break;
  222. }
  223. }
  224. }
  225. }
  226. </script>
  227. </head>
  228. <body link="#0000ff" vlink="#0000ff" alink="#0000ff" OnLoad="placeFocus()">
  229. <center>
  230. <table border="0" bgcolor="#ffffff" cellspacing="1" cellpadding="3">
  231. <tr><td><div align="center"><?php echo $_SESSION['toolkit_title']; ?></div></td></tr>
  232. </table><br />
  233. </center>
  234. <center>
  235. <font size="4">PHPBB Admin ToolKit: Create Config.php file</font>
  236. <br /><br />
  237. Config.php file not found! You may create a new one by entering in the information below:<br /><br />
  238. <table border="0" bgcolor="#ffffff" cellspacing="1" cellpadding="3">
  239. <tr>
  240. <td>
  241. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  242. <table border="0" cellpadding="5" cellspacing="0">
  243. <tr>
  244. <td>
  245. Database Type:
  246. </td>
  247. <td>
  248. <select name="dbms">
  249. <option value="mysql">MySQL 3.x</option>
  250. <option value="mysql4" selected>MySQL 4.x</option>
  251. <option value="postgres">PostgreSQL 7.x</option>
  252. <option value="mssql">MS SQL Server 7/2000</option>
  253. <option value="msaccess">MS Access [ ODBC ]</option>
  254. <option value="mssql-odbc">MS SQL Server [ ODBC ]</option></select>
  255. </td>
  256. </tr>
  257. <tr>
  258. <td>
  259. Host:
  260. </td>
  261. <td>
  262. <input type="text" name="dbhost" lengh="20" size="20" maxlengh="255">
  263. </td>
  264. </tr>
  265. <tr>
  266. <td>
  267. Username:
  268. </td>
  269. <td>
  270. <input type="text" name="dbuser" lengh="20" size="20" maxlengh="255">
  271. </td>
  272. </tr>
  273. <tr>
  274. <td>
  275. Password:
  276. </td>
  277. <td>
  278. <input type="password" name="dbpasswd" lengh="20" size="20" maxlengh="255">
  279. </td>
  280. </tr>
  281. <tr>
  282. <td>
  283. Database:
  284. </td>
  285. <td>
  286. <input type="text" name="dbname" lengh="20" size="20" maxlengh="255">
  287. </td>
  288. </tr>
  289. <tr>
  290. <td>
  291. Table Prefix:
  292. </td>
  293. <td>
  294. <input type="text" name="table_prefix" value="phpbb_" lengh="20" size="20" maxlengh="255">
  295. </td>
  296. </tr>
  297. <tr>
  298. <td colspan="2" align="center">
  299. <input type="hidden" name="configphp_setup" value="1" />
  300. <br /><input TYPE="submit" VALUE="Create Config.php">
  301. </td>
  302. </tr>
  303. </table>
  304. </form>
  305. </td>
  306. </tr>
  307. </table>
  308. </center>
  309. <?php
  310. if( isset( $_SESSION['configphp_error'] ) )
  311. {
  312. ?>
  313. <center>
  314. <table border="0" bgcolor="#ffffff" cellspacing="1" cellpadding="3">
  315. <tr>
  316. <td>
  317. <br /><br /><?php echo $_SESSION['configphp_error']; ?>
  318. </td>
  319. </tr>
  320. </table>
  321. <?php
  322. }
  323. ?>
  324. </body>
  325. </html>
  326. <?php
  327. } //-.1-a.2
  328. die();
  329. } //-.2-a
  330. /////////////////////////////////////////
  331. //
  332. // Check and set fist time password
  333. //
  334. if( !file_exists( 'toolkit_config.php' ) && $use_toolkit_config_file == 'yes' )
  335. { //-.1-a
  336. if( isset( $_POST['toolkitconfig_setup'] ) )
  337. { //-.1-a.1
  338. if( !isset( $_POST['admin_password'] ) || !isset( $_POST['admin_password_confirm'] ) )
  339. {
  340. $_SESSION['toolkitconfig_error'] = '<b>Error:</b> Either the admin password was not specified, or the passwords did not match.';
  341. header( "Location: $index" );
  342. die();
  343. }
  344. elseif( $_POST['admin_password'] == '' || $_POST['admin_password_confirm'] == '' )
  345. {
  346. $_SESSION['toolkitconfig_error'] = '<b>Error:</b> Either the admin password was not specified, or the passwords did not match.';
  347. header( "Location: $index" );
  348. die();
  349. }
  350. elseif( $_POST['admin_password'] != $_POST['admin_password_confirm'] )
  351. {
  352. $_SESSION['toolkitconfig_error'] = '<b>Error:</b> The admin passwords do not match.';
  353. header( "Location: $index" );
  354. die();
  355. }
  356. if( $_POST['mod_password'] != $_POST['mod_password_confirm'] )
  357. {
  358. $_SESSION['toolkitconfig_error'] = '<b>Error:</b> The mod passwords do not match.';
  359. header( "Location: $index" );
  360. die();
  361. }
  362. @chmod( "../$script_folder", 0777 )
  363. or die( "Could not CHMOD $script_folder to 777 to create toolkit_config.php!<br />
  364. 1: Extract the toolkit.php file and open it with notepad.<br />
  365. 2: Find \"\$use_toolkit_config_file\" on line 40.<br />
  366. 3: Change the 'yes' to 'no'.<br />
  367. 4: Replace both the admin and mod passwords on lines 41 and 42<br />
  368. 5: Upload toolkit.php to your $script_folder folder." );
  369. @touch( 'toolkit_config.php' )
  370. or die( "Could not create toolkit_config.php, access denied!<br />
  371. Please install this script using method 2:<br /><br />
  372. 1: Extract the toolkit.php file and open it with notepad.<br />
  373. 2: Find \"\$use_toolkit_config_file\" on line 40.<br />
  374. 3: Change the 'yes' to 'no'.<br />
  375. 4: Replace both the admin and mod passwords on lines 41 and 42<br />
  376. 5: Upload toolkit.php to your $script_folder folder." );
  377. $fp = fopen( 'toolkit_config.php', "w" )
  378. or die ("The file toolkit_config.php exists but could not be opened. Check the file permissions." );
  379. $version = $_SESSION['toolkitversion'];
  380. $adminpassword = md5( md5( $_POST['admin_password'] ) );
  381. $modpassword = md5( md5( $_POST['mod_password'] ) );
  382. fwrite( $fp, "<?php
  383. ////////////////////////////////////////////////////////////
  384. //
  385. // PHPBB Admin ToolKit v$version auto-generated config file.
  386. //
  387. // You may change the passwords in this file.
  388. // Note: The passwords in this file are hashed for security.
  389. // If you need to change your passwords, you can either use the MD5 Generator included
  390. // near the bottom of the toolkit index.
  391. // Or you can simply delete this toolkit_config.php file and run toolkit.php
  392. // to recreate this file with the new passwords.
  393. //
  394. // NOTE: For security, the passwords for this toolkit have been DOUBLE hashed!
  395. // Meaning, the password was hashed once using the md5() function, then the hash
  396. // was hashed again using the md5() function. The code equivalent is: \$pass = md5( md5( 'password' ) );
  397. // Because the password is double hashed, it should be almost completely uncrackable as
  398. // a brute force/dictionary attack would have to first crack a 32 character password, THEN
  399. // crack the result yielding the original password.
  400. // This way, even if someone got your toolkit.config.php file it would in theory
  401. // take the most powerful home computer over 10 years to break.
  402. //
  403. \$adminpassword = '$adminpassword';
  404. \$modpassword = '$modpassword';
  405. ?>" );
  406. fclose( $fp );
  407. chmod( "../$script_folder", 0755 );
  408. header( "Location: $index" );
  409. die();
  410. } //-.1-a.1
  411. else
  412. { //-.1-a.2
  413. session_destroy();
  414. ?>
  415. <html>
  416. <head>
  417. <title>PHPBB Admin ToolKit v<?php echo $_SESSION['toolkitversion']; ?></title>
  418. <SCRIPT LANGUAGE="JavaScript">
  419. function placeFocus() {
  420. if (document.forms.length > 0) {
  421. var field = document.forms[0];
  422. for (i = 0; i < field.length; i++) {
  423. if ((field.elements[i].name == "admin_password") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
  424. document.forms[0].elements[i].focus();
  425. break;
  426. }
  427. }
  428. }
  429. }
  430. </script>
  431. </head>
  432. <body link="#0000ff" vlink="#0000ff" alink="#0000ff" OnLoad="placeFocus()">
  433. <center>
  434. <table border="0" bgcolor="#ffffff" cellspacing="1" cellpadding="3">
  435. <tr><td><div align="center"><?php echo $_SESSION['toolkit_title']; ?></div></td></tr>
  436. </table><br />
  437. </center>
  438. <center>
  439. <font size="4">PHPBB Admin ToolKit: First Time Setup</font><br />
  440. <table border="0" bgcolor="#ffffff" cellspacing="1" cellpadding="3">
  441. <tr>
  442. <td>
  443. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  444. <table border="0" cellpadding="5" cellspacing="0">
  445. <tr>
  446. <td>
  447. Specify Admin Password:
  448. </td>
  449. <td>
  450. <input type="password" name="admin_password" lengh="20" size="20" maxlengh="255">
  451. </td>
  452. </tr>
  453. <tr>
  454. <td>
  455. Confirm Admin Password:
  456. </td>
  457. <td>
  458. <input type="password" name="admin_password_confirm" lengh="20" size="20" maxlengh="255">
  459. </td>
  460. </tr>
  461. <tr>
  462. <td>
  463. <br />Specify ModPassword:
  464. </td>
  465. <td>
  466. <br /><input type="password" name="mod_password" lengh="20" size="20" maxlengh="255"> (Optional)
  467. </td>
  468. </tr>
  469. <tr>
  470. <td>
  471. Confirm Mod Password:
  472. </td>
  473. <td>
  474. <input type="password" name="mod_password_confirm" lengh="20" size="20" maxlengh="255"> (Optional)
  475. </td>
  476. </tr>
  477. <tr>
  478. <td colspan="2" align="center">
  479. <input type="hidden" name="toolkitconfig_setup" value=1 />
  480. <br /><input TYPE="submit" VALUE=" Enter ">
  481. </td>
  482. </tr>
  483. </table>
  484. </form>
  485. </td>
  486. </tr>
  487. </table>
  488. </center>
  489. <?php
  490. if( isset( $_SESSION['toolkitconfig_error'] ) )
  491. {
  492. ?>
  493. <center>
  494. <table border="0" bgcolor="#ffffff" cellspacing="1" cellpadding="3">
  495. <tr>
  496. <td>
  497. <br /><br /><?php echo $_SESSION['toolkitconfig_error']; ?>
  498. </td>
  499. </tr>
  500. </table>
  501. <?php
  502. }
  503. ?>
  504. </body>
  505. </html>
  506. <?php
  507. } //-.1-a.2
  508. die();
  509. } //-.1-a
  510. elseif( file_exists( 'toolkit_config.php' ) && $use_toolkit_config_file == 'yes' )
  511. {
  512. include( 'toolkit_config.php' );
  513. }
  514. if( !isset( $_SESSION['user_level'] ) )
  515. { //-.1
  516. $_SESSION['user_level'] = "null";
  517. } //-.1
  518. if( !isset( $_SESSION['AUTH'] ) )
  519. {
  520. $_SESSION['AUTH'] = array();
  521. }
  522. // Safe SQL data function
  523. function safe_sql( $data )
  524. {
  525. if ( get_magic_quotes_gpc() )
  526. {
  527. $data = stripslashes( $data );
  528. }
  529. if( phpversion() >= 4.3 )
  530. {
  531. $data = mysql_real_escape_string( $data );
  532. }
  533. else
  534. {
  535. $data = mysql_escape_string( $data );
  536. }
  537. $data = str_replace( '&', '&amp;', $data );
  538. $data = str_replace( '<', '&lt;', $data );
  539. $data = str_replace( '>', '&gt;', $data );
  540. return $data;
  541. }
  542. function safe_html( $data )
  543. {
  544. $data = trim( $data );
  545. $data = str_replace( '&', '&amp;', $data );
  546. $data = str_replace( '<', '&lt;', $data );
  547. $data = str_replace( '>', '&gt;', $data );
  548. return $data;
  549. }
  550. // Safe descriptions data function
  551. function safe_desc( $data )
  552. {
  553. $data = str_replace( '&', '&amp;', $data );
  554. $data = str_replace( '<', '&lt;', $data );
  555. $data = str_replace( '>', '&gt;', $data );
  556. return $data;
  557. }
  558. // make_time function
  559. function make_time( $time )
  560. {
  561. // Set error value to false as no errors are generated yet
  562. $error = false;
  563. // Set vals to proper "type" (int)
  564. $mm = intval( $time['mm'] );
  565. $dd = intval( $time['dd'] );
  566. $yy = intval( $time['yy'] );
  567. $time_hh = intval( $time['time_hh'] );
  568. $time_mm = intval( $time['time_mm'] );
  569. $time_ss = intval( $time['time_ss'] );
  570. // Pad vals with leading zeros if single digets
  571. $mm = sprintf( "%02d", $mm );
  572. $dd = sprintf( "%02d", $dd );
  573. $yy = sprintf( "%02d", $yy );
  574. $time_hh = sprintf( "%02d", $time_hh );
  575. $time_mm = sprintf( "%02d", $time_mm );
  576. $time_ss = sprintf( "%02d", $time_ss );
  577. $time_ap = $time['time_ap'];
  578. // First check if specified date is a correct one
  579. if( !checkdate( $mm, $dd, $yy ) )
  580. {
  581. $_SESSION['errors']['make_time'][] = 'You have entered an invalid date combination.';
  582. $error = true;
  583. return false;
  584. }
  585. // Check if year is after 1970 (because thats when the timestamp starts)
  586. if( $yy < 1970 )
  587. {
  588. $_SESSION['errors']['make_time'][] = 'Due to the Unix timestamp restriction, the year must not be before 1970.';
  589. $error = true;
  590. return false;
  591. }
  592. // Now perform various checks on the time info
  593. if(
  594. (
  595. $time_hh > 12 ||
  596. $time_hh < 1 ||
  597. $time_mm > 60 ||
  598. $time_ss < 0 ||
  599. $time_ss > 60 ||
  600. $time_mm < 0
  601. )
  602. ||
  603. (
  604. $time_ap != 'pm' &&
  605. $time_ap != 'am'
  606. ) )
  607. {
  608. $_SESSION['errors']['make_time'][] = 'You have entered an invalid time.';
  609. $error = true;
  610. return false;
  611. }
  612. // Generate timestamp
  613. if( $time_ap == 'pm' )
  614. {
  615. $time_hh += 12;
  616. }
  617. if( $error == false )
  618. {
  619. $time = mktime( $time_hh, $time_mm, $time_ss, $mm, $dd, $yy );
  620. return $time;
  621. }
  622. }
  623. // Delete user core function
  624. // Only the actual sql queries are here, the checks and options are in the delete_user() function
  625. function delete_user_core( $user_id, $clear_posts = false, $retain_pms = false )
  626. {
  627. // Set global variables
  628. global $index;
  629. global $phpbb_version;
  630. global $phpbb_banlist;
  631. global $phpbb_user_group;
  632. global $phpbb_users;
  633. global $phpbb_groups;
  634. global $phpbb_posts;
  635. global $phpbb_posts_text;
  636. global $phpbb_topics;
  637. global $phpbb_vote_voters;
  638. global $phpbb_auth_access;
  639. global $phpbb_sessions;
  640. global $phpbb_sessions_keys;
  641. global $phpbb_privmsgs;
  642. global $phpbb_privmsgs_text;
  643. global $phpbb_topics_watch;
  644. // First things first, sanitize the $user_id
  645. $user_id = safe_sql( $user_id);
  646. //
  647. // Obtain username and level based on user_id
  648. //
  649. $sql = "SELECT * FROM $phpbb_users WHERE user_id=$user_id LIMIT 1";
  650. $result = mysql_query($sql);
  651. $myrow = mysql_fetch_array($result);
  652. $username = safe_sql( $myrow['username'] );
  653. $user_level = safe_sql( $myrow['user_level'] );
  654. // Obtain first admin account to set as group mod if deleted user is a group mod (step 5)
  655. $sql = "SELECT * FROM $phpbb_users WHERE user_level=1 ORDER BY user_id ASC LIMIT 1";
  656. $result = mysql_query($sql);
  657. $myrow = mysql_fetch_array($result);
  658. $admin_id= safe_sql( $myrow['user_id'] );
  659. // Debug info:
  660. // echo '<pre>';
  661. // echo gettype( $myrow );
  662. // die( $admin_id );
  663. // This actually starts the delete process
  664. // **************************************************************
  665. //
  666. // First sql query is to collect group information about the user
  667. //
  668. // **************************************************************
  669. $sql = "SELECT g.group_id FROM $phpbb_user_group ug, $phpbb_groups g WHERE ug.user_id = $user_id AND g.group_id = ug.group_id AND g.group_single_user = 1";
  670. $result = mysql_query($sql);
  671. $row = mysql_fetch_array($result);
  672. unset( $row[0] ); // Read note directly below about this line:
  673. // PHPBB's $row = $db->sql_fetchrow($result); line returns an array containg the user id:
  674. // Array
  675. // (
  676. // [group_id] => 123
  677. // )
  678. // The mqsql fetch array used in this scrip: $myrow = mysql_fetch_array($result);
  679. // Returns the following:
  680. // Array
  681. // (
  682. // [0] => 123
  683. // [group_id] => 123
  684. // )
  685. // Therefore I unset the $row[0] element
  686. // Debugging info:
  687. // echo '<pre>';
  688. // print_r( $row );
  689. // echo"\n\n$username";
  690. // die();
  691. // ***************************************************************************
  692. //
  693. // Second sql query sets the poster id to the anonymous account for all posts
  694. // First query in this section is for the $clear_posts variable
  695. //
  696. // ***************************************************************************
  697. //
  698. // This check fixes the:
  699. // Error deleting user's group from groups table:
  700. // Line: 1477
  701. // File: /toolkit.php
  702. // Query: DELETE FROM `phpbb_groups` WHERE `group_id`=
  703. // MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
  704. //
  705. // Error message that was appearing in v2.1a because the returned value of $row was not correct
  706. // Debug for numeric check
  707. /* echo '<pre>';
  708. var_dump( $row );
  709. $i = is_numeric( '2 3' );
  710. var_dump( $i );
  711. die(); */
  712. if( !is_numeric( $row['group_id'] ) )
  713. {
  714. echo '<font size="4"><b>An incorrect value has been returned for group_id in the \'phpbb_groups\' table:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF'].'<br /><b>User ID: </b>'.$user_id.'<br /><b>Username: </b>'.$username.'<br /><b>Details:</b> This value should be a purely numeric integer. The value returned by the database is:<br /><pre>';
  715. var_dump( $row );
  716. echo '</pre><br />Please contact Starfoxtj at <a href="http://starfoxtj.no-ip.com">http://starfoxtj.no-ip.com</a> and report this error.';
  717. echo '<br /><br /><b>Note: </b> The script has halted before any changes to the database were made for this specific user.<br />All other users that were deleted before <b>'.$username.'</b> were properly removed.';
  718. echo '<br /><br /><b>Full envoirment details:</b><br /><pre>';
  719. var_dump( get_defined_vars() );
  720. die();
  721. }
  722. // If clear posts is set to true, replace all posts made by user to "DELETED"
  723. if( $clear_posts == true )
  724. {
  725. $sql = "SELECT `post_id` FROM `$phpbb_posts` WHERE `poster_id`=$user_id";
  726. if( !$result = mysql_query( $sql ) )
  727. {
  728. die( '<font size="4"><b>Error selecting selecting posts to clear:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  729. }
  730. // Assings the results of the above query into an array
  731. while($myrow = mysql_fetch_array($result))
  732. {
  733. $marked_posts[] = $myrow['post_id'];
  734. }
  735. // Makes mark an empty array if the user has no PMs
  736. if( !isset( $marked_posts ) )
  737. {
  738. $marked_posts = array();
  739. }
  740. // First check to see if user has any posts, if not skip replacing the posts
  741. if( isset( $marked_posts ) && count( $marked_posts ) )
  742. {
  743. $marked_posts = implode( ',', $marked_posts );
  744. $sql = "UPDATE `$phpbb_posts_text` SET `post_text`='DELETED' WHERE `post_id` IN ( $marked_posts )";
  745. // echo '<pre>';
  746. // echo $sql;
  747. // echo '<br />';
  748. // print_r( $marked_posts );
  749. // die();
  750. if( !$result = mysql_query( $sql ) )
  751. {
  752. die( '<font size="4"><b>Error setting posts to DELETED:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  753. }
  754. }
  755. // Sets the poster id to the anonymous account for all posts and replaces the username with DELETED
  756. $sql = "UPDATE `$phpbb_posts` SET `poster_id`=-1, `post_username`='DELETED' WHERE `poster_id`=$user_id";
  757. if( !$result = mysql_query( $sql ) )
  758. {
  759. die( '<font size="4"><b>Error setting poster id to anonymous for deleted user:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  760. }
  761. }
  762. else
  763. {
  764. // Sets the poster id to the anonymous account for all posts, but retains the original username
  765. $sql = "UPDATE `$phpbb_posts` SET `poster_id`=-1, `post_username`='".str_replace( "\\'", "''", addslashes( $username ) )."' WHERE `poster_id`=$user_id";
  766. if( !$result = mysql_query( $sql ) )
  767. {
  768. die( '<font size="4"><b>Error setting poster id to anonymous for deleted user:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  769. }
  770. }
  771. // ***************************************************************************
  772. //
  773. // Third sql query sets the topic id to the anonymous account for all topics
  774. //
  775. // ***************************************************************************
  776. // If clear posts is set to true, replace all topics made by user to "DELETED"
  777. if( $clear_posts == true )
  778. {
  779. $sql = "UPDATE `$phpbb_topics` SET `topic_title`='DELETED' WHERE `topic_poster`=$user_id";
  780. if( !$result = mysql_query( $sql ) )
  781. {
  782. die( '<font size="4"><b>Error setting topics to DELETED:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  783. }
  784. // Sets the topic id to the anonymous account for all topics and replaces the username with DELETED
  785. $sql = "UPDATE `$phpbb_topics` SET `topic_poster`=-1 WHERE `topic_poster`=$user_id";
  786. if( !$result = mysql_query( $sql ) )
  787. {
  788. die( '<font size="4"><b>Error setting topic id poster to anonymous for deleted user:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  789. }
  790. }
  791. else
  792. {
  793. // Sets the poster id to the anonymous account for all posts, but retains the original username
  794. $sql = "UPDATE `$phpbb_topics` SET `topic_poster`=-1 WHERE `topic_poster`=$user_id";
  795. if( !$result = mysql_query( $sql ) )
  796. {
  797. die( '<font size="4"><b>Error setting topic id poster to anonymous for deleted user:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  798. }
  799. }
  800. // ***************************************************************************
  801. //
  802. // Fourth sql query sets the voter id to anonymous
  803. //
  804. // ***************************************************************************
  805. $sql = "UPDATE `$phpbb_vote_voters` SET `vote_user_id`=-1 WHERE `vote_user_id`=$user_id";
  806. if( !$result = mysql_query( $sql ) )
  807. {
  808. die( '<font size="4"><b>Error setting voter ID to anonymous:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  809. }
  810. // ***************************************************************************
  811. //
  812. // Fifth sql query collects the phpbb_groups info and assigns it to the
  813. // $group_mods array where the user is a moderator
  814. //
  815. // ***************************************************************************
  816. $sql = "SELECT `group_id` FROM `$phpbb_groups` WHERE `group_moderator`=$user_id";
  817. if( !$result = mysql_query( $sql ) )
  818. {
  819. die( '<font size="4"><b>Error selecting groups where user is a moderator:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  820. }
  821. // Assings the results of the above query into an array
  822. while($myrow = mysql_fetch_array($result))
  823. {
  824. $group_mod[] = $myrow['group_id'];
  825. }
  826. // Debugging info:
  827. // echo '<pre>';
  828. // print_r( $group_mod );
  829. // die();
  830. // If the user is a moderator for any groups, this query assigns the
  831. // new mod status to the oldest admin account
  832. if( isset( $group_mod ) && count( $group_mod ) )
  833. {
  834. //
  835. // Make SURE to insert a query here to check for the first admin account to associate as the new group moderator
  836. // after the deleted user is deleted!
  837. // Done
  838. // $admin_id = 3; //This is a temp static admin id that will be dymamic in the final release
  839. $update_mod_id = implode( ',', $group_mod );
  840. $sql = "UPDATE `$phpbb_groups` SET `group_moderator`=$admin_id WHERE `group_moderator` IN ( $update_mod_id )";
  841. // Debugging info:
  842. // echo '<pre>';
  843. // echo $sql;
  844. // die();
  845. if( !$result = mysql_query( $sql ) )
  846. {
  847. die( '<font size="4"><b>Error setting new group moderator to oldest admin:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  848. }
  849. }
  850. // ***************************************************************************
  851. //
  852. // Sixth sql query deletes the user from the phpbb_users table
  853. //
  854. // ***************************************************************************
  855. $sql = "DELETE FROM `$phpbb_users` WHERE `user_id`=$user_id";
  856. if( !$result = mysql_query( $sql ) )
  857. {
  858. die( '<font size="4"><b>Error deleting user from users table:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  859. }
  860. // ***************************************************************************
  861. //
  862. // Seventh sql query deletes the user from the phpbb_user_group table
  863. //
  864. // ***************************************************************************
  865. $sql = "DELETE FROM `$phpbb_user_group` WHERE `user_id`=$user_id";
  866. if( !$result = mysql_query( $sql ) )
  867. {
  868. die( '<font size="4"><b>Error deleting user from user_group table:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  869. }
  870. // ***************************************************************************
  871. //
  872. // Eighth sql query moved to the top to check and exit if error
  873. //
  874. // ***************************************************************************
  875. $sql = "DELETE FROM `$phpbb_groups` WHERE `group_id`=".$row['group_id'];
  876. if( !$result = mysql_query( $sql ) )
  877. {
  878. die( '<font size="4"><b>Error deleting user\'s group from groups table:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  879. }
  880. // ***************************************************************************
  881. //
  882. // Ninth sql query deletes the user from the phpbb_auth_access table
  883. //
  884. // ***************************************************************************
  885. $sql = "DELETE FROM `$phpbb_auth_access` WHERE `group_id`=".$row['group_id'];
  886. if( !$result = mysql_query( $sql ) )
  887. {
  888. die( '<font size="4"><b>Error deleting user from auth_access table:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  889. }
  890. // ***************************************************************************
  891. //
  892. // Tenth sql query deletes the user from the phpbb topics watch table
  893. //
  894. // ***************************************************************************
  895. $sql = "DELETE FROM `$phpbb_topics_watch` WHERE `user_id`=$user_id";
  896. if( !$result = mysql_query( $sql ) )
  897. {
  898. die( '<font size="4"><b>Error deleting user from topics_watch table:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  899. }
  900. // ***************************************************************************
  901. //
  902. // Eleventh sql query deletes the user from the banlist table
  903. //
  904. // ***************************************************************************
  905. $sql = "DELETE FROM `$phpbb_banlist` WHERE `ban_userid`=$user_id";
  906. if( !$result = mysql_query( $sql ) )
  907. {
  908. die( '<font size="4"><b>Error deleting user from the banlist table:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  909. }
  910. // ***************************************************************************
  911. //
  912. // Twelfth sql query deletes the user from the sessions table
  913. //
  914. // ***************************************************************************
  915. // This delete section was added in .19, so a check is done before using it incase
  916. // the admin is running an older version of phpbb
  917. if( $phpbb_version >= 0.19 )
  918. {
  919. $sql = "DELETE FROM `$phpbb_sessions` WHERE `session_user_id`=$user_id";
  920. if( !$result = mysql_query( $sql ) )
  921. {
  922. die( '<font size="4"><b>Error deleting user from the sessions table:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  923. }
  924. }
  925. // ***************************************************************************
  926. //
  927. // Twelfth sql query deletes the user from the sessions_keys table
  928. //
  929. // ***************************************************************************
  930. // This delete section was added in .19, so a check is done before using it incase
  931. // the admin is running an older version of phpbb
  932. if( $phpbb_version >= '.0.19' )
  933. {
  934. // First check if the sesssions keys table exists
  935. // (Since alot of .19 boards dont have it due to incomplete updates
  936. $sql_key_check ="SHOW TABLES LIKE '$phpbb_sessions_keys'";
  937. if( !$result_key_check = mysql_query( $sql_key_check ) )
  938. {
  939. die( '<font size="4"><b>Error selecting session keys table:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  940. }
  941. // This section actually checks if the table exists, if not it skips
  942. // deleting the user from this table
  943. if( mysql_fetch_array($result_key_check) )
  944. {
  945. $sql = "DELETE FROM `$phpbb_sessions_keys` WHERE `user_id`=$user_id";
  946. if( !$result = mysql_query( $sql ) )
  947. {
  948. die( '<font size="4"><b>Error deleting user from the sessions_keys table:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  949. }
  950. }
  951. }
  952. // ***************************************************************************
  953. //
  954. // The final sql query collets the to/from PMs with the user's id & deletes them
  955. //
  956. // ***************************************************************************
  957. // If retain_pms is set to true, change PM author to anonymous instead of deleting them
  958. if( $retain_pms == true )
  959. {
  960. // This query sets the from_user_id to the anonymous account so the PMs dont have to be deleted
  961. $sql = "UPDATE `$phpbb_privmsgs` SET `privmsgs_from_userid`=-1 WHERE `privmsgs_from_userid`=$user_id";
  962. if( !$result = mysql_query( $sql ) )
  963. {
  964. die( '<font size="4"><b>Error setting from PM from_user_id to anonymous:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  965. }
  966. // This query sets the to_user_id to the anonymous account so the PMs dont have to be deleted
  967. $sql = "UPDATE `$phpbb_privmsgs` SET `privmsgs_to_userid`=-1 WHERE `privmsgs_to_userid`=$user_id";
  968. if( !$result = mysql_query( $sql ) )
  969. {
  970. die( '<font size="4"><b>Error setting from PM to_user_id to anonymous:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  971. }
  972. }
  973. else
  974. {
  975. $sql = "SELECT `privmsgs_id` FROM `$phpbb_privmsgs` WHERE `privmsgs_from_userid`=$user_id OR `privmsgs_to_userid`=$user_id";
  976. if( !$result = mysql_query( $sql ) )
  977. {
  978. die( '<font size="4"><b>Error selecting PMs for the user:</b></font><br /><b>Line:</b> '.__LINE__.'<br /><b>File:</b> '.$_SERVER['PHP_SELF']."<br /><b>Query:</b> $sql<br /><b>MySQL Error:</b> ".mysql_error() );
  979. }
  980. // Debugging info:
  981. // echo "<br />$sql<br />";
  982. // This section marks and assigns the resulting PMs into the $marked array
  983. while($myrow = mysql_fetch_array($result))
  984. {
  985. $marked[] = $myrow['privmsgs_id'];
  986. }
  987. // Makes mark an empty array if the user has no PMs
  988. if( !isset( $marked ) )
  989. {
  990. $marked = array();
  991. }
  992. // This section actually goes through the list and deletes the PMs
  993. // Debugging info:
  994. // echo '<pre>';
  995. // print_r( $marked );
  996. if( count( $marked ) )
  997. {
  998. $delete_id = implode( ',', $marked );
  999. // Debugging info:
  1000. // echo "<br />$delete_id";
  1001. $sql = "DELETE FROM `$phpbb_privmsgs_text` WHERE `privmsgs_text_id` IN ( $delete_id )";
  1002. // Debugging info:
  1003. // echo "<br />$sql";
  1004. if( !$result = mysql_query( $sql ) )
  1005. {
  1006. die( 'Error deleting user PMs:<br />Line: '.__LINE__.'<br />File: '.$_SERVER['PHP_SELF']."<br />Query: $sql<br />MySQL Error: ".msql_error() );
  1007. }
  1008. $sql = "DELETE FROM `$phpbb_privmsgs` WHERE `privmsgs_id` IN ( $delete_id )";
  1009. // Debugging info:
  1010. // echo "<br />$sql";
  1011. if( !$result = mysql_query( $sql ) )
  1012. {
  1013. die( 'Error deleting user Pms:<br />Line: '.__LINE__.'<br />File: '.$_SERVER['PHP_SELF']."<br />Query: $sql" );
  1014. }
  1015. }
  1016. }
  1017. // And thats it! The user should now be fully and properly deleted!
  1018. }
  1019. // Delete User function
  1020. function delete_user( $user_id, $clear_posts = false, $retain_pms = false, $from = 'index' )
  1021. {
  1022. // Debugging info:
  1023. // var_dump( $user_id );
  1024. // var_dump( $clear_posts );
  1025. // var_dump( $retain_pms );
  1026. // var_dump( $from );
  1027. // Set global variables
  1028. global $index;
  1029. global $phpbb_version;
  1030. global $phpbb_banlist;
  1031. global $phpbb_user_group;
  1032. global $phpbb_users;
  1033. global $phpbb_groups;
  1034. global $phpbb_posts;
  1035. global $phpbb_posts_text;
  1036. global $phpbb_topics;
  1037. global $phpbb_vote_voters;
  1038. global $phpbb_auth_access;
  1039. global $phpbb_sessions;
  1040. global $phpbb_sessions_keys;
  1041. global $phpbb_privmsgs;
  1042. global $phpbb_privmsgs_text;
  1043. global $phpbb_topics_watch;
  1044. // Set redirect URL
  1045. if( $from == 'edit' )
  1046. {
  1047. $from ="$index?user_id=$user_id";
  1048. }
  1049. else
  1050. {
  1051. $from = $index;
  1052. }
  1053. // First, check if we are dealing with a single user, or an array of users
  1054. if( is_array( $user_id ) )
  1055. {
  1056. // Create user counter variable
  1057. $user_counter = 0;
  1058. // Loop through the array and perform security checks
  1059. // on each element before actually deleting anything
  1060. foreach( $user_id as $id )
  1061. { //user_id foreach
  1062. // First things first, sanitize the $user_id
  1063. $user_id = safe_sql( $id );
  1064. //
  1065. // Obtain username and level based on user_id
  1066. //
  1067. $sql = "SELECT * FROM $phpbb_users WHERE user_id=$id LIMIT 1";
  1068. $result = mysql_query($sql);
  1069. $myrow = mysql_fetch_array($result);
  1070. $username = safe_sql( $myrow['username'] );
  1071. $user_level = safe_sql( $myrow['user_level'] );
  1072. // Obtain first admin account to set as group mod if deleted user is a group mod (step 5)
  1073. $sql = "SELECT * FROM $phpbb_users WHERE user_level=1 ORDER BY user_id ASC LIMIT 1";
  1074. $result = mysql_query($sql);
  1075. $myrow = mysql_fetch_array($result);
  1076. $admin_id= safe_sql( $myrow['user_id'] );
  1077. // Debug info:
  1078. // echo '<pre>';
  1079. // echo gettype( $myrow );
  1080. // die( $admin_id );
  1081. // Check if admin account exists before deleting, if not return with error
  1082. if( !is_array( $myrow ) )
  1083. {
  1084. $_SESSION['errors']['edituser'][] = 'Due to the phpbb table requirements, at least one admin must exist in the database before a user can be deleted.<br />Either promote a current user to an admin, or register a new one give it admin status.';
  1085. header( "Location: $from" );
  1086. die();
  1087. }
  1088. // Check if attempting to delete the anonymous account
  1089. if( $id == -1 )
  1090. {
  1091. $_SESSION['errors']['edituser'][] = 'The anonymous account is required for phpbb to function correctly and cannot be deleted.';
  1092. continue;
  1093. }
  1094. // Check if attempting to delete an admin account
  1095. if( $user_level == 1 )
  1096. {
  1097. // Check to see if delete admin error has occured to prevent duplicate additions of the admin notification
  1098. // This way it will only list the delete error reason, then list only the admin account names on additional admin delete calls
  1099. if( !isset( $admin_delete_error ) )
  1100. {
  1101. $_SESSION['errors']['edituser'][] = "You cannot delete administrator accounts, they must first be demoted to a user.";
  1102. $admin_delete_error = true;
  1103. }
  1104. $_SESSION['errors']['edituser'][] = "<b>$username</b> is an administrator and therefore has been skipped.";
  1105. continue;
  1106. }
  1107. // This line calls the delete user core function which actually deletes the user
  1108. delete_user_core( $id, $clear_posts, $retain_pms );
  1109. $user_counter++;
  1110. } //user_id foreach
  1111. $_SESSION['errors']['edituser'][] = "$user_counter user(s) deleted successfully.";
  1112. }
  1113. else
  1114. {
  1115. // First things first, sanitize the $user_id
  1116. $user_id = safe_sql( $user_id );
  1117. //
  1118. // Obtain username and level based on user_id
  1119. //
  1120. $sql = "SELECT * FROM $phpbb_users WHERE user_id=$user_id LIMIT 1";
  1121. $result = mysql_query($sql);
  1122. $myrow = mysql_fetch_array($result);
  1123. $username = safe_sql( $myrow['username'] );
  1124. $user_level = safe_sql( $myrow['user_level'] );
  1125. // Obtain first admin account to set as group mod if deleted user is a group mod (step 5)
  1126. $sql = "SELECT * FROM $phpbb_users WHERE user_level=1 ORDER BY user_id ASC LIMIT 1";
  1127. $result = mysql_query($sql);
  1128. $myrow = mysql_fetch_array($result);
  1129. $admin_id= safe_sql( $myrow['user_id'] );
  1130. // Debug info:
  1131. // echo '<pre>';
  1132. // echo gettype( $myrow );
  1133. // die( $admin_id );
  1134. // Check if admin account exists before deleting, if not return with error
  1135. if( !is_array( $myrow ) )
  1136. {
  1137. $_SESSION['errors']['edituser'][] = 'Due to the phpbb table requirements, at least one admin must exist in the databas…

Large files files are truncated, but you can click here to view the full file