Project

General

Profile

Download (21.4 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 1b6b7fc4 Stephen Beaver
87 5b237745 Scott Ullrich
	if ($_POST['apply']) {
88
		$retval = 0;
89 3851094f Scott Ullrich
		$retval = vpn_ipsec_configure();
90 04b46591 Ermal Lu?i
		/* reload the filter in the background */
91
		filter_configure();
92 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
93 d17c7b79 jim-p
		if ($retval >= 0) {
94 a1d55e81 Phil Davis
			if (is_subsystem_dirty('ipsec')) {
95 a368a026 Ermal Lu?i
				clear_subsystem_dirty('ipsec');
96 a1d55e81 Phil Davis
			}
97 5b237745 Scott Ullrich
		}
98 30fdf440 Stephen Beaver
	} else if ($_POST['submit'] == 'Save') {
99 5b237745 Scott Ullrich
		$pconfig = $_POST;
100 574a2b47 Scott Ullrich
101 5b237745 Scott Ullrich
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
102 c20acc35 Scott Ullrich
103 5b237745 Scott Ullrich
		write_config();
104 9fad9848 jim-p
105
		$retval = vpn_ipsec_configure();
106 135ad35b Sander van Leeuwen
	} else if (isset($_POST['del'])) {
107 eca6f787 Renato Botelho
		/* delete selected p1 entries */
108
		if (is_array($_POST['p1entry']) && count($_POST['p1entry'])) {
109
			foreach ($_POST['p1entry'] as $p1entrydel) {
110
				unset($a_phase1[$p1entrydel]);
111
			}
112 a1d55e81 Phil Davis
			if (write_config()) {
113 eca6f787 Renato Botelho
				mark_subsystem_dirty('ipsec');
114 a1d55e81 Phil Davis
			}
115 eca6f787 Renato Botelho
		}
116 135ad35b Sander van Leeuwen
	} else if (isset($_POST['delp2'])) {
117 761882a1 Renato Botelho
		/* delete selected p2 entries */
118
		if (is_array($_POST['p2entry']) && count($_POST['p2entry'])) {
119
			foreach ($_POST['p2entry'] as $p2entrydel) {
120
				unset($a_phase2[$p2entrydel]);
121
			}
122 a1d55e81 Phil Davis
			if (write_config()) {
123 761882a1 Renato Botelho
				mark_subsystem_dirty('ipsec');
124 a1d55e81 Phil Davis
			}
125 761882a1 Renato Botelho
		}
126 eca6f787 Renato Botelho
	} else {
127
		/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
128 5ddd7e7b Sander van Leeuwen
129
		// TODO: this. is. nasty.
130 495c7f0c Renato Botelho
		unset($delbtn, $delbtnp2, $movebtn, $movebtnp2, $togglebtn, $togglebtnp2);
131 eca6f787 Renato Botelho
		foreach ($_POST as $pn => $pd) {
132 5ddd7e7b Sander van Leeuwen
			if (preg_match("/del_(\d+)/", $pn, $matches)) {
133 495c7f0c Renato Botelho
				$delbtn = $matches[1];
134 5ddd7e7b Sander van Leeuwen
			} else if (preg_match("/delp2_(\d+)/", $pn, $matches)) {
135 495c7f0c Renato Botelho
				$delbtnp2 = $matches[1];
136 5ddd7e7b Sander van Leeuwen
			} else if (preg_match("/move_(\d+)/", $pn, $matches)) {
137 eca6f787 Renato Botelho
				$movebtn = $matches[1];
138 5ddd7e7b Sander van Leeuwen
			} else if (preg_match("/movep2_(\d+)/", $pn, $matches)) {
139 495c7f0c Renato Botelho
				$movebtnp2 = $matches[1];
140 5ddd7e7b Sander van Leeuwen
			} else if (preg_match("/toggle_(\d+)/", $pn, $matches)) {
141 495c7f0c Renato Botelho
				$togglebtn = $matches[1];
142 5ddd7e7b Sander van Leeuwen
			} else if (preg_match("/togglep2_(\d+)/", $pn, $matches)) {
143 495c7f0c Renato Botelho
				$togglebtnp2 = $matches[1];
144 eca6f787 Renato Botelho
			}
145
		}
146 495c7f0c Renato Botelho
147
		$save = 1;
148
149 eca6f787 Renato Botelho
		/* move selected p1 entries before this */
150
		if (isset($movebtn) && is_array($_POST['p1entry']) && count($_POST['p1entry'])) {
151
			$a_phase1_new = array();
152
153
			/* copy all p1 entries < $movebtn and not selected */
154
			for ($i = 0; $i < $movebtn; $i++) {
155 a1d55e81 Phil Davis
				if (!in_array($i, $_POST['p1entry'])) {
156 eca6f787 Renato Botelho
					$a_phase1_new[] = $a_phase1[$i];
157 a1d55e81 Phil Davis
				}
158 eca6f787 Renato Botelho
			}
159
160
			/* copy all selected p1 entries */
161
			for ($i = 0; $i < count($a_phase1); $i++) {
162 a1d55e81 Phil Davis
				if ($i == $movebtn) {
163 eca6f787 Renato Botelho
					continue;
164 a1d55e81 Phil Davis
				}
165
				if (in_array($i, $_POST['p1entry'])) {
166 eca6f787 Renato Botelho
					$a_phase1_new[] = $a_phase1[$i];
167 a1d55e81 Phil Davis
				}
168 eca6f787 Renato Botelho
			}
169
170
			/* copy $movebtn p1 entry */
171 a1d55e81 Phil Davis
			if ($movebtn < count($a_phase1)) {
172 eca6f787 Renato Botelho
				$a_phase1_new[] = $a_phase1[$movebtn];
173 a1d55e81 Phil Davis
			}
174 eca6f787 Renato Botelho
175
			/* copy all p1 entries > $movebtn and not selected */
176
			for ($i = $movebtn+1; $i < count($a_phase1); $i++) {
177 a1d55e81 Phil Davis
				if (!in_array($i, $_POST['p1entry'])) {
178 eca6f787 Renato Botelho
					$a_phase1_new[] = $a_phase1[$i];
179 a1d55e81 Phil Davis
				}
180 eca6f787 Renato Botelho
			}
181 a1d55e81 Phil Davis
			if (count($a_phase1_new) > 0) {
182 eca6f787 Renato Botelho
				$a_phase1 = $a_phase1_new;
183 a1d55e81 Phil Davis
			}
184 eca6f787 Renato Botelho
185 495c7f0c Renato Botelho
		} else if (isset($movebtnp2) && is_array($_POST['p2entry']) && count($_POST['p2entry'])) {
186
			/* move selected p2 entries before this */
187 761882a1 Renato Botelho
			$a_phase2_new = array();
188
189 495c7f0c Renato Botelho
			/* copy all p2 entries < $movebtnp2 and not selected */
190
			for ($i = 0; $i < $movebtnp2; $i++) {
191 a1d55e81 Phil Davis
				if (!in_array($i, $_POST['p2entry'])) {
192 761882a1 Renato Botelho
					$a_phase2_new[] = $a_phase2[$i];
193 a1d55e81 Phil Davis
				}
194 761882a1 Renato Botelho
			}
195
196
			/* copy all selected p2 entries */
197
			for ($i = 0; $i < count($a_phase2); $i++) {
198 a1d55e81 Phil Davis
				if ($i == $movebtnp2) {
199 761882a1 Renato Botelho
					continue;
200 a1d55e81 Phil Davis
				}
201
				if (in_array($i, $_POST['p2entry'])) {
202 761882a1 Renato Botelho
					$a_phase2_new[] = $a_phase2[$i];
203 a1d55e81 Phil Davis
				}
204 761882a1 Renato Botelho
			}
205
206 495c7f0c Renato Botelho
			/* copy $movebtnp2 p2 entry */
207 a1d55e81 Phil Davis
			if ($movebtnp2 < count($a_phase2)) {
208 495c7f0c Renato Botelho
				$a_phase2_new[] = $a_phase2[$movebtnp2];
209 a1d55e81 Phil Davis
			}
210 761882a1 Renato Botelho
211 495c7f0c Renato Botelho
			/* copy all p2 entries > $movebtnp2 and not selected */
212
			for ($i = $movebtnp2+1; $i < count($a_phase2); $i++) {
213 a1d55e81 Phil Davis
				if (!in_array($i, $_POST['p2entry'])) {
214 761882a1 Renato Botelho
					$a_phase2_new[] = $a_phase2[$i];
215 a1d55e81 Phil Davis
				}
216 761882a1 Renato Botelho
			}
217 a1d55e81 Phil Davis
			if (count($a_phase2_new) > 0) {
218 761882a1 Renato Botelho
				$a_phase2 = $a_phase2_new;
219 a1d55e81 Phil Davis
			}
220 761882a1 Renato Botelho
221 495c7f0c Renato Botelho
		} else if (isset($togglebtn)) {
222 a1d55e81 Phil Davis
			if (isset($a_phase1[$togglebtn]['disabled'])) {
223 495c7f0c Renato Botelho
				unset($a_phase1[$togglebtn]['disabled']);
224 a1d55e81 Phil Davis
			} else {
225 495c7f0c Renato Botelho
				$a_phase1[$togglebtn]['disabled'] = true;
226 a1d55e81 Phil Davis
			}
227 495c7f0c Renato Botelho
		} else if (isset($togglebtnp2)) {
228 a1d55e81 Phil Davis
			if (isset($a_phase2[$togglebtnp2]['disabled'])) {
229 495c7f0c Renato Botelho
				unset($a_phase2[$togglebtnp2]['disabled']);
230 a1d55e81 Phil Davis
			} else {
231 495c7f0c Renato Botelho
				$a_phase2[$togglebtnp2]['disabled'] = true;
232 a1d55e81 Phil Davis
			}
233 495c7f0c Renato Botelho
		} else if (isset($delbtn)) {
234
			/* remove static route if interface is not WAN */
235 a1d55e81 Phil Davis
			if ($a_phase1[$delbtn]['interface'] <> "wan") {
236 495c7f0c Renato Botelho
				mwexec("/sbin/route delete -host {$a_phase1[$delbtn]['remote-gateway']}");
237 a1d55e81 Phil Davis
			}
238 eca6f787 Renato Botelho
239 495c7f0c Renato Botelho
			/* remove all phase2 entries that match the ikeid */
240
			$ikeid = $a_phase1[$delbtn]['ikeid'];
241 a1d55e81 Phil Davis
			foreach ($a_phase2 as $p2index => $ph2tmp) {
242 495c7f0c Renato Botelho
				if ($ph2tmp['ikeid'] == $ikeid) {
243
					unset($a_phase2[$p2index]);
244
				}
245 a1d55e81 Phil Davis
			}
246 495c7f0c Renato Botelho
			unset($a_phase1[$delbtn]);
247 761882a1 Renato Botelho
248 495c7f0c Renato Botelho
		} else if (isset($delbtnp2)) {
249
			unset($a_phase2[$delbtnp2]);
250 761882a1 Renato Botelho
251 a1d55e81 Phil Davis
		} else {
252 495c7f0c Renato Botelho
			$save = 0;
253 a1d55e81 Phil Davis
		}
254 495c7f0c Renato Botelho
255
		if ($save === 1) {
256 a1d55e81 Phil Davis
			if (write_config()) {
257 495c7f0c Renato Botelho
				mark_subsystem_dirty('ipsec');
258 a1d55e81 Phil Davis
			}
259 495c7f0c Renato Botelho
		}
260
	}
261 5b237745 Scott Ullrich
}
262 4df96eff Scott Ullrich
263 6c07db48 Phil Davis
$pgtitle = array(gettext("VPN"), gettext("IPsec"));
264 b32dd0a6 jim-p
$shortcut_section = "ipsec";
265 6deedfde jim-p
266 4df96eff Scott Ullrich
include("head.inc");
267
268 761e41a1 Stephen Beaver
$tab_array = array();
269
$tab_array[] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
270
$tab_array[] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
271
$tab_array[] = array(gettext("Pre-Shared Keys"), false, "vpn_ipsec_keys.php");
272
$tab_array[] = array(gettext("Advanced Settings"), false, "vpn_ipsec_settings.php");
273
display_top_tabs($tab_array);
274 53d4b84d Scott Ullrich
?>
275 422f27c0 Scott Ullrich
276 eca6f787 Renato Botelho
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
277 5ddd7e7b Sander van Leeuwen
278 323d040b Scott Ullrich
<?php
279 a1d55e81 Phil Davis
	if ($savemsg) {
280 7d7b35b9 Stephen Beaver
		print_info_box($savemsg, 'success');
281 a1d55e81 Phil Davis
	}
