示例#1
0
 /** Save */
 public function Save()
 {
     $version = pdo_real_escape_string($this->Version);
     $path = pdo_real_escape_string($this->Path);
     // Check if the version already exists
     $query = pdo_query("SELECT id FROM client_cmake WHERE version='" . $version . "'");
     if (pdo_num_rows($query) == 0) {
         $sql = "INSERT INTO client_cmake (version)\n              VALUES ('" . $version . "')";
         pdo_query($sql);
         $this->Id = pdo_insert_id('client_cmake');
         add_last_sql_error('clientCMake::Save()');
     } else {
         // update
         $query_array = pdo_fetch_array($query);
         $this->Id = $query_array['id'];
         $sql = "UPDATE client_cmake SET version='" . $version . "' WHERE id=" . qnum($this->Id);
         pdo_query($sql);
         add_last_sql_error('clientCMake::Save()');
     }
     // Insert into the siteid
     $query = pdo_query('SELECT cmakeid FROM client_site2cmake WHERE cmakeid=' . qnum($this->Id) . ' AND siteid=' . qnum($this->SiteId));
     if (pdo_num_rows($query) == 0) {
         $sql = 'INSERT INTO client_site2cmake (siteid,cmakeid,path)
           VALUES (' . qnum($this->SiteId) . ',' . qnum($this->Id) . ",'" . $path . "')";
         pdo_query($sql);
         add_last_sql_error('clientCMake::Save()');
     } else {
         // update
         $sql = "UPDATE client_site2cmake SET path='" . $path . "' WHERE cmakeid=" . qnum($this->Id) . ' AND siteid=' . qnum($this->SiteId);
         pdo_query($sql);
         add_last_sql_error('clientCMake::Save()');
     }
 }
示例#2
0
function get_related_dates($projectname, $basedate)
{
    include "cdash/config.php";
    require_once "cdash/pdo.php";
    $dates = array();
    $db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}");
    pdo_select_db("{$CDASH_DB_NAME}", $db);
    $dbQuery = pdo_query("SELECT nightlytime FROM project WHERE name='{$projectname}'");
    if (pdo_num_rows($dbQuery) > 0) {
        $project = pdo_fetch_array($dbQuery);
        $nightlytime = $project['nightlytime'];
        //echo "query result nightlytime: " . $nightlytime . "<br/>";
    } else {
        $nightlytime = "00:00:00";
        //echo "default nightlytime: " . $nightlytime . "<br/>";
    }
    if (!isset($basedate) || strlen($basedate) == 0) {
        $basedate = gmdate(FMT_DATE);
    }
    // Convert the nightly time into GMT
    $nightlytime = gmdate(FMT_TIME, strtotime($nightlytime));
    $nightlyhour = time2hour($nightlytime);
    $nightlyminute = time2minute($nightlytime);
    $nightlysecond = time2second($nightlytime);
    $basemonth = date2month($basedate);
    $baseday = date2day($basedate);
    $baseyear = date2year($basedate);
    $dates['nightly+2'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday + 2, $baseyear);
    $dates['nightly+1'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday + 1, $baseyear);
    $dates['nightly-0'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday, $baseyear);
    $dates['nightly-1'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday - 1, $baseyear);
    $dates['nightly-2'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday - 2, $baseyear);
    // Snapshot of "now"
    //
    $currentgmtime = time();
    $currentgmdate = gmdate(FMT_DATE, $currentgmtime);
    // Find the most recently past nightly time:
    //
    $todaymonth = date2month($currentgmdate);
    $todayday = date2day($currentgmdate);
    $todayyear = date2year($currentgmdate);
    $currentnightly = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $todaymonth, $todayday, $todayyear);
    while ($currentnightly > $currentgmtime) {
        $todayday = $todayday - 1;
        $currentnightly = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $todaymonth, $todayday, $todayyear);
    }
    $dates['now'] = $currentgmtime;
    $dates['most-recent-nightly'] = $currentnightly;
    $dates['today_utc'] = $currentgmdate;
    $dates['basedate'] = gmdate(FMT_DATE, $dates['nightly-0']);
    // CDash equivalent of DART1's "last rollup time"
    if ($dates['basedate'] === $dates['today_utc']) {
        // If it's today, it's now:
        $dates['last-rollup-time'] = $dates['now'];
    } else {
        // If it's not today, it's the nightly time on the basedate:
        $dates['last-rollup-time'] = $dates['nightly-0'];
    }
    return $dates;
}
示例#3
0
 /**
  * Authenticate to the web API as a project admin
  * @param project the name of the project
  * @param key the web API key for that project
  */
 function Authenticate()
 {
     include_once '../cdash/common.php';
     if (!isset($this->Parameters['project'])) {
         return array('status' => false, 'message' => "You must specify a project parameter.");
     }
     $projectid = get_project_id($this->Parameters['project']);
     if (!is_numeric($projectid) || $projectid <= 0) {
         return array('status' => false, 'message' => 'Project not found.');
     }
     if (!isset($this->Parameters['key']) || $this->Parameters['key'] == '') {
         return array('status' => false, 'message' => "You must specify a key parameter.");
     }
     $key = $this->Parameters['key'];
     $query = pdo_query("SELECT webapikey FROM project WHERE id={$projectid}");
     if (pdo_num_rows($query) == 0) {
         return array('status' => false, 'message' => "Invalid projectid.");
     }
     $row = pdo_fetch_array($query);
     $realKey = $row['webapikey'];
     if ($key != $realKey) {
         return array('status' => false, 'message' => "Incorrect API key passed.");
     }
     $token = create_web_api_token($projectid);
     return array('status' => true, 'token' => $token);
 }
