diff options
-rw-r--r-- | config/tftp2/tftp.inc | 118 | ||||
-rw-r--r-- | config/tftp2/tftp.xml | 74 | ||||
-rw-r--r-- | config/tftp2/tftp_files.php | 169 | ||||
-rw-r--r-- | pkg_config.10.xml | 2 |
4 files changed, 169 insertions, 194 deletions
diff --git a/config/tftp2/tftp.inc b/config/tftp2/tftp.inc index ea75e0d2..a2b7d1e3 100644 --- a/config/tftp2/tftp.inc +++ b/config/tftp2/tftp.inc @@ -1,23 +1,21 @@ <?php -/* $Id$ */ /* -/* ========================================================================== */ -/* - tftp_inc.php + tftp.inc + part of pfSense (https://www.pfSense.org/) Copyright (C) 2008 Mark J Crane + Copyright (C) 2011 Jim Pingle + Copyright (C) 2015 ESF, LLC 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. + 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. + 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 @@ -30,98 +28,60 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -function tftp_guid() { - if (function_exists('com_create_guid')){ - return com_create_guid(); - }else{ - mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up. - $charid = strtoupper(md5(uniqid(rand(), true))); - $hyphen = chr(45);// "-" - $uuid = chr(123)// "{" - .substr($charid, 0, 8).$hyphen - .substr($charid, 8, 4).$hyphen - .substr($charid,12, 4).$hyphen - .substr($charid,16, 4).$hyphen - .substr($charid,20,12) - .chr(125);// "}" - return $uuid; - } -} - -function tftp_pkg_is_service_running($servicename) { - exec("/bin/ps ax | awk '{ print $5 }'", $psout); - array_shift($psout); - foreach($psout as $line) { - $ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line))))); - } - if(is_service_running($servicename, $ps) or is_process_running($servicename) ) { - return true; - } - else { - return false; - } -} - -function tftp_byte_convert( $bytes ) { - - if ($bytes<=0) +function tftp_byte_convert($bytes) { + if ($bytes <= 0) { return '0 Byte'; - - $convention=1000; //[1000->10^x|1024->2^x] - $s=array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'); - $e=floor(log($bytes,$convention)); - return round($bytes/pow($convention,$e),2).' '.$s[$e]; + } + $convention = 1000; + $s = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'); + $e = floor(log($bytes, $convention)); + return round($bytes/pow($convention, $e), 2) . ' ' . $s[$e]; } function tftp_install_command() { global $config; - conf_mount_rw(); - - if (!is_dir('/tftpboot')) { - // Create the directory - exec("mkdir /tftpboot"); - - //Set the directory permissions - exec("chmod -R 777 /tftpboot"); - } - - if (!is_dir('/root/backup/')) { - // Create the backup directory - exec("mkdir /root/backup/"); - } - // if backup file exists restore it - $filename = 'tftp.bak.tgz'; + $tftpdir = "/tftpboot"; + $tftpbackup = "/root/backup/tftp.bak.tgz"; - //extract a specific directory to /usr/local/freeswitch - if (file_exists('/root/backup/'.$filename)) { - system('cd /; tar xvpfz /root/backup/tftp.bak.tgz'); - system('chmod -R 744 /tftpboot/*'); - unset($filename); + // Create the directories if required + conf_mount_rw(); + safe_mkdir("{$tftpdir}", 0777); + safe_mkdir("/root/backup/"); + + // Restore backup if it exists + if (file_exists($tftpbackup)) { + system("/usr/bin/tar xvpfz {$tftpbackup} -C /"); + system("/bin/chmod -R 0744 {$tftpdir}/*"); + unset($tftpbackup); } + conf_mount_ro(); } function tftp_deinstall_command() { - - //exec("rm -R /tftpboot"); + conf_mount_rw(); unlink_if_exists("/usr/local/etc/rc.d/tftp.sh"); unlink_if_exists("/tmp/pkg_mgr_tftp.log"); + conf_mount_ro(); } function tftp_generate_rules($type) { global $config, $FilterIflist; - if ($type != "nat") + + if ($type != "nat") { return; + } + // Open inetd.conf write handle - $inetd_fd = fopen("/var/etc/inetd.conf","a+"); - /* add tftp daemon */ + $inetd_fd = fopen("/var/etc/inetd.conf", "a+"); + // 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 + // Close file handle + fclose($inetd_fd); if (!empty($config['installedpackages']['tftpd']['config'][0]['tftpdinterface'])) { $tftpifs = explode(",", $config['installedpackages']['tftpd']['config'][0]['tftpdinterface']); - foreach($tftpifs as $tftpif) { + 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"; diff --git a/config/tftp2/tftp.xml b/config/tftp2/tftp.xml index 0a13548c..2a526a4c 100644 --- a/config/tftp2/tftp.xml +++ b/config/tftp2/tftp.xml @@ -2,44 +2,46 @@ <!DOCTYPE packagegui SYSTEM "./schema/packages.dtd"> <?xml-stylesheet type="text/xsl" href="./xsl/package.xsl"?> <packagegui> - <copyright> - <![CDATA[ + <copyright> + <![CDATA[ /* $Id$ */ -/* ========================================================================== */ +/* ====================================================================================== */ /* - tftp.xml - Copyright (C) 2008 Mark J Crane - All rights reserved. - */ -/* ========================================================================== */ + tftp.xml + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2008 Mark J Crane + Copyright (C) 2011 Jim Pingle + Copyright (C) 2015 ESF, LLC + All rights reserved. +*/ +/* ====================================================================================== */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + 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. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 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. - */ -/* ========================================================================== */ - ]]> - </copyright> - <description></description> - <requirements>Describe your package requirements here</requirements> - <faq>Currently there are no FAQ items provided.</faq> + 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. +*/ +/* ====================================================================================== */ + ]]> + </copyright> <name>tftp Settings</name> <version>2.0</version> <title>TFTP: Settings</title> @@ -65,12 +67,10 @@ <configpath>installedpackages->$packagename</configpath> <additional_files_needed> <prefix>/usr/local/pkg/</prefix> - <chmod>0755</chmod> <item>https://packages.pfsense.org/packages/config/tftp2/tftp.inc</item> </additional_files_needed> <additional_files_needed> <prefix>/usr/local/www/</prefix> - <chmod>0755</chmod> <item>https://packages.pfsense.org/packages/config/tftp2/tftp_files.php</item> </additional_files_needed> <custom_php_install_command> @@ -79,5 +79,7 @@ <custom_php_deinstall_command> tftp_deinstall_command(); </custom_php_deinstall_command> - <filter_rules_needed>tftp_generate_rules</filter_rules_needed> -</packagegui>
\ No newline at end of file + <filter_rules_needed> + tftp_generate_rules + </filter_rules_needed> +</packagegui> diff --git a/config/tftp2/tftp_files.php b/config/tftp2/tftp_files.php index 3562cd9f..eebe4c5e 100644 --- a/config/tftp2/tftp_files.php +++ b/config/tftp2/tftp_files.php @@ -1,10 +1,11 @@ <?php -/* $Id$ */ /* - tftp_files.php - Copyright (C) 2008 Mark J Crane - All rights reserved. - + tftp_files.php + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2008 Mark J Crane + Copyright (C) 2011 Jim Pingle + Copyright (C) 2015 ESF, LLC + All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -27,7 +28,6 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - require_once("guiconfig.inc"); require_once("/usr/local/pkg/tftp.inc"); @@ -36,9 +36,9 @@ $backup_dir = "/root/backup"; $backup_filename = "tftp.bak.tgz"; $backup_path = "{$backup_dir}/{$backup_filename}"; $files_dir = "/tftpboot"; - $filename = $_GET['filename']; $download_dir = $files_dir; + if (($_GET['a'] == "download") && $_GET['t'] == "backup") { conf_mount_rw(); $filename = $backup_filename; @@ -46,6 +46,7 @@ if (($_GET['a'] == "download") && $_GET['t'] == "backup") { system("tar -czC / -f {$backup_path} tftpboot"); conf_mount_ro(); } + if (($_GET['a'] == "download") && file_exists("{$download_dir}/{$filename}")) { session_cache_limiter('public'); @@ -55,8 +56,10 @@ if (($_GET['a'] == "download") && file_exists("{$download_dir}/{$filename}")) { header("Content-Type: application/download"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=\"{$filename}\""); - header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 - header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past + /* HTTP/1.1 */ + header("Cache-Control: no-cache, must-revalidate"); + /* Date in the past */ + header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Content-Length: " . filesize("{$download_dir}/{$filename}")); fpassthru($fd); exit; @@ -81,13 +84,15 @@ if ($_GET['a'] == "other") { } } if ($_POST['submit'] == "Save") { - if ($_POST['tftpdinterface']) { + 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']); + write_config(); + send_event("filter reload"); } } @@ -122,7 +127,7 @@ include("head.inc"); <?php $savemsg = $_GET["savemsg"]; if ($savemsg) { - print_info_box($savemsg); + print_info_box($savemsg); } ?> @@ -141,78 +146,81 @@ if ($savemsg) { <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> - <td class="tabcont" > + <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> + <form action="tftp_files.php" method="post" enctype="multipart/form-data" name="frmInterfaces" onsubmit=""> + <p><span class="vexpl"><strong>TFTP Daemon Interfaces</strong></span></p> <?=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 + <select name="tftpdinterface[]" multiple="multiple" 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"> + foreach ($ifdescs as $ifent => $ifdesc) { + $selected = ""; + if (in_array($ifent, $pconfig['tftpdinterface'])) { + $selected = " selected=\"selected\""; + } + echo "\t\t\t<option value=\"{$ifent}\"{$selected}>" . $ifdesc . "</option>\n"; + } + ?> + </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> + <td> + <p><span class="vexpl"><span class="red"><strong>TFTP files</strong></span><br /> + Trivial File Transport Protocol is a very simple file transfer protocol.<br /> + Use the file upload to add files to the /tftpboot directory.<br /> + Click on the file from the file list below to download it.<br /> + </span></p> + </td> </tr> </table> <br /> <div id="niftyOutter"> - <form action="tftp_files.php" method="POST" enctype="multipart/form-data" name="frmUpload" onSubmit=""> + <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> + <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> + <input name="submit" type="submit" class="button" id="upload" value="Upload" /> + </td> </tr> </table> - </div> </form> - - <br /> - <br /> - - <?php - echo "<table width='690' cellpadding='0' cellspacing='0' border='0'>\n"; - echo "<tr>\n"; - echo "<td width='80%'>\n"; - echo "<b>Backup / Restore</b><br />\n"; - echo "The 'backup' button will tar gzip /tftpboot/ to /root/backup/tftp.bak.tgz it then presents a file to download. \n"; - echo "If the backup file does not exist in /root/backup/tftp.bak.tgz then the 'restore' button will be hidden. \n"; - echo "Use Diagnostics->Command->File to upload: to browse to the file and then click on upload it now ready to be restored. \n"; - echo "<br /><br />\n"; - echo "</td>\n"; - 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 "</td>\n"; - echo "</tr>\n"; - echo "</table>\n"; - echo "<br /><br />\n\n"; - ?> - + </div> + <br /><br /> + + <table width='690' cellpadding='0' cellspacing='0' border='0'> + <tr> + <td width='80%'> + <strong>Backup / Restore</strong><br /> + The 'Backup' button compresses /tftpboot/ to /root/backup/tftp.bak.tgz; after that it presents the backup for download.<br /> + If the backup file does not exist in /root/backup/tftp.bak.tgz then the 'Restore' button will be hidden.<br /> + Use Diagnostics -> Command -> File to upload: to browse to the file and then click on upload.<br /> + After that, backup will be ready to be restored.<br /><br /> + </td> + <td width='20%' valign='middle' align='right'> + <input type="button" value="Backup" onclick="document.location.href='tftp_files.php?a=download&t=backup'" /> + <?php + 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"; + } + ?> + </td> + </tr> + </table> + <br /><br /> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> @@ -225,28 +233,33 @@ if ($savemsg) { if ($handle = opendir('/tftpboot')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { - $tftp_filesize = filesize('/tftpboot/'.$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 "<td class=\"listlr\" ondblclick=\"\">"; + echo "<a href=\"tftp_files.php?a=download&filename={$file}\">{$file}</a>"; + echo "</td>\n"; + echo "<td class=\"listlr\" ondblclick=\"\">"; + echo "\t\t" . date("F d Y H:i:s", filemtime('/tftpboot/'. $file)); + echo "</td>\n"; + echo "<td class=\"listlr\" ondblclick=\"\">"; + echo "\t\t{$tftp_filesize}"; + echo "</td>\n"; + echo "<td valign=\"middle\" nowrap=\"nowrap\" class=\"list\">\n"; + echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">\n"; + echo "<tr>\n"; + echo "<td valign=\"middle\">\n"; + echo "\t<form method=\"post\" action=\"/edit.php\" target=\"_blank\"><input type=\"hidden\" name=\"savetopath\" value=\"/tftpboot/{$file}\" />\n"; + echo "\t\t<input type=\"hidden\" name=\"submit\" value=\"Load\" />\n"; + echo "\t\t<input type='image' src=\"/themes/" . $g['theme'] . "/images/icons/icon_e.gif\" />\n"; + echo "\t</form>\n"; + echo "</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?')\">"; + echo "<img src=\"/themes/" . $g['theme'] . "/images/icons/icon_x.gif\" alt=\"\" width=\"17\" height=\"17\" border=\"0\" /></a>"; + echo "</td>\n"; + echo "</tr>\n"; + echo "</table>\n"; + echo "</td>\n"; echo "</tr>\n"; } } diff --git a/pkg_config.10.xml b/pkg_config.10.xml index 9a93695e..6eaf2ddb 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -339,7 +339,7 @@ <pkginfolink/> <port_category>ftp</port_category> <config_file>https://packages.pfsense.org/packages/config/tftp2/tftp.xml</config_file> - <version>2.1</version> + <version>2.2</version> <status>Stable</status> <required_version>2.2</required_version> <configurationfile>tftp.xml</configurationfile> |