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 phpservice_sync_package_php() { global $config; if($config['installedpackages']['phpservice']['config'] != "") { conf_mount_rw(); config_unlock(); $tmp = "\\n\";\n"; $tmp .= " } else {\n"; $tmp .= " fwrite(\$fp, \$syslogmsg);\n"; $tmp .= " fclose(\$fp);\n"; $tmp .= " }\n"; $tmp .= "\n"; $tmp .= "}\n"; $tmp .= "\n"; $tmp .= "\n"; $tmp .= "//\$msg = \"1.begin loop. \".date('r').\"\\n\";\n"; $tmp .= "//\$fp = fopen('/tmp/phpmonitor.txt', 'a');\n"; $tmp .= "//fwrite(\$fp, \$msg.\"\\n\");\n"; $tmp .= "//fclose(\$fp);\n"; $tmp .= "\n"; $tmp .= "\$x = 0;\n"; $tmp .= "while(\$x == 0) {\n"; $tmp .= "\n"; $tmp .= "\n"; $tmp .= " if(!file_exists('/tmp/phpmonitor.pid')) {\n"; $tmp .= " //if the file does not exist then close the program.\n"; $tmp .= " echo \"program closing\\n\";\n"; $tmp .= " return;\n"; $tmp .= " }\n"; $tmp .= "\n"; $tmp .= "\n"; $tmp .= "//------------------------------------------\n"; foreach($config['installedpackages']['phpservice']['config'] as $rowhelper) { $tmp .= base64_decode($rowhelper['php']); $tmp .= "\n"; $tmp .= "//------------------------------------------\n"; } $tmp .= "\n"; $tmp .= "\n"; $tmp .= " //usleep(100000); //micro seconds //2 seconds 2000000\n"; $tmp .= " sleep(1); //in seconds\n"; $tmp .= " //if (\$x > 60){ exit; } //exit after 60 seconds for testing\n"; $tmp .= "} //emd while\n"; $tmp .= "\n"; $tmp .= "\n"; $tmp .= "?>"; $fout = fopen("/usr/local/pkg/phpservice.php","w"); fwrite($fout, $tmp); unset($tmp); fclose($fout); conf_mount_ro(); } } function phpservice_sync_package() { global $config; phpservice_sync_package_php(); if (!is_dir('/usr/local/www/packages/phpservice/')) { exec("mkdir /usr/local/www/packages/phpservice/"); } } function php_install_command() { global $config; conf_mount_rw(); config_lock(); if (!is_dir('/usr/local/www/packages/phpservice/')) { exec("mkdir /usr/local/www/packages/phpservice/"); } //rename PHP files from .tmp to .php exec("cp /tmp/phpservice_php.tmp /usr/local/www/packages/phpservice/phpservice_php.php"); unlink_if_exists("/tmp/phpservice_php.tmp"); exec("cp /tmp/phpservice_php_edit.tmp /usr/local/www/packages/phpservice/phpservice_php_edit.php"); unlink_if_exists("/tmp/phpservice_php_edit.tmp"); //write_config(); write_rcfile(array( "file" => "phpservice.sh", "start" => "/usr/local/bin/php /usr/local/pkg/phpservice.php", "stop" => "rm /tmp/phpmonitor.pid" ) ); phpservice_sync_package(); $handle = popen("/usr/local/etc/rc.d/phpservice.sh start", "r"); pclose($handle); //if (pkg_is_service_running('phpservice')) { //documentation purposes //} conf_mount_ro(); config_unlock(); } function deinstall_command() { conf_mount_rw(); config_lock(); $handle = popen("/usr/local/etc/rc.d/phpservice.sh stop", "r"); unlink_if_exists("/usr/local/pkg/phpservice.xml"); unlink_if_exists("/usr/local/pkg/phpservice.inc"); unlink_if_exists("/usr/local/www/phpservice.inc"); unlink_if_exists("/usr/local/etc/rc.d/phpservice.sh"); conf_mount_ro(); config_unlock(); } ?>