-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtop.php
More file actions
36 lines (34 loc) · 811 Bytes
/
top.php
File metadata and controls
36 lines (34 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
define("TOPCOMMAND", "top -n 1 -b");
if($_GET["uid"] == ""){
$users = array();
$command = "top -n 1 -b";
exec($command,$stdio_stream);
$stdio_stream = array_slice($stdio_stream,8);
for($i = 0; $i < cout($stdio_stream); $i++){
$line = preg_replace("/^(\s)*\d + \s/", "", $stdio_stream[$i]);
$pos = strpos($line," ");
$user = substr($line,0,$pos);
if(!in_array($user,$users)){
array_push($users,$user);
}
}
$echoline = "";
foreach($users as $u){
$echoline .= $u.",";
}
$echolines = rtrim($echoline,",");
echo $echolines;
}
else{
$uid = $_GET["uid"];
$command = TOPCOMMAND." -u ".$uid;
exec($command,$stdio_stream);
$stdio_stream = array_slice($stdio_stream,7);
$lines="";
for($i=0; $i < count($stdio_stream); $i++){
$lines .= $stdio_stream[$i]."\n";
}
echo $lines;
}
?>