From cf7c10fa2dafb84bbd4f83efd67e8c6bae2ec50c Mon Sep 17 00:00:00 2001 From: doktornotor Date: Thu, 6 Aug 2015 08:33:49 +0200 Subject: tftp.xml - style cleanup - fix copyright header - fix file permissions - indentation --- config/tftp2/tftp.xml | 74 ++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) 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 @@ - - + - - - Describe your package requirements here - Currently there are no FAQ items provided. + 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. +*/ +/* ====================================================================================== */ + ]]> + tftp Settings 2.0 TFTP: Settings @@ -65,12 +67,10 @@ installedpackages->$packagename /usr/local/pkg/ - 0755 https://packages.pfsense.org/packages/config/tftp2/tftp.inc /usr/local/www/ - 0755 https://packages.pfsense.org/packages/config/tftp2/tftp_files.php @@ -79,5 +79,7 @@ tftp_deinstall_command(); - tftp_generate_rules - \ No newline at end of file + + tftp_generate_rules + + -- cgit v1.2.3 From 90a594d7e2cd1ed85df26b952ce3af73305b41b9 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Thu, 6 Aug 2015 08:38:48 +0200 Subject: tftp.inc - code improvements and cleanup - Fix copyright header - Remove unused functions - Use safe_mkdir() - Improve the backup restore code - Indentation and code style fixes --- config/tftp2/tftp.inc | 118 +++++++++++++++++--------------------------------- 1 file changed, 39 insertions(+), 79 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 @@ 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"; -- cgit v1.2.3 From 06f946b33bf7a6e7f49d7ed467fdc27eba919f49 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Thu, 6 Aug 2015 08:42:47 +0200 Subject: tftp_files.php - major code cleanup and fixes - fix copyright header - fix code indentation - XHTML valid code - make it possible to actually unset the selected TFTPD interfaces --- config/tftp2/tftp_files.php | 169 ++++++++++++++++++++++++-------------------- 1 file changed, 91 insertions(+), 78 deletions(-) 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 @@ @@ -141,78 +146,81 @@ if ($savemsg) { - \n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "
+ - - +
-
-

TFTP Daemon Interfaces
+ +

TFTP Daemon Interfaces



- -
+ foreach ($ifdescs as $ifent => $ifdesc) { + $selected = ""; + if (in_array($ifent, $pconfig['tftpdinterface'])) { + $selected = " selected=\"selected\""; + } + echo "\t\t\t\n"; + } + ?> +
+

TFTP files
-
- 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. -

+

TFTP files
+ 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.
+

+

-
+ + + + +
File to upload: -
    -
-
- -
-
- - \n"; - echo "
\n"; - echo "Backup / Restore
\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 "

\n"; - echo "
\n"; - echo " \n"; - if (file_exists('/root/backup/tftp.bak.tgz')) { - echo " \n"; - } - echo "
\n"; - echo "

\n\n"; - ?> - + +

+ + + + + + +
+ Backup / Restore
+ The 'Backup' button compresses /tftpboot/ to /root/backup/tftp.bak.tgz; after that it presents the backup for download.
+ If the backup file does not exist in /root/backup/tftp.bak.tgz then the 'Restore' button will be hidden.
+ Use Diagnostics -> Command -> File to upload: to browse to the file and then click on upload.
+ After that, backup will be ready to be restored.

+
+ + \n"; + } + ?> +
+

@@ -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 "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; } } -- cgit v1.2.3 From dde5afd76972bdea693fe27119d58808991a3277 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Thu, 6 Aug 2015 08:44:58 +0200 Subject: Bump tftp package version --- pkg_config.10.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg_config.10.xml b/pkg_config.10.xml index 60f28e41..a3363607 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -329,7 +329,7 @@ ftp https://packages.pfsense.org/packages/config/tftp2/tftp.xml - 2.1 + 2.2 Stable 2.2 tftp.xml -- cgit v1.2.3
\n"; - echo " \n"; - echo " $file"; - echo " "; - echo " \n"; - echo date ("F d Y H:i:s", filemtime('/tftpboot/'.$file)); - echo " \n"; - echo " ".$tftp_filesize; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
"; + echo "{$file}"; + echo ""; + echo "\t\t" . date("F d Y H:i:s", filemtime('/tftpboot/'. $file)); + echo ""; + echo "\t\t{$tftp_filesize}"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "\t
\n"; + echo "\t\t\n"; + echo "\t\t\n"; + echo "\t
\n"; + echo "
"; + echo "\"\""; + echo "
\n"; + echo "