Project

General

Profile

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