Fowarding this message as it was sent from the wrong account the first time.
Jonathan ---------- Forwarded message ---------- From: Jonathan Dieter <jdie...@lesbg.com> Date: Mon, Jul 12, 2010 at 4:33 PM Subject: PATCH: Add custom DHCP configuration To: support@pfsense.com In current 2.0BETA3, it seems that there's no way to write one's own configuration settings into dhcpd.conf. For example, if I want to chain-load gPXE, there's nowhere to put the following: if exists user-class and option user-class = "gPXE" { filename "http://www.lesaz.loc/netboot/pxelinux.0"; } else { filename "gpxe.pxe"; } I've added a "Custom DHCP configuration" that will be inserted at the end of the subnet declaration. To be honest, this feels a bit hackish (why at that location), but I'm not sure of any better place to put it. I did modify xmlparse.inc to make any name that ends as "_cdata" a CDATA type, as that was the most logical way that I could think of to maintain newlines. If there's a better way, please correct it (or let me know and I'll correct it). Jonathan
diff -urb new/etc/inc/services.inc custom/etc/inc/services.inc --- new/etc/inc/services.inc 2010-07-12 13:25:12.450445328 +0300 +++ custom/etc/inc/services.inc 2010-07-12 16:17:42.112987836 +0300 @@ -315,11 +315,13 @@ } } + /* Custom dhcp data goes here */ + $dhcpdconf .= $dhcpifconf['custom_cdata']; + $dhcpdconf .= <<<EOD } EOD; - /* add static mappings */ if (is_array($dhcpifconf['staticmap'])) { diff -urb new/etc/inc/xmlparse.inc custom/etc/inc/xmlparse.inc --- new/etc/inc/xmlparse.inc 2010-07-12 15:21:49.444916086 +0300 +++ custom/etc/inc/xmlparse.inc 2010-07-12 15:20:23.244665781 +0300 @@ -261,7 +261,7 @@ $xmlconfig .= str_repeat("\t", $indent); if((is_bool($cval) && $cval == true) || ($cval === "")) { $xmlconfig .= "<$ent/>\n"; - } else if (substr($ent, 0, 5) == "descr") { + } else if (substr($ent, 0, 5) == "descr" or substr($ent, -6) == "_cdata") { $xmlconfig .= "<$ent><![CDATA[" . htmlentities($cval) . "]]></$ent>\n"; } else { $xmlconfig .= "<$ent>" . htmlentities($cval) . "</$ent>\n"; @@ -285,7 +285,7 @@ $xmlconfig .= "<$ent/>\n"; } else if (!is_bool($val)) { $xmlconfig .= str_repeat("\t", $indent); - if (substr($ent, 0, 5) == "descr") + if (substr($ent, 0, 5) == "descr" or substr($ent, -6) == "_cdata") $xmlconfig .= "<$ent><![CDATA[" . htmlentities($val) . "]]></$ent>\n"; else $xmlconfig .= "<$ent>" . htmlentities($val) . "</$ent>\n"; diff -urb new/usr/local/www/services_dhcp.php custom/usr/local/www/services_dhcp.php --- new/usr/local/www/services_dhcp.php 2010-07-12 13:56:38.907508685 +0300 +++ custom/usr/local/www/services_dhcp.php 2010-07-12 16:21:51.004988888 +0300 @@ -155,6 +155,7 @@ $pconfig['rootpath'] = $config['dhcpd'][$if]['rootpath']; $pconfig['failover_peerip'] = $config['dhcpd'][$if]['failover_peerip']; $pconfig['netmask'] = $config['dhcpd'][$if]['netmask']; + $pconfig['custom_cdata'] = $config['dhcpd'][$if]['custom_cdata']; $pconfig['numberoptions'] = $config['dhcpd'][$if]['numberoptions']; if (!is_array($config['dhcpd'][$if]['staticmap'])) $config['dhcpd'][$if]['staticmap'] = array(); @@ -321,6 +322,7 @@ $config['dhcpd'][$if]['next-server'] = $_POST['nextserver']; $config['dhcpd'][$if]['filename'] = $_POST['filename']; $config['dhcpd'][$if]['rootpath'] = $_POST['rootpath']; + $config['dhcpd'][$if]['custom_cdata'] = $_POST['custom_cdata']; // Handle the custom options rowhelper if(isset($config['dhcpd'][$if]['numberoptions']['item'])) @@ -457,6 +459,12 @@ aodiv = document.getElementById('shownetboot'); aodiv.style.display = "block"; } + + function show_custom_config() { + document.getElementById("showcustombox").innerHTML=''; + aodiv = document.getElementById('showcustom'); + aodiv.style.display = "block"; + } </script> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> @@ -793,6 +801,18 @@ </td> </tr> <tr> + <td width="22%" valign="top" class="vncell">Custom DHCP configuration</td> + <td width="78%" class="vtable"> + <div id="showcustombox"> + <input type="button" onClick="show_custom_config()" value="Advanced"></input> - Show custom DHCP configuration</a> + </div> + <div id="showcustom" style="display:none"> + <textarea name="custom_cdata" cols="65" rows="4" class="formpre" id="custom_cdata"><?=htmlspecialchars($pconfig['custom_cdata']);?></textarea><br> + Use this to input any ISC DHCP settings that don't fit in the above settings. If you don't know what this means, don't use this. Settings here are not checked for validity, so you may break your DHCP setup. The contents of this box will be inserted into dhcpd.conf as part of the subnet. + </div> + </td> + </tr> + <tr> <td width="22%" valign="top"> </td> <td width="78%"> <input name="if" type="hidden" value="<?=$if;?>">
--------------------------------------------------------------------- To unsubscribe, e-mail: support-unsubscr...@pfsense.com For additional commands, e-mail: support-h...@pfsense.com Commercial support available - https://portal.pfsense.org