Project

General

Profile

Download (11.1 KB) Statistics
| Branch: | Tag: | Revision:
1 0927fb8c jim-p
<?php
2 63084885 Matthew Grooms
/*
3 c5d81585 Renato Botelho
 * status_openvpn.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * Copyright (c) 2008 Shrew Soft Inc.
8
 * All rights reserved.
9
 *
10 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13 c5d81585 Renato Botelho
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 c5d81585 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21 b9043cdc Stephen Beaver
 */
22 63084885 Matthew Grooms
23
##|+PRIV
24
##|*IDENT=page-status-openvpn
25 5230f468 jim-p
##|*NAME=Status: OpenVPN
26 63084885 Matthew Grooms
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
27
##|*MATCH=status_openvpn.php*
28
##|-PRIV
29
30 e9d35ff5 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
31 7d7b5a48 jim-p
$shortcut_section = "openvpn";
32
33 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
34 53663f57 jim-p
require_once("openvpn.inc");
35 2eaa97b9 jim-p
require_once("shortcuts.inc");
36 c92ccc70 Renato Botelho
require_once("service-utils.inc");
37 63084885 Matthew Grooms
38 0927fb8c jim-p
/* Handle AJAX */
39 1a8b6554 Steve Beaver
if ($_REQUEST['action']) {
40
	if ($_REQUEST['action'] == "kill") {
41
		$port  = $_REQUEST['port'];
42
		$remipp  = $_REQUEST['remipp'];
43 0927fb8c jim-p
		if (!empty($port) and !empty($remipp)) {
44 61fce4a6 Phil Davis
			$retval = openvpn_kill_client($port, $remipp);
45 0927fb8c jim-p
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
46
		} else {
47 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
48 0927fb8c jim-p
		}
49
		exit;
50
	}
51
}
52
53 53663f57 jim-p
$servers = openvpn_get_active_servers();
54 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
55 53663f57 jim-p
$clients = openvpn_get_active_clients();
56 63084885 Matthew Grooms
57 0927fb8c jim-p
include("head.inc"); ?>
58
59
<form action="status_openvpn.php" method="get" name="iform">
60
<script type="text/javascript">
61 4d33138f Colin Fleming
//<![CDATA[
62 0927fb8c jim-p
	function killClient(mport, remipp) {
63 b9144088 jim-p
		var busy = function(index,icon) {
64 3f98044a Francisco Cavalcante
			$(icon).bind("onclick","");
65
			$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
66
			$(icon).css("cursor","wait");
67 0927fb8c jim-p
		}
68
69 3f98044a Francisco Cavalcante
		$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
70 0927fb8c jim-p
71 3f98044a Francisco Cavalcante
		$.ajax(
72 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
73
				"?action=kill&port=" + mport + "&remipp=" + remipp,
74 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
75 0927fb8c jim-p
		);
76
	}
77
78
	function killComplete(req) {
79
		var values = req.responseText.split("|");
80 abe98adb Phil Davis
		if (values[3] != "0") {
81 0927fb8c jim-p
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
82
			return;
83
		}
84
85 5a5a11cd bruno
		$('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
86 3f98044a Francisco Cavalcante
			function(index,row) { $(row).fadeOut(1000); }
87 0927fb8c jim-p
		);
88
	}
89 4d33138f Colin Fleming
//]]>
90 0927fb8c jim-p
</script>
91 c64a0911 Hari
92 42b0c921 Phil Davis
<?php
93
	$i = 0;
94
	foreach ($servers as $server):
95
?>
96 0927fb8c jim-p
97 c64a0911 Hari
<div class="panel panel-default">
98 3d7a8696 k-paulius
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client Connections')?></h2></div>
99 c64a0911 Hari
		<div class="panel-body table-responsive">
100 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
101 c64a0911 Hari
				<thead>
102
					<tr>
103
						<th><?=gettext("Common Name")?></th>
