private static function core_storage_init_process() { $pso = pts_storage_object::recover_from_file(PTS_CORE_STORAGE); if ($pso == false) { $pso = new pts_storage_object(true, true); } // OpenBenchmarking.org - GSID $global_gsid = $pso->read_object('global_system_id'); $global_gsid_e = $pso->read_object('global_system_id_e'); $global_gsid_p = $pso->read_object('global_system_id_p'); if (empty($global_gsid) || pts_openbenchmarking::is_valid_gsid_format($global_gsid) == false) { // Global System ID for anonymous uploads, etc $requested_gsid = true; $global_gsid = pts_openbenchmarking_client::request_gsid(); if (is_array($global_gsid)) { $pso->add_object('global_system_id', $global_gsid['gsid']); // GSID $pso->add_object('global_system_id_p', $global_gsid['gsid_p']); // GSID_P $pso->add_object('global_system_id_e', $global_gsid['gsid_e']); // GSID_E pts_define('PTS_GSID', $global_gsid['gsid']); pts_define('PTS_GSID_E', $global_gsid['gsid_e']); } } else { if (pts_openbenchmarking::is_valid_gsid_e_format($global_gsid_e) == false || pts_openbenchmarking::is_valid_gsid_p_format($global_gsid_p) == false) { pts_define('PTS_GSID', $global_gsid); $requested_gsid = false; $global_gsid = pts_openbenchmarking_client::retrieve_gsid(); if (is_array($global_gsid)) { $pso->add_object('global_system_id_p', $global_gsid['gsid_p']); // GSID_P $pso->add_object('global_system_id_e', $global_gsid['gsid_e']); // GSID_E pts_define('PTS_GSID_E', $global_gsid['gsid_e']); } } else { pts_define('PTS_GSID', $global_gsid); pts_define('PTS_GSID_E', $global_gsid_e); $requested_gsid = false; } } $machine_self_id = $pso->read_object('machine_self_id'); if (empty($machine_self_id)) { $ns = md5('phoronix-test-suite'); $binary_ns = null; for ($i = 0; $i < strlen($ns); $i += 2) { $binary_ns .= chr(hexdec($ns[$i] . $ns[$i + 1])); } $msi_hash = sha1($binary_ns . uniqid(PTS_CORE_VERSION, true) . getenv('USERNAME') . getenv('USER') . getenv('HOSTNAME') . pts_network::get_local_ip()); $machine_self_id = sprintf('%08s-%04s-%04x-%04x-%12s', substr($msi_hash, 0, 8), substr($msi_hash, 8, 4), hexdec(substr($msi_hash, 12, 4)) & 0xfff | 0x5000, hexdec(substr($msi_hash, 16, 4)) & 0x3fff | 0x8000, substr($msi_hash, 20, 12)); // machine_self_id is self-generated unique name for Phoromatic/OB purposes in UUIDv5 format $pso->add_object('machine_self_id', $machine_self_id); } pts_define('PTS_MACHINE_SELF_ID', $machine_self_id); // Last Run Processing $last_core_version = $pso->read_object('last_core_version'); pts_define('FIRST_RUN_ON_PTS_UPGRADE', $last_core_version != PTS_CORE_VERSION); if (FIRST_RUN_ON_PTS_UPGRADE || $pso->read_object('last_php_version') != PTS_PHP_VERSION) { // Report any missing/recommended extensions self::program_requirement_checks(); } if (FIRST_RUN_ON_PTS_UPGRADE) { if ($requested_gsid == false) { pts_openbenchmarking_client::update_gsid(); } pts_client::build_temp_cache(); } $pso->add_object('last_core_version', PTS_CORE_VERSION); // PTS version last run $pso->add_object('last_php_version', PTS_PHP_VERSION); // PHP version last run //$last_pts_version = $pso->read_object('last_pts_version'); // do something here with $last_pts_version if you want that information $pso->add_object('last_pts_version', PTS_VERSION); // PTS version last run // Last Run Processing $last_run = $pso->read_object('last_run_time'); pts_define('IS_FIRST_RUN_TODAY', substr($last_run, 0, 10) != date('Y-m-d')); $pso->add_object('last_run_time', date('Y-m-d H:i:s')); // Time PTS was last run pts_define('TIME_SINCE_LAST_RUN', ceil((time() - strtotime($last_run)) / 60)); // TIME_SINCE_LAST_RUN is in minutes // User Agreement Checking $agreement_cs = $pso->read_object('user_agreement_cs'); $pso->add_object('user_agreement_cs', $agreement_cs); // User agreement check-sum // Phodevi Cache Handling $phodevi_cache = $pso->read_object('phodevi_smart_cache'); if ($phodevi_cache instanceof phodevi_cache && pts_client::read_env('NO_PHODEVI_CACHE') == false) { $phodevi_cache = $phodevi_cache->restore_cache(PTS_USER_PATH, PTS_CORE_VERSION); phodevi::set_device_cache($phodevi_cache); if ($external_phodevi_cache = pts_client::read_env('EXTERNAL_PHODEVI_CACHE')) { if (is_dir($external_phodevi_cache) && is_file($external_phodevi_cache . '/core.pt2so')) { $external_phodevi_cache .= '/core.pt2so'; } if (is_file($external_phodevi_cache)) { $external_phodevi_cache = pts_storage_object::force_recover_from_file($external_phodevi_cache); if ($external_phodevi_cache != false) { $external_phodevi_cache = $external_phodevi_cache->read_object('phodevi_smart_cache'); $external_phodevi_cache = $external_phodevi_cache->restore_cache(null, PTS_CORE_VERSION); if ($external_phodevi_cache != false) { //unset($external_phodevi_cache['system']['operating-system']); //unset($external_phodevi_cache['system']['vendor-identifier']); phodevi::set_device_cache($external_phodevi_cache); } } } } } // Archive to disk $pso->save_to_file(PTS_CORE_STORAGE); }
public static function run($r) { if (pts_client::create_lock(PTS_USER_PATH . 'phoromatic_server_lock') == false) { trigger_error('The Phoromatic Server is already running.', E_USER_ERROR); return false; } pts_file_io::unlink(getenv('PTS_EXT_LAUNCH_SCRIPT_DIR') . '/phoromatic-server-launcher'); if (PHP_VERSION_ID < 50400) { echo 'Running an unsupported PHP version. PHP 5.4+ is required to use this feature.' . PHP_EOL . PHP_EOL; return false; } if (!function_exists('socket_create_listen')) { echo 'PHP Sockets support is needed to use the Phoromatic Server.' . PHP_EOL . PHP_EOL; return false; } $server_launcher = '#!/bin/sh' . PHP_EOL; $web_port = 0; $remote_access = pts_config::read_user_config('PhoronixTestSuite/Options/Server/RemoteAccessPort', 'RANDOM'); $fp = false; $errno = null; $errstr = null; if ($remote_access == 'RANDOM') { do { if ($fp) { fclose($fp); } $remote_access = rand(8000, 8999); } while (($fp = fsockopen('127.0.0.1', $remote_access, $errno, $errstr, 5)) != false); echo 'Port ' . $remote_access . ' chosen as random port for this instance. Change the default port via the Phoronix Test Suite user configuration file.' . PHP_EOL; } $remote_access = is_numeric($remote_access) && $remote_access > 1 ? $remote_access : false; $blocked_ports = array(2049, 3659, 4045, 6000, 9000); if ($remote_access) { // ALLOWING SERVER TO BE REMOTELY ACCESSIBLE $server_ip = '0.0.0.0'; if (($fp = fsockopen('127.0.0.1', $remote_access, $errno, $errstr, 5)) != false) { fclose($fp); trigger_error('Port ' . $remote_access . ' is already in use by another server process. Close that process or change the Phoronix Test Suite server port via' . pts_config::get_config_file_location() . ' to proceed.', E_USER_ERROR); return false; } else { $web_port = $remote_access; $web_socket_port = pts_config::read_user_config('PhoronixTestSuite/Options/Server/WebSocketPort', ''); while ($web_socket_port == null || !is_numeric($web_socket_port) || ($fp = fsockopen('127.0.0.1', $web_socket_port, $errno, $errstr, 5)) != false) { if ($fp) { fclose($fp); } $web_socket_port = rand(8000, 8999); } } } else { echo PHP_EOL . PHP_EOL . 'You must first configure the remote web / Phoromatic settings via:' . PHP_EOL . ' ' . pts_config::get_config_file_location() . PHP_EOL . PHP_EOL . 'The RemoteAccessPort should be a network port to use for HTTP communication while WebSocketPort should be set to another available network port. Set to RANDOM if wishing to use randomly chosen available ports.' . PHP_EOL . PHP_EOL; return false; } if (!extension_loaded('sqlite3')) { echo PHP_EOL . PHP_EOL . 'PHP SQLite3 support must first be enabled before accessing the Phoromatic server (e.g. installing the php5-sqlite or php-pdo package depending on the distribution).' . PHP_EOL . PHP_EOL; return false; } // Setup server logger define('PHOROMATIC_SERVER', true); // Just create the logger so now it will flush it out $pts_logger = new pts_logger(); $pts_logger->clear_log(); echo pts_core::program_title(true) . ' starting Phoromatic Server' . PHP_EOL; $pts_logger->log(pts_core::program_title(true) . ' starting Phoromatic Server on ' . pts_network::get_local_ip()); echo 'Phoronix Test Suite User-Data Directory Path: ' . PTS_USER_PATH . PHP_EOL; echo 'Phoronix Test Suite Configuration File: ' . pts_config::get_config_file_location() . PHP_EOL; echo 'Phoromatic Server Log File: ' . $pts_logger->get_log_file_location() . PHP_EOL; $pts_logger->log('PTS_USER_PATH = ' . PTS_USER_PATH); $pts_logger->log('PTS_DOWNLOAD_CACHE_PATH = ' . PTS_DOWNLOAD_CACHE_PATH); $pts_logger->log('XML Configuration File = ' . pts_config::get_config_file_location()); // WebSocket Server Setup $server_launcher .= 'export PTS_WEB_PORT=' . $web_port . PHP_EOL; $server_launcher .= 'export PTS_WEBSOCKET_PORT=' . $web_socket_port . PHP_EOL; $server_launcher .= 'export PTS_WEBSOCKET_SERVER=PHOROMATIC' . PHP_EOL; $server_launcher .= 'export PTS_NO_FLUSH_LOGGER=1' . PHP_EOL; $server_launcher .= 'export PTS_PHOROMATIC_SERVER=1' . PHP_EOL; $server_launcher .= 'export PTS_PHOROMATIC_LOG_LOCATION=' . $pts_logger->get_log_file_location() . PHP_EOL; $server_launcher .= 'cd ' . getenv('PTS_DIR') . ' && PTS_MODE="CLIENT" ' . getenv('PHP_BIN') . ' pts-core/phoronix-test-suite.php start-ws-server &' . PHP_EOL; $server_launcher .= 'websocket_server_pid=$!' . PHP_EOL; $pts_logger->log('Starting WebSocket process on port ' . $web_socket_port); $server_launcher .= 'cd ' . getenv('PTS_DIR') . ' && PTS_MODE="CLIENT" ' . getenv('PHP_BIN') . ' pts-core/phoronix-test-suite.php start-phoromatic-event-server &' . PHP_EOL; $server_launcher .= 'event_server_pid=$!' . PHP_EOL; // HTTP Server Setup if (false && pts_client::executable_in_path('nginx') && is_file('/run/php-fpm/php-fpm.pid')) { // NGINX $nginx_conf = 'error_log /tmp/error.log; pid /tmp/nginx.pid; worker_processes 1; events { worker_connections 1024; } http { client_body_temp_path /tmp/client_body; fastcgi_temp_path /tmp/fastcgi_temp; proxy_temp_path /tmp/proxy_temp; scgi_temp_path /tmp/scgi_temp; uwsgi_temp_path /tmp/uwsgi_temp; tcp_nopush on; tcp_nodelay on; keepalive_timeout 180; types_hash_max_size 2048; include /etc/nginx/mime.types; index index.php; server { listen ' . $web_port . '; listen [::]:' . $web_port . ' default ipv6only=on; access_log /tmp/access.log; error_log /tmp/error.log; root ' . PTS_CORE_PATH . 'phoromatic/public_html; index index.php; try_files $uri $uri/ /index.php; location / { autoindex on; } location ~ \\.php$ { include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; fastcgi_split_path_info ^(.+\\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; } } }'; $nginx_conf_file = tempnam(PTS_USER_PATH, 'nginx_conf_'); file_put_contents($nginx_conf_file, $nginx_conf); $server_launcher .= 'nginx -c ' . $nginx_conf_file . PHP_EOL . 'rm -f ' . $nginx_conf_file . PHP_EOL; } else { if (($mongoose = pts_client::executable_in_path('mongoose')) && ($php_cgi = pts_client::executable_in_path('php-cgi'))) { // Mongoose Embedded Web Server $server_launcher .= $mongoose . ' -p ' . $web_port . ' -r ' . PTS_CORE_PATH . 'phoromatic/public_html/ -I ' . $php_cgi . ' -i index.php > /dev/null 2>> $PTS_PHOROMATIC_LOG_LOCATION &' . PHP_EOL; //2> /dev/null } else { if (strpos(getenv('PHP_BIN'), 'hhvm')) { echo PHP_EOL . 'Unfortunately, the HHVM built-in web server has abandoned upstream. Users will need to use the PHP binary or other alternatives.' . PHP_EOL . PHP_EOL; return; } else { // PHP Web Server $server_launcher .= getenv('PHP_BIN') . ' -S ' . $server_ip . ':' . $web_port . ' -t ' . PTS_CORE_PATH . 'phoromatic/public_html/ > /dev/null 2>> $PTS_PHOROMATIC_LOG_LOCATION &' . PHP_EOL; //2> /dev/null } } } $server_launcher .= 'http_server_pid=$!' . PHP_EOL; $server_launcher .= 'sleep 1' . PHP_EOL; $server_launcher .= 'echo "The Phoromatic Web Interface Is Accessible At: http://localhost:' . $web_port . '"' . PHP_EOL; $pts_logger->log('Starting HTTP process @ http://localhost:' . $web_port); // Avahi for zeroconf network discovery support if (pts_config::read_user_config('PhoronixTestSuite/Options/Server/AdvertiseServiceZeroConf', 'TRUE')) { if (is_dir('/etc/avahi/services') && is_writable('/etc/avahi/services')) { file_put_contents('/etc/avahi/services/phoromatic-server.service', '<?xml version="1.0" standalone=\'no\'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">phoromatic-server-%h</name> <service> <type>_http._tcp</type> <port>' . $web_port . '</port> </service> </service-group>'); } else { if (pts_client::executable_in_path('avahi-publish')) { $hostname = phodevi::read_property('system', 'hostname'); $hostname = $hostname == null ? rand(0, 99) : $hostname; $server_launcher .= 'avahi-publish -s phoromatic-server-' . $hostname . ' _http._tcp ' . $web_port . ' "Phoronix Test Suite Phoromatic" > /dev/null 2> /dev/null &' . PHP_EOL; $server_launcher .= 'avahi_publish_pid=$!' . PHP_EOL; } } } // Wait for input to shutdown process.. if (!PTS_IS_DAEMONIZED_SERVER_PROCESS) { $server_launcher .= PHP_EOL . 'echo -n "Press [ENTER] to kill server..."' . PHP_EOL; $server_launcher .= PHP_EOL . 'read var_name'; } else { $server_launcher .= PHP_EOL . 'while [ ! -f "/var/lib/phoronix-test-suite/end-phoromatic-server" ];'; $server_launcher .= PHP_EOL . 'do'; $server_launcher .= PHP_EOL . 'sleep 1'; $server_launcher .= PHP_EOL . 'done'; $server_launcher .= PHP_EOL . 'rm -f /var/lib/phoronix-test-suite/end-phoromatic-server' . PHP_EOL; } // Shutdown / Kill Servers $server_launcher .= PHP_EOL . 'kill $http_server_pid'; $server_launcher .= PHP_EOL . 'kill $websocket_server_pid'; $server_launcher .= PHP_EOL . 'kill $event_server_pid'; if (is_writable('/etc/avahi/services') && is_file('/etc/avahi/services/phoromatic-server.service')) { $server_launcher .= PHP_EOL . 'rm -f /etc/avahi/services/phoromatic-server.service'; } else { $server_launcher .= PHP_EOL . 'kill $avahi_publish_pid'; } $server_launcher .= PHP_EOL . 'rm -f ~/.phoronix-test-suite/run-lock*'; file_put_contents(getenv('PTS_EXT_LAUNCH_SCRIPT_DIR') . '/phoromatic-server-launcher', $server_launcher); }
function phoromatic_web_socket_server_ip() { $server_ip = $_SERVER['HTTP_HOST']; if (($x = strpos($server_ip, ':')) !== false) { $server_ip = substr($server_ip, 0, $x); } if ($server_ip == 'localhost' || $server_ip == '0.0.0.0') { $local_ip = pts_network::get_local_ip(); if ($local_ip) { $server_ip = $local_ip; } } // getenv('PTS_WEBSOCKET_PORT') return $server_ip . ':' . $_SERVER['SERVER_PORT']; }
protected static function upload_to_remote_server($to_post, $server_address = null, $server_http_port = null, $account_id = null) { static $last_communication_minute = null; static $communication_attempts = 0; if ($last_communication_minute == date('i') && $communication_attempts > 8) { // Something is wrong, Phoromatic shouldn't be communicating with server more than four times a minute return false; } else { if (date('i') != $last_communication_minute) { $last_communication_minute = date('i'); $communication_attempts = 0; } $communication_attempts++; } if ($server_address == null && self::$server_address != null) { $server_address = self::$server_address; } if ($server_http_port == null && self::$server_http_port != null) { $server_http_port = self::$server_http_port; } if ($account_id == null && self::$account_id != null) { $account_id = self::$account_id; } $to_post['aid'] = $account_id; $to_post['pts'] = PTS_VERSION; $to_post['pts_core'] = PTS_CORE_VERSION; $to_post['gsid'] = defined('PTS_GSID') ? PTS_GSID : null; $to_post['lip'] = pts_network::get_local_ip(); $to_post['h'] = phodevi::system_hardware(true); $to_post['nm'] = pts_network::get_network_mac(); $to_post['nw'] = implode(', ', pts_network::get_network_wol()); $to_post['s'] = phodevi::system_software(true); $to_post['n'] = phodevi::read_property('system', 'hostname'); $to_post['msi'] = PTS_MACHINE_SELF_ID; return pts_network::http_upload_via_post('http://' . $server_address . ':' . $server_http_port . '/phoromatic.php', $to_post); }