Project

General

Profile

Download (11.2 KB) Statistics
| Branch: | Tag: | Revision:
1 0927fb8c jim-p
<?php
2 63084885 Matthew Grooms
/*
3
	status_ovpenvpn.php
4
5 0927fb8c jim-p
    Copyright (C) 2010 Jim Pingle
6 63084885 Matthew Grooms
    Copyright (C) 2008 Shrew Soft Inc.
7 0927fb8c jim-p
8
    AJAX bits borrowed from diag_dump_states.php
9
    Copyright (C) 2005 Scott Ullrich, Colin Smith
10
11 63084885 Matthew Grooms
    All rights reserved.
12 0927fb8c jim-p
13 63084885 Matthew Grooms
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 0927fb8c jim-p
16 63084885 Matthew Grooms
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 0927fb8c jim-p
19 63084885 Matthew Grooms
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22 0927fb8c jim-p
23 63084885 Matthew Grooms
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34 61dda8f7 Matthew Grooms
/* DISABLE_PHP_LINT_CHECKING */
35 0927fb8c jim-p
/*
36 1d333258 Scott Ullrich
	pfSense_MODULE:	openvpn
37
*/
38 63084885 Matthew Grooms
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 e9d35ff5 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
47 7d7b5a48 jim-p
$shortcut_section = "openvpn";
48
49 63084885 Matthew Grooms
require("guiconfig.inc");
50 53663f57 jim-p
require_once("openvpn.inc");
51 63084885 Matthew Grooms
52 0927fb8c jim-p
/* Handle AJAX */
53
if($_GET['action']) {
54
	if($_GET['action'] == "kill") {
55
		$port  = $_GET['port'];
56
		$remipp  = $_GET['remipp'];
57
		if (!empty($port) and !empty($remipp)) {
58
			$retval = kill_client($port, $remipp);
59
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
60
		} else {
61 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
62 0927fb8c jim-p
		}
63
		exit;
64
	}
65
}
66
67
68
function kill_client($port, $remipp) {
69 71ca2cb2 Ermal
	global $g;
70
71
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
72
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
73 0927fb8c jim-p
	$errval;
74
	$errstr;
75
76
	/* open a tcp connection to the management port of each server */
77
	$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
78
	$killed = -1;
79
	if ($fp) {
80 19e3d450 Ermal
		stream_set_timeout($fp, 1);
81 0927fb8c jim-p
		fputs($fp, "kill {$remipp}\n");
82
		while (!feof($fp)) {
83
			$line = fgets($fp, 1024);
84 b0140675 Ermal
85
			$info = stream_get_meta_data($fp);
86
			if ($info['timed_out'])
87
				break;
88
89 0927fb8c jim-p
			/* parse header list line */
90 68b04527 jim-p
			if (strpos($line, "INFO:") !== false)
91 0927fb8c jim-p
				continue;
92 68b04527 jim-p
			if (strpos($line, "SUCCESS") !== false) {
93 0927fb8c jim-p
				$killed = 0;
94
			}
95
			break;
96
		}
97
		fclose($fp);
98
	}
99
	return $killed;
100
}
101
102 53663f57 jim-p
$servers = openvpn_get_active_servers();
103 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
104 53663f57 jim-p
$clients = openvpn_get_active_clients();
105 63084885 Matthew Grooms
106 0927fb8c jim-p
include("head.inc"); ?>
107
108
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
109
<?php include("fbegin.inc"); ?>
110
<form action="status_openvpn.php" method="get" name="iform">
111
<script type="text/javascript">
112
	function killClient(mport, remipp) {
113 b9144088 jim-p
		var busy = function(index,icon) {
114 e03ef9a0 Vinicius Coque
			jQuery(icon).bind("onclick","");
115
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
116
			jQuery(icon).css("cursor","wait");
117 0927fb8c jim-p
		}
118
119 e03ef9a0 Vinicius Coque
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
120 0927fb8c jim-p
121 e03ef9a0 Vinicius Coque
		jQuery.ajax(
122 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
123
				"?action=kill&port=" + mport + "&remipp=" + remipp,
124 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
125 0927fb8c jim-p
		);
126
	}
