array( 'default_value' => '', 'template_property_input_mapping' => 'authentication_uri', 'contexts' => array('option', 'input'), ), 'tenant' => array( 'default_value' => '', 'contexts' => array('option', 'input'), ), 'region' => array( 'default_value' => '', 'contexts' => array('option', 'input'), ), 'user' => array( 'default_value' => '', 'template_property_input_mapping' => 'username', 'contexts' => array('option', 'input'), ), 'password' => array( 'default_value' => '', 'contexts' => array('option', 'input'), ), 'path' => array( 'default_value' => '', 'template_property_input_mapping' => 'container', 'contexts' => array('option', 'input'), ), ); public function __construct() { // 4th parameter is a relative (to UPDRAFTPLUS_DIR) logo URL, which should begin with /, should we get approved for use of the OpenStack logo in future (have requested info) parent::__construct('openstack', 'OpenStack', 'OpenStack (Swift)', ''); } /** * Get Openstack service * * @param String $opts THis contains: 'tenant', 'user', 'password', 'authurl', (optional) 'region' * @param Boolean $useservercerts User server certificates * @param String $disablesslverify Check to disable SSL Verify * @return Array */ public function get_openstack_service($opts, $useservercerts = false, $disablesslverify = null) { // 'tenant', 'user', 'password', 'authurl', 'path', (optional) 'region' extract($opts); if (null === $disablesslverify) $disablesslverify = UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'); if (empty($user) || empty($password) || empty($authurl)) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $user, $password and $authurl being extracted in extract() line 29 throw new Exception(__('Authorisation failed (check your credentials)', 'updraftplus')); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Error message to be escaped when caught and printed. } updraft_try_include_file('vendor/autoload.php', 'include_once'); global $updraftplus; $updraftplus->log("OpenStack authentication URL: ".$authurl);// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $authurl being extracted in extract() line 29 $client = new OpenStack($authurl, array(// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $authurl being extracted in extract() line 29 'username' => $user,// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $user being extracted in extract() line 29 'password' => $password,// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $password being extracted in extract() line 29 'tenantName' => $tenant// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $tenant being extracted in extract() line 29 )); $this->client = $client; if ($disablesslverify) { $client->setSslVerification(false); } else { if ($useservercerts) { $client->setConfig(array($client::SSL_CERT_AUTHORITY => false)); } else { $client->setSslVerification(UPDRAFTPLUS_DIR.'/includes/cacert.pem', true, 2); } } $client->authenticate(); if (empty($region)) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- The variable is defined below. $catalog = $client->getCatalog(); if (!empty($catalog)) { $items = $catalog->getItems(); if (is_array($items)) { foreach ($items as $item) { $name = $item->getName(); $type = $item->getType(); if ('swift' != $name || 'object-store' != $type) continue; $eps = $item->getEndpoints(); if (!is_array($eps)) continue; foreach ($eps as $ep) { if (is_object($ep) && !empty($ep->region)) { $region = $ep->region; } } } } } } $this->region = $region; return $client->objectStoreService('swift', $region); } /** * This method overrides the parent method and lists the supported features of this remote storage option. * * @return Array - an array of supported features (any features not * mentioned are assumed to not be supported) */ public function get_supported_features() { // This options format is handled via only accessing options via $this->get_options() return array('multi_options', 'config_templates', 'multi_storage', 'conditional_logic'); } public function credentials_test($posted_settings) { if (empty($posted_settings['user'])) { /* translators: %s: Username */ echo esc_html(sprintf(__("Failure: No %s was given.", 'updraftplus'), __('username', 'updraftplus'))); return; } if (empty($posted_settings['password'])) { /* translators: %s: Password */ echo esc_html(sprintf(__("Failure: No %s was given.", 'updraftplus'), __('password', 'updraftplus'))); return; } if (empty($posted_settings['tenant'])) { /* translators: %s: Tenant (used in OpenStack storage) */ echo esc_html(sprintf(__("Failure: No %s was given.", 'updraftplus'), _x('tenant', '"tenant" is a term used with OpenStack storage - Google for "OpenStack tenant" to get more help on its meaning', 'updraftplus'))); return; } if (empty($posted_settings['authurl'])) { /* translators: %s: Authentication URI */ echo esc_html(sprintf(__("Failure: No %s was given.", 'updraftplus'), __('authentication URI', 'updraftplus'))); return; } $opts = array( 'user' => $posted_settings['user'], 'password' => $posted_settings['password'], 'authurl' => $posted_settings['authurl'], 'tenant' => $posted_settings['tenant'], 'region' => empty($posted_settings['region']) ? '' : $posted_settings['region'], ); $this->credentials_test_go($opts, $posted_settings['path'], $posted_settings['useservercerts'], $posted_settings['disableverify']); } /** * Check whether options have been set up by the user, or not * * @param Array $opts - the potential options * * @return Boolean */ public function options_exist($opts) { if (is_array($opts) && $opts['user'] && '' !== $opts['user'] && !empty($opts['authurl'])) return true; return false; } /** * Get the pre configuration template * * @return String - the template */ public function get_pre_configuration_template() { ?>
{{openstack_text_description}} {{faq_link_text}}