Project

General

Profile

Download (10.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_openvpn.php
4

    
5
	Copyright (C) 2005 Scott Ullrich, Colin Smith
6
	Copyright (C) 2008 Shrew Soft Inc.
7
	Copyright (C) 2010 Jim Pingle
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9

    
10
	AJAX bits borrowed from diag_dump_states.php
11

    
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23

    
24
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
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
$shortcut_section = "openvpn";
48

    
49
require("guiconfig.inc");
50
require_once("openvpn.inc");
51
require_once("shortcuts.inc");
52
require_once("service-utils.inc");
53

    
54
/* Handle AJAX */
55
if($_GET['action']) {
56
	if($_GET['action'] == "kill") {
57
		$port  = $_GET['port'];
58
		$remipp  = $_GET['remipp'];
59
		if (!empty($port) and !empty($remipp)) {
60
			$retval = kill_client($port, $remipp);
61
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
62
		} else {
63
			echo gettext("invalid input");
64
		}
65
		exit;
66
	}
67
}
68

    
69

    
70
function kill_client($port, $remipp) {
71
	global $g;
72

    
73
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
74
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
75
	$errval = null;
76
	$errstr = null;
77

    
78
	/* open a tcp connection to the management port of each server */
79
	$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
80
	$killed = -1;
81
	if ($fp) {
82
		stream_set_timeout($fp, 1);
83
		fputs($fp, "kill {$remipp}\n");
84
		while (!feof($fp)) {
85
			$line = fgets($fp, 1024);
86

    
87
			$info = stream_get_meta_data($fp);
88
			if ($info['timed_out']) {
89
				break;
90
			}
91

    
92
			/* parse header list line */
93
			if (strpos($line, "INFO:") !== false) {
94
				continue;
95
			}
96
			if (strpos($line, "SUCCESS") !== false) {
97
				$killed = 0;
98
			}
99
			break;
100
		}
101
		fclose($fp);
102
	}
103
	return $killed;
104
}
105

    
106
$servers = openvpn_get_active_servers();
107
$sk_servers = openvpn_get_active_servers("p2p");
108
$clients = openvpn_get_active_clients();
109

    
110
include("head.inc"); ?>
111

    
112
<body>
113
<form action="status_openvpn.php" method="get" name="iform">
114
<script type="text/javascript">
115
//<![CDATA[
116
	function killClient(mport, remipp) {
117
		var busy = function(index,icon) {
118
			jQuery(icon).bind("onclick","");
119
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
120
			jQuery(icon).css("cursor","wait");
121
		}
122

    
123
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
124

    
125
		jQuery.ajax(
126
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
127
				"?action=kill&port=" + mport + "&remipp=" + remipp,
128
			{ type: "get", complete: killComplete }
129
		);
130
	}
131

    
132
	function killComplete(req) {
133
		var values = req.responseText.split("|");
134
		if(values[3] != "0") {
135
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
136
			return;
137
		}
138

    
139
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
140
			function(index,row) { jQuery(row).fadeOut(1000); }
141
		);
142
	}
143
//]]>
144
</script>
145

    
146
<?php
147
	$i = 0;
148
	foreach ($servers as $server):
149
?>
150

    
151
<div class="panel panel-default">
152
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client connections')?></h2></div>
153
		<div class="panel-body table-responsive">
154
			<table class="table table-striped table-hover">
155
				<thead>
156
					<tr>
157
						<th><?=gettext("Common Name")?></th>
158
						<th><?=gettext("Real Address")?></th>
159
						<th><?=gettext("Virtual Address"); ?></th>
160
						<th><?=gettext("Connected Since"); ?></th>
161
						<th><?=gettext("Bytes Sent")?></th>
162
						<th><?=gettext("Bytes Received")?></th>
163
					</tr>
164
				</thead>
165
				<tbody>
166
					
167
					<?php
168
							foreach ($server['conns'] as $conn):
169
					?>
170
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
171
						<td><?=$conn['common_name'];?></td>
172
						<td><?=$conn['remote_host'];?></td>
173
						<td><?=$conn['virtual_addr'];?></td>
174
						<td><?=$conn['connect_time'];?></td>
175
						<td><?=format_bytes($conn['bytes_sent']);?></td>
176
						<td><?=format_bytes($conn['bytes_recv']);?></td>
177
						<td>
178
							<a
179
							   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style="cursor:pointer;"
180
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
181
							   title="<?php echo gettext("Kill client connection from") . " " . $conn['remote_host']; ?>">
182
							<i class="icon icon-remove"></i>
183
							</a>
184
						</td>
185
					</tr>
186
					<?php
187
							endforeach;
188
					?>
189
				</tbody>
190
				<tfoot>
191
					<tr>
192
						<td>
193
							<table>
194
								<tr>
195
									<td>
196
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
197
										<?= get_service_status_icon($ssvc, true, true); ?>
198
										<?= get_service_control_links($ssvc, true); ?>
199
									</td>
200
								</tr>
201
							</table>
202
						</td>
203
					</tr>
204
				</tfoot>
205
			</table>
206
		</div>
207
</div>
208
<?php
209
		if (is_array($server['routes']) && count($server['routes'])):
210
?>
211
<div id="shroutebut-<?= $i ?>">
212
	<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.") ?>
213
		<br /><br />
214
</div>
215
<div class="panel panel-default">
216
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
217
		<div class="panel-body table-responsive">
