1
|
<?php
|
2
|
/*
|
3
|
status_ovpenvpn.php
|
4
|
|
5
|
Copyright (C) 2010 Jim Pingle
|
6
|
Copyright (C) 2008 Shrew Soft Inc.
|
7
|
|
8
|
AJAX bits borrowed from diag_dump_states.php
|
9
|
Copyright (C) 2005 Scott Ullrich, Colin Smith
|
10
|
|
11
|
All rights reserved.
|
12
|
|
13
|
Redistribution and use in source and binary forms, with or without
|
14
|
modification, are permitted provided that the following conditions are met:
|
15
|
|
16
|
1. Redistributions of source code must retain the above copyright notice,
|
17
|
this list of conditions and the following disclaimer.
|
18
|
|
19
|
2. Redistributions in binary form must reproduce the above copyright
|
20
|
notice, this list of conditions and the following disclaimer in the
|
21
|
documentation and/or other materials provided with the distribution.
|
22
|
|
23
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
POSSIBILITY OF SUCH DAMAGE.
|
33
|
*/
|
34
|
/* DISABLE_PHP_LINT_CHECKING */
|
35
|
/*
|
36
|
pfSense_MODULE: openvpn
|
37
|
*/
|
38
|
|
39
|
##|+PRIV
|
40
|
##|*IDENT=page-status-openvpn
|
41
|
##|*NAME=Status: OpenVPN page
|
42
|
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
|
43
|
##|*MATCH=status_openvpn.php*
|
44
|
##|-PRIV
|
45
|
|
46
|
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
|
47
|
require("guiconfig.inc");
|
48
|
require_once("openvpn.inc");
|
49
|
|
50
|
/* Handle AJAX */
|
51
|
if($_GET['action']) {
|
52
|
if($_GET['action'] == "kill") {
|
53
|
$port = $_GET['port'];
|
54
|
$remipp = $_GET['remipp'];
|
55
|
if (!empty($port) and !empty($remipp)) {
|
56
|
$retval = kill_client($port, $remipp);
|
57
|
echo htmlentities("|{$port}|{$remipp}|{$retval}|");
|
58
|
} else {
|
59
|
echo gettext("invalid input");
|
60
|
}
|
61
|
exit;
|
62
|
}
|
63
|
}
|
64
|
|
65
|
|
66
|
function kill_client($port, $remipp) {
|
67
|
$tcpsrv = "tcp://127.0.0.1:{$port}";
|
68
|
$errval;
|
69
|
$errstr;
|
70
|
|
71
|
/* open a tcp connection to the management port of each server */
|
72
|
$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
|
73
|
$killed = -1;
|
74
|
if ($fp) {
|
75
|
fputs($fp, "kill {$remipp}\n");
|
76
|
while (!feof($fp)) {
|
77
|
$line = fgets($fp, 1024);
|
78
|
/* parse header list line */
|
79
|
if (strpos($line, "INFO:"))
|
80
|
continue;
|
81
|
if (strpos($line, "SUCCESS")) {
|
82
|
$killed = 0;
|
83
|
}
|
84
|
break;
|
85
|
}
|
86
|
fclose($fp);
|
87
|
}
|
88
|
return $killed;
|
89
|
}
|
90
|
|
91
|
$servers = openvpn_get_active_servers();
|
92
|
$clients = openvpn_get_active_clients();
|
93
|
|
94
|
include("head.inc"); ?>
|
95
|
|
96
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
|
97
|
<script src="/javascript/sorttable.js" type="text/javascript"></script>
|
98
|
<?php include("fbegin.inc"); ?>
|
99
|
<form action="status_openvpn.php" method="get" name="iform">
|
100
|
<script type="text/javascript">
|
101
|
function killClient(mport, remipp) {
|
102
|
var busy = function(icon) {
|
103
|
icon.onclick = "";
|
104
|
icon.src = icon.src.replace("\.gif", "_d.gif");
|
105
|
icon.style.cursor = "wait";
|
106
|
}
|
107
|
|
108
|
$A(document.getElementsByName("i:" + mport + ":" + remipp)).each(busy);
|
109
|
|
110
|
new Ajax.Request(
|
111
|
"<?=$_SERVER['SCRIPT_NAME'];?>" +
|
112
|
"?action=kill&port=" + mport + "&remipp=" + remipp,
|
113
|
{ method: "get", onComplete: killComplete }
|
114
|
);
|
115
|
}
|
116
|
|
117
|
function killComplete(req) {
|
118
|
var values = req.responseText.split("|");
|
119
|
if(values[3] != "0") {
|
120
|
alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
|
121
|
return;
|
122
|
}
|
123
|
|
124
|
$A(document.getElementsByName("r:" + values[1] + ":" + values[2])).each(
|
125
|
function(row) { Effect.Fade(row, { duration: 1.0 }); }
|
126
|
);
|
127
|
}
|
128
|
</script>
|
129
|
|
130
|
<?php foreach ($servers as $server): ?>
|
131
|
|
132
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
|
133
|
<tr>
|
134
|
<td colspan="6" class="listtopic">
|
135
|
<?=gettext("Client connections for"); ?> <?=$server['name'];?>
|
136
|
</td>
|
137
|
</tr>
|
138
|
<tr>
|
139
|
<td>
|
140
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
|
141
|
<tr>
|
142
|
<td class="listhdrr"><?=gettext("Common Name"); ?></td>
|
143
|
<td class="listhdrr"><?=gettext("Real Address"); ?></td>
|
144
|
<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
|
145
|
<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
|
146
|
<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
|
147
|
<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
|
148
|
</tr>
|
149
|
|
150
|
<?php foreach ($server['conns'] as $conn): ?>
|
151
|
<tr name='<?php echo "r:{$server['port']}:{$conn['remote_host']}"; ?>'>
|
152
|
<td class="listlr">
|
153
|
<?=$conn['common_name'];?>
|
154
|
</td>
|
155
|
<td class="listr">
|
156
|
<?=$conn['remote_host'];?>
|
157
|
</td>
|
158
|
<td class="listr">
|
159
|
<?=$conn['virtual_addr'];?>
|
160
|
</td>
|
161
|
<td class="listr">
|
162
|
<?=$conn['connect_time'];?>
|
163
|
</td>
|
164
|
<td class="listr">
|
165
|
<?=$conn['bytes_sent'];?>
|
166
|
</td>
|
167
|
<td class="listr">
|
168
|
<?=$conn['bytes_recv'];?>
|
169
|
</td>
|
170
|
<td class='list'>
|
171
|
<img src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' height='17' width='17' border='0'
|
172
|
onclick="killClient('<?php echo $server['port']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
|
173
|
name='<?php echo "i:{$server['port']}:{$conn['remote_host']}"; ?>'
|
174
|
title='<?=gettext("Kill client connection from"); ?> <?php echo $conn['remote_host']; ?>' alt='' />
|
175
|
</td>
|
176
|
</tr>
|
177
|
|
178
|
<?php endforeach; ?>
|
179
|
<tr>
|
180
|
<td colspan="6" class="list" height="12"></td>
|
181
|
</tr>
|
182
|
|
183
|
</table>
|
184
|
</td>
|
185
|
</tr>
|
186
|
</table>
|
187
|
|
188
|
<?php endforeach; ?>
|
189
|
<br>
|
190
|
|
191
|
|
192
|
<?php if (!empty($clients)) { ?>
|
193
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
|
194
|
<tr>
|
195
|
<td colspan="6" class="listtopic">
|
196
|
<?=gettext("OpenVPN client instances statistics"); ?>
|
197
|
</td>
|
198
|
</tr>
|
199
|
<tr>
|
200
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
|
201
|
<tr>
|
202
|
<td class="listhdrr"><?=gettext("Name"); ?></td>
|
203
|
<td class="listhdrr"><?=gettext("Status"); ?></td>
|
204
|
<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
|
205
|
<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
|
206
|
<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
|
207
|
<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
|
208
|
<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
|
209
|
</tr>
|
210
|
|
211
|
<?php foreach ($clients as $client): ?>
|
212
|
<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
|
213
|
<td class="listlr">
|
214
|
<?=$client['name'];?>
|
215
|
</td>
|
216
|
<td class="listlr">
|
217
|
<?=$client['status'];?>
|
218
|
</td>
|
219
|
<td class="listr">
|
220
|
<?=$client['connect_time'];?>
|
221
|
</td>
|
222
|
<td class="listr">
|
223
|
<?=$client['virtual_addr'];?>
|
224
|
</td>
|
225
|
<td class="listr">
|
226
|
<?=$client['remote_host'];?>
|
227
|
</td>
|
228
|
<td class="listr">
|
229
|
<?=$client['bytes_sent'];?>
|
230
|
</td>
|
231
|
<td class="listr">
|
232
|
<?=$client['bytes_recv'];?>
|
233
|
</td>
|
234
|
</tr>
|
235
|
<?php endforeach; ?>
|
236
|
</table>
|
237
|
</tr>
|
238
|
</table>
|
239
|
|
240
|
<?php
|
241
|
}
|
242
|
|
243
|
if ($DisplayNote) {
|
244
|
echo "<br/><b>" . gettext("NOTE") . ":</b> " . gettext("You need to bind each OpenVPN client to enable its management daemon: use 'Local port' setting in the OpenVPN client screen");
|
245
|
}
|
246
|
|
247
|
if ((empty($clients)) && (empty($servers))) {
|
248
|
echo gettext("No OpenVPN instance defined");
|
249
|
}
|
250
|
?>
|
251
|
|
252
|
|
253
|
<?php include("fend.inc"); ?>
|