1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
<?php
if (!defined('UPDRAFTPLUS_DIR')) die('No direct access allowed.');
require_once(UPDRAFTPLUS_DIR.'/methods/s3.php');
/** * Converted to multi-options (Feb 2017-) and previous options conversion removed: Yes */ class UpdraftPlus_BackupModule_s3generic extends UpdraftPlus_BackupModule_s3 {
protected $use_v4 = false;
/** * Given an S3 object, possibly set the region on it * * @param Object $obj - like UpdraftPlus_S3 * @param String $region * @param String $bucket_name */ protected function set_region($obj, $region = '', $bucket_name = '') { $config = $this->get_config(); $endpoint = ('' != $region && 'n/a' != $region) ? $region : $config['endpoint']; $log_message = "Set endpoint: $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 * * @return String - the template */ public function get_pre_configuration_template() { $this->get_pre_configuration_template_engine('s3generic', 'S3', __('S3 (Compatible)', 'updraftplus'), 'S3', '', ''); }
/** * Get the configuration template * * @return String - the template, ready for substitutions to be carried out */ public function get_configuration_template() { // 5th parameter = control panel URL // 6th = image HTML return $this->get_configuration_template_engine('s3generic', 'S3', __('S3 (Compatible)', 'updraftplus'), 'S3', '', ''); } /** * 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) { 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'])); } /** * Get handlebar partial template string for endpoint of s3 compatible remote storage method. Other child class can extend it. * * @return string the partial template string */ protected function get_partial_configuration_template_for_endpoint() { return '<tr class="'.$this->get_css_classes().'"> <th>'.sprintf(__('%s end-point', 'updraftplus'), 'S3').'</th> <td> <input data-updraft_settings_test="endpoint" type="text" class="updraft_input--wide" '.$this->output_settings_field_name_and_id('endpoint', true).' value="{{endpoint}}" /> </td> </tr>'; }
/** * Perform a test of user-supplied credentials, and echo the result * * @param Array $posted_settings - settings to test */ public function credentials_test($posted_settings) { $this->credentials_test_engine($this->get_config(), $posted_settings); } }
|