Project

General

Profile

Download (12.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_ovpenvpn.php
4

    
5
    Copyright (C) 2010 Jim Pingle
6
    Copyright (C) 2008 Shrew Soft Inc.
7

    
8
    AJAX bits borrowed from diag_dump_states.php
9
    Copyright (C) 2005 Scott Ullrich, Colin Smith
10

    
11
    All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	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

    
23
	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
/* DISABLE_PHP_LINT_CHECKING */
35
/*
36
	pfSense_MODULE:	openvpn
37
*/
38

    
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
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
47
$shortcut_section = "openvpn";
48

    
49
require("guiconfig.inc");
50
require_once("openvpn.inc");
51
require_once("shortcuts.inc");
52

    
53
/* Handle AJAX */
54
if($_GET['action']) {
55
	if($_GET['action'] == "kill") {
56
		$port  = $_GET['port'];
57
		$remipp  = $_GET['remipp'];
58
		if (!empty($port) and !empty($remipp)) {
59
			$retval = kill_client($port, $remipp);
60
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
61
		} else {
62
			echo gettext("invalid input");
63
		}
64
		exit;
65
	}
66
}
67

    
68

    
69
function kill_client($port, $remipp) {
70
	global $g;
71

    
72
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
73
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
74
	$errval;
75
	$errstr;
76

    
77
	/* open a tcp connection to the management port of each server */
78
	$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
79
	$killed = -1;
80
	if ($fp) {
81
		stream_set_timeout($fp, 1);
82
		fputs($fp, "kill {$remipp}\n");
83
		while (!feof($fp)) {
84
			$line = fgets($fp, 1024);
85

    
86
			$info = stream_get_meta_data($fp);
87
			if ($info['timed_out'])
88
				break;
89

    
90
			/* parse header list line */
91
			if (strpos($line, "INFO:") !== false)
92
				continue;
93
			if (strpos($line, "SUCCESS") !== false) {
94
				$killed = 0;
95
			}
96
			break;
97
		}
98
		fclose($fp);
99
	}
100
	return $killed;
101
}
102

    
103
$servers = openvpn_get_active_servers();
104
$sk_servers = openvpn_get_active_servers("p2p");
105
$clients = openvpn_get_active_clients();
106

    
107
include("head.inc"); ?>
108

    
109
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
110
<?php include("fbegin.inc"); ?>
111
<form action="status_openvpn.php" method="get" name="iform">
112
<script type="text/javascript">
113
	function killClient(mport, remipp) {
114
		var busy = function(index,icon) {
115
			jQuery(icon).bind("onclick","");
116
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
117
			jQuery(icon).css("cursor","wait");
118
		}
119

    
120
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
121

    
122
		jQuery.ajax(
123
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
124
				"?action=kill&port=" + mport + "&remipp=" + remipp,
125
			{ type: "get", complete: killComplete }
126
		);
127
	}
128

    
129
	function killComplete(req) {
130
		var values = req.responseText.split("|");
131
		if(values[3] != "0") {
132
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
133
			return;
134
		}
135

    
136
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
137
			function(index,row) { jQuery(row).fadeOut(1000); }
138
		);
139
	}
140
</script>
141
<?php $i = 0; ?>
142
<?php foreach ($servers as $server): ?>
143

    
144
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
145
	<tr>
146
		<td colspan="6" class="listtopic">
147
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
148
		</td>
149
	</tr>
150
	<tr>
151
		<td>
152
			<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">
153
			<tr>
154
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
155
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
156
				<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
157
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
158
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
159
				<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
160
			</tr>
161

    
162
			<?php foreach ($server['conns'] as $conn): ?>
163
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
164
				<td class="listlr">
165
					<?=$conn['common_name'];?>
166
				</td>
167
				<td class="listr">
168
					<?=$conn['remote_host'];?>
169
				</td>
170
				<td class="listr">
171
					<?=$conn['virtual_addr'];?>
172
				</td>
173
				<td class="listr">
174
					<?=$conn['connect_time'];?>
175
				</td>
176
				<td class="listr">
177
					<?=$conn['bytes_sent'];?>
178
				</td>
179
				<td class="listr">
180
					<?=$conn['bytes_recv'];?>
181
				</td>
182
				<td class='list'>
183
					<img src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' height='17' width='17' border='0'
184
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
185
					   name='<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>'
186
					   title='<?php echo gettext("Kill client connection from") . ' ' . $conn['remote_host']; ?>' alt='' />
187
				</td>
188
			</tr>
189

    
190
			<?php endforeach; ?>
191
			<tfoot>
192
			<tr>
193
				<td colspan="2" class="list" height="12">
194
				<table>
195
				<tr>
196
				<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
197
				<?= get_service_status_icon($ssvc, true, true); ?>
198
				<td><?= get_service_control_links($ssvc, true); ?></td>
199
				</tr>
200
				</table>
201
				</td>
202
				<td colspan="4" class="list" height="12">&nbsp;</td>
203
			</tr>
204
			</tfoot>
205
		</table>
206
		</td>
207
	</tr>
208
</table>
209
<?php if (is_array($server['routes']) && count($server['routes'])): ?>
210
<div id="shroutebut-<?= $i ?>">
211
<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>
212
<br/><br/>
213
</div>
214
<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 ?>">
215
	<tr>
216
		<td colspan="6" class="listtopic">
