/**
  * User attempts to update the given site's certification status. 
  * @param \Site $site
  * @param \CertificationStatus $newCertStatus
  * @param \User $user
  * @param string $reason The reason for this change, max 300 char. 
  * @throws \Exception If access is denied or the change is invalid
  */
 public function editCertificationStatus(\Site $site, \CertificationStatus $newCertStatus, \User $user, $reason)
 {
     //$this->editAuthorization($site, $user);
     require_once __DIR__ . '/Site.php';
     $siteService = new \org\gocdb\services\Site();
     $siteService->setEntityManager($this->em);
     if (count($siteService->authorizeAction(\Action::SITE_EDIT_CERT_STATUS, $site, $user)) == 0) {
         throw new \Exception('You do not have permission to change site certification status');
     }
     // TODO use validate service
     if (empty($reason)) {
         throw new \LogicException('A reason is required');
     }
     if (strlen($reason) > 300) {
         throw new \LogicException('Invalid reason - 300 char max');
     }
     // Admins can do any cert status change, e.g. to undo mistakes.
     if (!$user->isAdmin()) {
         $this->isChangeValid($site, $newCertStatus);
     }
     $oldStatusString = $site->getCertificationStatus()->getName();
     try {
         $this->em->beginTransaction();
         $now = new \DateTime('now', new \DateTimeZone('UTC'));
         // create a new CertStatusLog
         $certLog = new \CertificationStatusLog();
         $certLog->setAddedBy($user->getCertificateDn());
         $certLog->setNewStatus($newCertStatus->getName());
         $certLog->setOldStatus($oldStatusString);
         $certLog->setAddedDate($now);
         $certLog->setReason($reason);
         $this->em->persist($certLog);
         // update our site
         $site->addCertificationStatusLog($certLog);
         $site->setCertificationStatus($newCertStatus);
         $site->setCertificationStatusChangeDate($now);
         $this->em->merge($site);
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $ex) {
         $this->em->getConnection()->rollback();
         $this->em->close();
         throw $ex;
     }
 }