104
						<th><?=gettext("Real Address")?></th>
105 cbfd0754 jim-p
						<th><?=gettext("Virtual Address"); ?></th>
106 c64a0911 Hari
						<th><?=gettext("Connected Since"); ?></th>
107 cbfd0754 jim-p
						<th><?=gettext("Bytes Sent/Received")?></th>
108 ff59b884 Stephen Beaver
						<th><!-- Icons --></th>
109 c64a0911 Hari
					</tr>
110
				</thead>
111
				<tbody>
112 919d91f9 Phil Davis
113 9f605c1c Hari
					<?php
114
							foreach ($server['conns'] as $conn):
115
					?>
116 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
117 cbfd0754 jim-p
						<td>
118
							<?=$conn['common_name'];?>
119
					<?php if (!empty($conn['common_name']) && !empty($conn['user_name']) && ($conn['user_name'] != "UNDEF")): ?>
120
							<br />
121
					<?php endif; ?>
122
					<?php if (!empty($conn['user_name']) && ($conn['user_name'] != "UNDEF")): ?>
123
							<?=$conn['user_name'];?>
124
					<?php endif; ?>
125
						</td>
126 c64a0911 Hari
						<td><?=$conn['remote_host'];?></td>
127 cbfd0754 jim-p
						<td>
128
							<?=$conn['virtual_addr'];?>
129
					<?php if (!empty($conn['virtual_addr']) && !empty($conn['virtual_addr6'])): ?>
130
							<br />
131
					<?php endif; ?>
132
							<?=$conn['virtual_addr6'];?>
133
						</td>
134 c64a0911 Hari
						<td><?=$conn['connect_time'];?></td>
135 cbfd0754 jim-p
						<td><?=format_bytes($conn['bytes_sent']);?> / <?=format_bytes($conn['bytes_recv']);?></td>
136 c64a0911 Hari
						<td>
137 9f605c1c Hari
							<a
138 5c0ab3cd NewEraCracker
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
139 c64a0911 Hari
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
140 98128ad6 Phil Davis
							   title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
141 1b7379f9 Jared Dillard
							<i class="fa fa-times"></i>
142 9f605c1c Hari
							</a>
143 c64a0911 Hari
						</td>
144
					</tr>
145 9f605c1c Hari
					<?php
146
							endforeach;
147
					?>
148 c64a0911 Hari
				</tbody>
149
				<tfoot>
150
					<tr>
151 e9701cfe Stephen Beaver
						<td colspan="2">
152 c64a0911 Hari
							<table>
153
								<tr>
154
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
155 7b05178d NOYB
									<td>
156
										<?= gettext("Status") . ": " . get_service_status_icon($ssvc, false, true, false, "service_state"); ?>
157
									</td>
158
									<td>
159
										<?= gettext("Actions") . ": " . get_service_control_links($ssvc); ?>
160 c64a0911 Hari
									</td>
161
								</tr>
162
							</table>
163
						</td>
164 e9701cfe Stephen Beaver
						<td colspan="5">
165
						</td>
166 c64a0911 Hari
					</tr>
167
				</tfoot>
168
			</table>
169
		</div>
170
</div>
171 42b0c921 Phil Davis
<?php
172
		if (is_array($server['routes']) && count($server['routes'])):
173
?>
174 ec970b50 jim-p
<div id="shroutebut-<?= $i ?>">
175 37676f4e jim-p
	<button type="button" class="btn btn-info" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>">
176
		<i class="fa fa-plus-circle icon-embed-btn"></i>
177
		<?php echo gettext("Show Routing Table"); ?>
178
	</button>
179
	- <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
180
	<br /><br />
181 ec970b50 jim-p
</div>
182 56fafd85 Stephen Beaver
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
183 c64a0911 Hari
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
184
		<div class="panel-body table-responsive">
185 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
186 c64a0911 Hari
				<thead>
187
					<tr>