282 7d7b35b9 Stephen Beaver
283 a1d55e81 Phil Davis
	if ($pconfig['enable'] && is_subsystem_dirty('ipsec')) {
284 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."));
285 a1d55e81 Phil Davis
	}
286 574a2b47 Scott Ullrich
?>
287 5ddd7e7b Sander van Leeuwen
288 1b6b7fc4 Stephen Beaver
<form name="mainform" method="post">
289 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 />
290
	<input name="submit" type="submit" class="btn btn-sm btn-primary" value="<?=gettext("Save"); ?>" /><br /><br />
291
292
	<div class="panel panel-default">
293
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('IPSec tunnels')?></h2></div>
294
		<div class="panel-body table-responsive">
295
			<table class="table table-striped table-hover">
296
				<thead>
297
					<tr>
298
						<th>&nbsp;</th>
299
						<th>&nbsp;</th>
300 1b6b7fc4 Stephen Beaver
						<th><?=gettext("IKE")?></th>
301
						<th><?=gettext("Remote Gateway")?></th>
302
						<th><?=gettext("Mode")?></th>
303
						<th><?=gettext("P1 Protocol")?></th>
304
						<th><?=gettext("P1 Transforms")?></th>
305
						<th><?=gettext("P1 Description")?></th>
306
						<th><?=gettext("Actions")?></th>
