Project

General

Profile

Download (11.5 KB) Statistics
| Branch: | Tag: | Revision:
1 0927fb8c jim-p
<?php
2 63084885 Matthew Grooms
/*
3 aaec5634 Renato Botelho
 * status_openvpn.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * Copyright (c) 2008 Shrew Soft Inc.
8
 * All rights reserved.
9
 *
10
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions are met:
12
 *
13
 * 1. Redistributions of source code must retain the above copyright notice,
14
 *    this list of conditions and the following disclaimer.
15
 *
16
 * 2. Redistributions in binary form must reproduce the above copyright
17
 *    notice, this list of conditions and the following disclaimer in
18
 *    the documentation and/or other materials provided with the
19
 *    distribution.
20
 *
21
 * 3. All advertising materials mentioning features or use of this software
22
 *    must display the following acknowledgment:
23
 *    "This product includes software developed by the pfSense Project
24
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
25
 *
26
 * 4. The names "pfSense" and "pfSense Project" must not be used to
27
 *    endorse or promote products derived from this software without
28
 *    prior written permission. For written permission, please contact
29
 *    coreteam@pfsense.org.
30
 *
31
 * 5. Products derived from this software may not be called "pfSense"
32
 *    nor may "pfSense" appear in their names without prior written
33
 *    permission of the Electric Sheep Fencing, LLC.
34
 *
35
 * 6. Redistributions of any form whatsoever must retain the following
36
 *    acknowledgment:
37
 *
38
 * "This product includes software developed by the pfSense Project
39
 * for use in the pfSense software distribution (http://www.pfsense.org/).
40
 *
41
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
 * OF THE POSSIBILITY OF SUCH DAMAGE.
53 b9043cdc Stephen Beaver
 */
54 63084885 Matthew Grooms
55
##|+PRIV
56
##|*IDENT=page-status-openvpn
57 5230f468 jim-p
##|*NAME=Status: OpenVPN
58 63084885 Matthew Grooms
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
59
##|*MATCH=status_openvpn.php*
60
##|-PRIV
61
62 e9d35ff5 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
63 7d7b5a48 jim-p
$shortcut_section = "openvpn";
64
65 aceaf18c Phil Davis
require_once("guiconfig.inc");
66 53663f57 jim-p
require_once("openvpn.inc");
67 2eaa97b9 jim-p
require_once("shortcuts.inc");
68 c92ccc70 Renato Botelho
require_once("service-utils.inc");
69 63084885 Matthew Grooms
70 0927fb8c jim-p
/* Handle AJAX */
71 abe98adb Phil Davis
if ($_GET['action']) {
72
	if ($_GET['action'] == "kill") {
73 0927fb8c jim-p
		$port  = $_GET['port'];
74
		$remipp  = $_GET['remipp'];
75
		if (!empty($port) and !empty($remipp)) {
76 61fce4a6 Phil Davis
			$retval = openvpn_kill_client($port, $remipp);
77 0927fb8c jim-p
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
78
		} else {
79 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
80 0927fb8c jim-p
		}
81
		exit;
82
	}
83
}
84
85 53663f57 jim-p
$servers = openvpn_get_active_servers();
86 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
87 53663f57 jim-p
$clients = openvpn_get_active_clients();
88 63084885 Matthew Grooms
89 0927fb8c jim-p
include("head.inc"); ?>
90
91
<form action="status_openvpn.php" method="get" name="iform">
92
<script type="text/javascript">
93 4d33138f Colin Fleming
//<![CDATA[
94 0927fb8c jim-p
	function killClient(mport, remipp) {
95 b9144088 jim-p
		var busy = function(index,icon) {
96 3f98044a Francisco Cavalcante
			$(icon).bind("onclick","");
97
			$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
98
			$(icon).css("cursor","wait");
99 0927fb8c jim-p
		}
100
101 3f98044a Francisco Cavalcante
		$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
102 0927fb8c jim-p
103 3f98044a Francisco Cavalcante
		$.ajax(
104 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
105
				"?action=kill&port=" + mport + "&remipp=" + remipp,
106 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
107 0927fb8c jim-p
		);
108
	}
109
110
	function killComplete(req) {
111
		var values = req.responseText.split("|");
112 abe98adb Phil Davis
		if (values[3] != "0") {
113 0927fb8c jim-p
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
114
			return;
115
		}
116
117 7fa32308 bruno
		$('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
118 3f98044a Francisco Cavalcante
			function(index,row) { $(row).fadeOut(1000); }
119 0927fb8c jim-p
		);
120
	}
121 4d33138f Colin Fleming
//]]>
122 0927fb8c jim-p
</script>
123 c64a0911 Hari
124 42b0c921 Phil Davis
<?php
125
	$i = 0;
126
	foreach ($servers as $server):
