data = $data; } public function apply() { $success = $this->createAuthenticationIni(); if (isset($this->data['adminAccountData']['resourceConfig'])) { $success &= $this->createAccount(); } $success &= $this->createRolesIni(); 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 { Config::fromArray($config) ->setConfigFile(Config::resolvePath('authentication.ini')) ->saveIni(); } catch (Exception $e) { $this->authIniError = $e; return false; } $this->authIniError = false; return true; } protected function createRolesIni() { if (isset($this->data['adminAccountData']['username'])) { $config = array( 'users' => $this->data['adminAccountData']['username'], 'permissions' => '*' ); if ($this->data['backendConfig']['backend'] === 'db') { $config['groups'] = mt('setup', 'Administrators', 'setup.role.name'); } } else { // isset($this->data['adminAccountData']['groupname']) $config = array( 'groups' => $this->data['adminAccountData']['groupname'], 'permissions' => '*' ); } try { Config::fromArray(array(mt('setup', 'Administrators', 'setup.role.name') => $config)) ->setConfigFile(Config::resolvePath('roles.ini')) ->saveIni(); } 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 ($backend->select()->where('user_name', $this->data['adminAccountData']['username'])->count() === 0) { $backend->insert('user', array( 'user_name' => $this->data['adminAccountData']['username'], 'password' => $this->data['adminAccountData']['password'], 'is_active' => true )); $this->dbError = false; } } catch (Exception $e) { $this->dbError = $e; return 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' || $authType === 'msldap' ? 'LDAP' : ( mt('setup', 'webserver authentication', 'setup.summary.auth.type') ) ) ) . '
'; $backendHtml = '' . '' . t('Backend Name') . ' | ' . '' . $this->data['backendConfig']['name'] . ' | ' . '
' . mt('setup', 'User Object Class') . ' | ' . '' . ($authType === 'msldap' ? 'user' : $this->data['backendConfig']['user_class']) . ' | ' . '
' . mt('setup', 'Custom Filter') . ' | ' . '' . (trim($this->data['backendConfig']['filter']) ?: t('None', 'auth.ldap.filter')) . ' | ' . '
' . mt('setup', 'User Name Attribute') . ' | ' . '' . ($authType === 'msldap' ? 'sAMAccountName' : $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'] )) . '
'; } else { // isset($this->data['adminAccountData']['groupname']) $adminHtml = '' . sprintf( mt('setup', 'Administrative rights will initially be granted to members of the user group "%s".'), $this->data['adminAccountData']['groupname'] ) . '
'; } return $pageTitle . '