. All rights reserved. Includes code from m0n0wall which is: Copyright (C) 2003-2005 Manuel Kasper . All rights reserved. Includes code from pfSense which is: Copyright (C) 2004-2005 Scott Ullrich . 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. */ /* pfSense_BUILDER_BINARIES: /sbin/ifconfig pfSense_MODULE: interfaces */ ##|+PRIV ##|*IDENT=page-firewall-virtualipaddress-edit ##|*NAME=Firewall: Virtual IP Address: Edit page ##|*DESCR=Allow access to the 'Firewall: Virtual IP Address: Edit' page. ##|*MATCH=firewall_virtual_ip_edit.php* ##|-PRIV require("guiconfig.inc"); require("filter.inc"); require("shaper.inc"); if (!is_array($config['virtualip']['vip'])) { $config['virtualip']['vip'] = array(); } $a_vip = &$config['virtualip']['vip']; if (isset($_POST['id'])) $id = $_POST['id']; else $id = $_GET['id']; function return_first_two_octets($ip) { $ip_split = split("\.", $ip); return $ip_split[0] . "." . $ip_split[1]; } function find_last_used_vhid() { global $config, $g; $vhid = 0; foreach($config['virtualip']['vip'] as $vip) { if($vip['vhid'] > $vhid) $vhid = $vip['vhid']; } return $vhid; } if (isset($id) && $a_vip[$id]) { $pconfig['mode'] = $a_vip[$id]['mode']; $pconfig['vhid'] = $a_vip[$id]['vhid']; $pconfig['advskew'] = $a_vip[$id]['advskew']; $pconfig['password'] = $a_vip[$id]['password']; $pconfig['range'] = $a_vip[$id]['range']; $pconfig['subnet'] = $a_vip[$id]['subnet']; $pconfig['subnet_bits'] = $a_vip[$id]['subnet_bits']; $pconfig['descr'] = $a_vip[$id]['descr']; $pconfig['type'] = $a_vip[$id]['type']; $pconfig['interface'] = $a_vip[$id]['interface']; } else { $lastvhid = find_last_used_vhid(); $lastvhid++; $pconfig['vhid'] = $lastvhid; } if ($_POST) { unset($input_errors); $pconfig = $_POST; /* input validation */ $reqdfields = explode(" ", "mode"); $reqdfieldsn = array(gettext("Type")); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); if (($_POST['subnet'] && !is_ipaddr($_POST['subnet']))) $input_errors[] = gettext("A valid IP address must be specified."); $natiflist = get_configured_interface_with_descr(); foreach ($natiflist as $natif => $natdescr) { if ($_POST['interface'] == $natif && empty($config['interfaces'][$natif]['ipaddr'])) $input_errors[] = gettext("The interface chosen for the VIP has no ip configured so it cannot be used as a parent for the VIP."); if ($_POST['subnet'] == get_interface_ip($natif)) $input_errors[] = sprintf(gettext("The %s IP address may not be used in a virtual entry."),$natdescr); } if($_POST['subnet_bits'] == "32" and $_POST['type'] == "carp") $input_errors[] = gettext("The /32 subnet mask is invalid for CARP IPs."); /* check for overlaps with other virtual IP */ foreach ($a_vip as $vipent) { if (isset($id) && ($a_vip[$id]) && ($a_vip[$id] === $vipent)) continue; if (isset($_POST['subnet']) && $_POST['subnet'] == $vipent['subnet']) { $input_errors[] = gettext("There is already a virtual IP entry for the specified IP address."); break; } } /* make sure new ip is within the subnet of a valid ip * on one of our interfaces (wan, lan optX) */ if ($_POST['mode'] == "carp" or $_POST['mode'] == "carpdev-dhcp") { /* verify against reusage of vhids */ $idtracker = 0; foreach($config['virtualip']['vip'] as $vip) { if($vip['vhid'] == $_POST['vhid'] and $idtracker <> $id) $input_errors[] = sprintf(gettext("VHID %s is already in use. Pick a unique number."),$_POST['vhid']); $idtracker++; } if($_POST['password'] == "") $input_errors[] = gettext("You must specify a CARP password that is shared between the two VHID members."); $parent_ip = get_interface_ip($_POST['interface']); $parent_sn = get_interface_subnet($_POST['interface']); if (!ip_in_subnet($_POST['subnet'], gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn) && !ip_in_interface_alias_subnet($_POST['interface'], $_POST['subnet'])) { $cannot_find = $_POST['subnet'] . "/" . $_POST['subnet_bits'] ; $input_errors[] = sprintf(gettext("Sorry, we could not locate an interface with a matching subnet for %s. Please add an IP alias in this subnet on this interface."),$cannot_find); } } if (isset($id) && ($a_vip[$id])) { if ($a_vip[$id]['mode'] != $_POST['mode']) { $bringdown = false; if ($a_vip[$id]['mode'] == "proxyarp") { $vipiface = $a_vip[$id]['interface']; foreach ($a_vip as $vip) { if ($vip['interface'] == $vipiface && $vip['mode'] == "carp") { if (ip_in_subnet($vip['subnet'], gen_subnet($a_vip[$id]['subnet'], $a_vip[$id]['subnet_bits']) . "/" . $a_vip[$id]['subnet_bits'])) $input_errors[] = gettext("This entry cannot be modified because it is still referenced by CARP") . " {$vip['descr']}."; } } } } } if (!$input_errors) { $vipent = array(); $vipent['mode'] = $_POST['mode']; $vipent['interface'] = $_POST['interface']; /* ProxyARP specific fields */ if ($_POST['mode'] === "proxyarp") { if ($_POST['type'] == "range") { $vipent['range']['from'] = $_POST['range_from']; $vipent['range']['to'] = $_POST['range_to']; } } /* CARP specific fields */ if ($_POST['mode'] === "carp" or $_POST['mode'] == "carpdev-dhcp") { $vipent['vhid'] = $_POST['vhid']; $vipent['advskew'] = $_POST['advskew']; $vipent['password'] = $_POST['password']; } /* Common fields */ $vipent['descr'] = $_POST['descr']; if (isset($_POST['type'])) $vipent['type'] = $_POST['type']; else $vipent['type'] = "single"; if ($vipent['type'] == "single" || $vipent['type'] == "network") { if (!isset($_POST['subnet_bits'])) { $vipent['subnet_bits'] = "32"; } else { $vipent['subnet_bits'] = $_POST['subnet_bits']; } $vipent['subnet'] = $_POST['subnet']; } if ($_POST['mode'] == "carpdev-dhcp") { unset($vipent['subnet']); unset($vipent['subnet_bits']); unset($vipent['alias-subnet']); } if (!isset($id)) $id = count($a_vip); if (file_exists("{$g['tmp_path']}/.firewall_virtual_ip.apply")) $toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.firewall_virtual_ip.apply")); else $toapplylist = array(); $toapplylist[$id] = $a_vip[$id]; if (!empty($a_vip[$id])) { /* modify all virtual IP rules with this address */ for ($i = 0; isset($config['nat']['rule'][$i]); $i++) { if ($config['nat']['rule'][$i]['destination']['address'] == $a_vip[$id]['subnet']) $config['nat']['rule'][$i]['destination']['address'] = $vipent['subnet']; } } $a_vip[$id] = $vipent; mark_subsystem_dirty('vip'); write_config(); file_put_contents("{$g['tmp_path']}/.firewall_virtual_ip.apply", serialize($toapplylist)); header("Location: firewall_virtual_ip.php"); exit; } } $pgtitle = array(gettext("Firewall"),gettext("Virtual IP Address"),gettext("Edit")); include("head.inc"); ?>
> > > > > CarpDEV-DHCP */ ?>
*/ ?>
  
   /
Range:   -




  "> " onclick="history.back()">


  

    .