Project

General

Profile

Download (11.6 KB) Statistics
| Branch: | Tag: | Revision:
1 0927fb8c jim-p
<?php
2 63084885 Matthew Grooms
/*
3 ce77a9c4 Phil Davis
	status_openvpn.php
4 63084885 Matthew Grooms
*/
5 b9043cdc Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 cb41dd63 Renato Botelho
 *	Copyright (c)  2008 Shrew Soft Inc.
8 b9043cdc Stephen Beaver
 *
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 63084885 Matthew Grooms
57
##|+PRIV
58
##|*IDENT=page-status-openvpn
59 5230f468 jim-p
##|*NAME=Status: OpenVPN
60 63084885 Matthew Grooms
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
61
##|*MATCH=status_openvpn.php*
62
##|-PRIV
63
64 e9d35ff5 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
65 7d7b5a48 jim-p
$shortcut_section = "openvpn";
66
67 63084885 Matthew Grooms
require("guiconfig.inc");
68 53663f57 jim-p
require_once("openvpn.inc");
69 2eaa97b9 jim-p
require_once("shortcuts.inc");
70 c92ccc70 Renato Botelho
require_once("service-utils.inc");
71 63084885 Matthew Grooms
72 0927fb8c jim-p
/* Handle AJAX */
73 abe98adb Phil Davis
if ($_GET['action']) {
74
	if ($_GET['action'] == "kill") {
75 0927fb8c jim-p
		$port  = $_GET['port'];
76
		$remipp  = $_GET['remipp'];
77
		if (!empty($port) and !empty($remipp)) {
78 61fce4a6 Phil Davis
			$retval = openvpn_kill_client($port, $remipp);
79 0927fb8c jim-p
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
80
		} else {
81 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
82 0927fb8c jim-p
		}
83
		exit;
84
	}
85
}
86
87 53663f57 jim-p
$servers = openvpn_get_active_servers();
88 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
89 53663f57 jim-p
$clients = openvpn_get_active_clients();
90 63084885 Matthew Grooms
91 0927fb8c jim-p
include("head.inc"); ?>
92
93
<form action="status_openvpn.php" method="get" name="iform">
94
<script type="text/javascript">
95 4d33138f Colin Fleming
//<![CDATA[
96 0927fb8c jim-p
	function killClient(mport, remipp) {
97 b9144088 jim-p
		var busy = function(index,icon) {
98 3f98044a Francisco Cavalcante
			$(icon).bind("onclick","");
99
			$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
100
			$(icon).css("cursor","wait");
101 0927fb8c jim-p
		}
102
103 3f98044a Francisco Cavalcante
		$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
104 0927fb8c jim-p
105 3f98044a Francisco Cavalcante
		$.ajax(
106 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
107
				"?action=kill&port=" + mport + "&remipp=" + remipp,
108 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
109 0927fb8c jim-p
		);
110
	}
111
112
	function killComplete(req) {
113
		var values = req.responseText.split("|");
114 abe98adb Phil Davis
		if (values[3] != "0") {
115 0927fb8c jim-p
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
116
			return;
117
		}
118
119 3f98044a Francisco Cavalcante
		$('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
120
			function(index,row) { $(row).fadeOut(1000); }
121 0927fb8c jim-p
		);
122
	}
123 4d33138f Colin Fleming
//]]>
124 0927fb8c jim-p
</script>
125 c64a0911 Hari
126 42b0c921 Phil Davis
<?php
127
	$i = 0;
128
	foreach ($servers as $server):
129
?>
130 0927fb8c jim-p
131 c64a0911 Hari
<div class="panel panel-default">
132 3d7a8696 k-paulius
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client Connections')?></h2></div>
133 c64a0911 Hari
		<div class="panel-body table-responsive">
134 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
135 c64a0911 Hari
				<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 ff59b884 Stephen Beaver
						<th><!-- Icons --></th>
144 c64a0911 Hari
					</tr>
145
				</thead>
146
				<tbody>
147 919d91f9 Phil Davis
148 9f605c1c Hari
					<?php
149
							foreach ($server['conns'] as $conn):
150
					?>
151 c64a0911 Hari
					<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 9f605c1c Hari
							<a
160 5c0ab3cd NewEraCracker
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
161 c64a0911 Hari
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
162 98128ad6 Phil Davis
							   title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
163 1b7379f9 Jared Dillard
							<i class="fa fa-times"></i>
164 9f605c1c Hari
							</a>
165 c64a0911 Hari
						</td>
166
					</tr>
167 9f605c1c Hari
					<?php
168
							endforeach;
169
					?>
170 c64a0911 Hari
				</tbody>
171
				<tfoot>
172
					<tr>
173 e9701cfe Stephen Beaver
						<td colspan="2">
174 c64a0911 Hari
							<table>
175
								<tr>
176
									<td>
177
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
178
										<?= get_service_status_icon($ssvc, true, true); ?>
179 dca4eadf Stephen Beaver
										<?= get_service_control_links($ssvc); ?>
180 c64a0911 Hari
									</td>
181
								</tr>
182
							</table>
183
						</td>
184 e9701cfe Stephen Beaver
						<td colspan="5">
185
						</td>
186 c64a0911 Hari
					</tr>
