Project

General

Profile

Download (7.83 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 63084885 Matthew Grooms
require("guiconfig.inc");
48 53663f57 jim-p
require_once("openvpn.inc");
49 63084885 Matthew Grooms
50 0927fb8c jim-p
/* 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 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
60 0927fb8c jim-p
		}
61
		exit;
62
	}
63
}
64
65
66
function kill_client($port, $remipp) {
67 71ca2cb2 Ermal
	global $g;
68
69
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
70
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
71 0927fb8c jim-p
	$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 19e3d450 Ermal
		stream_set_timeout($fp, 1);
79 0927fb8c jim-p
		fputs($fp, "kill {$remipp}\n");
80
		while (!feof($fp)) {
81
			$line = fgets($fp, 1024);
82 b0140675 Ermal
83
			$info = stream_get_meta_data($fp);
84
			if ($info['timed_out'])
85
				break;
86
87 0927fb8c jim-p
			/* parse header list line */
88 68b04527 jim-p
			if (strpos($line, "INFO:") !== false)
89 0927fb8c jim-p
				continue;
90 68b04527 jim-p
			if (strpos($line, "SUCCESS") !== false) {
91 0927fb8c jim-p
				$killed = 0;
92
			}
93
			break;
94
		}
95
		fclose($fp);
96
	}
97
	return $killed;
98
}
99
100 53663f57 jim-p
$servers = openvpn_get_active_servers();
101
$clients = openvpn_get_active_clients();
102 63084885 Matthew Grooms
103 0927fb8c jim-p
include("head.inc"); ?>
104
105
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
106
<script src="/javascript/sorttable.js" type="text/javascript"></script>
107
<?php include("fbegin.inc"); ?>
108
<form action="status_openvpn.php" method="get" name="iform">
109
<script type="text/javascript">
110
	function killClient(mport, remipp) {
111
		var busy = function(icon) {
112
			icon.onclick      = "";
113
			icon.src          = icon.src.replace("\.gif", "_d.gif");
114
			icon.style.cursor = "wait";
115
		}
116
117
		$A(document.getElementsByName("i:" + mport + ":" + remipp)).each(busy);
118
119
		new Ajax.Request(
120
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
121
				"?action=kill&port=" + mport + "&remipp=" + remipp,
122
			{ method: "get", onComplete: killComplete }
123
		);
124
	}
125
126
	function killComplete(req) {
127
		var values = req.responseText.split("|");
128
		if(values[3] != "0") {
129
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
130
			return;
131
		}
132
133
		$A(document.getElementsByName("r:" + values[1] + ":" + values[2])).each(
134
			function(row) { Effect.Fade(row, { duration: 1.0 }); }
135
		);
136
	}
137
</script>
138
139
<?php foreach ($servers as $server): ?>
140
141
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
142
	<tr>
143
		<td colspan="6" class="listtopic">
144 e9d35ff5 Carlos Eduardo Ramos
			<?=gettext("Client connections for"); ?> <?=$server['name'];?>
145 0927fb8c jim-p
		</td>
146
	</tr>
147
	<tr>
148 41be629f jim-p
<?php if ($server['mode'] == "p2p_shared_key"): ?>
149
		<td>Status data is not available for shared key servers.</td>
150
<?php else: ?>
151 0927fb8c jim-p
		<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 e9d35ff5 Carlos Eduardo Ramos
				<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 0927fb8c jim-p
			</tr>
161
162
			<?php foreach ($server['conns'] as $conn): ?>
163 68b04527 jim-p
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
164 0927fb8c jim-p
				<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 71ca2cb2 Ermal
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
185 68b04527 jim-p
					   name='<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>'
186
					   title='<?php echo gettext("Kill client connection from") . ' ' . $conn['remote_host']; ?>' alt='' />
187 0927fb8c jim-p
				</td>
188
			</tr>
189
190
			<?php endforeach; ?>
191
			<tr>
192
				<td colspan="6" class="list" height="12"></td>
193
			</tr>
194
195
		</table>
196
		</td>
197 41be629f jim-p
<? endif; ?>
198 0927fb8c jim-p
	</tr>
199
</table>
200 63084885 Matthew Grooms
201 0927fb8c jim-p
<?php endforeach; ?>
202 d0f6649c pierrepomes
<br>
203
204
205 cf1ced6d pierrepomes
<?php if (!empty($clients)) { ?>
206 d0f6649c pierrepomes
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
207
	<tr>
208
		<td colspan="6" class="listtopic">
209 e9d35ff5 Carlos Eduardo Ramos
			<?=gettext("OpenVPN client instances statistics"); ?>
210 d0f6649c pierrepomes
		</td>
211
	</tr>
212
	<tr>
213
		<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">
214
		<tr>
215 e9d35ff5 Carlos Eduardo Ramos
			<td class="listhdrr"><?=gettext("Name"); ?></td>
216
			<td class="listhdrr"><?=gettext("Status"); ?></td>
217
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
218
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
219
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
220
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
221
			<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
222 d0f6649c pierrepomes
		</tr>
223
224
<?php foreach ($clients as $client): ?>
225
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
226
			<td class="listlr">
227
				<?=$client['name'];?>
228
			</td>
229
			<td class="listlr">
230
				<?=$client['status'];?>
231
			</td>
232
			<td class="listr">
233
				<?=$client['connect_time'];?>
234
			</td>
235
			<td class="listr">
236
				<?=$client['virtual_addr'];?>
237
			</td>
238
			<td class="listr">
239
				<?=$client['remote_host'];?>
240
			</td>
241
			<td class="listr">
242
				<?=$client['bytes_sent'];?>
243
			</td>
244
			<td class="listr">
245
				<?=$client['bytes_recv'];?>
246
			</td>
247
		</tr>
248
<?php endforeach; ?>
249
		</table>
250
	</tr>
251
</table>
252
253 cf1ced6d pierrepomes
<?php 
254
}
255
256
if ($DisplayNote) {
257 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");
258 d0f6649c pierrepomes
}
259
260 cf1ced6d pierrepomes
if ((empty($clients)) && (empty($servers))) {
261 e9d35ff5 Carlos Eduardo Ramos
	echo gettext("No OpenVPN instance defined");
262 d0f6649c pierrepomes
}
263
?>
264
265 63084885 Matthew Grooms
266
<?php include("fend.inc"); ?>