示例#4
0
 public function testTestHistory()
 {
     // Submit our testing data.
     $rep = dirname(__FILE__) . '/data/TestHistory';
     if (!$this->submission('InsightExample', "{$rep}/Test_1.xml")) {
         $this->fail('Failed to submit Test_1.xml');
         return 1;
     }
     if (!$this->submission('InsightExample', "{$rep}/Test_2.xml")) {
         $this->fail('Failed to submit Test_1.xml');
         return 1;
     }
     // Get the IDs for the two builds that we just created.
     $result = pdo_query("SELECT id FROM build WHERE name='TestHistory'");
     $num_builds = pdo_num_rows($result);
     if ($num_builds != 2) {
         $this->fail("Expected 2 builds, found {$num_builds}");
         return 1;
     }
     $buildids = array();
     while ($row = pdo_fetch_array($result)) {
         $buildids[] = $row['id'];
     }
     // Verify that testing history matches what we expect.
     $content = $this->connect($this->url . '/api/v1/viewTest.php?groupid=15&previous_builds=' . $buildids[1] . ',+' . $buildids[0] . '&projectid=5&tests%5B%5D=fails&tests%5B%5D=notrun&tests%5B%5D=flaky&tests%5B%5D=passes&time_begin=2015-11-16T01:00:00&time_end=2015-11-17T01:00:00');
     $jsonobj = json_decode($content, true);
     $success = true;
     $error_message = '';
     foreach ($jsonobj['tests'] as $test) {
         $history = $test['history'];
         if ($test['name'] == 'fails' && $history != 'Broken') {
             $error_message = "Expected history for test 'fails' to be 'Broken', instead found '{$history}'";
             $success = false;
         }
         if ($test['name'] == 'notrun' && $history != 'Inactive') {
             $error_message = "Expected history for test 'notrun' to be 'Inactive', instead found '{$history}'";
             $success = false;
         }
         if ($test['name'] == 'flaky' && $history != 'Unstable') {
             $error_message = "Expected history for test 'flaky' to be 'Unstable', instead found '{$history}'";
             $success = false;
         }
         if ($test['name'] == 'passes' && $history != 'Stable') {
             $error_message = "Expected history for test 'passes' to be 'Stable', instead found '{$history}'";
             $success = false;
         }
     }
     // Delete the builds that we created during this test.
     remove_build($buildids[0]);
     remove_build($buildids[1]);
     if ($success) {
         $this->pass('Test passed');
         return 0;
     } else {
         $this->fail($error_message);
         return 1;
     }
 }
示例#5
0
 /** Return the coverage per directory with the number of lines
  * covered and not covered */
 private function CoveragePerDirectory()
 {
     include_once '../cdash/common.php';
     if (!isset($this->Parameters['project'])) {
         echo "Project not set";
         return;
     }
     $projectid = get_project_id($this->Parameters['project']);
     if (!is_numeric($projectid) || $projectid <= 0) {
         echo "Project not found";
         return;
     }
     // Select the last build that has coverage from the project
     $query = pdo_query("SELECT buildid FROM coveragesummary,build WHERE build.id=coveragesummary.buildid\n                              AND build.projectid='{$projectid}' ORDER BY buildid DESC LIMIT 1");
     echo pdo_error();
     if (pdo_num_rows($query) == 0) {
         echo "No coverage entries found for this project";
         return;
     }
     $query_array = pdo_fetch_array($query);
     $buildid = $query_array['buildid'];
     // Find the coverage files
     $query = pdo_query("SELECT cf.fullpath,c.loctested,c.locuntested FROM coverage as c,coveragefile as cf\n                 WHERE c.fileid=cf.id AND c.buildid='" . $buildid . "' ORDER BY cf.fullpath ASC");
     echo pdo_error();
     $coveragearray = array();
     while ($query_array = pdo_fetch_array($query)) {
         $fullpath = $query_array['fullpath'];
         $paths = explode('/', $fullpath);
         $current = array();
         for ($i = 1; $i < count($paths) - 1; $i++) {
             if ($i == 1) {
                 if (!isset($coveragearray[$paths[$i]])) {
                     $coveragearray[$paths[$i]] = array();
                 }
                 $current =& $coveragearray[$paths[$i]];
             } else {
                 if ($i == count($paths) - 2) {
                     if (isset($current[$paths[$i]])) {
                         $v = $current[$paths[$i]]['locuntested'];
                         $current[$paths[$i]]['locuntested'] = (int) $v + $query_array['locuntested'];
                         $v = $current[$paths[$i]]['loctested'];
                         $current[$paths[$i]]['loctested'] = (int) $v + $query_array['loctested'];
                     } else {
                         @($current[$paths[$i]]['locuntested'] = $query_array['locuntested']);
                         @($current[$paths[$i]]['loctested'] = $query_array['loctested']);
                     }
                     unset($current);
                 } else {
                     $current[$paths[$i]] = array();
                     $current[$paths[$i]]['locuntested'] = 0;
                     $current[$paths[$i]]['loctested'] = 0;
                     $current =& $current[$paths[$i]];
                 }
             }
         }
     }
     return $coveragearray;
 }
示例#6
0
/** Get the last file id dynamicanalysis */
function get_last_fileid_dynamicanalysis($filename, $projectid, $siteid, $buildtype, $buildname, $starttime)
{
    $nextbuild = pdo_query("SELECT dynamicanalysis.id FROM build,dynamicanalysis\n                          WHERE build.siteid='{$siteid}' AND build.type='{$buildtype}' AND build.name='{$buildname}'\n                          AND build.projectid='{$projectid}' \n                          AND dynamicanalysis.buildid=build.id\n                          AND dynamicanalysis.name='{$filename}'\n                          ORDER BY build.starttime DESC LIMIT 1");
    if (pdo_num_rows($nextbuild) > 0) {
        $nextbuild_array = pdo_fetch_array($nextbuild);
        return $nextbuild_array["id"];
    }
    return 0;
}
示例#7
0
 public function Insert()
 {
     if (!$this->BuildId) {
         add_log('BuildId not set', 'BuildNote::Insert()', LOG_ERR, 0, $this->Id);
         return false;
     }
     if (!$this->Time) {
         add_log('Time not set', 'BuildNote::Insert()', LOG_ERR, 0, $this->Id);
         return false;
     }
     if (!$this->Name) {
         add_log('Name not set', 'BuildNote::Insert()', LOG_ERR, 0, $this->Id);
         return false;
     }
     if (!$this->Text) {
         add_log('Text not set', 'BuildNote::Insert()', LOG_ERR, 0, $this->Id);
         return false;
     }
     // Check if the note already exists
     $crc32 = $this->GetCrc32();
     $text = pdo_real_escape_string($this->Text);
     $timestamp = pdo_real_escape_string($this->Time);
     $name = pdo_real_escape_string($this->Name);
     $notecrc32 = pdo_query("SELECT id FROM note WHERE crc32='{$crc32}'");
     if (pdo_num_rows($notecrc32) == 0) {
         if ($this->Id) {
             $query = "INSERT INTO note (id,text,name,crc32) VALUES ('{$this->Id}','{$text}','{$name}','{$crc32}')";
         } else {
             $query = "INSERT INTO note (text,name,crc32) VALUES ('{$text}','{$name}','{$crc32}')";
         }
         if (!pdo_query($query)) {
             add_last_sql_error('BuildNote:Insert', 0, $this->BuildId);
             return false;
         }
         if (!$this->Id) {
             $this->Id = pdo_insert_id('note');
         }
     } else {
         // already there
         $notecrc32_array = pdo_fetch_array($notecrc32);
         $this->Id = $notecrc32_array['id'];
     }
     if (!$this->Id) {
         echo 'BuildNote::Insert(): No NoteId';
         return false;
     }
     $query = "INSERT INTO build2note (buildid,noteid,time)\n            VALUES ('{$this->BuildId}','{$this->Id}','{$this->Time}')";
     if (!pdo_query($query)) {
         add_last_sql_error('BuildNote:Insert', 0, $this->BuildId);
         return false;
     }
     return true;
 }