127
128
	function killComplete(req) {
129
		var values = req.responseText.split("|");
130
		if(values[3] != "0") {
131
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
132
			return;
133
		}
134
135 e03ef9a0 Vinicius Coque
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
136
			function(index,row) { jQuery(row).fadeOut(1000); }
137 0927fb8c jim-p
		);
138
	}
139
</script>
140 ec970b50 jim-p
<?php $i = 0; ?>
141 0927fb8c jim-p
<?php foreach ($servers as $server): ?>
142
143
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
144
	<tr>
145
		<td colspan="6" class="listtopic">
146 95305736 jim-p
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
147 0927fb8c jim-p
		</td>
148
	</tr>
149
	<tr>
150
		<td>
151
			<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
152
			<tr>
153 e9d35ff5 Carlos Eduardo Ramos
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
154
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
155
				<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
156
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
157
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
158
				<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
159 0927fb8c jim-p
			</tr>
160
161
			<?php foreach ($server['conns'] as $conn): ?>
162 68b04527 jim-p
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
163 0927fb8c jim-p
				<td class="listlr">
164
					<?=$conn['common_name'];?>
165
				</td>
166
				<td class="listr">
167
					<?=$conn['remote_host'];?>
168
				</td>
169
				<td class="listr">
170
					<?=$conn['virtual_addr'];?>
171
				</td>
172
				<td class="listr">
173
					<?=$conn['connect_time'];?>
174
				</td>
175
				<td class="listr">
176
					<?=$conn['bytes_sent'];?>
177
				</td>
178
				<td class="listr">
179
					<?=$conn['bytes_recv'];?>
180
				</td>
181
				<td class='list'>
182
					<img src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' height='17' width='17' border='0'
183 71ca2cb2 Ermal
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
184 68b04527 jim-p
					   name='<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>'
185
					   title='<?php echo gettext("Kill client connection from") . ' ' . $conn['remote_host']; ?>' alt='' />
186 0927fb8c jim-p
				</td>
187
			</tr>
188
189
			<?php endforeach; ?>
190 f06f7cc0 PiBa-NL
			<tfoot>
191 0927fb8c jim-p
			<tr>
192
				<td colspan="6" class="list" height="12"></td>
193
			</tr>
194 f06f7cc0 PiBa-NL
			</tfoot>
195 0927fb8c jim-p
		</table>
196
		</td>
197
	</tr>
198
</table>
199 ec970b50 jim-p
<?php if (is_array($server['routes']) && count($server['routes'])): ?>
200
<div id="shroutebut-<?= $i ?>">
201 39f245c8 jim-p
<input type="button" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>"></input> - <?= gettext("Display OpenVPN's internal routing table for this server.") ?></a>
202 ec970b50 jim-p
<br/><br/>
203
</div>
204 39f245c8 jim-p
<table style="display: none; padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0" id="tabroute-<?= $i ?>">
205 ec970b50 jim-p
	<tr>
206
		<td colspan="6" class="listtopic">
207
			<?=$server['name'];?> <?=gettext("Routing Table"); ?>
208
		</td>
209
	</tr>
210
	<tr>
211
		<td>
212
			<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
213
			<tr>
214
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
215
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
216
				<td class="listhdrr"><?=gettext("Target Network"); ?></td>
217
				<td class="listhdrr"><?=gettext("Last Used"); ?></td>
218
			</tr>
219
220
			<?php foreach ($server['routes'] as $conn): ?>
221
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
222
				<td class="listlr">
223
					<?=$conn['common_name'];?>
224
				</td>
225
				<td class="listr">
226
					<?=$conn['remote_host'];?>
227
				</td>
228
				<td class="listr">
229
					<?=$conn['virtual_addr'];?>
230
				</td>
231
				<td class="listr">
232
					<?=$conn['last_time'];?>
233
				</td>
234
			</tr>
235 63084885 Matthew Grooms
236 ec970b50 jim-p
			<?php endforeach; ?>
237
			<tfoot>
238
			<tr>
239
				<td colspan="6" class="list" height="12"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
240
			</tr>
241
			</tfoot>
242
		</table>
243
		</td>
244
	</tr>