307 30fdf440 Stephen Beaver
					</tr>
308
				</thead>
309 1d770fc7 Stephen Beaver
				<tbody class="p1-entries">
310 5ddd7e7b Sander van Leeuwen
<?php $i = 0; foreach ($a_phase1 as $ph1ent): ?>
311 e0fb12c1 Renato Botelho
<?php
312 5ddd7e7b Sander van Leeuwen
	$iconfn = "pass";
313
314
	$entryStatus = (isset($ph1ent['disabled']) ? 'disabled' : 'enabled');
315
316
	if ($entryStatus == 'disabled') {
317
		$iconfn .= "_d";
318
	}
319 e0fb12c1 Renato Botelho
?>
320 1b6b7fc4 Stephen Beaver
					<tr id="fr<?=$i?>" onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>" ondblclick="document.location='vpn_ipsec_phase1.php?p1index=<?=$i?>'" class="<?= $entryStatus ?>">
321 30fdf440 Stephen Beaver
						<td>
322
							<input type="checkbox" id="frc<?=$i?>" name="p1entry[]" value="<?=$i?>" onclick="fr_bgcolor('<?=$i?>')" />
323
						</td>
324
						<td>
325
							<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>
326
						</td>
327
						<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>">
328 e0fb12c1 Renato Botelho
<?php
329 5ddd7e7b Sander van Leeuwen
			if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == "ikev1")
