. 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-editphase1 ##|*NAME=VPN: IPsec: Edit Phase 1 page ##|*DESCR=Allow access to the 'VPN: IPsec: Edit Phase 1' page. ##|*MATCH=vpn_ipsec_phase1.php* ##|-PRIV require("functions.inc"); require("guiconfig.inc"); if (!is_array($config['ipsec']['phase1'])) $config['ipsec']['phase1'] = array(); if (!is_array($config['ipsec']['phase2'])) $config['ipsec']['phase2'] = array(); $a_phase1 = &$config['ipsec']['phase1']; $a_phase2 = &$config['ipsec']['phase2']; $p1index = $_GET['p1index']; if (isset($_POST['p1index'])) $p1index = $_POST['p1index']; if (isset($_GET['dup'])) { $p1index = $_GET['dup']; } if (isset($p1index) && $a_phase1[$p1index]) { // don't copy the ikeid on dup if (!isset($_GET['dup'])) $pconfig['ikeid'] = $a_phase1[$p1index]['ikeid']; $old_ph1ent = $a_phase1[$p1index]; $pconfig['disabled'] = isset($a_phase1[$p1index]['disabled']); if ($a_phase1[$p1index]['interface']) $pconfig['interface'] = $a_phase1[$p1index]['interface']; else $pconfig['interface'] = "wan"; list($pconfig['remotenet'],$pconfig['remotebits']) = explode("/", $a_phase1[$p1index]['remote-subnet']); if (isset($a_phase1[$p1index]['mobile'])) $pconfig['mobile'] = 'true'; else $pconfig['remotegw'] = $a_phase1[$p1index]['remote-gateway']; $pconfig['mode'] = $a_phase1[$p1index]['mode']; $pconfig['myid_type'] = $a_phase1[$p1index]['myid_type']; $pconfig['myid_data'] = $a_phase1[$p1index]['myid_data']; $pconfig['peerid_type'] = $a_phase1[$p1index]['peerid_type']; $pconfig['peerid_data'] = $a_phase1[$p1index]['peerid_data']; $pconfig['ealgo'] = $a_phase1[$p1index]['encryption-algorithm']; $pconfig['halgo'] = $a_phase1[$p1index]['hash-algorithm']; $pconfig['dhgroup'] = $a_phase1[$p1index]['dhgroup']; $pconfig['lifetime'] = $a_phase1[$p1index]['lifetime']; $pconfig['authentication_method'] = $a_phase1[$p1index]['authentication_method']; if (($pconfig['authentication_method'] == "pre_shared_key")|| ($pconfig['authentication_method'] == "xauth_psk_server")) { $pconfig['pskey'] = $a_phase1[$p1index]['pre-shared-key']; } else { $pconfig['certref'] = $a_phase1[$p1index]['certref']; } $pconfig['descr'] = $a_phase1[$p1index]['descr']; $pconfig['nat_traversal'] = $a_phase1[$p1index]['nat_traversal']; if ($a_phase1[$p1index]['dpd_delay'] && $a_phase1[$p1index]['dpd_maxfail']) { $pconfig['dpd_enable'] = true; $pconfig['dpd_delay'] = $a_phase1[$p1index]['dpd_delay']; $pconfig['dpd_maxfail'] = $a_phase1[$p1index]['dpd_maxfail']; } } else { /* defaults */ $pconfig['interface'] = "wan"; if($config['interfaces']['lan']) $pconfig['localnet'] = "lan"; $pconfig['mode'] = "aggressive"; $pconfig['myid_type'] = "myaddress"; $pconfig['peerid_type'] = "peeraddress"; $pconfig['authentication_method'] = "pre_shared_key"; $pconfig['ealgo'] = array( name => "3des" ); $pconfig['halgo'] = "sha1"; $pconfig['dhgroup'] = "2"; $pconfig['lifetime'] = "28800"; $pconfig['nat_traversal'] = "on"; $pconfig['dpd_enable'] = true; /* mobile client */ if($_GET['mobile']) $pconfig['mobile']=true; } if (isset($_GET['dup'])) unset($p1index); if ($_POST) { unset($input_errors); $pconfig = $_POST; /* input validation */ $method = $pconfig['authentication_method']; if (($method == "pre_shared_key")||($method == "xauth_psk_server")) { $reqdfields = explode(" ", "pskey"); $reqdfieldsn = explode(",", "Pre-Shared Key"); } else { $reqdfields = explode(" ", "certref"); $reqdfieldsn = explode(",", "My Certificate"); } if (!$pconfig['mobile']) { $reqdfields[] = "remotegw"; $reqdfieldsn[] = "Remote gateway"; } do_input_validation($pconfig, $reqdfields, $reqdfieldsn, &$input_errors); if (($pconfig['lifetime'] && !is_numeric($pconfig['lifetime']))) $input_errors[] = "The P1 lifetime must be an integer."; if (($pconfig['remotegw'] && !is_ipaddr($pconfig['remotegw']) && !is_domain($pconfig['remotegw']))) $input_errors[] = "A valid remote gateway address or host name must be specified."; if (($pconfig['remotegw'] && is_ipaddr($pconfig['remotegw']) && !isset($pconfig['disabled']) )) { $t = 0; foreach ($a_phase1 as $ph1tmp) { if ($p1index <> $t) { $tremotegw = $pconfig['remotegw']; if (($ph1tmp['remote-gateway'] == $tremotegw) && !isset($ph1tmp['disabled'])) { $input_errors[] = "The remote gateway \"$tremotegw\" is already used by phase1 \"${ph1tmp['descr']}\"."; } } $t++; } } /* My identity */ if ($pconfig['myid_type'] == "myaddress") $pconfig['myid_data'] = ""; if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "") $input_errors[] = gettext("Please enter an address for 'My Identifier'"); if ($pconfig['myid_type'] == "keyid tag" and $pconfig['myid_data'] == "") $input_errors[] = gettext("Please enter a keyid tag for 'My Identifier'"); if ($pconfig['myid_type'] == "fqdn" and $pconfig['myid_data'] == "") $input_errors[] = gettext("Please enter a fully qualified domain name for 'My Identifier'"); if ($pconfig['myid_type'] == "user_fqdn" and $pconfig['myid_data'] == "") $input_errors[] = gettext("Please enter a user and fully qualified domain name for 'My Identifier'"); if ($pconfig['myid_type'] == "dyn_dns" and $pconfig['myid_data'] == "") $input_errors[] = gettext("Please enter a dynamic domain name for 'My Identifier'"); if ((($pconfig['myid_type'] == "address") && !is_ipaddr($pconfig['myid_data']))) $input_errors[] = "A valid IP address for 'My identifier' must be specified."; if ((($pconfig['myid_type'] == "fqdn") && !is_domain($pconfig['myid_data']))) $input_errors[] = "A valid domain name for 'My identifier' must be specified."; if ($pconfig['myid_type'] == "fqdn") if (is_domain($pconfig['myid_data']) == false) $input_errors[] = "A valid FQDN for 'My identifier' must be specified."; if ($pconfig['myid_type'] == "user_fqdn") { $user_fqdn = explode("@",$pconfig['myid_data']); if (is_domain($user_fqdn[1]) == false) $input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified."; } if ($pconfig['myid_type'] == "dyn_dns") if (is_domain($pconfig['myid_data']) == false) $input_errors[] = "A valid Dynamic DNS address for 'My identifier' must be specified."; /* Peer identity */ if ($pconfig['myid_type'] == "peeraddress") $pconfig['peerid_data'] = ""; if ($pconfig['peerid_type'] == "address" and $pconfig['peerid_data'] == "") $input_errors[] = gettext("Please enter an address for 'Peer Identifier'"); if ($pconfig['peerid_type'] == "keyid tag" and $pconfig['peerid_data'] == "") $input_errors[] = gettext("Please enter a keyid tag for 'Peer Identifier'"); if ($pconfig['peerid_type'] == "fqdn" and $pconfig['peerid_data'] == "") $input_errors[] = gettext("Please enter a fully qualified domain name for 'Peer Identifier'"); if ($pconfig['peerid_type'] == "user_fqdn" and $pconfig['peerid_data'] == "") $input_errors[] = gettext("Please enter a user and fully qualified domain name for 'Peer Identifier'"); if ((($pconfig['peerid_type'] == "address") && !is_ipaddr($pconfig['peerid_data']))) $input_errors[] = "A valid IP address for 'Peer identifier' must be specified."; if ((($pconfig['peerid_type'] == "fqdn") && !is_domain($pconfig['peerid_data']))) $input_errors[] = "A valid domain name for 'Peer identifier' must be specified."; if ($pconfig['peerid_type'] == "fqdn") if (is_domain($pconfig['peerid_data']) == false) $input_errors[] = "A valid FQDN for 'Peer identifier' must be specified."; if ($pconfig['peerid_type'] == "user_fqdn") { $user_fqdn = explode("@",$pconfig['peerid_data']); if (is_domain($user_fqdn[1]) == false) $input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'Peer identifier' must be specified."; } if ($pconfig['dpd_enable']) { if (!is_numeric($pconfig['dpd_delay'])) $input_errors[] = "A numeric value must be specified for DPD delay."; if (!is_numeric($pconfig['dpd_maxfail'])) $input_errors[] = "A numeric value must be specified for DPD retries."; } /* build our encryption algorithms array */ $pconfig['ealgo'] = array(); $pconfig['ealgo']['name'] = $_POST['ealgo']; if($pconfig['ealgo_keylen']) $pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen']; if (!$input_errors) { $ph1ent['ikeid'] = $pconfig['ikeid']; $ph1ent['disabled'] = $pconfig['disabled'] ? true : false; $ph1ent['interface'] = $pconfig['interface']; /* if the remote gateway changed and the interface is not WAN then remove route */ /* the vpn_ipsec_configure() handles adding the route */ if ($pconfig['interface'] <> "wan") { if($old_ph1ent['remote-gateway'] <> $pconfig['remotegw']) { mwexec("/sbin/route delete -host {$oldph1ent['remote-gateway']}"); } } if ($pconfig['mobile']) $ph1ent['mobile'] = true; else $ph1ent['remote-gateway'] = $pconfig['remotegw']; $ph1ent['mode'] = $pconfig['mode']; $ph1ent['myid_type'] = $pconfig['myid_type']; $ph1ent['myid_data'] = $pconfig['myid_data']; $ph1ent['peerid_type'] = $pconfig['peerid_type']; $ph1ent['peerid_data'] = $pconfig['peerid_data']; $ph1ent['encryption-algorithm'] = $pconfig['ealgo']; $ph1ent['hash-algorithm'] = $pconfig['halgo']; $ph1ent['dhgroup'] = $pconfig['dhgroup']; $ph1ent['lifetime'] = $pconfig['lifetime']; $ph1ent['pre-shared-key'] = $pconfig['pskey']; $ph1ent['private-key'] = base64_encode($pconfig['privatekey']); $ph1ent['certref'] = $pconfig['certref']; $ph1ent['authentication_method'] = $pconfig['authentication_method']; $ph1ent['descr'] = $pconfig['descr']; $ph1ent['nat_traversal'] = $pconfig['nat_traversal']; if (isset($pconfig['dpd_enable'])) { $ph1ent['dpd_delay'] = $pconfig['dpd_delay']; $ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail']; } /* generate unique phase1 ikeid */ if ($ph1ent['ikeid'] == 0) $ph1ent['ikeid'] = ipsec_ikeid_next(); if (isset($p1index) && $a_phase1[$p1index]) $a_phase1[$p1index] = $ph1ent; else $a_phase1[] = $ph1ent; /* now we need to find all phase2 entries for this host */ if (is_array($a_phase2) && (count($a_phase2))) { foreach ($a_phase2 as $phase2) { if($phase2['ikeid'] == $ph1ent['ikeid']) { log_error("Reload {$ph1ent['descr']} tunnel(s)"); $old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']); $old_phase2 = $phase2; reload_tunnel_spd_policy ($ph1ent, $phase2, $old_ph1ent, $old_phase2); } } } write_config(); mark_subsystem_dirty('ipsec'); header("Location: vpn_ipsec.php"); exit; } } if ($pconfig['mobile']) $pgtitle = array("VPN","IPsec","Edit Phase 1", "Mobile Client"); else $pgtitle = array("VPN","IPsec","Edit Phase 1"); include("head.inc"); ?>
General information
Disabled > Disable this phase1 entry
Set this option to disable this phase1 without removing it from the list.
Interface
Select the interface for the local endpoint of this phase1 entry.
Remote gateway
Enter the public IP address or host name of the remote gateway
Description
You may enter a description here for your reference (not parsed).
Phase 1 proposal (Authentication)
Negotiation mode
Aggressive is more flexible, but less secure.
My identifier
Peer identifier
Encryption algorithm
Hash algorithm
Must match the setting chosen on the remote side.
DH key group
1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit
Must match the setting chosen on the remote side.
Lifetime seconds
Authentication method
Must match the setting chosen on the remote side.
Pre-Shared Key
Input your pre-shared key string.
My Certificate
Select a certificate previously configured in the Certificate Manager.
Advanced Options
NAT Traversal
Set this option to enable the use of NAT-T (i.e. the encapsulation of ESP in UDP packets) if needed, which can help with clients that are behind restrictive firewalls.
Dead Peer Detection onClick="dpdchkbox_change()"> Enable DPD

seconds
Delay between requesting peer acknowledgement.

retries
Number of consecutive failures allowed before disconnect.