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/tftp')) { // Create the directory exec("mkdir /usr/local/www/tftp"); } //rename PHP files from .tmp to .php exec("cp /tmp/tftp_files.tmp /usr/local/www/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 dgram udp wait root /usr/libexec/tftpd", "tftp dgram udp wait root /usr/libexec/tftpd", $contents); fwrite($handle, $contents); unset($contents); fclose($handle); unset($filename); // if backup file exists restore it $filename = 'tftp.bak.tgz'; //extract a specific directory to /usr/local/freeswitch if (file_exists('/tmp/'.$filename)) { system('cd /; tar xvpfz /tmp/tftp.bak.tgz'); system('chmod -R 744 /tftpboot/*'); unset($filename); } write_rcfile(array( "file" => "tftp.sh", "start" => "/usr/sbin/inetd", "stop" => "killall -9 inetd" ) ); //php_sync_package(); $handle = popen("/usr/sbin/inetd", "r"); pclose($handle); //if (pkg_is_service_running('inetd')) { // temp_sync_package(); //} //conf_mount_ro(); //config_unlock(); } function php_deinstall_command() { //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 dgram udp wait root /usr/libexec/tftpd", "#tftp dgram udp wait root /usr/libexec/tftpd", $contents); fwrite($handle, $contents); unset($contents); fclose($fout); unset($filename); exec("killall -9 inetd"); unlink_if_exists("/usr/local/pkg/tftp.xml"); unlink_if_exists("/usr/local/pkg/tftp.inc"); unlink_if_exists("/usr/local/www/tftp/tftp_files.php"); exec("rm -R /tftpboot"); unlink_if_exists("/usr/local/etc/rc.d/tftp.sh"); unlink_if_exists("/tmp/pkg_mgr_tftp.log"); } ?>