330
				echo "V1";
331
			else
332
				echo "V2";
333 e0fb12c1 Renato Botelho
?>
334 30fdf440 Stephen Beaver
						</td>
335 1b6b7fc4 Stephen Beaver
						<td>
336 e0fb12c1 Renato Botelho
<?php
337 5ddd7e7b Sander van Leeuwen
			if ($ph1ent['interface']) {
338
				$iflabels = get_configured_interface_with_descr();
339
340
				$carplist = get_configured_carp_interface_list();
341
				foreach ($carplist as $cif => $carpip)
342
					$iflabels[$cif] = $carpip." (".get_vip_descr($carpip).")";
343
344
				$aliaslist = get_configured_ip_aliases_list();
345
				foreach ($aliaslist as $aliasip => $aliasif)
346
					$iflabels[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
347
348
				$grouplist = return_gateway_groups_array();
349
				foreach ($grouplist as $name => $group) {
350
					if($group[0]['vip'] != "")
351
						$vipif = $group[0]['vip'];
352
					else
353
						$vipif = $group[0]['int'];
354
					$iflabels[$name] = "GW Group {$name}";
355
				}
356
				$if = htmlspecialchars($iflabels[$ph1ent['interface']]);
357
			}
358
			else
359
				$if = "WAN";
360
361
			if (!isset($ph1ent['mobile']))
362
				echo $if."<br />".$ph1ent['remote-gateway'];
363
			else
364
				echo $if."<br /><strong>" . gettext("Mobile Client") . "</strong>";
365 e0fb12c1 Renato Botelho
?>
366 135ad35b Sander van Leeuwen
				</td>
367
				<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>">
368
					<?=$spans?>
369
					<?php
370
					if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == "ikev1")
