summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErmal <eri@pfsense.org>2010-08-19 18:32:51 +0000
committerErmal <eri@pfsense.org>2010-08-19 18:32:51 +0000
commit2f06cc3f6c9a15d7295323283703c418227c6b1b (patch)
treec106e19dc3434d5ad2a8c4a679eb67862bdddd71
parent2445e8515882368b5d8335409c50abeb9653b1e1 (diff)
downloadpfsense-2f06cc3f6c9a15d7295323283703c418227c6b1b.zip
pfsense-2f06cc3f6c9a15d7295323283703c418227c6b1b.tar.gz
Make dhcrelay GUI be simple and easy to use by collapsing the interface tabs to a multiselect control. Remove proxydhcp option because it is broken and is not trivial to make it usable(if user request for it a reconsideration will be made). Allow multiple server ips on the server input box separated by commas. Also on the interface list do not show interfaces without an ip because dhcrelay will not be happy with them. Upgrade code is also included in this commit.
-rw-r--r--etc/inc/interfaces.inc2
-rw-r--r--etc/inc/services.inc131
-rw-r--r--etc/inc/upgrade_config.inc21
-rwxr-xr-xusr/local/www/services_dhcp_relay.php176
4 files changed, 146 insertions, 184 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc
index 5d5075a..057c684 100644
--- a/etc/inc/interfaces.inc
+++ b/etc/inc/interfaces.inc
@@ -2854,7 +2854,7 @@ function guess_interface_from_ip($ipaddress) {
return false;
}
/* create a route table we can search */
- exec("netstat -rnW", $output, $ret);
+ exec("netstat -rnWf inet", $output, $ret);
foreach($output as $line) {
if(preg_match("/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/[0-9]+[ ]+link[#]/", $line)) {
$fields = preg_split("/[ ]+/", $line);
diff --git a/etc/inc/services.inc b/etc/inc/services.inc
index 877368a..86bb78c 100644
--- a/etc/inc/services.inc
+++ b/etc/inc/services.inc
@@ -477,20 +477,10 @@ function services_dhcrelay_configure() {
/* kill any running dhcrelay */
killbypid("{$g['varrun_path']}/dhcrelay.pid");
- $dhcrelaycfg = $config['dhcrelay'];
+ $dhcrelaycfg =& $config['dhcrelay'];
/* DHCPRelay enabled on any interfaces? */
- $dhcrelayenable = false;
- if(is_array($dhcrelaycfg)) {
- foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
- if (isset($dhcrelayifconf['enable']) ||
- (isset($config['interfaces'][$dhcrelayif]['enable']) &&
- (!link_interface_to_bridge($dhcrelayif))))
- $dhcrelayenable = true;
- }
- }
-
- if (!$dhcrelayenable)
+ if (!isset($dhcrelaycfg['enable']))
return 0;
if ($g['booting'])
@@ -498,72 +488,79 @@ function services_dhcrelay_configure() {
else
sleep(1);
- $dhcrelayifs = array();
- foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
-
- $ifcfg = $config['interfaces'][$dhcrelayif];
+ $iflist = get_configured_interface_list();
- if (!isset($dhcrelayifconf['enable']) ||
- (!isset($ifcfg['enable']) ||
- link_interface_to_bridge($dhcrelayif)))
+ $dhcifaces = explode(",", $dhcrelaycfg['interface']);
+ foreach ($dhcifaces as $dhcrelayif) {
+ if (!isset($iflist[$dhcrelayif]) ||
+ link_interface_to_bridge($dhcrelayif))
continue;
- $dhcrelayifs[] = get_real_interface($dhcrelayif);
+ if (is_ipaddr(get_interface_ip($dhcrelayif)))
+ $dhcrelayifs[] = get_real_interface($dhcrelayif);
}
- /* In order for the relay to work, it needs to be active on the
- interface in which the destination server sits */
- $iflist = get_configured_interface_list();
- foreach ($iflist as $ifname) {
- $subnet = get_interface_ip($ifname) . "/" . get_interface_subnet($ifname);
- if (ip_in_subnet($dhcrelaycfg['server'],$subnet)) {
- $destif = get_real_interface($ifname);
- break;
+ /*
+ * In order for the relay to work, it needs to be active
+ * on the interface in which the destination server sits.
+ */
+ $srvips = explode(",", $dhcrelaycfg['server']);
+ foreach ($srvips as $srcidx => $srvip) {
+ unset($destif);
+ foreach ($iflist as $ifname) {
+ $subnet = get_interface_ip($ifname);
+ if (!is_ipaddr($subnet))
+ continue;
+ $subnet .= "/" . get_interface_subnet($ifname);
+ if (ip_in_subnet($srvip, $subnet)) {
+ $destif = get_real_interface($ifname);
+ break;
+ }
}
- }
- if (!isset($destif)) {
- if (is_array($config['staticroutes']['route'])) {
- foreach ($config['staticroutes']['route'] as $rtent) {
- if (ip_in_subnet($dhcrelaycfg['server'], $rtent['network'])) {
- $a_gateways = return_gateways_array(true);
- $destif = $a_gateways[$rtent['gateway']]['interface'];
- break;
+ if (!isset($destif)) {
+ if (is_array($config['staticroutes']['route'])) {
+ foreach ($config['staticroutes']['route'] as $rtent) {
+ if (ip_in_subnet($srvip, $rtent['network'])) {
+ $a_gateways = return_gateways_array(true);
+ $destif = $a_gateways[$rtent['gateway']]['interface'];
+ break;
+ }
}
}
}
- }
- if (!isset($destif)) {
- /* Create a array from the existing route table */
- exec("/usr/bin/netstat -rnf inet", $route_str);
- array_shift($route_str);
- array_shift($route_str);
- array_shift($route_str);
- array_shift($route_str);
- $route_arr = array();
- foreach($route_str as $routeline) {
- $items = preg_split("/[ ]+/i", $routeline);
- if (ip_in_subnet($$dhcrelaycfg['server'], $items[0])) {
- $destif = trim($items[2]);
- break;
- }
- }
- }
-
- if (!isset($destif)) {
- if (is_array($config['gateways']['gateway_item'])) {
- foreach ($config['gateways']['gateway_item'] as $gateway) {
- if (isset($gateway['defaultgw'])) {
- $a_gateways = return_gateways_array(true);
- $destif = $a_gateways[$rtent['gateway']]['interface'];
+ if (!isset($destif)) {
+ /* Create a array from the existing route table */
+ exec("/usr/bin/netstat -rnWf inet", $route_str);
+ array_shift($route_str);
+ array_shift($route_str);
+ array_shift($route_str);
+ array_shift($route_str);
+ $route_arr = array();
+ foreach($route_str as $routeline) {
+ $items = preg_split("/[ ]+/i", $routeline);
+ if (ip_in_subnet($srvip, $items[0])) {
+ $destif = trim($items[2]);
break;
- }
- }
- } else
- $destif = get_real_interface("wan");
- }
+ }
+ }
+ }
+
+ if (!isset($destif)) {
+ if (is_array($config['gateways']['gateway_item'])) {
+ foreach ($config['gateways']['gateway_item'] as $gateway) {
+ if (isset($gateway['defaultgw'])) {
+ $a_gateways = return_gateways_array(true);
+ $destif = $a_gateways[$rtent['gateway']]['interface'];
+ break;
+ }
+ }
+ } else
+ $destif = get_real_interface("wan");
+ }
- $dhcrelayifs[] = $destif;
+ $dhcrelayifs[] = $destif;
+ }
$dhcrelayifs = array_unique($dhcrelayifs);
/* fire up dhcrelay */
@@ -572,7 +569,7 @@ function services_dhcrelay_configure() {
if (isset($dhcrelaycfg['agentoption']))
$cmd .= " -a -m replace";
- $cmd .= " {$dhcrelaycfg['server']}";
+ $cmd .= " " . implode(" ", $srvips);
mwexec($cmd);
return 0;
diff --git a/etc/inc/upgrade_config.inc b/etc/inc/upgrade_config.inc
index 574be98..24f56f7 100644
--- a/etc/inc/upgrade_config.inc
+++ b/etc/inc/upgrade_config.inc
@@ -2069,4 +2069,25 @@ function upgrade_064_to_065() {
$config['system']['disablelargereceiveoffloading'] = true;
}
+function upgrade_065_to_066() {
+ global $config;
+
+ $dhcrelaycfg =& $config['dhcrelay'];
+
+ if (is_array($dhcrelaycfg)) {
+ $dhcrelayifs = array();
+ $foundifs = false;
+ /* DHCPRelay enabled on any interfaces? */
+ foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
+ if (isset($dhcrelayifconf['enable'])) {
+ $dhcrelayifs[] = $dhcrelayif;
+ unset($dhcrelaycfg['dhcrelayif']);
+ $foundifs = true;
+ }
+ }
+ if ($foundifs == true)
+ $dhcrelaycfg['interface'] = implode(",", $dhcrelayifs);
+ }
+}
+
?>
diff --git a/usr/local/www/services_dhcp_relay.php b/usr/local/www/services_dhcp_relay.php
index c9e8fd1..788893d 100755
--- a/usr/local/www/services_dhcp_relay.php
+++ b/usr/local/www/services_dhcp_relay.php
@@ -1,5 +1,4 @@
<?php
-/* $Id$ */
/*
services_dhcp.php
part of m0n0wall (http://m0n0.ch/wall)
@@ -39,51 +38,17 @@
##|*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['enable'] = isset($config['dhcrelay']['enable']);
+if (empty($config['dhcrelay']['interface']))
+ $pconfig['interface'] = array();
+else
+ $pconfig['interface'] = explode(",", $config['dhcrelay']['interface']);
$pconfig['server'] = $config['dhcrelay']['server'];
-$pconfig['proxydhcp'] = isset($config['dhcrelay']['proxydhcp']);
$pconfig['agentoption'] = isset($config['dhcrelay']['agentoption']);
-$ifcfg = $config['interfaces'][$if];
+$iflist = get_configured_interface_with_descr();
/* 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
@@ -92,7 +57,7 @@ $ifcfg = $config['interfaces'][$if];
$dhcpd_enabled = false;
if (is_array($config['dhcpd'])) {
foreach($config['dhcpd'] as $dhcp)
- if(isset($dhcp['enable']))
+ if (isset($dhcp['enable']))
$dhcpd_enabled = true;
}
@@ -103,42 +68,25 @@ if ($_POST) {
/* input validation */
if ($_POST['enable']) {
- if (isset($_POST['proxydhcp']))
- $_POST['server'] = get_wan_dhcp_server();
- $reqdfields = explode(" ", "server");
- $reqdfieldsn = array(gettext("Destination Server"));
+ $reqdfields = explode(" ", "server interface");
+ $reqdfieldsn = array(gettext("Destination Server"), gettext("Interface"));
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 ($_POST['server']) {
+ $checksrv = explode(",", $_POST['server']);
+ foreach ($checksrv as $srv) {
+ if (!is_ipaddr($srv))
+ $input_errors[] = gettext("A valid Destination Server IP address must be specified.");
}
- 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']['enable'] = $_POST['enable'] ? true : false;
+ $config['dhcrelay']['interface'] = implode(",", $_POST['interface']);
$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();
@@ -159,15 +107,12 @@ include("head.inc");
function enable_change(enable_over) {
if (document.iform.enable.checked || enable_over) {
document.iform.server.disabled = 0;
+ document.iform.interface.disabled = 0;
document.iform.agentoption.disabled = 0;
- document.iform.proxydhcp.disabled = 0;
} else {
document.iform.server.disabled = 1;
+ document.iform.interface.disabled = 1;
document.iform.agentoption.disabled = 1;
- document.iform.proxydhcp.disabled = 1;
- }
- if (document.iform.proxydhcp.checked) {
- document.iform.server.disabled = 1;
}
}
//-->
@@ -179,69 +124,68 @@ function enable_change(enable_over) {
<form action="services_dhcp_relay.php" method="post" name="iform" id="iform">
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($savemsg) print_info_box($savemsg); ?>
-<?php
- if ($dhcpd_enabled) {
- echo gettext("DHCP Server is currently enabled. Cannot enable the DHCP Relay service while the DHCP Server is enabled on any interface.");
- include("fend.inc");
- echo "</body>";
- echo "</html>";
- exit;
- }
-?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
- <tr><td>
- <?php
- /* active tabs */
- $tab_array = array();
- $tabscounter = 0;
- $i = 0;
- foreach ($iflist as $ifent => $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);
- ?>
- </td></tr>
<tr>
<td>
<div id="mainarea">
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
- <tr>
- <td width="22%" valign="top" class="vtable">&nbsp;</td>
+<?php
+ if ($dhcpd_enabled):
+ echo gettext("DHCP Server is currently enabled. Cannot enable the DHCP Relay service while the DHCP Server is enabled on any interface.");
+ else:
+?>
+ <tr>
+ <td colspan="2" valign="top" class="listtopic"><?=gettext("DHCP Relay configuration"); ?></td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq">Enable</td>
+ <td width="78%" class="vtable">
+ <input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
+ <strong><?php printf(gettext("Enable DHCP relay on interface"));?></strong>
+ </td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq">Interface(s)</td>
<td width="78%" class="vtable">
-<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
- <strong><?php printf(gettext("Enable DHCP relay on " .
- "%s " .
- "interface"),htmlspecialchars($iflist[$if]));?></strong></td>
- </tr>
- <tr>
+ <select id="interface" name="interface[]" multiple="true" class="formselect" size="3">
+ <?php
+ foreach ($iflist as $ifent => $ifdesc) {
+ if (!is_ipaddr(get_interface_ip($ifent)))
+ continue;
+ echo "<option value='{$ifent}'";
+ if (in_array($ifent, $pconfig['interface']))
+ echo "selected";
+ echo ">{$ifdesc}</option>\n";
+ }
+ ?>
+ </select>
+ <br />Interfaces without an ip address will not be shown.
+ </td>
+ </tr>
+ <tr>
<td width="22%" valign="top" class="vtable">&nbsp;</td>
<td width="78%" class="vtable">
<input name="agentoption" type="checkbox" value="yes" <?php if ($pconfig['agentoption']) echo "checked"; ?>>
<strong><?=gettext("Append circuit ID and agent ID to requests"); ?></strong><br>
<?php printf(gettext("If this is checked, the DHCP relay will append the circuit ID (%s interface number) and the agent ID to the DHCP request."), $g['product_name']); ?></td>
- </tr>
- <tr>
+ </tr>
+ <tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Destination server");?></td>
<td width="78%" class="vtable">
- <input name="proxydhcp" type="checkbox" value="yes" <?php if ($pconfig['proxydhcp']) echo "checked"; ?> onClick="enable_change(false)"> <?=gettext("Proxy requests to DHCP server on WAN subnet");?>
- <br><br><input name="server" type="text" class="formfld unknown" id="server" size="20" value="<?=htmlspecialchars($pconfig['server']);?>">
+ <input name="server" type="text" class="formfld unknown" id="server" size="20" value="<?=htmlspecialchars($pconfig['server']);?>">
<br>
- <?=gettext("This is the IP address of the server to which the DHCP packet is relayed. Select \"Proxy requests to DHCP server on WAN subnet\" to relay DHCP packets to the server that was used on the WAN interface.");?>
+ <?=gettext("This is the IP address of the server to which the DHCP packet is relayed. You can enter multiple ip address server entries separated by commas. Select \"Proxy requests to DHCP server on WAN subnet\" to relay DHCP packets to the server that was used on the WAN interface.");?>
</td>
- </tr>
- <tr>
+ </tr>
+ <tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
- <input name="if" type="hidden" value="<?=$if;?>">
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)">
</td>
- </tr>
- </table>
+ </tr>
+<?php endif; ?>
+ </table>
</div>
</td>
</tr>
OpenPOWER on IntegriCloud