Project

General

Profile

Download (9.25 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
require("guiconfig.inc");
48
require_once("openvpn.inc");
49

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

    
65

    
66
function kill_client($port, $remipp) {
67
	global $g;
68

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

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

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

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

    
100
$servers = openvpn_get_active_servers();
101
$sk_servers = openvpn_get_active_servers("sharedkey");
102
$clients = openvpn_get_active_clients();
103

    
104
include("head.inc"); ?>
105

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

    
118
		$A(document.getElementsByName("i:" + mport + ":" + remipp)).each(busy);
119

    
120
		new Ajax.Request(
121
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
122
				"?action=kill&port=" + mport + "&remipp=" + remipp,
123
			{ method: "get", onComplete: killComplete }
124
		);
125
	}
126

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

    
134
		$A(document.getElementsByName("r:" + values[1] + ":" + values[2])).each(
135
			function(row) { Effect.Fade(row, { duration: 1.0 }); }
136
		);
137
	}
138
</script>
139

    
140
<?php foreach ($servers as $server): ?>
141

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

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

    
188
			<?php endforeach; ?>
189
			<tr>
190
				<td colspan="6" class="list" height="12"></td>
191
			</tr>
192

    
193
		</table>
194
		</td>
195
	</tr>
196
</table>
197

    
198
<?php endforeach; ?>
199
<br>
200

    
201
<?php if (!empty($sk_servers)) { ?>
202
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
203
	<tr>
204
		<td colspan="6" class="listtopic">
205
			<?=gettext("Shared Key Server Instance Statistics"); ?>
206
		</td>
207
	</tr>
208
	<tr>
209
		<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">
210
		<tr>
211
			<td class="listhdrr"><?=gettext("Name"); ?></td>
212
			<td class="listhdrr"><?=gettext("Status"); ?></td>
213
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
214
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
215
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
216
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
217
			<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
218
		</tr>
219

    
220
<?php foreach ($sk_servers as $sk_server): ?>
221
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
222
			<td class="listlr">
223
				<?=$sk_server['name'];?>
224
			</td>
225
			<td class="listlr">
226
				<?=$sk_server['status'];?>
227
			</td>
228
			<td class="listr">
229
				<?=$sk_server['connect_time'];?>
230
			</td>
231
			<td class="listr">
232
				<?=$sk_server['virtual_addr'];?>
233
			</td>
234
			<td class="listr">
235
				<?=$sk_server['remote_host'];?>
236
			</td>
237
			<td class="listr">
238
				<?=$sk_server['bytes_sent'];?>
239
			</td>
240
			<td class="listr">
241
				<?=$sk_server['bytes_recv'];?>
242
			</td>
243
		</tr>
244
<?php endforeach; ?>
245
		</table>
246
	</tr>
247
</table>
248

    
249
<?php
250
} ?>
251
<br>
252
<?php if (!empty($clients)) { ?>
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("Client 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 ($clients as $client): ?>
272
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
273
			<td class="listlr">
274
				<?=$client['name'];?>
275
			</td>
276
			<td class="listlr">
277
				<?=$client['status'];?>
278
			</td>
279
			<td class="listr">
280
				<?=$client['connect_time'];?>
281
			</td>
282
			<td class="listr">
283
				<?=$client['virtual_addr'];?>
284
			</td>
285
			<td class="listr">
286
				<?=$client['remote_host'];?>
287
			</td>
288
			<td class="listr">
289
				<?=$client['bytes_sent'];?>
290
			</td>
291
			<td class="listr">
292
				<?=$client['bytes_recv'];?>
293
			</td>
294
		</tr>
295
<?php endforeach; ?>
296
		</table>
297
	</tr>
298
</table>
299

    
300
<?php 
301
}
302

    
303
if ($DisplayNote) {
304
	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");
305
}
306

    
307
if ((empty($clients)) && (empty($servers))) {
308
	echo gettext("No OpenVPN instance defined");
309
}
310
?>
311

    
312

    
313
<?php include("fend.inc"); ?>
(174-174/232)