function create_new_phoromatic_account($register_username, $register_password, $register_password_confirm, $register_email, $seed_accountid = null)
{
    // REGISTER NEW USER
    if (strlen($register_username) < 4 || strpos($register_username, ' ') !== false) {
        phoromatic_error_page('Oops!', 'Please go back and ensure the supplied username is at least four characters long and contains no spaces.');
        return false;
    }
    if (in_array(strtolower($register_username), array('admin', 'administrator', 'rootadmin'))) {
        phoromatic_error_page('Oops!', $register_username . ' is a reserved and common username that may be used for other purposes, please make a different selection.');
        return false;
    }
    if (strlen($register_password) < 6) {
        phoromatic_error_page('Oops!', 'Please go back and ensure the supplied password is at least six characters long.');
        return false;
    }
    if ($register_password != $register_password_confirm) {
        phoromatic_error_page('Oops!', 'Please go back and ensure the supplied password matches the password confirmation.');
        return false;
    }
    if ($register_email == null || filter_var($register_email, FILTER_VALIDATE_EMAIL) == false) {
        phoromatic_error_page('Oops!', 'Please enter a valid email address.');
        return false;
    }
    $valid_user_name_chars = '1234567890-_.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    for ($i = 0; $i < count($register_username); $i++) {
        if (strpos($valid_user_name_chars, substr($register_username, $i, 1)) === false) {
            phoromatic_error_page('Oops!', 'Please go back and ensure a valid user-name. The character <em>' . substr($register_username, $i, 1) . '</em> is not allowed.');
            return false;
        }
    }
    $matching_users = phoromatic_server::$db->querySingle('SELECT UserName FROM phoromatic_users WHERE UserName = \'' . SQLite3::escapeString($register_username) . '\'');
    if (!empty($matching_users)) {
        phoromatic_error_page('Oops!', 'The user-name is already taken.');
        return false;
    }
    if (phoromatic_server::read_setting('add_new_users_to_account') != null) {
        $account_id = phoromatic_server::read_setting('add_new_users_to_account');
        $is_new_account = false;
    } else {
        $id_tries = 0;
        do {
            if ($id_tries == 0 && $seed_accountid != null && isset($seed_accountid[5])) {
                $account_id = strtoupper(substr($seed_accountid, 0, 6));
            } else {
                $account_id = pts_strings::random_characters(6, true);
            }
            $matching_accounts = phoromatic_server::$db->querySingle('SELECT AccountID FROM phoromatic_accounts WHERE AccountID = \'' . $account_id . '\'');
            $id_tries++;
        } while (!empty($matching_accounts));
        $is_new_account = true;
    }
    $user_id = pts_strings::random_characters(4, true);
    if ($is_new_account) {
        pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' created a new account: ' . $user_id . ' - ' . $account_id);
        $account_salt = pts_strings::random_characters(12, true);
        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_accounts (AccountID, ValidateID, CreatedOn, Salt) VALUES (:account_id, :validate_id, :current_time, :salt)');
        $stmt->bindValue(':account_id', $account_id);
        $stmt->bindValue(':validate_id', pts_strings::random_characters(4, true));
        $stmt->bindValue(':salt', $account_salt);
        $stmt->bindValue(':current_time', phoromatic_server::current_time());
        $result = $stmt->execute();
        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_account_settings (AccountID) VALUES (:account_id)');
        $stmt->bindValue(':account_id', $account_id);
        $result = $stmt->execute();
        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_user_settings (UserID, AccountID) VALUES (:user_id, :account_id)');
        $stmt->bindValue(':user_id', $user_id);
        $stmt->bindValue(':account_id', $account_id);
        $result = $stmt->execute();
    } else {
        pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' being added to an account: ' . $user_id . ' - ' . $account_id);
        $account_salt = phoromatic_server::$db->querySingle('SELECT Salt FROM phoromatic_accounts WHERE AccountID = \'' . $account_id . '\'');
    }
    $salted_password = hash('sha256', $account_salt . $register_password);
    $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_users (UserID, AccountID, UserName, Email, Password, CreatedOn, LastIP, AdminLevel) VALUES (:user_id, :account_id, :user_name, :email, :password, :current_time, :last_ip, :admin_level)');
    $stmt->bindValue(':user_id', $user_id);
    $stmt->bindValue(':account_id', $account_id);
    $stmt->bindValue(':user_name', $register_username);
    $stmt->bindValue(':email', $register_email);
    $stmt->bindValue(':password', $salted_password);
    $stmt->bindValue(':last_ip', $_SERVER['REMOTE_ADDR']);
    $stmt->bindValue(':current_time', phoromatic_server::current_time());
    $stmt->bindValue(':admin_level', $is_new_account ? 1 : 10);
    $result = $stmt->execute();
    pts_file_io::mkdir(phoromatic_server::phoromatic_account_path($account_id));
    phoromatic_server::send_email($register_email, 'Phoromatic Account Registration', ($e = phoromatic_server::read_setting('admin_support_email')) != null ? $e : '*****@*****.**', '<p><strong>' . $register_username . '</strong>:</p><p>Your Phoromatic account has been created and is now active.</p>');
    return true;
}
    public static function render_page_process($PATH)
    {
        if (isset($_POST['suite_title'])) {
            //	echo '<pre>';
            //	var_dump($_POST);
            //	echo '</pre>';
            if (strlen($_POST['suite_title']) < 3) {
                echo '<h2>Suite title must be at least three characters.</h2>';
            }
            //echo 'TEST SUITE: ' . $_POST['suite_title'] . '<br />';
            //echo 'TEST SUITE: ' . $_POST['suite_description'] . '<br />';
            $tests = array();
            foreach ($_POST['test_add'] as $i => $test_identifier) {
                $test_prefix = $_POST['test_prefix'][$i];
                $args = array();
                $args_name = array();
                foreach ($_POST as $i => $v) {
                    if (strpos($i, $test_prefix) !== false && substr($i, -9) != '_selected') {
                        if (strpos($v, '||') !== false) {
                            $opts = explode('||', $v);
                            $a = array();
                            $d = array();
                            foreach ($opts as $opt) {
                                $t = explode('::', $opt);
                                array_push($a, $t[1]);
                                array_push($d, $t[0]);
                            }
                            array_push($args, $a);
                            array_push($args_name, $d);
                        } else {
                            array_push($args, array($v));
                            array_push($args_name, array($_POST[$i . '_selected']));
                        }
                    }
                }
                $test_args = array();
                $test_args_description = array();
                pts_test_run_options::compute_all_combinations($test_args, null, $args, 0);
                pts_test_run_options::compute_all_combinations($test_args_description, null, $args_name, 0, ' - ');
                foreach (array_keys($test_args) as $i) {
                    array_push($tests, array('test' => $test_identifier, 'description' => $test_args_description[$i], 'args' => $test_args[$i]));
                }
            }
            if (count($tests) < 1) {
                echo '<h2>You must add at least one test to the suite.</h2>';
            }
            $suite_writer = new pts_test_suite_writer();
            $version_bump = 0;
            do {
                $suite_version = '1.' . $version_bump . '.0';
                $suite_id = $suite_writer->clean_save_name_string($_POST['suite_title']) . '-' . $suite_version;
                $suite_dir = phoromatic_server::phoromatic_account_suite_path($_SESSION['AccountID'], $suite_id);
                $version_bump++;
            } while (is_dir($suite_dir));
            pts_file_io::mkdir($suite_dir);
            $save_to = $suite_dir . '/suite-definition.xml';
            $suite_writer->add_suite_information($_POST['suite_title'], $suite_version, $_SESSION['UserName'], 'System', $_POST['suite_description']);
            foreach ($tests as $m) {
                $suite_writer->add_to_suite($m['test'], $m['args'], $m['description']);
            }
            $suite_writer->save_xml($save_to);
            echo '<h2>Saved As ' . $suite_id . '</h2>';
        }
        echo phoromatic_webui_header_logged_in();
        $main = '<h1>Local Suites</h1><p>Find already created local test suites by your account/group via the <a href="/?local_suites">local suites</a> page.</p>';
        if (!PHOROMATIC_USER_IS_VIEWER) {
            $main .= '<h1>Build Suite</h1><p>A test suite in the realm of the Phoronix Test Suite, OpenBenchmarking.org, and Phoromatic is <strong>a collection of test profiles with predefined settings</strong>. Establishing a test suite makes it easy to run repetitive testing on the same set of test profiles by simply referencing the test suite name.</p>';
            $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="build_suite" id="build_suite" method="post" onsubmit="return validate_suite();">
			<h3>Title:</h3>
			<p><input type="text" name="suite_title" /></p>
			<h3>Description:</h3>
			<p><textarea name="suite_description" id="suite_description" cols="60" rows="2"></textarea></p>
			<h3>Tests In Schedule:</h3>
			<p><div id="test_details"></div></p>
			<h3>Add Another Test</h3>';
            $main .= '<select name="add_to_suite_select_test" id="add_to_suite_select_test" onchange="phoromatic_build_suite_test_details();">';
            $dc = pts_strings::add_trailing_slash(pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
            $dc_exists = is_file($dc . 'pts-download-cache.json');
            foreach (pts_openbenchmarking::available_tests(false, true) as $test) {
                $cache_checked = false;
                if ($dc_exists) {
                    $cache_json = file_get_contents($dc . 'pts-download-cache.json');
                    $cache_json = json_decode($cache_json, true);
                    if ($cache_json && isset($cache_json['phoronix-test-suite']['cached-tests'])) {
                        $cache_checked = true;
                        if (!in_array($test, $cache_json['phoronix-test-suite']['cached-tests'])) {
                            continue;
                        }
                    }
                }
                if (!$cache_checked && phoromatic_server::read_setting('show_local_tests_only') && pts_test_install_request::test_files_in_cache($test, true, true) == false) {
                    continue;
                }
                $main .= '<option value="' . $test . '">' . $test . '</option>';
            }
            $main .= '</select>';
            $main .= '<p align="right"><input name="submit" value="Create Suite" type="submit" onclick="return pts_rmm_validate_suite();" /></p>';
        }
        echo '<div id="pts_phoromatic_main_area">' . $main . '</div>';
        echo phoromatic_webui_footer();
    }
 public static function generate_result_export_dump($account_id)
 {
     pts_file_io::mkdir(self::phoromatic_path() . 'result-export/');
     $export_path = self::phoromatic_path() . 'result-export/' . $account_id . '/';
     pts_file_io::mkdir($export_path);
     $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_schedules WHERE AccountID = :account_id AND State = 1 AND (SELECT COUNT(*) FROM phoromatic_schedules_tests WHERE AccountID = :account_id AND ScheduleID = phoromatic_schedules.ScheduleID) > 0 AND (SELECT COUNT(*) FROM phoromatic_results WHERE AccountID = :account_id AND ScheduleID = phoromatic_schedules.ScheduleID) > 4 ORDER BY Title ASC');
     $stmt->bindValue(':account_id', $account_id);
     $result = $stmt->execute();
     $exported_result_index = array('phoromatic' => array());
     while ($result && ($row = $result->fetchArray())) {
         $id = str_replace(' ', '-', strtolower($row['Title']));
         $triggers = array();
         $stmt2 = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_results WHERE AccountID = :account_id AND ScheduleID = :schedule_id ORDER BY UploadTime DESC');
         $stmt2->bindValue(':account_id', $row['AccountID']);
         $stmt2->bindValue(':schedule_id', $row['ScheduleID']);
         $result2 = $stmt2->execute();
         pts_file_io::mkdir($export_path);
         while ($result2 && ($row2 = $result2->fetchArray())) {
             $composite_xml = phoromatic_server::phoromatic_account_result_path($row2['AccountID'], $row2['UploadID']) . 'composite.xml';
             if (is_file($composite_xml)) {
                 pts_file_io::mkdir($export_path . $id . '/' . $row2['Trigger']);
                 pts_file_io::mkdir($export_path . $id . '/' . $row2['Trigger'] . '/' . phoromatic_server::system_id_to_name($row2['SystemID'], $row2['AccountID']));
                 copy($composite_xml, $export_path . $id . '/' . $row2['Trigger'] . '/' . phoromatic_server::system_id_to_name($row2['SystemID'], $row2['AccountID']) . '/composite.xml');
             }
             pts_arrays::unique_push($triggers, $row2['Trigger']);
         }
         $exported_result_index['phoromatic'][$id] = array('title' => $row['Title'], 'id' => $id, 'description' => $row['Description'], 'triggers' => $triggers);
     }
     $exported_result_index = json_encode($exported_result_index, JSON_PRETTY_PRINT);
     file_put_contents($export_path . '/export-index.json', $exported_result_index);
 }
 public static function copy_file($from_file, $to_file)
 {
     // Copy a file for a module
     $save_base_dir = self::save_dir();
     pts_file_io::mkdir($save_base_dir);
     if (($extra_dir = dirname($to_file)) != "." && !is_dir($save_base_dir . $extra_dir)) {
         mkdir($save_base_dir . $extra_dir);
     }
     if (is_file($from_file) && (!is_file($save_base_dir . $to_file) || md5_file($from_file) != md5_file($save_base_dir . $to_file))) {
         if (copy($from_file, $save_base_dir . $to_file)) {
             return $save_base_dir . $to_file;
         }
     }
     return false;
 }
    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_test(&$test_run_manager, &$test_run_request)
 {
     $test_identifier = $test_run_request->test_profile->get_identifier();
     $extra_arguments = $test_run_request->get_arguments();
     $arguments_description = $test_run_request->get_arguments_description();
     $full_output = pts_config::read_bool_config('PhoronixTestSuite/Options/General/FullOutput', 'FALSE');
     // Do the actual test running process
     $test_directory = $test_run_request->test_profile->get_install_dir();
     if (!is_dir($test_directory)) {
         return false;
     }
     $lock_file = $test_directory . 'run_lock';
     if (pts_client::create_lock($lock_file) == false && $test_run_manager->is_multi_test_stress_run() == false) {
         self::test_run_error($test_run_manager, $test_run_request, 'The ' . $test_identifier . ' test is already running.');
         return false;
     }
     $active_result_buffer = new pts_test_result_buffer_active();
     $test_run_request->active =& $active_result_buffer;
     $execute_binary = $test_run_request->test_profile->get_test_executable();
     $times_to_run = $test_run_request->test_profile->get_times_to_run();
     $ignore_runs = $test_run_request->test_profile->get_runs_to_ignore();
     $test_type = $test_run_request->test_profile->get_test_hardware_type();
     $allow_cache_share = $test_run_request->test_profile->allow_cache_share();
     $min_length = $test_run_request->test_profile->get_min_length();
     $max_length = $test_run_request->test_profile->get_max_length();
     if ($test_run_request->test_profile->get_environment_testing_size() > 1 && ceil(disk_free_space($test_directory) / 1048576) < $test_run_request->test_profile->get_environment_testing_size()) {
         // Ensure enough space is available on disk during testing process
         self::test_run_error($test_run_manager, $test_run_request, 'There is not enough space (at ' . $test_directory . ') for this test to run.');
         pts_client::release_lock($lock_file);
         return false;
     }
     $to_execute = $test_run_request->test_profile->get_test_executable_dir();
     $pts_test_arguments = trim($test_run_request->test_profile->get_default_arguments() . ' ' . str_replace($test_run_request->test_profile->get_default_arguments(), '', $extra_arguments) . ' ' . $test_run_request->test_profile->get_default_post_arguments());
     $extra_runtime_variables = pts_tests::extra_environmental_variables($test_run_request->test_profile);
     // Start
     $cache_share_pt2so = $test_directory . 'cache-share-' . PTS_INIT_TIME . '.pt2so';
     $cache_share_present = $allow_cache_share && is_file($cache_share_pt2so);
     $test_run_request->set_used_arguments_description($arguments_description);
     pts_module_manager::module_process('__pre_test_run', $test_run_request);
     $time_test_start = time();
     pts_client::$display->test_run_start($test_run_manager, $test_run_request);
     if (!$cache_share_present) {
         $pre_output = pts_tests::call_test_script($test_run_request->test_profile, 'pre', 'Running Pre-Test Script', $pts_test_arguments, $extra_runtime_variables, true);
         if ($pre_output != null && (pts_client::is_debug_mode() || $full_output)) {
             pts_client::$display->test_run_instance_output($pre_output);
         }
         if (is_file($test_directory . 'pre-test-exit-status')) {
             // If the pre script writes its exit status to ~/pre-test-exit-status, if it's non-zero the test run failed
             $exit_status = pts_file_io::file_get_contents($test_directory . 'pre-test-exit-status');
             unlink($test_directory . 'pre-test-exit-status');
             if ($exit_status != 0) {
                 self::test_run_instance_error($test_run_manager, $test_run_request, 'The pre run script exited with a non-zero exit status.' . PHP_EOL);
                 self::test_run_error($test_run_manager, $test_run_request, 'This test execution has been abandoned.');
                 return false;
             }
         }
     }
     pts_client::$display->display_interrupt_message($test_run_request->test_profile->get_pre_run_message());
     $runtime_identifier = time();
     $execute_binary_prepend = '';
     if ($test_run_request->exec_binary_prepend != null) {
         $execute_binary_prepend = $test_run_request->exec_binary_prepend;
     }
     if (!$cache_share_present && $test_run_request->test_profile->is_root_required()) {
         if (phodevi::is_root() == false) {
             pts_client::$display->test_run_error('This test must be run as the root / administrator account.');
         }
         $execute_binary_prepend .= ' ' . PTS_CORE_STATIC_PATH . 'root-access.sh ';
     }
     if ($allow_cache_share && !is_file($cache_share_pt2so)) {
         $cache_share = new pts_storage_object(false, false);
     }
     if ($test_run_manager->get_results_identifier() != null && $test_run_manager->get_file_name() != null && pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/SaveTestLogs', 'FALSE')) {
         $backup_test_log_dir = PTS_SAVE_RESULTS_PATH . $test_run_manager->get_file_name() . '/test-logs/active/' . $test_run_manager->get_results_identifier() . '/';
         pts_file_io::delete($backup_test_log_dir);
         pts_file_io::mkdir($backup_test_log_dir, 0777, true);
     } else {
         $backup_test_log_dir = false;
     }
     for ($i = 0, $abort_testing = false, $time_test_start_actual = time(), $defined_times_to_run = $times_to_run; $i < $times_to_run && $i < 256 && !$abort_testing; $i++) {
         pts_client::$display->test_run_instance_header($test_run_request);
         $test_log_file = $test_directory . basename($test_identifier) . '-' . $runtime_identifier . '-' . ($i + 1) . '.log';
         $is_expected_last_run = $i == $times_to_run - 1;
         $test_extra_runtime_variables = array_merge($extra_runtime_variables, array('LOG_FILE' => $test_log_file, 'DISPLAY' => getenv('DISPLAY'), 'PATH' => getenv('PATH')));
         $restored_from_cache = false;
         if ($cache_share_present) {
             $cache_share = pts_storage_object::recover_from_file($cache_share_pt2so);
             if ($cache_share) {
                 $test_result = $cache_share->read_object('test_results_output_' . $i);
                 $test_extra_runtime_variables['LOG_FILE'] = $cache_share->read_object('log_file_location_' . $i);
                 if ($test_extra_runtime_variables['LOG_FILE'] != null) {
                     file_put_contents($test_extra_runtime_variables['LOG_FILE'], $cache_share->read_object('log_file_' . $i));
                     $test_run_time = 0;
                     // This wouldn't be used for a cache share since it would always be the same, but declare the value so the variable is at least initialized
                     $restored_from_cache = true;
                 }
             }
             unset($cache_share);
         }
         if ($restored_from_cache == false) {
             $test_run_command = 'cd ' . $to_execute . ' && ' . $execute_binary_prepend . './' . $execute_binary . ' ' . $pts_test_arguments . ' 2>&1';
             pts_client::test_profile_debug_message('Test Run Command: ' . $test_run_command);
             $is_monitoring = pts_test_result_parser::system_monitor_task_check($test_run_request->test_profile);
             $test_run_time_start = time();
             if (phodevi::is_windows() || pts_client::read_env('USE_PHOROSCRIPT_INTERPRETER') != false) {
                 $phoroscript = new pts_phoroscript_interpreter($to_execute . '/' . $execute_binary, $test_extra_runtime_variables, $to_execute);
                 $phoroscript->execute_script($pts_test_arguments);
                 $test_result = null;
             } else {
                 //$test_result = pts_client::shell_exec($test_run_command, $test_extra_runtime_variables);
                 $descriptorspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
                 $test_process = proc_open('exec ' . $execute_binary_prepend . './' . $execute_binary . ' ' . $pts_test_arguments . ' 2>&1', $descriptorspec, $pipes, $to_execute, array_merge($_ENV, pts_client::environmental_variables(), $test_extra_runtime_variables));
                 if (is_resource($test_process)) {
                     //echo proc_get_status($test_process)['pid'];
                     pts_module_manager::module_process('__test_running', $test_process);
                     $test_result = stream_get_contents($pipes[1]);
                     fclose($pipes[1]);
                     fclose($pipes[2]);
                     $return_value = proc_close($test_process);
                 }
             }
             $test_run_time = time() - $test_run_time_start;
             $monitor_result = $is_monitoring ? pts_test_result_parser::system_monitor_task_post_test($test_run_request->test_profile) : 0;
         }
         if (!isset($test_result[10240]) || pts_client::is_debug_mode() || $full_output) {
             pts_client::$display->test_run_instance_output($test_result);
         }
         if (is_file($test_log_file) && trim($test_result) == null && (filesize($test_log_file) < 10240 || pts_client::is_debug_mode() || $full_output)) {
             $test_log_file_contents = file_get_contents($test_log_file);
             pts_client::$display->test_run_instance_output($test_log_file_contents);
             unset($test_log_file_contents);
         }
         $test_run_request->test_result_standard_output = $test_result;
         $exit_status_pass = true;
         if (is_file($test_directory . 'test-exit-status')) {
             // If the test script writes its exit status to ~/test-exit-status, if it's non-zero the test run failed
             $exit_status = pts_file_io::file_get_contents($test_directory . 'test-exit-status');
             unlink($test_directory . 'test-exit-status');
             if ($exit_status != 0) {
                 self::test_run_instance_error($test_run_manager, $test_run_request, 'The test exited with a non-zero exit status.');
                 if ($is_expected_last_run && is_file($test_log_file)) {
                     $scan_log = pts_file_io::file_get_contents($test_log_file);
                     $test_run_error = pts_tests::scan_for_error($scan_log, $test_run_request->test_profile->get_test_executable_dir());
                     if ($test_run_error) {
                         self::test_run_instance_error($test_run_manager, $test_run_request, 'E: ' . $test_run_error);
                     }
                 }
                 $exit_status_pass = false;
             }
         }
         if (!in_array($i + 1, $ignore_runs) && $exit_status_pass) {
             if (isset($monitor_result) && $monitor_result != 0) {
                 $test_run_request->active->active_result = $monitor_result;
             } else {
                 pts_test_result_parser::parse_result($test_run_request, $test_extra_runtime_variables['LOG_FILE']);
             }
             pts_client::test_profile_debug_message('Test Result Value: ' . $test_run_request->active->active_result);
             if (!empty($test_run_request->active->active_result)) {
                 if ($test_run_time < 2 && intval($test_run_request->active->active_result) == $test_run_request->active->active_result && $test_run_request->test_profile->get_estimated_run_time() > 60 && !$restored_from_cache) {
                     // If the test ended in less than two seconds, outputted some int, and normally the test takes much longer, then it's likely some invalid run
                     self::test_run_instance_error($test_run_manager, $test_run_request, 'The test run ended prematurely.');
                     if ($is_expected_last_run && is_file($test_log_file)) {
                         $scan_log = pts_file_io::file_get_contents($test_log_file);
                         $test_run_error = pts_tests::scan_for_error($scan_log, $test_run_request->test_profile->get_test_executable_dir());
                         if ($test_run_error) {
                             self::test_run_instance_error($test_run_manager, $test_run_request, 'E: ' . $test_run_error);
                         }
                     }
                 } else {
                     // TODO integrate active_result into active buffer
                     $active_result_buffer->add_trial_run_result($test_run_request->active->active_result, $test_run_request->active->active_min_result, $test_run_request->active->active_max_result);
                 }
             } else {
                 if ($test_run_request->test_profile->get_display_format() != 'NO_RESULT') {
                     self::test_run_instance_error($test_run_manager, $test_run_request, 'The test run did not produce a result.');
                     if ($is_expected_last_run && is_file($test_log_file)) {
                         $scan_log = pts_file_io::file_get_contents($test_log_file);
                         $test_run_error = pts_tests::scan_for_error($scan_log, $test_run_request->test_profile->get_test_executable_dir());
                         if ($test_run_error) {
                             self::test_run_instance_error($test_run_manager, $test_run_request, 'E: ' . $test_run_error);
                         }
                     }
                 }
             }
             if ($allow_cache_share && !is_file($cache_share_pt2so)) {
                 $cache_share->add_object('test_results_output_' . $i, $test_run_request->active->active_result);
                 $cache_share->add_object('log_file_location_' . $i, $test_extra_runtime_variables['LOG_FILE']);
                 $cache_share->add_object('log_file_' . $i, is_file($test_log_file) ? file_get_contents($test_log_file) : null);
             }
         }
         if ($is_expected_last_run && $active_result_buffer->get_trial_run_count() > floor(($i - 2) / 2) && !$cache_share_present && $test_run_manager->do_dynamic_run_count()) {
             // The later check above ensures if the test is failing often the run count won't uselessly be increasing
             // Should we increase the run count?
             $increase_run_count = false;
             if ($defined_times_to_run == $i + 1 && $active_result_buffer->get_trial_run_count() > 0 && $active_result_buffer->get_trial_run_count() < $defined_times_to_run && $i < 64) {
                 // At least one run passed, but at least one run failed to produce a result. Increase count to try to get more successful runs
                 $increase_run_count = $defined_times_to_run - $active_result_buffer->get_trial_run_count();
             } else {
                 if ($active_result_buffer->get_trial_run_count() >= 2) {
                     // Dynamically increase run count if needed for statistical significance or other reasons
                     $increase_run_count = $test_run_manager->increase_run_count_check($active_result_buffer, $defined_times_to_run, $test_run_time);
                     if ($increase_run_count === -1) {
                         $abort_testing = true;
                     } else {
                         if ($increase_run_count == true) {
                             // Just increase the run count one at a time
                             $increase_run_count = 1;
                         }
                     }
                 }
             }
             if ($increase_run_count > 0) {
                 $times_to_run += $increase_run_count;
                 $is_expected_last_run = false;
                 //$test_run_request->test_profile->set_times_to_run($times_to_run);
             }
         }
         if ($times_to_run > 1 && $i < $times_to_run - 1) {
             if ($cache_share_present == false) {
                 $interim_output = pts_tests::call_test_script($test_run_request->test_profile, 'interim', 'Running Interim Test Script', $pts_test_arguments, $extra_runtime_variables, true);
                 if ($interim_output != null && (pts_client::is_debug_mode() || $full_output)) {
                     pts_client::$display->test_run_instance_output($interim_output);
                 }
                 //sleep(2); // Rest for a moment between tests
             }
             pts_module_manager::module_process('__interim_test_run', $test_run_request);
         }
         if (is_file($test_log_file)) {
             if ($is_expected_last_run) {
                 // For now just passing the last test log file...
                 // TODO XXX: clean this up with log files to preserve when needed, let multiple log files exist for extra_data, etc
                 pts_test_result_parser::generate_extra_data($test_run_request, $test_log_file);
             }
             if ($backup_test_log_dir) {
                 copy($test_log_file, $backup_test_log_dir . basename($test_log_file));
             }
             if (pts_client::test_profile_debug_message('Log File At: ' . $test_log_file) == false) {
                 unlink($test_log_file);
             }
         }
         if (is_file(PTS_USER_PATH . 'halt-testing') || is_file(PTS_USER_PATH . 'skip-test')) {
             pts_client::release_lock($lock_file);
             return false;
         }
         pts_client::$display->test_run_instance_complete($test_run_request);
     }
     $time_test_end_actual = time();
     if ($cache_share_present == false) {
         $post_output = pts_tests::call_test_script($test_run_request->test_profile, 'post', 'Running Post-Test Script', $pts_test_arguments, $extra_runtime_variables, true);
         if ($post_output != null && (pts_client::is_debug_mode() || $full_output)) {
             pts_client::$display->test_run_instance_output($post_output);
         }
         if (is_file($test_directory . 'post-test-exit-status')) {
             // If the post script writes its exit status to ~/post-test-exit-status, if it's non-zero the test run failed
             $exit_status = pts_file_io::file_get_contents($test_directory . 'post-test-exit-status');
             unlink($test_directory . 'post-test-exit-status');
             if ($exit_status != 0) {
                 self::test_run_instance_error($test_run_manager, $test_run_request, 'The post run script exited with a non-zero exit status.' . PHP_EOL);
                 $abort_testing = true;
             }
         }
     }
     if ($abort_testing) {
         self::test_run_error($test_run_manager, $test_run_request, 'This test execution has been abandoned.');
         return false;
     }
     // End
     $time_test_end = time();
     $time_test_elapsed = $time_test_end - $time_test_start;
     $time_test_elapsed_actual = $time_test_end_actual - $time_test_start_actual;
     if (!empty($min_length)) {
         if ($min_length > $time_test_elapsed_actual) {
             // The test ended too quickly, results are not valid
             self::test_run_error($test_run_manager, $test_run_request, 'This test ended prematurely.');
             return false;
         }
     }
     if (!empty($max_length)) {
         if ($max_length < $time_test_elapsed_actual) {
             // The test took too much time, results are not valid
             self::test_run_error($test_run_manager, $test_run_request, 'This test run was exhausted.');
             return false;
         }
     }
     if ($allow_cache_share && !is_file($cache_share_pt2so) && $cache_share instanceof pts_storage_object) {
         $cache_share->save_to_file($cache_share_pt2so);
         unset($cache_share);
     }
     if ($test_run_manager->get_results_identifier() != null && pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/SaveInstallationLogs', 'FALSE')) {
         if (is_file($test_run_request->test_profile->get_install_dir() . 'install.log')) {
             $backup_log_dir = PTS_SAVE_RESULTS_PATH . $test_run_manager->get_file_name() . '/installation-logs/' . $test_run_manager->get_results_identifier() . '/';
             pts_file_io::mkdir($backup_log_dir, 0777, true);
             copy($test_run_request->test_profile->get_install_dir() . 'install.log', $backup_log_dir . basename($test_identifier) . '.log');
         }
     }
     // Fill in missing test details
     if (empty($arguments_description)) {
         $arguments_description = $test_run_request->test_profile->get_test_subtitle();
     }
     $file_var_checks = array(array('pts-results-scale', 'set_result_scale', null), array('pts-results-proportion', 'set_result_proportion', null), array('pts-results-quantifier', 'set_result_quantifier', null), array('pts-test-version', 'set_version', null), array('pts-test-description', null, 'set_used_arguments_description'), array('pts-footnote', null, null));
     foreach ($file_var_checks as &$file_check) {
         list($file, $set_function, $result_set_function) = $file_check;
         if (is_file($test_directory . $file)) {
             $file_contents = pts_file_io::file_get_contents($test_directory . $file);
             unlink($test_directory . $file);
             if (!empty($file_contents)) {
                 if ($set_function != null) {
                     call_user_func(array($test_run_request->test_profile, $set_function), $file_contents);
                 } else {
                     if ($result_set_function != null) {
                         if ($result_set_function == 'set_used_arguments_description') {
                             $arguments_description = $file_contents;
                         } else {
                             call_user_func(array($test_run_request, $result_set_function), $file_contents);
                         }
                     } else {
                         if ($file == 'pts-footnote') {
                             $test_run_request->test_profile->test_installation->set_install_footnote($file_contents);
                         }
                     }
                 }
             }
         }
     }
     if (empty($arguments_description)) {
         $arguments_description = 'Phoronix Test Suite v' . PTS_VERSION;
     }
     foreach (pts_client::environmental_variables() as $key => $value) {
         $arguments_description = str_replace('$' . $key, $value, $arguments_description);
         if (!in_array($key, array('VIDEO_MEMORY', 'NUM_CPU_CORES', 'NUM_CPU_JOBS'))) {
             $extra_arguments = str_replace('$' . $key, $value, $extra_arguments);
         }
     }
     // Any device notes to add to PTS test notes area?
     foreach (phodevi::read_device_notes($test_type) as $note) {
         pts_test_notes_manager::add_note($note);
     }
     // As of PTS 4.4, this is removed and superceded effectively by reporting the notes to table
     // Any special information (such as forced AA/AF levels for graphics) to add to the description string of the result?
     /*
     if(($special_string = phodevi::read_special_settings_string($test_type)) != null)
     {
     	if(strpos($arguments_description, $special_string) === false)
     	{
     		if($arguments_description != null)
     		{
     			$arguments_description .= ' | ';
     		}
     
     		$arguments_description .= $special_string;
     	}
     }
     */
     // Result Calculation
     $test_run_request->set_used_arguments_description($arguments_description);
     $test_run_request->set_used_arguments($extra_arguments);
     pts_test_result_parser::calculate_end_result($test_run_request, $active_result_buffer);
     // Process results
     pts_client::$display->test_run_end($test_run_request);
     pts_client::$display->display_interrupt_message($test_run_request->test_profile->get_post_run_message());
     pts_module_manager::module_process('__post_test_run', $test_run_request);
     $report_elapsed_time = $cache_share_present == false && $test_run_request->active->get_result() != 0;
     pts_tests::update_test_install_xml($test_run_request->test_profile, $report_elapsed_time ? $time_test_elapsed : 0);
     pts_storage_object::add_in_file(PTS_CORE_STORAGE, 'total_testing_time', $time_test_elapsed / 60);
     if ($report_elapsed_time && pts_client::do_anonymous_usage_reporting() && $time_test_elapsed >= 60) {
         // If anonymous usage reporting enabled, report test run-time to OpenBenchmarking.org
         pts_openbenchmarking_client::upload_usage_data('test_complete', array($test_run_request, $time_test_elapsed));
     }
     // Remove lock
     pts_client::release_lock($lock_file);
     return $active_result_buffer;
 }
 public static function call_test_script($test_profile, $script_name, $print_string = null, $pass_argument = null, $extra_vars_append = null, $use_ctp = true)
 {
     $extra_vars = pts_tests::extra_environmental_variables($test_profile);
     if (isset($extra_vars_append['PATH'])) {
         // Special case variable where you likely want the two merged rather than overwriting
         $extra_vars['PATH'] = $extra_vars_append['PATH'] . (substr($extra_vars_append['PATH'], -1) != ':' ? ':' : null) . $extra_vars['PATH'];
         unset($extra_vars_append['PATH']);
     }
     if (is_array($extra_vars_append)) {
         $extra_vars = array_merge($extra_vars, $extra_vars_append);
     }
     // TODO: call_test_script could be better cleaned up to fit more closely with new pts_test_profile functions
     $result = null;
     $test_directory = $test_profile->get_install_dir();
     pts_file_io::mkdir($test_directory, 0777, true);
     $os_postfix = '_' . strtolower(phodevi::operating_system());
     $test_profiles = array($test_profile);
     if ($use_ctp) {
         $test_profiles = array_merge($test_profiles, $test_profile->extended_test_profiles());
     }
     if (pts_client::executable_in_path('bash')) {
         $sh = 'bash';
     } else {
         $sh = 'sh';
     }
     foreach ($test_profiles as &$this_test_profile) {
         $test_resources_location = $this_test_profile->get_resource_dir();
         if (is_file($run_file = $test_resources_location . $script_name . $os_postfix . '.sh') || is_file($run_file = $test_resources_location . $script_name . '.sh')) {
             if (!empty($print_string)) {
                 pts_client::$display->test_run_message($print_string);
             }
             if (phodevi::is_windows() || pts_client::read_env('USE_PHOROSCRIPT_INTERPRETER') != false) {
                 $phoroscript = new pts_phoroscript_interpreter($run_file, $extra_vars, $test_directory);
                 $phoroscript->execute_script($pass_argument);
                 $this_result = null;
             } else {
                 $this_result = pts_client::shell_exec('cd ' . $test_directory . ' && ' . $sh . ' ' . $run_file . ' "' . $pass_argument . '" 2>&1', $extra_vars);
             }
             if (trim($this_result) != null) {
                 $result = $this_result;
             }
         }
     }
     return $result;
 }
 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 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;
 }
