From b407b3896374abdeb6bf488e83a1f7a1b5b39639 Mon Sep 17 00:00:00 2001 From: jim-p Date: Mon, 16 May 2011 12:51:27 -0400 Subject: Misc TFTP package fixes. Whitespace, interface selection, adding nat rules, fixing broken links. --- config/tftp2/tftp.inc | 13 +++ config/tftp2/tftp_files.php | 261 +++++++++++++++++++++++--------------------- 2 files changed, 148 insertions(+), 126 deletions(-) (limited to 'config/tftp2') 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) {
- - + \n"; @@ -180,76 +202,63 @@ if ($savemsg) { echo "\n"; echo "\n"; echo "
- - - - - -

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 Daemon Interfaces
+

+ +
+ +

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: - -
    -
+ + + + + + + + + +
File to upload: +
    +
-
-
- +
+
+ \n"; echo "
\n"; echo " \n"; if (file_exists('/root/backup/tftp.bak.tgz')) { - echo " \n"; + echo " \n"; } echo "
\n"; echo "

\n\n"; - ?> - - + ?> + + - + - - \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "\n"; - - } - } - closedir($handle); - } - ?> - - - - - -
File Name (download) Last ModifiedSizeSize
\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 "
- - -
-
-
-
-
-
- - - - +\n"; + echo " \n"; + echo " \n"; + echo " $file"; + echo " "; + echo " \n"; + echo " \n"; + echo date ("F d Y H:i:s", filemtime('/tftpboot/'.$file)); + echo " \n"; + echo " \n"; + echo " ".$tftp_filesize; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " \n"; + echo "\n"; + } + } + closedir($handle); +} +?> + + + + + + + + + -- cgit v1.2.3