#!/usr/local/bin/php . 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. */ require("guiconfig.inc"); if (!is_array($config['ipsec']['tunnel'])) { $config['ipsec']['tunnel'] = array(); } $a_ipsec = &$config['ipsec']['tunnel']; $specialsrcdst = explode(" ", "lan"); $id = $_GET['id']; if (isset($_POST['id'])) $id = $_POST['id']; if (isset($id) && $a_ipsec[$id]) { $pconfig['disabled'] = isset($a_ipsec[$id]['disabled']); $pconfig['auto'] = isset($a_ipsec[$id]['auto']); $pconfig['creategif'] = $a_filter[$id]['creategif']; if (!isset($a_ipsec[$id]['local-subnet'])) $pconfig['localnet'] = "lan"; else address_to_pconfig($a_ipsec[$id]['local-subnet'], $pconfig['localnet'], $pconfig['localnetmask'], $none, $none, $none); if ($a_ipsec[$id]['interface']) $pconfig['interface'] = $a_ipsec[$id]['interface']; else $pconfig['interface'] = "wan"; list($pconfig['remotenet'],$pconfig['remotebits']) = explode("/", $a_ipsec[$id]['remote-subnet']); $pconfig['remotegw'] = $a_ipsec[$id]['remote-gateway']; $pconfig['p1mode'] = $a_ipsec[$id]['p1']['mode']; if (isset($a_ipsec[$id]['p1']['myident']['myaddress'])) $pconfig['p1myidentt'] = 'myaddress'; else if (isset($a_ipsec[$id]['p1']['myident']['address'])) { $pconfig['p1myidentt'] = 'address'; $pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['address']; } else if (isset($a_ipsec[$id]['p1']['myident']['fqdn'])) { $pconfig['p1myidentt'] = 'fqdn'; $pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['fqdn']; } else if (isset($a_ipsec[$id]['p1']['myident']['ufqdn'])) { $pconfig['p1myidentt'] = 'user_fqdn'; $pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['ufqdn']; } $pconfig['p1ealgo'] = $a_ipsec[$id]['p1']['encryption-algorithm']; $pconfig['p1halgo'] = $a_ipsec[$id]['p1']['hash-algorithm']; $pconfig['p1dhgroup'] = $a_ipsec[$id]['p1']['dhgroup']; $pconfig['p1lifetime'] = $a_ipsec[$id]['p1']['lifetime']; $pconfig['p1pskey'] = $a_ipsec[$id]['p1']['pre-shared-key']; $pconfig['p2proto'] = $a_ipsec[$id]['p2']['protocol']; $pconfig['p2ealgos'] = $a_ipsec[$id]['p2']['encryption-algorithm-option']; $pconfig['p2halgos'] = $a_ipsec[$id]['p2']['hash-algorithm-option']; $pconfig['p2pfsgroup'] = $a_ipsec[$id]['p2']['pfsgroup']; $pconfig['p2lifetime'] = $a_ipsec[$id]['p2']['lifetime']; $pconfig['descr'] = $a_ipsec[$id]['descr']; } else { /* defaults */ $pconfig['interface'] = "wan"; $pconfig['localnet'] = "lan"; $pconfig['p1mode'] = "aggressive"; $pconfig['p1myidentt'] = "myaddress"; $pconfig['p1ealgo'] = "3des"; $pconfig['p1halgo'] = "sha1"; $pconfig['p1dhgroup'] = "2"; $pconfig['p2proto'] = "esp"; $pconfig['p2ealgos'] = explode(",", "3des,blowfish,cast128,rijndael"); $pconfig['p2halgos'] = explode(",", "hmac_sha1,hmac_md5"); $pconfig['p2pfsgroup'] = "0"; } if ($_POST) { if (is_specialnet($_POST['localnettype'])) { $_POST['localnet'] = $_POST['localnettype']; $_POST['localnetmask'] = 0; } else if ($_POST['localnettype'] == "single") { $_POST['localnetmask'] = 32; } unset($input_errors); $pconfig = $_POST; /* input validation */ $reqdfields = explode(" ", "localnet remotenet remotebits remotegw p1pskey p2ealgos p2halgos"); $reqdfieldsn = explode(",", "Local network,Remote network,Remote network bits,Remote gateway,Pre-Shared Key,P2 Encryption Algorithms,P2 Hash Algorithms"); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); if (!is_specialnet($_POST['localnettype'])) { if (($_POST['localnet'] && !is_ipaddr($_POST['localnet']))) { $input_errors[] = "A valid local network IP address must be specified."; } if (($_POST['localnetmask'] && !is_numeric($_POST['localnetmask']))) { $input_errors[] = "A valid local network bit count must be specified."; } } if (($_POST['p1lifetime'] && !is_numeric($_POST['p1lifetime']))) { $input_errors[] = "The P1 lifetime must be an integer."; } if (($_POST['p2lifetime'] && !is_numeric($_POST['p2lifetime']))) { $input_errors[] = "The P2 lifetime must be an integer."; } if ($_POST['remotebits'] && (!is_numeric($_POST['remotebits']) || ($_POST['remotebits'] <= 0) || ($_POST['remotebits'] > 32))) { $input_errors[] = "The remote network bits are invalid."; } if (($_POST['remotenet'] && !is_ipaddr($_POST['remotenet']))) { $input_errors[] = "A valid remote network address must be specified."; } if (($_POST['remotegw'] && !is_ipaddr($_POST['remotegw']))) { $input_errors[] = "A valid remote gateway address must be specified."; } if ((($_POST['p1myidentt'] == "address") && !is_ipaddr($_POST['p1myident']))) { $input_errors[] = "A valid IP address for 'My identifier' must be specified."; } if ((($_POST['p1myidentt'] == "fqdn") && !is_domain($_POST['p1myident']))) { $input_errors[] = "A valid domain name for 'My identifier' must be specified."; } if ($_POST['p1myidentt'] == "user_fqdn") { $ufqdn = explode("@",$_POST['p1myident']); if (!is_domain($ufqdn[1])) $input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified."; } if ($_POST['p1myidentt'] == "myaddress") $_POST['p1myident'] = ""; if (!$input_errors) { $ipsecent['disabled'] = $_POST['disabled'] ? true : false; $ipsecent['creategif'] = $_POST['creategif'] ? true : false; $ipsecent['auto'] = $_POST['auto'] ? true : false; $ipsecent['interface'] = $pconfig['interface']; pconfig_to_address($ipsecent['local-subnet'], $_POST['localnet'], $_POST['localnetmask']); $ipsecent['remote-subnet'] = $_POST['remotenet'] . "/" . $_POST['remotebits']; $ipsecent['remote-gateway'] = $_POST['remotegw']; $ipsecent['p1']['mode'] = $_POST['p1mode']; $ipsecent['p1']['myident'] = array(); switch ($_POST['p1myidentt']) { case 'myaddress': $ipsecent['p1']['myident']['myaddress'] = true; break; case 'address': $ipsecent['p1']['myident']['address'] = $_POST['p1myident']; break; case 'fqdn': $ipsecent['p1']['myident']['fqdn'] = $_POST['p1myident']; break; case 'user_fqdn': $ipsecent['p1']['myident']['ufqdn'] = $_POST['p1myident']; break; } $ipsecent['p1']['encryption-algorithm'] = $_POST['p1ealgo']; $ipsecent['p1']['hash-algorithm'] = $_POST['p1halgo']; $ipsecent['p1']['dhgroup'] = $_POST['p1dhgroup']; $ipsecent['p1']['lifetime'] = $_POST['p1lifetime']; $ipsecent['p1']['pre-shared-key'] = $_POST['p1pskey']; $ipsecent['p2']['protocol'] = $_POST['p2proto']; $ipsecent['p2']['encryption-algorithm-option'] = $_POST['p2ealgos']; $ipsecent['p2']['hash-algorithm-option'] = $_POST['p2halgos']; $ipsecent['p2']['pfsgroup'] = $_POST['p2pfsgroup']; $ipsecent['p2']['lifetime'] = $_POST['p2lifetime']; $ipsecent['descr'] = $_POST['descr']; if (isset($id) && $a_ipsec[$id]) $a_ipsec[$id] = $ipsecent; else $a_ipsec[] = $ipsecent; write_config(); touch($d_ipsecconfdirty_path); header("Location: vpn_ipsec.php"); exit; } } ?> <?=gentitle("VPN: IPsec: Edit tunnel");?>

VPN: IPsec: Edit tunnel

Mode Tunnel
Disabled > Disable this tunnel
Set this option to disable this tunnel without removing it from the list.
Auto-establish > Automatically establish this tunnel
Set this option to automatically re-establish this tunnel after reboots/reconfigures. If this is not set, the tunnel is established on demand.
Interface
Select the interface for the local endpoint of this tunnel.
Local subnet
Type:  
Address:   /
Remote subnet /
Remote gateway
Enter the public IP address of the remote gateway
Description
You may enter a description here for your reference (not parsed).
Phase 1 proposal (Authentication)
Negotiation mode
Aggressive is faster, but less secure.
My identifier
Encryption algorithm
Must match the setting chosen on the remote side.
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
Pre-Shared Key
ASCII characters only!
Phase 2 proposal (SA/Key Exchange)
Protocol
ESP is encryption, AH is authentication only
Encryption algorithms $algoname): ?> >

Hint: use 3DES for best compatibility or if you have a hardware crypto accelerator card. Blowfish is usually the fastest in software encryption.
Hash algorithms $algoname): ?> >
PFS key group
1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit
Lifetime seconds
Misc
Multi-Tunnel routing "> Turn on multi-subnet routing.
If you would like to route multiple subnets across this VPN, check this.