PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/docleanup.php

https://github.com/Bigjoos/U-232-V1
PHP | 173 lines | 143 code | 20 blank | 10 comment | 15 complexity | 409f487e9846750b4f69f908b0a414db MD5 | raw file
  1. <?php
  2. /**
  3. * https://09source.kicks-ass.net:8443/svn/installer09/
  4. * Licence Info: GPL
  5. * Copyright (C) 2010 Installer09 v.1
  6. * A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
  7. * Project Leaders: Mindless,putyn,kidvision.
  8. **/
  9. if ( ! defined( 'IN_TBDEV_ADMIN' ) )
  10. {
  11. $HTMLOUT='';
  12. $HTMLOUT .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
  13. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  14. <html xmlns='http://www.w3.org/1999/xhtml'>
  15. <head>
  16. <title>Error!</title>
  17. </head>
  18. <body>
  19. <div style='font-size:33px;color:white;background-color:red;text-align:center;'>Incorrect access<br />You cannot access this file directly.</div>
  20. </body></html>";
  21. print $HTMLOUT;
  22. exit();
  23. }
  24. require_once(INCL_DIR.'user_functions.php');
  25. require_once(INCL_DIR.'html_functions.php');
  26. $lang = array_merge( $lang, load_language('ad_docleanup') );
  27. /** new way **/
  28. require_once(INCL_DIR.'class_check.php');
  29. class_check(UC_SYSOP, true, true);
  30. //if (!min_class(UC_SYSOP)) // or just simply: if (!min_class(UC_STAFF))
  31. //header( "Location: {$TBDEV['baseurl']}/index.php");
  32. $HTMLOUT ='';
  33. function calctime($val)
  34. {
  35. $days = intval($val / 86400);
  36. $val -= $days * 86400;
  37. $hours = intval($val / 3600);
  38. $val -= $hours * 3600;
  39. $mins = intval($val / 60);
  40. $secs = $val - ($mins * 60);
  41. return $days . " Days, " . $hours . " Hours, " . $mins . " Minutes, " . $secs . " Seconds";
  42. }
  43. if (!function_exists('memory_get_usage')) {
  44. function memory_get_usage()
  45. {
  46. if (substr(PHP_OS, 0, 3) == 'WIN') {
  47. if (substr(PHP_OS, 0, 3) == 'WIN') {
  48. $output = array();
  49. exec('tasklist /FI "PID eq ' . getmypid() . '" /FO LIST', $output);
  50. return preg_replace('/[\D]/', '', $output[5]) * 1024;
  51. }
  52. } else {
  53. $pid = getmypid();
  54. exec("ps -eo%mem,rss,pid | grep $pid", $output);
  55. $output = explode(" ", $output[0]);
  56. return $output[1] * 1024;
  57. }
  58. }
  59. }
  60. $HTMLOUT .= begin_main_frame('Cleanups');
  61. $HTMLOUT .= begin_table();
  62. $HTMLOUT .="<tr><td class='table'>Cleanup Name</td>
  63. <td class='table'>Last Run</td>
  64. <td class='table'>Runs every</td>
  65. <td class='table'>Scheduled to run</td>
  66. </tr>";
  67. $res = mysql_query("SELECT arg, value_u FROM avps");
  68. while ($arr = mysql_fetch_assoc($res)) {
  69. switch ($arr['arg']) {
  70. case 'lastcleantime': $arg = $TBDEV['autoclean_interval'];
  71. break;
  72. case 'lastslowcleantime': $arg = $TBDEV['autoslowclean_interval'];
  73. break;
  74. case 'lastslowcleantime2': $arg = $TBDEV['autoslowclean_interval2'];
  75. break;
  76. case 'lastlottocleantime': $arg = $TBDEV['lotteryclean_interval'];
  77. break;
  78. case 'lastoptimizedbtime': $arg = $TBDEV['optimizedb_interval'];
  79. break;
  80. case 'lastbackuptime': $arg = $TBDEV['autobackup_interval'];
  81. break;
  82. }
  83. $HTMLOUT .="<tr><td>".$arr['arg']."</td>
  84. <td>".get_date($arr['value_u'], 'TINY',0,1)."</td>
  85. <td>" . calctime($arg) . "</td>
  86. <td>" . calctime($arr['value_u'] - (time() - $arg)) . "</td>
  87. </tr>";
  88. }
  89. $HTMLOUT .= end_table();
  90. $HTMLOUT .="<form action='staffpanel.php?tool=docleanup&amp;action=docleanup' method='post'>
  91. <table align='center'>
  92. <tr>
  93. <td class='table'>
  94. <input type='checkbox' name='docleanup' />Do cleanup
  95. &nbsp;&nbsp;&nbsp;&nbsp;
  96. <input type='checkbox' name='doslowcleanup' />Do slow cleanup
  97. &nbsp;&nbsp;&nbsp;&nbsp;
  98. <input type='checkbox' name='doslowcleanup2' />Do slow cleanup 2
  99. &nbsp;&nbsp;&nbsp;&nbsp;
  100. <input type='checkbox' name='dolotterycleanup' />Do lotto clean
  101. &nbsp;&nbsp;&nbsp;&nbsp;
  102. <input type='checkbox' name='dooptimizedb' />Do optimization
  103. &nbsp;&nbsp;&nbsp;&nbsp;
  104. <input type='checkbox' name='dobackupdb' />Do mysql backup
  105. <input type='submit' value='Submit' />
  106. </td></tr></table>
  107. </form>";
  108. if (isset($_POST['docleanup'])) {
  109. sql_query("UPDATE avps SET value_u = " . TIME_NOW . " WHERE arg = 'lastcleantime'") or sqlerr(__FILE__, __LINE__);
  110. require_once("include/cleanup.php");
  111. docleanup();
  112. header('Refresh: 2; url='.$TBDEV['baseurl'].'/staffpanel.php?tool=docleanup');
  113. $HTMLOUT .="<br /><h1>Cleanup Done</h1>";
  114. }
  115. if (isset($_POST['doslowcleanup'])) {
  116. sql_query("UPDATE avps SET value_u = " . TIME_NOW . " WHERE arg = 'lastslowcleantime'") or sqlerr(__FILE__, __LINE__);
  117. require_once("include/cleanup.php");
  118. doslowcleanup();
  119. header('Refresh: 2; url='.$TBDEV['baseurl'].'/staffpanel.php?tool=docleanup');
  120. $HTMLOUT .="<br /><h1>Slow Cleanup Done</h1>";
  121. }
  122. if (isset($_POST['doslowcleanup2'])) {
  123. sql_query("UPDATE avps SET value_u = " . TIME_NOW . " WHERE arg = 'lastslowcleantime2'") or sqlerr(__FILE__, __LINE__);
  124. require_once("include/cleanup.php");
  125. doslowcleanup2();
  126. header('Refresh: 2; url='.$TBDEV['baseurl'].'/staffpanel.php?tool=docleanup');
  127. $HTMLOUT .="<br /><h1>Slow Cleanup 2 Done</h1>";
  128. }
  129. if (isset($_POST['dolotterycleanup'])) {
  130. sql_query("UPDATE avps SET value_u = " . TIME_NOW . " WHERE arg = 'lastlottocleantime'") or sqlerr(__FILE__, __LINE__);
  131. require_once("include/cleanup.php");
  132. dolotterycleanup();
  133. header('Refresh: 2; url='.$TBDEV['baseurl'].'/staffpanel.php?tool=docleanup');
  134. $HTMLOUT .="<br /><h1>Lottery Cleanup Done</h1>";
  135. }
  136. if (isset($_POST['dooptimizedb'])) {
  137. sql_query("UPDATE avps SET value_u = " . TIME_NOW . " WHERE arg = 'lastoptimizedbtime'") or sqlerr(__FILE__, __LINE__);
  138. require_once("include/cleanup.php");
  139. dooptimizedb();
  140. header('Refresh: 2; url='.$TBDEV['baseurl'].'/staffpanel.php?tool=docleanup');
  141. $HTMLOUT .="<br /><h1>Optimization Done</h1>";
  142. }
  143. if (isset($_POST['dobackupdb'])) {
  144. sql_query("UPDATE avps SET value_u = " . TIME_NOW . " WHERE arg = 'lastbackuptime'") or sqlerr(__FILE__, __LINE__);
  145. require_once("include/cleanup.php");
  146. dobackupdb();
  147. header('Refresh: 2; url='.$TBDEV['baseurl'].'/staffpanel.php?tool=docleanup');
  148. $HTMLOUT .="<br /><h1>Mysql backup Done</h1>";
  149. }
  150. $HTMLOUT .="Memory usage:" . memory_get_usage() . "<br /><br />";
  151. $HTMLOUT .= end_main_frame();
  152. print stdhead('Doclean Up') . $HTMLOUT . stdfoot();
  153. ?>