245
</table>
246
<?php endif; ?>
247
<br/>
248
<?php $i++; ?>
249 0927fb8c jim-p
<?php endforeach; ?>
250 ec970b50 jim-p
<br/>
251 d0f6649c pierrepomes
252 95305736 jim-p
<?php if (!empty($sk_servers)) { ?>
253
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
254
	<tr>
255
		<td colspan="6" class="listtopic">
256 453d9c96 jim-p
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
257 95305736 jim-p
		</td>
258
	</tr>
259
	<tr>
260
		<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
261
		<tr>
262
			<td class="listhdrr"><?=gettext("Name"); ?></td>
263
			<td class="listhdrr"><?=gettext("Status"); ?></td>
264
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
265
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
266
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
267
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
268
			<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
269
		</tr>
270 d0f6649c pierrepomes
271 95305736 jim-p
<?php foreach ($sk_servers as $sk_server): ?>
272
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
273
			<td class="listlr">
274
				<?=$sk_server['name'];?>
275
			</td>
276
			<td class="listlr">
277
				<?=$sk_server['status'];?>
278
			</td>
279
			<td class="listr">
280
				<?=$sk_server['connect_time'];?>
281
			</td>
282
			<td class="listr">
283
				<?=$sk_server['virtual_addr'];?>
284
			</td>
285
			<td class="listr">
286
				<?=$sk_server['remote_host'];?>
287
			</td>
288
			<td class="listr">
289
				<?=$sk_server['bytes_sent'];?>
290
			</td>
291
			<td class="listr">
292
				<?=$sk_server['bytes_recv'];?>
293
			</td>
294
		</tr>
295
<?php endforeach; ?>
296
		</table>
297
	</tr>
298
</table>
299
300
<?php
301
} ?>
302
<br>
303 cf1ced6d pierrepomes
<?php if (!empty($clients)) { ?>
304 d0f6649c pierrepomes
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
305
	<tr>
306
		<td colspan="6" class="listtopic">
307 95305736 jim-p
			<?=gettext("Client Instance Statistics"); ?>
308 d0f6649c pierrepomes
		</td>
309
	</tr>
310
	<tr>
311
		<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
312
		<tr>
313 e9d35ff5 Carlos Eduardo Ramos
			<td class="listhdrr"><?=gettext("Name"); ?></td>
314
			<td class="listhdrr"><?=gettext("Status"); ?></td>
315
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
316
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
317
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
318
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
319
			<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
320 d0f6649c pierrepomes
		</tr>
321
322
<?php foreach ($clients as $client): ?>
323
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
324
			<td class="listlr">
325
				<?=$client['name'];?>
326
			</td>
327
			<td class="listlr">
328
				<?=$client['status'];?>
329
			</td>
330
			<td class="listr">
331
				<?=$client['connect_time'];?>
332
			</td>
333
			<td class="listr">
334
				<?=$client['virtual_addr'];?>
335
			</td>
336
			<td class="listr">
337
				<?=$client['remote_host'];?>
338
			</td>
339
			<td class="listr">
340
				<?=$client['bytes_sent'];?>
341
			</td>
342
			<td class="listr">
343
				<?=$client['bytes_recv'];?>
344
			</td>
345
		</tr>
346
<?php endforeach; ?>
347
		</table>
348
	</tr>
349
</table>
350
351 cf1ced6d pierrepomes
<?php 
352
}
353
354
if ($DisplayNote) {
355 e9d35ff5 Carlos Eduardo Ramos
	echo "<br/><b>" . gettext("NOTE") . ":</b> " . gettext("You need to bind each OpenVPN client to enable its management daemon: use 'Local port' setting in the OpenVPN client screen");
356 d0f6649c pierrepomes
}
357
358 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
359 e9d35ff5 Carlos Eduardo Ramos
	echo gettext("No OpenVPN instance defined");
360 d0f6649c pierrepomes
}
361
?>
362
363 63084885 Matthew Grooms
364
<?php include("fend.inc"); ?>
365 ec970b50 jim-p
<script type="text/javascript">
366
function show_routes(id, buttonid) {
367
	document.getElementById(buttonid).innerHTML='';
368
	aodiv = document.getElementById(id);
369
	aodiv.style.display = "block";
370
}
371
</script>