diff options
Diffstat (limited to 'config/tftp2')
-rw-r--r-- | config/tftp2/tftp.inc | 13 | ||||
-rw-r--r-- | config/tftp2/tftp_files.php | 261 |
2 files changed, 148 insertions, 126 deletions
diff --git a/config/tftp2/tftp.inc b/config/tftp2/tftp.inc index 698122d2..a9af5fe3 100644 --- a/config/tftp2/tftp.inc +++ b/config/tftp2/tftp.inc @@ -115,6 +115,7 @@ function tftp_deinstall_command() { } function tftp_generate_rules($type) { + global $config, $FilterIflist; if ($type != "nat") return; // Open inetd.conf write handle @@ -122,5 +123,17 @@ function tftp_generate_rules($type) { /* add tftp daemon */ fwrite($inetd_fd, "tftp\t\tdgram\tudp\twait\t\troot\t/usr/libexec/tftpd\ttftpd /tftpboot\n"); fclose($inetd_fd); // Close file handle + + if (!empty($config['installedpackages']['tftpd']['config'][0]['tftpdinterface'])) { + $tftpifs = explode(",", $config['installedpackages']['tftpd']['config'][0]['tftpdinterface']); + foreach($tftpifs as $tftpif) { + if ($FilterIflist[$tftpif]) { + log_error("Adding TFTP nat rules"); + $natrules .= "rdr pass on {$FilterIflist[$tftpif]['if']} proto udp from any to {$FilterIflist[$tftpif]['ip']} port 69 -> 127.0.0.1 port 69\n"; + $natrules .= "nat on {$FilterIflist[$tftpif]['if']} from 127.0.0.1 to any -> {$FilterIflist[$tftpif]['ip']} port 1024:65535 \n"; + } + } + } + return $natrules; } ?> diff --git a/config/tftp2/tftp_files.php b/config/tftp2/tftp_files.php index bc2554ab..e2e02fcc 100644 --- a/config/tftp2/tftp_files.php +++ b/config/tftp2/tftp_files.php @@ -4,7 +4,7 @@ tftp_files.php Copyright (C) 2008 Mark J Crane All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -31,13 +31,15 @@ require_once("guiconfig.inc"); require_once("/usr/local/pkg/tftp.inc"); +$pconfig['tftpdinterface'] = explode(",", $config['installedpackages']['tftpd']['config'][0]['tftpdinterface']); + $filename = $_GET['filename']; if (($_GET['a'] == "download") && $_GET['t'] == "backup") { - conf_mount_rw(); - $tmp = '/root/backup/'; - $filename = 'tftp.bak.tgz'; - system('cd /;tar cvzf /root/backup/tftp.bak.tgz tftpboot'); - conf_mount_ro(); + conf_mount_rw(); + $tmp = '/root/backup/'; + $filename = 'tftp.bak.tgz'; + system('cd /;tar cvzf /root/backup/tftp.bak.tgz tftpboot'); + conf_mount_ro(); } if (($_GET['a'] == "download") && file_exists("/root/backup/".$filename)) { @@ -57,27 +59,34 @@ if (($_GET['a'] == "download") && file_exists("/root/backup/".$filename)) { if ($_GET['a'] == "other") { - if ($_GET['t'] == "restore") { - $tmp = '/root/backup/'; - $filename = 'tftp.bak.tgz'; - - //extract a specific directory to /tftpboot - if (file_exists('/root/backup/'.$filename)) { - //echo "The file $filename exists"; - conf_mount_rw(); - system('cd /; tar xvpfz /root/backup/'.$filename); - system('chmod -R 744 /tftpboot/*'); - header( 'Location: tftp_files.php?savemsg=Backup+has+been+restored.' ) ; - conf_mount_ro(); - } - else { - header( 'Location: tftp_files.php?savemsg=Restore+failed.+Backup+file+not+found.' ) ; - } - - exit; - } + if ($_GET['t'] == "restore") { + $tmp = '/root/backup/'; + $filename = 'tftp.bak.tgz'; + + //extract a specific directory to /tftpboot + if (file_exists('/root/backup/'.$filename)) { + //echo "The file $filename exists"; + conf_mount_rw(); + system('cd /; tar xvpfz /root/backup/'.$filename); + system('chmod -R 744 /tftpboot/*'); + header( 'Location: tftp_files.php?savemsg=Backup+has+been+restored.' ) ; + conf_mount_ro(); + } else { + header( 'Location: tftp_files.php?savemsg=Restore+failed.+Backup+file+not+found.' ) ; + } + exit; + } +} +if ($_POST['submit'] == "Save") { + if ($_POST['tftpdinterface']) { + $config['installedpackages']['tftpd']['config'][0]['tftpdinterface'] = implode(",", $_POST['tftpdinterface']); + $pconfig['tftpdinterface'] = $_POST['tftpdinterface']; + write_config(); + send_event("filter reload"); + } else { + unset($config['installedpackages']['tftpd']['config'][0]['tftpdinterface']); + } } - if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) { conf_mount_rw(); @@ -90,13 +99,13 @@ if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_na if ($_GET['act'] == "del") { - if ($_GET['type'] == 'tftp') { - conf_mount_rw(); + if ($_GET['type'] == 'tftp') { + conf_mount_rw(); unlink_if_exists("/tftpboot/".$_GET['filename']); - conf_mount_ro(); - header("Location: tftp_files.php"); - exit; - } + conf_mount_ro(); + header("Location: tftp_files.php"); + exit; + } } include("head.inc"); @@ -118,55 +127,68 @@ if ($savemsg) { <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td class="tabnavtbl"> <?php - + $tab_array = array(); $tab_array[] = array(gettext("Files"), false, "tftp_files.php"); - display_top_tabs($tab_array); - + display_top_tabs($tab_array); + ?> </td></tr> </table> <table width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td class="tabcont" > - - <table width="100%" border="0" cellpadding="6" cellspacing="0"> - <tr> - <td><p><span class="vexpl"><span class="red"><strong>TFTP files<br /> - </strong></span> - Trivial File Transport Protocol is a very simple file transfer - protocol. Use the file upload to add files to the /tftpboot directory. - Click on the file from the file list below to download it. - </span></p></td> - </tr> - </table> - <br /> + <tr> + <td class="tabcont" > + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr> + <td width="78%" class="vtable"> + <form action="tftp_files.php" method="POST" enctype="multipart/form-data" name="frmInterfaces" onSubmit=""> + <p><span class="vexpl"><strong>TFTP Daemon Interfaces<br/></strong> + <?=gettext("Choose the interfaces where you want the TFTP daemon to accept connections.");?><br/><br/> + <select name="tftpdinterface[]" multiple="true" class="formselect" size="3"> +<?php + $ifdescs = get_configured_interface_with_descr(); + foreach ($ifdescs as $ifent => $ifdesc): +?> + <option value="<?=$ifent;?>" <?php if (in_array($ifent, $pconfig['tftpdinterface'])) echo "selected"; ?>><?=gettext($ifdesc);?></option> +<?php endforeach; ?> + </select> + <br/><input name="submit" type="submit" class="button" id="save" value="Save"> + </form> + </td> + </tr> + <tr> + <td><p><span class="vexpl"><span class="red"><strong>TFTP files<br /> + </strong></span> + Trivial File Transport Protocol is a very simple file transfer + protocol. Use the file upload to add files to the /tftpboot directory. + Click on the file from the file list below to download it. + </span></p></td> + </tr> + </table> + <br /> <div id="niftyOutter"> <form action="tftp_files.php" method="POST" enctype="multipart/form-data" name="frmUpload" onSubmit=""> - <table> - - <tr> - <td align="right">File to upload:</td> - <td valign="top" class="label"> - <input name="ulfile" type="file" class="button" id="ulfile"> - </td> - </tr> - <tr> - <td valign="top"> </td> - <td valign="top" class="label"> - <input name="submit" type="submit" class="button" id="upload" value="Upload"></td> - </tr> - - </table> + <table> + <tr> + <td align="right">File to upload:</td> + <td valign="top" class="label"> + <input name="ulfile" type="file" class="button" id="ulfile"></td> + </tr> + <tr> + <td valign="top"> </td> + <td valign="top" class="label"> + <input name="submit" type="submit" class="button" id="upload" value="Upload"></td> + </tr> + </table> </div> </form> - <br /> - <br /> - + <br /> + <br /> + <?php echo "<table width='690' cellpadding='0' cellspacing='0' border='0'>\n"; echo "<tr>\n"; @@ -180,76 +202,63 @@ if ($savemsg) { echo "<td width='20%' valign='middle' align='right'>\n"; echo " <input type='button' value='backup' onclick=\"document.location.href='tftp_files.php?a=download&t=backup';\" />\n"; if (file_exists('/root/backup/tftp.bak.tgz')) { - echo " <input type='button' value='restore' onclick=\"document.location.href='tftp_files.php?a=other&t=restore';\" />\n"; + echo " <input type='button' value='restore' onclick=\"document.location.href='tftp_files.php?a=other&t=restore';\" />\n"; } echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; echo "<br /><br />\n\n"; - ?> - - + ?> + + <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="25%" class="listhdrr">File Name (download)</td> <td width="50%" class="listhdr">Last Modified</td> - <td width="50%" class="listhdr">Size</td> + <td width="50%" class="listhdr">Size</td> </tr> - - <?php - if ($handle = opendir('/tftpboot')) { - while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != "..") { - - $tftp_filesize = filesize('/tftpboot/'.$file); - $tftp_filesize = tftp_byte_convert($tftp_filesize); - - echo "<tr>\n"; - echo " <td class=\"listlr\" ondblclick=\"\">\n"; - echo " <a href=\"tftp_files.php?a=download&filename=".$file."\">\n"; - echo " $file"; - echo " </a>"; - echo " </td>\n"; - echo " <td class=\"listlr\" ondblclick=\"\">\n"; - echo date ("F d Y H:i:s", filemtime('/tftpboot/'.$file)); - echo " </td>\n"; - echo " <td class=\"listlr\" ondblclick=\"\">\n"; - echo " ".$tftp_filesize; - echo " </td>\n"; - echo " <td valign=\"middle\" nowrap class=\"list\">\n"; - echo " <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">\n"; - echo " <tr>\n"; - echo " <td valign=\"middle\"><form method='POST' action='/edit.php' target='_blank'><input type='hidden' name='savetopath' value='/tftpboot/".$file."'><input type='hidden' name='submit' value='Load'><input type='image' src=\"/themes/".$g['theme']."/images/icons/icon_e.gif\" width=\"17\" height=\"17\" border=\"0\"></form></td>\n"; - echo " <td><a href=\"tftp_files.php?type=tftp&act=del&filename=".$file."\" onclick=\"return confirm('Do you really want to delete this file?')\"><img src=\"/themes/". $g['theme']."/images/icons/icon_x.gif\" width=\"17\" height=\"17\" border=\"0\"></a></td>\n"; - echo " </tr>\n"; - echo " </table>\n"; - echo " </td>\n"; - echo "</tr>\n"; - - } - } - closedir($handle); - } - ?> - - <tr> - <td class="list" colspan="3"></td> - <td class="list"></td> - </tr> - </table> - - -<br> -<br> -<br> -<br> -<br> -<br> - -</td> -</tr> -</table> +<?php +if ($handle = opendir('/tftpboot')) { + while (false !== ($file = readdir($handle))) { + if ($file != "." && $file != "..") { + $tftp_filesize = filesize('/tftpboot/'.$file); + $tftp_filesize = tftp_byte_convert($tftp_filesize); + echo "<tr>\n"; + echo " <td class=\"listlr\" ondblclick=\"\">\n"; + echo " <a href=\"tftp_files.php?a=download&filename=".$file."\">\n"; + echo " $file"; + echo " </a>"; + echo " </td>\n"; + echo " <td class=\"listlr\" ondblclick=\"\">\n"; + echo date ("F d Y H:i:s", filemtime('/tftpboot/'.$file)); + echo " </td>\n"; + echo " <td class=\"listlr\" ondblclick=\"\">\n"; + echo " ".$tftp_filesize; + echo " </td>\n"; + echo " <td valign=\"middle\" nowrap class=\"list\">\n"; + echo " <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">\n"; + echo " <tr>\n"; + echo " <td valign=\"middle\"><form method='POST' action='/edit.php' target='_blank'><input type='hidden' name='savetopath' value='/tftpboot/".$file."'><input type='hidden' name='submit' value='Load'><input type='image' src=\"/themes/".$g['theme']."/images/icons/icon_e.gif\" width=\"17\" height=\"17\" border=\"0\"></form></td>\n"; + echo " <td><a href=\"tftp_files.php?type=tftp&act=del&filename=".$file."\" onclick=\"return confirm('Do you really want to delete this file?')\"><img src=\"/themes/". $g['theme']."/images/icons/icon_x.gif\" width=\"17\" height=\"17\" border=\"0\"></a></td>\n"; + echo " </tr>\n"; + echo " </table>\n"; + echo " </td>\n"; + echo "</tr>\n"; + } + } + closedir($handle); +} +?> + + <tr> + <td class="list" colspan="3"></td> + <td class="list"></td> + </tr> + </table> + </td> + </tr> +</table> </div> <?php include("fend.inc"); ?> |