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]; } 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'; //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); } } function tftp_deinstall_command() { //exec("rm -R /tftpboot"); unlink_if_exists("/usr/local/etc/rc.d/tftp.sh"); unlink_if_exists("/tmp/pkg_mgr_tftp.log"); } function tftp_generate_rules($type) { global $config, $FilterIflist; if ($type != "nat") return; // Open inetd.conf write handle $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 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; } ?>