217
			<?=$server['name'];?> <?=gettext("Routing Table"); ?>
218
		</td>
219
	</tr>
220
	<tr>
221
		<td>
222
			<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">
223
			<tr>
224
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
225
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
226
				<td class="listhdrr"><?=gettext("Target Network"); ?></td>
227
				<td class="listhdrr"><?=gettext("Last Used"); ?></td>
228
			</tr>
229

    
230
			<?php foreach ($server['routes'] as $conn): ?>
231
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
232
				<td class="listlr">
233
					<?=$conn['common_name'];?>
234
				</td>
235
				<td class="listr">
236
					<?=$conn['remote_host'];?>
237
				</td>
238
				<td class="listr">
239
					<?=$conn['virtual_addr'];?>
240
				</td>
241
				<td class="listr">
242
					<?=$conn['last_time'];?>
243
				</td>
244
			</tr>
245

    
246
			<?php endforeach; ?>
247
			<tfoot>
248
			<tr>
249
				<td colspan="6" class="list" height="12"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
250
			</tr>
251
			</tfoot>
252
		</table>
253
		</td>
254
	</tr>
255
</table>
256
<?php endif; ?>
257
<br/>
258
<?php $i++; ?>
259
<?php endforeach; ?>
260
<br/>
261

    
262
<?php if (!empty($sk_servers)) { ?>
263
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
264
	<tr>
265
		<td colspan="6" class="listtopic">
266
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
267
		</td>
268
	</tr>
269
	<tr>
270
		<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">
271
		<tr>
272
			<td class="listhdrr"><?=gettext("Name"); ?></td>
273
			<td class="listhdrr"><?=gettext("Status"); ?></td>
274
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
275
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
276
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
277
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
278
			<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
279
			<td class="listhdrr"><?=gettext("Service"); ?></td>
280
		</tr>
281

    
282
<?php foreach ($sk_servers as $sk_server): ?>
283
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
284
			<td class="listlr">
285
				<?=$sk_server['name'];?>
286
			</td>
287
			<td class="listlr">
288
				<?=$sk_server['status'];?>
289
			</td>
290
			<td class="listr">
291
				<?=$sk_server['connect_time'];?>
292
			</td>
293
			<td class="listr">
294
				<?=$sk_server['virtual_addr'];?>
295
			</td>
296
			<td class="listr">
297
				<?=$sk_server['remote_host'];?>
298
			</td>
299
			<td class="listr">
300
				<?=$sk_server['bytes_sent'];?>
301
			</td>
302
			<td class="listr">
303
				<?=$sk_server['bytes_recv'];?>
304
			</td>
305
			<td class="listr">
306
			<table>
307
			<tr>
308
			<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
309
			<?= get_service_status_icon($ssvc, false, true); ?>
310
			<td><?= get_service_control_links($ssvc, true); ?></td>
311
			</tr>
312
			</table>
313
			</td>
314
		</tr>
315
<?php endforeach; ?>
316
		</table>
317
	</tr>
318
</table>
319

    
320
<?php
321
} ?>
322
<br>
323
<?php if (!empty($clients)) { ?>
324
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
325
	<tr>
326
		<td colspan="6" class="listtopic">
327
			<?=gettext("Client Instance Statistics"); ?>
328
		</td>
329
	</tr>
330
	<tr>
331
		<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">
332
		<tr>
333
			<td class="listhdrr"><?=gettext("Name"); ?></td>
334
			<td class="listhdrr"><?=gettext("Status"); ?></td>
335
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
336
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
337
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
338
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
339
			<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
340
			<td class="listhdrr"><?=gettext("Service"); ?></td>
341
		</tr>
342

    
343
<?php foreach ($clients as $client): ?>
344
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
345
			<td class="listlr">
346
				<?=$client['name'];?>
347
			</td>
348
			<td class="listlr">
349
				<?=$client['status'];?>
350
			</td>
351
			<td class="listr">
352
				<?=$client['connect_time'];?>
353
			</td>
354
			<td class="listr">
355
				<?=$client['virtual_addr'];?>
356
			</td>
357
			<td class="listr">
358
				<?=$client['remote_host'];?>
359
			</td>
360
			<td class="listr">
361
				<?=$client['bytes_sent'];?>
362
			</td>
363
			<td class="listr">
364
				<?=$client['bytes_recv'];?>
365
			</td>
366
			<td class="listr" height="12">
367
			<table>
368
			<tr>
369
			<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
370
			<?= get_service_status_icon($ssvc, false, true); ?>
371
			<td><?= get_service_control_links($ssvc, true); ?></td>
372
			</tr>
373
			</table>
374
			</td>
375
		</tr>
376
<?php endforeach; ?>
377
		</table>
378
	</tr>
379
</table>
380

    
381
<?php 
382
}
383

    
384
if ($DisplayNote) {
385
	echo "<br/><b>" . gettext("NOTE") . ":</b> " . gettext("If you have 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.");
386
}
387

    
388
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
389
	echo gettext("No OpenVPN instance defined");
390
}
391
?>
392

    
393

    
394
<?php include("fend.inc"); ?>
395
<script type="text/javascript">
396
function show_routes(id, buttonid) {
397
	document.getElementById(buttonid).innerHTML='';
398
	aodiv = document.getElementById(id);
399
	aodiv.style.display = "block";
400
}
401
</script>
(187-187/246)