function SetText($text) { if ($this->ProjectId == -1) { echo "Banner::SetText(): no ProjectId specified"; return false; } $this->Text = pdo_real_escape_string($text); // Check if the project is already if ($this->Exists()) { // Update the project $query = "UPDATE banner SET"; $query .= " text='" . $this->Text . "'"; $query .= " WHERE projectid='" . $this->ProjectId . "'"; if (!pdo_query($query)) { add_last_sql_error("Banner:SetText", $this->ProjectId); echo $query; return false; } } else { $query = "INSERT INTO banner (projectid,text)\n VALUES (" . qnum($this->ProjectId) . ",'" . $this->Text . "')"; if (!pdo_query($query)) { add_last_sql_error("Banner:SetText", $this->ProjectId); echo $query; return false; } } return true; }
/** Get the number of tests that are failing */ function GetNumberOfFailures($checktesttiming, $testtimemaxstatus) { if (!$this->BuildId) { echo "BuildTest::GetNumberOfFailures(): BuildId not set"; return false; } $sql = "SELECT testfailed,testnotrun,testtimestatusfailed FROM build WHERE id=" . qnum($this->BuildId); $query = pdo_query($sql); if (!$query) { add_last_sql_error("BuildTest:GetNumberOfFailures", 0, $this->BuildId); return false; } $nfail_array = pdo_fetch_array($query); $sumerrors = 0; if ($nfail_array['testfailed'] > 0) { $sumerrors += $nfail_array['testfailed']; } if ($nfail_array['testnotrun'] > 0) { $sumerrors += $nfail_array['testnotrun']; } // Find if the build has any test failings if ($checktesttiming) { if ($nfail_array['testtimestatusfailed'] > 0) { $sumerrors += $nfail_array['testtimestatusfailed']; } } return $sumerrors; }
/** Update the content of the file */ function Insert() { if (!$this->BuildId || !is_numeric($this->BuildId)) { add_log("BuildId not set", "CoverageFileLog::Insert()", LOG_ERR, 0, $this->BuildId, CDASH_OBJECT_COVERAGE, $this->FileId); return false; } if (!$this->FileId || !is_numeric($this->FileId)) { add_log("FileId not set", "CoverageFileLog::Insert()", LOG_ERR, 0, $this->BuildId, CDASH_OBJECT_COVERAGE, $this->FileId); return false; } $log = ''; foreach ($this->Lines as $lineNumber => $code) { $log .= $lineNumber . ':' . $code . ';'; } foreach ($this->Branches as $lineNumber => $code) { $log .= 'b' . $lineNumber . ':' . $code . ';'; } if ($log != '') { $sql = "INSERT INTO coveragefilelog (buildid,fileid,log) VALUES "; $sql .= "(" . qnum($this->BuildId) . "," . qnum($this->FileId) . ",'" . $log . "')"; pdo_query($sql); add_last_sql_error("CoverageFileLog::Insert()"); } return true; }
/** Save in the database */ function Save() { if (!$this->BuildId) { echo "BuildConfigureErrorDiff::Save(): BuildId not set"; return false; } if ($this->Exists()) { // Update $query = "UPDATE configureerrordiff SET"; $query .= " type=" . qnum($this->Type); $query .= ",difference=" . qnum($this->Difference); $query .= " WHERE buildid=" . qnum($this->BuildId); if (!pdo_query($query)) { add_last_sql_error("BuildConfigureErrorDiff:Update", 0, $this->BuildId); return false; } } else { $query = "INSERT INTO configureerrordiff (buildid,type,difference)\n VALUES (" . qnum($this->BuildId) . "," . qnum($this->Type) . "," . qnum($this->Difference) . ")"; if (!pdo_query($query)) { add_last_sql_error("BuildConfigureErrorDiff:Create", 0, $this->BuildId); return false; } } return true; }
/** Get all the authors of a file */ public function GetAuthors($filename, $onlylast = false) { if (!$this->ProjectId) { echo 'DailyUpdate::GetAuthors(): ProjectId is not set<br>'; return false; } // Check if the note already exists $filename = pdo_real_escape_string($filename); // Remove if (substr($filename, 0, 2) == './') { $filename = substr($filename, 2); } $sql = ''; if ($onlylast) { $sql = ' ORDER BY dailyupdate.id DESC LIMIT 1'; } $query = pdo_query('SELECT DISTINCT up.userid,dailyupdate.id FROM user2project AS up,user2repository AS ur,dailyupdatefile,dailyupdate WHERE dailyupdatefile.dailyupdateid=dailyupdate.id AND dailyupdate.projectid=up.projectid AND ur.credential=dailyupdatefile.author AND up.projectid=' . qnum($this->ProjectId) . ' AND up.userid=ur.userid AND (ur.projectid=0 OR ur.projectid=' . qnum($this->ProjectId) . ")\n AND dailyupdatefile.filename LIKE '%" . $filename . "'" . $sql); if (!$query) { add_last_sql_error('DailyUpdate GetAuthors', $this->ProjectId); return false; } $authorids = array(); while ($query_array = pdo_fetch_array($query)) { $authorids[] = $query_array['userid']; } return $authorids; }
/** Save in the database */ public function Save() { if (!$this->BuildId) { echo 'BuildConfigureErrorDiff::Save(): BuildId not set'; return false; } if ($this->Exists()) { // Update $query = 'UPDATE configureerrordiff SET'; $query .= ' type=' . qnum($this->Type); $query .= ',difference=' . qnum($this->Difference); $query .= ' WHERE buildid=' . qnum($this->BuildId); if (!pdo_query($query)) { add_last_sql_error('BuildConfigureErrorDiff:Update', 0, $this->BuildId); return false; } } else { // insert $query = 'INSERT INTO configureerrordiff (buildid,type,difference) VALUES (' . qnum($this->BuildId) . ',' . qnum($this->Type) . ',' . qnum($this->Difference) . ')'; if (!pdo_query($query)) { add_last_sql_error('BuildConfigureErrorDiff:Create', 0, $this->BuildId); return false; } } return true; }
/** Remove the first builds that are at the beginning of the queue */ function removeFirstBuilds($projectid, $days, $maxbuilds, $force = false) { require 'config/config.php'; require_once 'include/pdo.php'; require_once 'include/common.php'; @set_time_limit(0); if (!$force && !isset($CDASH_AUTOREMOVE_BUILDS)) { return; } if (!$force && $CDASH_AUTOREMOVE_BUILDS != '1') { return; } if ($days < 2) { return; } // First remove the builds with the wrong date $currentdate = time() - 3600 * 24 * $days; $startdate = date(FMT_DATETIME, $currentdate); add_log('about to query for builds to remove', 'removeFirstBuilds'); $builds = pdo_query("SELECT id FROM build\n WHERE parentid IN (0, -1) AND\n starttime<'{$startdate}' AND\n projectid=" . qnum($projectid) . "\n ORDER BY starttime ASC LIMIT {$maxbuilds}"); add_last_sql_error('dailyupdates::removeFirstBuilds'); $buildids = array(); while ($builds_array = pdo_fetch_array($builds)) { $buildids[] = $builds_array['id']; } $s = 'removing old buildids for projectid: ' . $projectid; add_log($s, 'removeFirstBuilds'); echo ' -- ' . $s . "\n"; // for "interactive" command line feedback remove_build($buildids); // Remove any job schedules that are older than our cutoff date // and not due to repeat again. require_once 'models/constants.php'; require_once 'models/clientjobschedule.php'; $sql = 'SELECT scheduleid FROM client_job AS cj LEFT JOIN client_jobschedule AS cjs ON cj.scheduleid = cjs.id WHERE cj.status > ' . CDASH_JOB_RUNNING . "\n AND cjs.projectid={$projectid} AND cj.startdate < '{$startdate}'\n AND (cjs.repeattime = 0.00 OR\n (cjs.enddate < '{$startdate}' AND cjs.enddate != '1980-01-01 00:00:00'))"; $job_schedules = pdo_query($sql); while ($job_schedule = pdo_fetch_array($job_schedules)) { $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->Id = $job_schedule['scheduleid']; $ClientJobSchedule->Remove(); } // Remove any jobs that are older than our cutoff date. // This occurs when a job schedule is set to continue repeating, but // some of its past runs are older than our autoremove threshold. require_once 'models/clientjob.php'; $sql = 'SELECT cj.id FROM client_job AS cj LEFT JOIN client_jobschedule AS cjs ON cj.scheduleid = cjs.id WHERE cj.status > ' . CDASH_JOB_RUNNING . "\n AND cjs.projectid={$projectid} AND cj.startdate < '{$startdate}'"; $jobs = pdo_query($sql); while ($job = pdo_fetch_array($jobs)) { $ClientJob = new ClientJob(); $ClientJob->Id = $job['id']; $ClientJob->Remove(); } }
/** Get version */ function GetVersion() { if (!$this->Id) { add_log("ClientOS::GetVersion()", "Id not set"); return; } $name = pdo_query("SELECT version FROM client_os WHERE id=" . qnum($this->Id)); $row = pdo_fetch_array($name); return $row[0]; }
/** Get version */ public function GetVersion() { if (!$this->Id) { add_log('ClientOS::GetVersion()', 'Id not set'); return; } $name = pdo_query('SELECT version FROM client_os WHERE id=' . qnum($this->Id)); $row = pdo_fetch_array($name); return $row[0]; }
/** Return whether or not a CoverageSummaryDiff exists for this build. */ public function Exists() { if (!$this->BuildId) { return false; } $exists_result = pdo_single_row_query('SELECT COUNT(1) AS numrows FROM coveragesummarydiff WHERE buildid=' . qnum($this->BuildId)); if ($exists_result && array_key_exists('numrows', $exists_result)) { $numrows = $exists_result['numrows']; if ($numrows > 0) { return true; } } return false; }
/** 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; } }
function Insert() { if (strlen($this->DynamicAnalysisId) == 0) { echo "DynamicAnalysisDefect::Insert DynamicAnalysisId not set"; return false; } $this->Type = pdo_real_escape_string($this->Type); $this->Value = pdo_real_escape_string($this->Value); $this->DynamicAnalysisId = pdo_real_escape_string($this->DynamicAnalysisId); $query = "INSERT INTO dynamicanalysisdefect (dynamicanalysisid,type,value)\n VALUES (" . qnum($this->DynamicAnalysisId) . ",'{$this->Type}','{$this->Value}')"; if (!pdo_query($query)) { add_last_sql_error("DynamicAnalysisDefect Insert"); return false; } return true; }
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; } }
/** Return the name of a build */ function GetFiles() { if (!$this->BuildId) { echo "Coverage GetFiles(): BuildId not set"; return false; } $fileids = array(); $coverage = pdo_query("SELECT fileid FROM coverage WHERE buildid=" . qnum($this->BuildId)); if (!$coverage) { add_last_sql_error("Coverage GetFiles"); return false; } while ($coverage_array = pdo_fetch_array($coverage)) { $fileids[] = $coverage_array['fileid']; } return $fileids; }
public function Insert() { if (!$this->BuildId) { echo 'BuildError::Insert(): BuildId not set<br>'; return false; } $text = pdo_real_escape_string($this->Text); if (strlen($this->PreContext) == 0) { $precontext = 'NULL'; } else { $precontext = "'" . pdo_real_escape_string($this->PreContext) . "'"; } if (strlen($this->PostContext) == 0) { $postcontext = 'NULL'; } else { $postcontext = "'" . pdo_real_escape_string($this->PostContext) . "'"; } if (empty($this->SourceLine)) { $this->SourceLine = 0; } if (empty($this->RepeatCount)) { $this->RepeatCount = 0; } $crc32 = 0; // Compute the crc32 if ($this->SourceLine == 0) { $crc32 = crc32($text); // no need for precontext or postcontext, this doesn't work for parallel build } else { $crc32 = crc32($text . $this->SourceFile . $this->SourceLine); // some warning can be on the same line } $query = 'INSERT INTO builderror (buildid,type,logline,text,sourcefile,sourceline,precontext, postcontext,repeatcount,newstatus,crc32) VALUES (' . qnum($this->BuildId) . ',' . qnum($this->Type) . ',' . qnum($this->LogLine) . ",'{$text}','{$this->SourceFile}'," . qnum($this->SourceLine) . ', ' . $precontext . ',' . $postcontext . ',' . qnum($this->RepeatCount) . ',0,' . qnum($crc32) . ')'; if (!pdo_query($query)) { add_last_sql_error('BuildError Insert', 0, $this->BuildId); return false; } return true; }
/** Save in the database */ function Save() { if (!$this->BuildId || !is_numeric($this->BuildId)) { echo "BuildConfigureError::Save(): BuildId not set"; return false; } if (!$this->Type || !is_numeric($this->Type)) { echo "BuildConfigureError::Save(): Type not set"; return false; } if (!$this->Exists()) { $text = pdo_real_escape_string($this->Text); $query = "INSERT INTO configureerror (buildid,type,text)\n VALUES (" . qnum($this->BuildId) . "," . qnum($this->Type) . ",'{$text}')"; if (!pdo_query($query)) { add_last_sql_error("BuildConfigureError:Save", 0, $this->BuildId); return false; } } return true; }
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; }
/** Delete unused libraries */ function DeleteUnused($libraries) { if (!$this->SiteId) { add_log("ClientLibrary::DeleteUnused()", "SiteId not set"); return; } // Delete the old libraries $query = pdo_query("SELECT name,path,version,include,libraryid FROM client_library,client_site2library\n WHERE client_library.id=client_site2library.libraryid\n AND siteid=" . qnum($this->SiteId)); add_last_sql_error("ClientLibrary::DeleteUnused()"); while ($query_array = pdo_fetch_array($query)) { $delete = 1; foreach ($libraries as $library) { if ($library['name'] == $query_array['name'] && $library['version'] == $query_array['version'] && $library['path'] == $query_array['path'] && $library['include'] == $query_array['include']) { $delete = 0; break; } } if ($delete) { pdo_query("DELETE FROM client_site2library WHERE libraryid='" . $query_array['libraryid'] . "' AND path='" . $query_array['path'] . "' AND include='" . $query_array['include'] . "' AND siteid=" . qnum($this->SiteId)); add_last_sql_error("ClientLibrary::DeleteUnused()"); } } // Delete the client_compiler not attached to anything pdo_query("DELETE FROM client_library WHERE id NOT IN(SELECT libraryid AS id FROM client_site2library)"); }
function rest_post() { global $projectid; if (isset($_POST['newsubproject'])) { // Create a new subproject $SubProject = new SubProject(); $SubProject->SetProjectId($projectid); $newSubProject = htmlspecialchars(pdo_real_escape_string($_POST['newsubproject'])); $SubProject->SetName($newSubProject); if (isset($_POST['group'])) { $SubProject->SetGroup(htmlspecialchars(pdo_real_escape_string($_POST['group']))); } $SubProject->Save(); // Respond with a JSON representation of this new subproject $response = array(); $response['id'] = $SubProject->GetId(); $response['name'] = $SubProject->GetName(); $response['group'] = $SubProject->GetGroupId(); echo json_encode(cast_data_for_JSON($response)); return; } if (isset($_POST['newgroup'])) { // Create a new group $Group = new SubProjectGroup(); $Group->SetProjectId($projectid); $newGroup = htmlspecialchars(pdo_real_escape_string($_POST['newgroup'])); $Group->SetName($newGroup); if (isset($_POST['isdefault'])) { $Group->SetIsDefault($_POST['isdefault']); } $Group->SetCoverageThreshold(pdo_real_escape_numeric($_POST['threshold'])); $Group->Save(); // Respond with a JSON representation of this new group $response = array(); $response['id'] = $Group->GetId(); $response['name'] = $Group->GetName(); $response['is_default'] = $Group->GetIsDefault(); $response['coverage_threshold'] = $Group->GetCoverageThreshold(); echo json_encode(cast_data_for_JSON($response)); } if (isset($_POST['newLayout'])) { // Update the order of the SubProject groups. $inputRows = $_POST['newLayout']; foreach ($inputRows as $inputRow) { $id = qnum(pdo_real_escape_numeric($inputRow['id'])); $position = qnum(pdo_real_escape_numeric($inputRow['position'])); $query = "UPDATE subprojectgroup SET position={$position} WHERE id={$id}"; pdo_query($query); add_last_sql_error('API::subproject::newLayout::INSERT', $projectid); } return; } }
/** Get the text of a label */ function GetText() { return pdo_get_field_value("SELECT text FROM label WHERE id=" . qnum($this->Id), "text", 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']; }
function rest_get() { global $projectid; $subprojectid = get_subprojectid(); if ($subprojectid === false) { return; } $start = microtime_float(); $response = begin_JSON_response(); $response['projectid'] = $projectid; $response['subprojectid'] = $subprojectid; $SubProject = new SubProject(); $SubProject->SetId($subprojectid); $response['name'] = $SubProject->GetName(); $response['group'] = $SubProject->GetGroupId(); $query = pdo_query("\n SELECT id, name FROM subproject WHERE projectid=" . qnum($projectid) . "\n AND endtime='1980-01-01 00:00:00'"); if (!$query) { add_last_sql_error("getSubProject Select"); return false; } $dependencies = $SubProject->GetDependencies(); $dependencies_response = array(); $available_dependencies_response = array(); while ($row = pdo_fetch_array($query)) { if ($row['id'] == $subprojectid) { continue; } if (is_array($dependencies) && in_array($row['id'], $dependencies)) { $dep = array(); $dep['id'] = $row['id']; $dep['name'] = $row['name']; $dependencies_response[] = $dep; } else { $avail = array(); $avail['id'] = $row['id']; $avail['name'] = $row['name']; $available_dependencies_response[] = $avail; } } $response['dependencies'] = $dependencies_response; $response['available_dependencies'] = $available_dependencies_response; $end = microtime_float(); $response['generationtime'] = round($end - $start, 3); echo json_encode($response); }
/** 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; }
/** function to send email to site maintainers when the update * step fails */ function send_update_email($handler, $projectid) { include 'config/config.php'; include_once 'include/common.php'; require_once 'include/pdo.php'; require_once 'models/build.php'; require_once 'models/project.php'; require_once 'models/buildgroup.php'; $Project = new Project(); $Project->Id = $projectid; $Project->Fill(); // If we shouldn't sent any emails we stop if ($Project->EmailBrokenSubmission == 0) { return; } // If the handler has a buildid (it should), we use it if (isset($handler->BuildId) && $handler->BuildId > 0) { $buildid = $handler->BuildId; } else { // Get the build id $name = $handler->getBuildName(); $stamp = $handler->getBuildStamp(); $sitename = $handler->getSiteName(); $buildid = get_build_id($name, $stamp, $projectid, $sitename); } if ($buildid < 0) { return; } // Check if the group as no email $Build = new Build(); $Build->Id = $buildid; $groupid = $Build->GetGroup(); $BuildGroup = new BuildGroup(); $BuildGroup->SetId($groupid); // If we specified no email we stop here if ($BuildGroup->GetSummaryEmail() == 2) { return; } // Send out update errors to site maintainers $update_errors = check_email_update_errors($buildid); if ($update_errors['errors']) { // Find the site maintainer(s) $sitename = $handler->getSiteName(); $siteid = $handler->getSiteId(); $to_address = ''; $email_addresses = pdo_query('SELECT email FROM ' . qid('user') . ',site2user WHERE ' . qid('user') . ".id=site2user.userid AND site2user.siteid='{$siteid}'"); while ($email_addresses_array = pdo_fetch_array($email_addresses)) { if ($to_address != '') { $to_address .= ', '; } $to_address .= $email_addresses_array['email']; } if ($to_address != '') { $serverURI = get_server_URI(); // In the case of asynchronous submission, the serverURI contains /cdash // we need to remove it if ($CDASH_BASE_URL == '' && $CDASH_ASYNCHRONOUS_SUBMISSION) { $serverURI = substr($serverURI, 0, strrpos($serverURI, '/')); } // Generate the email to send $subject = 'CDash [' . $Project->Name . '] - Update Errors for ' . $sitename; $update_info = pdo_query('SELECT command,status FROM buildupdate AS u,build2update AS b2u WHERE b2u.updateid=u.id AND b2u.buildid=' . qnum($buildid)); $update_array = pdo_fetch_array($update_info); $body = "{$sitename} has encountered errors during the Update step and you have been identified as the maintainer of this site.\n\n"; $body .= "*Update Errors*\n"; $body .= 'Status: ' . $update_array['status'] . ' (' . $serverURI . '/viewUpdate.php?buildid=' . $buildid . ")\n"; if ($CDASH_TESTING_MODE) { add_log($to_address, 'TESTING: EMAIL', LOG_DEBUG); add_log($subject, 'TESTING: EMAILTITLE', LOG_DEBUG); add_log($body, 'TESTING: EMAILBODY', LOG_DEBUG); } else { if (cdashmail("{$to_address}", $subject, $body)) { add_log('email sent to: ' . $to_address, 'sendEmailExpectedBuilds'); return; } else { add_log('cannot send email to: ' . $to_address, 'sendEmailExpectedBuilds'); } } } } }
/** * Update the tally of configure errors & warnings for this build's * parent. **/ function UpdateParentConfigureNumbers($newWarnings, $newErrors) { $this->ParentId = $this->GetParentBuildId(); if ($this->ParentId < 1) { return; } $numErrors = 0; $numWarnings = 0; $parent = pdo_single_row_query("SELECT configureerrors, configurewarnings\n FROM build WHERE id=" . qnum($this->ParentId)); // Don't let the -1 default value screw up our math. if ($parent['configureerrors'] == -1) { $parent['configureerrors'] = 0; } if ($parent['configurewarnings'] == -1) { $parent['configurewarnings'] = 0; } $numErrors = $newErrors + $parent['configureerrors']; $numWarnings = $newWarnings + $parent['configurewarnings']; pdo_query("UPDATE build SET configureerrors='{$numErrors}',\n configurewarnings='{$numWarnings}'\n WHERE id=" . qnum($this->ParentId)); add_last_sql_error("Build:UpdateParentConfigureNumbers", $this->ProjectId, $this->Id); }
} } if (!empty($osids[0])) { $extrasql .= ")"; } // Libraries (should have all of them) if (!empty($libraryids[0])) { $tables .= ",client_site2library "; $extrasql .= " AND client_site2library.siteid=s.id AND ("; } foreach ($libraryids as $key => $libraryid) { if (!empty($libraryid)) { if ($key > 0) { $extrasql .= " AND "; } $extrasql .= "client_site2library.libraryid=" . qnum($libraryid); } } if (!empty($libraryids[0])) { $extrasql .= ")"; } // Check for the last 5 minutes $now = date(FMT_DATETIMESTD, time() - 5 * 60); $sql = "SELECT COUNT(DISTINCT s.id) FROM client_site AS s, client_os AS os, \n client_site2cmake,client_site2compiler" . $tables . "\n WHERE s.osid=os.id AND client_site2cmake.siteid=s.id \n AND client_site2compiler.siteid=s.id " . $extrasql . " AND s.lastping>'" . $now . "'"; $query = pdo_query($sql); echo pdo_error(); $query_array = pdo_fetch_array($query); if ($query_array[0] == 0) { echo "<br/><b>* No site matching these settings is currently available.</b><br/>"; } else { echo "<br/><b>* " . $query_array[0] . "</b> site";
add_site2user($siteid, $userid); } else { remove_site2user($siteid, $userid); } } $xml .= add_XML_value('warning', 'Claimed sites updated.'); } @($claimsite = $_POST['claimsite']); @($claimsiteid = $_POST['claimsiteid']); if ($claimsite) { add_site2user($claimsiteid, $userid); } @($updatesite = $_POST['updatesite']); @($geolocation = $_POST['geolocation']); if (isset($_POST['unclaimsite']) && isset($_GET['siteid'])) { pdo_query('DELETE FROM site2user WHERE siteid=' . qnum(pdo_real_escape_numeric($_GET['siteid'])) . ' AND userid=' . qnum($userid)); echo "<script language=\"javascript\">window.location='user.php'</script>"; return; } if ($updatesite || $geolocation) { $site_name = $_POST['site_name']; $site_description = $_POST['site_description']; $site_processoris64bits = $_POST['site_processoris64bits']; $site_processorvendor = $_POST['site_processorvendor']; $site_processorvendorid = $_POST['site_processorvendorid']; $site_processorfamilyid = $_POST['site_processorfamilyid']; $site_processormodelid = $_POST['site_processormodelid']; $site_processorcachesize = $_POST['site_processorcachesize']; $site_numberlogicalcpus = $_POST['site_numberlogicalcpus']; $site_numberphysicalcpus = $_POST['site_numberphysicalcpus']; $site_totalvirtualmemory = $_POST['site_totalvirtualmemory'];
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()"); } }
/** Get the labels given a projectid and userid */ public function GetLabels() { if (empty($this->ProjectId)) { echo 'LabelEmail GetLabels(): ProjectId not set'; return false; } if (empty($this->UserId)) { echo 'LabelEmail GetLabels(): UserId not set'; return false; } $labels = pdo_query('SELECT labelid FROM labelemail WHERE projectid=' . qnum($this->ProjectId) . ' AND userid=' . qnum($this->UserId)); if (!$labels) { add_last_sql_error('LabelEmail GetLabels'); return false; } $labelids = array(); while ($labels_array = pdo_fetch_array($labels)) { $labelids[] = $labels_array['labelid']; } return $labelids; }
/** Get the projects associated with the user */ function GetProjects() { if (!$this->UserId) { echo "UserProject GetProjects(): UserId not set"; return false; } $project = pdo_query("SELECT projectid FROM user2project WHERE userid=" . qnum($this->UserId)); if (!$project) { add_last_sql_error("UserProject GetProjects"); return false; } $projectids = array(); while ($project_array = pdo_fetch_array($project)) { $projectids[] = $project_array['projectid']; } return $projectids; }