Example #1
0
 /**
  * Check whether it's possible to connect to the database server
  *
  * This will only run the check if the user pushed the 'backend_validation' button.
  *
  * @param   array   $formData
  *
  * @return  bool
  */
 public function isValidPartial(array $formData)
 {
     if (isset($formData['backend_validation']) && parent::isValid($formData)) {
         try {
             $db = new DbTool($this->getValues());
             $db->checkConnectivity();
         } catch (PDOException $e) {
             $this->warning(sprintf($this->translate('Failed to successfully validate the configuration: %s'), $e->getMessage()));
             return false;
         }
         $this->info($this->translate('The configuration has been successfully validated.'));
     }
     return true;
 }
Example #2
0
 /**
  * Validate the given form data and check whether it's possible to connect to the database server
  *
  * @param   array   $data   The data to validate
  *
  * @return  bool
  */
 public function isValid($data)
 {
     if (false === parent::isValid($data)) {
         return false;
     }
     if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) {
         try {
             $db = new DbTool($this->getValues());
             $db->checkConnectivity();
         } catch (PDOException $e) {
             $this->addError($e->getMessage());
             $this->addSkipValidationCheckbox();
             return false;
         }
     }
     return true;
 }
Example #3
0
 /**
  * Return whether the configuration is valid
  *
  * @param   bool    $showLog    Whether to show the validation log
  *
  * @return  bool
  */
 protected function validateConfiguration($showLog = false)
 {
     $inspection = ResourceConfigForm::inspectResource($this);
     if ($inspection !== null) {
         if ($showLog) {
             $join = function ($e) use(&$join) {
                 return is_string($e) ? $e : join("\n", array_map($join, $e));
             };
             $this->addElement('note', 'inspection_output', array('order' => 0, 'value' => '<strong>' . $this->translate('Validation Log') . "</strong>\n\n" . join("\n", array_map($join, $inspection->toArray())), 'decorators' => array('ViewHelper', array('HtmlTag', array('tag' => 'pre', 'class' => 'log-output')))));
         }
         if ($inspection->hasError()) {
             $this->error(sprintf($this->translate('Failed to successfully validate the configuration: %s'), $inspection->getError()));
             return false;
         }
     }
     $configObject = new ConfigObject($this->getValues());
     if (!BackendConfigForm::isValidIdoSchema($this, $configObject) || !BackendConfigForm::isValidIdoInstance($this, $configObject)) {
         return false;
     }
     if ($this->getValue('db') === 'pgsql') {
         $db = new DbTool($this->getValues());
         $version = $db->connectToDb()->getServerVersion();
         if (version_compare($version, '9.1', '<')) {
             $this->error($this->translate(sprintf('The server\'s version %s is too old. The minimum required version is %s.', $version, '9.1')));
             return false;
         }
     }
     return true;
 }
 /**
  * Validate the given form data and check whether the defined user has sufficient access rights
  *
  * @param   array   $data   The data to validate
  *
  * @return  bool
  */
 public function isValid($data)
 {
     if (false === parent::isValid($data)) {
         return false;
     }
     if (isset($data['skip_validation']) && $data['skip_validation']) {
         return true;
     }
     $config = $this->config;
     $config['username'] = $this->getValue('username');
     $config['password'] = $this->getValue('password');
     $db = new DbTool($config);
     try {
         $db->connectToDb();
         // Are we able to login on the database?
     } catch (PDOException $_) {
         try {
             $db->connectToHost();
             // Are we able to login on the server?
         } catch (PDOException $e) {
             // We are NOT able to login on the server..
             $this->error($e->getMessage());
             $this->addSkipValidationCheckbox();
             return false;
         }
     }
     // In case we are connected the credentials filled into this
     // form need to be granted to create databases, users...
     if (false === $db->checkPrivileges($this->databaseSetupPrivileges)) {
         $this->error($this->translate('The provided credentials cannot be used to create the database and/or the user.'));
         $this->addSkipValidationCheckbox();
         return false;
     }
     // ...and to grant all required usage privileges to others
     if (false === $db->isGrantable($this->databaseUsagePrivileges)) {
         $this->error(sprintf($this->translate('The provided credentials cannot be used to grant all required privileges to the login "%s".'), $this->config['username']));
         $this->addSkipValidationCheckbox();
         return false;
     }
     return true;
 }