127
?>
128 0927fb8c jim-p
129 c64a0911 Hari
<div class="panel panel-default">
130 3d7a8696 k-paulius
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client Connections')?></h2></div>
131 c64a0911 Hari
		<div class="panel-body table-responsive">
132 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
133 c64a0911 Hari
				<thead>
134
					<tr>
135
						<th><?=gettext("Common Name")?></th>
136
						<th><?=gettext("Real Address")?></th>
137
						<th><?=gettext("Virtual Address"); ?></th>
138
						<th><?=gettext("Connected Since"); ?></th>
139
						<th><?=gettext("Bytes Sent")?></th>
140
						<th><?=gettext("Bytes Received")?></th>
141 ff59b884 Stephen Beaver
						<th><!-- Icons --></th>
142 c64a0911 Hari
					</tr>
143
				</thead>
144
				<tbody>
145 919d91f9 Phil Davis
146 9f605c1c Hari
					<?php
147
							foreach ($server['conns'] as $conn):
148
					?>
149 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
150
						<td><?=$conn['common_name'];?></td>
151
						<td><?=$conn['remote_host'];?></td>
152
						<td><?=$conn['virtual_addr'];?></td>
153
						<td><?=$conn['connect_time'];?></td>
154
						<td><?=format_bytes($conn['bytes_sent']);?></td>
155
						<td><?=format_bytes($conn['bytes_recv']);?></td>
156
						<td>
157 9f605c1c Hari
							<a
158 5c0ab3cd NewEraCracker
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
159 c64a0911 Hari
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
160 98128ad6 Phil Davis
							   title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
161 1b7379f9 Jared Dillard
							<i class="fa fa-times"></i>
162 9f605c1c Hari
							</a>
163 c64a0911 Hari
						</td>
164
					</tr>
165 9f605c1c Hari
					<?php
166
							endforeach;
167
					?>
168 c64a0911 Hari
				</tbody>
169
				<tfoot>
170
					<tr>
171 e9701cfe Stephen Beaver
						<td colspan="2">
172 c64a0911 Hari
							<table>
173
								<tr>
174
									<td>
175
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
176
										<?= get_service_status_icon($ssvc, true, true); ?>
177 dca4eadf Stephen Beaver
										<?= get_service_control_links($ssvc); ?>
178 c64a0911 Hari
									</td>
179
								</tr>
180
							</table>
181
						</td>
182 e9701cfe Stephen Beaver
						<td colspan="5">
183
						</td>
184 c64a0911 Hari
					</tr>
185
				</tfoot>
186
			</table>
187
		</div>
188
</div>
189 42b0c921 Phil Davis
<?php
190
		if (is_array($server['routes']) && count($server['routes'])):
191
?>
192 ec970b50 jim-p
<div id="shroutebut-<?= $i ?>">
193 37676f4e jim-p
	<button type="button" class="btn btn-info" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>">
194
		<i class="fa fa-plus-circle icon-embed-btn"></i>
195
		<?php echo gettext("Show Routing Table"); ?>
196
	</button>
197
	- <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
198
	<br /><br />
199 ec970b50 jim-p
</div>
200 56fafd85 Stephen Beaver
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
201 c64a0911 Hari
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
202
		<div class="panel-body table-responsive">
203 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
204 c64a0911 Hari
				<thead>
205
					<tr>
206
						<th><?=gettext("Common Name"); ?></th>
207
						<th><?=gettext("Real Address"); ?></th>
208
						<th><?=gettext("Target Network"); ?></th>
209
						<th><?=gettext("Last Used"); ?></th>
210
					</tr>
211 919d91f9 Phil Davis
				</thead>
212 c64a0911 Hari
				<tbody>
213 ec970b50 jim-p
214 42b0c921 Phil Davis
<?php
215
			foreach ($server['routes'] as $conn):
216
?>
217 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
218
						<td><?=$conn['common_name'];?></td>
219
						<td><?=$conn['remote_host'];?></td>
220
						<td><?=$conn['virtual_addr'];?></td>
221
						<td><?=$conn['last_time'];?></td>
222
					</tr>
223 42b0c921 Phil Davis
<?php
224
			endforeach;
225
?>
226 c64a0911 Hari
				</tbody>
227
				<tfoot>
228
					<tr>
229 e9701cfe Stephen Beaver
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
230 c64a0911 Hari
					</tr>
231
				</tfoot>
232
			</table>
233
		</div>
234
</div>
235 42b0c921 Phil Davis
<?php
236
		endif;
237
?>
238 8cd558b6 ayvis
<br />
239 42b0c921 Phil Davis
<?php
240
		$i++;
241
	endforeach;
