PluginProbe
UpdraftPlus: WP Backup & Migration Plugin / 1.22.24
UpdraftPlus: WP Backup & Migration Plugin v1.22.24
1.26.7 1.26.6 1.26.5 1.26.4 1.26.3 1.9.19 1.9.25 1.9.26 1.9.30 1.9.31 1.9.32 1.9.4 1.9.40 1.9.41 1.9.42 1.9.43 1.9.44 1.9.45 1.9.46 1.9.5 1.9.50 1.9.51 1.9.60 1.9.62 1.9.63 All 371 releases
updraftplus / methods / openstack2.php

openstack2.php in UpdraftPlus: WP Backup & Migration Plugin 1.22.24, at methods/openstack2.php

263 lines 12.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('UPDRAFTPLUS_DIR')) die('No direct access allowed.');
4
5 // SDK uses namespacing - requires PHP 5.3 (actually the SDK states its requirements as 5.3.3)
6 // @codingStandardsIgnoreLine
7 use OpenCloud\OpenStack;
8
9 updraft_try_include_file('methods/openstack-base.php', 'require_once');
10
11 class UpdraftPlus_BackupModule_openstack extends UpdraftPlus_BackupModule_openstack_base {
12
13 public function __construct() {
14 // 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)
15 parent::__construct('openstack', 'OpenStack', 'OpenStack (Swift)', '');
16 }
17
18 /**
19 * Get Openstack service
20 *
21 * @param String $opts THis contains: 'tenant', 'user', 'password', 'authurl', (optional) 'region'
22 * @param Boolean $useservercerts User server certificates
23 * @param String $disablesslverify Check to disable SSL Verify
24 * @return Array
25 */
26 public function get_openstack_service($opts, $useservercerts = false, $disablesslverify = null) {
27
28 // 'tenant', 'user', 'password', 'authurl', 'path', (optional) 'region'
29 extract($opts);
30
31 if (null === $disablesslverify) $disablesslverify = UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify');
32
33 if (empty($user) || empty($password) || empty($authurl)) throw new Exception(__('Authorisation failed (check your credentials)', 'updraftplus'));// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $user, $password and $authurl being extracted in extract() line 29
34
35 updraft_try_include_file('vendor/autoload.php', 'include_once');
36 global $updraftplus;
37 $updraftplus->log("OpenStack authentication URL: ".$authurl);// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $authurl being extracted in extract() line 29
38
39 $client = new OpenStack($authurl, array(// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $authurl being extracted in extract() line 29
40 'username' => $user,// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $user being extracted in extract() line 29
41 'password' => $password,// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $password being extracted in extract() line 29
42 'tenantName' => $tenant// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- $tenant being extracted in extract() line 29
43 ));
44 $this->client = $client;
45
46 if ($disablesslverify) {
47 $client->setSslVerification(false);
48 } else {
49 if ($useservercerts) {
50 $client->setConfig(array($client::SSL_CERT_AUTHORITY => false));
51 } else {
52 $client->setSslVerification(UPDRAFTPLUS_DIR.'/includes/cacert.pem', true, 2);
53 }
54 }
55
56 $client->authenticate();
57
58 if (empty($region)) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
59 $catalog = $client->getCatalog();
60 if (!empty($catalog)) {
61 $items = $catalog->getItems();
62 if (is_array($items)) {
63 foreach ($items as $item) {
64 $name = $item->getName();
65 $type = $item->getType();
66 if ('swift' != $name || 'object-store' != $type) continue;
67 $eps = $item->getEndpoints();
68 if (!is_array($eps)) continue;
69 foreach ($eps as $ep) {
70 if (is_object($ep) && !empty($ep->region)) {
71 $region = $ep->region;
72 }
73 }
74 }
75 }
76 }
77 }
78
79 $this->region = $region;
80
81 return $client->objectStoreService('swift', $region);
82
83 }
84
85 /**
86 * This method overrides the parent method and lists the supported features of this remote storage option.
87 *
88 * @return Array - an array of supported features (any features not
89 * mentioned are assumed to not be supported)
90 */
91 public function get_supported_features() {
92 // This options format is handled via only accessing options via $this->get_options()
93 return array('multi_options', 'config_templates', 'multi_storage', 'conditional_logic');
94 }
95
96 /**
97 * Retrieve default options for this remote storage module.
98 *
99 * @return Array - an array of options
100 */
101 public function get_default_options() {
102 return array(
103 'user' => '',
104 'authurl' => '',
105 'password' => '',
106 'tenant' => '',
107 'path' => '',
108 'region' => ''
109 );
110 }
111
112 public function credentials_test($posted_settings) {
113
114 if (empty($posted_settings['user'])) {
115 printf(__("Failure: No %s was given.", 'updraftplus'), __('username', 'updraftplus'));
116 return;
117 }
118
119 if (empty($posted_settings['password'])) {
120 printf(__("Failure: No %s was given.", 'updraftplus'), __('password', 'updraftplus'));
121 return;
122 }
123
124 if (empty($posted_settings['tenant'])) {
125 printf(__("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'));
126 return;
127 }
128
129 if (empty($posted_settings['authurl'])) {
130 printf(__("Failure: No %s was given.", 'updraftplus'), __('authentication URI', 'updraftplus'));
131 return;
132 }
133
134 $opts = array(
135 'user' => $posted_settings['user'],
136 'password' => $posted_settings['password'],
137 'authurl' => $posted_settings['authurl'],
138 'tenant' => $posted_settings['tenant'],
139 'region' => empty($posted_settings['region']) ? '' : $posted_settings['region'],
140 );
141
142 $this->credentials_test_go($opts, $posted_settings['path'], $posted_settings['useservercerts'], $posted_settings['disableverify']);
143 }
144
145 /**
146 * Check whether options have been set up by the user, or not
147 *
148 * @param Array $opts - the potential options
149 *
150 * @return Boolean
151 */
152 public function options_exist($opts) {
153 if (is_array($opts) && $opts['user'] && '' !== $opts['user'] && !empty($opts['authurl'])) return true;
154 return false;
155 }
156
157 /**
158 * Get the pre configuration template
159 *
160 * @return String - the template
161 */
162 public function get_pre_configuration_template() {
163 ?>
164 <tr class="{{get_template_css_classes false}} {{method_id}}_pre_config_container">
165 <td colspan="2">
166 {{#if storage_image_url}}
167 <img alt="{{storage_long_description}}" src="{{storage_image_url}}">
168 {{/if}}
169 <br>
170 {{{mb_substr_existence_label}}}
171 {{{curl_existence_label}}}
172 <br>
173 <p>{{openstack_text_description}} <a href="{{faq_link_url}}" target="_blank">{{faq_link_text}}</a></p>
174 </td>
175 </tr>
176
177 <?php
178 }
179
180 /**
181 * Get the configuration template
182 *
183 * @return String - the template, ready for substitutions to be carried out
184 */
185 public function get_configuration_template() {
186 ob_start();
187 ?>
188 <tr class="{{get_template_css_classes true}}">
189 <th>{{input_authentication_uri_label}}:</th>
190 <td><input title="{{input_authentication_uri_title}}" data-updraft_settings_test="authurl" type="text" autocomplete="off" class="updraft_input--wide udc-wd-600" id="{{get_template_input_attribute_value "id" "authurl"}}" name="{{get_template_input_attribute_value "name" "authurl"}}" value="{{authurl}}" />
191 <br>
192 <em>{{input_authentication_uri_title}}</em>
193 </td>
194 </tr>
195
196 <tr class="{{get_template_css_classes true}}">
197 <th><a href="{{input_tenant_link_url}}" title="{{input_tenant_link_title}}" target="_blank">{{input_tenant_label}}</a>:</th>
198 <td><input data-updraft_settings_test="tenant" type="text" autocomplete="off" class="updraft_input--wide udc-wd-600" id="{{get_template_input_attribute_value "id" "tenant"}}" name="{{get_template_input_attribute_value "name" "tenant"}}" value="{{tenant}}" />
199 </td>
200 </tr>
201
202 <tr class="{{get_template_css_classes true}}">
203 <th>{{input_region_label}}:</th>
204 <td><input title="{{input_region_title}}" data-updraft_settings_test="region" type="text" autocomplete="off" class="updraft_input--wide udc-wd-600" id="{{get_template_input_attribute_value "id" "region"}}" name="{{get_template_input_attribute_value "name" "region"}}" value="{{region}}" />
205 <br>
206 <em>{{input_region_title}}</em>
207 </td>
208 </tr>
209
210 <tr class="{{get_template_css_classes true}}">
211 <th>{{input_username_label}}:</th>
212 <td><input data-updraft_settings_test="user" type="text" autocomplete="off" class="updraft_input--wide udc-wd-600" id="{{get_template_input_attribute_value "id" "user"}}" name="{{get_template_input_attribute_value "name" "user"}}" value="{{user}}" />
213 </td>
214 </tr>
215
216 <tr class="{{get_template_css_classes true}}">
217 <th>{{input_password_label}}:</th>
218 <td><input data-updraft_settings_test="password" type="{{input_password_type}}" autocomplete="off" class="updraft_input--wide udc-wd-600" id="{{get_template_input_attribute_value "id" "password"}}" name="{{get_template_input_attribute_value "name" "password"}}" value="{{password}}" />
219 </td>
220 </tr>
221
222 <tr class="{{get_template_css_classes true}}">
223 <th>{{input_container_label}}:</th>
224 <td><input data-updraft_settings_test="path" type="text" class="updraft_input--wide udc-wd-600" id="{{get_template_input_attribute_value "id" "path"}}" name="{{get_template_input_attribute_value "name" "path"}}" value="{{path}}" /></td>
225 </tr>
226 {{{get_template_test_button_html "OpenStack (Swift)"}}}
227 <?php
228 return ob_get_clean();
229 }
230
231 /**
232 * 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
233 * 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
234 *
235 * @return Array an associative array keyed by names that describe themselves as they are
236 */
237 public function get_template_properties() {
238 global $updraftplus, $updraftplus_admin;
239 $properties = array(
240 'storage_image_url' => !empty($this->img_url) ? UPDRAFTPLUS_URL.$this->img_url : '',
241 'storage_long_description' => $this->long_desc,
242 'mb_substr_existence_label' => !apply_filters('updraftplus_openstack_mbsubstr_exists', function_exists('mb_substr')) ? wp_kses($updraftplus_admin->show_double_warning('<strong>'.__('Warning', 'updraftplus').':</strong> '.sprintf(__('Your web server\'s PHP installation does not include a required module (%s). Please contact your web hosting provider\'s support.', 'updraftplus'), 'mbstring').' '.sprintf(__("UpdraftPlus's %s module <strong>requires</strong> %s. Please do not file any support requests; there is no alternative.", 'updraftplus'), $this->desc, 'mbstring'), $this->method, false), $this->allowed_html_for_content_sanitisation()) : '',
243 '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()),
244 'openstack_text_description' => __('Get your access credentials from your OpenStack Swift provider, and then pick a container name to use for storage. This container will be created for you if it does not already exist.', 'updraftplus'),
245 'faq_link_text' => __('Also, you should read this important FAQ.', 'updraftplus'),
246 'faq_link_url' => wp_kses(apply_filters("updraftplus_com_link", "https://updraftplus.com/faqs/there-appear-to-be-lots-of-extra-files-in-my-rackspace-cloud-files-container/"), array(), array('http', 'https')),
247 'input_authentication_uri_label' => __('Authentication URI', 'updraftplus'),
248 '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'),
249 'input_tenant_label' => __('Tenant', 'updraftplus'),
250 'input_tenant_link_url' => 'https://docs.openstack.org/openstack-ops/content/projects_users.html',
251 'input_tenant_link_title' => __('Follow this link for more information', 'updraftplus'),
252 'input_region_label' => __('Region', 'updraftplus'),
253 'input_region_title' => __('Leave this blank, and a default will be chosen.', 'updraftplus'),
254 'input_username_label' => __('Username', 'updraftplus'),
255 'input_password_label' => __('Password', 'updraftplus'),
256 'input_password_type' => apply_filters('updraftplus_admin_secret_field_type', 'password'),
257 'input_container_label' => __('Container', 'updraftplus'),
258 'input_test_label' => sprintf(__('Test %s Settings', 'updraftplus'), $updraftplus->backup_methods[$this->get_id()]),
259 );
260 return wp_parse_args($properties, $this->get_persistent_variables_and_methods());
261 }
262 }
263