188
						<th><?=gettext("Common Name"); ?></th>
189
						<th><?=gettext("Real Address"); ?></th>
190
						<th><?=gettext("Target Network"); ?></th>
191
						<th><?=gettext("Last Used"); ?></th>
192
					</tr>
193 919d91f9 Phil Davis
				</thead>
194 c64a0911 Hari
				<tbody>
195 ec970b50 jim-p
196 42b0c921 Phil Davis
<?php
197
			foreach ($server['routes'] as $conn):
198
?>
199 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
200
						<td><?=$conn['common_name'];?></td>
201
						<td><?=$conn['remote_host'];?></td>
202
						<td><?=$conn['virtual_addr'];?></td>
203
						<td><?=$conn['last_time'];?></td>
204
					</tr>
205 42b0c921 Phil Davis
<?php
206
			endforeach;
207
?>
208 c64a0911 Hari
				</tbody>
209
				<tfoot>
210
					<tr>
211 e9701cfe Stephen Beaver
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
212 c64a0911 Hari
					</tr>
213
				</tfoot>
214
			</table>
215
		</div>
216
</div>
217 42b0c921 Phil Davis
<?php
218
		endif;
219
?>
220 8cd558b6 ayvis
<br />
221 42b0c921 Phil Davis
<?php
222
		$i++;
223
	endforeach;
224
?>
225 8cd558b6 ayvis
<br />
226 d0f6649c pierrepomes
227 42b0c921 Phil Davis
<?php
228
	if (!empty($sk_servers)) {
229
?>
230 c64a0911 Hari
<div class="panel panel-default">
231
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
232
		<div class="panel-body table-responsive">
233 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
234 c64a0911 Hari
				<thead>
235 919d91f9 Phil Davis
					<tr>
236 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
237 e9701cfe Stephen Beaver
						<th><?=gettext("Status"); ?></th>
238 c64a0911 Hari
						<th><?=gettext("Connected Since"); ?></th>
239 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
240 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
241 cbfd0754 jim-p
						<th><?=gettext("Bytes Sent / Received"); ?></th>
242 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
243
					</tr>
244
				</thead>
245
				<tbody>
246 d0f6649c pierrepomes
247 42b0c921 Phil Davis
<?php
248
		foreach ($sk_servers as $sk_server):
249
?>
250 c64a0911 Hari
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
251
						<td><?=htmlspecialchars($sk_server['name']);?></td>
252
						<td><?=$sk_server['status'];?></td>
253
						<td><?=$sk_server['connect_time'];?></td>
254 bffa3185 jim-p
						<td>
255
							<?=$sk_server['virtual_addr'];?>
256
					<?php if (!empty($sk_server['virtual_addr']) && !empty($sk_server['virtual_addr6'])): ?>
257
							<br />
258
					<?php endif; ?>
259
							<?=$sk_server['virtual_addr6'];?>
260
						</td>
261 c64a0911 Hari
						<td><?=$sk_server['remote_host'];?></td>
262 cbfd0754 jim-p
						<td><?=format_bytes($sk_server['bytes_sent']);?> / <?=format_bytes($sk_server['bytes_recv']);?></td>
263 c64a0911 Hari
						<td>
264
							<table>
265
								<tr>
266
									<td>
267
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
268
										<?= get_service_status_icon($ssvc, false, true); ?>
269 29fda3d3 Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
270 c64a0911 Hari
									</td>
271
								</tr>
272
							</table>
273
						</td>
274
					</tr>
275 42b0c921 Phil Davis
<?php
276
		endforeach;
277
?>
278 c64a0911 Hari
				</tbody>
279 a5eb046f Renato Botelho
			</table>
280 c64a0911 Hari
		</div>
281
</div>
282 95305736 jim-p
283
<?php
284 42b0c921 Phil Davis
	}
