Project

General

Profile

Download (20.7 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3
	vpn_ipsec.php
4
*/
5 30fdf440 Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c)  2004, 2005 Scott Ullrich
8
	Copyright (c)  2003-2005 Manuel Kasper <mk@neon1.net>
9
 *
10
 *	Redistribution and use in source and binary forms, with or without modification,
11
 *	are permitted provided that the following conditions are met:
12
 *
13
 *	1. Redistributions of source code must retain the above copyright notice,
14
 *		this list of conditions and the following disclaimer.
15
 *
16
 *	2. Redistributions in binary form must reproduce the above copyright
17
 *		notice, this list of conditions and the following disclaimer in
18
 *		the documentation and/or other materials provided with the
19
 *		distribution.
20
 *
21
 *	3. All advertising materials mentioning features or use of this software
22
 *		must display the following acknowledgment:
23
 *		"This product includes software developed by the pfSense Project
24
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
25
 *
26
 *	4. The names "pfSense" and "pfSense Project" must not be used to
27
 *		 endorse or promote products derived from this software without
28
 *		 prior written permission. For written permission, please contact
29
 *		 coreteam@pfsense.org.
30
 *
31
 *	5. Products derived from this software may not be called "pfSense"
32
 *		nor may "pfSense" appear in their names without prior written
33
 *		permission of the Electric Sheep Fencing, LLC.
34
 *
35
 *	6. Redistributions of any form whatsoever must retain the following
36
 *		acknowledgment:
37
 *
38
 *	"This product includes software developed by the pfSense Project
39
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
40
 *
41
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
53
 *
54
 *	====================================================================
55
 *
56
 */
