patschi

Untitled

Jun 13th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.59 KB | None | 0 0
  1. <?php
  2. if(empty($_GET['show'])) { die("access denied"); }
  3. if($_GET['get'] == "true") {
  4.  # http://wiki.vpslink.com/Linux_Command_Reference:_ps
  5. //$ps = shell_exec("ps aux | grep -v -E '[0-9]{0,} \[.*\]$'");
  6.  $ps = shell_exec("ps aux");
  7.  $ps = explode("\n", $ps);
  8.  unset($ps[0]);
  9.  
  10.  $return  = "<pre>";
  11.  $return .= "<table style='width:100%;'>";
  12.  $return .= "<tr>";
  13.  $return .= "<th>User</th>";
  14.  $return .= "<th>PID</th>";
  15.  $return .= "<th>CPU</th>";
  16.  $return .= "<th>Mem</th>";
  17.  //$return .= "<th>VSZ</th>";
  18.  //$return .= "<th>TTY</th>";
  19.  //$return .= "<th>Ste</th>";
  20.  $return .= "<th>Start</th>";
  21.  $return .= "<th>Command</th>";
  22.  $return .= "</tr>";
  23.  
  24.  $count=0;
  25.  foreach($ps as $part) {
  26.    if(strlen($part)<1) continue; else $count++;
  27.    
  28.     $user = shell_exec("echo \"".$part."\" | awk '{print $1}'");
  29.     $pid = shell_exec("echo \"".$part."\" | awk '{print $2}'");
  30.     $cpu = shell_exec("echo \"".$part."\" | awk '{print $3}'");
  31.     $mem = shell_exec("echo \"".$part."\" | awk '{print $4}'");
  32.     //$vsz = shell_exec("echo \"".$part."\" | awk '{print $5}'");
  33.     //$tty = shell_exec("echo \"".$part."\" | awk '{print $7}'");
  34.     //$state = shell_exec("echo \"".$part."\" | awk '{print $8}'");
  35.     $start = shell_exec("echo \"".$part."\" | awk '{print $9}'");
  36.     $command = shell_exec("echo \"".$part."\" | awk '{print $11}'");
  37.  
  38.     preg_match("/".preg_quote(trim($command), "/")."(.*)$/", $part, $matches);
  39.     $command = $command." ".$matches[1];
  40.  
  41.     $return .= "<tr>";
  42.     $return .= "<td style='font-size:10px;'>".htmlentities($user)."</td>";
  43.     $return .= "<td style='font-size:10px;'>".htmlentities($pid)."</td>";
  44.     $return .= "<td style='font-size:10px;'>".htmlentities($cpu)."</td>";
  45.     $return .= "<td style='font-size:10px;'>".htmlentities($mem)."</td>";
  46.     //$return .= "<td style='font-size:10px;'>".htmlentities($vsz)."</td>";
  47.     //$return .= "<td style='font-size:10px;'>".htmlentities($tty)."</td>";
  48.     //$return .= "<td style='font-size:10px;'>".htmlentities($state)."</td>";
  49.     $return .= "<td style='font-size:10px;'>".htmlentities($start)."</td>";
  50.     $return .= "<td style='font-size:10px;'>".htmlentities($command)."</td>";
  51.     $return .= "</tr>";
  52.  }
  53.  
  54.  $return .= "</table>";
  55.  $return  = "Es laufen ".$count." Prozesse. (Kernelprozesse ausgenommen!)".$return;
  56.  $return .= "</pre>";
  57.  
  58.  echo $return;
  59.  die();
  60. }
  61. ?>
  62. <html>
  63. <head>
  64. <title>Prozessliste</title>
  65. <style type="text/css">
  66. pre { font-family: Arial; }
  67. #content { position: absolute; left: 40px; }
  68. </style>
  69. <script type="text/javascript">
  70. function createAjaxRequest() {
  71.     var xmlHttp;   
  72.     if ( window.XMLHttpRequest )  {
  73.         xmlHttp = new XMLHttpRequest();
  74.      } else if ( window.ActiveXObject ) {
  75.         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");      
  76.     } else {
  77.         alert("AJAX wird von Ihrem Browser leider nicht unterstuetzt!\nBitte aktualisieren Sie Ihren Browser!");       
  78.     }  
  79.     return xmlHttp;
  80. }
  81.  
  82. function load()
  83. {
  84.     var reqObj = createAjaxRequest();
  85.     reqObj.open('GET', 'prozlist.php?get=true&show=true', true);
  86.     reqObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  87.     reqObj.send();
  88.     reqObj.onreadystatechange = function(){
  89.         if (reqObj.readyState == 4) {
  90.             document.getElementById('prozlist').innerHTML  = reqObj.responseText;
  91.         }
  92.     }
  93.   reload();
  94. }
  95.  
  96. function reload() {
  97.     window.setTimeout("load();", 5*1000);
  98. }
  99. </script>
  100. </head>
  101. <body onLoad="load();">
  102. Aktualisierung erfolgt jede 5 Sekunden.<br />
  103. <input type="button" value=" Manuele Aktualisierung " onclick="load();"><br />
  104. <br />
  105. <font size="3"><b>Prozessliste</b></font><br />
  106. <div id="content"><span id="prozlist"></span></div>
  107. </body>
  108. </html>
Advertisement
Add Comment
Please, Sign In to add comment