示例#10
0
 private static function select_drive_mount()
 {
     $drives = pts_file_io::glob('/dev/sd*');
     if (count($drives) == 0) {
         echo PHP_EOL . 'No Disk Drives Found' . PHP_EOL . PHP_EOL;
     } else {
         array_push($drives, 'No HDD');
         $to_mount = pts_user_io::prompt_text_menu('Select Drive / Partition To Mount', $drives);
         if ($to_mount != 'No HDD') {
             echo PHP_EOL . 'Attempting to mount: ' . $to_mount . PHP_EOL;
             exec('umount /media/pts-auto-mount 2>&1');
             pts_file_io::delete('/media/pts-auto-mount', null, true);
             pts_file_io::mkdir('/media/pts-auto-mount');
             echo exec('mount ' . $to_mount . ' /media/pts-auto-mount');
             putenv('PTS_TEST_INSTALL_ROOT_PATH=/media/pts-auto-mount/');
         } else {
             if (is_dir('/media/pts-auto-mount')) {
                 exec('umount /media/pts-auto-mount');
                 @rmdir('/media/pts-auto-mount');
             }
             putenv('PTS_TEST_INSTALL_ROOT_PATH=');
         }
     }
 }
示例#11
0
    public static function run_matisk($args)
    {
        echo PHP_EOL . 'MATISK For The Phoronix Test Suite' . PHP_EOL;
        if (!isset($args[0]) || !is_file($args[0])) {
            echo PHP_EOL . 'You must specify a MATISK INI file to load.' . PHP_EOL . PHP_EOL;
            return false;
        }
        self::$matisk_config_dir = dirname($args[0]) . '/';
        pts_file_io::mkdir(pts_module::save_dir());
        $ini = parse_ini_file($args[0], true);
        foreach (self::$ini_struct as $section => $items) {
            foreach ($items as $key => $r) {
                if (is_array($r) && !isset($ini[$section][$key])) {
                    $ini[$section][$key] = $r[0];
                }
            }
        }
        // Checks
        if (pts_test_suite::is_suite($ini['workload']['suite']) == false) {
            // See if the XML suite-definition was just tossed into the same directory
            if (($xml_file = self::find_file($ini['workload']['suite'] . '.xml')) !== false) {
                pts_file_io::mkdir(PTS_TEST_SUITE_PATH . 'local/' . $ini['workload']['suite']);
                copy($xml_file, PTS_TEST_SUITE_PATH . 'local/' . $ini['workload']['suite'] . '/suite-definition.xml');
            }
            if (pts_test_suite::is_suite($ini['workload']['suite']) == false) {
                echo PHP_EOL . 'A test suite must be specified to execute. If a suite needs to be constructed, run: ' . PHP_EOL . 'phoronix-test-suite build-suite' . PHP_EOL . PHP_EOL;
                return false;
            }
        }
        if ($ini['set_context']['external_contexts'] != null) {
            switch ($ini['set_context']['external_contexts_delimiter']) {
                case 'EOL':
                case '':
                    $ini['set_context']['external_contexts_delimiter'] = PHP_EOL;
                    break;
                case 'TAB':
                    $ini['set_context']['external_contexts_delimiter'] = "\t";
                    break;
            }
            if ($ff = self::find_file($ini['set_context']['external_contexts'])) {
                if (is_executable($ff)) {
                    $ini['set_context']['context'] = shell_exec($ff . ' 2> /dev/null');
                } else {
                    $ini['set_context']['context'] = file_get_contents($ff);
                }
            } else {
                // Hopefully it's a command to execute then...
                $ini['set_context']['context'] = shell_exec($ini['set_context']['external_contexts'] . ' 2> /dev/null');
            }
            $ini['set_context']['context'] = explode($ini['set_context']['external_contexts_delimiter'], $ini['set_context']['context']);
        } else {
            if ($ini['set_context']['context'] != null && !is_array($ini['set_context']['context'])) {
                $ini['set_context']['context'] = array($ini['set_context']['context']);
            }
        }
        if (is_array($ini['set_context']['context']) && count($ini['set_context']['context']) > 0) {
            foreach ($ini['set_context']['context'] as $i => $context) {
                if ($context == null) {
                    unset($ini['set_context']['context'][$i]);
                }
            }
            // Context testing
            if (count($ini['set_context']['context']) > 0 && $ini['set_context']['pre_run'] == null && $ini['set_context']['pre_install'] == null) {
                echo PHP_EOL . 'The pre_run or pre_install set_context fields must be set in order to set the system\'s context.' . PHP_EOL;
                return false;
            }
            if ($ini['set_context']['reverse_context_order']) {
                $ini['set_context']['context'] = array_reverse($ini['set_context']['context']);
            }
        }
        if (pts_strings::string_bool($ini['workload']['save_results'])) {
            if ($ini['workload']['save_name'] == null) {
                echo PHP_EOL . 'The save_name field cannot be left empty when saving the test results.' . PHP_EOL;
                return false;
            }
            /*
            if($ini['workload']['result_identifier'] == null)
            {
            	echo PHP_EOL . 'The result_identifier field cannot be left empty when saving the test results.' . PHP_EOL;
            	return false;
            }
            */
        }
        if (!empty($ini['environmental_variables']) && is_array($ini['environmental_variables'])) {
            foreach ($ini['environmental_variables'] as $key => $value) {
                putenv(trim($key) . '=' . trim($value));
            }
        }
        if (empty($ini['set_context']['context'])) {
            $ini['set_context']['context'] = array($ini['workload']['result_identifier']);
        }
        if (pts_strings::string_bool($ini['set_context']['log_context_outputs'])) {
            pts_file_io::mkdir(pts_module::save_dir() . $ini['workload']['save_name']);
        }
        $spent_context_file = pts_module::save_dir() . $ini['workload']['save_name'] . '.spent-contexts';
        if (!is_file($spent_context_file)) {
            touch($spent_context_file);
        } else {
            // If recovering from an existing run, don't rerun contexts that were already executed
            $spent_contexts = pts_file_io::file_get_contents($spent_context_file);
            $spent_contexts = explode(PHP_EOL, $spent_contexts);
            foreach ($spent_contexts as $sc) {
                if (($key = array_search($sc, $ini['set_context']['context'])) !== false) {
                    unset($ini['set_context']['context'][$key]);
                }
            }
        }
        if ($ini['set_context']['reboot_support'] && phodevi::is_linux()) {
            // In case a set-context involves a reboot, auto-recover
            $xdg_config_home = is_dir('/etc/xdg/autostart') && is_writable('/etc/xdg/autostart') ? '/etc/xdg/autostart' : pts_client::read_env('XDG_CONFIG_HOME');
            if ($xdg_config_home == false) {
                $xdg_config_home = pts_client::user_home_directory() . '.config';
            }
            if ($xdg_config_home != false && is_dir($xdg_config_home)) {
                $autostart_dir = $xdg_config_home . '/autostart/';
                pts_file_io::mkdir($xdg_config_home . '/autostart/');
            }
            file_put_contents($xdg_config_home . '/autostart/phoronix-test-suite-matisk.desktop', '
[Desktop Entry]
Name=Phoronix Test Suite Matisk Recovery
GenericName=Phoronix Test Suite
Comment=Matisk Auto-Recovery Support
Exec=gnome-terminal -e \'phoronix-test-suite matisk ' . $args[0] . '\'
Icon=phoronix-test-suite
Type=Application
Encoding=UTF-8
Categories=System;Monitor;');
        }
        if ($ini['installation']['block_phodevi_caching']) {
            // Block Phodevi caching if changing out system components and there is a chance one of the strings of changed contexts might be cached (e.g. OpenGL user-space driver)
            phodevi::$allow_phodevi_caching = false;
        }
        if (phodevi::system_uptime() < 60) {
            echo PHP_EOL . 'Sleeping 45 seconds while waiting for the system to settle...' . PHP_EOL;
            sleep(45);
        }
        self::$ini = $ini;
        $total_context_count = count(self::$ini['set_context']['context']);
        while (($context = array_shift(self::$ini['set_context']['context'])) !== null) {
            echo PHP_EOL . ($total_context_count - count(self::$ini['set_context']['context'])) . ' of ' . $total_context_count . ' in test execution queue [' . $context . ']' . PHP_EOL . PHP_EOL;
            self::$context = $context;
            if (pts_strings::string_bool(self::$ini['installation']['install_check']) || $ini['set_context']['pre_install'] != null) {
                self::process_user_config_external_hook_process('pre_install');
                $force_install = false;
                $no_prompts = true;
                if (pts_strings::string_bool(self::$ini['installation']['force_install'])) {
                    $force_install = true;
                }
                if (self::$ini['installation']['external_download_cache'] != null) {
                    pts_test_install_manager::add_external_download_cache(self::$ini['installation']['external_download_cache']);
                }
                // Do the actual test installation
                pts_test_installer::standard_install(self::$ini['workload']['suite'], $force_install, $no_prompts);
                self::process_user_config_external_hook_process('post_install');
            }
            $batch_mode = false;
            $auto_mode = true;
            $test_run_manager = new pts_test_run_manager($batch_mode, $auto_mode);
            if ($test_run_manager->initial_checks(self::$ini['workload']['suite']) == false) {
                return false;
            }
            if (self::$skip_test_set == false) {
                self::process_user_config_external_hook_process('pre_run');
                // Load the tests to run
                if ($test_run_manager->load_tests_to_run(self::$ini['workload']['suite']) == false) {
                    return false;
                }
                // Save results?
                $result_identifier = $ini['workload']['result_identifier'];
                if ($result_identifier == null) {
                    $result_identifier = '$MATISK_CONTEXT';
                }
                // Allow $MATIISK_CONTEXT as a valid user variable to pass it...
                $result_identifier = str_replace('$MATISK_CONTEXT', self::$context, $result_identifier);
                $test_run_manager->set_save_name(self::$ini['workload']['save_name']);
                $test_run_manager->set_results_identifier($result_identifier);
                $test_run_manager->set_description(self::$ini['workload']['description']);
                // Don't upload results unless it's the last in queue where the context count is now 0
                $test_run_manager->auto_upload_to_openbenchmarking(count(self::$ini['set_context']['context']) == 0 && self::$ini['general']['upload_to_openbenchmarking']);
                // Run the actual tests
                $test_run_manager->pre_execution_process();
                $test_run_manager->call_test_runs();
                $test_run_manager->post_execution_process();
            }
            self::$skip_test_set = false;
            file_put_contents($spent_context_file, self::$context . PHP_EOL, FILE_APPEND);
            pts_file_io::unlink(pts_module::save_dir() . self::$context . '.last-call');
            self::process_user_config_external_hook_process('post_run');
        }
        unlink($spent_context_file);
        isset($xdg_config_home) && pts_file_io::unlink($xdg_config_home . '/autostart/phoronix-test-suite-matisk.desktop');
    }
$stmt->bindValue(':benchmark_ticket_id', $BENCHMARK_TICKET_ID);
$stmt->bindValue(':trigger', $TRIGGER_STRING);
$stmt->bindValue(':upload_time', $upload_time);
$stmt->bindValue(':title', sqlite_escape_string($result_file->get_title()));
$stmt->bindValue(':description', sqlite_escape_string($result_file->get_description()));
$stmt->bindValue(':system_count', $result_file->get_system_count());
$stmt->bindValue(':result_count', $result_file->get_test_count());
$stmt->bindValue(':display_status', 1);
$stmt->bindValue(':xml_upload_hash', $xml_upload_hash);
$stmt->bindValue(':comparison_hash', $result_file->get_contained_tests_hash(false));
$stmt->bindValue(':elapsed_time', empty($ELAPSED_TIME) || !is_numeric($ELAPSED_TIME) || $ELAPSED_TIME < 0 ? 0 : $ELAPSED_TIME);
$stmt->bindValue(':pprid', phoromatic_server::compute_pprid(ACCOUNT_ID, SYSTEM_ID, $upload_time, $xml_upload_hash));
$result = $stmt->execute();
//echo phoromatic_server::$db->lastErrorMsg();
$result_directory = phoromatic_server::phoromatic_account_result_path(ACCOUNT_ID, $upload_id);
pts_file_io::mkdir($result_directory);
//phoromatic_add_activity_stream_event('result', $upload_id, 'uploaded');
file_put_contents($result_directory . 'composite.xml', $composite_xml);
if ($SYSTEM_LOGS_ZIP != null && $SYSTEM_LOGS_HASH != null) {
    if (sha1($SYSTEM_LOGS_ZIP) == $SYSTEM_LOGS_HASH) {
        $system_logs_zip = $result_directory . 'system-logs.zip';
        file_put_contents($system_logs_zip, base64_decode($_POST['system_logs_zip']));
        /*if(filesize($system_logs_zip) > 2097152)
        		{
        			unlink($system_logs_zip);
        		}*/
    }
    unset($SYSTEM_LOGS_ZIP);
}
$relative_id = 0;
foreach ($result_file->get_result_objects() as $result_object) {
示例#13
0
 private static function set_user_context($context_script, $trigger, $schedule_id, $process)
 {
     if (!empty($context_script)) {
         $context_file = pts_client::create_temporary_file();
         file_put_contents($context_file, $context_script);
         chmod($context_file, 0755);
         pts_file_io::mkdir(pts_module::save_dir());
         $storage_path = pts_module::save_dir() . 'memory.pt2so';
         $storage_object = pts_storage_object::recover_from_file($storage_path);
         $notes_log_file = pts_module::save_dir() . sha1($trigger . $schedule_id . $process);
         // We check to see if the context was already set but the system rebooted or something in that script
         if ($storage_object == false) {
             $storage_object = new pts_storage_object(true, true);
         } else {
             if ($storage_object->read_object('last_set_context_trigger') == $trigger && $storage_object->read_object('last_set_context_schedule') == $schedule_id && $storage_object->read_object('last_set_context_process') == $process) {
                 // If the script already ran once for this trigger, don't run it again
                 self::check_user_context_log($trigger, $schedule_id, $process, $notes_log_file, null);
                 return false;
             }
         }
         $storage_object->add_object('last_set_context_trigger', $trigger);
         $storage_object->add_object('last_set_context_schedule', $schedule_id);
         $storage_object->add_object('last_set_context_process', $process);
         $storage_object->save_to_file($storage_path);
         phoromatic::update_system_status('Setting context for: ' . $schedule_id . ' - ' . $trigger . ' - ' . $process);
         // Run the set context script
         $env_vars['PHOROMATIC_TRIGGER'] = $trigger;
         $env_vars['PHOROMATIC_SCHEDULE_ID'] = $schedule_id;
         $env_vars['PHOROMATIC_SCHEDULE_PROCESS'] = $process;
         $env_vars['PHOROMATIC_LOG_FILE'] = $notes_log_file;
         $log_output = pts_client::shell_exec('./' . $context_script . ' ' . $trigger . ' 2>&1', $env_vars);
         self::check_user_context_log($trigger, $schedule_id, $process, $notes_log_file, $log_output);
         // Just simply return true for now, perhaps check exit code status and do something
         return true;
     }
     return false;
 }
    public static function render_page_process($PATH)
    {
        $account_creation_string = phoromatic_server::read_setting('account_creation_alt');
        $account_creation_enabled = $account_creation_string == null;
        if ($account_creation_enabled && isset($_POST['register_username']) && isset($_POST['register_password']) && isset($_POST['register_password_confirm']) && isset($_POST['register_email'])) {
            $new_account = create_new_phoromatic_account($_POST['register_username'], $_POST['register_password'], $_POST['register_password_confirm'], $_POST['register_email'], isset($_POST['seed_accountid']) ? $_POST['seed_accountid'] : null);
            if ($new_account) {
                echo phoromatic_webui_header(array('Account Created'), '');
                $box = '<h1>Account Created</h1>
				<p>Your account has been created. You may now log-in to begin utilizing the Phoronix Test Suite\'s Phoromatic.</p>
				<form name="login_form" id="login_form" action="?login" method="post" onsubmit="return phoromatic_login(this);">
				<p><div style="width: 200px; font-weight: bold; float: left;">User:</div> <input type="text" name="username" /></p>
				<p><div style="width: 200px; font-weight: bold; float: left;">Password:</div> <input type="password" name="password" /></p>
				<p><div style="width: 200px; font-weight: bold; float: left;">&nbsp;</div> <input type="submit" value="Submit" /></p>
				</form>';
                echo phoromatic_webui_box($box);
                echo phoromatic_webui_footer();
            }
        } else {
            if (isset($_POST['username']) && isset($_POST['password']) && strtolower($_POST['username']) == 'rootadmin') {
                $admin_pw = phoromatic_server::read_setting('root_admin_pw');
                if (empty($admin_pw)) {
                    echo phoromatic_webui_header(array('Action Required'), '');
                    $box = '<h1>Root Admin Password Not Set</h1>
				<p>The root admin password has not yet been set for this system. It can be set by running on the system: <strong>phoronix-test-suite phoromatic.set-root-admin-password</strong>.</p>';
                    echo phoromatic_webui_box($box);
                    echo phoromatic_webui_footer();
                    return false;
                } else {
                    if (hash('sha256', 'PTS' . $_POST['password']) != $admin_pw) {
                        echo phoromatic_webui_header(array('Invalid Password'), '');
                        $box = '<h1>Root Admin Password Incorrect</h1>
				<p>The root admin password is incorrect.</p>';
                        echo phoromatic_webui_box($box);
                        echo phoromatic_webui_footer();
                        return false;
                    } else {
                        session_regenerate_id();
                        $_SESSION['UserID'] = 0;
                        $_SESSION['UserName'] = '******';
                        $_SESSION['AccountID'] = 0;
                        $_SESSION['AdminLevel'] = -40;
                        $_SESSION['CreatedOn'] = null;
                        $_SESSION['CoreVersionOnSignOn'] = PTS_CORE_VERSION;
                        session_write_close();
                        header('Location: /?admin');
                    }
                }
            } else {
                if (isset($_POST['username']) && isset($_POST['password'])) {
                    $matching_user = phoromatic_server::$db->querySingle('SELECT UserName, Password, AccountID, UserID, AdminLevel, CreatedOn FROM phoromatic_users WHERE UserName = \'' . SQLite3::escapeString($_POST['username']) . '\'', true);
                    if (!empty($matching_user)) {
                        $user_id = $matching_user['UserID'];
                        $created_on = $matching_user['CreatedOn'];
                        $user = $matching_user['UserName'];
                        $hashed_password = $matching_user['Password'];
                        $account_id = $matching_user['AccountID'];
                        $admin_level = $matching_user['AdminLevel'];
                        if ($admin_level < 1) {
                            pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' attempted to log-in to a disabled account: ' . $_POST['username']);
                            phoromatic_error_page('Disabled Account', 'The log-in is not possible as this account has been disabled.');
                            return false;
                        }
                        if ($user == $_POST['username']) {
                            $account_salt = phoromatic_server::$db->querySingle('SELECT Salt FROM phoromatic_accounts WHERE AccountID = \'' . $account_id . '\'');
                        } else {
                            $account_salt = null;
                        }
                        if ($account_salt != null && hash('sha256', $account_salt . $_POST['password']) == $hashed_password) {
                            session_regenerate_id();
                            $_SESSION['UserID'] = $user_id;
                            $_SESSION['UserName'] = $user;
                            $_SESSION['AccountID'] = $account_id;
                            $_SESSION['AdminLevel'] = $admin_level;
                            $_SESSION['CreatedOn'] = $created_on;
                            $_SESSION['CoreVersionOnSignOn'] = PTS_CORE_VERSION;
                            $account_salt = phoromatic_server::$db->exec('UPDATE phoromatic_users SET LastIP = \'' . $_SERVER['REMOTE_ADDR'] . '\', LastLogin = \'' . phoromatic_server::current_time() . '\' WHERE UserName = "******"');
                            session_write_close();
                            pts_file_io::mkdir(phoromatic_server::phoromatic_account_path($account_id));
                            pts_file_io::mkdir(phoromatic_server::phoromatic_account_result_path($account_id));
                            pts_file_io::mkdir(phoromatic_server::phoromatic_account_system_path($account_id));
                            pts_file_io::mkdir(phoromatic_server::phoromatic_account_suite_path($account_id));
                            echo phoromatic_webui_header(array('Welcome, ' . $user), '');
                            $box = '<h1>Log-In Successful</h1>
					<p><strong>' . $user . '</strong>, we are now redirecting you to your account portal. If you are not redirected within a few seconds, please <a href="?main">click here</a>.<script type="text/javascript">window.location.href = "?main";</script></p>';
                            echo phoromatic_webui_box($box);
                            echo phoromatic_webui_footer();
                            pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' successfully logged in as user: '******'REMOTE_ADDR'] . ' failed a log-in attempt as: ' . $_POST['username']);
                            phoromatic_error_page('Invalid Information', 'The user-name or password did not match our records.');
                            return false;
                        }
                    } else {
                        pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' failed a log-in attempt as: ' . $_POST['username']);
                        phoromatic_error_page('Invalid Information', 'The user-name was not found within our system.');
                        return false;
                    }
                } else {
                    echo phoromatic_webui_header(array(), '');
                    $box = '<h1>Welcome</h1>
			<p>You must log-in to your Phoromatic account or create an account to access this service.</p>
			<p>Phoromatic is the remote management and test orchestration system for the Phoronix Test Suite. Phoromatic allows the automatic scheduling of tests, remote installation of new tests, and the management of multiple test systems over a LAN or WAN all through an intuitive, easy-to-use web interface. Tests can be scheduled to automatically run on a routine basis across multiple test systems. The test results are then available from this central, secure location.</p>
			<p>Phoromatic makes it very easy to provide for automated scheduling of tests on multiple systems, is extremely extensible, allows various remote testing possibilities, makes it very trivial to manage multiple systems, and centralizes result management within an organization.</p>
			<p><a href="about.php">Learn more about Phoromatic</a>.</p>
			<hr />
			<h1>Log-In</h1>
			<form name="login_form" id="login_form" action="?login" method="post" onsubmit="return phoromatic_login(this);">
			<p><div style="width: 200px; font-weight: 500; float: left;">User:</div> <input type="text" name="username" /></p>
			<p><div style="width: 200px; font-weight: 500; float: left;">Password:</div> <input type="password" name="password" /></p>
			<p><div style="width: 200px; font-weight: 500; float: left;">&nbsp;</div> <input type="submit" value="Submit" /></p>
			</form>
			<hr />
			<h1>Register</h1>';
                    if (!empty($account_creation_string)) {
                        $box .= '<p>' . $account_creation_string . '</p>';
                    } else {
                        $box .= '
					<p>Creating a new Phoromatic account is free and easy. The public, open-source version of the Phoronix Test Suite client is limited in its Phoromatic server abilities when it comes to result management and local storage outside of the OpenBenchmarking.org cloud. For organizations looking for behind-the-firewall support and other enterprise features, <a href="http://www.phoronix-test-suite.com/?k=commercial">contact us</a>. To create a new account for this Phoromatic server, simply fill out the form below.</p>';
                        $box .= '<form name="register_form" id="register_form" action="?register" method="post" onsubmit="return phoromatic_initial_registration(this);">

					<div style="clear: both; font-weight: 500;">
					<div style="float: left; width: 25%;">Username</div>
					<div style="float: left; width: 25%;">Password</div>
					<div style="float: left; width: 25%;">Confirm Password</div>
					<div style="float: left; width: 25%;">Email Address</div>
					</div>

					<div style="clear: both;">
					<div style="float: left; width: 25%;"><input type="hidden" name="seed_accountid" value="' . (isset($_GET['seed_accountid']) ? $_GET['seed_accountid'] : null) . '" /><input type="text" name="register_username" /> <sup>1</sup></div>
					<div style="float: left; width: 25%;"><input type="password" name="register_password" /> <sup>2</sup></div>
					<div style="float: left; width: 25%;"><input type="password" name="register_password_confirm" /></div>
					<div style="float: left; width: 25%;"><input type="text" name="register_email" /> <sup>3</sup><br /><br /><input type="submit" value="Create Account" /></div>
					</div>

					</form>';
                        $box .= '<p style="font-size: 11px;"><sup>1</sup> Usernames shall be at least four characters long, not contain any spaces, and only be composed of normal ASCII characters.<br />
						<sup>2</sup> Passwords shall be at least six characters long.<br />
						<sup>3</sup> A valid email address is required for notifications, password reset, and other verification purposes.<br />
						</p>';
                    }
                    $box .= '<hr />
			<h1>View Public Results</h1>
			<p>For accounts that opted to share their test results publicly, you can directly <a href="public.php">view the public test results</a>.</p><hr />';
                    echo phoromatic_webui_box($box);
                    echo phoromatic_webui_footer();
                }
            }
        }
    }
