forked from firefly2442/phpftpwho
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·291 lines (261 loc) · 7.95 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<?php
//Want to disable the display of System Uptime?
//Set this variable to false
$display_system_uptime = true;
//Load style sheet
//<link rel="stylesheet" type="text/css" href="/stylesheets/default.css">
$template = $_GET['template'];
if ($template == "" || $template == "default") //load default style sheet
{
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheets/default.css\">";
$template = "default"; //in case template is not specified
}
else //load another style sheet
{
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheets/" . $template . ".css\">";
}
?>
<title>phpftpwho</title>
</head>
<body>
<center>
<h2>Current FTP Access</h2>
</center>
<?php
//run ftpwho command
$output = shell_exec("ftpwho -v");
if ($output == "") //run alternative command
$output = shell_exec("ftpwho -v -f /var/run/proftpd/proftpd.scoreboard");
if ($output == "") //run another alternative command
$output = shell_exec("/usr/bin/ftpwho -v");
if ($output == "") //run another alternative command
$output = shell_exec("/usr/local/bin/ftpwho -v");
if ($output == "")
echo "<p class=\"error\"><b>Error, unable to run ftpwho. Please check that Proftpd is running.</b></p><br>";
if (strpos($output, "up for") == true) //only for standalone?
{
$uptime = substr($output, strpos($output, "for") + 3, strlen($output));
$uptime = substr($uptime, 0, strpos($uptime, "min") + 3);
$output = substr($output, strpos($output, "min") + 3, strlen($output));
}
else //only for inetd?
{
$uptime = "Unknown";
$output = substr($output, strpos($output, "daemon:") + 7, strlen($output));
}
if ($display_system_uptime == true)
{
$computer_up = shell_exec("uptime");
echo "<b>System Uptime: </b>\n" . $computer_up;
echo "<br>";
}
echo "<b>FTP Server Uptime: </b>\n" . $uptime;
?>
<br><br>
<table>
<tr class="box_titles">
<td><b>ID</b></td>
<td><b>Username</b></td>
<td><b>Time Connected</b></td>
<td><b>Time Idle/Percent Complete</b></td>
<td><b>Operation</b></td>
<td><b>KB/s</b></td>
<td><b>Client</b></td>
<td><b>Server</b></td>
<td><b>Location</b></td>
</tr>
<?php
$user_count = 0;
if (!strpos($output, "no users")) //one or more users connected
{
$tok = strtok($output, " \n");
while ($tok != "Service" && $tok != "class" && $tok != false) //check for ending
{
$user_count++;
echo "<tr class=\"general_row\"><td>" . $tok; //ID
$username = strtok(" \n");
if ($username == "(none)")
echo "<td class=\"authentication\">";
else
echo "<td>";
echo $username . "</td>"; //user
$timeconnected = strtok(" \n");
if ($timeconnected == "(" || $timeconnected == "[")
{
$timeconnected = strtok(" \n");
echo "<td>" . substr($timeconnected, 0, strlen($timeconnected)-1) . "</td>"; //time connected
}
else
echo "<td>" . substr($timeconnected, 1, strlen($timeconnected)-2) . "</td>"; //time connected
$time_idle = strtok(" \n");
if ($time_idle == "(authenticating)") //user hasn't logged in yet
{
$client = "-";
$server = "-";
$kbps = "-";
$location = "-";
echo "<td class=\"authentication\">";
echo $time_idle . "</td>";
echo "<td>-</td><td>";
$time_idle = strtok(" \n");
$time_idle = str_replace("\t", "", $time_idle);
if ($time_idle == "KB/s:")
{
$kbps = strtok(" \n");
$time_idle = strtok(" \n");
$time_idle = str_replace("\t", "", $time_idle);
}
if ($time_idle == "client:")
{
$client = strtok(" \n");
$client = $client . strtok(" \n");
$client = str_replace("[", "\n[", $client); //separate with newline
$time_idle = strtok(" \n");
$time_idle = str_replace("\t", "", $time_idle);
}
if ($time_idle == "server:")
{
$server = strtok(" \n");
$server = $server . strtok(" \n");
$server = str_replace("(", "\n(", $server); //separate with newline
$time_idle = strtok(" \n");
$time_idle = str_replace("\t", "", $time_idle);
}
$tok = $time_idle;
echo $kbps . "</td>";
echo "<td>" . $client . "</td>";
echo "<td>" . $server. "</td>";
echo "<td>-</td>";
}
else //some type of operation is being performed or was performed
{
$client = "-";
$server = "-";
$kbps = "-";
$location = "";
echo "<td>";
if ($time_idle == "(")
{
$time_idle = strtok(" \n");
echo substr($time_idle, 0, strlen($time_idle)-1) . "</td>"; //time idle
}
else
echo $time_idle . "</td>";
$time_idle = strtok(" \n");
echo "<td class=\"operation\">";
while ($time_idle != "KB/s:" && $time_idle != "client:" && $time_idle != "idle")
{
echo " " . $time_idle;
$time_idle = strtok(" \n");
$time_idle = str_replace("\t", "", $time_idle);
}
if ($time_idle == "idle")
{
echo $time_idle . "</td>";
$time_idle = strtok(" \n");
}
$time_idle = str_replace("\t", "", $time_idle);
if ($time_idle == "KB/s:")
{
$kbps = strtok(" \n");
$time_idle = strtok(" \n");
$time_idle = str_replace("\t", "", $time_idle);
}
if ($time_idle == "client:")
{
$client = strtok(" \n");
$client = $client . strtok(" \n");
$client = str_replace("[", "\n[", $client); //separate with newline
$time_idle = strtok(" \n");
$time_idle = str_replace("\t", "", $time_idle);
}
if ($time_idle == "server:")
{
$server = strtok(" \n");
$server = $server . strtok("\n");
$server = str_replace("(", "\n(", $server); //separate with newline
$time_idle = strtok(" \n");
$time_idle = str_replace("\t", "", $time_idle);
}
if ($time_idle == "protocol:")
{
//throw this information out, don't really need it
$time_idle = strtok(" \n");
$time_idle = strtok(" \n");
$time_idle = str_replace("\t", "", $time_idle);
}
if ($time_idle == "location:")
{
$time_idle = strtok(" \n");
while (!is_numeric($time_idle) && $time_idle != "Service" && $time_idle != "class:") //accounts for spaces in directory names and files
{
$location = $location . " " . $time_idle;
$time_idle = strtok(" \n");
}
}
if ($time_idle == "class:")
{
//throw this information out, don't really need it
$time_idle = strtok(" \n");
$time_idle = strtok(" \n");
$time_idle = str_replace("\t", "", $time_idle);
}
echo "</td><td>";
echo $kbps . "</td>";
echo "<td>" . $client . "</td>";
echo "<td>" . $server . "</td>";
echo "<td>" . $location . "</td>";
$tok = $time_idle;
}
echo "</tr>\n";
}
}
else
{
//nobody is connected so display nothing
echo "<tr><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr>\n";
}
?>
<tr class="box_titles"><td><b>Total Users: <?=$user_count?></b></td></tr>
</table>
<br><br>
<form method=GET ACTION="index.php">
Template:
<select name="template">
<?php
//find all .css files in folder
//add them as possible selections
//make selected be default or whatever $template variable is
if ($handle = opendir('stylesheets')) //open stylesheet directory
{
while (false !== ($file = readdir($handle))) //find all files
{
if ($file != "." && $file != "..") //take out these non-files
{
if (substr($file, -4) == ".css") //make sure we only include .css file endings
{
$file = str_replace(".css", "", $file);
echo "<option value=\"" . $file . "\" ";
if ($template === $file)
{
echo "selected";
}
echo ">" . $file;
}
}
}
closedir($handle);
}
?>
</select>
<input type="submit" value="Submit">
</form>
<br><hr>
<center><a href="https://github.com/firefly2442/phpftpwho/">phpftpwho</a>
<br>Version: 1.06</center>
</body>
</html>