Exemple #1
0
 /**
  * Validates the user inputted user data against the
  * checks in the gocdb_schema.xml.
  * @param array $user_data containing all the fields for a GOCDB_USER
  *                       object
  * @throws \Exception If the site data can't be
  *                   validated. The \Exception message will contain a human
  *                   readable description of which field failed validation.
  * @return null */
 private function validateUser($userData)
 {
     require_once __DIR__ . '/Validate.php';
     $serv = new \org\gocdb\services\Validate();
     foreach ($userData as $field => $value) {
         $valid = $serv->validate('user', $field, $value);
         if (!$valid) {
             $error = "{$field} contains an invalid value: {$value}";
             throw new \Exception($error);
         }
     }
 }
Exemple #2
0
 /**
  * Validates the user inputted service data against the
  * checks in the gocdb_schema.xml.
  * @param string $endpoint_url the new URL
  * @throws \Exception If the new URL isn't
  *                    valid. The \Exception's message will contain a human
  *                    readable error message.
  * @return null
  */
 private function validateEndpointUrl($endpoint_url)
 {
     require_once __DIR__ . '/Validate.php';
     $serv = new \org\gocdb\services\Validate();
     $valid = $serv->validate('endpoint_location', "URL", $endpoint_url);
     if (!$valid) {
         throw new \Exception("Invalid URL: {$endpoint_url}");
     }
 }
Exemple #3
0
 /**
  * Checks the required values are present and then Validates the user 
  * inputted project data against the data in the gocdb_schema.xml.
  * @param array $projectData containing all the fields for a GOCDB project
  *                       object
  * @throws \Exception If the project's data can't be
  *                    validated. The \Exception message will contain a human
  *                    readable description of which field failed validation.
  * @return null */
 private function validate($projectData)
 {
     require_once __DIR__ . '/Validate.php';
     //check values are there (description may be "")
     if (!(array_key_exists('Name', $projectData) and array_key_exists('Description', $projectData))) {
         throw new \Exception("A name and description for the project must be specified");
     }
     //check values are strings
     if (!(is_string($projectData['Name']) and is_string($projectData['Description']))) {
         throw new \Exception("The new project name and description must be valid strings");
     }
     //check that the name is not null
     if (empty($projectData['Name'])) {
         throw new \Exception("A name must be specified for the Project");
     }
     //remove the ID fromt he values file if present (which it will be for an edit)
     if (array_key_exists("ID", $projectData)) {
         unset($projectData["ID"]);
     }
     $serv = new \org\gocdb\services\Validate();
     foreach ($projectData as $field => $value) {
         $valid = $serv->validate('project', strtoupper($field), $value);
         if (!$valid) {
             $error = "{$field} contains an invalid value: {$value}";
             throw new \Exception($error);
         }
     }
 }
Exemple #4
0
 /**
  * Validates the user inputted service group data against the
  * checks in the gocdb_schema.xml.
  * @param array $sgData containing all the fields for a GOCDB_USER
  *                       object
  * @throws \Exception If the site data can't be
  *                    validated. The \Exception message will contain a human
  *                    readable description of which field failed validation.
  * @return null */
 private function validate($sgData, $type = NULL)
 {
     if ($type == NULL) {
         $type = 'service_group';
     }
     require_once __DIR__ . '/Validate.php';
     $serv = new \org\gocdb\services\Validate();
     foreach ($sgData as $field => $value) {
         $valid = $serv->validate($type, $field, $value);
         if (!$valid) {
             $error = "{$field} contains an invalid value: {$value}";
             throw new \Exception($error);
         }
     }
 }
Exemple #5
0
 /**
  * Validates the user inputted site data against the
  * checks in the gocdb_schema.xml and applies additional logic checks 
  * that can't be described in the gocdb_schema.xml. 
  *  
  * @param array $site_data containing all the fields for a GOCDB_SITE
  *                       object
  * @throws \Exception if the site data can't be
  *                   validated. The \Exception message will contain a human
  *                   readable description of which field failed validation.
  * @return null
  */
 private function validate($site_data, $type)
 {
     require_once __DIR__ . '/Validate.php';
     $serv = new \org\gocdb\services\Validate();
     foreach ($site_data as $field => $value) {
         $valid = $serv->validate($type, $field, $value);
         if (!$valid) {
             $error = "{$field} contains an invalid value: {$value}";
             throw new \Exception($error);
         }
     }
     // Apply additional logic for validation that can't be captured solely using gocdb_schema.xml
     if (!empty($site_data['IP_V6_RANGE'])) {
         require_once __DIR__ . '/validation/IPv6Validator.php';
         $validator = new \IPv6Validator();
         $errors = array();
         $errors = $validator->validate($site_data['IP_V6_RANGE'], $errors);
         if (count($errors) > 0) {
             throw new \Exception($errors[0]);
             // show the first message.
         }
     }
 }
