-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
119 lines (103 loc) · 5.72 KB
/
functions.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
<?php
function getHelpActive($item, $page) {
if ($item == $page) {
return 'class="list-group-item active"';
} else {
return 'class="list-group-item"';
}
}
function getKernelBoot() {
$result = queryDB_RAW("SELECT * FROM kernelboot;");
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
array_push($data, $row);
}
return $data;
}
function getSanBoot() {
$result = queryDB_RAW("SELECT * FROM sanboot;");
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
array_push($data, $row);
}
return $data;
}
function getMemDiskBoot() {
$result = queryDB_RAW("SELECT * FROM memdiskboot;");
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
array_push($data, $row);
}
return $data;
}
function getChainloads() {
$result = queryDB_RAW("SELECT * FROM chainloads;");
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
array_push($data, $row);
}
return $data;
}
function getCPUInfo() {
return shell_exec("cat /proc/cpuinfo | grep 'model name' -m 1 | cut -d':' -f2");
}
function getUptime() {
return shell_exec("uptime -p");
}
function getCPULoad() {
return '<div class="progress"><div class="progress-bar" role="progressbar" aria-valuenow="' . shell_exec("grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}'") . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . shell_exec("grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage \"%\"}'") . ';"></div></div>';
}
function getRAMLoad() {
$total = shell_exec("free | grep Mem: | awk '{print $2}'");
$used = shell_exec("free | grep Mem: | awk '{print $3}'");
$percentage = ((100 / $total) * $used);
return '<div class="progress"><div class="progress-bar" role="progressbar" aria-valuenow="' . $percentage . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $percentage . '%;"></div></div>';
}
function getSWAPLoad() {
$total = shell_exec("free | grep Swap: | awk '{print $2}'");
$used = shell_exec("free | grep Swap: | awk '{print $3}'");
$percentage = ((100 / $total) * $used);
return '<div class="progress"><div class="progress-bar" role="progressbar" aria-valuenow="' . $percentage . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $percentage . '%;"></div></div>';
}
function getDISKLoad() {
return '<div class="progress"><div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: ' . shell_exec("df | grep root | awk '{print $5}'") . ';"></div></div>';
}
function getServiceDNSMASQ() {
if (strpos(shell_exec("systemctl status dnsmasq | grep Active:"), 'failed') !== false) {
return '<a href="?view=system&action=start-dnsmasq"><span class="glyphicon glyphicon-play" aria-hidden="true"></span></a> <span class="label label-danger">Failed</span>';
} else if (strpos(shell_exec("systemctl status dnsmasq | grep Active:"), 'inactive') !== false) {
return '<a href="?view=system&action=start-dnsmasq"><span class="glyphicon glyphicon-play" aria-hidden="true"></span></a> <span class="label label-warning">Stopped</span>';
} else {
return '<a href="?view=system&action=stop-dnsmasq"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span></a> <span class="label label-success">Started</span>';
}
}
function getServiceTFTPD() {
if (strpos(shell_exec("systemctl status tftp | grep Active:"), 'failed') !== false) {
return '<a href="?view=system&action=start-tftp"><span class="glyphicon glyphicon-play" aria-hidden="true"></span></a> <span class="label label-danger">Failed</span>';
} else if (strpos(shell_exec("systemctl status tftp | grep Active:"), 'inactive') !== false) {
return '<a href="?view=system&action=start-tftp"><span class="glyphicon glyphicon-play" aria-hidden="true"></span></a> <span class="label label-warning">Stopped</span>';
} else {
return '<a href="?view=system&action=stop-tftp"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span></a> <span class="label label-success">Started</span>';
}
}
function getServiceHTTPD() {
if (strpos(shell_exec("systemctl status httpd | grep Active:"), 'failed') !== false) {
return '<a href="?view=system&action=start-httpd"><span class="glyphicon glyphicon-play" aria-hidden="true"></span></a> <span class="label label-danger">Failed</span>';
} else if (strpos(shell_exec("systemctl status httpd | grep Active:"), 'inactive') !== false) {
return '<a href="?view=system&action=start-httpd"><span class="glyphicon glyphicon-play" aria-hidden="true"></span></a> <span class="label label-warning">Stopped</span>';
} else {
return '<a href="?view=system&action=stop-httpd"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span></a> <span class="label label-success">Started</span>';
}
}
function getServiceMARIADB() {
if (strpos(shell_exec("systemctl status mariadb | grep Active:"), 'failed') !== false) {
return '<a href="?view=system&action=start-db"><span class="glyphicon glyphicon-play" aria-hidden="true"></span></a> <span class="label label-danger">Failed</span>';
} else if (strpos(shell_exec("systemctl status mariadb | grep Active:"), 'inactive') !== false) {
return '<a href="?view=system&action=start-db"><span class="glyphicon glyphicon-play" aria-hidden="true"></span></a> <span class="label label-warning">Stopped</span>';
} else {
return '<a href="?view=system&action=stop-db"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span></a> <span class="label label-success">Started</span>';
}
}
function cleanWhitespace($string) {
return str_replace(' ', '', $string);
}