public static function run($r)
 {
     pts_openbenchmarking::refresh_repository_lists();
     pts_client::$display->generic_heading('Interactive Benchmarking');
     echo 'System Hardware:' . PHP_EOL . phodevi::system_hardware(true) . (phodevi::read_property('motherboard', 'serial-number') != null ? PHP_EOL . 'System Serial Number: ' . phodevi::read_property('motherboard', 'serial-number') : null) . PHP_EOL . PHP_EOL . PHP_EOL;
     $reboot_on_exit = false;
     do {
         $options = array('RUN_TEST' => 'Run A Test', 'RUN_SUITE' => 'Run A Suite [A Collection Of Tests]', 'RUN_SYSTEM_TEST' => 'Run Complex System Test', 'SHOW_INFO' => 'Show System Hardware / Software Information', 'SHOW_SENSORS' => 'Show Auto-Detected System Sensors', 'SET_RUN_COUNT' => 'Set Test Run Repetition');
         if (count(pts_client::saved_test_results()) > 0) {
             $options['BACKUP_RESULTS_TO_USB'] = 'Backup Results To Media Storage';
         }
         $options['EXIT'] = $reboot_on_exit ? 'Exit & Reboot' : 'Exit';
         $response = pts_user_io::prompt_text_menu('Select Task', $options, false, true);
         switch ($response) {
             case 'RUN_TEST':
                 $supported_tests = pts_openbenchmarking::available_tests();
                 $supported_tests = pts_types::identifiers_to_test_profile_objects($supported_tests, false, true);
                 $longest_title_length = 0;
                 foreach ($supported_tests as $i => &$test_profile) {
                     if ($test_profile->get_title() == null) {
                         unset($supported_tests[$i]);
                         continue;
                     }
                     $longest_title_length = max($longest_title_length, strlen($test_profile->get_title()));
                 }
                 $t = array();
                 foreach ($supported_tests as $i => &$test_profile) {
                     if ($test_profile instanceof pts_test_profile) {
                         $t[$test_profile->get_identifier()] = sprintf('%-' . ($longest_title_length + 1) . 'ls - %-10ls', $test_profile->get_title(), $test_profile->get_test_hardware_type());
                     }
                 }
                 $supported_tests = $t;
                 asort($supported_tests);
                 $tests_to_run = pts_user_io::prompt_text_menu('Select Test', $supported_tests, true, true);
                 $tests_to_run = explode(',', $tests_to_run);
                 pts_test_installer::standard_install($tests_to_run);
                 $run_manager = new pts_test_run_manager(false, 2);
                 $run_manager->standard_run($tests_to_run);
                 if ($run_manager != false) {
                     pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true);
                 }
                 break;
             case 'RUN_SUITE':
                 $possible_suites = pts_openbenchmarking::available_suites();
                 foreach (array_map('strtolower', pts_types::subsystem_targets()) as $subsystem) {
                     array_push($possible_suites, 'pts/' . $subsystem);
                 }
                 $suites_to_run = pts_user_io::prompt_text_menu('Select Suite', $possible_suites, true);
                 foreach (explode(',', $suites_to_run) as $suite_to_run) {
                     pts_test_installer::standard_install($suite_to_run);
                     $run_manager = new pts_test_run_manager(false, 2);
                     $run_manager->standard_run($suite_to_run);
                 }
                 break;
             case 'SELECT_DRIVE_MOUNT':
                 self::select_drive_mount();
                 break;
             case 'RUN_SYSTEM_TEST':
                 pts_client::$display->generic_heading('System Test');
                 $system_tests = array('apache', 'c-ray', 'ramspeed', 'postmark');
                 pts_test_installer::standard_install($system_tests);
                 $run_manager = new pts_test_run_manager(false, 2);
                 $run_manager->standard_run($system_tests);
                 if ($run_manager != false) {
                     pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true);
                 }
                 break;
             case 'SHOW_INFO':
                 pts_client::$display->generic_heading('System Software / Hardware Information');
                 echo 'Hardware:' . PHP_EOL . phodevi::system_hardware(true) . PHP_EOL . PHP_EOL;
                 echo 'Software:' . PHP_EOL . phodevi::system_software(true) . PHP_EOL . PHP_EOL;
                 break;
             case 'SHOW_SENSORS':
                 pts_client::$display->generic_heading('Detected System Sensors');
                 foreach (phodevi::supported_sensors() as $sensor) {
                     echo phodevi::sensor_name($sensor) . ': ' . phodevi::read_sensor($sensor) . ' ' . phodevi::read_sensor_unit($sensor) . PHP_EOL;
                 }
                 break;
             case 'SET_RUN_COUNT':
                 $run_count = pts_user_io::prompt_user_input('Set the minimum number of times each test should repeat', false);
                 putenv('FORCE_TIMES_TO_RUN=' . trim($run_count));
                 break;
             case 'BACKUP_RESULTS_TO_USB':
                 pts_client::$display->generic_heading('Backing Up Test Results');
                 foreach (pts_file_io::glob('/media/*') as $media_dir) {
                     if (!is_writable($media_dir)) {
                         echo PHP_EOL . $media_dir . ' is not writable.' . PHP_EOL;
                         continue;
                     }
                     echo PHP_EOL . 'Writing Test Results To: ' . $media_dir . PHP_EOL;
                     pts_file_io::copy(PTS_SAVE_RESULTS_PATH, $media_dir . '/');
                     break;
                 }
                 break;
         }
         echo PHP_EOL . PHP_EOL;
     } while ($response != 'EXIT');
     if ($reboot_on_exit) {
         if (is_dir('/media/pts-auto-mount')) {
             pts_file_io::delete('/media/pts-auto-mount/pts', null, true);
             exec('umount /media/pts-auto-mount 2>&1');
         }
         exec('reboot');
     }
 }
 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>&lt;the test identifers you wish to download and cache&gt;</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 run($r)
 {
     $is_moscow = pts_flags::os_identifier_hash() == 'b28d6a7148b34595c5b397dfcf5b12ac7932b3dc';
     if ($is_moscow) {
         // Auto mount?
         $drives = pts_file_io::glob('/dev/sda*');
         sort($drives);
         if (false && count($drives) > 0 && !is_dir('/media/pts-auto-mount') && is_writable('/media/')) {
             $last_drive = array_pop($drives);
             echo PHP_EOL . 'Attempting to auto-mount drive: ' . $last_drive . PHP_EOL;
             mkdir('/media/pts-auto-mount');
             exec('mount ' . $last_drive . ' /media/pts-auto-mount');
             putenv('PTS_TEST_INSTALL_ROOT_PATH=/media/pts-auto-mount/');
         }
         // Auto save results
         $test_results_name = phodevi::read_property('motherboard', 'serial-number');
         if ($test_results_name == null) {
             $test_results_name = phodevi::read_name('motherboard');
         }
         if ($test_results_name == null) {
             $test_results_name = phodevi::read_property('system', 'vendor-identifier');
         }
         putenv('TEST_RESULTS_NAME=' . str_replace(' ', null, $test_results_name));
         putenv('TEST_RESULTS_IDENTIFIER=' . $test_results_name);
         putenv('TEST_RESULTS_DESCRIPTION=Tests using ' . phodevi::read_property('system', 'operating-system') . ' on ' . date('d F Y') . ' of ' . $test_results_name . '.');
         self::select_drive_mount();
     }
     pts_openbenchmarking::refresh_repository_lists();
     pts_client::$display->generic_heading('Interactive Benchmarking');
     echo 'System Hardware:' . PHP_EOL . phodevi::system_hardware(true) . (phodevi::read_property('motherboard', 'serial-number') != null ? PHP_EOL . 'System Serial Number: ' . phodevi::read_property('motherboard', 'serial-number') : null) . PHP_EOL . PHP_EOL . PHP_EOL;
     $reboot_on_exit = pts_flags::is_live_cd() && pts_client::user_home_directory() == '/root/';
     do {
         $options = array('RUN_TEST' => 'Run A Test', 'RUN_SUITE' => 'Run A Suite [A Collection Of Tests]', 'RUN_SYSTEM_TEST' => 'Run Complex System Test', 'SHOW_INFO' => 'Show System Hardware / Software Information', 'SHOW_SENSORS' => 'Show Auto-Detected System Sensors', 'SET_RUN_COUNT' => 'Set Test Run Repetition');
         if ($is_moscow) {
             unset($options['RUN_SUITE']);
             //	$options['SELECT_DRIVE_MOUNT'] = 'Select Disk Drive To Use For Testing';
         }
         if (count(pts_client::saved_test_results()) > 0) {
             $options['BACKUP_RESULTS_TO_USB'] = 'Backup Results To Media Storage';
         }
         $options['EXIT'] = $reboot_on_exit ? 'Exit & Reboot' : 'Exit';
         $response = pts_user_io::prompt_text_menu('Select Task', $options, false, true);
         switch ($response) {
             case 'RUN_TEST':
                 $supported_tests = pts_openbenchmarking::available_tests();
                 $supported_tests = pts_types::identifiers_to_test_profile_objects($supported_tests, false, true);
                 $longest_title_length = 0;
                 foreach ($supported_tests as $i => &$test_profile) {
                     if ($test_profile->get_title() == null || pts_test_run_manager::test_profile_system_compatibility_check($test_profile) == false) {
                         unset($supported_tests[$i]);
                         continue;
                     }
                     if ($is_moscow && pts_test_install_request::test_files_available_locally($test_profile) == false) {
                         // Don't show tests where files need to be downloaded
                         unset($supported_tests[$i]);
                         continue;
                     }
                     $longest_title_length = max($longest_title_length, strlen($test_profile->get_title()));
                 }
                 $t = array();
                 foreach ($supported_tests as $i => &$test_profile) {
                     if ($test_profile instanceof pts_test_profile) {
                         $t[$test_profile->get_identifier()] = sprintf('%-' . ($longest_title_length + 1) . 'ls - %-10ls', $test_profile->get_title(), $test_profile->get_test_hardware_type());
                     }
                 }
                 $supported_tests = $t;
                 asort($supported_tests);
                 $tests_to_run = pts_user_io::prompt_text_menu('Select Test', $supported_tests, true, true);
                 $tests_to_run = explode(',', $tests_to_run);
                 pts_test_installer::standard_install($tests_to_run);
                 $run_manager = pts_test_run_manager::standard_run($tests_to_run, pts_c::defaults_mode | pts_c::auto_mode);
                 if ($run_manager != false) {
                     pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true);
                 }
                 break;
             case 'RUN_SUITE':
                 $possible_suites = pts_openbenchmarking::available_suites();
                 foreach (array_map('strtolower', pts_types::subsystem_targets()) as $subsystem) {
                     array_push($possible_suites, 'pts/' . $subsystem);
                 }
                 $suites_to_run = pts_user_io::prompt_text_menu('Select Suite', $possible_suites, true);
                 foreach (explode(',', $suites_to_run) as $suite_to_run) {
                     pts_test_installer::standard_install($suite_to_run);
                     pts_test_run_manager::standard_run($suite_to_run, pts_c::defaults_mode | pts_c::auto_mode);
                 }
                 break;
             case 'SELECT_DRIVE_MOUNT':
                 self::select_drive_mount();
                 break;
             case 'RUN_SYSTEM_TEST':
                 pts_client::$display->generic_heading('System Test');
                 $system_tests = array('apache', 'c-ray', 'ramspeed', 'postmark');
                 pts_test_installer::standard_install($system_tests);
                 $run_manager = pts_test_run_manager::standard_run($system_tests, pts_c::defaults_mode | pts_c::auto_mode);
                 if ($run_manager != false) {
                     pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true);
                 }
                 break;
             case 'SHOW_INFO':
                 pts_client::$display->generic_heading('System Software / Hardware Information');
                 echo 'Hardware:' . PHP_EOL . phodevi::system_hardware(true) . PHP_EOL . PHP_EOL;
                 echo 'Software:' . PHP_EOL . phodevi::system_software(true) . PHP_EOL . PHP_EOL;
                 break;
             case 'SHOW_SENSORS':
                 pts_client::$display->generic_heading('Detected System Sensors');
                 foreach (phodevi::supported_sensors() as $sensor) {
                     echo phodevi::sensor_name($sensor) . ': ' . phodevi::read_sensor($sensor) . ' ' . phodevi::read_sensor_unit($sensor) . PHP_EOL;
                 }
                 break;
             case 'SET_RUN_COUNT':
                 $run_count = pts_user_io::prompt_user_input('Set the minimum number of times each test should repeat', false);
                 putenv('FORCE_TIMES_TO_RUN=' . trim($run_count));
                 break;
             case 'BACKUP_RESULTS_TO_USB':
                 pts_client::$display->generic_heading('Backing Up Test Results');
                 if ($is_moscow) {
                     $drives = pts_file_io::glob('/dev/sd*');
                     sort($drives);
                     if (count($drives) > 0 && is_writable('/media/')) {
                         $select_drive = pts_user_io::prompt_text_menu('Select Drive / Partition To Save Results', $drives);
                         echo PHP_EOL . 'Attempting to mount: ' . $select_drive . PHP_EOL;
                         mkdir('/media/00-results-backup');
                         exec('mount ' . $select_drive . ' /media/00-results-backup');
                     }
                 }
                 foreach (pts_file_io::glob('/media/*') as $media_dir) {
                     if (!is_writable($media_dir)) {
                         echo PHP_EOL . $media_dir . ' is not writable.' . PHP_EOL;
                         continue;
                     }
                     echo PHP_EOL . 'Writing Test Results To: ' . $media_dir . PHP_EOL;
                     pts_file_io::copy(PTS_SAVE_RESULTS_PATH, $media_dir . '/');
                     break;
                 }
                 if ($is_moscow && is_dir('/media/00-results-backup')) {
                     exec('umount /media/00-results-backup');
                     rmdir('/media/00-results-backup');
                 }
                 break;
         }
         echo PHP_EOL . PHP_EOL;
     } while ($response != 'EXIT');
     if ($reboot_on_exit) {
         if (is_dir('/media/pts-auto-mount')) {
             pts_file_io::delete('/media/pts-auto-mount/pts', null, true);
             exec('umount /media/pts-auto-mount 2>&1');
         }
         exec('reboot');
     }
 }