242
?>
243 8cd558b6 ayvis
<br />
244 d0f6649c pierrepomes
245 42b0c921 Phil Davis
<?php
246
	if (!empty($sk_servers)) {
247
?>
248 c64a0911 Hari
<div class="panel panel-default">
249
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
250
		<div class="panel-body table-responsive">
251 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
252 c64a0911 Hari
				<thead>
253 919d91f9 Phil Davis
					<tr>
254 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
255 e9701cfe Stephen Beaver
						<th><?=gettext("Status"); ?></th>
256 c64a0911 Hari
						<th><?=gettext("Connected Since"); ?></th>
257 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
258 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
259
						<th><?=gettext("Bytes Sent"); ?></th>
260 a66ce627 NewEraCracker
						<th><?=gettext("Bytes Received"); ?></th>
261 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
262
					</tr>
263
				</thead>
264
				<tbody>
265 d0f6649c pierrepomes
266 42b0c921 Phil Davis
<?php
267
		foreach ($sk_servers as $sk_server):
268
?>
269 c64a0911 Hari
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
270
						<td><?=htmlspecialchars($sk_server['name']);?></td>
271
						<td><?=$sk_server['status'];?></td>
272
						<td><?=$sk_server['connect_time'];?></td>
273
						<td><?=$sk_server['virtual_addr'];?></td>
274
						<td><?=$sk_server['remote_host'];?></td>
275
						<td><?=format_bytes($sk_server['bytes_sent']);?></td>
276
						<td><?=format_bytes($sk_server['bytes_recv']);?></td>
277
						<td>
278
							<table>
279
								<tr>
280
									<td>
281
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
282
										<?= get_service_status_icon($ssvc, false, true); ?>
283 dca4eadf Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
284 c64a0911 Hari
									</td>
285
								</tr>
286
							</table>
287
						</td>
288
					</tr>
289 42b0c921 Phil Davis
<?php
290
		endforeach;
291
?>
292 c64a0911 Hari
				</tbody>
293 a5eb046f Renato Botelho
			</table>
294 c64a0911 Hari
		</div>
295
</div>
296 95305736 jim-p
297
<?php
298 42b0c921 Phil Davis
	}
299
?>
300 8cd558b6 ayvis
<br />
301 42b0c921 Phil Davis
<?php
302
	if (!empty($clients)) {
303
?>
304 c64a0911 Hari
<div class="panel panel-default">
305
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
306
		<div class="panel-body table-responsive">
307 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
308 c64a0911 Hari
				<thead>
309 919d91f9 Phil Davis
					<tr>
310 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
311
						<th><?=gettext("Status"); ?></th>
312
						<th><?=gettext("Connected Since"); ?></th>
313 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
314 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
315
						<th><?=gettext("Bytes Sent"); ?></th>
316 a66ce627 NewEraCracker
						<th><?=gettext("Bytes Received"); ?></th>
317 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
318
					</tr>
319
				</thead>
320
				<tbody>
321 d0f6649c pierrepomes
322 42b0c921 Phil Davis
<?php
323
		foreach ($clients as $client):
324
?>
325 c64a0911 Hari
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
326
						<td><?=htmlspecialchars($client['name']);?></td>
327
						<td><?=$client['status'];?></td>
328
						<td><?=$client['connect_time'];?></td>
329
						<td><?=$client['virtual_addr'];?></td>
330
						<td><?=$client['remote_host'];?></td>
331
						<td><?=format_bytes($client['bytes_sent']);?></td>
332
						<td><?=format_bytes($client['bytes_recv']);?></td>
333
						<td>
334
							<table>
335
								<tr>
336
									<td>
337
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
338
										<?= get_service_status_icon($ssvc, false, true); ?>
339 dca4eadf Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
340 c64a0911 Hari
									</td>
341
								</tr>
342
							</table>
343
						</td>
344
					</tr>
345 42b0c921 Phil Davis
<?php
346
		endforeach;
347
?>
348 c64a0911 Hari
				</tbody>
349 a5eb046f Renato Botelho
			</table>
350 c64a0911 Hari
		</div>
351 56fafd85 Stephen Beaver
	</div>
352 d0f6649c pierrepomes
353 919d91f9 Phil Davis
<?php
354 cf1ced6d pierrepomes
}
355
356
if ($DisplayNote) {
357 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."));
358 d0f6649c pierrepomes
}
359
360 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
361 8545adde k-paulius
	print_info_box(gettext("No OpenVPN instances defined."));
362 d0f6649c pierrepomes
}
363
?>
364 2a351d32 Colin Fleming
</form>
365 56fafd85 Stephen Beaver
366 ec970b50 jim-p
<script type="text/javascript">
367 4d33138f Colin Fleming
//<![CDATA[
368 56fafd85 Stephen Beaver
369 ec970b50 jim-p
function show_routes(id, buttonid) {
370
	document.getElementById(buttonid).innerHTML='';
371
	aodiv = document.getElementById(id);
372
	aodiv.style.display = "block";
373
}
374 56fafd85 Stephen Beaver
375 4d33138f Colin Fleming
//]]>
376 ec970b50 jim-p
</script>
377 c2081df1 NOYB
378
<?php include("foot.inc"); ?>