57 5b237745 Scott Ullrich
58 6b07c15a Matthew Grooms
##|+PRIV
59
##|*IDENT=page-vpn-ipsec
60
##|*NAME=VPN: IPsec page
61
##|*DESCR=Allow access to the 'VPN: IPsec' page.
62
##|*MATCH=vpn_ipsec.php*
63
##|-PRIV
64
65 5b237745 Scott Ullrich
require("guiconfig.inc");
66 7a927e67 Scott Ullrich
require_once("functions.inc");
67
require_once("filter.inc");
68
require_once("shaper.inc");
69 483e6de8 Scott Ullrich
require_once("ipsec.inc");
70
require_once("vpn.inc");
71 5b237745 Scott Ullrich
72 a1d55e81 Phil Davis
if (!is_array($config['ipsec']['phase1'])) {
73 a93e56c5 Matthew Grooms
	$config['ipsec']['phase1'] = array();
74 a1d55e81 Phil Davis
}
75 a93e56c5 Matthew Grooms
76 a1d55e81 Phil Davis
if (!is_array($config['ipsec']['phase2'])) {
77 a93e56c5 Matthew Grooms
	$config['ipsec']['phase2'] = array();
78 a1d55e81 Phil Davis
}
79 a93e56c5 Matthew Grooms
80
$a_phase1 = &$config['ipsec']['phase1'];
81
$a_phase2 = &$config['ipsec']['phase2'];
82
83 5b237745 Scott Ullrich
$pconfig['enable'] = isset($config['ipsec']['enable']);
84
85
if ($_POST) {
86
	if ($_POST['apply']) {
87
		$retval = 0;
88 3851094f Scott Ullrich
		$retval = vpn_ipsec_configure();
89 04b46591 Ermal Lu?i
		/* reload the filter in the background */
90
		filter_configure();
91 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
92 d17c7b79 jim-p
		if ($retval >= 0) {
93 a1d55e81 Phil Davis
			if (is_subsystem_dirty('ipsec')) {
94 a368a026 Ermal Lu?i
				clear_subsystem_dirty('ipsec');
95 a1d55e81 Phil Davis
			}
96 5b237745 Scott Ullrich
		}
97 30fdf440 Stephen Beaver
	} else if ($_POST['submit'] == 'Save') {
98 5b237745 Scott Ullrich
		$pconfig = $_POST;
99 574a2b47 Scott Ullrich
100 5b237745 Scott Ullrich
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
101 c20acc35 Scott Ullrich
102 5b237745 Scott Ullrich
		write_config();
103 9fad9848 jim-p
104
		$retval = vpn_ipsec_configure();
105 135ad35b Sander van Leeuwen
	} else if (isset($_POST['del'])) {
106 eca6f787 Renato Botelho
		/* delete selected p1 entries */
107
		if (is_array($_POST['p1entry']) && count($_POST['p1entry'])) {
108
			foreach ($_POST['p1entry'] as $p1entrydel) {
109
				unset($a_phase1[$p1entrydel]);
110
			}
111 a1d55e81 Phil Davis
			if (write_config()) {
112 eca6f787 Renato Botelho
				mark_subsystem_dirty('ipsec');
113 a1d55e81 Phil Davis
			}
114 eca6f787 Renato Botelho
		}
115 135ad35b Sander van Leeuwen
	} else if (isset($_POST['delp2'])) {
116 761882a1 Renato Botelho
		/* delete selected p2 entries */
117
		if (is_array($_POST['p2entry']) && count($_POST['p2entry'])) {
118
			foreach ($_POST['p2entry'] as $p2entrydel) {
119
				unset($a_phase2[$p2entrydel]);
120
			}
121 a1d55e81 Phil Davis
			if (write_config()) {
122 761882a1 Renato Botelho
				mark_subsystem_dirty('ipsec');
123 a1d55e81 Phil Davis
			}
124 761882a1 Renato Botelho
		}
125 eca6f787 Renato Botelho
	} else {
126
		/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
127 5ddd7e7b Sander van Leeuwen
128
		// TODO: this. is. nasty.
129 495c7f0c Renato Botelho
		unset($delbtn, $delbtnp2, $movebtn, $movebtnp2, $togglebtn, $togglebtnp2);
130 eca6f787 Renato Botelho
		foreach ($_POST as $pn => $pd) {
131 5ddd7e7b Sander van Leeuwen
			if (preg_match("/del_(\d+)/", $pn, $matches)) {
132 495c7f0c Renato Botelho
				$delbtn = $matches[1];
133 5ddd7e7b Sander van Leeuwen
			} else if (preg_match("/delp2_(\d+)/", $pn, $matches)) {
134 495c7f0c Renato Botelho
				$delbtnp2 = $matches[1];
135 5ddd7e7b Sander van Leeuwen
			} else if (preg_match("/move_(\d+)/", $pn, $matches)) {
136 eca6f787 Renato Botelho
				$movebtn = $matches[1];
137 5ddd7e7b Sander van Leeuwen
			} else if (preg_match("/movep2_(\d+)/", $pn, $matches)) {
138 495c7f0c Renato Botelho
				$movebtnp2 = $matches[1];
139 5ddd7e7b Sander van Leeuwen
			} else if (preg_match("/toggle_(\d+)/", $pn, $matches)) {
140 495c7f0c Renato Botelho
				$togglebtn = $matches[1];
141 5ddd7e7b Sander van Leeuwen
			} else if (preg_match("/togglep2_(\d+)/", $pn, $matches)) {
142 495c7f0c Renato Botelho
				$togglebtnp2 = $matches[1];
143 eca6f787 Renato Botelho
			}
144
		}
145 495c7f0c Renato Botelho
146
		$save = 1;
147
148 eca6f787 Renato Botelho
		/* move selected p1 entries before this */
149
		if (isset($movebtn) && is_array($_POST['p1entry']) && count($_POST['p1entry'])) {
150
			$a_phase1_new = array();
151
152
			/* copy all p1 entries < $movebtn and not selected */
153
			for ($i = 0; $i < $movebtn; $i++) {
154 a1d55e81 Phil Davis
				if (!in_array($i, $_POST['p1entry'])) {
155 eca6f787 Renato Botelho
					$a_phase1_new[] = $a_phase1[$i];
156 a1d55e81 Phil Davis
				}
157 eca6f787 Renato Botelho
			}
158
159
			/* copy all selected p1 entries */
160
			for ($i = 0; $i < count($a_phase1); $i++) {
161 a1d55e81 Phil Davis
				if ($i == $movebtn) {
162 eca6f787 Renato Botelho
					continue;
163 a1d55e81 Phil Davis
				}
164
				if (in_array($i, $_POST['p1entry'])) {
165 eca6f787 Renato Botelho
					$a_phase1_new[] = $a_phase1[$i];
166 a1d55e81 Phil Davis
				}
167 eca6f787 Renato Botelho
			}
168
169
			/* copy $movebtn p1 entry */
170 a1d55e81 Phil Davis
			if ($movebtn < count($a_phase1)) {
171 eca6f787 Renato Botelho
				$a_phase1_new[] = $a_phase1[$movebtn];
172 a1d55e81 Phil Davis
			}
173 eca6f787 Renato Botelho
174
			/* copy all p1 entries > $movebtn and not selected */
175
			for ($i = $movebtn+1; $i < count($a_phase1); $i++) {
176 a1d55e81 Phil Davis
				if (!in_array($i, $_POST['p1entry'])) {
177 eca6f787 Renato Botelho
					$a_phase1_new[] = $a_phase1[$i];
178 a1d55e81 Phil Davis
				}
179 eca6f787 Renato Botelho
			}
180 a1d55e81 Phil Davis
			if (count($a_phase1_new) > 0) {
181 eca6f787 Renato Botelho
				$a_phase1 = $a_phase1_new;
182 a1d55e81 Phil Davis
			}
183 eca6f787 Renato Botelho
184 495c7f0c Renato Botelho
		} else if (isset($movebtnp2) && is_array($_POST['p2entry']) && count($_POST['p2entry'])) {
185
			/* move selected p2 entries before this */
186 761882a1 Renato Botelho
			$a_phase2_new = array();
187
188 495c7f0c Renato Botelho
			/* copy all p2 entries < $movebtnp2 and not selected */
189
			for ($i = 0; $i < $movebtnp2; $i++) {
190 a1d55e81 Phil Davis
				if (!in_array($i, $_POST['p2entry'])) {
191 761882a1 Renato Botelho
					$a_phase2_new[] = $a_phase2[$i];
192 a1d55e81 Phil Davis
				}
193 761882a1 Renato Botelho
			}
194
195
			/* copy all selected p2 entries */
196
			for ($i = 0; $i < count($a_phase2); $i++) {
197 a1d55e81 Phil Davis
				if ($i == $movebtnp2) {
198 761882a1 Renato Botelho
					continue;
199 a1d55e81 Phil Davis
				}
200
				if (in_array($i, $_POST['p2entry'])) {
201 761882a1 Renato Botelho
					$a_phase2_new[] = $a_phase2[$i];
202 a1d55e81 Phil Davis
				}
203 761882a1 Renato Botelho
			}
204
205 495c7f0c Renato Botelho
			/* copy $movebtnp2 p2 entry */
206 a1d55e81 Phil Davis
			if ($movebtnp2 < count($a_phase2)) {
207 495c7f0c Renato Botelho
				$a_phase2_new[] = $a_phase2[$movebtnp2];
208 a1d55e81 Phil Davis
			}
209 761882a1 Renato Botelho
210 495c7f0c Renato Botelho
			/* copy all p2 entries > $movebtnp2 and not selected */
211
			for ($i = $movebtnp2+1; $i < count($a_phase2); $i++) {
212 a1d55e81 Phil Davis
				if (!in_array($i, $_POST['p2entry'])) {
213 761882a1 Renato Botelho
					$a_phase2_new[] = $a_phase2[$i];
214 a1d55e81 Phil Davis
				}
215 761882a1 Renato Botelho
			}
216 a1d55e81 Phil Davis
			if (count($a_phase2_new) > 0) {
217 761882a1 Renato Botelho
				$a_phase2 = $a_phase2_new;
218 a1d55e81 Phil Davis
			}
219 761882a1 Renato Botelho
220 495c7f0c Renato Botelho
		} else if (isset($togglebtn)) {
221 a1d55e81 Phil Davis
			if (isset($a_phase1[$togglebtn]['disabled'])) {
222 495c7f0c Renato Botelho
				unset($a_phase1[$togglebtn]['disabled']);
223 a1d55e81 Phil Davis
			} else {
224 495c7f0c Renato Botelho
				$a_phase1[$togglebtn]['disabled'] = true;
225 a1d55e81 Phil Davis
			}
226 495c7f0c Renato Botelho
		} else if (isset($togglebtnp2)) {
227 a1d55e81 Phil Davis
			if (isset($a_phase2[$togglebtnp2]['disabled'])) {
228 495c7f0c Renato Botelho
				unset($a_phase2[$togglebtnp2]['disabled']);
229 a1d55e81 Phil Davis
			} else {
230 495c7f0c Renato Botelho
				$a_phase2[$togglebtnp2]['disabled'] = true;
231 a1d55e81 Phil Davis
			}
232 495c7f0c Renato Botelho
		} else if (isset($delbtn)) {
233
			/* remove static route if interface is not WAN */
234 a1d55e81 Phil Davis
			if ($a_phase1[$delbtn]['interface'] <> "wan") {
235 495c7f0c Renato Botelho
				mwexec("/sbin/route delete -host {$a_phase1[$delbtn]['remote-gateway']}");
236 a1d55e81 Phil Davis
			}
237 eca6f787 Renato Botelho
238 495c7f0c Renato Botelho
			/* remove all phase2 entries that match the ikeid */
239
			$ikeid = $a_phase1[$delbtn]['ikeid'];
240 a1d55e81 Phil Davis
			foreach ($a_phase2 as $p2index => $ph2tmp) {
241 495c7f0c Renato Botelho
				if ($ph2tmp['ikeid'] == $ikeid) {
242
					unset($a_phase2[$p2index]);
243
				}
244 a1d55e81 Phil Davis
			}
245 495c7f0c Renato Botelho
			unset($a_phase1[$delbtn]);
246 761882a1 Renato Botelho
247 495c7f0c Renato Botelho
		} else if (isset($delbtnp2)) {
248
			unset($a_phase2[$delbtnp2]);
249 761882a1 Renato Botelho
250 a1d55e81 Phil Davis
		} else {
251 495c7f0c Renato Botelho
			$save = 0;
252 a1d55e81 Phil Davis
		}
253 495c7f0c Renato Botelho
254
		if ($save === 1) {
255 a1d55e81 Phil Davis
			if (write_config()) {
256 495c7f0c Renato Botelho
				mark_subsystem_dirty('ipsec');
257 a1d55e81 Phil Davis
			}
258 495c7f0c Renato Botelho
		}
259
	}
260 5b237745 Scott Ullrich
}
261 4df96eff Scott Ullrich
262 6c07db48 Phil Davis
$pgtitle = array(gettext("VPN"), gettext("IPsec"));
263 b32dd0a6 jim-p
$shortcut_section = "ipsec";
264 6deedfde jim-p
265 4df96eff Scott Ullrich
include("head.inc");
266
267 761e41a1 Stephen Beaver
$tab_array = array();
268
$tab_array[] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
269
$tab_array[] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
270
$tab_array[] = array(gettext("Pre-Shared Keys"), false, "vpn_ipsec_keys.php");
271
$tab_array[] = array(gettext("Advanced Settings"), false, "vpn_ipsec_settings.php");
272
display_top_tabs($tab_array);
273 53d4b84d Scott Ullrich
?>
274 422f27c0 Scott Ullrich
275 eca6f787 Renato Botelho
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
276 5ddd7e7b Sander van Leeuwen
277 323d040b Scott Ullrich
<?php
278 a1d55e81 Phil Davis
	if ($savemsg) {
279 7d7b35b9 Stephen Beaver
		print_info_box($savemsg, 'success');
280 a1d55e81 Phil Davis
	}
