diff options
author | Mark Crane <mcrane@pfsense.org> | 2009-02-01 09:23:28 +0000 |
---|---|---|
committer | Mark Crane <mcrane@pfsense.org> | 2009-02-01 09:23:28 +0000 |
commit | d00e4a703c02e59b9318d11612109642a1186b36 (patch) | |
tree | e4f3771a03299a49e09d66463bde3e37351a32d8 /packages/tftp/tftp.inc | |
parent | d264affd78ce4e5d881c98db98c336c21474f573 (diff) | |
download | pfsense-packages-d00e4a703c02e59b9318d11612109642a1186b36.tar.gz pfsense-packages-d00e4a703c02e59b9318d11612109642a1186b36.tar.bz2 pfsense-packages-d00e4a703c02e59b9318d11612109642a1186b36.zip |
TFTP package add the TFTP DHCP Option to the DHCP Server, Also add edit for text based files.
Diffstat (limited to 'packages/tftp/tftp.inc')
-rw-r--r-- | packages/tftp/tftp.inc | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/packages/tftp/tftp.inc b/packages/tftp/tftp.inc index 32c11f8b..b731a9ac 100644 --- a/packages/tftp/tftp.inc +++ b/packages/tftp/tftp.inc @@ -131,7 +131,90 @@ function php_install_command() unset($contents); fclose($handle); unset($filename); - + + + // add a TFTP DHCP Option to the DHCP Server + $filename = "/usr/local/www/services_dhcp.php"; + $fout = fopen($filename,"r"); + $tmp = fread($fout, filesize($filename)); + fclose($fout); + + //tftp was not found in the string + if (strpos($tmp, "tftp") === false) { + $tmpsearch = "\$pconfig['netmask'] = \$config['dhcpd'][\$if]['netmask'];"; + $tmpreplace = "\$pconfig['netmask'] = \$config['dhcpd'][\$if]['netmask'];\n"; + $tmpreplace .= "\$pconfig['tftp'] = \$config['dhcpd'][\$if]['options']['tftp-server-name'];"; + $tmp = str_replace($tmpsearch, $tmpreplace, $tmp); + unset($tmpsearch, $tmpreplace); + + $tmpsearch = "\$config['dhcpd'][\$if]['filename'] = \$_POST['filename'];"; + $tmpreplace = "\$config['dhcpd'][\$if]['filename'] = \$_POST['filename'];\n"; + $tmpreplace .= " \$config['dhcpd'][\$if]['options']['tftp-server-name'] = \$_POST['tftp'];"; + $tmp = str_replace($tmpsearch, $tmpreplace, $tmp); + unset($tmpsearch, $tmpreplace); + + $tmpsearch = "function show_netboot_config() {"; + $tmpreplace = "function show_tftp_config() {\n"; + $tmpreplace .= " document.getElementById(\"showtftpbox\").innerHTML=''\n"; + $tmpreplace .= " aodiv = document.getElementById('showtftp');\n"; + $tmpreplace .= " aodiv.style.display = \"block\";\n"; + $tmpreplace .= "}\n"; + $tmpreplace .= "\n"; + $tmpreplace .= "function show_netboot_config() {"; + $tmp = str_replace($tmpsearch, $tmpreplace, $tmp); + unset($tmpsearch, $tmpreplace); + + $tmpsearch = "<td width=\"22%\" valign=\"top\" class=\"vncell\">Enable Network booting</td>"; + $tmpreplace .= ""; + //$tmpreplace = " <tr>\n"; + $tmpreplace .= "<td width=\"22%\" valign=\"top\" class=\"vncell\">TFTP server</td>\n"; + $tmpreplace .= " <td width=\"78%\" class=\"vtable\">\n"; + $tmpreplace .= " <div id=\"showtftpbox\">\n"; + $tmpreplace .= " <input type=\"button\" onClick=\"show_tftp_config()\" value=\"Advanced\"></input> - Show TFTP configuration</a>\n"; + $tmpreplace .= " </div>\n"; + $tmpreplace .= " <div id=\"showtftp\" style=\"display:none\">\n"; + $tmpreplace .= " <input name=\"tftp\" type=\"text\" class=\"formfld\" id=\"tftp\" size=\"20\" value=\"<"."?=htmlspecialchars(\$pconfig['tftp']);?".">\"><br>\n"; + $tmpreplace .= " </div>\n"; + $tmpreplace .= " </td>\n"; + $tmpreplace .= " </tr>\n"; + $tmpreplace .= "\n"; + $tmpreplace .= " <tr>\n"; + $tmpreplace .= " <td width=\"22%\" valign=\"top\" class=\"vncell\">Enable Network booting</td>"; + $tmpreplace .= "\n"; + $tmp = str_replace($tmpsearch, $tmpreplace, $tmp); + unset($tmpsearch, $tmpreplace); + + $fout = fopen($filename,"w"); + fwrite($fout, $tmp); + unset($tmp); + fclose($fout); + } + unset($tmp, $filename); + + + + $filename = "/etc/inc/services.inc"; + $fout = fopen($filename,"r"); + $tmp = fread($fout, filesize($filename)); + fclose($fout); + + //tftp was not found in the string + if (strpos($tmp, "tftp") === false) { + $tmpsearch = "if (is_array(\$dhcpifconf['ntpserver']) && \$dhcpifconf['ntpserver'][0])"; + $tmpreplace = "if (isset(\$dhcpifconf['options']['tftp-server-name'])) {\n"; + $tmpreplace .= " \$dhcpdconf .= \" option tftp-server-name \\\"\".\$dhcpifconf['options']['tftp-server-name'].\"\\\";\".\"\\n\";\n"; + $tmpreplace .= " }\n"; + $tmpreplace .= " \n"; + $tmpreplace .= " if (is_array(\$dhcpifconf['ntpserver']) && \$dhcpifconf['ntpserver'][0])"; + $tmp = str_replace($tmpsearch, $tmpreplace, $tmp); + unset($tmpsearch, $tmpreplace); + + $fout = fopen($filename,"w"); + fwrite($fout, $tmp); + fclose($fout); + } + unset($tmp, $filename); + // if backup file exists restore it $filename = 'tftp.bak.tgz'; |