Project

General

Profile

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