示例#15
0
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$J = json_decode($JSON, true);
if ($J == null) {
    $json['phoromatic']['response'] = 'Failed';
    echo json_encode($json);
    exit;
}
pts_file_io::mkdir(phoromatic_server::phoromatic_account_system_path(ACCOUNT_ID));
pts_file_io::mkdir(phoromatic_server::phoromatic_account_system_path(ACCOUNT_ID, SYSTEM_ID));
$system_path = phoromatic_server::phoromatic_account_system_path(ACCOUNT_ID, SYSTEM_ID);
if (isset($J['phoromatic']['client-log'])) {
    file_put_contents($system_path . 'phoronix-test-suite.log', $J['phoromatic']['client-log']);
}
if (isset($J['phoromatic']['stats'])) {
    file_put_contents($system_path . 'sensors.json', json_encode($J['phoromatic']['stats']));
}
if (is_file($system_path . 'sensors-pool.json')) {
    $sensor_file = file_get_contents($system_path . 'sensors-pool.json');
    $sensor_file = json_decode($sensor_file, true);
    if ($sensor_file && !empty($sensor_file)) {
        foreach ($sensor_file as $name => $sensor) {
            if (isset($sensor['last-updated']) < time() - 600) {
                unset($sensor_file['sensors'][$name]);
            }
示例#16
0
 public static function generate_result_file_graphs($test_results_identifier, $save_to_dir = false, $extra_attributes = null)
 {
     if ($save_to_dir) {
         if (pts_file_io::mkdir($save_to_dir . '/result-graphs') == false) {
             // Directory must exist, so remove any old graph files first
             foreach (pts_file_io::glob($save_to_dir . '/result-graphs/*') as $old_file) {
                 unlink($old_file);
             }
         }
     }
     if ($test_results_identifier instanceof pts_result_file) {
         $result_file =& $test_results_identifier;
     } else {
         $result_file = new pts_result_file($test_results_identifier);
     }
     $generated_graphs = array();
     $generated_graph_tables = false;
     // Render overview chart
     if ($save_to_dir) {
         $chart = new pts_ResultFileTable($result_file);
         $chart->renderChart($save_to_dir . '/result-graphs/overview.BILDE_EXTENSION');
         $intent = -1;
         if (($intent = pts_result_file_analyzer::analyze_result_file_intent($result_file, $intent, true)) || $result_file->get_system_count() == 1) {
             $chart = new pts_ResultFileCompactSystemsTable($result_file, $intent);
         } else {
             $chart = new pts_ResultFileSystemsTable($result_file);
         }
         $chart->renderChart($save_to_dir . '/result-graphs/systems.BILDE_EXTENSION');
         unset($chart);
         if ($intent && is_dir($save_to_dir . '/system-logs/')) {
             $chart = new pts_DetailedSystemComponentTable($result_file, $save_to_dir . '/system-logs/', $intent);
             if ($chart) {
                 $chart->renderChart($save_to_dir . '/result-graphs/detailed_component.BILDE_EXTENSION');
             }
         }
     }
     $result_objects = $result_file->get_result_objects();
     $test_titles = array();
     foreach ($result_objects as &$result_object) {
         array_push($test_titles, $result_object->test_profile->get_title());
     }
     $offset = 0;
     foreach ($result_objects as $key => &$result_object) {
         $save_to = $save_to_dir;
         $offset++;
         if ($save_to_dir && is_dir($save_to_dir)) {
             $save_to .= '/result-graphs/' . $offset . '.BILDE_EXTENSION';
             if (PTS_IS_CLIENT) {
                 if ($result_file->is_multi_way_comparison(null, $extra_attributes) || pts_client::read_env('GRAPH_GROUP_SIMILAR')) {
                     $table_keys = array();
                     foreach ($test_titles as $this_title_index => $this_title) {
                         if (isset($test_titles[$key]) && $this_title == $test_titles[$key]) {
                             array_push($table_keys, $this_title_index);
                         }
                     }
                 } else {
                     $table_keys = $key;
                 }
                 $chart = new pts_ResultFileTable($result_file, null, $table_keys);
                 $chart->renderChart($save_to_dir . '/result-graphs/' . $offset . '_table.BILDE_EXTENSION');
                 unset($chart);
                 $generated_graph_tables = true;
             }
         }
         $graph = pts_render::render_graph($result_object, $result_file, $save_to, $extra_attributes);
         array_push($generated_graphs, $graph);
     }
     // Generate mini / overview graphs
     if ($save_to_dir) {
         $graph = new pts_OverviewGraph($result_file);
         if ($graph->doSkipGraph() == false) {
             $graph->renderGraph();
             // Check to see if skip_graph was realized during the rendering process
             if ($graph->doSkipGraph() == false) {
                 $graph->svg_dom->output($save_to_dir . '/result-graphs/visualize.BILDE_EXTENSION');
             }
         }
         unset($graph);
         $graph = new pts_RadarOverviewGraph($result_file);
         if ($graph->doSkipGraph() == false) {
             $graph->renderGraph();
             // Check to see if skip_graph was realized during the rendering process
             if ($graph->doSkipGraph() == false) {
                 $graph->svg_dom->output($save_to_dir . '/result-graphs/radar.BILDE_EXTENSION');
             }
         }
         unset($graph);
     }
     // Save XSL
     if (count($generated_graphs) > 0 && $save_to_dir) {
         file_put_contents($save_to_dir . '/pts-results-viewer.xsl', pts_client::xsl_results_viewer_graph_template($generated_graph_tables));
     }
     return $generated_graphs;
 }
 public function process_test_run_request($run_index)
 {
     $result = false;
     if ($this->result_file && $this->result_file->get_test_count() > 0) {
         $this->result_file->get_xml(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/composite.xml');
     }
     if (is_object($run_index)) {
         $test_run_request = $run_index;
         $run_index = 0;
     } else {
         $test_run_request = $this->get_test_to_run($run_index);
     }
     if ($run_index != 0 && count(pts_file_io::glob($test_run_request->test_profile->get_install_dir() . 'cache-share-*.pt2so')) == 0) {
         // Sleep for six seconds between tests by default
         sleep(6);
     }
     if ($test_run_request == false) {
         return;
     }
     $active_result_buffer = pts_test_execution::run_test($this, $test_run_request);
     if (pts_file_io::unlink(PTS_USER_PATH . 'halt-testing')) {
         // Stop the testing process entirely
         return false;
     } else {
         if (pts_file_io::unlink(PTS_USER_PATH . 'skip-test')) {
             // Just skip the current test and do not save the results, but continue testing
             return true;
         } else {
             if (pts_client::read_env('LIMIT_ELAPSED_TEST_TIME') > 0 && PTS_INIT_TIME + pts_client::read_env('LIMIT_ELAPSED_TEST_TIME') * 60 > time()) {
                 // Allocated amount of time has expired
                 return false;
             }
         }
     }
     $test_successful = false;
     if ($test_run_request->test_profile->get_display_format() == 'NO_RESULT') {
         $test_successful = true;
     } else {
         if ($test_run_request instanceof pts_test_result && $test_run_request->active) {
             $end_result = $test_run_request->active->get_result();
             // removed count($result) > 0 in the move to pts_test_result
             if (count($test_run_request) > 0 && (is_numeric($end_result) && $end_result > 0 || !is_numeric($end_result) && isset($end_result[3]))) {
                 pts_module_manager::module_process('__post_test_run_success', $test_run_request);
                 $test_identifier = $this->get_results_identifier();
                 $test_successful = true;
                 if (!empty($test_identifier)) {
                     $test_run_request->test_result_buffer = new pts_test_result_buffer();
                     $test_run_request->test_result_buffer->add_test_result($this->results_identifier, $test_run_request->active->get_result(), $active_result_buffer->get_values_as_string(), self::process_json_report_attributes($test_run_request), $test_run_request->active->get_min_result(), $test_run_request->active->get_max_result());
                     $this->result_file->add_result($test_run_request);
                     if ($test_run_request->secondary_linked_results != null && is_array($test_run_request->secondary_linked_results)) {
                         foreach ($test_run_request->secondary_linked_results as &$run_request_minor) {
                             if (strpos($run_request_minor->get_arguments_description(), $test_run_request->get_arguments_description()) === false) {
                                 $run_request_minor->set_used_arguments_description($test_run_request->get_arguments_description() . ' - ' . $run_request_minor->get_arguments_description());
                                 $run_request_minor->set_used_arguments($test_run_request->get_arguments() . ' - ' . $run_request_minor->get_arguments_description());
                             }
                             $run_request_minor->test_result_buffer = new pts_test_result_buffer();
                             $run_request_minor->test_result_buffer->add_test_result($this->results_identifier, $run_request_minor->active->get_result(), $run_request_minor->active->get_values_as_string(), self::process_json_report_attributes($test_run_request), $run_request_minor->active->get_min_result(), $run_request_minor->active->get_max_result());
                             $this->result_file->add_result($run_request_minor);
                         }
                     }
                     if ($this->get_results_identifier() != null && $this->get_file_name() != null && pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/SaveTestLogs', 'FALSE')) {
                         static $xml_write_pos = 1;
                         pts_file_io::mkdir(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/test-logs/' . $xml_write_pos . '/');
                         if (is_dir(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/test-logs/active/' . $this->get_results_identifier())) {
                             $test_log_write_dir = PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/test-logs/' . $xml_write_pos . '/' . $this->get_results_identifier() . '/';
                             if (is_dir($test_log_write_dir)) {
                                 pts_file_io::delete($test_log_write_dir, null, true);
                             }
                             rename(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/test-logs/active/' . $this->get_results_identifier() . '/', $test_log_write_dir);
                         }
                         $xml_write_pos++;
                     }
                 }
             }
             pts_file_io::unlink(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/test-logs/active/');
         }
     }
     if ($test_successful == false && $test_run_request->test_profile->get_identifier() != null) {
         array_push($this->failed_tests_to_run, $test_run_request);
         // For now delete the failed test log files, but it may be a good idea to keep them
         pts_file_io::delete(PTS_SAVE_RESULTS_PATH . $this->get_file_name() . '/test-logs/active/' . $this->get_results_identifier() . '/', null, true);
     }
     pts_module_manager::module_process('__post_test_run_process', $this->result_file);
     return true;
 }
 protected static function setup_test_install_directory(&$test_install_request, $remove_old_files = false)
 {
     $identifier = $test_install_request->test_profile->get_identifier();
     pts_file_io::mkdir($test_install_request->test_profile->get_install_dir());
     if ($remove_old_files) {
         // Remove any (old) files that were installed
         $ignore_files = array('pts-install.xml', 'install-failed.log');
         foreach ($test_install_request->get_download_objects() as $download_object) {
             $ignore_files[] = $download_object->get_filename();
         }
         pts_file_io::delete($test_install_request->test_profile->get_install_dir(), $ignore_files);
     }
     pts_file_io::symlink(pts_core::user_home_directory() . '.Xauthority', $test_install_request->test_profile->get_install_dir() . '.Xauthority');
     pts_file_io::symlink(pts_core::user_home_directory() . '.drirc', $test_install_request->test_profile->get_install_dir() . '.drirc');
 }
 public function execute_script($pass_arguments = null)
 {
     if ($this->script_file == null) {
         return false;
     }
     $script_contents = file_get_contents($this->script_file);
     $prev_exit_status = 0;
     $script_pointer = -1;
     do {
         $exit_status = 0;
         if ($prev_exit_status != 0) {
             $exit_status = $prev_exit_status;
             $prev_exit_status = 0;
         }
         $script_contents = substr($script_contents, $script_pointer + 1);
         $line = $script_contents;
         $prev_script_pointer = $script_pointer;
         if (($script_pointer = strpos($line, "\n")) !== false) {
             $line = substr($line, 0, $script_pointer);
         }
         $line_r = $line != null ? pts_strings::trim_explode(' ', $line) : null;
         switch (isset($line_r[0]) ? $line_r[0] : null) {
             case '':
                 break;
             case 'mv':
                 // TODO: implement folder support better
                 $line_r[1] = $this->get_real_path($line_r[1], $pass_arguments);
                 $line_r[2] = $this->get_real_path($line_r[2], $pass_arguments);
                 //pts_file_io::delete($line_r[2], null, true);
                 //copy($line_r[1], $line_r[2] . (is_dir($line_r[2]) ? basename($line_r[1]) : null));
                 //pts_file_io::delete($line_r[1], null, true);
                 rename($line_r[1], $line_r[2] . (is_dir($line_r[2]) ? basename($line_r[1]) : null));
                 break;
             case 'cp':
                 // TODO: implement folder support better
                 $line_r[1] = $this->get_real_path($line_r[1], $pass_arguments);
                 $line_r[2] = $this->get_real_path($line_r[2], $pass_arguments);
                 copy($line_r[1], $line_r[2] . (is_dir($line_r[2]) ? basename($line_r[1]) : null));
                 break;
             case 'cat':
                 // TODO: implement folder support better
                 $line_r[1] = $this->get_real_path($line_r[1], $pass_arguments);
                 $line_r[3] = $this->get_real_path($line_r[3], $pass_arguments);
                 copy($line_r[1], $line_r[3]);
                 break;
             case 'cd':
                 if ($line_r[1] == '..') {
                     if (substr($this->var_current_directory, -1) == '/') {
                         $this->var_current_directory = substr($this->var_current_directory, 0, -1);
                     }
                     $this->var_current_directory = substr($this->var_current_directory, 0, strrpos($this->var_current_directory, '/') + 1);
                 } else {
                     if ($line_r[1] == '~') {
                         $this->var_current_directory = $this->environmental_variables["HOME"];
                     } else {
                         if (substr($line_r[1], 0, 1) == '"') {
                             // On Windows some directories are encased in quotes for spaces in the directory names
                             array_shift($line_r);
                             $this->var_current_directory = implode(' ', $line_r);
                         } else {
                             if (is_readable($line_r[1])) {
                                 $this->var_current_directory = $line_r[1];
                             } else {
                                 if (is_readable($this->get_real_path($line_r[1], $pass_arguments))) {
                                     $this->var_current_directory = $this->get_real_path($line_r[1], $pass_arguments);
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 'touch':
                 if (!is_file($this->var_current_directory . $line_r[1]) && is_writable($this->var_current_directory)) {
                     touch($this->var_current_directory . $line_r[1]);
                 }
                 break;
             case 'mkdir':
                 pts_file_io::mkdir($this->var_current_directory . $line_r[1]);
                 break;
             case 'rm':
                 for ($i = 1; $i < count($line_r); $i++) {
                     if (is_file($this->var_current_directory . $line_r[$i])) {
                         unlink($this->var_current_directory . $line_r[$i]);
                     } else {
                         if (is_dir($this->var_current_directory . $line_r[$i])) {
                             pts_file_io::delete($this->var_current_directory . $line_r[$i], null, true);
                         }
                     }
                 }
                 break;
             case 'chmod':
                 $chmod_file = self::find_file_in_array($line_r);
                 if ($chmod_file) {
                     chmod($chmod_file, 0755);
                 }
                 break;
             case 'unzip':
                 $zip_file = self::find_file_in_array($line_r);
                 pts_compression::zip_archive_extract($zip_file, $this->var_current_directory);
                 break;
             case 'tar':
                 // TODO: implement
                 break;
             case 'echo':
                 if ($line == "echo \$? > ~/install-exit-status") {
                     file_put_contents($this->var_current_directory . "install-exit-status", $exit_status);
                     break;
                 } else {
                     if ($line == "echo \$? > ~/test-exit-status") {
                         file_put_contents($this->var_current_directory . "test-exit-status", $exit_status);
                         break;
                     }
                 }
                 $start_echo = strpos($script_contents, "\"") + 1;
                 $end_echo = $start_echo - 1;
                 do {
                     $end_echo = strpos($script_contents, "\"", $end_echo + 1);
                 } while ($script_contents[$end_echo - 1] == "\\");
                 $script_pointer = strpos($script_contents, "\n", $end_echo);
                 $line_remainder = substr($script_contents, $end_echo + 1, $script_pointer - $end_echo - 1);
                 $echo_contents = substr($script_contents, $start_echo, $end_echo - $start_echo);
                 $this->parse_variables_in_string($echo_contents, $pass_arguments);
                 $echo_contents = str_replace("\\\$", "\$", $echo_contents);
                 $echo_contents = str_replace("\\\"", "\"", $echo_contents);
                 if (($to_file = strpos($line_remainder, ' > ')) !== false) {
                     $to_file = trim(substr($line_remainder, $to_file + 3));
                     if (($end_file = strpos($to_file, ' ')) !== false) {
                         $to_file = substr($to_file, 0, $end_file);
                     }
                     // TODO: right now it's expecting the file location pipe to be relative location
                     $echo_dir = pts_strings::add_trailing_slash(str_replace('"', null, $this->var_current_directory));
                     // needed for phodevi::is_windows() specviewperf10
                     file_put_contents($echo_dir . $to_file, $echo_contents . "\n");
                 } else {
                     echo $echo_contents;
                 }
                 break;
             case '#!/bin/sh':
             case '#':
             case null:
                 // IGNORE
                 break;
             case 'case':
                 //echo "\nUNHANDLED EVENT\n";
                 return false;
                 // TODO: decide how to handle
                 break;
             default:
                 $exec_output = array();
                 if (phodevi::is_windows() && substr($line, 0, 2) == "./") {
                     $line = substr($line, 2);
                 }
                 $this->parse_variables_in_string($line, $pass_arguments);
                 $cd_dir = $this->var_current_directory;
                 if (phodevi::is_windows() && strpos($cd_dir, ':\\') === 1) {
                     $cd_dir = str_replace('/', '\\', $cd_dir);
                     $cd_dir = str_replace('\\\\', '\\', $cd_dir);
                 }
                 exec("cd " . $cd_dir . " && " . $line . " 2>&1", $exec_output, $prev_exit_status);
                 break;
         }
     } while ($script_contents != false);
 }