Example #5
0
 /**
  * Return whether the configuration is valid
  *
  * @return  bool
  */
 protected function validateConfiguration()
 {
     try {
         $db = new DbTool($this->getValues());
         $db->checkConnectivity();
     } catch (Exception $e) {
         $this->error(sprintf($this->translate('Failed to successfully validate the configuration: %s'), $e->getMessage()));
         return false;
     }
     $state = true;
     $connectionError = null;
     try {
         $db->connectToDb();
     } catch (Exception $e) {
         $connectionError = $e;
     }
     if ($connectionError === null && array_search('icinga_instances', $db->listTables(), true) !== false) {
         $this->warning($this->translate('The database you\'ve configured to use for Icinga Web 2 seems to be the one of Icinga. Please be aware' . ' that this database configuration is supposed to be used for Icinga Web 2\'s configuration and that' . ' it is highly recommended to not mix different schemas in the same database. If this is intentional,' . ' you can skip the validation and ignore this warning. If not, please provide a different database.'));
         $state = false;
     }
     if ($this->getValue('db') === 'pgsql') {
         if ($connectionError !== null) {
             $this->warning($this->translate(sprintf('Unable to check the server\'s version. This is usually not a critical error as there is' . ' probably only access to the database permitted which does not exist yet. If you are' . ' absolutely sure you are running PostgreSQL in a version equal to or newer than 9.1,' . ' you can skip the validation and safely proceed to the next step. The error was: %s', $connectionError->getMessage())));
             $state = false;
         } else {
             $version = $db->getServerVersion();
             if (version_compare($version, '9.1', '<')) {
                 $this->error($this->translate(sprintf('The server\'s version %s is too old. The minimum required version is %s.', $version, '9.1')));
                 $state = false;
             }
         }
     }
     return $state;
 }