281 7d7b35b9 Stephen Beaver
282 a1d55e81 Phil Davis
	if ($pconfig['enable'] && is_subsystem_dirty('ipsec')) {
283 8cd558b6 ayvis
		print_info_box_np(gettext("The IPsec tunnel configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));
284 a1d55e81 Phil Davis
	}
285 574a2b47 Scott Ullrich
?>
286 5ddd7e7b Sander van Leeuwen
287
<form method="post">
288 30fdf440 Stephen Beaver
	<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked=\"checked\"";?> />&nbsp;&nbsp;<?=gettext("Enable IPsec")?><br /><br />
289
	<input name="submit" type="submit" class="btn btn-sm btn-primary" value="<?=gettext("Save"); ?>" /><br /><br />
290
291
	<div class="panel panel-default">
292
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('IPSec tunnels')?></h2></div>
293
		<div class="panel-body table-responsive">
294
			<table class="table table-striped table-hover">
295
				<thead>
296
					<tr>
297
						<th>&nbsp;</th>
298
						<th>&nbsp;</th>
299
						<th><?=gettext("IKE"); ?></th>
300
						<th><?=gettext("Remote Gateway"); ?></th>
301
						<th><?=gettext("Mode"); ?></th>
302
						<th><?=gettext("P1 Protocol"); ?></th>
303
						<th><?=gettext("P1 Transforms"); ?></th>
304
						<th><?=gettext("P1 Description"); ?></th>
305
						<th></th>
306
					</tr>
307
				</thead>
308 1d770fc7 Stephen Beaver
				<tbody class="p1-entries">
309 5ddd7e7b Sander van Leeuwen
<?php $i = 0; foreach ($a_phase1 as $ph1ent): ?>
310 e0fb12c1 Renato Botelho
<?php
311 5ddd7e7b Sander van Leeuwen
	$iconfn = "pass";
312
313
	$entryStatus = (isset($ph1ent['disabled']) ? 'disabled' : 'enabled');
314
315
	if ($entryStatus == 'disabled') {
316
		$iconfn .= "_d";
317
	}
318 e0fb12c1 Renato Botelho
?>
319 30fdf440 Stephen Beaver
					<tr id="fr<?=$i?>" ondblclick="document.location='vpn_ipsec_phase1.php?p1index=<?=$i?>'" class="<?= $entryStatus ?>">
320
						<td>
321
							<input type="checkbox" id="frc<?=$i?>" name="p1entry[]" value="<?=$i?>" onclick="fr_bgcolor('<?=$i?>')" />
322
						</td>
323
						<td>
324
							<button value="toggle_<?=$i?>" name="toggle_<?=$i?>" title="<?=gettext("click to toggle enabled/disabled status")?>" class="btn btn-xs btn-default" type="submit"><?= ($entryStatus == 'disabled' ? 'enable' : 'disable') ?></button>
325
						</td>
326
						<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>">
327 e0fb12c1 Renato Botelho
<?php
328 5ddd7e7b Sander van Leeuwen
			if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == "ikev1")
329
				echo "V1";
330
			else
331
				echo "V2";
332 e0fb12c1 Renato Botelho
?>
333 30fdf440 Stephen Beaver
						</td>
334
						<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>">
335 e0fb12c1 Renato Botelho
<?php
336 5ddd7e7b Sander van Leeuwen
			if ($ph1ent['interface']) {
337
				$iflabels = get_configured_interface_with_descr();
338
339
				$carplist = get_configured_carp_interface_list();
340
				foreach ($carplist as $cif => $carpip)
341
					$iflabels[$cif] = $carpip." (".get_vip_descr($carpip).")";
342
343
				$aliaslist = get_configured_ip_aliases_list();
344
				foreach ($aliaslist as $aliasip => $aliasif)
345
					$iflabels[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
346
347
				$grouplist = return_gateway_groups_array();
348
				foreach ($grouplist as $name => $group) {
349
					if($group[0]['vip'] != "")
350
						$vipif = $group[0]['vip'];
351
					else
352
						$vipif = $group[0]['int'];
353
					$iflabels[$name] = "GW Group {$name}";
354
				}
355
				$if = htmlspecialchars($iflabels[$ph1ent['interface']]);
356
			}
357
			else
358
				$if = "WAN";
359
360
			if (!isset($ph1ent['mobile']))
361
				echo $if."<br />".$ph1ent['remote-gateway'];
362
			else
363
				echo $if."<br /><strong>" . gettext("Mobile Client") . "</strong>";
364 e0fb12c1 Renato Botelho
?>
365 135ad35b Sander van Leeuwen
				</td>
366
				<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>">
367
					<?=$spans?>
368
					<?php
369
					if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == "ikev1")
370
						echo "{$ph1ent['mode']}";
371
					?>
372
					<?=$spane?>
373
				</td>
374
				<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>">
375
					<?=$p1_ealgos[$ph1ent['encryption-algorithm']['name']]['name']?>
376 e0fb12c1 Renato Botelho
<?php
377 5ddd7e7b Sander van Leeuwen
			if ($ph1ent['encryption-algorithm']['keylen']) {
378
				if ($ph1ent['encryption-algorithm']['keylen']=="auto")
379
					echo " (" . gettext("auto") . ")";
380
				else
381
					echo " ({$ph1ent['encryption-algorithm']['keylen']} " . gettext("bits") . ")";
382
			}
383 e0fb12c1 Renato Botelho
?>
384 30fdf440 Stephen Beaver
						</td>
385
						<td>
386
							<?=$p1_halgos[$ph1ent['hash-algorithm']]?>
387
						</td>
388
						<td>
389
							<?=htmlspecialchars($ph1ent['descr'])?>
390
						</td>
391
						<td>
392 135ad35b Sander van Leeuwen
					<?php // TODO: add mouseover behaviour which indicates insert position when moving ?>
393 1d770fc7 Stephen Beaver
					<button class="btn btn-xs btn-default" type="submit" name="move_<?=$i?>" value="move_<?=$i?>"><?=gettext("Move checked entries to here")?></button>
394 30fdf440 Stephen Beaver
							<a class="btn btn-xs btn-primary" href="vpn_ipsec_phase1.php?p1index=<?=$i?>" title="<?=gettext("edit phase1 entry"); ?>">edit</a>
395
							<button class="btn btn-xs btn-danger" type="submit" name="del_<?=$i?>" value="del_<?=$i?>" title="<?=gettext('delete phase1 entry'); ?>">delete</button>
396 135ad35b Sander van Leeuwen
		<?php if (!isset($ph1ent['mobile'])): ?>
397
					<a class="btn btn-xs btn-success" href="vpn_ipsec_phase1.php?dup=<?=$i?>" title="<?=gettext("copy phase1 entry"); ?>">copy</a>
398
		<?php endif; ?>
399 30fdf440 Stephen Beaver
						</td>
400
					</tr>
401
					<tr class="<?= $entryStatus ?>">
402
						<td colspan="2"></td>
403
						<td colspan="7" class="contains-table">
404 e0fb12c1 Renato Botelho
<?php
405 5ddd7e7b Sander van Leeuwen
			if (isset($_POST["tdph2-{$i}-visible"]))
406
				$tdph2_visible = htmlspecialchars($_POST["tdph2-{$i}-visible"]);
407
			else
408
				$tdph2_visible = 0;
409 e0fb12c1 Renato Botelho
?>
410 135ad35b Sander van Leeuwen
					<input type="hidden" name="tdph2-<?=$i?>-visible" id="tdph2-<?=$i?>-visible" value="<?=$tdph2_visible?>" />
411
					<div id="shph2but-<?=$i?>" <?=($tdph2_visible == '1' ? 'style="display:none"' : '')?>>
412 91ebc808 Renato Botelho
<?php
413 5ddd7e7b Sander van Leeuwen
				$phase2count=0;
414 7d7b35b9 Stephen Beaver
415 5ddd7e7b Sander van Leeuwen
				foreach ($a_phase2 as $ph2ent) {
416
					if ($ph2ent['ikeid'] != $ph1ent['ikeid'])
417
						continue;
418
					$phase2count++;
419
				}
420
				$fr_prefix = "frp2{$i}";
421
				$fr_header = $fr_prefix . "header";
422 91ebc808 Renato Botelho
?>
423 135ad35b Sander van Leeuwen
						<input type="button" onclick="show_phase2('tdph2-<?=$i?>','shph2but-<?=$i?>')" value="+" /> - <?php printf(gettext("Show %s Phase-2 entries"), $phase2count); ?>
424
					</div>
425
					<div id="tdph2-<?=$i?>" <?=($tdph2_visible != '1' ? 'style="display:none"' : '')?>>
426
						<table class="table table-striped table-hover">
427
							<thead>
428
								<tr>
429
									<th>&nbsp;</th>
430
									<th>&nbsp;</th>
431
									<th><?=gettext("Mode"); ?></th>
432
									<th><?=gettext("Local Subnet"); ?></th>
433
									<th><?=gettext("Remote Subnet"); ?></th>
434
									<th><?=gettext("P2 Protocol"); ?></th>
435
									<th><?=gettext("P2 Transforms"); ?></th>
436
									<th><?=gettext("P2 Auth Methods"); ?></th>
437
									<th>&nbsp;</th>
438
								</tr>
439
							</thead>
440 1d770fc7 Stephen Beaver
							<tbody class="p2-entries">
441 5ddd7e7b Sander van Leeuwen
<?php $j = 0; foreach ($a_phase2 as $ph2index => $ph2ent): ?>
442 e0fb12c1 Renato Botelho
<?php
443 5ddd7e7b Sander van Leeuwen
						if ($ph2ent['ikeid'] != $ph1ent['ikeid'])
444
							continue;
445
446
						$fr_c = $fr_prefix . "c" . $j;
447
						$fr_d = $fr_prefix . "d" . $j;
448
449
						$iconfn = "pass";
450
						$entryStatus = (isset($ph2ent['disabled']) || isset($ph1ent['disabled']) ? 'disabled' : 'enabled');
451
452
						if ($entryStatus == 'disabled')
453
							$iconfn .= "_d";
454
455 e0fb12c1 Renato Botelho
?>
456 135ad35b Sander van Leeuwen
								<tr id="<?=$fr_prefix . $j?>" ondblclick="document.location='vpn_ipsec_phase2.php?p2index=<?=$ph2ent['uniqid']?>'" class="<?= $entryStatus ?>">
457
									<td>
458
										<input type="checkbox" id="<?=$fr_c?>" name="p2entry[]" value="<?=$ph2index?>" onclick="fr_bgcolor('<?=$j?>', '<?=$fr_prefix?>')" />
459
									</td>
460
									<td>
461
										<button value="togglep2_<?=$ph2index?>" name="togglep2_<?=$ph2index?>" title="<?=gettext("click to toggle enabled/disabled status")?>" class="btn btn-xs btn-default" type="submit"><?= ($entryStatus == 'disabled'? 'enable' : 'disable') ?></button>
462
									</td>
463
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
464
										<?=$ph2ent['mode']?>
465
									</td>
466 5ddd7e7b Sander van Leeuwen
<?php if(($ph2ent['mode'] == "tunnel") or ($ph2ent['mode'] == "tunnel6")): ?>
467 135ad35b Sander van Leeuwen
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
468
										<?=ipsec_idinfo_to_text($ph2ent['localid']); ?>
469
									</td>
470
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
471
										<?=ipsec_idinfo_to_text($ph2ent['remoteid']); ?>
472
									</td>
473 5ddd7e7b Sander van Leeuwen
<?php else: ?>
474 135ad35b Sander van Leeuwen
									<td colspan="2"></td>
475 5ddd7e7b Sander van Leeuwen
<?php endif; ?>
476 135ad35b Sander van Leeuwen
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
477
										<?=$p2_protos[$ph2ent['protocol']]; ?>
478
									</td>
479
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
480 e0fb12c1 Renato Botelho
<?php
481 5ddd7e7b Sander van Leeuwen
								foreach ($ph2ent['encryption-algorithm-option'] as $k => $ph2ea) {
482
									if ($k)
483
										echo ", ";
484
									echo $p2_ealgos[$ph2ea['name']]['name'];
485
									if ($ph2ea['keylen']) {
486
										if ($ph2ea['keylen']=="auto")
487
											echo " (" . gettext("auto") . ")";
488
										else
489
											echo " ({$ph2ea['keylen']} " . gettext("bits") . ")";
490 761882a1 Renato Botelho
									}
491 5ddd7e7b Sander van Leeuwen
								}
492 e0fb12c1 Renato Botelho
?>
493 135ad35b Sander van Leeuwen
									</td>
494
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
495 e0fb12c1 Renato Botelho
<?php
496 5ddd7e7b Sander van Leeuwen
								if (!empty($ph2ent['hash-algorithm-option']) && is_array($ph2ent['hash-algorithm-option'])) {
497
									foreach ($ph2ent['hash-algorithm-option'] as $k => $ph2ha) {
498
										if ($k)
499
											echo ", ";
500
										echo $p2_halgos[$ph2ha];
501
									}
502
								}
503 e0fb12c1 Renato Botelho
?>
504 135ad35b Sander van Leeuwen
									</td>
505
									<td>
506
										<?php // TODO: add mouseover behaviour which indicates insert position when moving ?>
507 1d770fc7 Stephen Beaver
										<button class="btn btn-xs btn-default" type="submit" name="movep2_<?=$j?>" value="movep2_<?=$j?>"><?=gettext("Move checked P2s here")?></button>
508 135ad35b Sander van Leeuwen
										<a class="btn btn-xs btn-primary" href="vpn_ipsec_phase2.php?p2index=<?=$ph2ent['uniqid']?>" title="<?=gettext("edit phase2 entry"); ?>">edit</a>
509
										<button class="btn btn-xs btn-danger" type="submit" name="delp2_<?=$ph2index?>" value="delp2_<?=$ph2index?>" title="<?=gettext('delete phase2 entry'); ?>">delete</button>
510
										<a class="btn btn-xs btn-success" href="vpn_ipsec_phase2.php?dup=<?=$ph2ent['uniqid']?>" title="<?=gettext("add a new Phase 2 based on this one"); ?>">copy</a>
511
									</td>
512
								</tr>
513 5ddd7e7b Sander van Leeuwen
<?php $j++; endforeach; ?>
514 135ad35b Sander van Leeuwen
								<tr>
515
									<td colspan="8"></td>
516
									<td>
517 761882a1 Renato Botelho
<?php
518 5ddd7e7b Sander van Leeuwen
							if ($j == 0):
519 761882a1 Renato Botelho
?>
520 d62df86b Jared Dillard
										<i class="icon icon-arrow-down" title="<?=gettext("move selected phase2 entries to end")?>" alt="move"></i>
521 761882a1 Renato Botelho
<?php
522 5ddd7e7b Sander van Leeuwen
							else:
523 761882a1 Renato Botelho
?>
524 d62df86b Jared Dillard
										<i class="icon icon-arrow-down" name="movep2_<?=$j?>" onmouseover="fr_insline(<?=$j?>, true, '<?=$fr_prefix?>')" onmouseout="fr_insline(<?=$j?>, false, '<?=$fr_prefix?>')" title="<?=gettext("move selected phase2 entries to end")?>" alt="move"></i>
525 761882a1 Renato Botelho
<?php
526 5ddd7e7b Sander van Leeuwen
							endif;
527 761882a1 Renato Botelho
?>
528 135ad35b Sander van Leeuwen
										<a href="vpn_ipsec_phase2.php?ikeid=<?=$ph1ent['ikeid']?><?php if (isset($ph1ent['mobile'])) echo "&amp;mobile=true"?>">
529 d62df86b Jared Dillard
											<i class="icon icon-plus-sign" title="<?=gettext("add phase2 entry"); ?>" alt="add"></i>
530 135ad35b Sander van Leeuwen
										</a>
531 761882a1 Renato Botelho
<?php
532 5ddd7e7b Sander van Leeuwen
							if ($j == 0):
533 761882a1 Renato Botelho
?>
534 d62df86b Jared Dillard
										<i class="icon icon-remove-sign" title="<?=gettext("delete selected phase2 entries")?>" alt="delete"></i>
535 761882a1 Renato Botelho
<?php
536 5ddd7e7b Sander van Leeuwen
							else:
537 761882a1 Renato Botelho
?>
538 d62df86b Jared Dillard
										<i name="delp2" class="icon icon-remove-sign" title="<?=gettext("delete selected phase2 entries")?>" onclick="return confirm('<?=gettext("Do you really want to delete the selected phase2 entries?")?>')"></i>
539 761882a1 Renato Botelho
<?php
540 5ddd7e7b Sander van Leeuwen
							endif;
541 761882a1 Renato Botelho
?>
542 30fdf440 Stephen Beaver
											</td>
543
										</tr>
544
									</tbody>
545
								</table>
546
							</div>
547
						</td>
548
					</tr>
549 761882a1 Renato Botelho
<?php
550 135ad35b Sander van Leeuwen
					$i++;
551 30fdf440 Stephen Beaver
				endforeach;	 // $a_phase1 as $ph1ent
552 761882a1 Renato Botelho
?>
553 30fdf440 Stephen Beaver
			</tbody>
554
		</table>
555
	</div>
556 135ad35b Sander van Leeuwen
</div>
557 5ddd7e7b Sander van Leeuwen
558 135ad35b Sander van Leeuwen
<nav class="action-buttons">
559
<?php if ($i !== 0): ?>
560
	<input type="submit" name="move_<?=$i?>" class="btn btn-default" value="<?=gettext("move selected phase1 entries to end")?>" />
561
<?php endif; ?>
562
	<a href="vpn_ipsec_phase1.php" class="btn btn-success"><?=gettext("add new phase1")?></a>
563
<?php if ($i !== 0): ?>
564
	<input type="submit" name="del" class="btn btn-danger" value="<?=gettext("delete selected phase1 entries")?>" onclick="return confirm('<?=gettext("Do you really want to delete the selected phase1 entries?")?>')" />
565
<?php endif; ?>
566
</nav>
567 5b237745 Scott Ullrich
</form>
568 5ddd7e7b Sander van Leeuwen
569
<div class="alert alert-info">
570
	<strong><?=gettext("Note:")?></strong><br />
571
	<?=gettext("You can check your IPsec status at"); ?> <a href="diag_ipsec.php"><?=gettext("Status:IPsec"); ?></a>.<br />
572
	<?=gettext("IPsec Debug Mode can be enabled at"); ?> <a href="vpn_ipsec_settings.php"><?=gettext("VPN:IPsec:Advanced Settings"); ?></a>.<br />
573
	<?=gettext("IPsec can be set to prefer older SAs at"); ?> <a href="vpn_ipsec_settings.php"><?=gettext("VPN:IPsec:Advanced Settings"); ?></a>.
574
</div>
575
576
<?php include("foot.inc"); ?>
577 0a95b653 Scott Ullrich
<script type="text/javascript">
578 391453a1 Colin Fleming
//<![CDATA[
579 0a95b653 Scott Ullrich
function show_phase2(id, buttonid) {
580
	document.getElementById(buttonid).innerHTML='';
581 91ebc808 Renato Botelho
	document.getElementById(id).style.display = "block";
582
	var visible = id + '-visible';
583
	document.getElementById(visible).value = "1";
584 0a95b653 Scott Ullrich
}
585 1d770fc7 Stephen Beaver
586
events.push(function() {
587
	// Make rules sortable
588
	$('table tbody.p2-entries').sortable({
589
		cursor: 'grabbing',
590
		update: function(event, ui) {
591
			$('#order-store').removeAttr('disabled');
592
		}
593
	});
594
});
595 391453a1 Colin Fleming
//]]>
596 8a251ec2 Chris Buechler
</script>