示例#1
0
 /** Schedule a build */
 private function ScheduleBuild()
 {
     include "cdash/config.php";
     include_once 'cdash/common.php';
     include_once "models/clientjobschedule.php";
     include_once "models/clientos.php";
     include_once "models/clientcmake.php";
     include_once "models/clientcompiler.php";
     include_once "models/clientlibrary.php";
     if (!isset($this->Parameters['token'])) {
         return array('status' => false, 'message' => 'You must specify a token parameter.');
     }
     $clientJobSchedule = new ClientJobSchedule();
     $status = array();
     $status['scheduled'] = 0;
     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.');
     }
     $clientJobSchedule->ProjectId = $projectid;
     // Perform the authentication (make sure user has project admin priviledges)
     if (!web_api_authenticate($projectid, $this->Parameters['token'])) {
         return array('status' => false, 'message' => 'Invalid API token.');
     }
     // We would need a user login/password at some point
     $clientJobSchedule->UserId = '1';
     if (isset($this->Parameters['userid'])) {
         $clientJobSchedule->UserId = pdo_real_escape_string($this->Parameters['userid']);
     }
     // Experimental: 0
     // Nightly: 1
     // Continuous: 2
     $clientJobSchedule->Type = 0;
     if (isset($this->Parameters['type'])) {
         $clientJobSchedule->Type = pdo_real_escape_string($this->Parameters['type']);
     }
     if (!isset($this->Parameters['repository'])) {
         return array('status' => false, 'message' => 'You must specify a repository parameter.');
     }
     $clientJobSchedule->Repository = pdo_real_escape_string($this->Parameters['repository']);
     if (isset($this->Parameters['module'])) {
         $clientJobSchedule->Module = pdo_real_escape_string($this->Parameters['module']);
     }
     if (isset($this->Parameters['tag'])) {
         $clientJobSchedule->Tag = pdo_real_escape_string($this->Parameters['tag']);
     }
     if (isset($this->Parameters['suffix'])) {
         $clientJobSchedule->BuildNameSuffix = pdo_real_escape_string($this->Parameters['suffix']);
     }
     // Build Configuration
     // Debug: 0
     // Release: 1
     // RelWithDebInfo: 2
     // MinSizeRel: 3
     $clientJobSchedule->BuildConfiguration = 0;
     if (isset($this->Parameters['configuration'])) {
         $clientJobSchedule->BuildConfiguration = pdo_real_escape_string($this->Parameters['configuration']);
     }
     $clientJobSchedule->StartDate = date("Y-m-d H:i:s");
     $clientJobSchedule->StartTime = date("Y-m-d H:i:s");
     $clientJobSchedule->EndDate = '1980-01-01 00:00:00';
     $clientJobSchedule->RepeatTime = 0;
     // No repeat
     $clientJobSchedule->Enable = 1;
     $clientJobSchedule->Save();
     // Remove everything and add them back in
     $clientJobSchedule->RemoveDependencies();
     // Set CMake
     if (isset($this->Parameters['cmakeversion'])) {
         $cmakeversion = pdo_real_escape_string($this->Parameters['cmakeversion']);
         $ClientCMake = new ClientCMake();
         $ClientCMake->Version = $cmakeversion;
         $cmakeid = $ClientCMake->GetIdFromVersion();
         if (!empty($cmakeid)) {
             $clientJobSchedule->AddCMake($cmakeid);
         }
     }
     // Set the site id (for now only one)
     if (isset($this->Parameters['siteid'])) {
         $siteid = pdo_real_escape_string($this->Parameters['siteid']);
         $clientJobSchedule->AddSite($siteid);
     }
     if (isset($this->Parameters['osname']) || isset($this->Parameters['osversion']) || isset($this->Parameters['osbits'])) {
         $ClientOS = new ClientOS();
         $osname = '';
         $osversion = '';
         $osbits = '';
         if (isset($this->Parameters['osname'])) {
             $osname = $this->Parameters['osname'];
         }
         if (isset($this->Parameters['osversion'])) {
             $osversion = $this->Parameters['osversion'];
         }
         if (isset($this->Parameters['osbits'])) {
             $osbits = $this->Parameters['osbits'];
         }
         $osids = $ClientOS->GetOS($osname, $osversion, $osbits);
         foreach ($osids as $osid) {
             $clientJobSchedule->AddOS($osid);
         }
     }
     if (isset($this->Parameters['compilername']) || isset($this->Parameters['compilerversion'])) {
         $ClientCompiler = new ClientCompiler();
         $compilername = '';
         $compilerversion = '';
         if (isset($this->Parameters['compilername'])) {
             $compilername = $this->Parameters['compilername'];
         }
         if (isset($this->Parameters['compilerversion'])) {
             $compilerversion = $this->Parameters['compilerversion'];
         }
         $compilerids = $ClientCompiler->GetCompiler($compilername, $compilerversion);
         foreach ($compilerids as $compilerid) {
             $clientJobSchedule->AddCompiler($compilerid);
         }
     }
     if (isset($this->Parameters['libraryname']) || isset($this->Parameters['libraryversion'])) {
         $ClientLibrary = new ClientLibrary();
         $libraryname = '';
         $libraryversion = '';
         if (isset($this->Parameters['libraryname'])) {
             $libraryname = $this->Parameters['libraryname'];
         }
         if (isset($this->Parameters['libraryversion'])) {
             $libraryversion = $this->Parameters['libraryversion'];
         }
         $libraryids = $ClientLibrary->GetLibrary($libraryname, $libraryversion);
         foreach ($libraryids as $libraryid) {
             $clientJobSchedule->AddLibrary($libraryid);
         }
     }
     $status['scheduleid'] = $clientJobSchedule->Id;
     $status['scheduled'] = 1;
     $status['status'] = true;
     return $status;
 }
