|
1
|
|
|
<?php require($_SERVER['DOCUMENT_ROOT'] . "/static/config.inc.php"); ?> |
|
2
|
|
|
<?php require($_SERVER['DOCUMENT_ROOT'] . "/static/conn.php"); ?> |
|
3
|
|
|
<?php require($_SERVER['DOCUMENT_ROOT'] . "/lib/profile.php"); ?> |
|
4
|
|
|
<?php |
|
5
|
|
|
session_start(); |
|
6
|
|
|
|
|
7
|
|
|
ini_set('display_errors', 1); |
|
8
|
|
|
ini_set('display_startup_errors', 1); |
|
9
|
|
|
error_reporting(E_ALL); |
|
10
|
|
|
|
|
11
|
|
|
if(!isset($_SESSION['siteusername'])) { |
|
12
|
|
|
header("Location: ../index.php"); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
if(isAdmin($_SESSION['siteusername'], $conn) == false) { |
|
|
|
|
|
|
16
|
|
|
die("Ur not admin"); |
|
17
|
|
|
} else { |
|
18
|
|
|
if(@$_POST['suspend']) { |
|
19
|
|
|
suspendUser($_POST['subject'], $conn); |
|
20
|
|
|
echo "Suces<br>"; |
|
21
|
|
|
} else if(@$_POST['unsuspend']) { |
|
22
|
|
|
unsuspendUser($_POST['subject'], $conn); |
|
23
|
|
|
echo "Suces<br>"; |
|
24
|
|
|
} else if(@$_POST['del']) { |
|
25
|
|
|
delPostsFromUser($_POST['subject'], $conn); |
|
26
|
|
|
echo "succes<br>"; |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function _getServerLoadLinuxData() |
|
31
|
|
|
{ |
|
32
|
|
|
if (is_readable("/proc/stat")) |
|
33
|
|
|
{ |
|
34
|
|
|
$stats = @file_get_contents("/proc/stat"); |
|
35
|
|
|
|
|
36
|
|
|
if ($stats !== false) |
|
37
|
|
|
{ |
|
38
|
|
|
// Remove double spaces to make it easier to extract values with explode() |
|
39
|
|
|
$stats = preg_replace("/[[:blank:]]+/", " ", $stats); |
|
40
|
|
|
|
|
41
|
|
|
// Separate lines |
|
42
|
|
|
$stats = str_replace(array("\r\n", "\n\r", "\r"), "\n", $stats); |
|
43
|
|
|
$stats = explode("\n", $stats); |
|
44
|
|
|
|
|
45
|
|
|
// Separate values and find line for main CPU load |
|
46
|
|
|
foreach ($stats as $statLine) |
|
47
|
|
|
{ |
|
48
|
|
|
$statLineData = explode(" ", trim($statLine)); |
|
49
|
|
|
|
|
50
|
|
|
// Found! |
|
51
|
|
|
if |
|
52
|
|
|
( |
|
53
|
|
|
(count($statLineData) >= 5) && |
|
54
|
|
|
($statLineData[0] == "cpu") |
|
55
|
|
|
) |
|
56
|
|
|
{ |
|
57
|
|
|
return array( |
|
58
|
|
|
$statLineData[1], |
|
59
|
|
|
$statLineData[2], |
|
60
|
|
|
$statLineData[3], |
|
61
|
|
|
$statLineData[4], |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return null; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// Returns server load in percent (just number, without percent sign) |
|
72
|
|
|
function getServerLoad() |
|
73
|
|
|
{ |
|
74
|
|
|
$load = null; |
|
75
|
|
|
|
|
76
|
|
|
if (stristr(PHP_OS, "win")) |
|
77
|
|
|
{ |
|
78
|
|
|
$cmd = "wmic cpu get loadpercentage /all"; |
|
79
|
|
|
@exec($cmd, $output); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
if ($output) |
|
82
|
|
|
{ |
|
83
|
|
|
foreach ($output as $line) |
|
84
|
|
|
{ |
|
85
|
|
|
if ($line && preg_match("/^[0-9]+\$/", $line)) |
|
86
|
|
|
{ |
|
87
|
|
|
$load = $line; |
|
88
|
|
|
break; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
else |
|
94
|
|
|
{ |
|
95
|
|
|
if (is_readable("/proc/stat")) |
|
96
|
|
|
{ |
|
97
|
|
|
// Collect 2 samples - each with 1 second period |
|
98
|
|
|
// See: https://de.wikipedia.org/wiki/Load#Der_Load_Average_auf_Unix-Systemen |
|
99
|
|
|
$statData1 = _getServerLoadLinuxData(); |
|
100
|
|
|
sleep(1); |
|
101
|
|
|
$statData2 = _getServerLoadLinuxData(); |
|
102
|
|
|
|
|
103
|
|
|
if |
|
104
|
|
|
( |
|
105
|
|
|
(!is_null($statData1)) && |
|
106
|
|
|
(!is_null($statData2)) |
|
107
|
|
|
) |
|
108
|
|
|
{ |
|
109
|
|
|
// Get difference |
|
110
|
|
|
$statData2[0] -= $statData1[0]; |
|
111
|
|
|
$statData2[1] -= $statData1[1]; |
|
112
|
|
|
$statData2[2] -= $statData1[2]; |
|
113
|
|
|
$statData2[3] -= $statData1[3]; |
|
114
|
|
|
|
|
115
|
|
|
// Sum up the 4 values for User, Nice, System and Idle and calculate |
|
116
|
|
|
// the percentage of idle time (which is part of the 4 values!) |
|
117
|
|
|
$cpuTime = $statData2[0] + $statData2[1] + $statData2[2] + $statData2[3]; |
|
118
|
|
|
|
|
119
|
|
|
// Invert percentage to get CPU time, not idle time |
|
120
|
|
|
$load = 100 - ($statData2[3] * 100 / $cpuTime); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return $load; |
|
126
|
|
|
} |
|
127
|
|
|
?> |
|
128
|
|
|
<!DOCTYPE html> |
|
129
|
|
|
<html> |
|
130
|
|
|
<head> |
|
131
|
|
|
<link href="/static/css/required.css" rel="stylesheet"> |
|
132
|
|
|
<title>Witter: What are you doing?</title> |
|
133
|
|
|
</head> |
|
134
|
|
|
<body id="front"> |
|
135
|
|
|
<div id="container"> |
|
136
|
|
|
<?php require($_SERVER['DOCUMENT_ROOT'] . "/static/header.php"); ?> |
|
137
|
|
|
<div id="content"> |
|
138
|
|
|
<div class="wrapper"> |
|
139
|
|
|
<form method="post" enctype="multipart/form-data" id="submitform"> |
|
140
|
|
|
<b>Suspend User</b> |
|
141
|
|
|
<br><input placeholder="Subject" type="text" name="subject" required="required" size="63"></b><br> |
|
142
|
|
|
<input type="submit" name="suspend" value="Suspend"> |
|
143
|
|
|
</form><br> |
|
144
|
|
|
|
|
145
|
|
|
<form method="post" enctype="multipart/form-data" id="submitform"> |
|
146
|
|
|
<b>Unsuspend User</b> |
|
147
|
|
|
<br><input placeholder="Subject" type="text" name="subject" required="required" size="63"></b><br> |
|
148
|
|
|
<input type="submit" name="unsuspend" value="Unsuspend"> |
|
149
|
|
|
</form><br> |
|
150
|
|
|
|
|
151
|
|
|
<form method="post" enctype="multipart/form-data" id="submitform"> |
|
152
|
|
|
<b>Delete Posts from User</b> |
|
153
|
|
|
<br><input placeholder="Subject" type="text" name="subject" required="required" size="63"></b><br> |
|
154
|
|
|
<input type="submit" name="del" value="Delete"> |
|
155
|
|
|
</form><br> |
|
156
|
|
|
<?php require($_SERVER['DOCUMENT_ROOT'] . "/static/footer.php"); ?> |
|
157
|
|
|
</div> |
|
158
|
|
|
</div> |
|
159
|
|
|
</div> |
|
160
|
|
|
</body> |
|
161
|
|
|
</html> |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.