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; }
private static function core_storage_init_process() { $pso = pts_storage_object::recover_from_file(PTS_CORE_STORAGE); if ($pso == false) { $pso = new pts_storage_object(true, true); } // OpenBenchmarking.org - GSID $global_gsid = $pso->read_object('global_system_id'); $global_gsid_e = $pso->read_object('global_system_id_e'); $global_gsid_p = $pso->read_object('global_system_id_p'); if (empty($global_gsid) || pts_openbenchmarking::is_valid_gsid_format($global_gsid) == false) { // Global System ID for anonymous uploads, etc $requested_gsid = true; $global_gsid = pts_openbenchmarking_client::request_gsid(); if (is_array($global_gsid)) { $pso->add_object('global_system_id', $global_gsid['gsid']); // GSID $pso->add_object('global_system_id_p', $global_gsid['gsid_p']); // GSID_P $pso->add_object('global_system_id_e', $global_gsid['gsid_e']); // GSID_E pts_define('PTS_GSID', $global_gsid['gsid']); pts_define('PTS_GSID_E', $global_gsid['gsid_e']); } } else { if (pts_openbenchmarking::is_valid_gsid_e_format($global_gsid_e) == false || pts_openbenchmarking::is_valid_gsid_p_format($global_gsid_p) == false) { pts_define('PTS_GSID', $global_gsid); $requested_gsid = false; $global_gsid = pts_openbenchmarking_client::retrieve_gsid(); if (is_array($global_gsid)) { $pso->add_object('global_system_id_p', $global_gsid['gsid_p']); // GSID_P $pso->add_object('global_system_id_e', $global_gsid['gsid_e']); // GSID_E pts_define('PTS_GSID_E', $global_gsid['gsid_e']); } } else { pts_define('PTS_GSID', $global_gsid); pts_define('PTS_GSID_E', $global_gsid_e); $requested_gsid = false; } } $machine_self_id = $pso->read_object('machine_self_id'); if (empty($machine_self_id)) { $ns = md5('phoronix-test-suite'); $binary_ns = null; for ($i = 0; $i < strlen($ns); $i += 2) { $binary_ns .= chr(hexdec($ns[$i] . $ns[$i + 1])); } $msi_hash = sha1($binary_ns . uniqid(PTS_CORE_VERSION, true) . getenv('USERNAME') . getenv('USER') . getenv('HOSTNAME') . pts_network::get_local_ip()); $machine_self_id = sprintf('%08s-%04s-%04x-%04x-%12s', substr($msi_hash, 0, 8), substr($msi_hash, 8, 4), hexdec(substr($msi_hash, 12, 4)) & 0xfff | 0x5000, hexdec(substr($msi_hash, 16, 4)) & 0x3fff | 0x8000, substr($msi_hash, 20, 12)); // machine_self_id is self-generated unique name for Phoromatic/OB purposes in UUIDv5 format $pso->add_object('machine_self_id', $machine_self_id); } pts_define('PTS_MACHINE_SELF_ID', $machine_self_id); // Last Run Processing $last_core_version = $pso->read_object('last_core_version'); pts_define('FIRST_RUN_ON_PTS_UPGRADE', $last_core_version != PTS_CORE_VERSION); if (FIRST_RUN_ON_PTS_UPGRADE || $pso->read_object('last_php_version') != PTS_PHP_VERSION) { // Report any missing/recommended extensions self::program_requirement_checks(); } if (FIRST_RUN_ON_PTS_UPGRADE) { if ($requested_gsid == false) { pts_openbenchmarking_client::update_gsid(); } pts_client::build_temp_cache(); } $pso->add_object('last_core_version', PTS_CORE_VERSION); // PTS version last run $pso->add_object('last_php_version', PTS_PHP_VERSION); // PHP version last run //$last_pts_version = $pso->read_object('last_pts_version'); // do something here with $last_pts_version if you want that information $pso->add_object('last_pts_version', PTS_VERSION); // PTS version last run // Last Run Processing $last_run = $pso->read_object('last_run_time'); pts_define('IS_FIRST_RUN_TODAY', substr($last_run, 0, 10) != date('Y-m-d')); $pso->add_object('last_run_time', date('Y-m-d H:i:s')); // Time PTS was last run pts_define('TIME_SINCE_LAST_RUN', ceil((time() - strtotime($last_run)) / 60)); // TIME_SINCE_LAST_RUN is in minutes // User Agreement Checking $agreement_cs = $pso->read_object('user_agreement_cs'); $pso->add_object('user_agreement_cs', $agreement_cs); // User agreement check-sum // Phodevi Cache Handling $phodevi_cache = $pso->read_object('phodevi_smart_cache'); if ($phodevi_cache instanceof phodevi_cache && pts_client::read_env('NO_PHODEVI_CACHE') == false) { $phodevi_cache = $phodevi_cache->restore_cache(PTS_USER_PATH, PTS_CORE_VERSION); phodevi::set_device_cache($phodevi_cache); if ($external_phodevi_cache = pts_client::read_env('EXTERNAL_PHODEVI_CACHE')) { if (is_dir($external_phodevi_cache) && is_file($external_phodevi_cache . '/core.pt2so')) { $external_phodevi_cache .= '/core.pt2so'; } if (is_file($external_phodevi_cache)) { $external_phodevi_cache = pts_storage_object::force_recover_from_file($external_phodevi_cache); if ($external_phodevi_cache != false) { $external_phodevi_cache = $external_phodevi_cache->read_object('phodevi_smart_cache'); $external_phodevi_cache = $external_phodevi_cache->restore_cache(null, PTS_CORE_VERSION); if ($external_phodevi_cache != false) { //unset($external_phodevi_cache['system']['operating-system']); //unset($external_phodevi_cache['system']['vendor-identifier']); phodevi::set_device_cache($external_phodevi_cache); } } } } } // Archive to disk $pso->save_to_file(PTS_CORE_STORAGE); }
private static function set_user_context($context_script, $trigger, $schedule_id, $process) { if (!empty($context_script)) { if (!is_executable($context_script)) { if (($context_script = pts_client::executable_in_path($context_script)) == false || !is_executable($context_script)) { return false; } } $storage_path = pts_module::save_dir() . 'memory.pt2so'; $storage_object = pts_storage_object::recover_from_file($storage_path); // 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 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); // Run the set context script exec($context_script . ' ' . $trigger); // Just simply return true for now, perhaps check exit code status and do something return true; } return false; }