示例#2
0
function client_submit()
{
    include 'config/config.php';
    if (!$CDASH_MANAGE_CLIENTS) {
        return 0;
    }
    include_once 'models/clientsite.php';
    include_once 'models/clientos.php';
    include_once 'models/clientjob.php';
    include_once 'models/clientjobschedule.php';
    include_once 'models/clientcmake.php';
    include_once 'models/clientcompiler.php';
    include_once 'models/clientlibrary.php';
    include 'config/config.php';
    require_once 'include/common.php';
    // Client asks for the site id
    if (isset($_GET['getsiteid'])) {
        if (!isset($_GET['sitename']) || !isset($_GET['systemname'])) {
            echo 'ERROR: sitename or systemname not set';
            return 0;
        }
        $sitename = htmlspecialchars(pdo_real_escape_string($_GET['sitename']));
        $systemname = htmlspecialchars(pdo_real_escape_string($_GET['systemname']));
        // Should get the site id
        $ClientSite = new ClientSite();
        $siteid = $ClientSite->GetId($sitename, $systemname);
        echo $siteid;
        return 1;
    } elseif (isset($_GET['getjob'])) {
        if (!isset($_GET['siteid'])) {
            echo '0';
            return 1;
        }
        if (!$_GET['siteid']) {
            echo '0';
            return 1;
        }
        $ClientJobSchedule = new ClientJobSchedule();
        $ClientJobSchedule->SiteId = pdo_real_escape_numeric($_GET['siteid']);
        $jobid = $ClientJobSchedule->HasJob();
        if ($jobid > 0) {
            // if we have something to do
            echo $ClientJobSchedule->GetCTestScript();
        } else {
            echo '0';
            // send zero to let the client know that nothing is there
        }
        return 1;
    } elseif (isset($_GET['submitinfo'])) {
        if (!isset($_GET['sitename']) || !isset($_GET['systemname'])) {
            echo '0';
            return 1;
        }
        $filehandle = 'php://input';
        $contents = file_get_contents($filehandle);
        $xml = new SimpleXMLElement($contents);
        // Add/Update the OS
        $ClientOS = new ClientOS();
        $ClientOS->Name = $ClientOS->GetPlatformFromName($xml->system->platform);
        $ClientOS->Version = $ClientOS->GetVersionFromName($xml->system->version);
        $ClientOS->Bits = $xml->system->bits;
        $ClientOS->Save();
        // Add/Update the site
        $ClientSite = new ClientSite();
        $ClientSite->Name = htmlspecialchars(pdo_real_escape_string($_GET['sitename']));
        $ClientSite->SystemName = htmlspecialchars(pdo_real_escape_string($_GET['systemname']));
        $ClientSite->Host = 'none';
        $ClientSite->OsId = $ClientOS->Id;
        $ClientSite->BaseDirectory = $xml->system->basedirectory;
        $ClientSite->Save();
        $siteid = $ClientSite->Id;
        // Add/Update the compiler(s)
        $compilers = array();
        foreach ($xml->compiler as $compiler) {
            $ClientCompiler = new ClientCompiler();
            $ClientCompiler->Name = $compiler->name;
            $ClientCompiler->Version = $compiler->version;
            $ClientCompiler->Command = $compiler->command;
            $ClientCompiler->Generator = $compiler->generator;
            $ClientCompiler->SiteId = $siteid;
            $ClientCompiler->Save();
            $comp = array();
            $comp['name'] = $compiler->name;
            $comp['version'] = $compiler->version;
            $comp['command'] = $compiler->command;
            $comp['generator'] = $compiler->generator;
            $compilers[] = $comp;
        }
        $ClientCompiler = new ClientCompiler();
        $ClientCompiler->SiteId = $siteid;
        $ClientCompiler->DeleteUnused($compilers);
        // Add/Update CMake(s)
        $cmakes = array();
        foreach ($xml->cmake as $cmake) {
            $ClientCMake = new ClientCMake();
            $ClientCMake->Version = $cmake->version;
            $ClientCMake->Path = $cmake->path;
            $ClientCMake->SiteId = $siteid;
            $ClientCMake->Save();
            $cm = array();
            $cm['path'] = $cmake->path;
            $cm['version'] = $cmake->version;
            $cmakes[] = $cm;
        }
        $ClientCMake = new ClientCMake();
        $ClientCMake->SiteId = $siteid;
        $ClientCMake->DeleteUnused($cmakes);
        // Add/Update Libraries
        $libraries = array();
        foreach ($xml->library as $library) {
            $ClientLibrary = new ClientLibrary();
            $ClientLibrary->Name = $library->name;
            $ClientLibrary->Path = $library->path;
            $ClientLibrary->Include = $library->include;
            $ClientLibrary->Version = $library->version;
            $ClientLibrary->SiteId = $siteid;
            $ClientLibrary->Save();
            $lib = array();
            $lib['name'] = $library->name;
            $lib['path'] = $library->path;
            $lib['version'] = $library->version;
            $lib['include'] = $library->include;
            $libraries[] = $lib;
        }
        $ClientLibrary = new ClientLibrary();
        $ClientLibrary->SiteId = $siteid;
        $ClientLibrary->DeleteUnused($libraries);
        // Add/Update Programs
        $programs = array();
        foreach ($xml->program as $program) {
            $prog = array();
            $prog['name'] = $program->name;
            $prog['path'] = $program->path;
            $prog['version'] = $program->version;
            $programs[] = $prog;
        }
        $ClientSite->UpdatePrograms($programs);
        // Add/Update the list of allowed projects
        $allowedProjects = array();
        foreach ($xml->allowedproject as $allowedProject) {
            $allowedProjects[] = $allowedProject;
        }
        $ClientSite->UpdateAllowedProjects($allowedProjects);
        return 1;
    } elseif (isset($_GET['jobdone'])) {
        // Mark the job has finished
        if (!isset($_GET['siteid'])) {
            echo '0';
            return 1;
        }
        if (!$_GET['siteid']) {
            echo '0';
            return 1;
        }
        $ClientJob = new ClientJob();
        $ClientJob->SiteId = pdo_real_escape_numeric($_GET['siteid']);
        $ClientJob->SetFinished();
        return 1;
    } elseif (isset($_GET['jobfailed'])) {
        // Mark the job has failed
        if (!isset($_GET['siteid'])) {
            echo '0';
            return 1;
        }
        if (!$_GET['siteid']) {
            echo '0';
            return 1;
        }
        $ClientJob = new ClientJob();
        $ClientJob->SiteId = pdo_real_escape_numeric($_GET['siteid']);
        $ClientJob->SetFailed();
        return 1;
    }
    return 0;
}
示例#3
0
 }
 // Compiler versions
 $Compiler = new ClientCompiler();
 $compilerids = $Compiler->getAll();
 foreach ($compilerids as $compilerid) {
     $xml .= '<compiler>';
     $Compiler->Id = $compilerid;
     $xml .= add_XML_value('name', $Compiler->GetName() . '-' . $Compiler->GetVersion());
     $xml .= add_XML_value('id', $compilerid);
     if (isset($compilers) && array_search($compilerid, $compilers) !== false) {
         $xml .= add_XML_value('selected', '1');
     }
     $xml .= '</compiler>';
 }
 // CMake versions
 $CMake = new ClientCMake();
 $cmakeids = $CMake->getAll();
 foreach ($cmakeids as $cmakeid) {
     $xml .= '<cmake>';
     $CMake->Id = $cmakeid;
     $xml .= add_XML_value('version', $CMake->GetVersion());
     $xml .= add_XML_value('id', $cmakeid);
     if (isset($cmakes) && array_search($cmakeid, $cmakes) !== false) {
         $xml .= add_XML_value('selected', '1');
     }
     $xml .= '</cmake>';
 }
 // Sites
 $Site = new ClientSite();
 $siteids = $Site->GetAllForProject($projectid);
 foreach ($siteids as $siteid) {