Exemple #6
0
 /**
  * Performs some basic checks on the values aray and then validates the user
  * inputted scope type data against the data in the gocdb_schema.xml.
  * @param array $scopeData containing all the fields for a GOCDB scope object
  * @param boolean $scopeIsNew true if the values are for a new scope
  * @param string $oldScopeName name of the sope before this cvhange. Only 
  *                             relevant if scopeIsNew = false
  * @throws \Exception If the project's data can't be
  *                    validated. The \Exception message will contain a human
  *                    readable description of which field failed validation.
  * @return null */
 private function validate($scopeData, $scopeIsNew, $oldScopeName = '')
 {
     require_once __DIR__ . '/Validate.php';
     //check values are there
     if (!(array_key_exists('Name', $scopeData) and array_key_exists('Description', $scopeData))) {
         throw new \Exception("A name scope must be specified");
     }
     //check values are strings
     if (!(is_string($scopeData['Name']) and is_string($scopeData['Description']))) {
         throw new \Exception("The new scope name must be a valid string");
     }
     //check that the name is not null
     if (empty($scopeData['Name'])) {
         throw new \Exception("A name must be specified for the Scope");
     }
     //check the name is unique
     if ($scopeIsNew or $scopeData['Name'] != $oldScopeName) {
         if (!$this->scopeNameIsUnique($scopeData['Name'])) {
             throw new \Exception("Scope names must be unique, '" . $scopeData['Name'] . "' is already in use");
         }
     }
     //remove the ID fromt the values file if present (which it may be for an edit)
     if (array_key_exists("Id", $scopeData)) {
         unset($scopeData["Id"]);
     }
     $serv = new \org\gocdb\services\Validate();
     foreach ($scopeData as $field => $value) {
         $valid = $serv->validate('scope', strtoupper($field), $value);
         if (!$valid) {
             $error = "{$field} contains an invalid value: {$value}";
             throw new \Exception($error);
         }
     }
 }
Exemple #7
0
function showAllSites()
{
    require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';
    $exServ = \Factory::getExtensionsService();
    // Do we really need to validate the URL parameter values, as the query
    // to the DB always uses bind variables to protect against injection?
    require_once __DIR__ . '/../../../../lib/Gocdb_Services/Validate.php';
    $validatorService = new \org\gocdb\services\Validate();
    $ngi = '%%';
    if (!empty($_GET['NGI'])) {
        $ngi = $_GET['NGI'];
        if (!$validatorService->validate('ngi', 'NAME', $ngi)) {
            throw new Exception("Invalid NGI parameter value");
        }
    }
    $prodStatus = '%%';
    if (!empty($_GET['prodStatus'])) {
        $prodStatus = $_GET['prodStatus'];
    }
    //must be done before the if certstatus in the block that sets $certStatus
    $showClosed = false;
    if (isset($_GET['showClosed'])) {
        $showClosed = true;
    }
    $certStatus = '%%';
    if (!empty($_GET['certStatus'])) {
        $certStatus = $_GET['certStatus'];
        //set show closed as true if production status selected is 'closed' - otherwise
        // there will be no results
        if ($certStatus == 'Closed') {
            $showClosed = true;
        }
    }
    // Site extension property key name
    $siteKeyNames = "";
    if (isset($_GET['siteKeyNames'])) {
        $siteKeyNames = $_GET['siteKeyNames'];
    }
    // Site extension property key value
    $siteKeyValues = "";
    if (isset($_GET['selectedSiteKeyValue'])) {
        $siteKeyValues = $_GET['selectedSiteKeyValue'];
    }
    $scope = '%%';
    if (!empty($_GET['scope'])) {
        $scope = $_GET['scope'];
    }
    $serv = \Factory::getSiteService();
    $params['scopes'] = \Factory::getScopeService()->getScopes();
    $params['sites'] = $serv->getSitesBy($ngi, $prodStatus, $certStatus, $scope, $showClosed, null, $siteKeyNames, $siteKeyValues);
    $params['NGIs'] = $serv->getNGIs();
    $params['prodStatuses'] = $serv->getProdStatuses();
    //Remove SC and PPS infrastructures from drop down list. TODO: Delete this block once they no longer exist
    $SCInfrastructure = $serv->getProdStatusByName('SC');
    $PPSInfrastructure = $serv->getProdStatusByName('PPS');
    $productionStatuses = array();
    foreach ($params['prodStatuses'] as $ps) {
        if ($ps != $SCInfrastructure and $ps != $PPSInfrastructure) {
            $productionStatuses[] = $ps;
        }
    }
    $params['prodStatuses'] = $productionStatuses;
    //delete up to here once pps and sc infrastructures have been removed from database
    /* Doctrine will provide keynames that are the same even when selecting distinct becase the object
     * is distinct even though the name is not unique. To avoid showing the same name repeatdly in the filter
     * we will load all the keynames into an array before making it unique
     */
    $keynames = array();
    foreach ($exServ->getSiteExtensionsKeyNames() as $extension) {
        $keynames[] = $extension->getKeyName();
    }
    $keynames = array_unique($keynames);
    $params['selectedNgi'] = $ngi;
    $params['certStatuses'] = $serv->getCertStatuses();
    $params['selectedProdStatus'] = $prodStatus;
    $params['selectedCertStatus'] = $certStatus;
    $params['selectedScope'] = $scope;
    $params['showClosed'] = $showClosed;
    $params['siteKeyNames'] = $keynames;
    $params['selectedSiteKeyNames'] = $siteKeyNames;
    $params['selectedSiteKeyValue'] = $siteKeyValues;
    show_view("site/view_all.php", $params, "Sites");
}