. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ##|+PRIV ##|*IDENT=page-vpn-ipsec-editphase2 ##|*NAME=VPN: IPsec: Edit Phase 2 page ##|*DESCR=Allow access to the 'VPN: IPsec: Edit Phase 2' page. ##|*MATCH=vpn_ipsec_phase2.php* ##|-PRIV require("functions.inc"); require("guiconfig.inc"); require_once("ipsec.inc"); require_once("vpn.inc"); if (!is_array($config['ipsec']['client'])) $config['ipsec']['client'] = array(); $a_client = &$config['ipsec']['client']; if (!is_array($config['ipsec']['phase2'])) $config['ipsec']['phase2'] = array(); $a_phase2 = &$config['ipsec']['phase2']; $p2index = $_GET['p2index']; if (isset($_POST['p2index'])) $p2index = $_POST['p2index']; if (isset($_GET['dup'])) $p2index = $_GET['dup']; if (isset($p2index) && $a_phase2[$p2index]) { $pconfig['ikeid'] = $a_phase2[$p2index]['ikeid']; $pconfig['disabled'] = isset($a_phase2[$p2index]['disabled']); $pconfig['mode'] = $a_phase2[$p2index]['mode']; $pconfig['descr'] = $a_phase2[$p2index]['descr']; $old_ph2ent = $a_phase2[$p2index]; idinfo_to_pconfig("local",$a_phase2[$p2index]['localid'],$pconfig); idinfo_to_pconfig("remote",$a_phase2[$p2index]['remoteid'],$pconfig); $pconfig['proto'] = $a_phase2[$p2index]['protocol']; ealgos_to_pconfig($a_phase2[$p2index]['encryption-algorithm-option'],$pconfig); $pconfig['halgos'] = $a_phase2[$p2index]['hash-algorithm-option']; $pconfig['pfsgroup'] = $a_phase2[$p2index]['pfsgroup']; $pconfig['lifetime'] = $a_phase2[$p2index]['lifetime']; $pconfig['pinghost'] = $a_phase2[$p2index]['pinghost']; if (isset($a_phase2[$p2index]['mobile'])) $pconfig['mobile'] = true; } else { $pconfig['ikeid'] = $_GET['ikeid']; /* defaults */ $pconfig['localid_type'] = "lan"; $pconfig['remoteid_type'] = "network"; $pconfig['proto'] = "esp"; $pconfig['ealgos'] = explode(",", "3des,blowfish,cast128,aes"); $pconfig['halgos'] = explode(",", "hmac_sha1,hmac_md5"); $pconfig['pfsgroup'] = "0"; $pconfig['lifetime'] = "3600"; /* mobile client */ if($_GET['mobile']) $pconfig['mobile']=true; } if (isset($_GET['dup'])) unset($p2index); if ($_POST) { unset($input_errors); $pconfig = $_POST; if (!isset( $_POST['ikeid'])) $input_errors[] = "A valid ikeid must be specified."; /* input validation */ $reqdfields = explode(" ", "localid_type halgos"); $reqdfieldsn = explode(",", "Local network type,P2 Hash Algorithms"); if (!isset($pconfig['mobile'])){ $reqdfields[] = "remoteid_type"; $reqdfieldsn[] = "Remote network type"; } do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); if($pconfig['mode'] == "tunnel") { switch ($pconfig['localid_type']) { case "network": if (($pconfig['localid_netbits'] != 0 && !$pconfig['localid_netbits']) || !is_numeric($pconfig['localid_netbits'])) $input_errors[] = "A valid local network bit count must be specified."; case "address": if (!$pconfig['localid_address'] || !is_ipaddr($pconfig['localid_address'])) $input_errors[] = "A valid local network IP address must be specified."; break; } switch ($pconfig['remoteid_type']) { case "network": if (($pconfig['remoteid_netbits'] != 0 && !$pconfig['remoteid_netbits']) || !is_numeric($pconfig['remoteid_netbits'])) $input_errors[] = "A valid remote network bit count must be specified."; case "address": if (!$pconfig['remoteid_address'] || !is_ipaddr($pconfig['remoteid_address'])) $input_errors[] = "A valid remote network IP address must be specified."; break; } } /* TODO : Validate enabled phase2's are not duplicates */ $ealgos = pconfig_to_ealgos($pconfig); if (!count($ealgos)) { $input_errors[] = "At least one encryption algorithm must be selected."; } if (($_POST['lifetime'] && !is_numeric($_POST['lifetime']))) { $input_errors[] = "The P2 lifetime must be an integer."; } if (!$input_errors) { $ph2ent['ikeid'] = $pconfig['ikeid']; $ph2ent['mode'] = $pconfig['mode']; $ph2ent['disabled'] = $pconfig['disabled'] ? true : false; if($ph2ent['mode'] == "tunnel") { $ph2ent['localid'] = pconfig_to_idinfo("local",$pconfig); $ph2ent['remoteid'] = pconfig_to_idinfo("remote",$pconfig); } $ph2ent['protocol'] = $pconfig['proto']; $ph2ent['encryption-algorithm-option'] = $ealgos; $ph2ent['hash-algorithm-option'] = $pconfig['halgos']; $ph2ent['pfsgroup'] = $pconfig['pfsgroup']; $ph2ent['lifetime'] = $pconfig['lifetime']; $ph2ent['pinghost'] = $pconfig['pinghost']; $ph2ent['descr'] = $pconfig['descr']; if (isset($pconfig['mobile'])) $ph2ent['mobile'] = true; if (isset($p2index) && $a_phase2[$p2index]) $a_phase2[$p2index] = $ph2ent; else $a_phase2[] = $ph2ent; /* now we need to find all phase2 entries for this host */ if(is_array($ph2ent)) { ipsec_lookup_phase1($ph2ent, $ph1ent); $old_ph1ent = $ph1ent; reload_tunnel_spd_policy ($ph1ent, $ph2ent, $old_ph1ent, $old_ph2ent); } write_config(); mark_subsystem_dirty('ipsec'); header("Location: vpn_ipsec.php"); exit; } } if ($pconfig['mobile']) $pgtitle = array("VPN","IPsec","Edit Phase 2", "Mobile Client"); else $pgtitle = array("VPN","IPsec","Edit Phase 2"); $statusurl = "diag_ipsec.php"; $logurl = "diag_logs_ipsec.php"; include("head.inc"); ?>