. 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_MODULE: dhcprelay */ ##|+PRIV ##|*IDENT=page-services-dhcprelay ##|*NAME=Services: DHCP Relay page ##|*DESCR=Allow access to the 'Services: DHCP Relay' page. ##|*MATCH=services_dhcp_relay.php* ##|-PRIV function get_wan_dhcp_server() { global $config, $g; $dhclientfn = $g['vardb_path'] . "/dhclient.leases." . $config['interfaces']['wan']['if']; if(file_exists($dhclientfn)) $leases = file($dhclientfn); else $leases = array(); /* Start at the end, work backwards finding the latest lease for the WAN */ $dhcpserver = ""; $iface = ""; $iface = ""; for ($i = (count($leases)-1); $i >= 0; $i--) { if ($leases[$i] == "}") { unset($iface); unset($dhcpserver); } elseif (strstr($leases[$i],"interface")) { preg_match("/\s+interface \"(\w+)\";/",$leases[$i],$iface); } elseif (strstr($leases[$i],"dhcp-server-identifier")) { preg_match("/\s+dhcp-server-identifier (\d+\.\d+\.\d+\.\d+);/",$leases[$i],$dhcpserver); } if ($iface == $config['interfaces']['wan'] && isset($dhcpserver)) { break; } } return $dhcpserver[1]; } require("guiconfig.inc"); $if = $_GET['if']; if ($_POST['if']) $if = $_POST['if']; $iflist = get_configured_interface_with_descr(); if (!$if || !isset($iflist[$if])) $if = "lan"; $pconfig['enable'] = isset($config['dhcrelay'][$if]['enable']); $pconfig['server'] = $config['dhcrelay']['server']; $pconfig['proxydhcp'] = isset($config['dhcrelay']['proxydhcp']); $pconfig['agentoption'] = isset($config['dhcrelay']['agentoption']); $ifcfg = $config['interfaces'][$if]; /* set the enabled flag which will tell us if DHCP server is enabled * on any interface. We will use this to disable dhcp-relay since * the two are not compatible with each other. */ $dhcpd_enabled = false; if (is_array($config['dhcpd'])) { foreach($config['dhcpd'] as $dhcp) if(isset($dhcp['enable'])) $dhcpd_enabled = true; } if ($_POST) { unset($input_errors); $pconfig = $_POST; /* input validation */ if ($_POST['enable']) { if (isset($_POST['proxydhcp'])) $_POST['server'] = get_wan_dhcp_server(); $reqdfields = explode(" ", "server"); $reqdfieldsn = array(gettext("Destination Server")); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); if (($_POST['server'] && !is_ipaddr($_POST['server']))) $input_errors[] = gettext("A valid Destination Server IP address must be specified."); if (!$input_errors) { /* make sure that the DHCP server isn't enabled on this interface */ if (isset($config['dhcpd'][$if]['enable'])) $input_errors[] = sprintf(gettext("You must disable the DHCP server on the %s interface before enabling the DHCP Relay."),$iflist[$if]); /* make sure that the DHCP server isn't running on any of the implied interfaces */ foreach ($config['interfaces'] as $ifname => $ifcfg) { $subnet = $ifcfg['ipaddr'] . "/" . $ifcfg['subnet']; if (ip_in_subnet($_POST['server'],$subnet)) $destif = $ifname; } if (!isset($destif)) $destif = "wan"; if (isset($config['dhcpd'][$destif]['enable'])) $input_errors[] = sprintf(gettext("You must disable the DHCP server on the %s interface before enabling the DHCP Relay."),$destif); /* if proxydhcp is selected, make sure DHCP is enabled on WAN */ if (isset($config['dhcrelay']['proxydhcp']) && $config['interfaces']['wan']['ipaddr'] != "dhcp") $input_errors[] = gettext("You must have DHCP active on the WAN interface before enabling the DHCP proxy option."); } } if (!$input_errors) { $config['dhcrelay']['agentoption'] = $_POST['agentoption'] ? true : false; $config['dhcrelay']['proxydhcp'] = $_POST['proxydhcp'] ? true : false; $config['dhcrelay']['server'] = $_POST['server']; $config['dhcrelay'][$if]['enable'] = $_POST['enable'] ? true : false; write_config(); $retval = 0; $retval = services_dhcrelay_configure(); $savemsg = get_std_save_message($retval); } } $pgtitle = array(gettext("Services"),gettext("DHCP Relay")); include("head.inc"); ?>
"; echo ""; exit; } ?>
$ifname) { if ($ifent == $if) $active = true; else $active = false; $tab_array[] = array($ifname, $active, "services_dhcp_relay.php?if={$ifent}"); } display_top_tabs($tab_array); ?>
  onClick="enable_change(false)">
  >
onClick="enable_change(false)">


  " onclick="enable_change(true)">