218
			<table class="table table-striped table-hover">
219
				<thead>
220
					<tr>
221
						<th><?=gettext("Common Name"); ?></th>
222
						<th><?=gettext("Real Address"); ?></th>
223
						<th><?=gettext("Target Network"); ?></th>
224
						<th><?=gettext("Last Used"); ?></th>
225
					</tr>
226
				</thead>	
227
				<tbody>
228

    
229
<?php
230
			foreach ($server['routes'] as $conn):
231
?>
232
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
233
						<td><?=$conn['common_name'];?></td>
234
						<td><?=$conn['remote_host'];?></td>
235
						<td><?=$conn['virtual_addr'];?></td>
236
						<td><?=$conn['last_time'];?></td>
237
					</tr>
238
<?php
239
			endforeach;
240
?>
241
				</tbody>
242
				<tfoot>
243
					<tr>
244
						<td><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
245
					</tr>
246
				</tfoot>
247
			</table>
248
		</div>
249
</div>
250
<?php
251
		endif;
252
?>
253
<br />
254
<?php
255
		$i++;
256
	endforeach;
257
?>
258
<br />
259

    
260
<?php
261
	if (!empty($sk_servers)) {
262
?>
263
<div class="panel panel-default">
264
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
265
		<div class="panel-body table-responsive">
266
			<table class="table table-striped table-hover">
267
				<thead>
268
					<tr>  
269
						<th><?=gettext("Name"); ?></th>
270
						<th><?=gettext("Connected Since"); ?></th>
271
						<th><?=gettext("Virtual Addr"); ?></th>
272
						<th><?=gettext("Remote Host"); ?></th>
273
						<th><?=gettext("Bytes Sent"); ?></th>
274
						<th><?=gettext("Bytes Rcvd"); ?></th>
275
						<th><?=gettext("Service"); ?></th>
276
					</tr>
277
				</thead>
278
				<tbody>
279

    
280
<?php
281
		foreach ($sk_servers as $sk_server):
282
?>
283
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
284
						<td><?=htmlspecialchars($sk_server['name']);?></td>
285
						<td><?=$sk_server['status'];?></td>
286
						<td><?=$sk_server['connect_time'];?></td>
287
						<td><?=$sk_server['virtual_addr'];?></td>
288
						<td><?=$sk_server['remote_host'];?></td>
289
						<td><?=format_bytes($sk_server['bytes_sent']);?></td>
290
						<td><?=format_bytes($sk_server['bytes_recv']);?></td>
291
						<td>
292
							<table>
293
								<tr>
294
									<td>
295
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
296
										<?= get_service_status_icon($ssvc, false, true); ?>
297
										<?= get_service_control_links($ssvc, true); ?>
298
									</td>
299
								</tr>
300
							</table>
301
						</td>
302
					</tr>
303
<?php
304
		endforeach;
305
?>
306
				</tbody>
307
			</table>
308
		</div>
309
</div>
310

    
311
<?php
312
	}
313
?>
314
<br />
315
<?php
316
	if (!empty($clients)) {
317
?>
318
<div class="panel panel-default">
319
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
320
		<div class="panel-body table-responsive">
321
			<table class="table table-striped table-hover">
322
				<thead>
323
					<tr>  
324
						<th><?=gettext("Name"); ?></th>
325
						<th><?=gettext("Status"); ?></th>
326
						<th><?=gettext("Connected Since"); ?></th>
327
						<th><?=gettext("Virtual Addr"); ?></th>
328
						<th><?=gettext("Remote Host"); ?></th>
329
						<th><?=gettext("Bytes Sent"); ?></th>
330
						<th><?=gettext("Bytes Rcvd"); ?></th>
331
						<th><?=gettext("Service"); ?></th>
332
					</tr>
333
				</thead>
334
				<tbody>
335

    
336
<?php
337
		foreach ($clients as $client):
338
?>
339
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
340
						<td><?=htmlspecialchars($client['name']);?></td>
341
						<td><?=$client['status'];?></td>
342
						<td><?=$client['connect_time'];?></td>
343
						<td><?=$client['virtual_addr'];?></td>
344
						<td><?=$client['remote_host'];?></td>
345
						<td><?=format_bytes($client['bytes_sent']);?></td>
346
						<td><?=format_bytes($client['bytes_recv']);?></td>
347
						<td>
348
							<table>
349
								<tr>
350
									<td>
351
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
352
										<?= get_service_status_icon($ssvc, false, true); ?>
353
										<?= get_service_control_links($ssvc, true); ?>
354
									</td>
355
								</tr>
356
							</table>
357
						</td>
358
					</tr>
359
<?php
360
		endforeach;
361
?>
362
				</tbody>
363
			</table>
364
		</div>
365
</div>
366

    
367
<?php 
368
}
369

    
370
if ($DisplayNote) {
371
 	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."));
372
}
373

    
374
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
375
	print_info_box(gettext("No OpenVPN instances defined"));
376
}
377
?>
378
</form>
379
<?php include("fend.inc"); ?>
380
<script type="text/javascript">
381
//<![CDATA[
382
function show_routes(id, buttonid) {
383
	document.getElementById(buttonid).innerHTML='';
384
	aodiv = document.getElementById(id);
385
	aodiv.style.display = "block";
386
}
387
//]]>
388
</script>
389
</body>
390
</html>
(179-179/235)