PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/system_view.php

https://github.com/Bigjoos/U-232-V3
PHP | 202 lines | 186 code | 0 blank | 16 comment | 26 complexity | 5505281dd83da19c3201a44ff3a51de7 MD5 | raw file
  1. <?php
  2. /**
  3. * https://github.com/Bigjoos/
  4. * Licence Info: GPL
  5. * Copyright (C) 2010 U-232 v.3
  6. * A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
  7. * Project Leaders: Mindless, putyn.
  8. *
  9. */
  10. if (!defined('IN_INSTALLER09_ADMIN')) {
  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. echo $htmlout;
  22. exit();
  23. }
  24. require_once (INCL_DIR.'user_functions.php');
  25. require_once (CLASS_DIR.'class_check.php');
  26. class_check(UC_SYSOP, true, true);
  27. $lang = array_merge($lang);
  28. $htmlout = '';
  29. if (isset($_GET['phpinfo']) AND $_GET['phpinfo']) {
  30. @ob_start();
  31. phpinfo();
  32. $parsed = @ob_get_contents();
  33. @ob_end_clean();
  34. preg_match("#<body>(.*)</body>#is", $parsed, $match1);
  35. $php_body = $match1[1];
  36. // PREVENT WRAP: Most cookies
  37. $php_body = str_replace("; ", ";<br />", $php_body);
  38. // PREVENT WRAP: Very long string cookies
  39. $php_body = str_replace("%3B", "<br />", $php_body);
  40. // PREVENT WRAP: Serialized array string cookies
  41. $php_body = str_replace(";i:", ";<br />i:", $php_body);
  42. // PREVENT WRAP: LS_COLORS env
  43. $php_body = str_replace(":*.", "<br />:*.", $php_body);
  44. // PREVENT WRAP: PATH env
  45. $php_body = str_replace("bin:/", "bin<br />:/", $php_body);
  46. // PREVENT WRAP: Cookie %2C split
  47. $php_body = str_replace("%2C", "%2C<br />", $php_body);
  48. // PREVENT WRAP: Cookie , split
  49. $php_body = preg_replace("#,(\d+),#", ",<br />\\1,", $php_body);
  50. $php_style = "<style type='text/css'>
  51. .center {text-align: center;}
  52. .center table { margin-left: auto; margin-right: auto; text-align: left; }
  53. .center th { text-align: center; }
  54. h1 {font-size: 150%;}
  55. h2 {font-size: 125%;}
  56. .p {text-align: left;}
  57. .e {background-color: #ccccff; font-weight: bold;}
  58. .h {background-color: #9999cc; font-weight: bold;}
  59. .v {background-color: #cccccc; white-space: normal;}
  60. </style>\n";
  61. $html = $php_style.$php_body;
  62. echo $html;
  63. stdfoot();
  64. exit();
  65. }
  66. $html = array();
  67. function sql_get_version()
  68. {
  69. $query = sql_query("SELECT VERSION() AS version");
  70. if (!$row = mysqli_fetch_assoc($query)) {
  71. unset($row);
  72. $query = sql_query("SHOW VARIABLES LIKE 'version'");
  73. $row = mysqli_fetch_row($query);
  74. $row['version'] = $row[1];
  75. }
  76. $true_version = $row['version'];
  77. $tmp = explode('.', preg_replace("#[^\d\.]#", "\\1", $row['version']));
  78. $mysql_version = sprintf('%d%02d%02d', $tmp[0], $tmp[1], $tmp[2]);
  79. return $mysql_version." (".$true_version.")";
  80. }
  81. $php_version = phpversion()." (".@php_sapi_name().") ( <a href='{$INSTALLER09['baseurl']}/staffpanel.php?tool=system_view&amp;action=system_view&amp;phpinfo=1'>PHP INFO</a> )";
  82. $server_software = php_uname();
  83. // print $php_version ." ".$server_software;
  84. $load_limit = "--";
  85. $server_load_found = 0;
  86. $using_cache = 0;
  87. $avp = @sql_query("SELECT value_s FROM avps WHERE arg = 'loadlimit'");
  88. if (false !== $row = mysqli_fetch_assoc($avp)) {
  89. $loadinfo = explode("-", $row['value_s']);
  90. if (intval($loadinfo[1]) > (time() - 20)) {
  91. $server_load_found = 1;
  92. $using_cache = 1;
  93. $load_limit = $loadinfo[0];
  94. }
  95. }
  96. if (!$server_load_found) {
  97. if (@file_exists('/proc/loadavg')) {
  98. if ($fh = @fopen('/proc/loadavg', 'r')) {
  99. $data = @fread($fh, 6);
  100. @fclose($fh);
  101. $load_avg = explode(" ", $data);
  102. $load_limit = trim($load_avg[0]);
  103. }
  104. } else if (strstr(strtolower(PHP_OS) , 'win')) {
  105. $serverstats = @shell_exec("typeperf \"Processor(_Total)\% Processor Time\" -sc 1");
  106. if ($serverstats) {
  107. $server_reply = explode("\n", str_replace("\r", "", $serverstats));
  108. $serverstats = array_slice($server_reply, 2, 1);
  109. $statline = explode(",", str_replace('"', '', $serverstats[0]));
  110. $load_limit = round($statline[1], 4);
  111. }
  112. } else {
  113. if ($serverstats = @exec("uptime")) {
  114. preg_match("/(?:averages)?\: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $serverstats, $load);
  115. $load_limit = $load[1];
  116. }
  117. }
  118. if ($load_limit) {
  119. @sql_query("UPDATE avps SET value_s = '".$load_limit."-".time()."' WHERE arg = 'loadlimit'");
  120. }
  121. }
  122. $total_memory = $avail_memory = "--";
  123. if (strstr(strtolower(PHP_OS) , 'win')) {
  124. $mem = @shell_exec('systeminfo');
  125. if ($mem) {
  126. $server_reply = explode("\n", str_replace("\r", "", $mem));
  127. if (count($server_reply)) {
  128. foreach ($server_reply as $info) {
  129. if (strstr($info, "Total Physical Memory")) {
  130. $total_memory = trim(str_replace(":", "", strrchr($info, ":")));
  131. }
  132. if (strstr($info, "Available Physical Memory")) {
  133. $avail_memory = trim(str_replace(":", "", strrchr($info, ":")));
  134. }
  135. }
  136. }
  137. }
  138. } else {
  139. $mem = @shell_exec("free -m");
  140. $server_reply = explode("\n", str_replace("\r", "", $mem));
  141. $mem = array_slice($server_reply, 1, 1);
  142. $mem = preg_split("#\s+#", $mem[0]);
  143. $total_memory = $mem[1].' MB';
  144. $avail_memory = $mem[3].' MB';
  145. }
  146. $disabled_functions = @ini_get('disable_functions') ? str_replace(",", ", ", @ini_get('disable_functions')) : "<i>no information</i>";
  147. if (strstr(strtolower(PHP_OS) , 'win')) {
  148. $tasks = @shell_exec("tasklist");
  149. $tasks = str_replace(" ", " ", $tasks);
  150. } else {
  151. $tasks = @shell_exec("top -b -n 1");
  152. $tasks = str_replace(" ", " ", $tasks);
  153. }
  154. if (!$tasks) {
  155. $tasks = "<i>Unable to obtain process information</i>";
  156. } else {
  157. $tasks = "<pre>".$tasks."</pre>";
  158. }
  159. $load_limit = $load_limit." (From Cache: ".($using_cache == 1 ? "<span style='color:green;font-weight:bold;'>True)</span>" : "<span style='color:red;font-weight:bold;'>False)</span>");
  160. $html[] = array(
  161. 'MySQL Version',
  162. sql_get_version()
  163. );
  164. $html[] = array(
  165. "PHP Version",
  166. $php_version
  167. );
  168. $html[] = array(
  169. "Safe Mode",
  170. @ini_get('safe_mode') == 1 ? "<span style='color:red;font-weight:bold;'>ON</span>" : "<span style='color:green;font-weight:bold;'>OFF</span>"
  171. );
  172. $html[] = array(
  173. "Disabled PHP Functions",
  174. $disabled_functions
  175. );
  176. $html[] = array(
  177. "Server Software",
  178. $server_software
  179. );
  180. $html[] = array(
  181. "Current Server Load",
  182. $load_limit
  183. );
  184. $html[] = array(
  185. "Total Server Memory",
  186. $total_memory
  187. );
  188. $html[] = array(
  189. "Available Physical Memory",
  190. $avail_memory
  191. );
  192. $html[] = array(
  193. "System Processes",
  194. $tasks
  195. );
  196. $htmlout.= '<table>';
  197. foreach ($html as $key => $value) {
  198. $htmlout.= '<tr><td>'.$value[0].'</td><td>'.$value[1].'</td></tr>';
  199. }
  200. $htmlout.= '</table>';
  201. echo stdhead('System Overview').$htmlout.stdfoot();
  202. ?>