This repository has been archived by the owner on Mar 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisk.php
141 lines (124 loc) · 3.91 KB
/
disk.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/*
* Created by Sikevux
* Inspired by Zash
* And Do What Ever The Fuck You Want With It
*
* Contributions by: kd35a
*/
/*
* TODO
* Rite so we totaly need a drive array, not just partitions
* real drives. Then prolly some nice way to kill the /dev/
* part on all the disks, without making the luks drives
* look like crack with a hat
*/
function percent($amount, $total) {
$count = $amount / $total;
$countt = $count * 100;
$result = number_format($countt, 0);
return $result;
}
$not_wanted_filesystems = "none|tmpfs|udev|AFS|loop|sr";
$disc_count = shell_exec("df -Pk|grep -v -E \"".$not_wanted_filesystems."\"|wc -l");
$disc_name = shell_exec("df -Pk|grep -v -E \"".$not_wanted_filesystems."\"|awk -v col=1 'NR > 1 {sub( \"\", \"\", \$col); print \$col }'");
for($i=1; $i<$disc_count; $i++) {
$drive_array[] = shell_exec("df -Pk|grep -v -E \"".$not_wanted_filesystems."\"|awk -v col=1 'NR > 1 {sub( \"\", \"\", \$col); print \$col }'|sed -n '".$i."p'");
$drive_max[] = shell_exec("df -Pk|grep -v -E \"".$not_wanted_filesystems."\"|awk -v col=4 'NR > 1 {sub( \"\", \"\", \$col); print \$col }'|sed -n '".$i."p'");
$drive_use_b[] = shell_exec("df -Pk|grep -v -E \"".$not_wanted_filesystems."\"|awk -v col=3 'NR > 1 {sub( \"\", \"\", \$col); print \$col }'|sed -n '".$i."p'");
$drive_use[] = shell_exec("df -Pk|grep -v -E \"".$not_wanted_filesystems."\"|awk -v col=5 'NR > 1 {sub( \"\", \"\", \$col); print \$col }'|sed -n '".$i."p'");
}
$system_max = shell_exec("df -Pk | awk -v col=4 'NR > 1 {sub( \"\", \"\", \$col); tot += \$col;} END { print tot }'");
for($i=0; $i<$disc_count-1; $i++) {
$drive_percent[$i] = percent($drive_max[$i], $system_max);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title><?php echo substr(shell_exec(hostname), 0, -1); ?> status</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<meta content="width=400" name="viewport" />
<style type="text/css">
body {
margin: 14% 5% 0;
}
h1,h2 {
font: 1em sans-serif;
margin: 2pt 0;
}
h1 {
font-size: 3em;
text-align: center;
}
h1+h2 {
text-align: center;
}
h2 {
font-size: 1.2em;
margin-left: 1em;
}
h3 {
margin-top: 15em;
font-size: 12px;
text-align: center;
}
.drive,.partition,.used-space {
float: left;
}
.drive {
width: 100%;
outline: 1px solid black;
margin: 1ex0;
}
.partition {
background-color: #80ff80;
}
.used-space {
white-space: nowrap;
background-color: #ff8080;
overflow: visible;
}
<?php
for($i=0; $i<$disc_count-1; $i++) {
print("#".substr($drive_array[$i], 0, -1).".partition {\n\t\t\twidth: ".$drive_percent[$i]."%;\n\t\t}\n\t\t");
print("#".substr($drive_array[$i], 0, -1).".partition .used-space {\n\t\t\twidth: ".substr($drive_use[$i], 0, -1).";\n\t\t}\n\t\t");
}
?>
</style>
</head>
<body>
<h1>
<?php system("hostname"); ?>
</h1>
<?php
$updata = shell_exec('uptime');
preg_match("/(up[ ]{1,}(([\d]{1,3}[ ]{1,}((day)|(days)),[ ]{1,})?([\d]{1,2}:)?[\d]{1,2}( min)?))(,[ \da-z]{0,},[ a-z:]{1,})([\d]{1,}.[\d]{2}, [\d]{1,}.[\d]{2}, [\d]{1,}.[\d]{2})/", $updata, $tmp);
$uptime = $tmp[2];
$load = explode('average:', $updata);
$kdata = shell_exec('uname -sr');
$kernel = explode('-', $kdata);
?>
<h2>
<?php echo $kernel[0]." – up ".$uptime; ?>
</h2>
<!-- TODO: Automate this part -->
<h2>disk sda</h2>
<div class="drive" id="sda">
<div class="partition" id="sda1">
<div class="used-space"> sda1 on /boot</div>
</div>
<div class="partition" id="sda5">
<div class="used-space"> sda5 on /</div>
</div>
</div>
<p />
<h2>disk sdb</h2>
<div class="drive" id="sdb">
<div class="partition" id="sdb1">
<div class="used-space"> sdb1 on /pool</div>
</div>
</div>
<h3>:3</h3>
</body>
</html>