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 php_sync_package() { //global $config; //sync_package_tftp_files(); //if (pkg_is_service_running('inetd')) { // sync_package_tftp(); //} } function php_install_command() { global $config; conf_mount_rw(); config_lock(); if (!is_dir('/tftpboot')) { // Create the directory exec("mkdir /tftpboot"); //Set the directory permissions exec("chmod -R 777 /tftpboot"); } if (!is_dir('/usr/local/www/packages/')) { // Create the packages directory exec("mkdir /usr/local/www/packages/"); } if (!is_dir('/usr/local/www/packages/tftp')) { // Create the tftp directory exec("mkdir /usr/local/www/packages/tftp"); } if (!is_dir('/root/backup/')) { // Create the backup directory exec("mkdir /root/backup/"); } //rename PHP files from .tmp to .php exec("cp /tmp/tftp_files.tmp /usr/local/www/packages/tftp/tftp_files.php"); unlink_if_exists("/tmp/tftp_files.tmp"); //prepare inetd.conf for tftp $filename = "/etc/inetd.conf"; $handle = fopen($filename,"rb"); $contents = fread($handle, filesize($filename)); fclose($handle); $handle = fopen($filename,"w"); $contents = str_replace("#tftp", "tftp", $contents); fwrite($handle, $contents); unset($contents); fclose($handle); unset($filename); // add a TFTP DHCP Option to the DHCP Server $filename = "/usr/local/www/services_dhcp.php"; $fout = fopen($filename,"r"); $tmp = fread($fout, filesize($filename)); fclose($fout); //tftp was not found in the string if (strpos($tmp, "tftp") === false) { $tmpsearch = "\$pconfig['netmask'] = \$config['dhcpd'][\$if]['netmask'];"; $tmpreplace = "\$pconfig['netmask'] = \$config['dhcpd'][\$if]['netmask'];\n"; $tmpreplace .= "\$pconfig['tftp'] = \$config['dhcpd'][\$if]['options']['tftp-server-name'];"; $tmp = str_replace($tmpsearch, $tmpreplace, $tmp); unset($tmpsearch, $tmpreplace); $tmpsearch = "\$config['dhcpd'][\$if]['filename'] = \$_POST['filename'];"; $tmpreplace = "\$config['dhcpd'][\$if]['filename'] = \$_POST['filename'];\n"; $tmpreplace .= " \$config['dhcpd'][\$if]['options']['tftp-server-name'] = \$_POST['tftp'];"; $tmp = str_replace($tmpsearch, $tmpreplace, $tmp); unset($tmpsearch, $tmpreplace); $tmpsearch = "function show_netboot_config() {"; $tmpreplace = "function show_tftp_config() {\n"; $tmpreplace .= " document.getElementById(\"showtftpbox\").innerHTML='';\n"; $tmpreplace .= " aodiv = document.getElementById('showtftp');\n"; $tmpreplace .= " aodiv.style.display = \"block\";\n"; $tmpreplace .= "}\n"; $tmpreplace .= "\n"; $tmpreplace .= "function show_netboot_config() {"; $tmp = str_replace($tmpsearch, $tmpreplace, $tmp); unset($tmpsearch, $tmpreplace); $tmpsearch = "