示例#8
0
 function Insert()
 {
     if (!$this->BuildId) {
         echo "BuildNote::Insert(): BuildId is not set<br>";
         return false;
     }
     if (!$this->Time) {
         echo "BuildNote::Insert(): Time is not set<br>";
         return false;
     }
     if (!$this->Name) {
         echo "BuildNote::Insert(): Name is not set<br>";
         return false;
     }
     if (!$this->Text) {
         echo "BuildNote::Insert(): Text is not set<br>";
         return false;
     }
     // Check if the note already exists
     $crc32 = $this->GetCrc32();
     $text = pdo_real_escape_string($this->Text);
     $timestamp = pdo_real_escape_string($this->Time);
     $name = pdo_real_escape_string($this->Name);
     $notecrc32 = pdo_query("SELECT id FROM note WHERE crc32='{$crc32}'");
     if (pdo_num_rows($notecrc32) == 0) {
         if ($this->Id) {
             $query = "INSERT INTO note (id,text,name,crc32) VALUES ('{$this->Id}','{$text}','{$name}','{$crc32}')";
         } else {
             $query = "INSERT INTO note (text,name,crc32) VALUES ('{$text}','{$name}','{$crc32}')";
         }
         if (!pdo_query($query)) {
             add_last_sql_error("BuildNote:Insert", 0, $this->BuildId);
             return false;
         }
         if (!$this->Id) {
             $this->Id = pdo_insert_id("note");
         }
     } else {
         $notecrc32_array = pdo_fetch_array($notecrc32);
         $this->Id = $notecrc32_array["id"];
     }
     if (!$this->Id) {
         echo "BuildNote::Insert(): No NoteId";
         return false;
     }
     $query = "INSERT INTO build2note (buildid,noteid,time)\n              VALUES ('{$this->BuildId}','{$this->Id}','{$this->Time}')";
     if (!pdo_query($query)) {
         add_last_sql_error("BuildNote:Insert", 0, $this->BuildId);
         return false;
     }
     return true;
 }
示例#9
0
文件: banner.php 项目: rpshaw/CDash
 /** Return the text */
 function GetText()
 {
     $query = pdo_query("SELECT text FROM banner WHERE projectid=" . qnum($this->ProjectId));
     if (pdo_num_rows($query) == 0) {
         return false;
     }
     $query_array = pdo_fetch_array($query);
     $this->Text = $query_array['text'];
     if (strlen($this->Text) == 0) {
         return false;
     }
     return $this->Text;
 }
 function testBuildsRemovedOnSubmission()
 {
     $this->enableAutoRemoveConfigSetting();
     $this->setAutoRemoveTimeFrame();
     $this->deleteLog($this->logfilename);
     $this->startCodeCoverage();
     $result = $this->db->query("SELECT id FROM project WHERE name = 'EmailProjectExample'");
     $projectid = $result[0]['id'];
     // Submit the first build
     $rep = dirname(__FILE__) . "/data/EmailProjectExample";
     $testxml1 = "{$rep}/1_test.xml";
     if (!$this->submission('EmailProjectExample', $testxml1)) {
         $this->fail("submission 1 failed");
         $this->stopCodeCoverage();
         return;
     }
     // Check that the test is actually there
     if (!($query = pdo_query("SELECT name FROM build WHERE projectid='{$projectid}' AND stamp='20090223-0100-Nightly'"))) {
         $this->fail("pdo_query returned false");
         return 1;
     }
     $query_array = pdo_fetch_array($query);
     if ($query_array[0] != 'Win32-MSVC2009') {
         echo $query_array[0];
         $this->fail("First build not inserted correctly");
         return 1;
     }
     // Looks like it's a new day
     $this->db->query("DELETE FROM dailyupdate WHERE projectid='{$projectid}'");
     $testxml2 = "{$rep}/2_test.xml";
     if (!$this->submission('EmailProjectExample', $testxml2)) {
         $this->fail("submission 2 failed");
         $this->stopCodeCoverage();
         return 1;
     }
     // The removal of the builds are done asynchronously so we might need to wait a little bit
     // in order for the process to be done
     sleep(10);
     // seconds
     // Check that the first test is gone
     if (!($query = pdo_query("SELECT id FROM build WHERE projectid='{$projectid}' AND stamp='20090223-0100-Nightly'"))) {
         $this->fail("pdo_query returned false");
         return 1;
     }
     if (pdo_num_rows($query) > 0) {
         $this->fail("Auto remove build on submit failed");
         return 1;
     }
     $this->pass("Passed");
     $this->stopCodeCoverage();
 }
