Project

General

Profile

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