187
				</tfoot>
188
			</table>
189
		</div>
190
</div>
191 42b0c921 Phil Davis
<?php
192
		if (is_array($server['routes']) && count($server['routes'])):
193
?>
194 ec970b50 jim-p
<div id="shroutebut-<?= $i ?>">
195 37676f4e jim-p
	<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 ec970b50 jim-p
</div>
202 56fafd85 Stephen Beaver
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
203 c64a0911 Hari
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
204
		<div class="panel-body table-responsive">
205 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
206 c64a0911 Hari
				<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 919d91f9 Phil Davis
				</thead>
214 c64a0911 Hari
				<tbody>
215 ec970b50 jim-p
216 42b0c921 Phil Davis
<?php
217
			foreach ($server['routes'] as $conn):
218
?>
219 c64a0911 Hari
					<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 42b0c921 Phil Davis
<?php
226
			endforeach;
227
?>
228 c64a0911 Hari
				</tbody>
229
				<tfoot>
230
					<tr>
231 e9701cfe Stephen Beaver
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
232 c64a0911 Hari
					</tr>
233
				</tfoot>
234
			</table>
235
		</div>
236
</div>
237 42b0c921 Phil Davis
<?php
238
		endif;
239
?>
240 8cd558b6 ayvis
<br />
241 42b0c921 Phil Davis
<?php
242
		$i++;
243
	endforeach;
244
?>
245 8cd558b6 ayvis
<br />
246 d0f6649c pierrepomes
247 42b0c921 Phil Davis
<?php
248
	if (!empty($sk_servers)) {
249
?>
250 c64a0911 Hari
<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 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
254 c64a0911 Hari
				<thead>
255 919d91f9 Phil Davis
					<tr>
256 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
257 e9701cfe Stephen Beaver
						<th><?=gettext("Status"); ?></th>
258 c64a0911 Hari
						<th><?=gettext("Connected Since"); ?></th>
259 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
260 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
261
						<th><?=gettext("Bytes Sent"); ?></th>
262 a66ce627 NewEraCracker
						<th><?=gettext("Bytes Received"); ?></th>
263 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
264
					</tr>
265
				</thead>
266
				<tbody>
267 d0f6649c pierrepomes
268 42b0c921 Phil Davis
<?php
269
		foreach ($sk_servers as $sk_server):
270
?>
271 c64a0911 Hari
					<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 dca4eadf Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
286 c64a0911 Hari
									</td>
287
								</tr>
288
							</table>
289
						</td>
290
					</tr>
291 42b0c921 Phil Davis
<?php
292
		endforeach;
293
?>
294 c64a0911 Hari
				</tbody>
295 a5eb046f Renato Botelho
			</table>
296 c64a0911 Hari
		</div>
297
</div>
298 95305736 jim-p
299
<?php
300 42b0c921 Phil Davis
	}
301
?>
302 8cd558b6 ayvis
<br />
303 42b0c921 Phil Davis
<?php
304
	if (!empty($clients)) {
305
?>
306 c64a0911 Hari
<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 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
310 c64a0911 Hari
				<thead>
311 919d91f9 Phil Davis
					<tr>
312 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
313
						<th><?=gettext("Status"); ?></th>
314
						<th><?=gettext("Connected Since"); ?></th>
315 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
316 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
317
						<th><?=gettext("Bytes Sent"); ?></th>
318 a66ce627 NewEraCracker
						<th><?=gettext("Bytes Received"); ?></th>
319 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
320
					</tr>
321
				</thead>
322
				<tbody>
323 d0f6649c pierrepomes
324 42b0c921 Phil Davis
<?php
325
		foreach ($clients as $client):
326
?>
327 c64a0911 Hari
					<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 dca4eadf Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
342 c64a0911 Hari
									</td>
343
								</tr>
344
							</table>
345
						</td>
346
					</tr>
347 42b0c921 Phil Davis
<?php
348
		endforeach;
349
?>
350 c64a0911 Hari
				</tbody>
351 a5eb046f Renato Botelho
			</table>
352 c64a0911 Hari
		</div>
353 56fafd85 Stephen Beaver
	</div>
354 d0f6649c pierrepomes
355 919d91f9 Phil Davis
<?php
356 cf1ced6d pierrepomes
}
357
358
if ($DisplayNote) {
359 4a22d33f Stephen Beaver
 	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 d0f6649c pierrepomes
}
361
362 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
363 8545adde k-paulius
	print_info_box(gettext("No OpenVPN instances defined."));
364 d0f6649c pierrepomes
}
365
?>
366 2a351d32 Colin Fleming
</form>
367 56fafd85 Stephen Beaver
368 ec970b50 jim-p
<script type="text/javascript">
369 4d33138f Colin Fleming
//<![CDATA[
370 56fafd85 Stephen Beaver
371 ec970b50 jim-p
function show_routes(id, buttonid) {
372
	document.getElementById(buttonid).innerHTML='';
373
	aodiv = document.getElementById(id);
374
	aodiv.style.display = "block";
375
}
376 56fafd85 Stephen Beaver
377 4d33138f Colin Fleming
//]]>
378 ec970b50 jim-p
</script>
379 c2081df1 NOYB
380
<?php include("foot.inc"); ?>