示例#11
0
function orsee_session_read($aKey)
{
    $query = "SELECT DataValue FROM " . table('http_sessions') . " WHERE SessionID=:aKey";
    $pars = array(':aKey' => $aKey);
    $result = or_query($query, $pars);
    if (pdo_num_rows($result) == 1) {
        $r = pdo_fetch_assoc($result);
        return $r['DataValue'];
    } else {
        $query = "INSERT INTO " . table('http_sessions') . " (SessionID, LastUpdated, DataValue)\n                       VALUES (:aKey, NOW(), '')";
        or_query($query, $pars);
        return "";
    }
}
示例#12
0
 /** Save the site information */
 function Save()
 {
     if ($this->OSName != "" || $this->OSPlatform != "" || $this->OSRelease != "" || $this->OSVersion != "") {
         if (empty($this->BuildId)) {
             return false;
         }
         // Check if we already have a buildinformation for that build. If yes we just skip it
         $query = pdo_query("SELECT buildid FROM buildinformation WHERE buildid=" . qnum($this->BuildId));
         add_last_sql_error("BuildInformation Insert", 0, $this->BuildId);
         if (pdo_num_rows($query) == 0) {
             pdo_query("INSERT INTO buildinformation (buildid,osname,osrelease,osversion,osplatform,compilername,compilerversion) \n                    VALUES (" . qnum($this->BuildId) . ",'{$this->OSName}','{$this->OSRelease}',\n                            '{$this->OSVersion}','{$this->OSPlatform}','{$this->CompilerName}','{$this->CompilerVersion}')");
             add_last_sql_error("BuildInformation Insert", 0, $this->BuildId);
         }
         return true;
     }
 }
