Project

General

Profile

Download (11.6 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
	<button type="button" class="btn btn-info" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>">
196
		<i class="fa fa-plus-circle icon-embed-btn"></i>
197
		<?php echo gettext("Show Routing Table"); ?>
198
	</button>
199
	- <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
200
	<br /><br />
201
</div>
202
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
203
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
204
		<div class="panel-body table-responsive">
205
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
206
				<thead>
207
					<tr>
208
						<th><?=gettext("Common Name"); ?></th>
209
						<th><?=gettext("Real Address"); ?></th>
210
						<th><?=gettext("Target Network"); ?></th>
211
						<th><?=gettext("Last Used"); ?></th>
212
					</tr>
213
				</thead>
214
				<tbody>
215

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

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

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

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

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

    
355
<?php
356
}
357

    
358
if ($DisplayNote) {
359
 	print_info_box(gettext("If there are 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."));
360
}
361

    
362
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
363
	print_info_box(gettext("No OpenVPN instances defined."));
364
}
365
?>
366
</form>
367

    
368
<script type="text/javascript">
369
//<![CDATA[
370

    
371
function show_routes(id, buttonid) {
372
	document.getElementById(buttonid).innerHTML='';
373
	aodiv = document.getElementById(id);
374
	aodiv.style.display = "block";
375
}
376

    
377
//]]>
378
</script>
379

    
380
<?php include("foot.inc"); ?>
(179-179/225)