data = $data; } public function apply() { $success = $this->createAuthenticationIni(); if (isset($this->data['adminAccountData']['resourceConfig'])) { $success &= $this->createAccount(); } $success &= $this->defineInitialAdmin(); return $success; } protected function createAuthenticationIni() { $config = array(); $backendConfig = $this->data['backendConfig']; $backendName = $backendConfig['name']; unset($backendConfig['name']); $config[$backendName] = $backendConfig; if (isset($this->data['resourceName'])) { $config[$backendName]['resource'] = $this->data['resourceName']; } try { $writer = new PreservingIniWriter(array( 'config' => new Zend_Config($config), 'filename' => Config::resolvePath('authentication.ini'), 'filemode' => octdec($this->data['fileMode']) )); $writer->write(); } catch (Exception $e) { $this->authIniError = $e; return false; } $this->authIniError = false; return true; } protected function defineInitialAdmin() { $config = array(); $config['admins'] = array( 'users' => $this->data['adminAccountData']['username'], 'permission' => '*' ); try { $writer = new PreservingIniWriter(array( 'config' => new Zend_Config($config), 'filename' => Config::resolvePath('permissions.ini'), 'filemode' => octdec($this->data['fileMode']) )); $writer->write(); } catch (Exception $e) { $this->permIniError = $e; return false; } $this->permIniError = false; return true; } protected function createAccount() { try { $backend = new DbUserBackend( ResourceFactory::createResource(new Zend_Config($this->data['adminAccountData']['resourceConfig'])) ); if (array_search($this->data['adminAccountData']['username'], $backend->listUsers()) === false) { $backend->addUser( $this->data['adminAccountData']['username'], $this->data['adminAccountData']['password'] ); } } catch (Exception $e) { $this->dbError = $e; return false; } $this->dbError = false; return true; } public function getSummary() { $pageTitle = '

' . t('Authentication') . '

'; $backendTitle = '

' . t('Backend Configuration') . '

'; $adminTitle = '

' . t('Initial Administrative Account') . '

'; $authType = $this->data['backendConfig']['backend']; $backendDesc = '

' . sprintf( t('Users will authenticate using %s.', 'setup.summary.auth'), $authType === 'db' ? t('a database', 'setup.summary.auth.type') : ( $authType === 'ldap' ? 'LDAP' : t('webserver authentication', 'setup.summary.auth.type') ) ) . '

'; $backendHtml = '' . '' . '' . '' . '' . '' . '' . ($authType === 'ldap' ? ( '' . '' . '' . '' . '' . '' . '' . '' ) : ($authType === 'autologin' ? ( '' . '' . '' . '' ) : '')) . '' . '
' . t('Backend Name') . '' . $this->data['backendConfig']['name'] . '
' . t('User Object Class') . '' . $this->data['backendConfig']['user_class'] . '
' . t('User Name Attribute') . '' . $this->data['backendConfig']['user_name_attribute'] . '
' . t('Filter Pattern') . '' . $this->data['backendConfig']['strip_username_regexp'] . '
'; $adminHtml = '

' . (isset($this->data['adminAccountData']['resourceConfig']) ? sprintf( t('Administrative rights will initially be granted to a new account called "%s".'), $this->data['adminAccountData']['username'] ) : sprintf( t('Administrative rights will initially be granted to an existing account called "%s".'), $this->data['adminAccountData']['username'] )) . '

'; return $pageTitle . '
' . $backendDesc . $backendTitle . $backendHtml . '
' . '
' . $adminTitle . $adminHtml . '
'; } public function getReport() { $report = ''; if ($this->authIniError === false) { $message = t('Authentication configuration has been successfully written to: %s'); $report .= '

' . sprintf($message, Config::resolvePath('authentication.ini')) . '

'; } elseif ($this->authIniError !== null) { $message = t('Authentication configuration could not be written to: %s; An error occured:'); $report .= '

' . sprintf($message, Config::resolvePath('authentication.ini')) . '

' . '

' . $this->authIniError->getMessage() . '

'; } if ($this->dbError === false) { $message = t('Account "%s" has been successfully created.'); $report .= '

' . sprintf($message, $this->data['adminAccountData']['username']) . '

'; } elseif ($this->dbError !== null) { $message = t('Unable to create account "%s". An error occured:'); $report .= '

' . sprintf($message, $this->data['adminAccountData']['username']) . '

' . '

' . $this->dbError->getMessage() . '

'; } if ($this->permIniError === false) { $message = t('Account "%s" has been successfully defined as initial administrator.'); $report .= '

' . sprintf($message, $this->data['adminAccountData']['username']) . '

'; } elseif ($this->permIniError !== null) { $message = t('Unable to define account "%s" as initial administrator. An error occured:'); $report .= '

' . sprintf($message, $this->data['adminAccountData']['username']) . '

' . '

' . $this->permIniError->getMessage() . '

'; } return $report; } }