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->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'));
             if (!$this->hasPageData('setup_authentication_backend')) {
                 $suggestions = $this->getPageData('setup_ldap_discovery');
                 if (isset($suggestions['backend'])) {
                     $page->populate($suggestions['backend']);
                 }
             }
             if ($this->getDirection() === static::FORWARD) {
                 $backendConfig = $this->getPageData('setup_authentication_backend');
                 if ($backendConfig !== null && $request->getPost('name') !== $backendConfig['name']) {
                     $pageData =& $this->getPageData();
                     unset($pageData['setup_usergroup_backend']);
                 }
             }
         }
         if ($this->getDirection() === static::FORWARD) {
             $backendConfig = $this->getPageData('setup_authentication_backend');
             if ($backendConfig !== null && $request->getPost('backend') !== $backendConfig['backend']) {
                 $pageData =& $this->getPageData();
                 unset($pageData['setup_usergroup_backend']);
             }
         }
         /*} elseif ($page->getName() === 'setup_ldap_discovery_confirm') {
           $page->setResourceConfig($this->getPageData('setup_ldap_discovery'));*/
     } elseif ($page->getName() === 'setup_auth_db_resource') {
         $page->addDescription(mt('setup', 'Now please configure the database resource where to store users and user groups.'));
         $page->addDescription(mt('setup', 'Note that the database itself does not need to exist at this time as' . ' it is going to be created once the wizard is about to be finished.'));
     } elseif ($page->getName() === 'setup_usergroup_backend') {
         $page->setResourceConfig($this->getPageData('setup_ldap_resource'));
         $page->setBackendConfig($this->getPageData('setup_authentication_backend'));
     } elseif ($page->getName() === 'setup_admin_account') {
         $page->setBackendConfig($this->getPageData('setup_authentication_backend'));
         $page->setGroupConfig($this->getPageData('setup_usergroup_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') {
         $page->addDescription(mt('setup', 'Now please configure the database resource where to store user preferences.'));
         $page->addDescription(mt('setup', 'Note that the database itself does not need to exist at this time as' . ' it is going to be created once the wizard is about to be finished.'));
         $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']);
         }
         if ($this->getDirection() === static::FORWARD) {
             $resourceConfig = $this->getPageData('setup_ldap_resource');
             if ($resourceConfig !== null && $request->getPost('name') !== $resourceConfig['name']) {
                 $pageData =& $this->getPageData();
                 unset($pageData['setup_usergroup_backend']);
             }
         }
     } elseif ($page->getName() === 'setup_general_config') {
         $authData = $this->getPageData('setup_authentication_type');
         if ($authData['type'] === 'db') {
             $page->create($this->getRequestData($page, $request))->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 #2
0
 /**
  * @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']);
         }
     }
 }