示例#13
0
文件: pdo.php 项目: rpshaw/CDash
function pdo_single_row_query($qry)
{
    $result = pdo_query($qry);
    if (FALSE === $result) {
        add_log('error: pdo_query failed: ' . pdo_error(), 'pdo_single_row_query', LOG_ERR);
        return array();
    }
    $num_rows = pdo_num_rows($result);
    if (0 !== $num_rows && 1 !== $num_rows) {
        add_log('error: at most 1 row should be returned, not ' . $num_rows, 'pdo_single_row_query', LOG_ERR);
        add_log('warning: returning the first row anyway even though result ' . 'contains ' . $num_rows . ' rows', 'pdo_single_row_query', LOG_WARNING);
    }
    $row = pdo_fetch_array($result);
    pdo_free_result($result);
    return $row;
}
示例#14
0
 public function Insert()
 {
     if (strlen($this->UpdateId) == 0) {
         echo 'BuildUpdateFile:Insert UpdateId not set';
         return false;
     }
     $this->Filename = pdo_real_escape_string($this->Filename);
     // Sometimes the checkin date is not found in that case we put the usual date
     if ($this->CheckinDate == 'Unknown') {
         $this->CheckinDate = '1980-01-01';
     }
     if (strtotime($this->CheckinDate) === false && is_numeric($this->CheckinDate)) {
         $this->CheckinDate = date(FMT_DATETIME, $this->CheckinDate);
     } elseif (strtotime($this->CheckinDate) !== false) {
         $this->CheckinDate = date(FMT_DATETIME, strtotime($this->CheckinDate));
     } else {
         $this->CheckinDate = '1980-01-01';
     }
     $this->Author = pdo_real_escape_string($this->Author);
     $this->UpdateId = pdo_real_escape_string($this->UpdateId);
     // Check if we have a robot file for this build
     $robot = pdo_query('SELECT authorregex FROM projectrobot,build,build2update
             WHERE projectrobot.projectid=build.projectid
             AND build2update.buildid=build.id
             AND build2update.updateid=' . qnum($this->UpdateId) . " AND robotname='" . $this->Author . "'");
     if (pdo_num_rows($robot) > 0) {
         $robot_array = pdo_fetch_array($robot);
         $regex = $robot_array['authorregex'];
         preg_match($regex, $this->Log, $matches);
         if (isset($matches[1])) {
             $this->Author = $matches[1];
         }
     }
     $this->Email = pdo_real_escape_string($this->Email);
     $this->Committer = pdo_real_escape_string($this->Committer);
     $this->CommitterEmail = pdo_real_escape_string($this->CommitterEmail);
     $this->Log = pdo_real_escape_string($this->Log);
     $this->Revision = pdo_real_escape_string($this->Revision);
     $this->PriorRevision = pdo_real_escape_string($this->PriorRevision);
     $query = 'INSERT INTO updatefile (updateid,filename,checkindate,author,email,log,revision,priorrevision,status,committer,committeremail)
           VALUES (' . qnum($this->UpdateId) . ",'{$this->Filename}','{$this->CheckinDate}','{$this->Author}','{$this->Email}',\n                      '{$this->Log}','{$this->Revision}','{$this->PriorRevision}','{$this->Status}','{$this->Committer}','{$this->CommitterEmail}')";
     if (!pdo_query($query)) {
         add_last_sql_error('BuildUpdateFile Insert', 0, $this->UpdateId);
         return false;
     }
 }
示例#15
0
文件: clientos.php 项目: rpshaw/CDash
 /** Save a site */
 function Save()
 {
     $name = $this->GetNameFromPlatform($this->Name);
     $version = $this->GetNameFromVersion($this->Version);
     if (strlen($name) == 0) {
         return false;
     }
     // Check if the name and bits system already exists
     $query = pdo_query("SELECT id FROM client_os WHERE name='" . $name . "' AND version='" . $version . "' AND bits='" . $this->Bits . "'");
     if (pdo_num_rows($query) == 0) {
         $sql = "INSERT INTO client_os (name,version,bits) \n              VALUES ('" . $name . "','" . $version . "','" . $this->Bits . "')";
         pdo_query($sql);
         $this->Id = pdo_insert_id('client_os');
         add_last_sql_error("ClientOS::Save()");
     } else {
         $query_array = pdo_fetch_array($query);
         $this->Id = $query_array['id'];
     }
 }
示例#16
0
文件: image.php 项目: kitware/cdash
 /** Check if exists */
 public function Exists()
 {
     // If no id specify return false
     if ($this->Id) {
         $query = pdo_query("SELECT count(*) AS c FROM image WHERE id='" . $this->Id . "'");
         $query_array = pdo_fetch_array($query);
         if ($query_array['c'] == 0) {
             return false;
         }
         return true;
     } else {
         // Check if the checksum exists
         $query = pdo_query("SELECT id FROM image WHERE checksum='" . $this->Checksum . "'");
         if (pdo_num_rows($query) > 0) {
             $query_array = pdo_fetch_array($query);
             $this->Id = $query_array['id'];
             return true;
         }
         return false;
     }
     return true;
 }
示例#17
0
 function Insert()
 {
     if (!$this->BuildId) {
         echo "BuildFile::Insert(): BuildId not set<br>";
         return false;
     }
     if (!$this->Type) {
         echo "BuildFile::Insert(): Type not set<br>";
         return false;
     }
     if (!$this->md5) {
         echo "BuildFile::Insert(): md5 not set<br>";
         return false;
     }
     if (!$this->Filename) {
         echo "BuildFile::Insert(): Filename not set<br>";
         return false;
     }
     $filename = pdo_real_escape_string($this->Filename);
     $type = pdo_real_escape_string($this->Type);
     $md5 = pdo_real_escape_string($this->md5);
     // Check if we already have a row
     $query = "SELECT buildid FROM buildfile WHERE buildid=" . qnum($this->BuildId) . " AND md5='" . $md5 . "'";
     $query_result = pdo_query($query);
     if (!$query_result) {
         add_last_sql_error("BuildFile Insert", 0, $this->BuildId);
         return false;
     }
     if (pdo_num_rows($query_result) > 0) {
         return false;
     }
     $query = "INSERT INTO buildfile (buildid,type,filename,md5)\n              VALUES (" . qnum($this->BuildId) . ",'" . $type . "','" . $filename . "','" . $md5 . "')";
     if (!pdo_query($query)) {
         add_last_sql_error("BuildFile Insert", 0, $this->BuildId);
         return false;
     }
     return true;
 }
示例#18
0
文件: site.php 项目: rpshaw/CDash
 /** Check if the site already exists */
 function Exists()
 {
     // If no id specify return false
     if (!$this->Id && !$this->Name) {
         return false;
     }
     if ($this->Id) {
         $query = pdo_query("SELECT count(*) AS c FROM site WHERE id=" . qnum($this->Id));
         $query_array = pdo_fetch_array($query);
         if ($query_array['c'] > 0) {
             return true;
         }
     }
     if ($this->Name) {
         $query = pdo_query("SELECT id FROM site WHERE name='" . $this->Name . "'");
         if (pdo_num_rows($query) > 0) {
             $query_array = pdo_fetch_array($query);
             $this->Id = $query_array['id'];
             return true;
         }
     }
     return false;
 }
示例#19
0
文件: errorlog.php 项目: rpshaw/CDash
 function Insert()
 {
     if (!is_numeric($this->ProjectId) || !is_numeric($this->BuildId) || !is_numeric($this->ResourceId) || !is_numeric($this->ResourceType) || !is_numeric($this->Type)) {
         return false;
     }
     $description = pdo_real_escape_string($this->Description);
     // If the projectid is not set but the buildid is we are trying to find
     // the projectid
     if ($this->ProjectId == 0 && $this->BuildId > 0) {
         $query = pdo_query("SELECT projectid FROM build WHERE id='" . $this->BuildId . "'");
         if (pdo_num_rows($query) > 0) {
             $query_array = pdo_fetch_array($query);
             $this->ProjectId = $query_array['projectid'];
         }
     }
     // Insert a new row every time an error exists
     $now = date("Y-m-d H:i:s");
     $sql = "INSERT INTO errorlog (projectid,buildid,type,date,resourcetype,resourceid,description)\n               VALUES ('" . $this->ProjectId . "','" . $this->BuildId . "','" . $this->Type . "','" . $now . "','" . $this->ResourceType . "','" . $this->ResourceId . "','" . $description . "')";
     pdo_query($sql);
     echo pdo_error();
     // We don't log on purpose (loop loop ;)
     return true;
 }
示例#20
0
 /** Save */
 function Save()
 {
     // Check if the name/version already exists
     $query = pdo_query("SELECT id FROM client_library WHERE name='" . $this->Name . "' AND version='" . $this->Version . "'");
     if (pdo_num_rows($query) == 0) {
         $sql = "INSERT INTO client_library (name,version)\n              VALUES ('" . $this->Name . "','" . $this->Version . "')";
         pdo_query($sql);
         $this->Id = pdo_insert_id('client_library');
         add_last_sql_error("ClientLibrary::Save()");
     } else {
         $query_array = pdo_fetch_array($query);
         $this->Id = $query_array['id'];
         $sql = "UPDATE client_library SET version='" . $this->Version . "' WHERE id=" . qnum($this->Id);
         pdo_query($sql);
         add_last_sql_error("ClientLibrary::Save()");
     }
     // Insert into the siteid
     $query = pdo_query("SELECT libraryid FROM client_site2library WHERE libraryid=" . qnum($this->Id) . " AND siteid=" . qnum($this->SiteId));
     if (pdo_num_rows($query) == 0) {
         $sql = "INSERT INTO client_site2library (siteid,libraryid,path,include)\n              VALUES (" . qnum($this->SiteId) . "," . qnum($this->Id) . ",'" . $this->Path . "','" . $this->Include . "')";
         pdo_query($sql);
         add_last_sql_error("ClientLibrary::Save()");
     } else {
         $sql = "UPDATE client_site2library SET path='" . $this->Path . "',include='" . $this->Include . "' WHERE libraryid=" . qnum($this->Id) . " AND siteid=" . qnum($this->SiteId);
         pdo_query($sql);
         add_last_sql_error("ClientLibrary::Save()");
     }
 }
示例#21
0
 function GetIdFromName($file, $buildid)
 {
     $coveragefile = pdo_query("SELECT id FROM coveragefile,coverage WHERE fullpath LIKE '%" . $file . "%' \n                               AND coverage.buildid=" . qnum($buildid) . " AND coverage.fileid=coveragefile.id");
     if (!$coveragefile) {
         add_last_sql_error("CoverageFile:GetIdFromName()");
         return false;
     }
     if (pdo_num_rows($coveragefile) == 0) {
         return false;
     }
     $coveragefile_array = pdo_fetch_array($coveragefile);
     return $coveragefile_array['id'];
 }
示例#22
0
         $LabelEmail->UpdateLabels($_POST['emaillabels']);
     } else {
         $LabelEmail->UpdateLabels(NULL);
     }
     // Redirect
     header('location: user.php');
 } else {
     if ($Subscribe) {
         @($emailcategory_update = $_POST["emailcategory_update"]);
         @($emailcategory_configure = $_POST["emailcategory_configure"]);
         @($emailcategory_warning = $_POST["emailcategory_warning"]);
         @($emailcategory_error = $_POST["emailcategory_error"]);
         @($emailcategory_test = $_POST["emailcategory_test"]);
         @($emailcategory_dynamicanalysis = $_POST["emailcategory_dynamicanalysis"]);
         $EmailCategory = $emailcategory_update + $emailcategory_configure + $emailcategory_warning + $emailcategory_error + $emailcategory_test + $emailcategory_dynamicanalysis;
         if (pdo_num_rows($user2project) > 0) {
             pdo_query("UPDATE user2project SET role='{$Role}',emailtype='{$EmailType}',\n                         emailcategory='{$EmailCategory}'.\n                         emailmissingsites='{$EmailMissingSites}',\n                         emailsuccess='{$EmailSuccess}'\n                         WHERE userid='{$userid}' AND projectid='{$projectid}'");
             // Update the repository credential
             $UserProject = new UserProject();
             $UserProject->ProjectId = $projectid;
             $UserProject->UserId = $userid;
             $UserProject->UpdateCredentials($Credentials);
             if ($Role == 0) {
                 // Remove the claim sites for this project if they are only part of this project
                 pdo_query("DELETE FROM site2user WHERE userid='{$userid}'\n                 AND siteid NOT IN\n                (SELECT build.siteid FROM build,user2project as up WHERE\n                 up.projectid = build.projectid AND up.userid='{$userid}' AND up.role>0\n                 GROUP BY build.siteid)");
             }
         } else {
             pdo_query("INSERT INTO user2project (role,userid,projectid,emailtype,emailcategory,emailsuccess,\n                                           emailmissingsites)\n                 VALUES ('{$Role}','{$userid}','{$projectid}','{$EmailType}','{$EmailCategory}',\n                         '{$EmailSuccess}','{$EmailMissingSites}')");
             $UserProject = new UserProject();
             $UserProject->ProjectId = $projectid;
             $UserProject->UserId = $userid;
示例#23
0
           window.location = "";
       });
}
</script>
 <form method="post" action="">

  <table width="100%"  border="0">
  <tr>
  <?php 
