public static function run($r) { $force_options = array('PhoronixTestSuite/Options/OpenBenchmarking/AnonymousUsageReporting' => 'FALSE'); if (pts_network::internet_support_available() == false) { $force_options['PhoronixTestSuite/Options/Networking/NoInternetCommunication'] = 'TRUE'; } pts_config::user_config_generate($force_options); $pso = pts_storage_object::recover_from_file(PTS_CORE_STORAGE); $pso->add_object('user_agreement_cs', 'enterprise-agree'); $pso->save_to_file(PTS_CORE_STORAGE); echo PHP_EOL . 'Enterprise setup tasks executed.' . PHP_EOL . PHP_EOL; }
public static function __pre_option_process() { // Once a day check for new version if (IS_FIRST_RUN_TODAY && pts_network::internet_support_available()) { // Check For pts-core updates $latest_reported_version = pts_network::http_get_contents('http://www.phoronix-test-suite.com/LATEST'); $current_e = explode('.', PTS_VERSION); $latest_e = explode('.', $latest_reported_version); if ($latest_reported_version != PTS_VERSION && $latest_e[0] >= $current_e[0] && ($latest_e[1] > $current_e[1] || $latest_e[1] == $current_e[1] && $latest_e[2] >= $current_e[2])) { // New version of PTS is available pts_client::$display->generic_heading('An outdated version of the Phoronix Test Suite is installed.' . PHP_EOL . 'The version in use is v' . PTS_VERSION . ', but the latest is v' . $latest_reported_version . '.' . PHP_EOL . 'Visit http://www.phoronix-test-suite.com/ to update this software.'); } } return pts_module::MODULE_UNLOAD; // This module doesn't have anything else to do }
public static function run($r) { pts_client::$display->generic_heading('Network Setup'); if (!pts_user_io::prompt_bool_input('Configure the Phoronix Test Suite to use a HTTP proxy', false)) { return false; } $proxy_address = pts_user_io::prompt_user_input('Enter IP address / server name of proxy'); $proxy_port = pts_user_io::prompt_user_input('Enter TCP port for proxy server'); echo PHP_EOL . 'Testing Proxy Server (' . $proxy_address . ':' . $proxy_port . ')' . PHP_EOL; if (pts_network::http_get_contents('http://www.phoronix-test-suite.com/PTS', $proxy_address, $proxy_port) == 'PTS') { echo PHP_EOL . 'Proxy Setup Completed; Storing Network Settings.' . PHP_EOL; pts_config::user_config_generate(array('PhoronixTestSuite/Options/Networking/ProxyAddress' => $proxy_address, 'PhoronixTestSuite/Options/Networking/ProxyPort' => $proxy_port)); } else { echo PHP_EOL . 'Proxy Setup Failed.' . PHP_EOL; } }
protected function send_wol_wakeup($mac, $ip) { $sent_wol_request = false; if (PTS_IS_DAEMONIZED_SERVER_PROCESS) { foreach (array('etherwake', 'ether-wake') as $etherwake) { if (pts_client::executable_in_path($etherwake)) { shell_exec($etherwake . ' ' . $mac . ' 2>&1'); $sent_wol_request = true; sleep(5); break; } } } if (true || $sent_wol_request == false) { pts_network::send_wol_packet($ip, $mac); $sent_wol_request = true; } return $sent_wol_request; }
public static function run($r) { foreach (pts_types::identifiers_to_test_profile_objects($r, true, true) as $test_profile) { echo 'Checking: ' . $test_profile . PHP_EOL; foreach (pts_test_install_request::read_download_object_list($test_profile) as $test_file_download) { foreach ($test_file_download->get_download_url_array() as $url) { $stream_context = pts_network::stream_context_create(); stream_context_set_params($stream_context, array('notification' => 'pts_stream_status_callback')); $file_pointer = @fopen($url, 'r', false, $stream_context); //fread($file_pointer, 1024); if ($file_pointer == false) { echo PHP_EOL . 'BAD URL: ' . $test_file_download->get_filename() . ' / ' . $url . PHP_EOL; } else { @fclose($file_pointer); } } } } }
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']; }
public static function retrieve_gsid() { if (!pts_network::internet_support_available()) { return false; } // If the GSID_E and GSID_P are not known due to being from an old client $json = pts_openbenchmarking::make_openbenchmarking_request('retrieve_gsid', array()); $json = json_decode($json, true); return isset($json['openbenchmarking']['gsid']) ? $json['openbenchmarking']['gsid'] : false; }
public static function render_page_process($PATH) { echo phoromatic_webui_header_logged_in(); $main = null; if (!PHOROMATIC_USER_IS_VIEWER) { if (function_exists('ssh2_connect') && isset($_POST['ip']) && isset($_POST['port']) && isset($_POST['password']) && isset($_POST['username'])) { $connection = ssh2_connect($_POST['ip'], $_POST['port']); if (ssh2_auth_password($connection, $_POST['username'], $_POST['password'])) { $tmp_local_file = tempnam('/tmp', 'pts-ssh'); $tmp_remote_file = 'pts-ssh-' . rand(9999, 99999); file_put_contents($tmp_local_file, '#!/bin/sh if [ -w /var/lib/phoronix-test-suite/ ] then PHORO_FILE_PATH=/var/lib/phoronix-test-suite/ elif [ -w $HOME/.phoronix-test-suite/ ] then PHORO_FILE_PATH=$HOME/.phoronix-test-suite/ fi echo "' . phoromatic_web_socket_server_ip() . '" >> $PHORO_FILE_PATH/phoromatic-servers mkdir -p $PHORO_FILE_PATH/modules-data/phoromatic echo "' . phoromatic_web_socket_server_addr() . '" > $PHORO_FILE_PATH/modules-data/phoromatic/last-phoromatic-server '); ssh2_scp_send($connection, $tmp_local_file, $tmp_remote_file); unlink($tmp_local_file); ssh2_exec($connection, 'chmod +x ' . $tmp_remote_file); ssh2_exec($connection, './' . $tmp_remote_file); ssh2_exec($connection, 'rm' . $tmp_remote_file); } } if (isset($_POST['ip_claim']) && !empty($_POST['ip_claim']) && isset($_POST['ping'])) { $ip_ping = ip2long($_POST['ip_claim']) !== false ? $_POST['ip_claim'] : null; if ($ip_ping) { echo '<h3>Ping Test: ' . $ip_ping . '</h3>'; echo '<pre>'; echo shell_exec('ping -c 1 ' . $ip_ping); echo '</pre>'; } } else { if (isset($_POST['ip_claim']) && !empty($_POST['ip_claim']) || isset($_POST['mac_claim']) && !empty($_POST['mac_claim'])) { $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_system_association_claims (AccountID, IPAddress, NetworkMAC, CreationTime) VALUES (:account_id, :ip_address, :mac_address, :creation_time)'); $stmt->bindValue(':account_id', $_SESSION['AccountID']); $stmt->bindValue(':ip_address', $_POST['ip_claim']); $stmt->bindValue(':mac_address', $_POST['mac_claim']); $stmt->bindValue(':creation_time', phoromatic_server::current_time()); $result = $stmt->execute(); } } if (isset($_POST['remove_claim']) && !empty($_POST['remove_claim'])) { list($ipc, $macc) = explode(',', $_POST['remove_claim']); $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_system_association_claims WHERE AccountID = :account_id AND NetworkMAC = :mac_address AND IPAddress = :ip_address'); $stmt->bindValue(':account_id', $_SESSION['AccountID']); $stmt->bindValue(':ip_address', $ipc); $stmt->bindValue(':mac_address', $macc); $stmt->bindValue(':creation_time', phoromatic_server::current_time()); $result = $stmt->execute(); } $main .= '<h2>Add Phoromatic Server Info Via SSH</h2> <p>If your Phoromatic client systems are SSH-enabled, you can specify their SSH connection information below. In doing so, the Phoromatic Server will do a one-time connection to it immediately to pre-seed the system with the Phoromatic Server account information for this account. This should allow the client systems to then find the server automatically next time the phoronix-test-suite is run. This command assumes the Phoronix Test Suite is already pre-installed on the client system in your desired configuration.</p>'; if (function_exists('ssh2_connect')) { $main .= '<h3>Phoromatic Client SSH Information:</h3>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="ssh_connect" method="post"> <p><strong>IP Address:</strong> <input type="text" name="ip" /></p> <p><strong>SSH Port:</strong> <input type="text" name="port" value="22" /></p> <p><strong>Username:</strong> <input type="text" name="username" /></p> <p><strong>Password:</strong> <input type="password" name="password" /></p> <p><input name="submit" value="Seed Phoromatic Server Account Information" type="submit" /></p> </form>'; } else { $main .= '<h3>PHP SSH2 Must Be Installed For This Feature</h3>'; } $main .= '<hr />'; $main .= '<h2>Add Phoromatic Server Info Via IP/MAC</h2> <p>If deploying a Phoromatic Server within an organization, you can attempt for automatic configuration of Phoromatic clients if you know the system\'s IP or MAC addresses. When specifying either of these fields, if a Phoromatic client attempts to connect to this Phoromatic system without being associated to an account, it will be claimed by this account as long as no other Phoromatic accounts are attempting to claim the IP/MAC. This method can be particularly useful if running the Phoromatic client as a systemd/Upstart service where it will continually poll every 90 seconds auto-detected Phoromatic Servers on the LAN via zero-conf networking. For this feature to work, the zero-conf networking (Avahi) support must be enabled and working.</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="auto_associate" method="post"> <p><strong>IP Address Claim:</strong> <input type="text" name="ip_claim" /></p> <p><strong>MAC Address Claim:</strong> <input type="text" name="mac_claim" /></p> <p><input name="ping" value="Ping Test" type="submit" /> <input name="submit" value="Submit Claim" type="submit" /></p> </form>'; $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_system_association_claims WHERE AccountID = :account_id ORDER BY IPAddress ASC'); $stmt->bindValue(':account_id', $_SESSION['AccountID']); $result = $stmt->execute(); $claims = array(); $main .= '<p style="max-height: 500px; overflow-y: auto; ">'; while ($row = $result->fetchArray()) { $ip = $row['IPAddress'] != null ? $row['IPAddress'] : '<em>' . pts_network::mac_to_ip($row['NetworkMAC']) . '</em>'; $main .= $ip . ' ' . $row['NetworkMAC'] . '<br />'; array_push($claims, $row['IPAddress'] . ',' . $row['NetworkMAC']); } $main .= '</p>'; if (!empty($claims)) { $main .= '<hr /><h2>Remove Claim</h2><p>Removing a claimed IP / MAC address.</p>'; $main .= '<p><form action="' . $_SERVER['REQUEST_URI'] . '" name="remove_claim" method="post"><select name="remove_claim" id="remove_claim">'; foreach ($claims as $claim) { $main .= '<option value="' . $claim . '">' . str_replace(',', ' ', $claim) . '</option>'; } $main .= '</select> <input name="submit" value="Remove Claim" type="submit" /></form></p>'; } $main .= '<hr />'; } $right = null; echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in($right)); echo phoromatic_webui_footer(); }
public static function phoromatic_download_server_caches() { static $caches = null; if ($caches == null) { $caches = array(); $archived_servers = pts_client::available_phoromatic_servers(); foreach ($archived_servers as $archived_server) { $repo = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/download-cache.php?repo'); if (!empty($repo)) { $repo = json_decode($repo, true); if ($repo && isset($repo['phoronix-test-suite']['download-cache'])) { $caches[$archived_server['ip'] . ':' . $archived_server['http_port']] = $repo['phoronix-test-suite']['download-cache']; } } } } return $caches; }
public static function find_zeroconf_phoromatic_servers($find_multiple = false) { if (!pts_network::network_support_available()) { return null; } $hosts = $find_multiple ? array() : null; if (PTS_IS_CLIENT && pts_client::executable_in_path('avahi-browse')) { $avahi_browse = explode(PHP_EOL, shell_exec('avahi-browse -p -r -t _http._tcp 2>&1')); foreach (array_reverse($avahi_browse) as $avahi_line) { if (strrpos($avahi_line, 'phoromatic-server') !== false) { $avahi_line = explode(';', $avahi_line); if (isset($avahi_line[8]) && ip2long($avahi_line[7]) !== false && is_numeric($avahi_line[8])) { $server_ip = $avahi_line[7]; $server_port = $avahi_line[8]; //echo $server_ip . ':' . $server_port; if ($find_multiple) { array_push($hosts, array($server_ip, $server_port)); } else { $hosts = array($server_ip, $server_port); break; } } } } } return $hosts; }
public function scan_download_caches($local_download_caches, $remote_download_caches, $remote_files, $phoromatic_server_caches, $skip_hash_checks = false) { $download_location = $this->test_profile->get_install_dir(); $main_download_cache = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH))); foreach ($this->test_files as &$download_package) { $package_filename = $download_package->get_filename(); if (is_file($download_location . $package_filename)) { // File is already there in the test/destination directory, must have been previously downloaded // Could add an MD5 check here to ensure validity, but if it made it here it was already valid unless user modified it if ($download_package->get_filesize() == 0) { $download_package->set_filesize(filesize($download_location . $package_filename)); } $download_package->set_download_location('IN_DESTINATION_DIR'); } else { if (is_file($main_download_cache . $package_filename)) { // In main download cache if ($download_package->get_filesize() == 0) { $download_package->set_filesize(filesize($main_download_cache . $package_filename)); } $download_package->set_download_location('MAIN_DOWNLOAD_CACHE', array($main_download_cache . $package_filename)); } else { if (is_file(PTS_SHARE_PATH . 'download-cache/' . $package_filename)) { // In system's /usr/share download cache if ($download_package->get_filesize() == 0) { $download_package->set_filesize(filesize(PTS_SHARE_PATH . 'download-cache/' . $package_filename)); } $download_package->set_download_location('MAIN_DOWNLOAD_CACHE', array(PTS_SHARE_PATH . 'download-cache/' . $package_filename)); } else { // Scan the local download caches foreach ($local_download_caches as &$cache_directory) { if (is_file($cache_directory . $package_filename) && ($skip_hash_checks || $download_package->check_file_hash($cache_directory . $package_filename))) { if ($download_package->get_filesize() == 0) { $download_package->set_filesize(filesize($cache_directory . $package_filename)); } $download_package->set_download_location('LOCAL_DOWNLOAD_CACHE', array($cache_directory . $package_filename)); break; } } // Look-aside download cache copy // Check to see if the same package name with the same package check-sum is already present in another test installation $lookaside_copy = pts_test_install_manager::file_lookaside_test_installations($download_package); if ($lookaside_copy) { if ($download_package->get_filesize() == 0) { $download_package->set_filesize(filesize($lookaside_copy)); } $download_package->set_download_location('LOOKASIDE_DOWNLOAD_CACHE', array($lookaside_copy)); } // Check Phoromatic server caches if ($download_package->get_download_location_type() == null && $phoromatic_server_caches) { foreach ($phoromatic_server_caches as $server_url => $repo) { if (isset($repo[$package_filename]) && ($skip_hash_checks || $repo[$package_filename]['md5'] == $download_package->get_md5() || $repo[$package_filename]['sha256'] == $download_package->get_sha256() || $download_package->get_sha256() == null && $download_package->get_md5() == null)) { $download_package->set_download_location('REMOTE_DOWNLOAD_CACHE', array($server_url . '/download-cache.php?download=' . $package_filename)); break; } } } // If still not found, check remote download caches if ($download_package->get_download_location_type() == null) { if (isset($remote_files[$package_filename])) { $download_package->set_download_location('REMOTE_DOWNLOAD_CACHE', $remote_files[$package_filename]); } else { if (!empty($remote_download_caches)) { // Check for files manually foreach ($remote_download_caches as $remote_dir) { $remote_file = $remote_dir . $package_filename; $stream_context = pts_network::stream_context_create(); $file_pointer = fopen($remote_file, 'r', false, $stream_context); if ($file_pointer !== false) { $download_package->set_download_location('REMOTE_DOWNLOAD_CACHE', $remote_file); break; } } } } } } } } } }
public function post_execution_process() { if ($this->do_save_results()) { if ($this->result_file_writer->get_result_count() == 0 && !pts_result_file::is_test_result_file($this->get_file_name()) && pts_c::$test_flags ^ pts_c::is_recovering && pts_c::$test_flags ^ pts_c::remote_mode) { pts_file_io::delete(PTS_SAVE_RESULTS_PATH . $this->get_file_name()); return false; } pts_file_io::delete(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/test-logs/active/', null, true); if (pts_c::$test_flags ^ pts_c::is_recovering && (!pts_result_file::is_test_result_file($this->get_file_name()) || $this->result_already_contains_identifier() == false)) { $this->result_file_writer->add_test_notes(pts_test_notes_manager::generate_test_notes($this->tests_to_run), $this->generate_json_system_attributes()); } echo PHP_EOL; pts_module_manager::module_process('__event_results_process', $this); pts_client::save_result_file($this->result_file_writer, $this->get_file_name()); pts_module_manager::module_process('__event_results_saved', $this); //echo PHP_EOL . 'Results Saved To: ; . PTS_SAVE_RESULTS_PATH . $this->get_file_name() . ;/composite.xml' . PHP_EOL; if (!(pts_c::$test_flags & pts_c::auto_mode)) { if (pts_c::$test_flags & pts_c::batch_mode) { if (self::$batch_mode_options['OpenBrowser']) { pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/index.html', null, true, true); } } else { pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/index.html', null, true, false); } } if ($this->allow_sharing_of_results && pts_network::internet_support_available()) { if ($this->auto_upload_to_openbenchmarking || pts_openbenchmarking_client::auto_upload_results() || pts_flags::upload_to_openbenchmarking()) { $upload_results = true; } else { if (pts_c::$test_flags & pts_c::batch_mode) { $upload_results = self::$batch_mode_options['UploadResults']; } else { if (!(pts_c::$test_flags & pts_c::auto_mode)) { $upload_results = pts_user_io::prompt_bool_input('Would you like to upload the results to OpenBenchmarking.org', true); } else { $upload_results = false; } } } if ($upload_results) { $this->openbenchmarking_results_data = pts_openbenchmarking::upload_test_result($this, true); if ($this->get_results_url()) { if (!(pts_c::$test_flags & pts_c::auto_mode) && pts_openbenchmarking_client::auto_upload_results() == false) { pts_client::display_web_page($this->get_results_url(), 'Do you want to launch OpenBenchmarking.org', true); } } else { echo PHP_EOL . 'Results Failed To Upload.' . PHP_EOL; } } } } }
public static function render_page_process($PATH) { if ($_SESSION['AdminLevel'] != -40) { header('Location: /?main'); } $main = null; if (isset($_POST['new_phoromatic_path']) && !empty($_POST['new_phoromatic_path'])) { $new_dir = dirname($_POST['new_phoromatic_path']); if (!is_dir($new_dir)) { $main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> must be a valid directory.</h2>'; } else { if (!is_writable($new_dir)) { $main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> is not a writable location.</h2>'; } else { if (!is_dir($_POST['new_phoromatic_path'])) { if (mkdir($_POST['new_phoromatic_path']) == false) { $main .= '<h2 style="color: red;">Failed to make directory <em>' . $_POST['new_phoromatic_path'] . '</em>.</h2>'; } } if (is_dir($_POST['new_phoromatic_path'])) { $new_phoromatic_dir = pts_strings::add_trailing_slash($_POST['new_phoromatic_path']); $d = glob($new_phoromatic_dir . '*'); if (!empty($d)) { $new_phoromatic_dir .= 'phoromatic/'; pts_file_io::mkdir($new_phoromatic_dir); } $d = glob($new_phoromatic_dir . '*'); if (!empty($d)) { $main .= '<h2 style="color: red;"><em>' . $new_phoromatic_dir . '</em> must be an empty directory.</h2>'; } else { if (pts_file_io::copy(phoromatic_server::phoromatic_path(), $new_phoromatic_dir)) { pts_config::user_config_generate(array('PhoromaticStorage' => $new_phoromatic_dir)); header('Location: /?admin'); } else { $main .= '<h2 style="color: red;"><em>Failed to copy old Phoromatic data to new location.</h2>'; } } } } } } if (isset($_POST['new_dc_path']) && !empty($_POST['new_dc_path'])) { $new_dir = dirname($_POST['new_dc_path']); if (!is_dir($new_dir)) { $main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> must be a valid directory.</h2>'; } else { if (!is_writable($new_dir)) { $main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> is not a writable location.</h2>'; } else { if (!is_dir($_POST['new_dc_path'])) { if (mkdir($_POST['new_dc_path']) == false) { $main .= '<h2 style="color: red;">Failed to make directory <em>' . $_POST['new_dc_path'] . '</em>.</h2>'; } } if (is_dir($_POST['new_dc_path'])) { $new_dc_dir = pts_strings::add_trailing_slash($_POST['new_dc_path']); if (pts_file_io::copy(pts_strings::add_trailing_slash(pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH))), $new_dc_dir)) { pts_config::user_config_generate(array('CacheDirectory' => $new_dc_dir)); header('Location: /?admin'); } else { $main .= '<h2 style="color: red;"><em>Failed to copy old Phoromatic data to new location.</h2>'; } } } } } if (isset($_POST['new_proxy_address']) && isset($_POST['new_proxy_port'])) { if (pts_network::http_get_contents('http://www.phoronix-test-suite.com/PTS', $_POST['new_proxy_address'], $_POST['new_proxy_port']) == 'PTS') { pts_config::user_config_generate(array('PhoronixTestSuite/Options/Networking/ProxyAddress' => $_POST['new_proxy_address'], 'PhoronixTestSuite/Options/Networking/ProxyPort' => $_POST['new_proxy_port'])); } else { $main .= '<h2 style="color: red;">Failed to connect via proxy server.</h2>'; } } if (isset($_POST['new_http_port']) && isset($_POST['new_ws_port'])) { if (empty($_POST['new_http_port']) || !is_numeric($_POST['new_http_port']) && $_POST['new_http_port'] != 'RANDOM') { $main .= '<h2 style="color: red;">The HTTP port must be a valid port number or <em>RANDOM</em>.</h2>'; } if (empty($_POST['new_ws_port']) || !is_numeric($_POST['new_ws_port']) && $_POST['new_ws_port'] != 'RANDOM') { $main .= '<h2 style="color: red;">The WebSocket port must be a valid port number or <em>RANDOM</em>.</h2>'; } pts_config::user_config_generate(array('PhoronixTestSuite/Options/Server/RemoteAccessPort' => $_POST['new_http_port'], 'PhoronixTestSuite/Options/Server/WebSocketPort' => $_POST['new_ws_port'])); } if (isset($_POST['add_new_users_to_account'])) { if (empty($_POST['add_new_users_to_account'])) { phoromatic_server::save_setting('add_new_users_to_account', null); } else { $stmt = phoromatic_server::$db->prepare('SELECT COUNT(AccountID) AS AccountHitCount FROM phoromatic_accounts WHERE AccountID = :account_id'); $stmt->bindValue(':account_id', $_POST['add_new_users_to_account']); $result = $stmt->execute(); $row = $result->fetchArray(); if (empty($row['AccountHitCount'])) { $main .= '<h2 style="color: red;"><em>' . $_POST['add_new_users_to_account'] . '</em> is not a valid account ID.</h2>'; } else { phoromatic_server::save_setting('add_new_users_to_account', $_POST['add_new_users_to_account']); } } } if (isset($_POST['account_creation_alt'])) { phoromatic_server::save_setting('account_creation_alt', $_POST['account_creation_alt']); } if (isset($_POST['main_page_message'])) { phoromatic_server::save_setting('main_page_message', $_POST['main_page_message']); } if (isset($_POST['force_result_sharing'])) { phoromatic_server::save_setting('force_result_sharing', $_POST['force_result_sharing']); } if (isset($_POST['show_local_tests_only'])) { phoromatic_server::save_setting('show_local_tests_only', $_POST['show_local_tests_only']); } if (isset($_POST['new_admin_support_email'])) { phoromatic_server::save_setting('admin_support_email', $_POST['new_admin_support_email']); } if (isset($_POST['rebuild_results_db'])) { foreach (pts_file_io::glob(phoromatic_server::phoromatic_path() . 'accounts/*/results/*/composite.xml') as $composite_xml) { $account_id = basename(dirname(dirname(dirname($composite_xml)))); $upload_id = basename(dirname($composite_xml)); $result_file = new pts_result_file($composite_xml); // Validate the XML $relative_id = 0; foreach ($result_file->get_result_objects() as $result_object) { $relative_id++; $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_results_results (AccountID, UploadID, AbstractID, TestProfile, ComparisonHash) VALUES (:account_id, :upload_id, :abstract_id, :test_profile, :comparison_hash)'); $stmt->bindValue(':account_id', $account_id); $stmt->bindValue(':upload_id', $upload_id); $stmt->bindValue(':abstract_id', $relative_id); $stmt->bindValue(':test_profile', $result_object->test_profile->get_identifier()); $stmt->bindValue(':comparison_hash', $result_object->get_comparison_hash(true, false)); $result = $stmt->execute(); } if ($relative_id > 0) { foreach ($result_file->get_systems() as $s) { $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_results_systems (AccountID, UploadID, SystemIdentifier, Hardware, Software) VALUES (:account_id, :upload_id, :system_identifier, :hardware, :software)'); $stmt->bindValue(':account_id', $account_id); $stmt->bindValue(':upload_id', $upload_id); $stmt->bindValue(':system_identifier', $s->get_identifier()); $stmt->bindValue(':hardware', $s->get_hardware()); $stmt->bindValue(':software', $s->get_software()); $result = $stmt->execute(); } } } } $main .= '<h1>Phoromatic Server Configuration</h1>'; $main .= '<h2>Phoromatic Storage Location</h2>'; $main .= '<p>The Phoromatic Storage location is where all Phoromatic-specific test results, account data, and other information is archived. This path is controlled via the <em>' . pts_config::get_config_file_location() . '</em> configuration file with the <em>PhoromaticStorage</em> element. Adjusting the directory from the user configuration XML file is the recommended way to adjust the Phoromatic storage path when the Phoromatic Server is not running, while using the below form is an alternative method to attempt to live migrate the storage path.</p>'; $main .= '<p><strong>Current Storage Path:</strong> ' . phoromatic_server::phoromatic_path() . '</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="update_phoromatic_path" method="post">'; $main .= '<p><input type="text" name="new_phoromatic_path" value="' . (isset($_POST['new_phoromatic_path']) ? $_POST['new_phoromatic_path'] : null) . '" /></p>'; $main .= '<p><input name="submit" value="Update Phoromatic Storage Location" type="submit" /></p>'; $main .= '</form>'; $main .= '<hr /><h2>Download Cache Location</h2>'; $main .= '<p>The download cache is where the Phoronix Test Suite is able to make an archive of files needed by test profiles. The Phoromatic Server is then able to allow Phoronix Test Suite client systems on the intranet. To add test files to this cache on the Phoromatic Server, run <strong>phoronix-test-suite make-download-cache <em><the test identifers you wish to download and cache></em></strong>.</p>'; $main .= '<p><strong>Current Download Cache Path:</strong> ' . pts_strings::add_trailing_slash(pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH))) . '</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="update_dc_path" method="post">'; $main .= '<p><input type="text" name="new_dc_path" value="' . (isset($_POST['new_dc_path']) ? $_POST['new_dc_path'] : null) . '" /></p>'; $main .= '<p><input name="submit" value="Update Download Cache Location" type="submit" /></p>'; $main .= '</form>'; $main .= '<hr /><h2>Network Proxy</h2>'; $main .= '<p>If a network proxy is needed for the Phoromatic Server to access the open Internet, please provide the IP address and HTTP port address below.</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="update_proxy" method="post">'; $main .= '<p><strong>Proxy HTTP Port:</strong> <input type="text" name="new_proxy_port" size="4" value="' . (isset($_POST['new_proxy_port']) ? $_POST['new_proxy_port'] : pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyPort')) . '" /></p>'; $main .= '<p><strong>Proxy IP Address:</strong> <input type="text" name="new_proxy_address" value="' . (isset($_POST['new_proxy_address']) ? $_POST['new_proxy_address'] : pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyAddress')) . '" /></p>'; $main .= '<p><input name="submit" value="Update Network Proxy" type="submit" /></p>'; $main .= '</form>'; $main .= '<hr /><h2>Phoromatic Server Ports</h2>'; $main .= '<p>The HTTP and WebSocket ports for the Phoromatic Server can be adjusted via this form or the user configuration XML file. The new ports will not go into effect until the Phoromatic Server instance has been restarted.</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="update_ports" method="post">'; $main .= '<p><strong>HTTP Port:</strong> <input type="text" name="new_http_port" size="4" value="' . (isset($_POST['new_http_port']) ? $_POST['new_http_port'] : pts_config::read_user_config('PhoronixTestSuite/Options/Server/RemoteAccessPort')) . '" /></p>'; $main .= '<p><strong>WebSocket Port:</strong> <input type="text" name="new_ws_port" size="4" value="' . (isset($_POST['new_ws_port']) ? $_POST['new_ws_port'] : pts_config::read_user_config('PhoronixTestSuite/Options/Server/WebSocketPort')) . '" /></p>'; $main .= '<p><input name="submit" value="Update Web Ports" type="submit" /></p>'; $main .= '</form>'; $main .= '<hr /><h2>Support Email Address</h2>'; $main .= '<p>This email address will be shown as the sender of emails regarding new account registration and other non-group-related messages. This email address may also be shown as a support email address in case of user problems.</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="support_email" method="post">'; $main .= '<p><strong>E-Mail:</strong> <input type="text" name="new_admin_support_email" value="' . phoromatic_server::read_setting('admin_support_email') . '" /></p>'; $main .= '<p><input name="submit" value="Update E-Mail Address" type="submit" /></p>'; $main .= '</form>'; $main .= '<hr /><h1>Account Creation</h1>'; $main .= '<h2>Add To Existing Account</h2><p>Whenever a new account is created via the main log-in page, rather than creating a new group account, you can opt to have the account added as a viewer to an existing group of accounts. To do so, enter the account ID in the field below. The user is added to that account ID with viewer privileges while the main administrator for that account can elevate the privileges from their account\'s Users page. You can find the list of account IDs via the main rootadmin page account listing. Leave this field blank to disable the feature. This option only affects the creation of new accounts.</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="add_accounts_to_one" method="post">'; $main .= '<p><strong>Main Account ID:</strong> <input type="text" name="add_new_users_to_account" size="6" value="' . phoromatic_server::read_setting('add_new_users_to_account') . '" /></p>'; $main .= '<p><input name="submit" value="Update Account Handling" type="submit" /></p>'; $main .= '</form>'; $main .= '<hr /><h1>Account Creation</h1>'; $main .= '<p>By default, new accounts can be created at-will from the main page of the Phoromatic Server web interface. <strong>To disable the ability to create new accounts from the main welcome page</strong>, enter a message in the field below -- e.g. account creation disabled, contact XYZ department via email to request a new account, or other string to present to the user in place of the account creation box. Leave this box empty to allow new accounts to be created. HTML input is allowed.</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="account_creation_text" method="post">'; $main .= '<p><strong>Account Creation String:</strong> <textarea name="account_creation_alt" cols="50" rows="4">' . phoromatic_server::read_setting('account_creation_alt') . '</textarea></p>'; $main .= '<p><input name="submit" value="Update Account Handling" type="submit" /></p>'; $main .= '</form>'; $main .= '<hr /><h1>Main Page Message</h1>'; $main .= '<p>If you wish to present users with a custom message once logging into their Phoromatic account, set the HTML-allowed string below and it will be shown on the main page once logging in.</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="main_page_message" method="post">'; $main .= '<p><strong>Main Page Message String:</strong> <textarea name="main_page_message" cols="50" rows="4">' . phoromatic_server::read_setting('main_page_message') . '</textarea></p>'; $main .= '<p><input name="submit" value="Update Main Page Message" type="submit" /></p>'; $main .= '</form>'; $main .= '<hr /><h1>Force Results To Be Shared</h1>'; $main .= '<p>If you wish to force that all accounts/groups on this Phoromatic Server instance are shared/viewable amongst other groups on this server, set this value to True. Otherwise the result sharing is limited to each group\'s selected option on the account settings page.</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="force_result_share" method="post">'; $main .= '<p><strong>Force Result Sharing:</strong> <select name="force_result_sharing"><option value="0">False</option><option value="1" ' . (phoromatic_server::read_setting('force_result_sharing') ? 'selected="selected"' : null) . '>True</option></select></p>'; $main .= '<p><input name="submit" value="Update" type="submit" /></p>'; $main .= '</form>'; $main .= '<hr /><h1>Only Advertise Tests With Files Locally Cached</h1>'; $main .= '<p>Enabling this option will only advertise test profiles on the Phoromatic Server web interface if the needed files for that test are present within the Phoromatic Server\'s PTS download cache. This feature is particularly useful for environments where the client test system lacks direct Internet access.</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="show_local_tests_only" method="post">'; $main .= '<p><strong>Only Advertise Cached Tests:</strong> <select name="show_local_tests_only"><option value="0">False</option><option value="1" ' . (phoromatic_server::read_setting('show_local_tests_only') ? 'selected="selected"' : null) . '>True</option></select></p>'; $main .= '<p><input name="submit" value="Update" type="submit" /></p>'; $main .= '</form>'; $main .= '<hr /><h1>Rebuild Results/Systems SQLite Tables</h1>'; $main .= '<p>If you somehow damaged some of your SQLite tables, this option will attempt to rebuild the phoromatic_results_results and phoromatic_results_systems tables.</p>'; $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="rebuild_results_db" method="post">'; $main .= '<p><strong>Force Results Table Rebuild:</strong> <select name="rebuild_results_db"><option value="0">False</option><option value="1" ' . (phoromatic_server::read_setting('rebuild_results_db') ? 'selected="selected"' : null) . '>True</option></select></p>'; $main .= '<p><input name="submit" value="Rebuild Results Table" type="submit" /></p>'; $main .= '</form>'; echo phoromatic_webui_header_logged_in(); echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in()); echo phoromatic_webui_footer(); }
public static function validate_test_profile(&$test_profile) { if ($test_profile->get_file_location() == null) { echo PHP_EOL . 'ERROR: The file location of the XML test profile source could not be determined.' . PHP_EOL; return false; } // Validate the XML against the XSD Schemas libxml_clear_errors(); // Now re-create the pts_test_profile object around the rewritten XML $test_profile = new pts_test_profile($test_profile->get_identifier()); $valid = $test_profile->validate(); if ($valid == false) { echo PHP_EOL . 'Errors occurred parsing the main XML.' . PHP_EOL; pts_validation::process_libxml_errors(); return false; } // Rewrite the main XML file to ensure it is properly formatted, elements are ordered according to the schema, etc... $test_profile_writer = new pts_test_profile_writer(); $test_profile_writer->rebuild_test_profile($test_profile); $test_profile_writer->save_xml($test_profile->get_file_location()); // Now re-create the pts_test_profile object around the rewritten XML $test_profile = new pts_test_profile($test_profile->get_identifier()); $valid = $test_profile->validate(); if ($valid == false) { echo PHP_EOL . 'Errors occurred parsing the main XML.' . PHP_EOL; pts_validation::process_libxml_errors(); return false; } else { echo PHP_EOL . 'Test Profile XML Is Valid.' . PHP_EOL; } // Validate the downloads file $download_xml_file = $test_profile->get_file_download_spec(); if (empty($download_xml_file) == false) { $writer = new pts_test_profile_downloads_writer(); $writer->rebuild_download_file($test_profile); $writer->save_xml($download_xml_file); $downloads_parser = new pts_test_downloads_nye_XmlReader($download_xml_file); $valid = $downloads_parser->validate(); if ($valid == false) { echo PHP_EOL . 'Errors occurred parsing the downloads XML.' . PHP_EOL; pts_validation::process_libxml_errors(); return false; } else { echo PHP_EOL . 'Test Downloads XML Is Valid.' . PHP_EOL; } // Validate the individual download files echo PHP_EOL . 'Testing File Download URLs.' . PHP_EOL; $files_missing = 0; $file_count = 0; foreach (pts_test_install_request::read_download_object_list($test_profile) as $download) { foreach ($download->get_download_url_array() as $url) { $stream_context = pts_network::stream_context_create(); stream_context_set_params($stream_context, array('notification' => 'pts_stream_status_callback')); $file_pointer = fopen($url, 'r', false, $stream_context); if ($file_pointer == false) { echo 'File Missing: ' . $download->get_filename() . ' / ' . $url . PHP_EOL; $files_missing++; } else { fclose($file_pointer); } $file_count++; } } if ($files_missing > 0) { return false; } } // Validate the parser file $parser_file = $test_profile->get_file_parser_spec(); if (empty($parser_file) == false) { $writer = self::rebuild_result_parser_file($parser_file); $writer->saveXMLFile($parser_file); $parser = new pts_parse_results_nye_XmlReader($parser_file); $valid = $parser->validate(); if ($valid == false) { echo PHP_EOL . 'Errors occurred parsing the results parser XML.' . PHP_EOL; pts_validation::process_libxml_errors(); return false; } else { echo PHP_EOL . 'Test Results Parser XML Is Valid.' . PHP_EOL; } } // Make sure no extra files are in there $allowed_files = pts_validation::test_profile_permitted_files(); foreach (pts_file_io::glob($test_profile->get_resource_dir() . '*') as $tp_file) { if (!is_file($tp_file) || !in_array(basename($tp_file), $allowed_files)) { echo PHP_EOL . basename($tp_file) . ' is not allowed in the test package.' . PHP_EOL; return false; } } return true; }
public static function download_test_suite($qualified_identifier) { if (is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml')) { return true; } $file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip'; if (pts_network::internet_support_available()) { $hash_json = pts_openbenchmarking::make_openbenchmarking_request('suite_hash', array('i' => $qualified_identifier)); $hash_json = json_decode($hash_json, true); $hash_check = isset($hash_json['openbenchmarking']['suite']['hash']) ? $hash_json['openbenchmarking']['suite']['hash'] : null; // should also check for ['openbenchmarking']['suite']['error'] problems } if (!is_file($file)) { if (pts_network::internet_support_available()) { $test_suite = pts_openbenchmarking::make_openbenchmarking_request('download_suite', array('i' => $qualified_identifier)); if ($test_suite != null && ($hash_check == null || $hash_check == sha1($test_suite))) { // save it file_put_contents($file, $test_suite); $hash_check = null; } else { if (is_file('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip') && ($hash_check == null || sha1_file('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip') == $hash_check)) { copy('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip', $file); } } } if (!is_file($file) && ($test_suite = self::phoromatic_server_ob_cache_request('suite', substr($qualified_identifier, 0, strpos($qualified_identifier, '/')), substr($qualified_identifier, strpos($qualified_identifier, '/') + 1)))) { if ($b64 = base64_decode($test_suite)) { $test_suite = $b64; } file_put_contents($file, $test_suite); } if (PTS_IS_CLIENT && !is_file($file)) { trigger_error('Network support is needed to obtain ' . $qualified_identifier . ' data.' . PHP_EOL, E_USER_ERROR); return false; } } if (!is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml') && is_file($file) && ($hash_check == null || is_file($file) && sha1_file($file) == $hash_check)) { // extract it pts_file_io::mkdir(PTS_TEST_SUITE_PATH . dirname($qualified_identifier)); pts_file_io::mkdir(PTS_TEST_SUITE_PATH . $qualified_identifier); pts_compression::zip_archive_extract($file, PTS_TEST_SUITE_PATH . $qualified_identifier); if (is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml')) { return true; } else { unlink($file); return false; } } return false; }
public static function run_connection($args) { if (pts_client::create_lock(PTS_USER_PATH . 'phoromatic_lock') == false) { trigger_error('Phoromatic is already running.', E_USER_ERROR); return false; } define('PHOROMATIC_PROCESS', true); if (pts_client::$pts_logger == false) { pts_client::$pts_logger = new pts_logger(); } pts_client::$pts_logger->log(pts_title(true) . ' [' . PTS_CORE_VERSION . '] starting Phoromatic client'); if (phodevi::system_uptime() < 60) { echo 'PHOROMATIC: Sleeping for 60 seconds as system freshly started.' . PHP_EOL; pts_client::$pts_logger->log('Sleeping for 60 seconds as system freshly started'); sleep(60); } $server_setup = self::setup_server_addressing($args); //$http_comm = new phoromatic_client_comm_http(); if (!$server_setup) { if (PTS_IS_DAEMONIZED_SERVER_PROCESS) { if (pts_client::executable_in_path('reboot')) { shell_exec('reboot'); sleep(5); } } return false; } $times_failed = 0; $has_success = false; $do_exit = false; $just_started = true; self::setup_system_environment(); pts_client::$pts_logger->log('SYSTEM HARDWARE: ' . phodevi::system_hardware(true)); pts_client::$pts_logger->log('SYSTEM SOFTWARE: ' . phodevi::system_software(true)); while ($do_exit == false) { $server_response = phoromatic::upload_to_remote_server(array('r' => 'start')); if ($server_response == false) { $times_failed++; pts_client::$pts_logger->log('Server response failed'); if ($times_failed >= 2) { trigger_error('Communication with server failed.', E_USER_ERROR); if (PTS_IS_DAEMONIZED_SERVER_PROCESS == false && $times_failed > 5) { return false; } else { if (PTS_IS_DAEMONIZED_SERVER_PROCESS && $times_failed > 10) { if (pts_client::executable_in_path('reboot')) { shell_exec('reboot'); sleep(5); } } } } } else { if (substr($server_response, 0, 1) == '[') { // Likely a notice/warning from server echo PHP_EOL . substr($server_response, 0, strpos($server_response, PHP_EOL)) . PHP_EOL; } else { if (substr($server_response, 0, 1) == '{') { $times_failed = 0; $json = json_decode($server_response, true); if ($has_success == false) { $has_success = true; pts_module::save_file('last-phoromatic-server', self::$server_address . ':' . self::$server_http_port . '/' . self::$account_id); } if ($json != null) { if (isset($json['phoromatic']['error']) && !empty($json['phoromatic']['error'])) { trigger_error($json['phoromatic']['error'], E_USER_ERROR); } if (isset($json['phoromatic']['response']) && !empty($json['phoromatic']['response'])) { echo PHP_EOL . $json['phoromatic']['response'] . PHP_EOL; } } if ($just_started) { if (PTS_IS_DAEMONIZED_SERVER_PROCESS) { $pid = pcntl_fork(); if ($pid == 0) { // Start the tick thread self::tick_thread(); } } $just_started = false; } if (isset($json['phoromatic']['pre_set_sys_env_vars']) && !empty($json['phoromatic']['pre_set_sys_env_vars'])) { // pre_set_sys_env_vars was added during PTS 5.8 development // Sets environment variables on client as specified via the Phoromatic Server's systems page foreach (explode(';', $json['phoromatic']['pre_set_sys_env_vars']) as $i => $v_string) { $var = explode('=', $v_string); if (count($var) == 2) { putenv($var[0] . '=' . $var[1]); } } } switch (isset($json['phoromatic']['task']) ? $json['phoromatic']['task'] : null) { case 'install': phoromatic::update_system_status('Installing Tests'); pts_suite_nye_XmlReader::set_temporary_suite('pre-seed', $json['phoromatic']['test_suite']); pts_test_installer::standard_install('pre-seed'); break; case 'benchmark': // Make sure all latest tests are available pts_openbenchmarking::refresh_repository_lists(null, true); $benchmark_timer = time(); self::$is_running_as_phoromatic_node = true; $test_flags = pts_c::auto_mode | pts_c::batch_mode; $suite_identifier = sha1(time() . rand(2, 1000)); pts_suite_nye_XmlReader::set_temporary_suite($suite_identifier, $json['phoromatic']['test_suite']); self::$p_save_identifier = $json['phoromatic']['trigger_id']; $phoromatic_results_identifier = self::$p_save_identifier; $phoromatic_save_identifier = $json['phoromatic']['save_identifier']; self::$p_schedule_id = isset($json['phoromatic']['schedule_id']) ? $json['phoromatic']['schedule_id'] : false; self::$p_trigger_id = self::$p_save_identifier; $benchmark_ticket_id = isset($json['phoromatic']['benchmark_ticket_id']) ? $json['phoromatic']['benchmark_ticket_id'] : null; phoromatic::update_system_status('Running Benchmarks For: ' . $phoromatic_save_identifier); if (pts_strings::string_bool($json['phoromatic']['settings']['RunInstallCommand'])) { if (isset($json['phoromatic']['pre_install_set_context'])) { phoromatic::set_user_context($json['phoromatic']['pre_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_INSTALL'); } if (pts_strings::string_bool($json['phoromatic']['settings']['ForceInstallTests'])) { $test_flags |= pts_c::force_install; } pts_client::set_test_flags($test_flags); pts_test_installer::standard_install($suite_identifier); if (isset($json['phoromatic']['post_install_set_context'])) { phoromatic::set_user_context($json['phoromatic']['post_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_INSTALL'); } } $env_vars = isset($json['phoromatic']['environment_variables']) ? pts_strings::parse_value_string_vars($json['phoromatic']['environment_variables']) : array(); // Do the actual running phodevi::clear_cache(); if (pts_test_run_manager::initial_checks($suite_identifier, 0, 'SHORT')) { self::$test_run_manager = new pts_test_run_manager($test_flags); pts_test_run_manager::set_batch_mode(array('UploadResults' => isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']), 'SaveResults' => true, 'RunAllTestCombinations' => false, 'OpenBrowser' => false)); // Load the tests to run if (self::$test_run_manager->load_tests_to_run($suite_identifier)) { phoromatic::update_system_status('Tests In Run Queue: ' . implode(', ', self::$test_run_manager->get_tests_to_run_identifiers())); if (isset($json['phoromatic']['pre_run_set_context'])) { phoromatic::set_user_context($json['phoromatic']['pre_run_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_RUN'); } if (isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking'])) { self::$test_run_manager->auto_upload_to_openbenchmarking(); pts_openbenchmarking_client::override_client_setting('UploadSystemLogsByDefault', pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs'])); } // Save results? // Run the actual tests if (isset($env_vars['PTS_CONCURRENT_TEST_RUNS']) && $env_vars['PTS_CONCURRENT_TEST_RUNS'] > 1) { $total_loop_time = isset($env_vars['TOTAL_LOOP_TIME']) ? $env_vars['TOTAL_LOOP_TIME'] : false; pts_client::$pts_logger->log('STRESS / MULTI-TEST EXECUTION STARTED @ ' . date('Y-m-d H:i:s')); pts_client::$pts_logger->log('CONCURRENT RUNS = ' . $env_vars['PTS_CONCURRENT_TEST_RUNS'] . ' TOTAL LOOP TIME = ' . $total_loop_time); $r = self::$test_run_manager->multi_test_stress_run_execute($env_vars['PTS_CONCURRENT_TEST_RUNS'], $total_loop_time); if ($r == false) { return; } pts_client::$pts_logger->log('STRESS / MULTI-TEST EXECUTION ENDED @ ' . date('Y-m-d H:i:s')); } else { self::$test_run_manager->auto_save_results($phoromatic_save_identifier, $phoromatic_results_identifier, isset($json['phoromatic']['test_description']) ? $json['phoromatic']['test_description'] : 'A Phoromatic run.'); self::$test_run_manager->pre_execution_process(); self::$test_run_manager->call_test_runs(); } phoromatic::update_system_status('Benchmarks Completed For: ' . $phoromatic_save_identifier); self::$test_run_manager->post_execution_process(); $elapsed_benchmark_time = time() - $benchmark_timer; // Handle uploading data to server $result_file = new pts_result_file(self::$test_run_manager->get_file_name()); $upload_system_logs = pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']); $server_response = self::upload_test_result($result_file, $upload_system_logs, isset($json['phoromatic']['schedule_id']) ? $json['phoromatic']['schedule_id'] : null, $phoromatic_save_identifier, $json['phoromatic']['trigger_id'], $elapsed_benchmark_time, $benchmark_ticket_id); //pts_client::$pts_logger->log('DEBUG RESPONSE MESSAGE: ' . $server_response); if (!pts_strings::string_bool($json['phoromatic']['settings']['ArchiveResultsLocally'])) { pts_client::remove_saved_result_file(self::$test_run_manager->get_file_name()); } } if (isset($json['phoromatic']['post_install_set_context'])) { phoromatic::set_user_context($json['phoromatic']['post_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_RUN'); } } self::$p_schedule_id = null; self::$is_running_as_phoromatic_node = false; break; case 'reboot': echo PHP_EOL . 'Phoromatic received a remote command to reboot.' . PHP_EOL; phoromatic::update_system_status('Attempting System Reboot'); if (pts_client::executable_in_path('reboot')) { shell_exec('reboot'); sleep(5); } break; case 'shutdown-if-supports-wake': $supports_wol = false; foreach (pts_network::get_network_wol() as $net_device) { if (strpos($net_device, 'g') !== false) { $supports_wol = true; break; } } if (!$supports_wol) { break; } case 'shutdown': if (isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script'])) { self::run_client_update_script($json['phoromatic']['client_update_script']); sleep(10); } echo PHP_EOL . 'Phoromatic received a remote command to shutdown.' . PHP_EOL; phoromatic::update_system_status('Attempting System Shutdown'); if (pts_client::executable_in_path('poweroff')) { shell_exec('poweroff'); sleep(5); } break; case 'maintenance': echo PHP_EOL . 'Idling, system maintenance mode set by Phoromatic Server.' . PHP_EOL; phoromatic::update_system_status('Maintenance Mode'); sleep(60); break; case 'idle': if (isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script'])) { self::run_client_update_script($json['phoromatic']['client_update_script']); } //echo PHP_EOL . 'Idling, waiting for task.' . PHP_EOL; phoromatic::update_system_status('Idling, Waiting For Task'); break; case 'exit': echo PHP_EOL . 'Phoromatic received a remote command to exit.' . PHP_EOL; phoromatic::update_system_status('Exiting Phoromatic'); $do_exit = true; break; } } } } if (!$do_exit) { if ($server_response == false) { sleep(rand(10, 30)); } else { sleep(60); } } } pts_client::release_lock(PTS_USER_PATH . 'phoromatic_lock'); }
public static function run($r) { $render_dir = pts_client::temporary_directory() . '/pts-render-test-310815/'; if (!is_file($render_dir . 'mega-render-test.tar.bz2')) { pts_file_io::mkdir($render_dir); pts_network::download_file('http://linuxbenchmarking.com/misc/mega-render-test-310815.tar.bz2', $render_dir . 'mega-render-test.tar.bz2'); pts_compression::archive_extract($render_dir . 'mega-render-test.tar.bz2'); } define('PATH_TO_EXPORTED_PHOROMATIC_DATA', $render_dir . 'mega-render-test-310815/'); error_reporting(E_ALL); ini_set('memory_limit', '2048M'); $export_index_json = file_get_contents(PATH_TO_EXPORTED_PHOROMATIC_DATA . 'export-index.json'); $export_index_json = json_decode($export_index_json, true); $dump_size = 0; $start = microtime(true); foreach (array_keys($export_index_json['phoromatic']) as $REQUESTED) { $this_render_test = time(); $tracker =& $export_index_json['phoromatic'][$REQUESTED]; $triggers = $tracker['triggers']; echo PHP_EOL . 'STARTING RENDER TEST ON: ' . $REQUESTED . ' (' . count($triggers) . ' Triggers)' . PHP_EOL; $length = count($tracker['triggers']); $result_files = array(); foreach ($triggers as $trigger) { $results_for_trigger = glob(PATH_TO_EXPORTED_PHOROMATIC_DATA . '/' . $REQUESTED . '/' . $trigger . '/*/composite.xml'); echo '.'; if ($results_for_trigger == false) { continue; } foreach ($results_for_trigger as $composite_xml) { // Add to result file $system_name = basename(dirname($composite_xml)) . ': ' . $trigger; array_push($result_files, new pts_result_merge_select($composite_xml, null, $system_name)); } } echo 'STARTING MERGE; '; $result_file = new pts_result_file(null, true); $result_file->merge($result_files); echo 'MAKING NEW RESULT FILE; '; $extra_attributes = array('reverse_result_buffer' => true, 'force_simple_keys' => true, 'force_line_graph_compact' => true, 'force_tracking_line_graph' => true); //$extra_attributes['normalize_result_buffer'] = true; $intent = null; //$table = new pts_ResultFileTable($result_file, $intent); //echo '<p style="text-align: center; overflow: auto;" class="result_object">' . pts_render::render_graph_inline_embed($table, $result_file, $extra_attributes) . '</p>'; echo 'STARTING RESULT LOOP; '; $html_dump = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body>'; foreach ($result_file->get_result_objects(isset($_POST['show_only_changed_results']) ? 'ONLY_CHANGED_RESULTS' : -1) as $i => $result_object) { echo $result_object->test_profile->get_title() . ' '; $html_dump .= '<h3>' . $result_object->get_arguments_description() . '</h3>'; $html_dump .= pts_render::render_graph_inline_embed($result_object, $result_file, $extra_attributes); unset($result_object); } $table = new pts_ResultFileSystemsTable($result_file); $html_dump .= pts_render::render_graph_inline_embed($table, $result_file, $extra_attributes); echo PHP_EOL . PHP_EOL . 'RENDER TEST ON: ' . $REQUESTED . ' TOOK ' . (time() - $this_render_test) . PHP_EOL; $dump_size += strlen($html_dump); file_put_contents(PATH_TO_EXPORTED_PHOROMATIC_DATA . $REQUESTED . '.html', $html_dump . '</body></html>'); } echo PHP_EOL . 'RENDER TEST TOOK: ' . (time() - $start) . PHP_EOL . PHP_EOL; echo PHP_EOL . 'PEAK MEMORY USAGE: ' . round(memory_get_peak_usage(true) / 1048576, 3) . ' MB'; echo PHP_EOL . 'PEAK MEMORY USAGE (emalloc): ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB'; echo PHP_EOL . 'TOTAL FILE SIZE: ' . ceil($dump_size / 1000) . ' KB'; echo PHP_EOL; }
public static function run($r) { pts_client::$display->generic_heading('Available Tests'); $available_tests = pts_openbenchmarking::available_tests(false); $available_suites = pts_openbenchmarking::available_suites(false); $test_count = count($available_tests); $suite_count = count($available_suites); $total_count = $test_count + $suite_count; $total_cache_count = 0; $total_cache_size = 0; if ($test_count == 0 || !pts_network::internet_support_available()) { echo PHP_EOL . 'No tests found. Please check that you have Internet connectivity to download test profile data from OpenBenchmarking.org. The Phoronix Test Suite has documentation on configuring the network setup, proxy settings, and PHP network options. Please contact Phoronix Media if you continuing to experience problems.' . PHP_EOL . PHP_EOL; return false; } $terminal_width = pts_client::terminal_width(); // Cache test profiles foreach ($available_tests as $i => $identifier) { $repo = substr($identifier, 0, strpos($identifier, '/')); $test = substr($identifier, strlen($repo) + 1); $repo_index = pts_openbenchmarking::read_repository_index($repo); echo $i . '/' . $total_count . ': ' . ($repo_index['tests'][$test]['title'] != null ? $repo_index['tests'][$test]['title'] . ' [' . $repo_index['tests'][$test]['test_type'] . ']' : null) . PHP_EOL; foreach ($repo_index['tests'][$test]['versions'] as $version) { $qualified_identifier = $repo . '/' . $test . '-' . $version; echo $qualified_identifier; $success = pts_openbenchmarking::download_test_profile($repo . '/' . $test . '-' . $version); if ($success && is_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip')) { $file_size = round(filesize(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip') / 1024, 2); $info = $file_size . 'KB - ' . sha1_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip'); $r_size = $terminal_width - strlen($qualified_identifier) - 3 - strlen($info); if ($r_size > 0) { echo ' ' . str_repeat('.', $terminal_width - strlen($qualified_identifier) - 3 - strlen($info)) . ' ' . $info . PHP_EOL; } $total_cache_count++; $total_cache_size += $file_size; } } echo PHP_EOL; } // Cache test suites foreach ($available_suites as $i => $identifier) { $repo = substr($identifier, 0, strpos($identifier, '/')); $test = substr($identifier, strlen($repo) + 1); $repo_index = pts_openbenchmarking::read_repository_index($repo); echo $i + $test_count . '/' . $total_count . ': ' . $repo_index['suites'][$test]['title'] . PHP_EOL; foreach ($repo_index['suites'][$test]['versions'] as $version) { $qualified_identifier = $repo . '/' . $test . '-' . $version; echo $qualified_identifier; $success = pts_openbenchmarking::download_test_suite($repo . '/' . $test . '-' . $version); if ($success && is_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip')) { $file_size = round(filesize(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip') / 1024, 2); $info = $file_size . 'KB - ' . sha1_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip'); $dot_size = $terminal_width - strlen($qualified_identifier) - 3 - strlen($info); echo ' ' . str_repeat('.', $dot_size >= 0 ? $dot_size : 0) . ' ' . $info . PHP_EOL; $total_cache_count++; $total_cache_size += $file_size; } } echo PHP_EOL; } echo PHP_EOL . $total_cache_count . ' Files Cached' . PHP_EOL . $test_count . ' Test Profiles' . PHP_EOL . $suite_count . ' Test Suites' . PHP_EOL . $total_cache_size . 'KB Total Cache Size' . PHP_EOL . PHP_EOL; }
public static function available_phoromatic_servers() { $phoromatic_servers = array(); $possible_servers = pts_network::find_zeroconf_phoromatic_servers(true); foreach (self::$phoromatic_servers as $server) { array_push($possible_servers, array($server['ip'], $server['http_port'])); } $user_config_phoromatic_servers = pts_config::read_user_config('PhoronixTestSuite/Options/General/PhoromaticServers', ''); foreach (explode(',', $user_config_phoromatic_servers) as $static_server) { $static_server = explode(':', $static_server); if (count($static_server) == 2) { array_push($possible_servers, array($static_server[0], $static_server[1])); } } if (is_file(PTS_USER_PATH . 'phoromatic-servers')) { $phoromatic_servers_file = pts_file_io::file_get_contents(PTS_USER_PATH . 'phoromatic-servers'); foreach (explode(PHP_EOL, $phoromatic_servers_file) as $ps_file_line) { $ps_file_line = explode(':', trim($ps_file_line)); if (count($ps_file_line) == 2 && ip2long($ps_file_line[0]) !== false && is_numeric($ps_file_line) && $ps_file_line > 100) { array_push($possible_servers, array($ps_file_line[0], $ps_file_line[1])); } } } foreach ($possible_servers as $possible_server) { // possible_server[0] is the Phoromatic Server IP // possible_server[1] is the Phoromatic Server HTTP PORT if (in_array($possible_server[0], array_keys($phoromatic_servers))) { continue; } $server_response = pts_network::http_get_contents('http://' . $possible_server[0] . ':' . $possible_server[1] . '/server.php', false, false, 3); if (stripos($server_response, 'Phoromatic') !== false) { trigger_error('Phoromatic Server Auto-Detected At: ' . $possible_server[0] . ':' . $possible_server[1], E_USER_NOTICE); $phoromatic_servers[$possible_server[0]] = array('ip' => $possible_server[0], 'http_port' => $possible_server[1]); } } return $phoromatic_servers; }
public function post_execution_process() { if ($this->do_save_results()) { if ($this->result_file->get_test_count() == 0 && $this->is_new_result_file) { pts_file_io::delete(PTS_SAVE_RESULTS_PATH . $this->get_file_name()); return false; } pts_file_io::delete(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/test-logs/active/', null, true); if ($this->is_new_result_file || $this->result_already_contains_identifier() == false) { // nothing to do here now } echo PHP_EOL; pts_module_manager::module_process('__event_results_process', $this); pts_client::save_test_result($this->get_file_name() . '/composite.xml', $this->result_file->get_xml(), true, $this->results_identifier); pts_module_manager::module_process('__event_results_saved', $this); //echo PHP_EOL . 'Results Saved To: ; . PTS_SAVE_RESULTS_PATH . $this->get_file_name() . ;/composite.xml' . PHP_EOL; if (!$this->auto_mode) { if ($this->batch_mode) { if ($this->batch_mode['OpenBrowser']) { pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/index.html', null, true, true); } } else { pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/index.html', null, true, false); } } if ($this->allow_sharing_of_results && pts_network::internet_support_available()) { if ($this->auto_upload_to_openbenchmarking || pts_openbenchmarking_client::auto_upload_results() || pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/AlwaysUploadResultsToOpenBenchmarking', 'FALSE')) { $upload_results = true; } else { if ($this->batch_mode) { $upload_results = $this->batch_mode['UploadResults']; } else { if (!$this->auto_mode) { $upload_results = pts_user_io::prompt_bool_input('Would you like to upload the results to OpenBenchmarking.org', true); } else { $upload_results = false; } } } if ($upload_results) { $this->openbenchmarking_results_data = pts_openbenchmarking::upload_test_result($this, true); if ($this->get_results_url()) { if (!$this->auto_mode && !$this->batch_mode && pts_openbenchmarking_client::auto_upload_results() == false) { pts_client::display_web_page($this->get_results_url(), 'Do you want to launch OpenBenchmarking.org', true); } } else { echo PHP_EOL . 'Results Failed To Upload.' . PHP_EOL; } } } } }
protected static function install_test_process(&$test_install_request, $no_prompts) { // Install a test $identifier = $test_install_request->test_profile->get_identifier(); $test_install_directory = $test_install_request->test_profile->get_install_dir(); pts_file_io::mkdir(dirname($test_install_directory)); pts_file_io::mkdir($test_install_directory); $installed = false; if (ceil(disk_free_space($test_install_directory) / 1048576) < $test_install_request->test_profile->get_download_size() + 128) { self::test_install_error(null, $test_install_request, 'There is not enough space at ' . $test_install_directory . ' for the test files.'); } else { if (ceil(disk_free_space($test_install_directory) / 1048576) < $test_install_request->test_profile->get_environment_size(false) + 128) { self::test_install_error(null, $test_install_request, 'There is not enough space at ' . $test_install_directory . ' for this test.'); } else { pts_test_installer::setup_test_install_directory($test_install_request, true); // Download test files $download_test_files = pts_test_installer::download_test_files($test_install_request, false, $no_prompts); if ($download_test_files == false) { self::test_install_error(null, $test_install_request, 'Downloading of needed test files failed.'); return false; } if ($test_install_request->test_profile->get_file_installer() != false) { self::create_compiler_mask($test_install_request); pts_module_manager::module_process('__pre_test_install', $identifier); pts_client::$display->test_install_begin($test_install_request); $pre_install_message = $test_install_request->test_profile->get_pre_install_message(); $post_install_message = $test_install_request->test_profile->get_post_install_message(); $install_agreement = $test_install_request->test_profile->get_installation_agreement_message(); if (!empty($install_agreement)) { if (pts_strings::is_url($install_agreement)) { $install_agreement = pts_network::http_get_contents($install_agreement); if (empty($install_agreement)) { self::test_install_error(null, $test_install_request, 'The user agreement could not be found. Test installation aborted.'); return false; } } echo $install_agreement . PHP_EOL; if (!$no_prompts) { $user_agrees = pts_user_io::prompt_bool_input('Do you agree to these terms', false, 'INSTALL_AGREEMENT'); if (!$user_agrees) { self::test_install_error(null, $test_install_request, 'User agreement failed; this test will not be installed.'); return false; } } } pts_client::$display->display_interrupt_message($pre_install_message); $install_time_length_start = microtime(true); $install_log = pts_tests::call_test_script($test_install_request->test_profile, 'install', null, $test_install_directory, $test_install_request->special_environment_vars, false); $test_install_request->install_time_duration = ceil(microtime(true) - $install_time_length_start); pts_client::$display->display_interrupt_message($post_install_message); if (!empty($install_log)) { file_put_contents($test_install_directory . 'install.log', $install_log); pts_file_io::unlink($test_install_directory . 'install-failed.log'); pts_client::$display->test_install_output($install_log); } if (is_file($test_install_directory . 'install-exit-status')) { // If the installer writes its exit status to ~/install-exit-status, if it's non-zero the install failed $install_exit_status = pts_file_io::file_get_contents($test_install_directory . 'install-exit-status'); unlink($test_install_directory . 'install-exit-status'); if ($install_exit_status != 0 && phodevi::is_windows() == false) { $install_error = null; // TODO: perhaps better way to handle this than to remove pts-install.xml pts_file_io::unlink($test_install_directory . 'pts-install.xml'); if (is_file($test_install_directory . 'install.log')) { $install_log = pts_file_io::file_get_contents($test_install_directory . 'install.log'); $install_error = pts_tests::scan_for_error($install_log, $test_install_directory); copy($test_install_directory . 'install.log', $test_install_directory . 'install-failed.log'); } //pts_test_installer::setup_test_install_directory($test_install_request, true); // Remove installed files from the bunked installation self::test_install_error(null, $test_install_request, 'The installer exited with a non-zero exit status.'); if ($install_error != null) { $test_install_request->install_error = pts_tests::pretty_error_string($install_error); if ($test_install_request->install_error != null) { self::test_install_error(null, $test_install_request, 'ERROR: ' . $test_install_request->install_error); } } pts_client::$display->test_install_error('LOG: ' . str_replace(pts_core::user_home_directory(), '~/', $test_install_directory) . 'install-failed.log' . PHP_EOL); if (pts_client::do_anonymous_usage_reporting()) { // If anonymous usage reporting enabled, report test install failure to OpenBenchmarking.org pts_openbenchmarking_client::upload_usage_data('test_install_failure', array($test_install_request, $install_error)); } return false; } } pts_module_manager::module_process('__post_test_install', $identifier); $installed = true; if (pts_config::read_bool_config('PhoronixTestSuite/Options/Installation/RemoveDownloadFiles', 'FALSE')) { // Remove original downloaded files foreach ($test_install_request->get_download_objects() as $download_object) { pts_file_io::unlink($test_install_directory . $download_object->get_filename()); } } } else { pts_client::$display->test_install_error('No installation script found.'); $installed = true; } // Additional validation checks? $custom_validated_output = pts_tests::call_test_script($test_install_request->test_profile, 'validate-install', PHP_EOL . 'Validating Installation...' . PHP_EOL, $test_install_directory, null, false); if (!empty($custom_validated_output) && !pts_strings::string_bool($custom_validated_output)) { $installed = false; } } } echo PHP_EOL; return $installed; }
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); }