371
						echo "{$ph1ent['mode']}";
372
					?>
373
					<?=$spane?>
374
				</td>
375
				<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>">
376
					<?=$p1_ealgos[$ph1ent['encryption-algorithm']['name']]['name']?>
377 e0fb12c1 Renato Botelho
<?php
378 5ddd7e7b Sander van Leeuwen
			if ($ph1ent['encryption-algorithm']['keylen']) {
379
				if ($ph1ent['encryption-algorithm']['keylen']=="auto")
380
					echo " (" . gettext("auto") . ")";
381
				else
382
					echo " ({$ph1ent['encryption-algorithm']['keylen']} " . gettext("bits") . ")";
383
			}
384 e0fb12c1 Renato Botelho
?>
385 30fdf440 Stephen Beaver
						</td>
386
						<td>
387
							<?=$p1_halgos[$ph1ent['hash-algorithm']]?>
388
						</td>
389
						<td>
390
							<?=htmlspecialchars($ph1ent['descr'])?>
391
						</td>
392 1b6b7fc4 Stephen Beaver
						<td style="cursor: pointer;">
393
							<a	class="fa fa-anchor" id="Xmove_<?=$i?>" title="<?=gettext("Move checked entries to here")?>"></a>
394
							<button style="display: none;" class="btn btn-default btn-xs" type="submit" id="move_<?=$i?>" name="move_<?=$i?>" value="move_<?=$i?>"><?=gettext("Move checked entries to here")?></button>
395
							<a class="fa fa-pencil" href="vpn_ipsec_phase1.php?p1index=<?=$i?>" title="<?=gettext("Edit phase1 entry"); ?>"></a>
396
<?php if (!isset($ph1ent['mobile'])): ?>
397
							<a class="fa fa-clone" href="vpn_ipsec_phase1.php?dup=<?=$i?>" title="<?=gettext("Copy phase1 entry"); ?>"></a>
398
<?php endif; ?>
399
							<a	class="fa fa-trash" id="Xdel_<?=$i?>" title="<?=gettext('Delete phase1 entry'); ?>"></a>
400
							<button style="display: none;" class="btn btn-xs btn-warning" type="submit" id="del_<?=$i?>" name="del_<?=$i?>" value="del_<?=$i?>" title="<?=gettext('Delete phase1 entry'); ?>">delete</button>
401
402 30fdf440 Stephen Beaver
						</td>
403
					</tr>
404
					<tr class="<?= $entryStatus ?>">
405
						<td colspan="2"></td>
406
						<td colspan="7" class="contains-table">
407 e0fb12c1 Renato Botelho
<?php
408 5ddd7e7b Sander van Leeuwen
			if (isset($_POST["tdph2-{$i}-visible"]))
409
				$tdph2_visible = htmlspecialchars($_POST["tdph2-{$i}-visible"]);
410
			else
411
				$tdph2_visible = 0;
412 e0fb12c1 Renato Botelho
?>
413 135ad35b Sander van Leeuwen
					<input type="hidden" name="tdph2-<?=$i?>-visible" id="tdph2-<?=$i?>-visible" value="<?=$tdph2_visible?>" />
414
					<div id="shph2but-<?=$i?>" <?=($tdph2_visible == '1' ? 'style="display:none"' : '')?>>
415 91ebc808 Renato Botelho
<?php
416 5ddd7e7b Sander van Leeuwen
				$phase2count=0;
417 7d7b35b9 Stephen Beaver
418 5ddd7e7b Sander van Leeuwen
				foreach ($a_phase2 as $ph2ent) {
419
					if ($ph2ent['ikeid'] != $ph1ent['ikeid'])
420
						continue;
421
					$phase2count++;
422
				}
423
				$fr_prefix = "frp2{$i}";