Example #6
0
 /**
  * Return the new page to set as current page
  *
  * {@inheritdoc} Runs additional checks related to some registered pages.
  *
  * @param   string  $requestedPage      The name of the requested page
  * @param   Form    $originPage         The origin page
  *
  * @return  Form                        The new page
  *
  * @throws  InvalidArgumentException    In case the requested page does not exist or is not permitted yet
  */
 protected function getNewPage($requestedPage, Form $originPage)
 {
     $skip = false;
     $newPage = parent::getNewPage($requestedPage, $originPage);
     if ($newPage->getName() === 'setup_auth_db_resource') {
         $authData = $this->getPageData('setup_authentication_type');
         $skip = $authData['type'] !== 'db';
     } elseif ($newPage->getname() === 'setup_ldap_discovery') {
         $authData = $this->getPageData('setup_authentication_type');
         $skip = $authData['type'] !== 'ldap';
         /*} elseif ($newPage->getName() === 'setup_ldap_discovery_confirm') {
           $skip = false === $this->hasPageData('setup_ldap_discovery');*/
     } elseif ($newPage->getName() === 'setup_ldap_resource') {
         $authData = $this->getPageData('setup_authentication_type');
         $skip = $authData['type'] !== 'ldap';
     } elseif ($newPage->getName() === 'setup_config_db_resource') {
         $authData = $this->getPageData('setup_authentication_type');
         $configData = $this->getPageData('setup_general_config');
         $skip = $authData['type'] === 'db' || $configData['global_config_backend'] !== 'db';
     } elseif (in_array($newPage->getName(), array('setup_auth_db_creation', 'setup_config_db_creation'))) {
         if (($newPage->getName() === 'setup_auth_db_creation' || $this->hasPageData('setup_config_db_resource')) && (($config = $this->getPageData('setup_auth_db_resource')) !== null || ($config = $this->getPageData('setup_config_db_resource')) !== null) && !$config['skip_validation']) {
             $db = new DbTool($config);
             try {
                 $db->connectToDb();
                 // Are we able to login on the database?
                 if (array_search(reset($this->databaseTables), $db->listTables()) === false) {
                     // In case the database schema does not yet exist the
                     // user needs the privileges to setup the database
                     $skip = $db->checkPrivileges($this->databaseSetupPrivileges, $this->databaseTables);
                 } else {
                     // In case the database schema exists the user needs the required privileges
                     // to operate the database, if those are missing we ask for another user
                     $skip = $db->checkPrivileges($this->databaseUsagePrivileges, $this->databaseTables);
                 }
             } catch (PDOException $_) {
                 try {
                     $db->connectToHost();
                     // Are we able to login on the server?
                     // It is not possible to reliably determine whether a database exists or not if a user can't
                     // log in to the database, so we just require the user to be able to create the database
                     $skip = $db->checkPrivileges(array_unique(array_merge($this->databaseCreationPrivileges, $this->databaseSetupPrivileges)), $this->databaseTables);
                 } catch (PDOException $_) {
                     // We are NOT able to login on the server..
                 }
             }
         } else {
             $skip = true;
         }
     }
     return $skip ? $this->skipPage($newPage) : $newPage;
 }
 public function getSummary()
 {
     $resourceConfig = $this->data['resourceConfig'];
     if (isset($this->data['adminName'])) {
         $resourceConfig['username'] = $this->data['adminName'];
         if (isset($this->data['adminPassword'])) {
             $resourceConfig['password'] = $this->data['adminPassword'];
         }
     }
     $db = new DbTool($resourceConfig);
     try {
         $db->connectToDb();
         if (array_search(reset($this->data['tables']), $db->listTables(), true) === false) {
             if ($resourceConfig['username'] !== $this->data['resourceConfig']['username']) {
                 $message = sprintf(mt('setup', 'The database user "%s" will be used to setup the missing schema required by Icinga' . ' Web 2 in database "%s" and to grant access to it to a new login called "%s".'), $resourceConfig['username'], $resourceConfig['dbname'], $this->data['resourceConfig']['username']);
             } else {
                 $message = sprintf(mt('setup', 'The database user "%s" will be used to setup the missing' . ' schema required by Icinga Web 2 in database "%s".'), $resourceConfig['username'], $resourceConfig['dbname']);
             }
         } else {
             $message = sprintf(mt('setup', 'The database "%s" already seems to be fully set up. No action required.'), $resourceConfig['dbname']);
         }
     } catch (PDOException $_) {
         try {
             $db->connectToHost();
             if ($resourceConfig['username'] !== $this->data['resourceConfig']['username']) {
                 if ($db->hasLogin($this->data['resourceConfig']['username'])) {
                     $message = sprintf(mt('setup', 'The database user "%s" will be used to create the missing database' . ' "%s" with the schema required by Icinga Web 2 and to grant' . ' access to it to an existing login called "%s".'), $resourceConfig['username'], $resourceConfig['dbname'], $this->data['resourceConfig']['username']);
                 } else {
                     $message = sprintf(mt('setup', 'The database user "%s" will be used to create the missing database' . ' "%s" with the schema required by Icinga Web 2 and to grant' . ' access to it to a new login called "%s".'), $resourceConfig['username'], $resourceConfig['dbname'], $this->data['resourceConfig']['username']);
                 }
             } else {
                 $message = sprintf(mt('setup', 'The database user "%s" will be used to create the missing' . ' database "%s" with the schema required by Icinga Web 2.'), $resourceConfig['username'], $resourceConfig['dbname']);
             }
         } catch (Exception $_) {
             $message = mt('setup', 'No connection to database host possible. You\'ll need to setup the' . ' database with the schema required by Icinga Web 2 manually.');
         }
     }
     return '<h2>' . mt('setup', 'Database Setup', 'setup.page.title') . '</h2><p>' . $message . '</p>';
 }
Example #8
0
 /**
  * Return whether the configuration is valid
  *
  * @return  bool
  */
 protected function validateConfiguration()
 {
     try {
         $db = new DbTool($this->getValues());
         $db->checkConnectivity();
     } catch (PDOException $e) {
         $this->error(sprintf($this->translate('Failed to successfully validate the configuration: %s'), $e->getMessage()));
         return false;
     }
     if ($this->getValue('db') === 'pgsql') {
         if (!$db->isConnected()) {
             try {
                 $db->connectToDb();
             } catch (PDOException $e) {
                 $this->warning($this->translate(sprintf('Unable to check the server\'s version. This is usually not a critical error as there is' . ' probably only access to the database permitted which does not exist yet. If you are' . ' absolutely sure you are running PostgreSQL in a version equal to or newer than 9.1,' . ' you can skip the validation and safely proceed to the next step. The error was: %s', $e->getMessage())));
                 return false;
             }
         }
         $version = $db->getServerVersion();
         if (version_compare($version, '9.1', '<')) {
             $this->error($this->translate(sprintf('The server\'s version %s is too old. The minimum required version is %s.', $version, '9.1')));
             return false;
         }
     }
     return true;
 }