Project

General

Profile

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