Project

General

Profile

Download (11.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_openvpn.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c)  2008 Shrew Soft Inc.
8
 *
9
 *	Redistribution and use in source and binary forms, with or without modification,
10
 *	are permitted provided that the following conditions are met:
11
 *
12
 *	1. Redistributions of source code must retain the above copyright notice,
13
 *		this list of conditions and the following disclaimer.
14
 *
15
 *	2. Redistributions in binary form must reproduce the above copyright
16
 *		notice, this list of conditions and the following disclaimer in
17
 *		the documentation and/or other materials provided with the
18
 *		distribution.
19
 *
20
 *	3. All advertising materials mentioning features or use of this software
21
 *		must display the following acknowledgment:
22
 *		"This product includes software developed by the pfSense Project
23
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
24
 *
25
 *	4. The names "pfSense" and "pfSense Project" must not be used to
26
 *		 endorse or promote products derived from this software without
27
 *		 prior written permission. For written permission, please contact
28
 *		 coreteam@pfsense.org.
29
 *
30
 *	5. Products derived from this software may not be called "pfSense"
31
 *		nor may "pfSense" appear in their names without prior written
32
 *		permission of the Electric Sheep Fencing, LLC.
33
 *
34
 *	6. Redistributions of any form whatsoever must retain the following
35
 *		acknowledgment:
36
 *
37
 *	"This product includes software developed by the pfSense Project
38
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
52
 *
53
 *	====================================================================
54
 *
55
 */
56

    
57
##|+PRIV
58
##|*IDENT=page-status-openvpn
59
##|*NAME=Status: OpenVPN
60
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
61
##|*MATCH=status_openvpn.php*
62
##|-PRIV
63

    
64
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
65
$shortcut_section = "openvpn";
66

    
67
require("guiconfig.inc");
68
require_once("openvpn.inc");
69
require_once("shortcuts.inc");
70
require_once("service-utils.inc");
71

    
72
/* Handle AJAX */
73
if ($_GET['action']) {
74
	if ($_GET['action'] == "kill") {
75
		$port  = $_GET['port'];
76
		$remipp  = $_GET['remipp'];
77
		if (!empty($port) and !empty($remipp)) {
78
			$retval = openvpn_kill_client($port, $remipp);
79
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
80
		} else {
81
			echo gettext("invalid input");
82
		}
83
		exit;
84
	}
85
}
86

    
87
$servers = openvpn_get_active_servers();
88
$sk_servers = openvpn_get_active_servers("p2p");
89
$clients = openvpn_get_active_clients();
90

    
91
include("head.inc"); ?>
92

    
93
<form action="status_openvpn.php" method="get" name="iform">
94
<script type="text/javascript">
95
//<![CDATA[
96
	function killClient(mport, remipp) {
97
		var busy = function(index,icon) {
98
			$(icon).bind("onclick","");
99
			$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
100
			$(icon).css("cursor","wait");
101
		}
102

    
103
		$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
104

    
105
		$.ajax(
106
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
107
				"?action=kill&port=" + mport + "&remipp=" + remipp,
108
			{ type: "get", complete: killComplete }
109
		);
110
	}
111

    
112
	function killComplete(req) {
113
		var values = req.responseText.split("|");
114
		if (values[3] != "0") {
115
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
116
			return;
117
		}
118

    
119
		$('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
120
			function(index,row) { $(row).fadeOut(1000); }
121
		);
122
	}
123
//]]>
124
</script>
125

    
126
<?php
127
	$i = 0;
128
	foreach ($servers as $server):
129
?>
130

    
131
<div class="panel panel-default">
132
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client Connections')?></h2></div>
133
		<div class="panel-body table-responsive">
134
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
135
				<thead>
136
					<tr>
137
						<th><?=gettext("Common Name")?></th>
138
						<th><?=gettext("Real Address")?></th>
139
						<th><?=gettext("Virtual Address"); ?></th>
140
						<th><?=gettext("Connected Since"); ?></th>
141
						<th><?=gettext("Bytes Sent")?></th>
142
						<th><?=gettext("Bytes Received")?></th>
143
						<th><!-- Icons --></th>
144
					</tr>
145
				</thead>
146
				<tbody>
147

    
148
					<?php
149
							foreach ($server['conns'] as $conn):
150
					?>
151
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
152
						<td><?=$conn['common_name'];?></td>
153
						<td><?=$conn['remote_host'];?></td>
154
						<td><?=$conn['virtual_addr'];?></td>
155
						<td><?=$conn['connect_time'];?></td>
156
						<td><?=format_bytes($conn['bytes_sent']);?></td>
157
						<td><?=format_bytes($conn['bytes_recv']);?></td>
158
						<td>
159
							<a
160
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
161
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
162
							   title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
163
							<i class="fa fa-times"></i>
164
							</a>
165
						</td>
166
					</tr>
167
					<?php
168
							endforeach;
169
					?>
170
				</tbody>
171
				<tfoot>
172
					<tr>
173
						<td colspan="2">
174
							<table>
175
								<tr>
176
									<td>
177
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
178
										<?= get_service_status_icon($ssvc, true, true); ?>
179
										<?= get_service_control_GET_links($ssvc, true); ?>
180
									</td>
181
								</tr>
182
							</table>
183
						</td>
184
						<td colspan="5">
185
						</td>
186
					</tr>
187
				</tfoot>
188
			</table>
189
		</div>
190
</div>
191
<?php
192
		if (is_array($server['routes']) && count($server['routes'])):
193
?>
194
<div id="shroutebut-<?= $i ?>">
195
	<input type="button" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>" /> - <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
