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 IniWriter(array( 'config' => Config::fromArray($config), 'filename' => Config::resolvePath('authentication.ini') )); $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 IniWriter(array( 'config' => Config::fromArray($config), 'filename' => Config::resolvePath('permissions.ini') )); $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 ConfigObject($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 = '
' . sprintf( mt('setup', 'Users will authenticate using %s.', 'setup.summary.auth'), $authType === 'db' ? mt('setup', 'a database', 'setup.summary.auth.type') : ( $authType === 'ldap' ? 'LDAP' : mt('setup', 'webserver authentication', 'setup.summary.auth.type') ) ) . '
'; $backendHtml = '' . '' . 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'] . ' | ' . '
' . (isset($this->data['adminAccountData']['resourceConfig']) ? sprintf( mt('setup', 'Administrative rights will initially be granted to a new account called "%s".'), $this->data['adminAccountData']['username'] ) : sprintf( mt('setup', 'Administrative rights will initially be granted to an existing account called "%s".'), $this->data['adminAccountData']['username'] )) . '
'; return $pageTitle . '' . sprintf($message, Config::resolvePath('authentication.ini')) . '
'; } elseif ($this->authIniError !== null) { $message = mt('setup', '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 = mt('setup', 'Account "%s" has been successfully created.'); $report .= '' . sprintf($message, $this->data['adminAccountData']['username']) . '
'; } elseif ($this->dbError !== null) { $message = mt('setup', 'Unable to create account "%s". An error occured:'); $report .= '' . sprintf($message, $this->data['adminAccountData']['username']) . '
' . '' . $this->dbError->getMessage() . '
'; } if ($this->permIniError === false) { $message = mt('setup', 'Account "%s" has been successfully defined as initial administrator.'); $report .= '' . sprintf($message, $this->data['adminAccountData']['username']) . '
'; } elseif ($this->permIniError !== null) { $message = mt('setup', 'Unable to define account "%s" as initial administrator. An error occured:'); $report .= '' . sprintf($message, $this->data['adminAccountData']['username']) . '
' . '' . $this->permIniError->getMessage() . '
'; } return $report; } }