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');
}
/**
* Retrieve default options for this remote storage module.
*
* @return Array - an array of options
*/
public function get_default_options() {
return array(
'user' => '',
'authurl' => '',
'password' => '',
'tenant' => '',
'path' => '',
'region' => ''
);
}
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() {
?>
{{{get_template_test_button_html "OpenStack (Swift)"}}}
show_double_warning(
''.__('Warning', 'updraftplus').': '.
/* translators: %s: Required module name */
sprintf(__('Your web server\'s PHP installation does not include a required module (%s).', 'updraftplus'), 'mbstring').' '.
__('Please contact your web hosting provider\'s support.', 'updraftplus').' '.
/* translators: 1: Module name, 2: Required module name */
sprintf(__('UpdraftPlus\'s %1$s module requires %2$s.', 'updraftplus'), $this->desc, 'mbstring').' '.
__('Please do not file any support requests; there is no alternative.', 'updraftplus'),
$this->method,
false
), $this->allowed_html_for_content_sanitisation());
}
$properties = array(
'storage_image_url' => !empty($this->img_url) ? UPDRAFTPLUS_URL.$this->img_url : '',
'storage_long_description' => $this->long_desc,
'mb_substr_existence_label' => $mb_substr_existence_label,
'curl_existence_label' => wp_kses($updraftplus_admin->curl_check($this->long_desc, false, $this->method.' hidden-in-updraftcentral', false), $this->allowed_html_for_content_sanitisation()),
'openstack_text_description' => __('Get your access credentials from your OpenStack Swift provider, and then pick a container name to use for storage.', 'updraftplus').' '.__('This container will be created for you if it does not already exist.', 'updraftplus'),
'faq_link_text' => __('Also, you should read this important FAQ.', 'updraftplus'),
'faq_link_url' => wp_kses(apply_filters("updraftplus_com_link", "https://teamupdraft.com/documentation/updraftplus/topics/cloud-storage/rackspace/there-are-extra-files-in-my-rackspace-cloud-files-container/?utm_source=udp-plugin&utm_medium=referral&utm_campaign=paac&utm_content=openstack-important-faq&utm_creative_format=tex"), array(), array('http', 'https')),
'input_authentication_uri_label' => __('Authentication URI', 'updraftplus'),
'input_authentication_uri_title' => _x('This needs to be a v2 (Keystone) authentication URI; v1 (Swauth) is not supported.', 'Keystone and swauth are technical terms which cannot be translated', 'updraftplus'),
'input_tenant_label' => __('Tenant', 'updraftplus'),
'input_tenant_link_url' => 'https://docs.openstack.org/openstack-ops/content/projects_users.html',
'input_tenant_link_title' => __('Follow this link for more information', 'updraftplus'),
'input_region_label' => __('Region', 'updraftplus'),
'input_region_title' => __('Leave this blank, and a default will be chosen.', 'updraftplus'),
'input_username_label' => __('Username', 'updraftplus'),
'input_password_label' => __('Password', 'updraftplus'),
'input_password_type' => apply_filters('updraftplus_admin_secret_field_type', 'password'),
'input_container_label' => __('Container', 'updraftplus'),
/* translators: %s: Remote storage method */
'input_test_label' => sprintf(__('Test %s Settings', 'updraftplus'), $updraftplus->backup_methods[$this->get_id()]),
);
return wp_parse_args($properties, $this->get_persistent_variables_and_methods());
}
}