Exemplo n.º 1
0
/** Main function to parse the incoming xml from ctest */
function ctest_parse($filehandler, $projectid, $expected_md5 = '', $do_checksum = true, $scheduleid = 0)
{
    include 'cdash/config.php';
    require_once 'cdash/common.php';
    require_once 'models/project.php';
    include 'cdash/version.php';
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/ctestparser.php")) {
        require_once "local/ctestparser.php";
        $localParser = new LocalParser();
        $localParser->SetProjectId($projectid);
        $localParser->BufferSizeMB = 8192 / (1024 * 1024);
    }
    // Check if this is a new style PUT submission.
    if (parse_put_submission($filehandler, $projectid, $expected_md5)) {
        return true;
    }
    $content = fread($filehandler, 8192);
    $handler = null;
    $parser = xml_parser_create();
    $file = "";
    if (preg_match('/<Update/', $content)) {
        $handler = new UpdateHandler($projectid, $scheduleid);
        $file = "Update";
    } else {
        if (preg_match('/<Build/', $content)) {
            $handler = new BuildHandler($projectid, $scheduleid);
            $file = "Build";
        } else {
            if (preg_match('/<Configure/', $content)) {
                $handler = new ConfigureHandler($projectid, $scheduleid);
                $file = "Configure";
            } else {
                if (preg_match('/<Testing/', $content)) {
                    $handler = new TestingHandler($projectid, $scheduleid);
                    $file = "Test";
                } else {
                    if (preg_match('/<CoverageLog/', $content)) {
                        $handler = new CoverageLogHandler($projectid, $scheduleid);
                        $file = "CoverageLog";
                    } else {
                        if (preg_match('/<Coverage/', $content)) {
                            $handler = new CoverageHandler($projectid, $scheduleid);
                            $file = "Coverage";
                        } else {
                            if (preg_match('/<report/', $content)) {
                                $handler = new CoverageJUnitHandler($projectid, $scheduleid);
                                $file = "Coverage";
                            } else {
                                if (preg_match('/<Notes/', $content)) {
                                    $handler = new NoteHandler($projectid, $scheduleid);
                                    $file = "Notes";
                                } else {
                                    if (preg_match('/<DynamicAnalysis/', $content)) {
                                        $handler = new DynamicAnalysisHandler($projectid, $scheduleid);
                                        $file = "DynamicAnalysis";
                                    } else {
                                        if (preg_match('/<Project/', $content)) {
                                            $handler = new ProjectHandler($projectid, $scheduleid);
                                            $file = "Project";
                                        } else {
                                            if (preg_match('/<Upload/', $content)) {
                                                $handler = new UploadHandler($projectid, $scheduleid);
                                                $file = "Upload";
                                            } else {
                                                if (preg_match('/<test-results/', $content)) {
                                                    $handler = new TestingNUnitHandler($projectid, $scheduleid);
                                                    $file = "Test";
                                                } else {
                                                    if (preg_match('/<testsuite/', $content)) {
                                                        $handler = new TestingJUnitHandler($projectid, $scheduleid);
                                                        $file = "Test";
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($handler == NULL) {
        echo "no handler found";
        add_log('error: could not create handler based on xml content', 'ctest_parse', LOG_ERR);
        $Project = new Project();
        $Project->Id = $projectid;
        // Try to get the IP of the build
        $ip = $_SERVER['REMOTE_ADDR'];
        $Project->SendEmailToAdmin('Cannot create handler based on XML content', 'An XML submission from ' . $ip . ' to the project ' . get_project_name($projectid) . ' cannot be parsed. The content of the file is as follow: ' . $content);
        return;
    }
    xml_set_element_handler($parser, array($handler, 'startElement'), array($handler, 'endElement'));
    xml_set_character_data_handler($parser, array($handler, 'text'));
    xml_parse($parser, $content, false);
    $projectname = get_project_name($projectid);
    $sitename = "";
    $buildname = "";
    $stamp = "";
    if ($file != "Project") {
        $sitename = $handler->getSiteName();
        $buildname = $handler->getBuildName();
        $stamp = $handler->getBuildStamp();
    }
    // Check if the build is in the block list
    $query = pdo_query("SELECT id FROM blockbuild WHERE projectid=" . qnum($projectid) . "\n                         AND (buildname='' OR buildname='" . $buildname . "')\n                         AND (sitename='' OR sitename='" . $sitename . "')\n                         AND (ipaddress='' OR ipaddress='" . $_SERVER['REMOTE_ADDR'] . "')");
    if (pdo_num_rows($query) > 0) {
        echo $query_array['id'];
        echo "The submission is banned from this CDash server.";
        add_log("Submission is banned from this CDash server", "ctestparser");
        return;
    }
    // Write the file to the backup directory.
    $filename = writeBackupFile($filehandler, $content, $projectname, $buildname, $sitename, $stamp, $file . ".xml");
    if ($filename === false) {
        return $handler;
    }
    $statusarray = array();
    $statusarray['status'] = 'OK';
    $statusarray['message'] = '';
    if ($do_checksum == true) {
        $md5sum = md5_file($filename);
        $md5error = false;
        if ($expected_md5 == '' || $expected_md5 == $md5sum) {
            $statusarray['status'] = 'OK';
        } else {
            $statusarray['status'] = 'ERROR';
            $statusarray['message'] = 'Checksum failed for file. Expected ' . $expected_md5 . ' but got ' . $md5sum;
            $md5error = true;
        }
        $statusarray['md5'] = $md5sum;
        if ($md5error) {
            displayReturnStatus($statusarray);
            add_log("Checksum failure on file: {$filename}", "ctest_parse", LOG_ERR, $projectid);
            return FALSE;
        }
    }
    $parsingerror = '';
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/ctestparser.php")) {
        $parsingerror = $localParser->StartParsing();
        if ($parsingerror != '') {
            $statusarray['status'] = 'ERROR';
            $statusarray['message'] = $parsingerror;
            displayReturnStatus($statusarray);
            exit;
        }
    }
    if (!($parseHandle = fopen($filename, 'r'))) {
        $statusarray['status'] = 'ERROR';
        $statusarray['message'] = "ERROR: Cannot open file ({$filename})";
        displayReturnStatus($statusarray);
        add_log("Cannot open file ({$filename})", "parse_xml_file", LOG_ERR);
        return $handler;
    }
    //burn the first 8192 since we have already parsed it
    $content = fread($parseHandle, 8192);
    while (!feof($parseHandle)) {
        $content = fread($parseHandle, 8192);
        if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/ctestparser.php")) {
            $parsingerror = $localParser->ParseFile();
            if ($parsingerror != '') {
                $statusarray['status'] = 'ERROR';
                $statusarray['message'] = $parsingerror;
                displayReturnStatus($statusarray);
                exit;
            }
        }
        xml_parse($parser, $content, false);
    }
    xml_parse($parser, null, true);
    xml_parser_free($parser);
    fclose($parseHandle);
    unset($parseHandle);
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/ctestparser.php")) {
        $parsingerror = $localParser->EndParsingFile();
    }
    displayReturnStatus($statusarray);
    return $handler;
}
Exemplo n.º 2
0
/** Main function to parse the incoming xml from ctest */
function ctest_parse($filehandler, $projectid, $expected_md5 = '', $do_checksum = true, $scheduleid = 0)
{
    include 'config/config.php';
    require_once 'include/common.php';
    require_once 'models/project.php';
    include 'include/version.php';
    global $CDASH_USE_LOCAL_DIRECTORY;
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/ctestparser.php')) {
        require_once 'local/ctestparser.php';
        $localParser = new LocalParser();
        $localParser->SetProjectId($projectid);
        $localParser->BufferSizeMB = 8192 / (1024 * 1024);
    }
    // Check if this is a new style PUT submission.
    if (parse_put_submission($filehandler, $projectid, $expected_md5)) {
        return true;
    }
    $content = fread($filehandler, 8192);
    $handler = null;
    $parser = xml_parser_create();
    $file = '';
    if (preg_match('/<Update/', $content)) {
        // Should be first otherwise confused with Build
        $handler = new UpdateHandler($projectid, $scheduleid);
        $file = 'Update';
    } elseif (preg_match('/<Build/', $content)) {
        $handler = new BuildHandler($projectid, $scheduleid);
        $file = 'Build';
    } elseif (preg_match('/<Configure/', $content)) {
        $handler = new ConfigureHandler($projectid, $scheduleid);
        $file = 'Configure';
    } elseif (preg_match('/<Testing/', $content)) {
        $handler = new TestingHandler($projectid, $scheduleid);
        $file = 'Test';
    } elseif (preg_match('/<CoverageLog/', $content)) {
        // Should be before coverage
        $handler = new CoverageLogHandler($projectid, $scheduleid);
        $file = 'CoverageLog';
    } elseif (preg_match('/<Coverage/', $content)) {
        $handler = new CoverageHandler($projectid, $scheduleid);
        $file = 'Coverage';
    } elseif (preg_match('/<report/', $content)) {
        $handler = new CoverageJUnitHandler($projectid, $scheduleid);
        $file = 'Coverage';
    } elseif (preg_match('/<Notes/', $content)) {
        $handler = new NoteHandler($projectid, $scheduleid);
        $file = 'Notes';
    } elseif (preg_match('/<DynamicAnalysis/', $content)) {
        $handler = new DynamicAnalysisHandler($projectid, $scheduleid);
        $file = 'DynamicAnalysis';
    } elseif (preg_match('/<Project/', $content)) {
        $handler = new ProjectHandler($projectid, $scheduleid);
        $file = 'Project';
    } elseif (preg_match('/<Upload/', $content)) {
        $handler = new UploadHandler($projectid, $scheduleid);
        $file = 'Upload';
    } elseif (preg_match('/<test-results/', $content)) {
        $handler = new TestingNUnitHandler($projectid, $scheduleid);
        $file = 'Test';
    } elseif (preg_match('/<testsuite/', $content)) {
        $handler = new TestingJUnitHandler($projectid, $scheduleid);
        $file = 'Test';
    }
    // Try to get the IP of the build
    global $CDASH_REMOTE_ADDR;
    $ip = $CDASH_REMOTE_ADDR ? $CDASH_REMOTE_ADDR : $_SERVER['REMOTE_ADDR'];
    if ($handler == null) {
        echo 'no handler found';
        add_log('error: could not create handler based on xml content', 'ctest_parse', LOG_ERR);
        $Project = new Project();
        $Project->Id = $projectid;
        $Project->SendEmailToAdmin('Cannot create handler based on XML content', 'An XML submission from ' . $ip . ' to the project ' . get_project_name($projectid) . ' cannot be parsed. The content of the file is as follow: ' . $content);
        return false;
    }
    xml_set_element_handler($parser, array($handler, 'startElement'), array($handler, 'endElement'));
    xml_set_character_data_handler($parser, array($handler, 'text'));
    xml_parse($parser, $content, false);
    $projectname = get_project_name($projectid);
    $sitename = '';
    $buildname = '';
    $stamp = '';
    if ($file != 'Project') {
        // projects don't have some of these fields.
        $sitename = $handler->getSiteName();
        $buildname = $handler->getBuildName();
        $stamp = $handler->getBuildStamp();
    }
    // Check if the build is in the block list
    $query = pdo_query('SELECT id FROM blockbuild WHERE projectid=' . qnum($projectid) . "\n            AND (buildname='' OR buildname='" . $buildname . "')\n            AND (sitename='' OR sitename='" . $sitename . "')\n            AND (ipaddress='' OR ipaddress='" . $ip . "')");
    if (pdo_num_rows($query) > 0) {
        echo 'The submission is banned from this CDash server.';
        add_log('Submission is banned from this CDash server', 'ctestparser');
        return false;
    }
    // If backups are disabled, switch the filename to that of the existing handle
    // Otherwise, create a backup file and process from that
    global $CDASH_BACKUP_TIMEFRAME;
    if ($CDASH_BACKUP_TIMEFRAME == '0') {
        $meta_data = stream_get_meta_data($filehandler);
        $filename = $meta_data['uri'];
    } else {
        $filename = writeBackupFile($filehandler, $content, $projectname, $buildname, $sitename, $stamp, $file . '.xml');
        if ($filename === false) {
            return $handler;
        }
    }
    $statusarray = array();
    $statusarray['status'] = 'OK';
    $statusarray['message'] = '';
    if ($do_checksum == true) {
        $md5sum = md5_file($filename);
        $md5error = false;
        if ($expected_md5 == '' || $expected_md5 == $md5sum) {
            $statusarray['status'] = 'OK';
        } else {
            $statusarray['status'] = 'ERROR';
            $statusarray['message'] = 'Checksum failed for file. Expected ' . $expected_md5 . ' but got ' . $md5sum;
            $md5error = true;
        }
        $statusarray['md5'] = $md5sum;
        if ($md5error) {
            displayReturnStatus($statusarray);
            add_log("Checksum failure on file: {$filename}", 'ctest_parse', LOG_ERR, $projectid);
            return false;
        }
    }
    $parsingerror = '';
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/ctestparser.php')) {
        $parsingerror = $localParser->StartParsing();
        if ($parsingerror != '') {
            $statusarray['status'] = 'ERROR';
            $statusarray['message'] = $parsingerror;
            displayReturnStatus($statusarray);
            exit;
        }
    }
    if (!($parseHandle = fopen($filename, 'r'))) {
        $statusarray['status'] = 'ERROR';
        $statusarray['message'] = "ERROR: Cannot open file ({$filename})";
        displayReturnStatus($statusarray);
        add_log("Cannot open file ({$filename})", 'parse_xml_file', LOG_ERR);
        return $handler;
    }
    //burn the first 8192 since we have already parsed it
    $content = fread($parseHandle, 8192);
    while (!feof($parseHandle)) {
        $content = fread($parseHandle, 8192);
        if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/ctestparser.php')) {
            $parsingerror = $localParser->ParseFile();
            if ($parsingerror != '') {
                $statusarray['status'] = 'ERROR';
                $statusarray['message'] = $parsingerror;
                displayReturnStatus($statusarray);
                exit;
            }
        }
        xml_parse($parser, $content, false);
    }
    xml_parse($parser, null, true);
    xml_parser_free($parser);
    fclose($parseHandle);
    unset($parseHandle);
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/ctestparser.php')) {
        $parsingerror = $localParser->EndParsingFile();
    }
    check_for_immediate_deletion($filename);
    displayReturnStatus($statusarray);
    return $handler;
}
Exemplo n.º 3
0
/** 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);
    }
}
Exemplo n.º 4
0
/** 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);
}