OS : Linux
PHP Version : 7.4.33
Software : Apache/2.4.6 (CentOS) PHP/7.4.33
Information System : get_config();
$endpoint = ('' != $region && 'n/a' != $region) ? $region : $config['endpoint'];
if (!empty($endpoint)) {
$endpoint = preg_replace('/^(http|https):\/\//i', '', trim($endpoint));
}
$log_message = "Set endpoint (".get_class($obj)."): $endpoint";
$log_message_append = '';
if (is_string($endpoint) && preg_match('/^(.*):(\d+)$/', $endpoint, $matches)) {
$endpoint = $matches[1];
$port = $matches[2];
$log_message_append = ", port=$port";
$obj->setPort($port);
}
// This provider requires domain-style access. In future it might be better to provide an option rather than hard-coding the knowledge.
if (is_string($endpoint) && preg_match('/\.aliyuncs\.com$/i', $endpoint)) {
$obj->useDNSBucketName(true, $bucket_name);
}
global $updraftplus;
if ($updraftplus->backup_time) $this->log($log_message.$log_message_append);
$obj->setEndpoint($endpoint);
}
/**
* 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 asuumed 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(
'accesskey' => '',
'secretkey' => '',
'path' => '',
'endpoint' => '',
);
}
/**
* Retrieve specific options for this remote storage module
*
* @param Boolean $force_refresh - if set, and if relevant, don't use cached credentials, but get them afresh
*
* @return Array - an array of options
*/
protected function get_config($force_refresh = false) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Filter use
$opts = $this->get_options();
$opts['whoweare'] = 'S3';
$opts['whoweare_long'] = __('S3 (Compatible)', 'updraftplus');
$opts['key'] = 's3generic';
return $opts;
}
/**
* Get the pre configuration template
*/
public function get_pre_configuration_template() {
?>
{{{ssl_certificates_errors_link_text}}}
'.__('Examples of S3-compatible storage providers:', 'updraftplus').' DigitalOcean Spaces, Linode Object Storage, Cloudian, Connectria, Constant, Eucalyptus, Nifty, Cloudn'.__('... and many more!', 'updraftplus').'
partial_template_name }})
*
* @return Array an associative array keyed by name of the partial templates
*/
public function get_partial_templates() {
$partial_templates = array();
$partial_templates['s3generic_additional_configuration_top'] = '';
ob_start();
?>
{{{pre_template_opening_html}}}
{{{xmlwriter_existence_label}}}
{{{simplexmlelement_existence_label}}}
{{{curl_existence_label}}}
{{input_endpoint_label}}:
{{input_bucket_access_style_label}}:
{{{input_bucket_access_style_readmore}}}
get_id().'_partial_templates', $partial_templates), parent::get_partial_templates());
}
/**
* Modifies handerbar template options
* The function require because It should override parent class's UpdraftPlus_BackupModule_s3::transform_options_for_template() functionality with no operation.
*
* @param array $opts
* @return Array - Modified handerbar template options
*/
public function transform_options_for_template($opts) {
if (!empty($opts['instance_id']) && 'default' !== $opts['instance_id']) {
if (!isset($opts['signature_version'])) { // this check is to find out whether we're dealing with a pre-existing configuration or not
$opts['signature_version'] = 'v2'; // the pre-existing S3-Compatible configurations before signature_version was introduced by default use SigV2, so we wan't to keep it that way as we don't want to break what's already working
$opts['signature_version'] = apply_filters('updraftplus_s3_signature_version', $opts['signature_version'], false, $this);
if (!empty($opts['endpoint'])) {
if (preg_match('/\.(leviia|r2\.cloudflarestorage)\.com$/i', $opts['endpoint']) || (preg_match('/\.amazonaws\.com$/i', $opts['endpoint']) && !empty($opts['bucket_access_style']) && 'virtual_host_style' === $opts['bucket_access_style'])) {
// due to the merge of S3-generic bucket access style MR on March 2021, if virtual-host bucket access style is selected, connecting to an amazonaws bucket location where the user doesn't have an access to it will throw an S3 InvalidRequest exception. It requires the signature to be set to version 4
$opts['signature_version'] = 'v4';
}
}
}
if (!$this->options_exist($opts)) $opts['signature_version'] = 'v4'; // if no pre-existing S3-Compatible configurations were setup, there would always be an initial instance id created with a blank configuration form (no access key, secret key, location, and endpoint), this initial instance id/form should use SigV4
}
return $opts;
}
/**
* 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) {
return (parent::options_exist($opts) && !empty($opts['endpoint']));
}
/**
* Retrieve a list of template properties by taking all the persistent variables and methods of the parent class and combining them with the ones that are unique to this module, also the necessary HTML element attributes and texts which are also unique only to this backup module
* NOTE: Please sanitise all strings that are required to be shown as HTML content on the frontend side (i.e. wp_kses()), or any other technique to prevent XSS attacks that could come via WP hooks
*
* @return Array an associative array keyed by names that describe themselves as they are
*/
public function get_template_properties() {
global $updraftplus, $updraftplus_admin;
$properties = array(
'pre_template_opening_html' => wp_kses('{{input_signature_version_label}}:
{{{input_signature_version_readmore}}}