Exemplo n.º 1
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;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 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>';
 }