424
				$fr_header = $fr_prefix . "header";
425 91ebc808 Renato Botelho
?>
426 135ad35b Sander van Leeuwen
						<input type="button" onclick="show_phase2('tdph2-<?=$i?>','shph2but-<?=$i?>')" value="+" /> - <?php printf(gettext("Show %s Phase-2 entries"), $phase2count); ?>
427
					</div>
428
					<div id="tdph2-<?=$i?>" <?=($tdph2_visible != '1' ? 'style="display:none"' : '')?>>
429
						<table class="table table-striped table-hover">
430
							<thead>
431
								<tr>
432
									<th>&nbsp;</th>
433
									<th>&nbsp;</th>
434
									<th><?=gettext("Mode"); ?></th>
435
									<th><?=gettext("Local Subnet"); ?></th>
436
									<th><?=gettext("Remote Subnet"); ?></th>
437
									<th><?=gettext("P2 Protocol"); ?></th>
438
									<th><?=gettext("P2 Transforms"); ?></th>
439
									<th><?=gettext("P2 Auth Methods"); ?></th>
440 1b6b7fc4 Stephen Beaver
									<th><?=gettext("P2 actions")?></th>
441 135ad35b Sander van Leeuwen
								</tr>
442
							</thead>
443 1d770fc7 Stephen Beaver
							<tbody class="p2-entries">
444 5ddd7e7b Sander van Leeuwen
<?php $j = 0; foreach ($a_phase2 as $ph2index => $ph2ent): ?>
445 e0fb12c1 Renato Botelho
<?php
446 5ddd7e7b Sander van Leeuwen
						if ($ph2ent['ikeid'] != $ph1ent['ikeid'])
447
							continue;
448
449
						$fr_c = $fr_prefix . "c" . $j;
450
						$fr_d = $fr_prefix . "d" . $j;
451
452
						$iconfn = "pass";
453
						$entryStatus = (isset($ph2ent['disabled']) || isset($ph1ent['disabled']) ? 'disabled' : 'enabled');
454
455
						if ($entryStatus == 'disabled')
456
							$iconfn .= "_d";
457
458 e0fb12c1 Renato Botelho
?>
459 135ad35b Sander van Leeuwen
								<tr id="<?=$fr_prefix . $j?>" ondblclick="document.location='vpn_ipsec_phase2.php?p2index=<?=$ph2ent['uniqid']?>'" class="<?= $entryStatus ?>">
460
									<td>
461
										<input type="checkbox" id="<?=$fr_c?>" name="p2entry[]" value="<?=$ph2index?>" onclick="fr_bgcolor('<?=$j?>', '<?=$fr_prefix?>')" />
462
									</td>
463
									<td>
464
										<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>
465
									</td>
466
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
467
										<?=$ph2ent['mode']?>
468
									</td>
469 5ddd7e7b Sander van Leeuwen
<?php if(($ph2ent['mode'] == "tunnel") or ($ph2ent['mode'] == "tunnel6")): ?>
470 135ad35b Sander van Leeuwen
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
471
										<?=ipsec_idinfo_to_text($ph2ent['localid']); ?>
472
									</td>
473
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
474
										<?=ipsec_idinfo_to_text($ph2ent['remoteid']); ?>
475
									</td>
476 5ddd7e7b Sander van Leeuwen
<?php else: ?>
477 135ad35b Sander van Leeuwen
									<td colspan="2"></td>
478 5ddd7e7b Sander van Leeuwen
<?php endif; ?>
479 135ad35b Sander van Leeuwen
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
480
										<?=$p2_protos[$ph2ent['protocol']]; ?>
481
									</td>
482
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
483 e0fb12c1 Renato Botelho
<?php
484 5ddd7e7b Sander van Leeuwen
								foreach ($ph2ent['encryption-algorithm-option'] as $k => $ph2ea) {
485
									if ($k)
486
										echo ", ";
487
									echo $p2_ealgos[$ph2ea['name']]['name'];
488
									if ($ph2ea['keylen']) {
489
										if ($ph2ea['keylen']=="auto")
490
											echo " (" . gettext("auto") . ")";
491
										else
492
											echo " ({$ph2ea['keylen']} " . gettext("bits") . ")";
493 761882a1 Renato Botelho
									}
494 5ddd7e7b Sander van Leeuwen
								}