285
?>
286 8cd558b6 ayvis
<br />
287 42b0c921 Phil Davis
<?php
288
	if (!empty($clients)) {
289
?>
290 c64a0911 Hari
<div class="panel panel-default">
291
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
292
		<div class="panel-body table-responsive">
293 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
294 c64a0911 Hari
				<thead>
295 919d91f9 Phil Davis
					<tr>
296 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
297
						<th><?=gettext("Status"); ?></th>
298
						<th><?=gettext("Connected Since"); ?></th>
299 cbfd0754 jim-p
						<th><?=gettext("Local Address"); ?></th>
300 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
301 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
302 cbfd0754 jim-p
						<th><?=gettext("Bytes Sent/Received"); ?></th>
303 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
304
					</tr>
305
				</thead>
306
				<tbody>
307 d0f6649c pierrepomes
308 42b0c921 Phil Davis
<?php
309
		foreach ($clients as $client):
310
?>
311 c64a0911 Hari
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
312
						<td><?=htmlspecialchars($client['name']);?></td>
313
						<td><?=$client['status'];?></td>
314
						<td><?=$client['connect_time'];?></td>
315 2906d139 jim-p
						<td>
316
					<?php if (empty($client['local_host']) && empty($client['local_port'])): ?>
317
							(pending)
318
					<?php else: ?>
319
							<?=$client['local_host'];?>:<?=$client['local_port'];?>
320
					<?php endif; ?>
321
						</td>
322 cbfd0754 jim-p
						<td>
323
							<?=$client['virtual_addr'];?>
324
					<?php if (!empty($client['virtual_addr']) && !empty($client['virtual_addr6'])): ?>
325
							<br />
326
					<?php endif; ?>
327
							<?=$client['virtual_addr6'];?>
328
						</td>
329 2906d139 jim-p
						<td>
330
					<?php if (empty($client['remote_host']) && empty($client['remote_port'])): ?>
331
							(pending)
332
					<?php else: ?>
333
							<?=$client['remote_host'];?>:<?=$client['remote_port'];?>
334
					<?php endif; ?>
335
						</td>
336 cbfd0754 jim-p
						<td><?=format_bytes($client['bytes_sent']);?> / <?=format_bytes($client['bytes_recv']);?></td>
337 c64a0911 Hari
						<td>
338
							<table>
339
								<tr>
340
									<td>
341
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
342
										<?= get_service_status_icon($ssvc, false, true); ?>
343 29fda3d3 Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
344 c64a0911 Hari
									</td>
345
								</tr>
346
							</table>
347
						</td>
348
					</tr>
349 42b0c921 Phil Davis
<?php
350
		endforeach;
351
?>
352 c64a0911 Hari
				</tbody>
353 a5eb046f Renato Botelho
			</table>
354 c64a0911 Hari
		</div>
355 56fafd85 Stephen Beaver
	</div>
356 d0f6649c pierrepomes
357 919d91f9 Phil Davis
<?php
358 cf1ced6d pierrepomes
}
359
360
if ($DisplayNote) {
361 530c7ccf NOYB
 	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."));
362 d0f6649c pierrepomes
}
363
364 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
365 8545adde k-paulius
	print_info_box(gettext("No OpenVPN instances defined."));
366 d0f6649c pierrepomes
}
367
?>
368 2a351d32 Colin Fleming
</form>
369 56fafd85 Stephen Beaver
370 ec970b50 jim-p
<script type="text/javascript">
371 4d33138f Colin Fleming
//<![CDATA[
372 56fafd85 Stephen Beaver
373 ec970b50 jim-p
function show_routes(id, buttonid) {
374
	document.getElementById(buttonid).innerHTML='';
375
	aodiv = document.getElementById(id);
376
	aodiv.style.display = "block";
377
}
378 56fafd85 Stephen Beaver
379 4d33138f Colin Fleming
//]]>
380 ec970b50 jim-p
</script>
381 c2081df1 NOYB
382
<?php include("foot.inc"); ?>