From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- modules/setup/library/Setup/Steps/ResourceStep.php | 199 +++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 modules/setup/library/Setup/Steps/ResourceStep.php (limited to 'modules/setup/library/Setup/Steps/ResourceStep.php') diff --git a/modules/setup/library/Setup/Steps/ResourceStep.php b/modules/setup/library/Setup/Steps/ResourceStep.php new file mode 100644 index 0000000..d9daf3b --- /dev/null +++ b/modules/setup/library/Setup/Steps/ResourceStep.php @@ -0,0 +1,199 @@ +data = $data; + } + + public function apply() + { + $resourceConfig = array(); + if (isset($this->data['dbResourceConfig'])) { + $dbConfig = $this->data['dbResourceConfig']; + $resourceName = $dbConfig['name']; + unset($dbConfig['name']); + $resourceConfig[$resourceName] = $dbConfig; + } + + if (isset($this->data['ldapResourceConfig'])) { + $ldapConfig = $this->data['ldapResourceConfig']; + $resourceName = $ldapConfig['name']; + unset($ldapConfig['name']); + $resourceConfig[$resourceName] = $ldapConfig; + } + + try { + Config::fromArray($resourceConfig) + ->setConfigFile(Config::resolvePath('resources.ini')) + ->saveIni(); + } catch (Exception $e) { + $this->error = $e; + return false; + } + + $this->error = false; + return true; + } + + public function getSummary() + { + if (isset($this->data['dbResourceConfig']) && isset($this->data['ldapResourceConfig'])) { + $pageTitle = '

' . mt('setup', 'Resources', 'setup.page.title') . '

'; + } else { + $pageTitle = '

' . mt('setup', 'Resource', 'setup.page.title') . '

'; + } + + if (isset($this->data['dbResourceConfig'])) { + $dbTitle = '

' . mt('setup', 'Database', 'setup.page.title') . '

'; + $dbHtml = '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . ''; + + if (defined('\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT') + && isset($this->data['resourceConfig']['ssl_do_not_verify_server_cert']) + && $this->data['resourceConfig']['ssl_do_not_verify_server_cert'] + ) { + $dbHtml .= '' + . '' + . '' + . '' + . ''; + } + if (isset($this->data['dbResourceConfig']['ssl_key']) && $this->data['dbResourceConfig']['ssl_key']) { + $dbHtml .= '' + .'' + . '' + . '' + . ''; + } + if (isset($this->data['dbResourceConfig']['ssl_cert']) && $this->data['dbResourceConfig']['ssl_cert']) { + $dbHtml .= '' + . '' + . '' + . '' + . ''; + } + if (isset($this->data['dbResourceConfig']['ssl_ca']) && $this->data['dbResourceConfig']['ssl_ca']) { + $dbHtml .= '' + . '' + . '' + . '' + . ''; + } + if (isset($this->data['dbResourceConfig']['ssl_capath']) && $this->data['dbResourceConfig']['ssl_capath']) { + $dbHtml .= '' + . '' + . '' + . '' + . ''; + } + if (isset($this->data['dbResourceConfig']['ssl_cipher']) && $this->data['dbResourceConfig']['ssl_cipher']) { + $dbHtml .= '' + . '' + . '' + . '' + . ''; + } + + $dbHtml .= '' + . '' + . '
' . t('Resource Name') . '' . $this->data['dbResourceConfig']['name'] . '
' . t('Database Type') . '' . $this->data['dbResourceConfig']['db'] . '
' . t('Host') . '' . $this->data['dbResourceConfig']['host'] . '
' . t('Port') . '' . $this->data['dbResourceConfig']['port'] . '
' . t('Database Name') . '' . $this->data['dbResourceConfig']['dbname'] . '
' . t('Username') . '' . $this->data['dbResourceConfig']['username'] . '
' . t('Password') . '' . str_repeat('*', strlen($this->data['dbResourceConfig']['password'])) . '
' . t('SSL Do Not Verify Server Certificate') . '' . $this->data['resourceConfig']['ssl_do_not_verify_server_cert'] . '
' . t('SSL Key') . '' . $this->data['dbResourceConfig']['ssl_key'] . '
' . t('SSL Cert') . '' . $this->data['dbResourceConfig']['ssl_cert'] . '
' . t('CA') . '' . $this->data['dbResourceConfig']['ssl_ca'] . '
' . t('CA Path') . '' . $this->data['dbResourceConfig']['ssl_capath'] . '
' . t('Cipher') . '' . $this->data['dbResourceConfig']['ssl_cipher'] . '
'; + } + + if (isset($this->data['ldapResourceConfig'])) { + $ldapTitle = '

LDAP

'; + $ldapHtml = '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '
' . t('Resource Name') . '' . $this->data['ldapResourceConfig']['name'] . '
' . t('Host') . '' . $this->data['ldapResourceConfig']['hostname'] . '
' . t('Port') . '' . $this->data['ldapResourceConfig']['port'] . '
' . t('Root DN') . '' . $this->data['ldapResourceConfig']['root_dn'] . '
' . t('Bind DN') . '' . $this->data['ldapResourceConfig']['bind_dn'] . '
' . t('Bind Password') . '' . str_repeat('*', strlen($this->data['ldapResourceConfig']['bind_pw'])) . '
'; + } + + return $pageTitle . (isset($dbTitle) ? '
' . $dbTitle . $dbHtml . '
' : '') + . (isset($ldapTitle) ? '
' . $ldapTitle . $ldapHtml . '
' : ''); + } + + public function getReport() + { + if ($this->error === false) { + return array(sprintf( + mt('setup', 'Resource configuration has been successfully written to: %s'), + Config::resolvePath('resources.ini') + )); + } elseif ($this->error !== null) { + return array( + sprintf( + mt('setup', 'Resource configuration could not be written to: %s. An error occured:'), + Config::resolvePath('resources.ini') + ), + sprintf(mt('setup', 'ERROR: %s'), IcingaException::describe($this->error)) + ); + } + } +} -- cgit v1.2.3