Example #1
0
 /**
  * Setup the given page that is either going to be displayed or validated
  *
  * @param   Form        $page       The page to setup
  * @param   Request     $request    The current request
  */
 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 (($authDbResourceData = $this->getPageData('setup_auth_db_resource')) !== null && $authDbResourceData['name'] === $request->getPost('name') || ($configDbResourceData = $this->getPageData('setup_config_db_resource')) !== null && $configDbResourceData['name'] === $request->getPost('name') || ($ldapResourceData = $this->getPageData('setup_ldap_resource')) !== null && $ldapResourceData['name'] === $request->getPost('name')) {
             $page->error(mt('monitoring', 'The given resource name is already in use.'));
         }
     }
 }
Example #2
0
 /**
  * Return whether the given resource contains a valid IDO schema
  *
  * @param   Form            $form
  * @param   ConfigObject    $resourceConfig
  *
  * @return  bool
  */
 public static function isValidIdoSchema(Form $form, ConfigObject $resourceConfig)
 {
     try {
         $db = ResourceFactory::createResource($resourceConfig);
         $db->select()->from('icinga_dbversion', array('version'))->fetchOne();
     } catch (Exception $_) {
         $form->error($form->translate('Cannot find the IDO schema. Please verify that the given database ' . 'contains the schema and that the configured user has access to it.'));
         return false;
     }
     return true;
 }
 /**
  * Return whether a single icinga instance is writing to the given resource
  *
  * @param   Form            $form
  * @param   ConfigObject    $resourceConfig
  *
  * @return  bool                                True if it's a single instance, false if none
  *                                              or multiple instances are writing to it
  */
 public static function isValidIdoInstance(Form $form, ConfigObject $resourceConfig)
 {
     $db = ResourceFactory::createResource($resourceConfig);
     $rowCount = $db->select()->from('icinga_instances')->count();
     if ($rowCount === 0) {
         $form->error($form->translate('There is currently no icinga instance writing to the IDO. Make sure ' . 'that a icinga instance is configured and able to write to the IDO.'));
         return false;
     } elseif ($rowCount > 1) {
         $form->warning($form->translate('There is currently more than one icinga instance writing to the IDO. You\'ll see all objects from all' . ' instances without any differentation. If this is not desired, consider setting up a separate IDO' . ' for each instance.'));
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * Setup the given page that is either going to be displayed or validated
  *
  * @param   Form        $page       The page to setup
  * @param   Request     $request    The current request
  */
 public function setupPage(Form $page, Request $request)
 {
     if ($page->getName() === 'setup_requirements') {
         $page->setWizard($this);
     } elseif ($page->getName() === 'setup_authentication_backend') {
         $authData = $this->getPageData('setup_authentication_type');
         if ($authData['type'] === 'db') {
             $page->setResourceConfig($this->getPageData('setup_auth_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_auth_db_resource'));
         } elseif ($authData['type'] === 'ldap') {
             $page->setResourceConfig($this->getPageData('setup_ldap_resource'));
         }
     } elseif ($page->getName() === 'setup_auth_db_creation' || $page->getName() === 'setup_config_db_creation') {
         $page->setDatabaseSetupPrivileges(array_unique(array_merge($this->databaseCreationPrivileges, $this->databaseSetupPrivileges)));
         $page->setDatabaseUsagePrivileges($this->databaseUsagePrivileges);
         $page->setResourceConfig($this->getPageData('setup_auth_db_resource') ?: $this->getPageData('setup_config_db_resource'));
     } elseif ($page->getName() === 'setup_summary') {
         $page->setSubjectTitle('Icinga Web 2');
         $page->setSummary($this->getSetup()->getSummary());
     } elseif ($page->getName() === 'setup_config_db_resource') {
         $ldapData = $this->getPageData('setup_ldap_resource');
         if ($ldapData !== null && $request->getPost('name') === $ldapData['name']) {
             $page->error(mt('setup', 'The given resource name must be unique and is already in use by the LDAP resource'));
         }
     } elseif ($page->getName() === 'setup_ldap_resource') {
         $suggestion = $this->getPageData('setup_ldap_discovery');
         if (isset($suggestion['resource'])) {
             $page->populate($suggestion['resource']);
         }
     } elseif ($page->getName() === 'setup_general_config') {
         $authData = $this->getPageData('setup_authentication_type');
         if ($authData['type'] === 'db') {
             $page->create()->getElement('global_config_backend')->setValue('db');
             $page->info(mt('setup', 'Note that choosing "Database" as preference storage causes' . ' Icinga Web 2 to use the same database as for authentication.'), false);
         }
     } 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']);
             if ($authData['type'] === 'db') {
                 unset($pageData['setup_auth_db_resource']);
                 unset($pageData['setup_auth_db_creation']);
             } elseif ($request->getPost('type') === 'db') {
                 unset($pageData['setup_config_db_resource']);
                 unset($pageData['setup_config_db_creation']);
             }
         }
     }
 }
Example #5
0
 /**
  * Validate the ido instance availability
  *
  * @param   Form            $form
  * @param   ConfigObject    $resourceConfig
  *
  * @return  bool                                Whether validation succeeded or not
  */
 public static function isValidIdoInstance(Form $form, ConfigObject $resourceConfig)
 {
     $resource = ResourceFactory::createResource($resourceConfig);
     $result = $resource->select()->from('icinga_instances', array('instance_name'));
     $instances = $result->fetchAll();
     if (count($instances) === 1) {
         return true;
     } elseif (count($instances) > 1) {
         $form->warning($form->translate('IDO instance validation failed, because there are multiple instances available.'));
         return false;
     }
     $form->error($form->translate('IDO instance validation failed, because there is no IDO instance available.'));
     return false;
 }