495 e0fb12c1 Renato Botelho
?>
496 135ad35b Sander van Leeuwen
									</td>
497
									<td id="<?=$fr_d?>" onclick="fr_toggle('<?=$j?>', '<?=$fr_prefix?>')">
498 e0fb12c1 Renato Botelho
<?php
499 5ddd7e7b Sander van Leeuwen
								if (!empty($ph2ent['hash-algorithm-option']) && is_array($ph2ent['hash-algorithm-option'])) {
500
									foreach ($ph2ent['hash-algorithm-option'] as $k => $ph2ha) {
501
										if ($k)
502
											echo ", ";
503
										echo $p2_halgos[$ph2ha];
504
									}
505
								}
506 e0fb12c1 Renato Botelho
?>
507 135ad35b Sander van Leeuwen
									</td>
508 1b6b7fc4 Stephen Beaver
									<td style="cursor: pointer;">
509
									<!--	<button class="btn btn-xs btn-default" type="submit" name="movep2_<?=$j?>" value="movep2_<?=$j?>"><?=gettext("Move checked P2s here")?></button> -->
510
										<a class="fa fa-pencil" href="vpn_ipsec_phase2.php?p2index=<?=$ph2ent['uniqid']?>" title="<?=gettext("Edit phase2 entry"); ?>"></a>
511
										<a class="fa fa-clone" href="vpn_ipsec_phase2.php?dup=<?=$ph2ent['uniqid']?>" title="<?=gettext("Add a new Phase 2 based on this one"); ?>"></a>
512
										<a	class="fa fa-trash" id="Xdelp2_<?=$i?>" title="<?=gettext('Delete phase2 entry'); ?>"></a>
513
										<button style="display: none;" class="btn btn-xs btn-warning" type="submit" id="delp2_<?=$ph2index?>" name="delp2_<?=$ph2index?>" value="delp2_<?=$ph2index?>" title="<?=gettext('delete phase2 entry'); ?>">delete</button>
514 135ad35b Sander van Leeuwen
									</td>
515
								</tr>
516 5ddd7e7b Sander van Leeuwen
<?php $j++; endforeach; ?>
517 135ad35b Sander van Leeuwen
								<tr>
518
									<td colspan="8"></td>
519
									<td>
520 761882a1 Renato Botelho
<?php
521 1b6b7fc4 Stephen Beaver
/*
522 5ddd7e7b Sander van Leeuwen
							if ($j == 0):
523 761882a1 Renato Botelho
?>
524 d62df86b Jared Dillard
										<i class="icon icon-arrow-down" title="<?=gettext("move selected phase2 entries to end")?>" alt="move"></i>
525 761882a1 Renato Botelho
<?php
526 5ddd7e7b Sander van Leeuwen
							else:
527 761882a1 Renato Botelho
?>
528 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>
529 761882a1 Renato Botelho
<?php
530 5ddd7e7b Sander van Leeuwen
							endif;
531 1b6b7fc4 Stephen Beaver
*/
532 761882a1 Renato Botelho
?>
533 1b6b7fc4 Stephen Beaver
										<a class="btn btn-xs btn-success" href="vpn_ipsec_phase2.php?ikeid=<?=$ph1ent['ikeid']?><?php if (isset($ph1ent['mobile'])) echo "&amp;mobile=true"?>"><?=gettext("Add phase2 entry"); ?>
534 135ad35b Sander van Leeuwen
										</a>
535 761882a1 Renato Botelho
<?php
536 1b6b7fc4 Stephen Beaver
/*
537 5ddd7e7b Sander van Leeuwen
							if ($j == 0):
538 761882a1 Renato Botelho
?>
539 d62df86b Jared Dillard
										<i class="icon icon-remove-sign" title="<?=gettext("delete selected phase2 entries")?>" alt="delete"></i>
540 761882a1 Renato Botelho
<?php
541 5ddd7e7b Sander van Leeuwen
							else:
542 761882a1 Renato Botelho
?>
543 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>
544 761882a1 Renato Botelho
<?php
545 5ddd7e7b Sander van Leeuwen
							endif;
546 1b6b7fc4 Stephen Beaver
*/
547 761882a1 Renato Botelho
?>
548 30fdf440 Stephen Beaver
											</td>
