-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.php
More file actions
144 lines (127 loc) · 2.95 KB
/
index.php
File metadata and controls
144 lines (127 loc) · 2.95 KB
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
<?php
// Configuration values --------
$vpn_name = "VPN Status";
$vpn_host = "127.0.0.1";
$vpn_port = 5555;
// -----------------------------
$fp = fsockopen($vpn_host, $vpn_port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
exit;
}
fwrite($fp, "status\n\n\n");
sleep(1);
fwrite($fp, "quit\n\n\n");
sleep(1);
$clients = array();
$inclients = $inrouting = false;
while (!feof($fp)) {
$line = fgets($fp, 128);
if (substr($line, 0, 13) == "ROUTING TABLE") {
$inclients = false;
}
if ($inclients) {
$cdata = split(',', $line);
$clines[$cdata[1]] = array($cdata[2], $cdata[3], $cdata[4]);
}
if (substr($line, 0, 11) == "Common Name") {
$inclients = true;
}
if (substr($line, 0, 12) == "GLOBAL STATS") {
$inrouting = false;
}
if ($inrouting) {
$routedata = split(',', $line);
array_push($clients, array_merge($routedata,
$clines[$routedata[2]]));
}
if (substr($line, 0, 15) == "Virtual Address") {
$inrouting = true;
}
}
$headers = array('VPN Address', 'Name', 'Real Address', 'Last Active',
'Received', 'Sent', 'Connected Since');
$tdalign = array('left', 'left', 'left', 'left', 'right', 'right',
'left');
/* DEBUG
print "<pre>";
print_r($headers);
print_r($clients);
print_r($clines);
print_r($routedata);
print "</pre>";
*/
fclose($fp);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $vpn_name ?> status</title>
<meta http-equiv='refresh' content='300' />
<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
background-color: #E5EAF0;
}
h1 {
color: green;
font-size: 24px;
text-align: center;
padding-bottom: 0;
margin-bottom: 0;
}
p.info {
text-align: center;
font-size: 12px;
}
.status0 {
background: #ebb;
}
.status1 {
background: lime;
}
table {
#border: medium solid maroon;
margin: 0 auto;
border-collapse: collapse;
}
th {
background: maroon;
color: white;
}
tr {
border-bottom: 1px solid silver;
}
td {
padding: 0px 10px 0px 10px;
}
</style>
</head>
<body>
<table>
<tr>
<?php foreach ($headers as $th) { ?>
<th><?php echo $th?></th>
<?php } ?>
</tr>
<?php foreach ($clients as $client) {
$client[3] = date ('Y-m-d H:i', strtotime($client[3]));
$client[6] = date ('Y-m-d H:i', strtotime($client[6]));
$client[4] = number_format($client[4], 0, '', '.');
$client[5] = number_format($client[5], 0, '', '.');
$client[2] = preg_replace('/(.*):.*/', '$1', $client[2]);
$i = 0;
?>
<tr>
<?php foreach ($client as $td) { ?>
<td align='<?php echo $tdalign[$i++] ?>'><?php echo $td?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
<p class='info'>This page gets reloaded every 5 min.<br />Last update:
<b><?php echo date ("Y-m-d H:i:s") ?></b></p>
</body>
</html>