/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { try { $dbUserBackend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig())); if ($dbUserBackend->select()->where('is_active', true)->count() < 1) { $form->addError($form->translate('No active users found under the specified database backend')); return false; } } catch (Exception $e) { $form->addError(sprintf($form->translate('Using the specified backend failed: %s'), $e->getMessage())); return false; } return true; }
/** * Validate the resource configuration by trying to connect with it * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidResource(Form $form) { $result = ResourceFactory::createResource(new ConfigObject($form->getValues()))->inspect(); if ($result->hasError()) { $form->addError(sprintf('%s (%s)', $form->translate('Connectivity validation failed, connection to the given resource not possible.'), $result->getError())); } // TODO: display diagnostics in $result->toArray() to the user return !$result->hasError(); }
/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { $backend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig())); $result = $backend->inspect(); if ($result->hasError()) { $form->addError(sprintf($form->translate('Using the specified backend failed: %s'), $result->getError())); } // TODO: display diagnostics in $result->toArray() to the user return !$result->hasError(); }
/** * Validate the resource configuration by trying to connect with it * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidResource(Form $form) { try { $resource = ResourceFactory::createResource(new ConfigObject($form->getValues())); $resource->getConnection()->getConnection(); } catch (Exception $e) { $form->addError($form->translate('Connectivity validation failed, connection to the given resource not possible.')); return false; } return true; }
/** * @see Wizard::setupPage() */ public function setupPage(Form $page, Request $request) { if ($page->getName() === 'setup_requirements') { $page->setRequirements($this->getRequirements()); } elseif ($page->getName() === 'setup_monitoring_summary') { $page->setSummary($this->getSetup()->getSummary()); $page->setSubjectTitle(mt('monitoring', 'the monitoring module', 'setup.summary.subject')); } elseif ($this->getDirection() === static::FORWARD && ($page->getName() === 'setup_monitoring_ido' || $page->getName() === 'setup_monitoring_livestatus')) { if (($dbResourceData = $this->getPageData('setup_db_resource')) !== null && $dbResourceData['name'] === $request->getPost('name') || ($ldapResourceData = $this->getPageData('setup_ldap_resource')) !== null && $ldapResourceData['name'] === $request->getPost('name')) { $page->addError(mt('monitoring', 'The given resource name is already in use.')); } } }
/** * Validate the resource configuration by trying to connect with it * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidResource(Form $form) { try { $resource = ResourceFactory::createResource(new ConfigObject($form->getValues())); $resource->bind(); } catch (Exception $e) { $msg = $form->translate('Connectivity validation failed, connection to the given resource not possible.'); if ($error = $e->getMessage()) { $msg .= ' (' . $error . ')'; } $form->addError($msg); return false; } return true; }
/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { /** * @var $result Inspection */ $result = UserBackend::create(null, new ConfigObject($form->getValues()))->inspect(); if ($result->hasError()) { $form->addError($result->getError()); } // TODO: display diagnostics in $result->toArray() to the user return !$result->hasError(); }
/** * @see Wizard::setupPage() */ public function setupPage(Form $page, Request $request) { if ($page->getName() === 'setup_requirements') { $page->setWizard($this); } elseif ($page->getName() === 'setup_preferences_type') { $authData = $this->getPageData('setup_authentication_type'); if ($authData['type'] === 'db') { $page->create()->getElement('store')->setValue('db'); $page->addDescription(mt('setup', 'Note that choosing "Database" causes Icinga Web 2 to use the same database as for authentication.')); } } elseif ($page->getName() === 'setup_authentication_backend') { $authData = $this->getPageData('setup_authentication_type'); if ($authData['type'] === 'db') { $page->setResourceConfig($this->getPageData('setup_db_resource')); } elseif ($authData['type'] === 'ldap') { $page->setResourceConfig($this->getPageData('setup_ldap_resource')); $suggestions = $this->getPageData('setup_ldap_discovery'); if (isset($suggestions['backend'])) { $page->populate($suggestions['backend']); } } /*} elseif ($page->getName() === 'setup_ldap_discovery_confirm') { $page->setResourceConfig($this->getPageData('setup_ldap_discovery'));*/ } elseif ($page->getName() === 'setup_admin_account') { $page->setBackendConfig($this->getPageData('setup_authentication_backend')); $authData = $this->getPageData('setup_authentication_type'); if ($authData['type'] === 'db') { $page->setResourceConfig($this->getPageData('setup_db_resource')); } elseif ($authData['type'] === 'ldap') { $page->setResourceConfig($this->getPageData('setup_ldap_resource')); } } elseif ($page->getName() === 'setup_database_creation') { $page->setDatabaseSetupPrivileges(array_unique(array_merge($this->databaseCreationPrivileges, $this->databaseSetupPrivileges))); $page->setDatabaseUsagePrivileges($this->databaseUsagePrivileges); $page->setResourceConfig($this->getPageData('setup_db_resource')); } elseif ($page->getName() === 'setup_summary') { $page->setSubjectTitle('Icinga Web 2'); $page->setSummary($this->getSetup()->getSummary()); } elseif ($page->getName() === 'setup_db_resource') { $ldapData = $this->getPageData('setup_ldap_resource'); if ($ldapData !== null && $request->getPost('name') === $ldapData['name']) { $page->addError(mt('setup', 'The given resource name must be unique and is already in use by the LDAP resource')); } } elseif ($page->getName() === 'setup_ldap_resource') { $dbData = $this->getPageData('setup_db_resource'); if ($dbData !== null && $request->getPost('name') === $dbData['name']) { $page->addError(mt('setup', 'The given resource name must be unique and is already in use by the database resource')); } $suggestion = $this->getPageData('setup_ldap_discovery'); if (isset($suggestion['resource'])) { $page->populate($suggestion['resource']); } } elseif ($page->getName() === 'setup_authentication_type' && $this->getDirection() === static::FORWARD) { $authData = $this->getPageData($page->getName()); if ($authData !== null && $request->getPost('type') !== $authData['type']) { // Drop any existing page data in case the authentication type has changed, // otherwise it will conflict with other forms that depend on this one $pageData =& $this->getPageData(); unset($pageData['setup_admin_account']); unset($pageData['setup_authentication_backend']); } } }
/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { try { $ldapUserBackend = UserBackend::create(null, new ConfigObject($form->getValues())); $ldapUserBackend->assertAuthenticationPossible(); } catch (AuthenticationException $e) { if (($previous = $e->getPrevious()) !== null) { $form->addError($previous->getMessage()); } else { $form->addError($e->getMessage()); } return false; } catch (Exception $e) { $form->addError(sprintf($form->translate('Unable to validate authentication: %s'), $e->getMessage())); return false; } return true; }
/** * Validate the ido instance schema resource * * @param Form $form * @param ConfigObject $resourceConfig * * @return bool Whether validation succeeded or not */ public static function isValidIdoSchema(Form $form, ConfigObject $resourceConfig) { try { $resource = ResourceFactory::createResource($resourceConfig); $result = $resource->select()->from('icinga_dbversion', array('version')); $result->fetchOne(); } catch (Exception $e) { $form->addError($form->translate('IDO schema validation failed, it looks like that the IDO schema is missing in the given database.')); return false; } return true; }