Exemple #2
0
    // then no changes will have occurred and the log will be empty for that Site.
    //
    // Importantly, because the v4 certStatus change log was added AFTER some
    // sites were already added to GOCDB4, the LAST AddedDate does NOT
    // necessarily correspond with the date of the CURRENT certification status.
    // Rather, the date of the CURRENT certStatus in v4 is recorded as
    // a link/linkType object using the dateOn property.
    foreach ($xmlCertStatusChanges as $xmlCertStatusChange) {
        $targetSiteName = (string) $xmlCertStatusChange->SITE;
        // only interested in the current site
        if ($targetSiteName == $doctrineSite->getShortName()) {
            $doctrineCertStatusChangeLog = new \CertificationStatusLog();
            $doctrineCertStatusChangeLog->setAddedBy((string) $xmlCertStatusChange->CHANGED_BY);
            $doctrineCertStatusChangeLog->setOldStatus((string) $xmlCertStatusChange->OLD_STATUS);
            $doctrineCertStatusChangeLog->setNewStatus((string) $xmlCertStatusChange->NEW_STATUS);
            $doctrineCertStatusChangeLog->setReason((string) $xmlCertStatusChange->COMMENT);
            $insertDate = new DateTime("@" . (string) $xmlCertStatusChange->UNIX_TIME);
            $doctrineCertStatusChangeLog->setAddedDate($insertDate);
            $entityManager->persist($doctrineCertStatusChangeLog);
            $doctrineSite->addCertificationStatusLog($doctrineCertStatusChangeLog);
        }
    }
    $entityManager->persist($doctrineSite);
}
// echo "\nPersisting Sites";
// $i = 0;
// foreach($allSites as $site) {
//     $i++;
//     $entityManager->persist($site);
//     // Flush periodically to free memory.
//     if($i % 10000 == 0) {
Exemple #3
0
 /**
  * Adds a site. $values is in the following format:
  * Array
  * (
  *     [Scope] => 2
  *     [Country] => 6
  *     [Timezone] => 1
  *     [ProductionStatus] => 1
  *     [NGI] => 11
  *     [Certification_Status] => 1
  *     [Site] => Array
  *     (
  *                 [SHORT_NAME] => MyTestSite
  *                 [OFFICIAL_NAME] => TestSite
  *                 [HOME_URL] => https://test.host.com
  *                 [GIIS_URL] => ldap://giis_url:234
  *                 [IP_RANGE] => 0.0.0.0/255.255.255.234
  *                 [IP_V6_RANGE] => 0000:0000:0000:0000:0000:0000:0000:0000[/int]
  *                 [LOCATION] => Britain
  *                 [LATITUDE] => 234
  *                 [LONGITUDE] => 234
  *                 [DESCRIPTION] => Test
  *                 [EMAIL] => lcg@rl.ac.uk
  *                 [CONTACTTEL] => +44 01925 603762, +44 01235 44 5010234
  *                 [EMERGENCYTEL] => +44 01925 603762, +44 01235 44 5010, +44 01925 603513234
  *                 [CSIRTEMAIL] => gocdb-admins@mailtalk.ac.uk
  *                 [CSIRTTEL] => +44 01925 603762, +44 01235 44 5010, +44 01925 603513234
  *                 [EMERGENCYEMAIL] => jcasson@234.com
  *                 [HELPDESKEMAIL] => gocdb-admins@mailtalk.ac.uk
  *                 [DOMAIN] => Test.com
  *     )
  * )
  * @param array $values New Site Values
  * @param \User $user User making the request
  */
 public function addSite($values, \User $user = null)
 {
     //Check the portal is not in read only mode, throws exception if it is
     $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user);
     if (is_null($user)) {
         throw new Exception("Unregistered users may not add new sites");
     }
     if (!$user->isAdmin()) {
         $ngiService = new \org\gocdb\services\NGI();
         $ngiService->setEntityManager($this->em);
         $usersNGIs = $ngiService->getNGIsBySupportedAction(\Action::NGI_ADD_SITE, $user);
         if (count($usersNGIs) == 0) {
             throw new \Exception("You do not have permission to add a new site." . " To add a new site you require a managing role over an NGI");
         }
     }
     // do as much validation before starting a new db tx
     // check the site object data is valid
     $this->validate($values['Site'], 'site');
     //check there are the required number of scopes specified
     $this->checkNumberOfScopes($values['Scope_ids']);
     $this->uniqueCheck($values['Site']['SHORT_NAME']);
     // Populate the entity
     try {
         /* Create a PK for this site
          * This is persisted/flushed (but not committed) before the site 
          * so the PK is set by the database.
          * If the site insertion fails the PK can still be rolled back.  
          */
         $this->em->getConnection()->beginTransaction();
         $pk = new \PrimaryKey();
         $this->em->persist($pk);
         // flush synchronizes the in-memory state of managed objects with the database
         // but we can still rollback
         $this->em->flush();
         //$this->em->getConnection()->commit();
         //$this->em->getConnection()->beginTransaction();
         $site = new \Site();
         $site->setPrimaryKey($pk->getId() . "G0");
         $site->setOfficialName($values['Site']['OFFICIAL_NAME']);
         $site->setShortName($values['Site']['SHORT_NAME']);
         $site->setDescription($values['Site']['DESCRIPTION']);
         $site->setHomeUrl($values['Site']['HOME_URL']);
         $site->setEmail($values['Site']['EMAIL']);
         $site->setTelephone($values['Site']['CONTACTTEL']);
         $site->setGiisUrl($values['Site']['GIIS_URL']);
         $site->setLatitude($values['Site']['LATITUDE']);
         $site->setLongitude($values['Site']['LONGITUDE']);
         $site->setCsirtEmail($values['Site']['CSIRTEMAIL']);
         $site->setIpRange($values['Site']['IP_RANGE']);
         $site->setIpV6Range($values['Site']['IP_V6_RANGE']);
         $site->setDomain($values['Site']['DOMAIN']);
         $site->setLocation($values['Site']['LOCATION']);
         $site->setCsirtTel($values['Site']['CSIRTTEL']);
         $site->setEmergencyTel($values['Site']['EMERGENCYTEL']);
         $site->setEmergencyEmail($values['Site']['EMERGENCYEMAIL']);
         $site->setHelpdeskEmail($values['Site']['HELPDESKEMAIL']);
         $site->setTimezoneId($values['Site']['TIMEZONE']);
         // get the parent NGI entity
         $dql = "SELECT n FROM NGI n WHERE n.id = :id";
         $parentNgi = $this->em->createQuery($dql)->setParameter('id', $values['NGI'])->getSingleResult();
         $site->setNgiDoJoin($parentNgi);
         // get the target infrastructure
         $dql = "SELECT i FROM Infrastructure i WHERE i.id = :id";
         $inf = $this->em->createQuery($dql)->setParameter('id', $values['ProductionStatus'])->getSingleResult();
         $site->setInfrastructure($inf);
         // get the cert status
         if (!isset($values['Certification_Status']) || $values['Certification_Status'] == null || $values['Certification_Status'] == '') {
             throw new \LogicException("Missing seed data - No certification status values in the DB (required data)");
         }
         $dql = "SELECT c FROM CertificationStatus c WHERE c.id = :id";
         $certStatus = $this->em->createQuery($dql)->setParameter('id', $values['Certification_Status'])->getSingleResult();
         $site->setCertificationStatus($certStatus);
         $now = new \DateTime('now', new \DateTimeZone('UTC'));
         $site->setCertificationStatusChangeDate($now);
         // create a new CertStatusLog
         $certLog = new \CertificationStatusLog();
         $certLog->setAddedBy($user->getCertificateDn());
         $certLog->setNewStatus($certStatus->getName());
         $certLog->setOldStatus(null);
         $certLog->setAddedDate($now);
         $certLog->setReason('Initial creation');
         $this->em->persist($certLog);
         $site->addCertificationStatusLog($certLog);
         // Set the scopes
         foreach ($values['Scope_ids'] as $scopeId) {
             $dql = "SELECT s FROM Scope s WHERE s.id = :id";
             $scope = $this->em->createQuery($dql)->setParameter('id', $scopeId)->getSingleResult();
             $site->addScope($scope);
         }
         // get the country
         $dql = "SELECT c FROM Country c WHERE c.id = :id";
         $country = $this->em->createQuery($dql)->setParameter('id', $values['Country'])->getSingleResult();
         $site->setCountry($country);
         // deprecated - don't use the lookup DB entity
         //	    	$dql = "SELECT t FROM Timezone t WHERE t.id = :id";
         //	    	$timezone = $this->em->createQuery($dql)
         //	    		->setParameter('id', $values['Timezone'])
         //	    		->getSingleResult();
         //	    	$site->setTimezone($timezone);
         $this->em->persist($site);
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $ex) {
         $this->em->getConnection()->rollback();
         //$this->em->remove($pk);
         //$this->em->flush();
         $this->em->close();
         throw $ex;
     }
     return $site;
 }