// If expected
// Find the groups available for this project
$isexpected = 0;
$currentgroupid = $currentgroup_array["id"];
// This works only for the most recent dashboard (and future)
$build2groupexpected = pdo_query("SELECT groupid FROM build2grouprule WHERE groupid='{$currentgroupid}' AND buildtype='{$buildtype}'\n                                      AND buildname='{$buildname}' AND siteid='{$siteid}' AND endtime='1980-01-01 00:00:00' AND expected='1'");
if (pdo_num_rows($build2groupexpected) > 0) {
    $isexpected = 1;
}
?>
  <td bgcolor="#DDDDDD" width="35%"><font size="2"><b><?php 
echo $currentgroup_array["name"];
?>
</b>:  </font></td>
  <td bgcolor="#DDDDDD" width="65%" colspan="2"  id="nob"><font size="2"><a href="#" onclick="javascript:markasnonexpected_click('<?php 
echo $siteid;
?>
','<?php 
echo $buildname;
?>
','<?php 
echo $buildtype;
示例#24
0
include_once "cdash/common.php";
include_once "cdash/version.php";
require_once "cdash/cdashmail.php";
$db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}");
pdo_select_db("{$CDASH_DB_NAME}", $db);
$xml = begin_XML_for_XSLT();
$xml .= "<title>Recover password</title>";
if (isset($CDASH_NO_REGISTRATION) && $CDASH_NO_REGISTRATION == 1) {
    $xml .= add_XML_value("noregister", "1");
}
@($recover = $_POST["recover"]);
if ($recover) {
    $email = pdo_real_escape_string($_POST["email"]);
    $emailResult = pdo_query("SELECT id FROM " . qid("user") . " where email='{$email}'");
    add_last_sql_error("recoverPassword");
    if (pdo_num_rows($emailResult) == 0) {
        $xml .= "<warning>This email is not registered.</warning>";
    } else {
        // Create a new password
        $keychars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#\$%&";
        $length = 10;
        // seed with microseconds
        function make_seed_recoverpass()
        {
            list($usec, $sec) = explode(' ', microtime());
            return (double) $sec + (double) $usec * 100000;
        }
        srand(make_seed_recoverpass());
        $password = "";
        $max = strlen($keychars) - 1;
        for ($i = 0; $i <= $length; $i++) {
示例#25
0
 /**
  * Parse an individual .gcov file.
  **/
 public function ParseGcovFile($fileinfo)
 {
     $coverageFileLog = new CoverageFileLog();
     $coverageFileLog->AggregateBuildId = $this->AggregateBuildId;
     $coverageFileLog->PreviousAggregateParentId = $this->PreviousAggregateParentId;
     $coverageFile = new CoverageFile();
     $coverage = new Coverage();
     $coverage->CoverageFile = $coverageFile;
     // Begin parsing this file.
     // The first thing we look for is the full path to this source file.
     $file = new SplFileObject($fileinfo);
     $path = '';
     while (!$file->eof()) {
         $gcovLine = $file->current();
         $term = ':Source:';
         $pos = strpos($gcovLine, $term);
         if ($pos !== false) {
             $path = substr($gcovLine, $pos + strlen($term));
             break;
         }
         $file->next();
     }
     if (empty($path)) {
         return;
     }
     // Check if this file belongs to a different SubProject.
     $buildid = $this->Build->Id;
     if (!empty($this->SubProjectPath) && strpos($path, $this->SubProjectPath) === false) {
         // Find the SubProject that corresponds to this path.
         $query = "SELECT id, name, path FROM subproject\n                WHERE projectid = {$this->ProjectId} AND\n                endtime = '1980-01-01 00:00:00' AND\n                path != '' AND\n                '{$path}' LIKE CONCAT('%',path,'%')";
         $result = pdo_query($query);
         if (!$result || pdo_num_rows($result) == 0) {
             add_log("No SubProject found for '{$path}'", 'ParseGcovFile', LOG_INFO, $this->ProjectId, $this->Build->Id);
             return;
         }
         $row = pdo_fetch_array($result);
         $subprojectid = $row['id'];
         $subprojectname = $row['name'];
         $subprojectpath = $row['path'];
         // Find the sibling build that performed this SubProject.
         $siblingBuild = new Build();
         $query = 'SELECT b.id FROM build AS b
             INNER JOIN subproject2build AS sp2b ON (sp2b.buildid=b.id)
             WHERE b.parentid=
             (SELECT parentid FROM build WHERE id=' . $this->Build->Id . ")\n                AND sp2b.subprojectid={$subprojectid}";
         $row = pdo_single_row_query($query);
         if ($row && array_key_exists('id', $row)) {
             $buildid = $row['id'];
             $siblingBuild->Id = $buildid;
             $siblingBuild->FillFromId($buildid);
         } else {
             // Build doesn't exist yet, add it here.
             $siblingBuild->Name = $this->Build->Name;
             $siblingBuild->ProjectId = $this->ProjectId;
             $siblingBuild->SiteId = $this->Build->SiteId;
             $siblingBuild->SetParentId($this->Build->GetParentId());
             $siblingBuild->SetStamp($this->Build->GetStamp());
             $siblingBuild->SetSubProject($subprojectname);
             $siblingBuild->StartTime = $this->Build->StartTime;
             $siblingBuild->EndTime = $this->Build->EndTime;
             $siblingBuild->SubmitTime = gmdate(FMT_DATETIME);
             add_build($siblingBuild, 0);
             $buildid = $siblingBuild->Id;
         }
         $coverageFileLog->Build = $siblingBuild;
         // Remove any part of the file path that comes before
         // the subproject path.
         $path = substr($path, strpos($path, $subprojectpath));
         // Replace the subproject path with '.'
         $path = substr_replace($path, '.', 0, strlen($subprojectpath));
     } else {
         // If this source file isn't from the source or binary directory
         // we shouldn't include it in our coverage report.
         if (!empty($this->SubProjectPath) && strpos($path, $this->SubProjectPath) !== false) {
             $path = substr($path, strpos($path, $this->SubProjectPath));
             $path = substr_replace($path, '.', 0, strlen($this->SubProjectPath));
         } elseif (strpos($path, $this->SourceDirectory) !== false) {
             $path = str_replace($this->SourceDirectory, '.', trim($path));
         } elseif (strpos($path, $this->BinaryDirectory) !== false) {
             $path = str_replace($this->BinaryDirectory, '.', trim($path));
         } else {
             return;
         }
         $coverageFileLog->Build = $this->Build;
     }
     // Get a reference to the coverage summary for this build.
     if ($buildid === $this->Build->Id) {
         $coverageSummary = $this->CoverageSummary;
     } else {
         if (!array_key_exists($buildid, $this->SubProjectSummaries)) {
             $coverageSummary = new CoverageSummary();
             $coverageSummary->BuildId = $buildid;
             $this->SubProjectSummaries[$buildid] = $coverageSummary;
         } else {
             $coverageSummary = $this->SubProjectSummaries[$buildid];
         }
     }
     // Use a regexp to resolve any /../ in this path.
     // We can't use realpath() because we're referencing a path that
     // doesn't exist on the server.
     // For a source file that contains:
     //   #include "src/../include/foo.h"
     // CDash will report the covered file as include/foo.h
     $pattern = "#/[^/]*?/\\.\\./#";
     while (strpos($path, "/../") !== false) {
         $path = preg_replace($pattern, "/", $path, 1);
     }
     $coverageFile->FullPath = trim($path);
     $lineNumber = 0;
     // The lack of rewind is intentional.
     while (!$file->eof()) {
         $gcovLine = $file->current();
         // "Ordinary" entries in a .gcov file take the following format:
         // <lineNumber>: <timesHit>: <source code at that line>
         // So we check if this line matches the format & parse the
         // data out of it if so.
         $fields = explode(':', $gcovLine, 3);
         if (count($fields) > 2) {
             // Separate out delimited values from this line.
             $timesHit = trim($fields[0]);
             $lineNumber = trim($fields[1]);
             $sourceLine = rtrim($fields[2]);
             if ($lineNumber > 0) {
                 $coverageFile->File .= $sourceLine;
                 // cannot be <br/> for backward compatibility.
                 $coverageFile->File .= '<br>';
             }
             // This is how gcov indicates a line of unexecutable code.
             if ($timesHit === '-') {
                 $file->next();
                 continue;
             }
             // This is how gcov indicates an uncovered line.
             if ($timesHit === '#####') {
                 $timesHit = 0;
             }
             $coverageFileLog->AddLine($lineNumber - 1, $timesHit);
             $file->next();
         } else {
             $coveredBranches = 0;
             $uncoveredBranches = 0;
             $throwBranches = 0;
             $fallthroughBranches = 0;
             while (count($fields) < 3 && !$file->eof()) {
                 // Parse branch coverage here.
                 if (substr($gcovLine, 0, 6) === 'branch') {
                     // Figure out whether this branch was covered or not.
                     if (strpos($gcovLine, 'taken 0%') !== false) {
                         $uncoveredBranches += 1;
                     } else {
                         $coveredBranches += 1;
                     }
                     // Also keep track of the different types of branches encountered.
                     if (strpos($gcovLine, '(throw)') !== false) {
                         $throwBranches += 1;
                     } elseif (strpos($gcovLine, '(fallthrough)') !== false) {
                         $fallthroughBranches += 1;
                     }
                 }
                 $file->next();
                 $gcovLine = $file->current();
                 $fields = explode(':', $gcovLine);
             }
             // Don't report branch coverage for this line if we only
             // encountered (throw) and (fallthrough) branches here.
             $totalBranches = $coveredBranches + $uncoveredBranches;
             if ($totalBranches > 0 && $totalBranches > $throwBranches + $fallthroughBranches) {
                 $coverageFileLog->AddBranch($lineNumber - 1, $coveredBranches, $totalBranches);
             }
         }
     }
     // Save these models to the database.
     $coverageFile->TrimLastNewline();
     $coverageFile->Update($buildid);
     $coverageFileLog->BuildId = $buildid;
     $coverageFileLog->FileId = $coverageFile->Id;
     $coverageFileLog->Insert(true);
     // Query the filelog to get how many lines & branches were covered.
     // We do this after inserting the filelog because we want to accurately
     // reflect the union of the current and previously existing results
     // (if any).
     $stats = $coverageFileLog->GetStats();
     $coverage->LocUntested = $stats['locuntested'];
     $coverage->LocTested = $stats['loctested'];
     $coverage->Covered = 1;
     $coverage->BranchesUntested = $stats['branchesuntested'];
     $coverage->BranchesTested = $stats['branchestested'];
     // Add any labels.
     if (array_key_exists($path, $this->Labels)) {
         foreach ($this->Labels[$path] as $labelText) {
             $label = new Label();
             $label->SetText($labelText);
             $coverage->AddLabel($label);
         }
     }
     // Add this Coverage to our summary.
     $coverageSummary->AddCoverage($coverage);
 }
pdo_select_db("{$CDASH_DB_NAME}", $db);
@($projectname = $_GET['project']);
if ($projectname != null) {
    $projectname = htmlspecialchars(pdo_real_escape_string($projectname));
}
@($date = $_GET['date']);
if ($date != null) {
    $date = htmlspecialchars(pdo_real_escape_string($date));
}
$projectid = get_project_id($projectname);
if ($projectid == 0) {
    echo 'Invalid project';
    return;
}
$project = pdo_query("SELECT * FROM project WHERE id='{$projectid}'");
if (pdo_num_rows($project) > 0) {
    $project_array = pdo_fetch_array($project);
    $svnurl = make_cdash_url(htmlentities($project_array['cvsurl']));
    $homeurl = make_cdash_url(htmlentities($project_array['homeurl']));
    $bugurl = make_cdash_url(htmlentities($project_array['bugtrackerurl']));
    $googletracker = htmlentities($project_array['googletracker']);
    $docurl = make_cdash_url(htmlentities($project_array['documentationurl']));
    $projectpublic = $project_array['public'];
    $projectname = $project_array['name'];
} else {
    $projectname = 'NA';
}
checkUserPolicy(@$_SESSION['cdash']['loginid'], $project_array['id']);
$xml = begin_XML_for_XSLT();
$xml .= '<title>CDash - SubProject dependencies Graph - ' . $projectname . '</title>';
list($previousdate, $currentstarttime, $nextdate) = get_dates($date, $project_array['nightlytime']);
示例#27
0
 function FillFromUserId()
 {
     if (!$this->ProjectId) {
         add_log('ProjectId not set', "UserProject FillFromUserId()", LOG_ERR, $this->ProjectId, 0, CDASH_OBJECT_USER, $this->UserId);
         return false;
     }
     if (!$this->UserId) {
         add_log('UserId not set', "UserProject FillFromUserId()", LOG_ERR, $this->ProjectId, 0, CDASH_OBJECT_USER, $this->UserId);
         return false;
     }
     $sql = "SELECT emailcategory,emailsuccess\n               FROM user2project\n               WHERE projectid=" . qnum($this->ProjectId) . "\n               AND userid=" . qnum($this->UserId) . "\n               AND emailtype>0";
     $user = pdo_query($sql);
     if (!$user) {
         add_last_sql_error("UserProject FillFromRepositoryCredential");
         return false;
     }
     if (pdo_num_rows($user) == 0) {
         return false;
     }
     $user_array = pdo_fetch_array($user);
     $this->EmailCategory = $user_array['emailcategory'];
     $this->EmailSuccess = $user_array['emailsuccess'];
     return true;
 }
示例#28
0
        $xml .= add_XML_value('description', stripslashes($siteinformation_array['description']));
        $xml .= add_XML_value('processoris64bits', $siteinformation_array['processoris64bits']);
        $xml .= add_XML_value('processorvendor', $siteinformation_array['processorvendor']);
        $xml .= add_XML_value('processorvendorid', $siteinformation_array['processorvendorid']);
        $xml .= add_XML_value('processorfamilyid', $siteinformation_array['processorfamilyid']);
        $xml .= add_XML_value('processormodelid', $siteinformation_array['processormodelid']);
        $xml .= add_XML_value('processorcachesize', $siteinformation_array['processorcachesize']);
        $xml .= add_XML_value('numberlogicalcpus', $siteinformation_array['numberlogicalcpus']);
        $xml .= add_XML_value('numberphysicalcpus', $siteinformation_array['numberphysicalcpus']);
        $xml .= add_XML_value('totalvirtualmemory', $siteinformation_array['totalvirtualmemory']);
        $xml .= add_XML_value('totalphysicalmemory', $siteinformation_array['totalphysicalmemory']);
        $xml .= add_XML_value('logicalprocessorsperphysical', $siteinformation_array['logicalprocessorsperphysical']);
        $xml .= add_XML_value('processorclockfrequency', $siteinformation_array['processorclockfrequency']);
        $xml .= add_XML_value('ip', $site_array['ip']);
        $xml .= add_XML_value('latitude', $site_array['latitude']);
        $xml .= add_XML_value('longitude', $site_array['longitude']);
        $xml .= add_XML_value('outoforder', $site_array['outoforder']);
        $xml .= '</site>';
        $user2site = pdo_query("SELECT su.userid FROM site2user AS su,user2project AS up\n                            WHERE su.userid=up.userid AND up.role>0 AND su.siteid='{$siteid}' and su.userid='{$userid}'");
        echo pdo_error();
        if (pdo_num_rows($user2site) == 0) {
            $xml .= add_XML_value('siteclaimed', '0');
        } else {
            $xml .= add_XML_value('siteclaimed', '1');
        }
        $xml .= '</user>';
    }
    $xml .= '</cdash>';
    // Now doing the xslt transition
    generate_XSLT($xml, 'editSite');
}
示例#29
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;
}
示例#30
0
 function UpdateAllowedProjects($projectNames)
 {
     if (!$this->Id) {
         add_log("ClientSite::UpdateAllowedProjects()", "Id not set");
         return;
     }
     pdo_query("DELETE FROM client_site2project WHERE siteid=" . qnum($this->Id));
     foreach ($projectNames as $projectName) {
         $projectid = 0;
         $projectName = pdo_real_escape_string($projectName);
         $project = pdo_query("SELECT id FROM project WHERE name='{$projectName}'");
         if (pdo_num_rows($project) > 0) {
             $project_array = pdo_fetch_array($project);
             $projectid = $project_array["id"];
         }
         if (!$projectid) {
             add_log("ClientSite::UpdateAllowedProjects()", "Invalid project name given: {$projectName}");
             continue;
         }
         $sql = "INSERT INTO client_site2project (siteid,projectid) VALUES ('" . $this->Id . "','" . $projectid . "')";
         pdo_query($sql);
         add_last_sql_error("clientSite::UpdateAllowedProjects()");
     }
 }