Best Phoronix-test-suite code snippet using phoromatic
phoromatic.php
Source:phoromatic.php
...14 GNU General Public License for more details.15 You should have received a copy of the GNU General Public License16 along with this program. If not, see <http://www.gnu.org/licenses/>.17*/18class phoromatic extends pts_module_interface19{20 const module_name = 'Phoromatic Client';21 const module_version = '1.1.0';22 const module_description = 'The Phoromatic client is used for connecting to a Phoromatic server (Phoromatic.com or a locally run server) to facilitate the automatic running of tests, generally across multiple test nodes in a routine manner. For more details visit http://www.phoromatic.com/. This module is intended to be used with Phoronix Test Suite 5.2+ clients and servers.';23 const module_author = 'Phoronix Media';24 private static $account_id = null;25 private static $server_address = null;26 private static $server_http_port = null;27 private static $server_ws_port = null;28 private static $is_running_as_phoromatic_node = false;29 private static $log_file = null;30 private static $limit_network_communication = false;31 private static $p_save_identifier = null;32 private static $p_schedule_id = null;33 private static $p_trigger_id = null;34 private static $benchmark_ticket_id = null;35 private static $in_stress_mode = false;36 private static $has_run_server_setup_func = false;37 private static $test_run_manager = null;38 public static function module_info()39 {40 return 'The Phoromatic module contains the client support for interacting with Phoromatic and Phoromatic Tracker services.';41 }42 public static function user_commands()43 {44 return array('connect' => 'run_connection', 'explore' => 'explore_network', 'upload_result' => 'upload_unscheduled_result', 'set_root_admin_password' => 'set_root_admin_password', 'list_results' => 'recent_phoromatic_server_results', 'clone' => 'clone_phoromatic_server_result', 'export_results_for_account_schedules' => 'generate_export_result_schedule_dump');45 }46 public static function upload_unscheduled_result($args)47 {48 $server_setup = self::setup_server_addressing($args);49 if(!$server_setup)50 return false;51 $uploads = 0;52 foreach($args as $arg)53 {54 if(pts_types::is_result_file($arg))55 {56 $uploads++;57 echo PHP_EOL . 'Uploading: ' . $arg . PHP_EOL;58 $result_file = pts_types::identifier_to_object($arg);59 $server_response = self::upload_test_result($result_file);60 $server_response = json_decode($server_response, true);61 if(isset($server_response['phoromatic']['response']))62 echo ' Result Uploaded' . PHP_EOL;63 else64 echo ' Upload Failed' . PHP_EOL;65 }66 }67 if($uploads == 0)68 echo PHP_EOL . 'No Result Files Found To Upload.' . PHP_EOL;69 }70 public static function set_root_admin_password()71 {72 phoromatic_server::prepare_database();73 $root_admin_pw = phoromatic_server::read_setting('root_admin_pw');74 if($root_admin_pw != null)75 {76 do77 {78 $check_root_pw = pts_user_io::prompt_user_input('Please enter the existing root-admin password');79 }80 while(hash('sha256', 'PTS' . $check_root_pw) != $root_admin_pw);81 }82 echo PHP_EOL . 'The new root-admin password must be at least six characters long.' . PHP_EOL;83 do84 {85 $new_root_pw = pts_user_io::prompt_user_input('Please enter the new root-admin password');86 }87 while(strlen($new_root_pw) < 6);88 $new_root_pw = hash('sha256', 'PTS' . $new_root_pw);89 $root_admin_pw = phoromatic_server::save_setting('root_admin_pw', $new_root_pw);90 }91 public static function generate_export_result_schedule_dump($r)92 {93 phoromatic_server::prepare_database();94 if(isset($r[0]) && !empty($r[0]))95 {96 phoromatic_server::generate_result_export_dump($r[0]);97 }98 }99 public static function explore_network()100 {101 pts_client::$display->generic_heading('Phoromatic Servers');102 $archived_servers = pts_client::available_phoromatic_servers();103 $server_count = 0;104 foreach($archived_servers as $archived_server)105 {106 $response = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/server.php?phoromatic_info');107 if(!empty($response))108 {109 $response = json_decode($response, true);110 if($response && isset($response['pts']))111 {112 $server_count++;113 echo PHP_EOL . 'IP: ' . $archived_server['ip'] . PHP_EOL;114 echo 'HTTP PORT: ' . $archived_server['http_port'] . PHP_EOL;115 echo 'WEBSOCKET PORT: ' . $response['ws_port'] . PHP_EOL;116 echo 'SERVER: ' . $response['http_server'] . PHP_EOL;117 echo 'PHORONIX TEST SUITE: ' . $response['pts'] . ' [' . $response['pts_core'] . ']' . PHP_EOL;118 // TODO XXX fix/finish below code...119 if(false && ($ws = new phoromatic_client_comm_ws($archived_server['ip'], $response['ws_port'])))120 {121 // Query the WebSocket Server for some Phoromatic Server details122 $s = $ws->send(array('phoromatic' => array('event' => 'pts-version')));123 $s = $ws->send(array('phoromatic' => array('event' => 'download-cache')));124 $r = $ws->receive_until('download-cache');125 var_dump($r);126 }127 else128 {129 // Provide some other server info via HTTP130 $repo = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/download-cache.php?repo');131 echo 'DOWNLOAD CACHE: ';132 if(!empty($repo))133 {134 $repo = json_decode($repo, true);135 if($repo && isset($repo['phoronix-test-suite']['download-cache']))136 {137 $total_file_size = 0;138 foreach($repo['phoronix-test-suite']['download-cache'] as $file_name => $inf)139 {140 $total_file_size += $repo['phoronix-test-suite']['download-cache'][$file_name]['file_size'];141 }142 echo count($repo['phoronix-test-suite']['download-cache']) . ' FILES / ' . round($total_file_size / 1000000) . ' MB CACHE SIZE';143 }144 }145 else146 {147 echo 'N/A';148 }149 }150 echo PHP_EOL;151 $repo = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/openbenchmarking-cache.php?repos');152 echo 'SUPPORTED OPENBENCHMARKING.ORG REPOSITORIES:' . PHP_EOL;153 if(!empty($repo))154 {155 $repo = json_decode($repo, true);156 if($repo && is_array($repo['repos']))157 {158 foreach($repo['repos'] as $data)159 {160 echo ' ' . $data['title'] . ' - Last Generated: ' . date('d M Y H:i', $data['generated']) . PHP_EOL;161 }162 }163 }164 else165 {166 echo ' N/A' . PHP_EOL;167 }168 }169 }170 }171 if($server_count == 0)172 {173 echo PHP_EOL . 'No Phoromatic Servers detected.' . PHP_EOL . PHP_EOL;174 }175 }176 protected static function tick_thread()177 {178 static $last_phoromatic_log = 0;179 while(true)180 {181 $j = array();182 $log_size = pts_client::$pts_logger->get_log_file_size();183 if($log_size != $last_phoromatic_log)184 {185 $phoromatic_log = file_get_contents(pts_client::$pts_logger->get_log_file_location());186 $last_phoromatic_log = $log_size;187 $j['phoromatic']['client-log'] = $phoromatic_log;188 }189 foreach(phodevi::supported_sensors() as $sensor)190 {191 $j['phoromatic']['stats']['sensors'][phodevi::sensor_name($sensor)] = array('value' => phodevi::read_sensor($sensor), 'unit' => phodevi::read_sensor_unit($sensor));192 }193 $j['phoromatic']['stats']['uptime'] = ceil(phodevi::system_uptime() / 60);194 $server_response = phoromatic::upload_to_remote_server(array(195 'r' => 'tick',196 'j' => json_encode($j),197 ));198 $server_response = json_decode($server_response, true);199 if($server_response && isset($server_response['phoromatic']['tick_thread']))200 {201 switch($server_response['phoromatic']['tick_thread'])202 {203 case 'reboot':204 if(pts_client::executable_in_path('reboot'))205 {206 shell_exec('reboot');207 }208 break;209 case 'halt-testing':210 touch(PTS_USER_PATH . 'halt-testing');211 break;212 }213 }214 // Randomize the thread work a little bit to ensure not hitting the systems at the same time215 sleep(rand(60, 90));216 }217 }218 protected static function upload_to_remote_server($to_post, $server_address = null, $server_http_port = null, $account_id = null)219 {220 static $last_communication_minute = null;221 static $communication_attempts = 0;222 if($last_communication_minute == date('i') && $communication_attempts > 8)223 {224 // Something is wrong, Phoromatic shouldn't be communicating with server more than four times a minute225 return false;226 }227 else228 {229 if(date('i') != $last_communication_minute)230 {231 $last_communication_minute = date('i');232 $communication_attempts = 0;233 }234 $communication_attempts++;235 }236 if($server_address == null && self::$server_address != null)237 {238 $server_address = self::$server_address;239 }240 if($server_http_port == null && self::$server_http_port != null)241 {242 $server_http_port = self::$server_http_port;243 }244 if($account_id == null && self::$account_id != null)245 {246 $account_id = self::$account_id;247 }248 $to_post['aid'] = $account_id;249 $to_post['pts'] = PTS_VERSION;250 $to_post['pts_core'] = PTS_CORE_VERSION;251 $to_post['gsid'] = defined('PTS_GSID') ? PTS_GSID : null;252 $to_post['lip'] = pts_network::get_local_ip();253 $to_post['h'] = phodevi::system_hardware(true);254 $to_post['nm'] = pts_network::get_network_mac();255 $to_post['nw'] = implode(', ', pts_network::get_network_wol());256 $to_post['s'] = phodevi::system_software(true);257 $to_post['n'] = phodevi::read_property('system', 'hostname');258 $to_post['msi'] = PTS_MACHINE_SELF_ID;259 return pts_network::http_upload_via_post('http://' . $server_address . ':' . $server_http_port . '/phoromatic.php', $to_post, false);260 }261 protected static function update_system_status($current_task, $estimated_time_remaining = 0, $percent_complete = 0, $for_schedule = null, $estimate_to_next_comm = 0)262 {263 static $last_msg = null;264 // Avoid an endless flow of "idling" messages, etc265 if($current_task != $last_msg)266 pts_client::$pts_logger && pts_client::$pts_logger->log($current_task);267 $last_msg = $current_task;268 if(self::$limit_network_communication)269 {270 static $last_comm_time = 0;271 if(time() > ($last_comm_time + 800 + rand(0, 180)))272 {273 // It's been at least half hour since last update, so report in state...274 $last_comm_time = time();275 }276 else277 {278 return;279 }280 }281 return phoromatic::upload_to_remote_server(array(282 'r' => 'update_system_status',283 'a' => $current_task,284 'time' => $estimated_time_remaining,285 'pc' => $percent_complete,286 'sched' => (!empty($for_schedule) ? $for_schedule : self::$p_schedule_id),287 'bid' => (!empty(self::$benchmark_ticket_id) ? self::$benchmark_ticket_id : 0),288 'o' => $estimate_to_next_comm289 ));290 }291 public static function startup_ping_check($server_ip, $http_port)292 {293 $server_response = phoromatic::upload_to_remote_server(array(294 'r' => 'ping',295 ), $server_ip, $http_port);296 }297 protected static function setup_server_addressing($server_string = null)298 {299 self::$has_run_server_setup_func = true;300 if(isset($server_string[0]) && strpos($server_string[0], '/', strpos($server_string[0], ':')) > 6)301 {302 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to connect to Phoromatic Server: ' . $server_string[0]);303 self::$account_id = substr($server_string[0], strrpos($server_string[0], '/') + 1);304 self::$server_address = substr($server_string[0], 0, strpos($server_string[0], ':'));305 self::$server_http_port = substr($server_string[0], strlen(self::$server_address) + 1, -1 - strlen(self::$account_id));306 pts_client::$display->generic_heading('Server IP: ' . self::$server_address . PHP_EOL . 'Server HTTP Port: ' . self::$server_http_port . PHP_EOL . 'Account ID: ' . self::$account_id);307 pts_client::register_phoromatic_server(self::$server_address, self::$server_http_port);308 }309 else if(($last_server = trim(pts_module::read_file('last-phoromatic-server'))) && !empty($last_server))310 {311 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to connect to last server connection: ' . $last_server);312 $last_account_id = substr($last_server, strrpos($last_server, '/') + 1);313 $last_server_address = substr($last_server, 0, strpos($last_server, ':'));314 $last_server_http_port = substr($last_server, strlen($last_server_address) + 1, -1 - strlen($last_account_id));315 pts_client::$pts_logger && pts_client::$pts_logger->log('Last Server IP: ' . $last_server_address . ' Last Server HTTP Port: ' . $last_server_http_port . ' Last Account ID: ' . $last_account_id);316 for($i = 0; $i < 10; $i++)317 {318 $server_response = phoromatic::upload_to_remote_server(array(319 'r' => 'ping',320 ), $last_server_address, $last_server_http_port, $last_account_id);321 $server_response = json_decode($server_response, true);322 if($server_response && isset($server_response['phoromatic']['ping']))323 {324 self::$server_address = $last_server_address;325 self::$server_http_port = $last_server_http_port;326 self::$account_id = $last_account_id;327 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection restored');328 pts_client::register_phoromatic_server(self::$server_address, self::$server_http_port);329 break;330 }331 else332 {333 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection failed');334 sleep((12 * ($i + 1)));335 }336 }337 }338 if(self::$server_address == null)339 {340 $archived_servers = pts_client::available_phoromatic_servers();341 if(!empty($archived_servers))342 {343 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to auto-discover Phoromatic Servers');344 self::attempt_phoromatic_server_auto_discover($archived_servers);345 }346 }347 if(self::$server_address == null || self::$server_http_port == null || self::$account_id == null)348 {349 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection setup failed');350 echo PHP_EOL . 'You must pass the Phoromatic Server information as an argument to phoromatic.connect, or otherwise configure your network setup.' . PHP_EOL . ' e.g. phoronix-test-suite phoromatic.connect 192.168.1.2:5555/I0SSJY' . PHP_EOL . PHP_EOL;351 if(PTS_IS_DAEMONIZED_SERVER_PROCESS && !empty($archived_servers))352 {353 echo 'The Phoromatic client appears to be running as a system service/daemon so will attempt to continue auto-polling to find the Phoromatic Server.' . PHP_EOL . PHP_EOL;354 $success = false;355 do356 {357 pts_client::$pts_logger && pts_client::$pts_logger->log('Will auto-poll connected servers every 90 seconds looking for a claim by a Phoromatic Server');358 sleep(90);359 $success = self::attempt_phoromatic_server_auto_discover($archived_servers);360 }361 while($success == false);362 }363 else364 {365 return false;366 }367 }368 return true;369 }370 protected static function attempt_phoromatic_server_auto_discover(&$phoromatic_servers)371 {372 foreach($phoromatic_servers as &$archived_server)373 {374 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to auto-discover Phoromatic Server on: ' . $archived_server['ip'] . ': ' . $archived_server['http_port']);375 $server_response = phoromatic::upload_to_remote_server(array(376 'r' => 'ping',377 ), $archived_server['ip'], $archived_server['http_port']);378 $server_response = json_decode($server_response, true);379 if($server_response && isset($server_response['phoromatic']['account_id']))380 {381 self::$server_address = $archived_server['ip'];382 self::$server_http_port = $archived_server['http_port'];383 self::$account_id = $server_response['phoromatic']['account_id'];384 return true;385 }386 }387 return false;388 }389 protected static function setup_system_environment()390 {391 if(is_writable('/boot/grub/grubenv') && pts_client::executable_in_path('grub-editenv'))392 {393 // In case system fails or reboots in process and don't want to hang on GRUB recordfail394 shell_exec('grub-editenv /boot/grub/grubenv unset recordfail 2>&1');395 }396 }397 public static function run_connection($args)398 {399 if(pts_client::create_lock(PTS_USER_PATH . 'phoromatic_lock') == false)400 {401 trigger_error('Phoromatic is already running.', E_USER_ERROR);402 return false;403 }404 define('PHOROMATIC_PROCESS', true);405 if(pts_client::$pts_logger == false)406 {407 pts_client::$pts_logger = new pts_logger();408 }409 pts_client::$pts_logger->log(pts_core::program_title(true) . ' [' . PTS_CORE_VERSION . '] starting Phoromatic client');410 if(phodevi::system_uptime() < 60)411 {412 echo 'PHOROMATIC: Sleeping for 60 seconds as system freshly started.' . PHP_EOL;413 pts_client::$pts_logger->log('Sleeping for 60 seconds as system freshly started');414 sleep(60);415 }416 $server_setup = self::setup_server_addressing($args);417 //$http_comm = new phoromatic_client_comm_http();418 if(!$server_setup)419 {420 if(getenv('PTS_NO_REBOOT_ON_NETWORK_FAILURE') == false && PTS_IS_DAEMONIZED_SERVER_PROCESS)421 {422 if(pts_client::executable_in_path('reboot'))423 {424 shell_exec('reboot');425 sleep(5);426 }427 }428 return false;429 }430 $times_failed = 0;431 $has_success = false;432 $do_exit = false;433 $just_started = true;434 self::setup_system_environment();435 pts_client::$pts_logger->log('SYSTEM HARDWARE: ' . phodevi::system_hardware(true));436 pts_client::$pts_logger->log('SYSTEM SOFTWARE: ' . phodevi::system_software(true));437 while($do_exit == false)438 {439 $server_response = phoromatic::upload_to_remote_server(array(440 'r' => 'start',441 ));442 if($server_response == false)443 {444 $times_failed++;445 pts_client::$pts_logger->log('Server response failed');446 if($times_failed >= 2)447 {448 trigger_error('Communication with server failed.', E_USER_ERROR);449 if(PTS_IS_DAEMONIZED_SERVER_PROCESS == false && $times_failed > 5)450 {451 return false;452 }453 else if(PTS_IS_DAEMONIZED_SERVER_PROCESS && $times_failed > 10)454 {455 if(getenv('PTS_NO_REBOOT_ON_NETWORK_FAILURE') == false && pts_client::executable_in_path('reboot'))456 {457 shell_exec('reboot');458 sleep(5);459 }460 }461 }462 }463 else if(substr($server_response, 0, 1) == '[')464 {465 // Likely a notice/warning from server466 echo PHP_EOL . substr($server_response, 0, strpos($server_response, PHP_EOL)) . PHP_EOL;467 }468 else if(substr($server_response, 0, 1) == '{')469 {470 $times_failed = 0;471 $json = json_decode($server_response, true);472 if($has_success == false)473 {474 $has_success = true;475 pts_module::save_file('last-phoromatic-server', self::$server_address . ':' . self::$server_http_port . '/' . self::$account_id);476 }477 if($json != null)478 {479 if(isset($json['phoromatic']['error']) && !empty($json['phoromatic']['error']))480 {481 trigger_error($json['phoromatic']['error'], E_USER_ERROR);482 }483 if(isset($json['phoromatic']['response']) && !empty($json['phoromatic']['response']))484 {485 echo PHP_EOL . $json['phoromatic']['response'] . PHP_EOL;486 }487 }488 self::$limit_network_communication = isset($json['phoromatic']['settings']['LimitNetworkCommunication']) && pts_strings::string_bool($json['phoromatic']['settings']['LimitNetworkCommunication']);489 if(self::$limit_network_communication)490 {491 // Sleep to ensure network communication is somewhat random in case all systems started at same time492 sleep(0, 20);493 }494 if($just_started)495 {496 if(PTS_IS_DAEMONIZED_SERVER_PROCESS && !self::$limit_network_communication)497 {498 $pid = pcntl_fork();499 if($pid == 0)500 {501 // Start the tick thread502 self::tick_thread();503 }504 }505 $just_started = false;506 }507 if(isset($json['phoromatic']['pre_set_sys_env_vars']) && !empty($json['phoromatic']['pre_set_sys_env_vars']))508 {509 // pre_set_sys_env_vars was added during PTS 5.8 development510 // Sets environment variables on client as specified via the Phoromatic Server's systems page511 foreach(explode(';', $json['phoromatic']['pre_set_sys_env_vars']) as $i => $v_string)512 {513 $var = explode('=', $v_string);514 if(count($var) == 2)515 {516 putenv($var[0] . '=' . $var[1]);517 }518 }519 }520 switch(isset($json['phoromatic']['task']) ? $json['phoromatic']['task'] : null)521 {522 case 'install':523 phoromatic::update_system_status('Installing Tests');524 pts_test_suite::set_temporary_suite('pre-seed', $json['phoromatic']['test_suite']);525 pts_test_installer::standard_install('pre-seed', false, true);526 break;527 case 'benchmark':528 // Make sure all latest tests are available529 pts_openbenchmarking::refresh_repository_lists(null, true);530 $benchmark_timer = time();531 self::$is_running_as_phoromatic_node = true;532 $suite_identifier = sha1(time() . rand(2, 1000));533 pts_test_suite::set_temporary_suite($suite_identifier, $json['phoromatic']['test_suite']);534 self::$p_save_identifier = $json['phoromatic']['trigger_id'];535 $phoromatic_results_identifier = self::$p_save_identifier;536 $phoromatic_save_identifier = $json['phoromatic']['save_identifier'];537 self::$p_schedule_id = isset($json['phoromatic']['schedule_id']) ? $json['phoromatic']['schedule_id'] : false;538 self::$p_trigger_id = self::$p_save_identifier;539 $benchmark_ticket_id = isset($json['phoromatic']['benchmark_ticket_id']) ? $json['phoromatic']['benchmark_ticket_id'] : null;540 self::$benchmark_ticket_id = $benchmark_ticket_id;541 phoromatic::update_system_status('Running Benchmarks For: ' . $phoromatic_save_identifier);542 if(pts_strings::string_bool($json['phoromatic']['settings']['RunInstallCommand']))543 {544 if(isset($json['phoromatic']['pre_install_set_context']))545 {546 phoromatic::set_user_context($json['phoromatic']['pre_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_INSTALL');547 }548 pts_test_installer::standard_install($suite_identifier, pts_strings::string_bool($json['phoromatic']['settings']['ForceInstallTests']), true);549 if(isset($json['phoromatic']['post_install_set_context']))550 {551 phoromatic::set_user_context($json['phoromatic']['post_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_INSTALL');552 }553 }554 $env_vars = isset($json['phoromatic']['environment_variables']) ? pts_strings::parse_value_string_vars($json['phoromatic']['environment_variables']) : array();555 $is_stress_run = isset($env_vars['PTS_CONCURRENT_TEST_RUNS']) && $env_vars['PTS_CONCURRENT_TEST_RUNS'] > 1;556 // Do the actual running557 phodevi::clear_cache();558 if($is_stress_run)559 {560 self::$test_run_manager = new pts_stress_run_manager(array(561 'UploadResults' => false,562 'SaveResults' => false,563 'PromptForTestDescription' => false,564 'RunAllTestCombinations' => false,565 'PromptSaveName' => false,566 'PromptForTestIdentifier' => false,567 'OpenBrowser' => false568 ), true);569 if(self::$test_run_manager->initial_checks($suite_identifier, 'SHORT'))570 {571 if(self::$test_run_manager->load_tests_to_run($suite_identifier))572 {573 self::$test_run_manager->action_on_stress_log_set(array('phoromatic', 'upload_stress_log_sane'));574 self::$in_stress_mode = $phoromatic_save_identifier;575 self::$test_run_manager->multi_test_stress_run_execute($env_vars['PTS_CONCURRENT_TEST_RUNS'], $env_vars['TOTAL_LOOP_TIME']);576 self::$in_stress_mode = false;577 self::upload_stress_log(self::$test_run_manager->get_stress_log());578 }579 }580 self::$benchmark_ticket_id = null;581 break;582 }583 else584 {585 self::$test_run_manager = new pts_test_run_manager(array(586 'UploadResults' => (isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking'])),587 'SaveResults' => true,588 'RunAllTestCombinations' => false,589 'OpenBrowser' => false590 ), true);591 }592 if(self::$test_run_manager->initial_checks($suite_identifier, 'SHORT'))593 {594 // Load the tests to run595 if(self::$test_run_manager->load_tests_to_run($suite_identifier))596 {597 phoromatic::update_system_status('Tests In Run Queue: ' . implode(', ', self::$test_run_manager->get_tests_to_run_identifiers()));598 if(isset($json['phoromatic']['pre_run_set_context']))599 {600 phoromatic::set_user_context($json['phoromatic']['pre_run_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_RUN');601 }602 if(isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']))603 {604 self::$test_run_manager->auto_upload_to_openbenchmarking();605 pts_openbenchmarking_client::override_client_setting('UploadSystemLogsByDefault', pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']));606 }607 // Save results?608 // Run the actual tests609 self::$test_run_manager->auto_save_results($phoromatic_save_identifier, $phoromatic_results_identifier, (isset($json['phoromatic']['test_description']) ? $json['phoromatic']['test_description'] : 'A Phoromatic run.'));610 self::$test_run_manager->pre_execution_process();611 self::$test_run_manager->call_test_runs();612 phoromatic::update_system_status('Benchmarks Completed For: ' . $phoromatic_save_identifier);613 self::$test_run_manager->post_execution_process();614 $elapsed_benchmark_time = time() - $benchmark_timer;615 // Handle uploading data to server616 $result_file = new pts_result_file(self::$test_run_manager->get_file_name());617 $upload_system_logs = pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']);618 $server_response = self::upload_test_result($result_file, $upload_system_logs, (isset($json['phoromatic']['schedule_id']) ? $json['phoromatic']['schedule_id'] : null), $phoromatic_save_identifier, $json['phoromatic']['trigger_id'], $elapsed_benchmark_time, $benchmark_ticket_id);619 //pts_client::$pts_logger->log('DEBUG RESPONSE MESSAGE: ' . $server_response);620 if(!pts_strings::string_bool($json['phoromatic']['settings']['ArchiveResultsLocally']))621 {622 pts_client::remove_saved_result_file(self::$test_run_manager->get_file_name());623 }624 }625 if(isset($json['phoromatic']['post_run_set_context']))626 {627 phoromatic::set_user_context($json['phoromatic']['post_run_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_RUN');628 }629 }630 self::$p_schedule_id = null;631 self::$is_running_as_phoromatic_node = false;632 self::$benchmark_ticket_id = null;633 break;634 case 'reboot':635 echo PHP_EOL . 'Phoromatic received a remote command to reboot.' . PHP_EOL;636 phoromatic::update_system_status('Attempting System Reboot');637 if(pts_client::executable_in_path('reboot'))638 {639 shell_exec('reboot');640 sleep(5);641 }642 break;643 case 'shutdown-if-supports-wake':644 $supports_wol = false;645 foreach(pts_network::get_network_wol() as $net_device)646 {647 if(strpos($net_device, 'g') !== false)648 {649 $supports_wol = true;650 break;651 }652 }653 if(!$supports_wol)654 break;655 case 'shutdown':656 if(isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script']))657 {658 self::run_client_update_script($json['phoromatic']['client_update_script']);659 sleep(10);660 }661 echo PHP_EOL . 'Phoromatic received a remote command to shutdown.' . PHP_EOL;662 phoromatic::update_system_status('Attempting System Shutdown');663 if(pts_client::executable_in_path('poweroff'))664 {665 shell_exec('poweroff');666 sleep(5);667 }668 break;669 case 'maintenance':670 echo PHP_EOL . 'Idling, system maintenance mode set by Phoromatic Server.' . PHP_EOL;671 phoromatic::update_system_status('Maintenance Mode');672 sleep(60);673 break;674 case 'idle':675 if(isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script']))676 {677 self::run_client_update_script($json['phoromatic']['client_update_script']);678 }679 //echo PHP_EOL . 'Idling, waiting for task.' . PHP_EOL;680 phoromatic::update_system_status('Idling, Waiting For Task');681 break;682 case 'exit':683 echo PHP_EOL . 'Phoromatic received a remote command to exit.' . PHP_EOL;684 phoromatic::update_system_status('Exiting Phoromatic');685 $do_exit = true;686 break;687 }688 }689 if(!$do_exit)690 {691 if($server_response == false)692 sleep(rand(10, 30));693 else if(self::$limit_network_communication)694 sleep(60, 240);695 else696 sleep(60);697 }698 }699 pts_client::release_lock(PTS_USER_PATH . 'phoromatic_lock');700 }701 private static function upload_test_result(&$result_file, $upload_system_logs = true, $schedule_id = 0, $save_identifier = null, $trigger = null, $elapsed_time = 0, $benchmark_ticket_id = null)702 {703 $system_logs = null;704 $system_logs_hash = null;705 // TODO: Potentially integrate this code below shared with pts_openbenchmarking_client into a unified function for validating system log files706 $system_log_dir = PTS_SAVE_RESULTS_PATH . $result_file->get_identifier() . '/system-logs/';707 if(is_dir($system_log_dir) && $upload_system_logs)708 {709 $is_valid_log = true;710 $finfo = function_exists('finfo_open') ? finfo_open(FILEINFO_MIME_TYPE) : false;711 foreach(pts_file_io::glob($system_log_dir . '*') as $log_dir)712 {713 if($is_valid_log == false || !is_dir($log_dir))714 {715 $is_valid_log = false;716 break;717 }718 foreach(pts_file_io::glob($log_dir . '/*') as $log_file)719 {720 if(!is_file($log_file))721 {722 $is_valid_log = false;723 break;724 }725 if($finfo && substr(finfo_file($finfo, $log_file), 0, 5) != 'text/')726 {727 $is_valid_log = false;728 break;729 }730 }731 }732 if($is_valid_log)733 {734 $system_logs_zip = pts_client::create_temporary_file('.zip');735 pts_compression::zip_archive_create($system_logs_zip, $system_log_dir);736 if(filesize($system_logs_zip) == 0)737 {738 pts_client::$pts_logger && pts_client::$pts_logger->log('System log ZIP file failed to generate. Missing PHP ZIP support?');739 }740 else if(filesize($system_logs_zip) < 2097152)741 {742 // If it's over 2MB, probably too big743 $system_logs = base64_encode(file_get_contents($system_logs_zip));744 $system_logs_hash = sha1($system_logs);745 }746 else747 {748 // trigger_error('The systems log attachment is too large to upload to OpenBenchmarking.org.', E_USER_WARNING);749 }750 unlink($system_logs_zip);751 }752 }753 $composite_xml = $result_file->get_xml();754 $composite_xml_hash = sha1($composite_xml);755 $composite_xml_type = 'composite_xml';756 // Compress the result file XML if it's big757 if(isset($composite_xml[50000]) && function_exists('gzdeflate'))758 {759 $composite_xml_gz = gzdeflate($composite_xml);760 if($composite_xml_gz != false)761 {762 $composite_xml = $composite_xml_gz;763 $composite_xml_type = 'composite_xml_gz';764 }765 }766 // Upload to Phoromatic767 $times_tried = 0;768 do769 {770 if($times_tried > 0)771 {772 sleep(rand(5, 20));773 }774 $res = phoromatic::upload_to_remote_server(array(775 'r' => 'result_upload',776 //'ob' => $ob_data['id'],777 'sched' => $schedule_id,778 'bid' => $benchmark_ticket_id,779 'o' => $save_identifier,780 'ts' => $trigger,781 'et' => $elapsed_time,782 $composite_xml_type => base64_encode($composite_xml),783 'composite_xml_hash' => $composite_xml_hash,784 'system_logs_zip' => $system_logs,785 'system_logs_hash' => $system_logs_hash786 ));787 $times_tried++;788 }789 while($res == false && $times_tried < 4);790 return $res;791 }792 private static function upload_stress_log($stress_log)793 {794 // Upload Logs to Phoromatic795 if($stress_log == null || self::$benchmark_ticket_id == null)796 {797 return;798 }799 $times_tried = 0;800 do801 {802 if($times_tried > 0)803 {804 sleep(rand(5, 20));805 }806 $res = phoromatic::upload_to_remote_server(array(807 'r' => 'stress_log_upload',808 'bid' => self::$benchmark_ticket_id,809 'l' => $stress_log810 ));811 $times_tried++;812 }813 while($res == false && $times_tried < 4);814 return $res;815 }816 public static function upload_stress_log_sane($stress_log)817 {818 static $last_log_upload = 0;819 if(time() > ($last_log_upload + 60))820 {821 self::upload_stress_log($stress_log);822 $last_log_upload = time();823 }824 }825 public static function recent_phoromatic_server_results()826 {827 self::setup_server_addressing();828 $server_response = phoromatic::upload_to_remote_server(array('r' => 'list_results'));829 $server_response = json_decode($server_response, true);830 if(isset($server_response['phoromatic']['results']) && !empty($server_response['phoromatic']['results']))831 {832 foreach($server_response['phoromatic']['results'] as $pprid => $result)833 {834 echo sprintf('%-26ls - %-25ls - %-30ls', $result['Title'], $pprid, date('j M H:i', strtotime($result['UploadTime']))) . PHP_EOL;835 echo sprintf(' %-20ls - %-25ls' . PHP_EOL, $result['SystemName'], $result['GroupName']) . PHP_EOL;836 }837 }838 else839 echo PHP_EOL . 'No Phoromatic Server results discovered.';840 echo PHP_EOL;841 }842 public static function clone_phoromatic_server_result($args)843 {844 self::setup_server_addressing();845 $id = $args[0];846 $server_response = phoromatic::upload_to_remote_server(array('r' => 'clone_result', 'i' => $id));847 $server_response = json_decode($server_response, true);848 if(isset($server_response['phoromatic']['result']['composite_xml']) && !empty($server_response['phoromatic']['result']['composite_xml']))849 {850 $composite_xml = base64_decode($server_response['phoromatic']['result']['composite_xml']);851 $result_file = new pts_result_file($composite_xml);852 // TODO XXX: Add system log downloading support853 pts_client::save_test_result($id . '/composite.xml', $result_file->get_xml(), true);854 echo PHP_EOL . 'Result File Saved As: ' . $id . PHP_EOL . PHP_EOL;855 }856 else857 echo PHP_EOL . 'No Phoromatic result found.' . PHP_EOL;858 }859 private static function run_client_update_script($update_script)860 {861 static $last_update_script_check_time = 0;862 // Don't keep checking it so check no more than every 20 minutes863 if($last_update_script_check_time < (time() - 1200) && !empty($update_script))864 {865 $last_update_script_check_time = time();866 $update_file = pts_client::create_temporary_file();867 $update_script = str_replace("\r", PHP_EOL, $update_script);868 file_put_contents($update_file, $update_script);869 phoromatic::update_system_status('Running Phoronix Test Suite Update Script');870 $env_vars = array();871 pts_client::shell_exec('bash ' . $update_file . ' 2>&1', $env_vars);872 }873 }874 private static function set_user_context($context_script, $trigger, $schedule_id, $process)875 {876 if(!empty($context_script))877 {878 $context_file = pts_client::create_temporary_file();879 file_put_contents($context_file, $context_script);880 chmod($context_file, 0755);881 pts_file_io::mkdir(pts_module::save_dir());882 $storage_path = pts_module::save_dir() . 'memory.pt2so';883 $storage_object = pts_storage_object::recover_from_file($storage_path);884 $notes_log_file = pts_module::save_dir() . sha1($trigger . $schedule_id . $process);885 // We check to see if the context was already set but the system rebooted or something in that script886 if($storage_object == false)887 {888 $storage_object = new pts_storage_object(true, true);889 }890 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)891 {892 // If the script already ran once for this trigger, don't run it again893 self::check_user_context_log($trigger, $schedule_id, $process, $notes_log_file, null);894 return false;895 }896 $storage_object->add_object('last_set_context_trigger', $trigger);897 $storage_object->add_object('last_set_context_schedule', $schedule_id);898 $storage_object->add_object('last_set_context_process', $process);899 $storage_object->save_to_file($storage_path);900 phoromatic::update_system_status('Setting context for: ' . $schedule_id . ' - ' . $trigger . ' - ' . $process);901 // Run the set context script902 $env_vars['PHOROMATIC_TRIGGER'] = $trigger;903 $env_vars['PHOROMATIC_SCHEDULE_ID'] = $schedule_id;904 $env_vars['PHOROMATIC_SCHEDULE_PROCESS'] = $process;905 $env_vars['PHOROMATIC_LOG_FILE'] = $notes_log_file;906 $log_output = pts_client::shell_exec('./' . $context_script . ' ' . $trigger . ' 2>&1', $env_vars);907 self::check_user_context_log($trigger, $schedule_id, $process, $notes_log_file, $log_output);908 // Just simply return true for now, perhaps check exit code status and do something909 return true;910 }911 return false;912 }913 private static function check_user_context_log($trigger, $schedule_id, $process, $log_file, $log_output)914 {915 if(is_file($log_file) && ($lf_conts = pts_file_io::file_get_contents($log_file)) != null)916 {917 $context_log = $lf_conts;918 unlink($log_file);919 }920 else921 {922 $context_log = trim($log_output);923 }924 if($context_log != null)925 {926 $server_response = phoromatic::upload_to_remote_server(array(927 'r' => 'user_context_log',928 'sched' => $schedule_id,929 'ts' => $trigger,930 'i' => $process,931 'o' => $context_log,932 ));933 }934 }935 public static function __pre_test_install($test_identifier)936 {937 /* if(self::$has_run_server_setup_func == false)938 {939 self::setup_server_addressing();940 }941 */942 // XXX finish wiring in the above code to various parts for making auto-reporting from clients943 if(!self::$is_running_as_phoromatic_node)944 {945 return false;946 }947 static $last_update_time = 0;948 if(time() > ($last_update_time + 30))949 {950 phoromatic::update_system_status('Installing: ' . $test_identifier);951 $last_update_time = time();952 }953 }954 public static function __pre_test_run($pts_test_result)955 {956 if(!self::$is_running_as_phoromatic_node)957 {958 return false;959 }960 if(self::$in_stress_mode)961 {962 static $time_in_stress_run = 0;963 $msg = 'Stress-Run Testing';964 if(($time_in_stress_run + (60 * 60)) > time())965 {966 // Don't report this same string so often...967 return;968 }969 $time_in_stress_run = time();970 }971 else972 {973 $msg = 'Running: ' . $pts_test_result->test_profile->get_identifier() . ($pts_test_result->get_arguments_description() != null ? ' [' . $pts_test_result->get_arguments_description() . ']' : null);974 }975 phoromatic::update_system_status($msg,976 ceil(self::$test_run_manager->get_estimated_run_time() / 60),977 self::$test_run_manager->get_percent_complete(),978 null,979 ceil($pts_test_result->test_profile->get_estimated_run_time() / 60));980 }981 public static function __event_results_saved($test_run_manager)982 {983 /*if(pts_module::read_variable('AUTO_UPLOAD_RESULTS_TO_PHOROMATIC') && pts_module::is_module_setup())984 {985 phoromatic::upload_unscheduled_test_results($test_run_manager->get_file_name());986 }*/987 }988 public static function __event_run_error($error_obj)989 {990 list($test_run_manager, $test_run_request, $error_msg) = $error_obj;991 if(stripos('Download Failed', $error_msg) !== false || stripos('check-sum of the downloaded file failed', $error_msg) !== false || stripos('attempting', $error_msg) !== false)992 return false;993 $server_response = phoromatic::upload_to_remote_server(array(994 'r' => 'error_report',995 'sched' => self::$p_schedule_id,996 'ts' => self::$p_trigger_id,997 'err' => $error_msg,998 'ti' => $test_run_request->test_profile->get_identifier(),999 'o' => $test_run_request->get_arguments_description()1000 ));1001 //pts_client::$pts_logger && pts_client::$pts_logger->log('TEMP DEBUG MESSAGE: ' . $server_response);1002 }1003}1004?>...
phoromatic_functions.php
Source:phoromatic_functions.php
...15 You should have received a copy of the GNU General Public License16 along with this program. If not, see <http://www.gnu.org/licenses/>.17*/18define('PAGE_LOAD_START_TIME', microtime(true));19function phoromatic_annotate_entry($type, $id, $secondary_id)20{21 $annotate_hash = sha1($id . $secondary_id);22 if(isset($_GET['da_' . $annotate_hash]))23 {24 $user_name = isset($_SESSION['UserName']) ? $_SESSION['UserName'] : null;25 $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_annotations WHERE Type = :type AND ID = :id AND SecondaryID = :secondary_id AND AnnotatedBy = :user_name AND AccountID = :account_id AND AnnotatedTime = :annotated_time');26 $stmt->bindValue(':account_id', (isset($_SESSION['AccountID']) ? $_SESSION['AccountID'] : null));27 $stmt->bindValue(':type', $type);28 $stmt->bindValue(':id', $id);29 $stmt->bindValue(':secondary_id', $secondary_id);30 $stmt->bindValue(':user_name', $user_name);31 $stmt->bindValue(':annotated_time', $_GET['da_' . $annotate_hash]);32 $result = $stmt->execute();33 }34 if(isset($_POST['add_annotation_' . $annotate_hash]) && !empty($_POST['add_annotation_' . $annotate_hash]))35 {36 $annotation = $_POST['add_annotation_' . $annotate_hash];37 $user_name = isset($_SESSION['UserName']) ? $_SESSION['UserName'] : null;38 $annotation = str_replace("\n", '<br />', $annotation);39 $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_annotations (AccountID, Type, ID, SecondaryID, AnnotatedTime, AnnotatedBy, Annotation) VALUES (:account_id, :type, :id, :secondary_id, :annotated_time, :user_name, :annotation)');40 $stmt->bindValue(':account_id', (isset($_SESSION['AccountID']) ? $_SESSION['AccountID'] : null));41 $stmt->bindValue(':type', $type);42 $stmt->bindValue(':id', $id);43 $stmt->bindValue(':secondary_id', $secondary_id);44 $stmt->bindValue(':annotated_time', phoromatic_server::current_time());45 $stmt->bindValue(':user_name', $user_name);46 $stmt->bindValue(':annotation', $annotation);47 $result = $stmt->execute();48 }49 // XXX: AccountID = :account_id AND50 $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_annotations WHERE Type = :type AND ID = :id AND SecondaryID = :secondary_id ORDER BY AnnotatedTime ASC');51 $stmt->bindValue(':account_id', (isset($_SESSION['AccountID']) ? $_SESSION['AccountID'] : null));52 $stmt->bindValue(':type', $type);53 $stmt->bindValue(':id', $id);54 $stmt->bindValue(':secondary_id', $secondary_id);55 $result = $stmt->execute();56 $row = $result->fetchArray();57 $output = null;58 if($row)59 {60 do61 {62 $annotation = $row['Annotation'];63 $annotation = str_replace("\n", 'XXXX', $annotation);64 $annotation = str_replace("\t", ' ', $annotation);65 $annotation = str_replace(' ', ' ', $annotation);66 $output .= '<p>' . $annotation . '<br /><em>Annotation By <strong>' . ($row['AnnotatedBy'] != null ? $row['AnnotatedBy'] : 'Unknown') . '</strong> at <strong>' . phoromatic_user_friendly_timedate($row['AnnotatedTime']) . '</strong>.</em>';67 if(isset($_SESSION['UserName']) && !empty($_SESSION['UserName']) && $_SESSION['UserName'] == $row['AnnotatedBy'])68 {69 $output .= ' <a href="' . $_SERVER['REQUEST_URI'] . '/&da_' . $annotate_hash . '=' . $row['AnnotatedTime'] . '">Delete Annotation</a>';70 }71 $output .= '</p>';72 }73 while($row = $result->fetchArray());74 }75 $output .= '<p id="annotation_link_' . $annotate_hash . '"><a onclick="javascript:toggle_annotate_area(\'' . $annotate_hash . '\');" style="font-size: 80%;">Add Annotation</a></p>';76 $output .= '<form method="post" action="' . $_SERVER['REQUEST_URI'] . '"><p style="display: none;" id="annotation_area_' . $annotate_hash . '"><textarea name="add_annotation_' . $annotate_hash . '" cols="50" rows="4"></textarea><br /><input name="submit" value="Add Annotation" type="submit" /</p></form>';77 return $output;78}79function phoromatic_init_web_page_setup()80{81 if(session_save_path() == null)82 {83 // This is needed since on at least EL6 by default there is no session_save_path set84 if(is_writable('/var/lib/php') && is_dir('/var/lib/php'))85 {86 session_save_path('/var/lib/php');87 }88 else if(is_writable('/var/lib/php5') && is_dir('/var/lib/php5'))89 {90 session_save_path('/var/lib/php5');91 }92 else93 {94 session_save_path('/tmp');95 }96 }97 define('PHOROMATIC_SERVER', true);98 if(PTS_IS_DEV_BUILD)99 {100 error_reporting(E_ALL);101 }102 session_start();103 define('PTS_MODE', 'WEB_CLIENT');104 define('PTS_AUTO_LOAD_OBJECTS', true);105 define('PHOROMATIC_USER_IS_VIEWER', !isset($_SESSION['AdminLevel']) || $_SESSION['AdminLevel'] >= 10 || $_SESSION['AdminLevel'] < 1 ? true : false);106 include('../../pts-core.php');107 pts_core::init();108}109function phoromatic_user_friendly_timedate($time)110{111 return phoromatic_server::user_friendly_timedate($time);112}113function phoromatic_compute_estimated_time_remaining_string($estimated_minutes, $last_comm, $append = 'Remaining')114{115 $remaining = phoromatic_compute_estimated_time_remaining($estimated_minutes, $last_comm);116 return $remaining > 0 ? '~' . pts_strings::plural_handler($remaining, 'Minute') . ' ' . $append : null;117}118function phoromatic_compute_estimated_time_remaining($estimated_minutes, $last_comm)119{120 if($estimated_minutes > 0)121 {122 $estimated_completion = strtotime($last_comm) + ($estimated_minutes * 60);123 if(time() < $estimated_completion)124 {125 return ceil(($estimated_completion - time()) / 60);126 }127 }128 return 0;129}130function phoromatic_webui_header($left_items, $right = null)131{132 $ret = PHP_EOL . '<div id="pts_phoromatic_top_header">133 <ul>134 <li><a href="?"><img style="vertical-align: middle;" class="img_logo_pg" src="images/phoromatic_logo.png" /></a>';135 if(isset($_SESSION['AdminLevel']) &&$_SESSION['AdminLevel'] > 0 && isset($_SESSION['AccountID']) && !empty($_SESSION['AccountID']))136 {137 $ret .= '<ul id="pts_phoromatic_info">';138 $ret .= '<li><a class="ph_date" href="#">' . date('H:i T - j F') . '</a></li>';139 $group_name = phoromatic_account_id_to_group_name($_SESSION['AccountID']);140 if($group_name != null)141 {142 $ret .= '<li><a href="#">' . $group_name . '</a></li>';143 }144 $ret .= '</ul>';145 }146 $ret .= '</li>';147 //$ret .= '<ul>';148 foreach($left_items as $i => $item)149 {150 if(is_array($item))151 {152 $ret .= '<li>' . $i;153 if(!empty($item))154 {155 $ret .= '<ul>';156 foreach($item as $sub_item)157 {158 $ret .= '<li>' . $sub_item . '</li>';159 }160 $ret .= '</ul>';161 }162 $ret .= '</li>' . PHP_EOL;163 }164 else165 {166 $ret .= '<li>' . $item . '</li>' . PHP_EOL;167 }168 }169 $ret .= '<li><div id="phoromatic_result_selected_info_box"></div> <a href="#" onclick="javascript:phoromatic_generate_comparison(\'?result/\');"><div id="phoromatic_result_compare_info_box">Compare</div></a> <a href="#" onclick="javascript:phoromatic_delete_results(\'?results/delete/\'); return false;"><div id="phoromatic_result_delete_box">Delete</div></a></li>';170 $ret .= '</ul>';171 if($right != null)172 {173 $ret .= '<div id="pts_phoromatic_top_header_right">' . $right .'</div>';174 }175 $ret .=' </div>';176 return $ret;177}178function phoromatic_get_posted_var($name, $default_value = null)179{180 return isset($_POST[$name]) ? $_POST[$name] : null;181}182function phoromatic_webui_main($main, $right = null)183{184 return '<div id="pts_phoromatic_main">' . ($right != null ? '<div id="pts_phoromatic_menu_right">' . $right . '</div>' : null) . '<div id="pts_phoromatic_main_area">' . $main . '</div><div style="clear: both;"></div></div>';185}186function phoromatic_webui_box(&$box)187{188 return '<div id="pts_phoromatic_main_box"><div id="pts_phoromatic_main_box_inside">' . $box . '</div></div>';189}190function phoromatic_results_for_schedule($schedule_id, $limit_results = false)191{192 switch($limit_results)193 {194 case 'TODAY':195 $stmt = phoromatic_server::$db->prepare('SELECT COUNT(UploadID) As UploadCount FROM phoromatic_results WHERE AccountID = :account_id AND ScheduleID = :schedule_id AND UploadTime LIKE :today_date');196 $stmt->bindValue(':today_date', date('Y-m-d') . '%');197 break;198 default:199 $stmt = phoromatic_server::$db->prepare('SELECT COUNT(UploadID) As UploadCount FROM phoromatic_results WHERE AccountID = :account_id AND ScheduleID = :schedule_id');200 break;201 }202 $stmt->bindValue(':account_id', $_SESSION['AccountID']);203 $stmt->bindValue(':schedule_id', $schedule_id);204 $test_result_result = $stmt->execute();205 $row = $test_result_result->fetchArray();206 return empty($row) ? 0 : $row['UploadCount'];207}208function phoromatic_schedule_activeon_string($active_on, $active_at = null)209{210 if(!empty($active_on))211 {212 $active_days = explode(',', $active_on);213 $week = array('M', 'T', 'W', 'TH', 'F', 'S', 'SU');214 foreach($active_days as $i => &$day)215 {216 if(!isset($week[$day]))217 {218 unset($active_days[$i]);219 }220 else221 {222 $day = $week[$day];223 }224 }225 return implode(' ', $active_days) . (!empty($active_at) ? ' @ ' . str_replace('.', ':', $active_at) : null );226 }227}228function phoromatic_webui_footer()229{230 return '<div id="pts_phoromatic_bottom_footer">231<div style="float: right; padding: 2px 10px; overflow: hidden;"><a href="http://openbenchmarking.org/" style="margin-right: 20px;"><img src="data:image/png;base64,' . base64_encode(file_get_contents('images/ob-white-logo.png')) . '" /></a> <a href="http://www.phoronix-test-suite.com/"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewbox="0 0 76 41" width="76" height="41" preserveAspectRatio="xMinYMin meet">232 <path d="m74 22v9m-5-16v16m-5-28v28m-23-2h12.5c2.485281 0 4.5-2.014719 4.5-4.5s-2.014719-4.5-4.5-4.5h-8c-2.485281 0-4.5-2.014719-4.5-4.5s2.014719-4.5 4.5-4.5h12.5m-21 5h-11m11 13h-2c-4.970563 0-9-4.029437-9-9v-20m-24 40v-20c0-4.970563 4.0294373-9 9-9 4.970563 0 9 4.029437 9 9s-4.029437 9-9 9h-9" stroke="#c8d905" stroke-width="4" fill="none" />233</svg></a></div>234<p style="margin: 6px 15px;"><strong>' . date('H:i T - j F Y') . '</strong>' . (PTS_IS_DEV_BUILD ? ' [' . round(microtime(true) - PAGE_LOAD_START_TIME, 2) . 's Page Load Time]' : null) . '<br />Copyright © 2008 - ' . date('Y') . ' by <a href="http://www.phoronix-media.com/">Phoronix Media</a>. All rights reserved.<br />235All trademarks used are properties of their respective owners.<br />' . pts_core::program_title(true) . ' - Core Version ' . PTS_CORE_VERSION . ' - PHP ' . PHP_VERSION . '</p></div> <script type="text/javascript"> phoromatic_checkbox_toggle_result_comparison(\'\'); </script>';236}237function phoromatic_add_activity_stream_event($activity_event, $activity_event_id, $activity_event_type)238{239 $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_activity_stream (AccountID, ActivityTime, ActivityCreator, ActivityCreatorType, ActivityEvent, ActivityEventID, ActivityEventType) VALUES (:account_id, :activity_time, :activity_creator, :activity_creator_type, :activity_event, :activity_event_id, :activity_event_type)');240 $stmt->bindValue(':account_id', $_SESSION['AccountID']);241 $stmt->bindValue(':activity_time', phoromatic_server::current_time());242 $stmt->bindValue(':activity_creator', $_SESSION['UserName']);243 $stmt->bindValue(':activity_creator_type', 'USER');244 $stmt->bindValue(':activity_event', $activity_event);245 $stmt->bindValue(':activity_event_id', $activity_event_id);246 $stmt->bindValue(':activity_event_type', $activity_event_type);247 return $stmt->execute();248}249function phoromatic_tracker_page_relevant()250{251 $stmt = phoromatic_server::$db->prepare('SELECT RunTargetSystems, RunTargetGroups, (SELECT COUNT(*) FROM phoromatic_results WHERE ScheduleID = phoromatic_schedules.ScheduleID) AS UploadedResultCount FROM phoromatic_schedules WHERE AccountID = :account_id AND State >= 1 ORDER BY Title ASC');252 $stmt->bindValue(':account_id', $_SESSION['AccountID']);253 $result = $stmt->execute();254 $row = $result->fetchArray();255 if($row)256 {257 do258 {259 if($row['UploadedResultCount'] > (($row['RunTargetSystems'] + $row['RunTargetGroups'] + 1) * 7))260 {261 return true;262 }263 }264 while($row = $result->fetchArray());265 }266 return false;267}268function phoromatic_webui_header_logged_in()269{270 $html_links = array();271 if($_SESSION['AdminLevel'] == -40)272 {273 $pages = array('Admin', 'Admin_Config', 'Admin_Data', 'Logout');274 }275 else if($_SESSION['AdminLevel'] > 0)276 {277 $sub_main_menu = array();278 $sub_systems_menu = array();279 $sub_testing_menu = array();280 $sub_results_menu = array();281 if(phoromatic_account_system_count() > 0)282 {283 $sub_systems_menu[] = 'Dashboard';284 $sub_systems_menu[] = 'Maintenance Table';285 $sub_systems_menu[] = 'Component Table';286 }287 $sub_main_menu[] = '<a href="?tests">Test Profiles</a>';288 if(isset($_SESSION['AdminLevel']) && $_SESSION['AdminLevel'] < 4)289 {290 $sub_main_menu[] = 'Users';291 }292 array_push($sub_main_menu, 'Settings', '<a href="?account_activity">Account Activity</a>', 'Logout');293 $sub_testing_menu[] = '<a href="?schedules">Test Schedules</a>';294 if(!PHOROMATIC_USER_IS_VIEWER)295 {296 array_push($sub_testing_menu, '<a href="?sched">Create A Schedule</a>', '<a href="?benchmark">Run A Benchmark</a>');297 }298 if(phoromatic_tracker_page_relevant())299 {300 $sub_results_menu[] = 'Tracker';301 }302 $sub_results_menu[] = '<a href="/rss.php?user=' . $_SESSION['UserID'] . '&v=' . sha1($_SESSION['CreatedOn']) . '">Results Feed <img src="images/rss.png" /></a>';303 $pages = array('Main' => $sub_main_menu, 'Systems' => $sub_systems_menu, '<a href="/?testing">Testing</a>' => $sub_testing_menu, 'Results' => $sub_results_menu, '<form action="/?search" method="post" id="search"><input type="search" name="search" id="seach_input" size="16" /> <input type="submit" name="sa" value="Search" /></form>');304 }305 foreach($pages as $title => $page)306 {307 if(is_array($page) || empty($page))308 {309 $menu_row = array();310 foreach($page as $sub_page)311 {312 $menu_row[] = menu_item_to_html($sub_page);313 }314 $html_links[menu_item_to_html($title)] = $menu_row;315 }316 else317 {318 $html_links[] = menu_item_to_html($page);319 }320 }321 return phoromatic_webui_header($html_links, null);322}323function menu_item_to_html($page)324{325 if(strpos($page, '</') !== false)326 return $page;327 $page_link = strtolower($page);328 if(($x = strpos($page_link, '<br />')) !== false)329 {330 $page_link = trim(substr($page_link, $x + 6));331 }332 $page_link = str_replace(' ', '_', $page_link);333 if(strtolower($page) == PAGE_REQUEST)334 {335 return '<a href="?' . $page_link . '"><u>' . str_replace('_', ' ', $page) . '</u></a>';336 }337 else338 {339 return '<a href="?' . $page_link . '">' . str_replace('_', ' ', $page) . '</a>';340 }341}342function phoromatic_webui_right_panel_logged_in($add = null)343{344 $right = null;345 if($_SESSION['AdminLevel'] == -40)346 {347 $right .= '<h3>Phoromatic Server</h3><hr /><p><strong>' . date('H:i T - j F Y') . '</p>';348 }349 else if($_SESSION['AdminLevel'] > 0)350 {351 //$right .= '<a href="#" onclick="javascript:phoromatic_generate_comparison(\'?result/\');"><div id="phoromatic_result_compare_info_box"></div></a> <a href="#" onclick="javascript:phoromatic_delete_results(\'?results/delete/\'); return false;"><div id="phoromatic_result_delete_box">Delete Selected Results</div></a>';352 if(($bad_systems = phoromatic_server::systems_appearing_down()) != false)353 {354 $right .= '<ul><li><span class="alert">Systems Needing Attention</span></li>';355 foreach($bad_systems as $system)356 {357 $right .= '<li><a href="?systems/' . $system . '">' . phoromatic_server::system_id_to_name($system) . '</a></li>';358 }359 $right .= '</ul><hr />';360 }361 $right .= $add;362 if($add == null)363 {364 $recently_active_systems = phoromatic_server::recently_active_systems($_SESSION['AccountID']);365 if(!empty($recently_active_systems))366 {367 $right .= '<ul><li>Recently Active Systems</li>';368 foreach($recently_active_systems as &$row)369 {370 $right .= '<li><a href="?systems/' . $row['SystemID'] . '">' . $row['Title'] . '</a></li>';371 }372 $right .= '</ul><hr />';373 }374 $right .= '375 <ul>376 <li>Today\'s Scheduled Events</li>';377 $stmt = phoromatic_server::$db->prepare('SELECT Title, ScheduleID, RunAt FROM phoromatic_schedules WHERE AccountID = :account_id AND State >= 1 AND ActiveOn LIKE :active_on ORDER BY RunAt,Title ASC');378 $stmt->bindValue(':account_id', $_SESSION['AccountID']);379 $stmt->bindValue(':active_on', '%' . (date('N') - 1) . '%');380 $result = $stmt->execute();381 $row = $result->fetchArray();382 if($row == false)383 {384 $right .= '</ul><p style="text-align: left; margin: 6px 10px;">No Events Found</p>';385 }386 else387 {388 do389 {390 $right .= '<li>' . $row['RunAt'] . ' <a href="?schedules/' . $row['ScheduleID'] . '">' . $row['Title'] . '</a></li>';391 }392 while($row = $result->fetchArray());393 $right .= '</ul>';394 }395 }396 $system_count = phoromatic_account_system_count();397 $schedule_count = phoromatic_account_schedule_count();398 $stmt = phoromatic_server::$db->prepare('SELECT COUNT(UploadID) AS ResultCount FROM phoromatic_results WHERE AccountID = :account_id');399 $stmt->bindValue(':account_id', $_SESSION['AccountID']);400 $result = $stmt->execute();401 $row = $result->fetchArray();402 $result_count = $row['ResultCount'];403 $stmt = phoromatic_server::$db->prepare('SELECT COUNT(ActivityTime) AS ActivityCount FROM phoromatic_activity_stream WHERE AccountID = :account_id AND ActivityTime LIKE :today_date');404 $stmt->bindValue(':account_id', $_SESSION['AccountID']);405 $stmt->bindValue(':today_date', date('Y-m-d') . '%');406 $result = $stmt->execute();407 $row = $result->fetchArray();408 $activity_count = $row['ActivityCount'];409 $group_name = phoromatic_account_id_to_group_name($_SESSION['AccountID']);410 if($group_name != null)411 {412 $group_name = '<strong>' . $group_name . '</strong><br />';413 }414 $right .= '<hr /><p><strong>' . date('H:i T - j F Y') . '</strong><br />' . $group_name . '<a href="?systems">' . $system_count . ' System' . ($system_count == 1 ? '' : 's') . '</a><br /><a href="?schedules">' . $schedule_count . ' Schedule' . ($schedule_count == 1 ? '' : 's') . '</a><br /><a href="?results">' . $result_count . ' Result' . ($result_count == 1 ? '' : 's') . '</a>';415$right .= ' <a href="/rss.php?user=' . $_SESSION['UserID'] . '&v=' . sha1($_SESSION['CreatedOn']) . '"><img src="images/rss.png" /></a>';416 $right .= '<br /><a href="?account_activity">' . $activity_count . ' Activity Events Today</a></p>';417 }418 return $right;419}420function phoromatic_account_schedule_count()421{422 static $schedule_count = 0;423 if($schedule_count == 0)424 {425 $stmt = phoromatic_server::$db->prepare('SELECT COUNT(Title) AS ScheduleCount FROM phoromatic_schedules WHERE AccountID = :account_id AND State >= 1');426 $stmt->bindValue(':account_id', $_SESSION['AccountID']);427 $result = $stmt->execute();428 $row = $result->fetchArray();429 $schedule_count = $row['ScheduleCount'];430 }431 return $schedule_count;432}433function phoromatic_account_system_count()434{435 static $sys_count = 0;436 if($sys_count == 0)437 {438 $stmt = phoromatic_server::$db->prepare('SELECT COUNT(Title) AS SystemCount FROM phoromatic_systems WHERE AccountID = :account_id AND State >= 0');439 $stmt->bindValue(':account_id', $_SESSION['AccountID']);440 $result = $stmt->execute();441 $row = $result->fetchArray();442 $sys_count = $row['SystemCount'];443 }444 return $sys_count;445}446function phoromatic_web_socket_server_ip()447{448 $server_ip = $_SERVER['HTTP_HOST'];449 if(($x = strpos($server_ip, ':')) !== false)450 {451 $server_ip = substr($server_ip, 0, $x);452 }453 if($server_ip == 'localhost' || $server_ip == '0.0.0.0')454 {455 $local_ip = pts_network::get_local_ip();456 if($local_ip)457 {458 $server_ip = $local_ip;459 }460 }461 // getenv('PTS_WEBSOCKET_PORT')462 return $server_ip . ':' . $_SERVER['SERVER_PORT'];463}464function phoromatic_web_socket_server_addr()465{466 // getenv('PTS_WEBSOCKET_PORT')467 return phoromatic_web_socket_server_ip() . '/' . $_SESSION['AccountID'];468}469function phoromatic_error_page($title, $description)470{471 echo phoromatic_webui_header(array(''), '');472 $box = '<h1>' . $title . '</h1>473 <h2>' . $description . '</h2>474 <p>To fix this error, try <a onclick="javascript:window.history.back();">returning to the previous page</a>. Still having problems? Consider <a href="https://github.com/phoronix-test-suite/phoronix-test-suite/issues?state=open">opening a GitHub issue report</a>; commercial support customers should contact Phoronix Media.</p><hr /><hr />';475 echo phoromatic_webui_box($box);476 echo phoromatic_webui_footer();477}478function phoromatic_systems_needing_attention()479{480 $main = null;481 $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID, State, LastIP, LocalIP, LastCommunication FROM phoromatic_systems WHERE AccountID = :account_id AND State = 0 ORDER BY LastCommunication DESC');482 $stmt->bindValue(':account_id', $_SESSION['AccountID']);483 $result = $stmt->execute();484 if($row = $result->fetchArray())485 {486 $main .= '<div class="pts_phoromatic_info_box_area"><div style="float: left; width: 100%;"><ul><li><h1>Systems Needing Attention</h1></li><li class="light" style="font-weight: normal;">The following systems have attempted to sync with this Phoromatic account but have not been validated. When clicking on them you are able to approve or disable them from your account along with editing the system information.</li>';487 do488 {489 $ip = $row['LocalIP'];490 if($row['LastIP'] != $row['LocalIP'])491 {492 $ip .= ' / ' . $row['LastIP'];493 }494 $main .= '<a href="?systems/' . $row['SystemID'] . '/edit"><li>' . $row['Title'] . '<br /><em><strong>IP:</strong> ' . $ip . ' <strong>Last Communication:</strong> ' . $row['LastCommunication'] . '</em></li></a>';495 }496 while($row = $result->fetchArray());497 $main .= '</ul></div></div>';498 }499 return $main;500}501function phoromatic_system_id_to_name($system_id, $aid = false)502{503 return phoromatic_server::system_id_to_name($system_id, $aid);504}505function phoromatic_oldest_result_for_schedule($schedule_id)506{507 static $old_time;508 if(!isset($old_time[$schedule_id]))509 {510 $stmt = phoromatic_server::$db->prepare('SELECT UploadTime FROM phoromatic_results WHERE AccountID = :account_id AND ScheduleID = :schedule_id ORDER BY UploadTime ASC LIMIT 1');511 $stmt->bindValue(':account_id', $_SESSION['AccountID']);512 $stmt->bindValue(':schedule_id', $schedule_id);513 $result = $stmt->execute();514 $row = $result->fetchArray();515 $old_time[$schedule_id] = $row['UploadTime'];516 }517 return $old_time[$schedule_id];518}519function phoromatic_schedule_id_to_name($schedule_id)520{521 static $schedule_names;522 if(!isset($schedule_names[$schedule_id]))523 {524 $stmt = phoromatic_server::$db->prepare('SELECT Title FROM phoromatic_schedules WHERE AccountID = :account_id AND ScheduleID = :schedule_id');525 $stmt->bindValue(':account_id', $_SESSION['AccountID']);526 $stmt->bindValue(':schedule_id', $schedule_id);527 $result = $stmt->execute();528 $row = $result->fetchArray();529 $schedule_names[$schedule_id] = $row['Title'];530 }531 return $schedule_names[$schedule_id];532}533function phoromatic_account_id_to_group_name($account_id)534{535 // XXX deprecated536 return phoromatic_server::account_id_to_group_name($account_id);537}538function create_new_phoromatic_account($register_username, $register_password, $register_password_confirm, $register_email, $seed_accountid = null)539{540 // REGISTER NEW USER541 if(strlen($register_username) < 4 || strpos($register_username, ' ') !== false)542 {543 phoromatic_error_page('Oops!', 'Please go back and ensure the supplied username is at least four characters long and contains no spaces.');544 return false;545 }546 if(in_array(strtolower($register_username), array('admin', 'administrator', 'rootadmin')))547 {548 phoromatic_error_page('Oops!', $register_username . ' is a reserved and common username that may be used for other purposes, please make a different selection.');549 return false;550 }551 if(strlen($register_password) < 6)552 {553 phoromatic_error_page('Oops!', 'Please go back and ensure the supplied password is at least six characters long.');554 return false;555 }556 if($register_password != $register_password_confirm)557 {558 phoromatic_error_page('Oops!', 'Please go back and ensure the supplied password matches the password confirmation.');559 return false;560 }561 if($register_email == null || filter_var($register_email, FILTER_VALIDATE_EMAIL) == false)562 {563 phoromatic_error_page('Oops!', 'Please enter a valid email address.');564 return false;565 }566 $valid_user_name_chars = '1234567890-_.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';567 for($i = 0; $i < count($register_username); $i++)568 {569 if(strpos($valid_user_name_chars, substr($register_username, $i, 1)) === false)570 {571 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.');572 return false;573 }574 }575 $matching_users = phoromatic_server::$db->querySingle('SELECT UserName FROM phoromatic_users WHERE UserName = \'' . SQLite3::escapeString($register_username) . '\'');576 if(!empty($matching_users))577 {578 phoromatic_error_page('Oops!', 'The user-name is already taken.');579 return false;580 }581 if(phoromatic_server::read_setting('add_new_users_to_account') != null)582 {583 $account_id = phoromatic_server::read_setting('add_new_users_to_account');584 $is_new_account = false;585 }586 else587 {588 $id_tries = 0;589 do590 {591 if($id_tries == 0 && $seed_accountid != null && isset($seed_accountid[5]))592 {593 $account_id = strtoupper(substr($seed_accountid, 0, 6));594 }595 else596 {597 $account_id = pts_strings::random_characters(6, true);598 }599 $matching_accounts = phoromatic_server::$db->querySingle('SELECT AccountID FROM phoromatic_accounts WHERE AccountID = \'' . $account_id . '\'');600 $id_tries++;601 }602 while(!empty($matching_accounts));603 $is_new_account = true;604 }605 $user_id = pts_strings::random_characters(4, true);606 if($is_new_account)607 {608 pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' created a new account: ' . $user_id . ' - ' . $account_id);609 $account_salt = pts_strings::random_characters(12, true);610 $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_accounts (AccountID, ValidateID, CreatedOn, Salt) VALUES (:account_id, :validate_id, :current_time, :salt)');611 $stmt->bindValue(':account_id', $account_id);612 $stmt->bindValue(':validate_id', pts_strings::random_characters(4, true));613 $stmt->bindValue(':salt', $account_salt);614 $stmt->bindValue(':current_time', phoromatic_server::current_time());615 $result = $stmt->execute();616 $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_account_settings (AccountID) VALUES (:account_id)');617 $stmt->bindValue(':account_id', $account_id);618 $result = $stmt->execute();619 $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_user_settings (UserID, AccountID) VALUES (:user_id, :account_id)');620 $stmt->bindValue(':user_id', $user_id);621 $stmt->bindValue(':account_id', $account_id);622 $result = $stmt->execute();623 }624 else625 {626 pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' being added to an account: ' . $user_id . ' - ' . $account_id);627 $account_salt = phoromatic_server::$db->querySingle('SELECT Salt FROM phoromatic_accounts WHERE AccountID = \'' . $account_id . '\'');628 }629 $salted_password = hash('sha256', $account_salt . $register_password);630 $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)');631 $stmt->bindValue(':user_id', $user_id);632 $stmt->bindValue(':account_id', $account_id);633 $stmt->bindValue(':user_name', $register_username);634 $stmt->bindValue(':email', $register_email);635 $stmt->bindValue(':password', $salted_password);636 $stmt->bindValue(':last_ip', $_SERVER['REMOTE_ADDR']);637 $stmt->bindValue(':current_time', phoromatic_server::current_time());638 $stmt->bindValue(':admin_level', ($is_new_account ? 1 : 10));639 $result = $stmt->execute();640 pts_file_io::mkdir(phoromatic_server::phoromatic_account_path($account_id));641 phoromatic_server::send_email($register_email, 'Phoromatic Account Registration', (($e = phoromatic_server::read_setting('admin_support_email')) != null ? $e : 'no-reply@phoromatic.com'), '<p><strong>' . $register_username . '</strong>:</p><p>Your Phoromatic account has been created and is now active.</p>');642 return true;643}644?>...
start.php
Source:start.php
...17*/18$json = array();19if(SYSTEM_IN_MAINTENANCE_MODE)20{21 $json['phoromatic']['task'] = 'maintenance';22 //$json['phoromatic']['response'] = '[' . date('H:i:s') . '] System in maintenance mode.';23 echo json_encode($json);24 return;25}26$day_of_week_int = date('N') - 1;27$stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_account_settings WHERE AccountID = :account_id');28$stmt->bindValue(':account_id', ACCOUNT_ID);29$result = $stmt->execute();30$phoromatic_account_settings = $result->fetchArray(SQLITE3_ASSOC);31unset($phoromatic_account_settings['AccountID']);32$sys_stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_systems WHERE AccountID = :account_id AND SystemID = :system_id LIMIT 1');33$sys_stmt->bindValue(':account_id', ACCOUNT_ID);34$sys_stmt->bindValue(':system_id', SYSTEM_ID);35$sys_result = $sys_stmt->execute();36$sys_row = $sys_result->fetchArray();37// SEE IF SCHEDULE NEEDS TO RUN38$schedule_row = phoromatic_server::system_check_for_open_schedule_run(ACCOUNT_ID, SYSTEM_ID, 0, $sys_row);39if($schedule_row != false)40{41 $res = phoromatic_generate_test_suite($schedule_row, $json, $phoromatic_account_settings, $sys_row);42 if($res)43 {44 return;45 }46}47// END OF SCHEDULE RUN48// BENCHMARK TICKET49$ticket_row = phoromatic_server::system_check_for_open_benchmark_ticket(ACCOUNT_ID, SYSTEM_ID, $sys_row);50if($ticket_row != false)51{52 pts_logger::add_to_log(SYSTEM_ID . ' - needs to benchmark ticket for ' . $ticket_row['Title']);53 $res = phoromatic_generate_benchmark_ticket($ticket_row, $json, $phoromatic_account_settings, $sys_row);54 if($res)55 {56 return;57 }58}59// END OF BENCHMARK TICKET60if($CLIENT_CORE_VERSION >= 5511 && date('i') == 0 && $phoromatic_account_settings['PreSeedTestInstalls'] == 1 && phoromatic_pre_seed_tests_to_install($json, $phoromatic_account_settings, $sys_row))61{62 // XXX TODO: with WS backend won't need to limit to on the hour attempt63 return;64}65// Provide client with update script to ensure client is updated if it's doing nothing besides idling/shutting down66$update_script_path = phoromatic_server::phoromatic_account_path(ACCOUNT_ID) . 'client-update-script.sh';67if(is_file($update_script_path))68{69 $json['phoromatic']['client_update_script'] = file_get_contents($update_script_path);70}71if($phoromatic_account_settings['PowerOffWhenDone'] == 1 && $sys_row['BlockPowerOffs'] != 1)72{73 $json['phoromatic']['response'] = '[' . date('H:i:s') . '] Shutting system down per user settings as no more tests scheduled for today...';74 $json['phoromatic']['task'] = 'shutdown';75 echo json_encode($json);76 return;77}78$json['phoromatic']['task'] = 'idle';79$json['phoromatic']['response'] = '[' . date('H:i:s') . '] Idling, waiting for task assignment...';80echo json_encode($json);81return;82function phoromatic_generate_test_suite(&$test_schedule, &$json, $phoromatic_account_settings, &$sys_row)83{84 if(isset($test_schedule['Trigger']))85 {86 $trigger_id = $test_schedule['Trigger'];87 }88 else89 {90 $trigger_id = date('Y-m-d');91 }92 $new_suite = new pts_test_suite();93 $new_suite->set_title($test_schedule['Title']);94 $new_suite->set_version('1.0.0');95 $new_suite->set_maintainer($test_schedule['LastModifiedBy']);96 $new_suite->set_suite_type('System');97 $new_suite->set_description($test_schedule['Description']);98 $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_schedules_tests WHERE AccountID = :account_id AND ScheduleID = :schedule_id');99 $stmt->bindValue(':account_id', ACCOUNT_ID);100 $stmt->bindValue(':schedule_id', $test_schedule['ScheduleID']);101 $result = $stmt->execute();102 $test_count = 0;103 while($row = $result->fetchArray())104 {105 $new_suite->add_to_suite($row['TestProfile'], $row['TestArguments'], $row['TestDescription']);106 $test_count++;107 }108 if($test_count == 0)109 {110 return false;111 }112 $json['phoromatic']['task'] = 'benchmark';113 $json['phoromatic']['save_identifier'] = $test_schedule['Title'] . ' - ' . $trigger_id;114 $json['phoromatic']['trigger_id'] = $trigger_id;115 $json['phoromatic']['schedule_id'] = $test_schedule['ScheduleID'];116 $json['phoromatic']['test_suite'] = $new_suite->get_xml();117 $json['phoromatic']['pre_set_sys_env_vars'] = $sys_row['SystemVariables'];118 $contexts = array('SetContextPreInstall' => 'pre_install_set_context', 'SetContextPostInstall' => 'post_install_set_context', 'SetContextPreRun' => 'pre_run_set_context', 'SetContextPostRun' => 'post_run_set_context');119 foreach($contexts as $context => $v)120 {121 $json['phoromatic'][$v] = null;122 if(isset($test_schedule[$context]) && !empty($test_schedule[$context]) && is_file(phoromatic_server::phoromatic_account_path(ACCOUNT_ID) . 'context_' . $test_schedule[$context]))123 {124 $json['phoromatic'][$v] = file_get_contents(phoromatic_server::phoromatic_account_path(ACCOUNT_ID) . 'context_' . $test_schedule[$context]);125 }126 }127 $json['phoromatic']['settings'] = $phoromatic_account_settings;128 echo json_encode($json);129 return true;130}131function phoromatic_generate_benchmark_ticket(&$ticket_row, &$json, $phoromatic_account_settings, &$sys_row)132{133 $test_suite = phoromatic_server::phoromatic_account_suite_path(ACCOUNT_ID, $ticket_row['SuiteToRun']) . 'suite-definition.xml';134 if(!is_file($test_suite))135 {136 return false;137 }138 $json['phoromatic']['task'] = 'benchmark';139 $json['phoromatic']['save_identifier'] = $ticket_row['Title'];140 $json['phoromatic']['test_description'] = $ticket_row['Description'];141 $json['phoromatic']['trigger_id'] = $ticket_row['ResultIdentifier'];142 $json['phoromatic']['benchmark_ticket_id'] = $ticket_row['TicketID'];143 $json['phoromatic']['result_identifier'] = $ticket_row['ResultIdentifier'];144 $json['phoromatic']['test_suite'] = file_get_contents($test_suite);145 $json['phoromatic']['settings'] = $phoromatic_account_settings;146 $json['phoromatic']['environment_variables'] = $ticket_row['EnvironmentVariables'];147 $json['phoromatic']['pre_set_sys_env_vars'] = $sys_row['SystemVariables'];148 echo json_encode($json);149 return true;150}151function phoromatic_pre_seed_tests_to_install(&$json, $phoromatic_account_settings, &$sys_row)152{153 $new_suite = new pts_test_suite();154 $new_suite->set_title('Pre-Seed');155 $new_suite->set_version('1.0.0');156 $new_suite->set_maintainer('Phoromatic');157 $new_suite->set_suite_type('System');158 $new_suite->set_description('Pre-seeding commonly used tests to host.');159 $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_schedules_tests WHERE AccountID = :account_id');160 $stmt->bindValue(':account_id', ACCOUNT_ID);161 $result = $stmt->execute();162 $test_count = 0;163 while($row = $result->fetchArray())164 {165 $new_suite->add_to_suite($row['TestProfile']);166 $test_count++;167 }168 if($test_count == 0)169 {170 return false;171 }172 $json['phoromatic']['task'] = 'install';173 $json['phoromatic']['test_suite'] = $new_suite->get_xml();174 $json['phoromatic']['settings'] = $phoromatic_account_settings;175 $json['phoromatic']['pre_set_sys_env_vars'] = $sys_row['SystemVariables'];176 echo json_encode($json);177 return true;178}179?>...
phoromatic
Using AI Code Generation
1require_once('pts-core/phoromatic.php');2$phoromatic = new phoromatic();3$phoromatic->loadSystemInfo();4$phoromatic->loadSystemStats();5$phoromatic->loadSystemLogs();6$phoromatic->getSystemInfo();7$phoromatic->getSystemStats();8$phoromatic->getSystemLogs();9require_once('pts-core/phoromatic.php');10$phoromatic = new phoromatic();11$phoromatic->loadSystemInfo();12$phoromatic->loadSystemStats();13$phoromatic->loadSystemLogs();14$phoromatic->getSystemInfo();15$phoromatic->getSystemStats();16$phoromatic->getSystemLogs();17require_once('pts-core/phoromatic.php');18$phoromatic = new phoromatic();19$phoromatic->loadSystemInfo();20$phoromatic->loadSystemStats();21$phoromatic->loadSystemLogs();22$phoromatic->getSystemInfo();23$phoromatic->getSystemStats();24$phoromatic->getSystemLogs();25require_once('pts-core/phoromatic.php');26$phoromatic = new phoromatic();27$phoromatic->loadSystemInfo();28$phoromatic->loadSystemStats();29$phoromatic->loadSystemLogs();30$phoromatic->getSystemInfo();31$phoromatic->getSystemStats();32$phoromatic->getSystemLogs();33require_once('
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!