549
										</tr>
550
									</tbody>
551
								</table>
552
							</div>
553
						</td>
554
					</tr>
555 761882a1 Renato Botelho
<?php
556 135ad35b Sander van Leeuwen
					$i++;
557 30fdf440 Stephen Beaver
				endforeach;	 // $a_phase1 as $ph1ent
558 761882a1 Renato Botelho
?>
559 30fdf440 Stephen Beaver
			</tbody>
560
		</table>
561
	</div>
562 135ad35b Sander van Leeuwen
</div>
563 5ddd7e7b Sander van Leeuwen
564 135ad35b Sander van Leeuwen
<nav class="action-buttons">
565 1b6b7fc4 Stephen Beaver
<?php
566
/*
567
	if ($i !== 0): ?>
568 135ad35b Sander van Leeuwen
	<input type="submit" name="move_<?=$i?>" class="btn btn-default" value="<?=gettext("move selected phase1 entries to end")?>" />
569 1b6b7fc4 Stephen Beaver
<?php endif;
570
*/
571
?>
572
	<a href="vpn_ipsec_phase1.php" class="btn btn-success"><?=gettext("Add new P1")?></a>
573 135ad35b Sander van Leeuwen
<?php if ($i !== 0): ?>
574 1b6b7fc4 Stephen Beaver
	<input type="submit" name="del" class="btn btn-danger" value="<?=gettext("Delete selected P1s")?>" onclick="return confirm('<?=gettext("Do you really want to delete the selected phase1 entries?")?>')" />
575 135ad35b Sander van Leeuwen
<?php endif; ?>
576
</nav>
577 5b237745 Scott Ullrich
</form>
578 5ddd7e7b Sander van Leeuwen
579
<div class="alert alert-info">
580
	<strong><?=gettext("Note:")?></strong><br />
581
	<?=gettext("You can check your IPsec status at"); ?> <a href="diag_ipsec.php"><?=gettext("Status:IPsec"); ?></a>.<br />
582
	<?=gettext("IPsec Debug Mode can be enabled at"); ?> <a href="vpn_ipsec_settings.php"><?=gettext("VPN:IPsec:Advanced Settings"); ?></a>.<br />
583
	<?=gettext("IPsec can be set to prefer older SAs at"); ?> <a href="vpn_ipsec_settings.php"><?=gettext("VPN:IPsec:Advanced Settings"); ?></a>.
584
</div>
585
586 0a95b653 Scott Ullrich
<script type="text/javascript">
587 391453a1 Colin Fleming
//<![CDATA[
588 0a95b653 Scott Ullrich
function show_phase2(id, buttonid) {
589
	document.getElementById(buttonid).innerHTML='';
590 91ebc808 Renato Botelho
	document.getElementById(id).style.display = "block";
591
	var visible = id + '-visible';
592
	document.getElementById(visible).value = "1";
593 0a95b653 Scott Ullrich
}
594 1d770fc7 Stephen Beaver
595
events.push(function() {
596
	// Make rules sortable
597
	$('table tbody.p2-entries').sortable({
598
		cursor: 'grabbing',
599
		update: function(event, ui) {
600
			$('#order-store').removeAttr('disabled');
601
		}
602
	});
603 1b6b7fc4 Stephen Beaver
604
	$('[id^=Xmove_]').click(function (event) {
605
		$('#' + event.target.id.slice(1)).click();
606
	});
607
608
	$('[id^=Xdel_]').click(function (event) {
609
		if(confirm("<?=gettext('Are you sure you wish to delete this P1 entry?')?>")) {
610
			$('#' + event.target.id.slice(1)).click();
611
		}
612
	});
613
614
	$('[id^=Xdelp2_]').click(function (event) {
615
		if(confirm("<?=gettext('Are you sure you wish to delete this P2 entry?')?>")) {
616
			$('#' + event.target.id.slice(1)).click();
617
		}
618
	});
619 1d770fc7 Stephen Beaver
});
620 391453a1 Colin Fleming
//]]>
621 8a251ec2 Chris Buechler
</script>
622 1b6b7fc4 Stephen Beaver
623
<?php
624
include("foot.inc");