196
		<br /><br />
197
</div>
198
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
199
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
200
		<div class="panel-body table-responsive">
201
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
202
				<thead>
203
					<tr>
204
						<th><?=gettext("Common Name"); ?></th>
205
						<th><?=gettext("Real Address"); ?></th>
206
						<th><?=gettext("Target Network"); ?></th>
207
						<th><?=gettext("Last Used"); ?></th>
208
					</tr>
209
				</thead>
210
				<tbody>
211

    
212
<?php
213
			foreach ($server['routes'] as $conn):
214
?>
215
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
216
						<td><?=$conn['common_name'];?></td>
217
						<td><?=$conn['remote_host'];?></td>
218
						<td><?=$conn['virtual_addr'];?></td>
219
						<td><?=$conn['last_time'];?></td>
220
					</tr>
221
<?php
222
			endforeach;
223
?>
224
				</tbody>
225
				<tfoot>
226
					<tr>
227
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
228
					</tr>
229
				</tfoot>
230
			</table>
231
		</div>
232
</div>
233
<?php
234
		endif;
235
?>
236
<br />
237
<?php
238
		$i++;
239
	endforeach;
240
?>
241
<br />
242

    
243
<?php
244
	if (!empty($sk_servers)) {
245
?>
246
<div class="panel panel-default">
247
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
248
		<div class="panel-body table-responsive">
249
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
250
				<thead>
251
					<tr>
252
						<th><?=gettext("Name"); ?></th>
253
						<th><?=gettext("Status"); ?></th>
254
						<th><?=gettext("Connected Since"); ?></th>
255
						<th><?=gettext("Virtual Address"); ?></th>
256
						<th><?=gettext("Remote Host"); ?></th>
257
						<th><?=gettext("Bytes Sent"); ?></th>
258
						<th><?=gettext("Bytes Received"); ?></th>
259
						<th><?=gettext("Service"); ?></th>
260
					</tr>
261
				</thead>
262
				<tbody>
263

    
264
<?php
265
		foreach ($sk_servers as $sk_server):
266
?>
267
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
268
						<td><?=htmlspecialchars($sk_server['name']);?></td>
269
						<td><?=$sk_server['status'];?></td>
270
						<td><?=$sk_server['connect_time'];?></td>
271
						<td><?=$sk_server['virtual_addr'];?></td>
272
						<td><?=$sk_server['remote_host'];?></td>
273
						<td><?=format_bytes($sk_server['bytes_sent']);?></td>
274
						<td><?=format_bytes($sk_server['bytes_recv']);?></td>
275
						<td>
276
							<table>
277
								<tr>
278
									<td>
279
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
280
										<?= get_service_status_icon($ssvc, false, true); ?>
281
										<?= get_service_control_GET_links($ssvc, true); ?>
282
									</td>
283
								</tr>
284
							</table>
285
						</td>
286
					</tr>
287
<?php
288
		endforeach;
289
?>
290
				</tbody>
291
			</table>
292
		</div>
293
</div>
294

    
295
<?php
296
	}
297
?>
298
<br />
299
<?php
300
	if (!empty($clients)) {
301
?>
302
<div class="panel panel-default">
303
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
304
		<div class="panel-body table-responsive">
305
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
306
				<thead>
307
					<tr>
308
						<th><?=gettext("Name"); ?></th>
309
						<th><?=gettext("Status"); ?></th>
310
						<th><?=gettext("Connected Since"); ?></th>
311
						<th><?=gettext("Virtual Address"); ?></th>
312
						<th><?=gettext("Remote Host"); ?></th>
313
						<th><?=gettext("Bytes Sent"); ?></th>
314
						<th><?=gettext("Bytes Received"); ?></th>
315
						<th><?=gettext("Service"); ?></th>
316
					</tr>
317
				</thead>
318
				<tbody>
319

    
320
<?php
321
		foreach ($clients as $client):
322
?>
323
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
324
						<td><?=htmlspecialchars($client['name']);?></td>
325
						<td><?=$client['status'];?></td>
326
						<td><?=$client['connect_time'];?></td>
327
						<td><?=$client['virtual_addr'];?></td>
328
						<td><?=$client['remote_host'];?></td>
329
						<td><?=format_bytes($client['bytes_sent']);?></td>
330
						<td><?=format_bytes($client['bytes_recv']);?></td>
331
						<td>
332
							<table>
333
								<tr>
334
									<td>
335
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
336
										<?= get_service_status_icon($ssvc, false, true); ?>
337
										<?= get_service_control_GET_links($ssvc, true); ?>
338
									</td>
339
								</tr>
340
							</table>
341
						</td>
342
					</tr>
343
<?php
344
		endforeach;
345
?>
346
				</tbody>
347
			</table>
348
		</div>
349
	</div>
350

    
351
<?php
352
}
353

    
354
if ($DisplayNote) {
355
 	print_info_box(gettext("If you have custom options that override the management features of OpenVPN on a client or server, they will cause that OpenVPN instance to not work correctly with this status page."));
356
}
357

    
358
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
359
	print_info_box(gettext("No OpenVPN instances defined."));
360
}
361
?>
362
</form>
363

    
364
<script type="text/javascript">
365
//<![CDATA[
366

    
367
function show_routes(id, buttonid) {
368
	document.getElementById(buttonid).innerHTML='';
369
	aodiv = document.getElementById(id);
370
	aodiv.style.display = "block";
371
}
372

    
373
//]]>
374
</script>
375

    
376
<?php include("foot.inc"); ?>
(179-179/227)