/** Asynchronous submission */ function do_submit_asynchronous($filehandle, $projectid, $expected_md5 = '') { include 'cdash/config.php'; include 'cdash/version.php'; do { $filename = $CDASH_BACKUP_DIRECTORY . "/" . mt_rand() . ".xml"; $fp = @fopen($filename, 'x'); } while (!$fp); fclose($fp); unset($fp); $outfile = fopen($filename, 'w'); // Save the file in the backup directory while (!feof($filehandle)) { $content = fread($filehandle, 8192); if (fwrite($outfile, $content) === FALSE) { echo "ERROR: Cannot write to file ({$filename})"; add_log("Cannot write to file ({$filename})", "do_submit_asynchronous", LOG_ERR, $projectid); fclose($outfile); unset($outfile); return; } } fclose($outfile); unset($outfile); // Sends the file size to the local parser if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/ctestparser.php")) { require_once "local/ctestparser.php"; $localParser = new LocalParser(); $filesize = filesize($filename); $localParser->SetFileSize($projectid, $filesize); } $md5sum = md5_file($filename); $md5error = false; echo "<cdash version=\"" . $CDASH_VERSION . "\">\n"; if ($expected_md5 == '' || $expected_md5 == $md5sum) { echo " <status>OK</status>\n"; echo " <message></message>\n"; } else { echo " <status>ERROR</status>\n"; echo " <message>Checksum failed for file. Expected {$expected_md5} but got {$md5sum}.</message>\n"; $md5error = true; } echo " <md5>{$md5sum}</md5>\n"; echo "</cdash>\n"; if ($md5error) { add_log("Checksum failure on file: {$filename}", "do_submit_asynchronous", LOG_ERR, $projectid); return; } $bytes = filesize($filename); // Insert the filename in the database $now_utc = gmdate(FMT_DATETIMESTD); pdo_query("INSERT INTO submission (filename,projectid,status,attempts,filesize,filemd5sum,created) " . "VALUES ('" . $filename . "','" . $projectid . "','0','0','{$bytes}','{$md5sum}','{$now_utc}')"); // Get the ID associated with this submission. We may need to reference it // later if this is a CDash@home (client) submission. $submissionid = pdo_insert_id('submission'); // We find the daily updates // If we have php curl we do it asynchronously if (function_exists("curl_init") == TRUE) { $currentURI = get_server_URI(true); $request = $currentURI . "/cdash/dailyupdatescurl.php?projectid=" . $projectid; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 1); if ($CDASH_USE_HTTPS) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); } curl_exec($ch); curl_close($ch); $clientscheduleid = isset($_GET["clientscheduleid"]) ? pdo_real_escape_numeric($_GET["clientscheduleid"]) : 0; if ($clientscheduleid !== 0) { pdo_query("INSERT INTO client_jobschedule2submission (scheduleid,submissionid) " . "VALUES ('{$clientscheduleid}','{$submissionid}')"); } // Save submitter IP in the database in the async case, so we have a valid // IP at Site::Insert time when processing rather than 'localhost's IP: pdo_insert_query("INSERT INTO submission2ip (submissionid, ip) " . "VALUES ('{$submissionid}', '" . $_SERVER['REMOTE_ADDR'] . "')"); // Call process submissions via cURL. trigger_process_submissions($projectid); } else { add_log("Cannot submit asynchronously: php curl_init function does not exist", "do_submit_asynchronous", LOG_ERR, $projectid); } }
/** Asynchronous submission */ function do_submit_asynchronous($filehandle, $projectid, $expected_md5 = '') { include 'config/config.php'; include 'include/version.php'; do { $filename = $CDASH_BACKUP_DIRECTORY . '/' . mt_rand() . '.xml'; $fp = @fopen($filename, 'x'); } while (!$fp); fclose($fp); unset($fp); $outfile = fopen($filename, 'w'); // Save the file in the backup directory while (!feof($filehandle)) { $content = fread($filehandle, 8192); if (fwrite($outfile, $content) === false) { echo "ERROR: Cannot write to file ({$filename})"; add_log("Cannot write to file ({$filename})", 'do_submit_asynchronous', LOG_ERR, $projectid); fclose($outfile); unset($outfile); return; } } fclose($outfile); unset($outfile); // Sends the file size to the local parser if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/ctestparser.php')) { require_once 'local/ctestparser.php'; $localParser = new LocalParser(); $filesize = filesize($filename); $localParser->SetFileSize($projectid, $filesize); } $md5sum = md5_file($filename); $md5error = false; echo '<cdash version="' . $CDASH_VERSION . "\">\n"; if ($expected_md5 == '' || $expected_md5 == $md5sum) { echo " <status>OK</status>\n"; echo " <message></message>\n"; } else { echo " <status>ERROR</status>\n"; echo " <message>Checksum failed for file. Expected {$expected_md5} but got {$md5sum}.</message>\n"; $md5error = true; } echo " <md5>{$md5sum}</md5>\n"; echo "</cdash>\n"; if ($md5error) { add_log("Checksum failure on file: {$filename}", 'do_submit_asynchronous', LOG_ERR, $projectid); return; } $bytes = filesize($filename); // Insert the filename in the database $now_utc = gmdate(FMT_DATETIMESTD); pdo_query('INSERT INTO submission (filename,projectid,status,attempts,filesize,filemd5sum,created) ' . "VALUES ('" . $filename . "','" . $projectid . "','0','0','{$bytes}','{$md5sum}','{$now_utc}')"); // Get the ID associated with this submission. We may need to reference it // later if this is a CDash@home (client) submission. $submissionid = pdo_insert_id('submission'); // We find the daily updates $currentURI = get_server_URI(true); $request = $currentURI . '/ajax/dailyupdatescurl.php?projectid=' . $projectid; if ($CDASH_DAILY_UPDATES && curl_request($request) === false) { return; } $clientscheduleid = isset($_GET['clientscheduleid']) ? pdo_real_escape_numeric($_GET['clientscheduleid']) : 0; if ($clientscheduleid !== 0) { pdo_query('INSERT INTO client_jobschedule2submission (scheduleid,submissionid) ' . "VALUES ('{$clientscheduleid}','{$submissionid}')"); } // Save submitter IP in the database in the async case, so we have a valid // IP at Site::Insert time when processing rather than 'localhost's IP: pdo_insert_query('INSERT INTO submission2ip (submissionid, ip) ' . "VALUES ('{$submissionid}', '" . $_SERVER['REMOTE_ADDR'] . "')"); // Call process submissions via cURL. trigger_process_submissions($projectid); }