Project

General

Profile

Download (11.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

    
52
/* 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
			echo gettext("invalid input");
62
		}
63
		exit;
64
	}
65
}
66

    
67

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

    
71
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
72
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
73
	$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
		stream_set_timeout($fp, 1);
81
		fputs($fp, "kill {$remipp}\n");
82
		while (!feof($fp)) {
83
			$line = fgets($fp, 1024);
84

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

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

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

    
106
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
		var busy = function(index,icon) {
114
			jQuery(icon).bind("onclick","");
115
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
116
			jQuery(icon).css("cursor","wait");
117
		}
118

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

    
121
		jQuery.ajax(
122
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
123
				"?action=kill&port=" + mport + "&remipp=" + remipp,
124
			{ type: "get", complete: killComplete }
125
		);
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
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
136
			function(index,row) { jQuery(row).fadeOut(1000); }
137
		);
138
	}
139
</script>
140
<?php $i = 0; ?>
141
<?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
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
147
		</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
				<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
			</tr>
160

    
161
			<?php foreach ($server['conns'] as $conn): ?>
162
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
163
				<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
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
184
					   name='<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>'
185
					   title='<?php echo gettext("Kill client connection from") . ' ' . $conn['remote_host']; ?>' alt='' />
186
				</td>
187
			</tr>
188

    
189
			<?php endforeach; ?>
190
			<tfoot>
191
			<tr>
192
				<td colspan="6" class="list" height="12"></td>
193
			</tr>
194
			</tfoot>
195
		</table>
196
		</td>
197
	</tr>
198
</table>
199
<?php if (is_array($server['routes']) && count($server['routes'])): ?>
200
<div id="shroutebut-<?= $i ?>">
201
<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
<br/><br/>
203
</div>
204
<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
	<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

    
236
			<?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
<?php endforeach; ?>
250
<br/>
251

    
252
<?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
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
257
		</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

    
271
<?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
<?php if (!empty($clients)) { ?>
304
<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
			<?=gettext("Client Instance Statistics"); ?>
308
		</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
			<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
		</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
<?php 
352
}
353

    
354
if ($DisplayNote) {
355
	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
}
357

    
358
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
359
	echo gettext("No OpenVPN instance defined");
360
}
361
?>
362

    
363

    
364
<?php include("fend.inc"); ?>
365
<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>
(187-187/246)