PluginProbe
UpdraftPlus: WP Backup & Migration Plugin / 1.22.19
UpdraftPlus: WP Backup & Migration Plugin v1.22.19
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.19, at methods/openstack2.php

222 lines 9.2 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 require_once(UPDRAFTPLUS_DIR.'/methods/openstack-base.php');
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 include_once(UPDRAFTPLUS_DIR.'/vendor/autoload.php');
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 /**
113 * Get the pre middlesection configuration template
114 *
115 * @return String - the template
116 */
117 public function get_pre_configuration_middlesection_template() {
118
119 ?>
120 <p><?php _e('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');?> <a href="<?php echo apply_filters("updraftplus_com_link", "https://updraftplus.com/faqs/there-appear-to-be-lots-of-extra-files-in-my-rackspace-cloud-files-container/");?>" target="_blank"><?php _e('Also, you should read this important FAQ.', 'updraftplus'); ?></a></p>
121
122 <?php
123 }
124
125 /**
126 * This outputs the html to the settings page for the Openstack settings.
127 *
128 * @return String - the partial template, ready for substitutions to be carried out
129 */
130 public function get_configuration_middlesection_template() {
131 ob_start();
132 $classes = $this->get_css_classes();
133 ?>
134
135 <tr class="<?php echo $classes; ?>">
136 <th><?php echo ucfirst(__('authentication URI', 'updraftplus'));?>:</th>
137 <td><input title="<?php echo _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');?>" data-updraft_settings_test="authurl" type="text" autocomplete="off" class="updraft_input--wide" <?php $this->output_settings_field_name_and_id('authurl');?> value="{{authurl}}" />
138 <br>
139 <em><?php echo _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');?></em>
140 </td>
141 </tr>
142
143 <tr class="<?php echo $classes; ?>">
144 <th><a href="http://docs.openstack.org/openstack-ops/content/projects_users.html" title="<?php _e('Follow this link for more information', 'updraftplus');?>" target="_blank"><?php _e('Tenant', 'updraftplus');?></a>:</th>
145 <td><input data-updraft_settings_test="tenant" type="text" autocomplete="off" class="updraft_input--wide" <?php $this->output_settings_field_name_and_id('tenant');?> value="{{tenant}}" />
146 </td>
147 </tr>
148
149 <tr class="<?php echo $classes; ?>">
150 <th><?php _e('Region', 'updraftplus');?>:</th>
151 <td><input title="<?php _e('Leave this blank, and a default will be chosen.', 'updraftplus');?>" data-updraft_settings_test="region" type="text" autocomplete="off" class="updraft_input--wide" <?php $this->output_settings_field_name_and_id('region');?> value="{{region}}" />
152 <br>
153 <em><?php _e('Leave this blank, and a default will be chosen.', 'updraftplus');?></em>
154 </td>
155 </tr>
156
157 <tr class="<?php echo $classes; ?>">
158 <th><?php _e('Username', 'updraftplus');?>:</th>
159 <td><input data-updraft_settings_test="user" type="text" autocomplete="off" class="updraft_input--wide" <?php $this->output_settings_field_name_and_id('user');?> value="{{user}}" />
160 </td>
161 </tr>
162
163 <tr class="<?php echo $classes; ?>">
164 <th><?php _e('Password', 'updraftplus');?>:</th>
165 <td><input data-updraft_settings_test="password" type="<?php echo apply_filters('updraftplus_admin_secret_field_type', 'password'); ?>" autocomplete="off" class="updraft_input--wide" <?php $this->output_settings_field_name_and_id('password');?> value="{{password}}" />
166 </td>
167 </tr>
168
169 <tr class="<?php echo $classes; ?>">
170 <th><?php echo __('Container', 'updraftplus');?>:</th>
171 <td><input data-updraft_settings_test="path" type="text" class="updraft_input--wide" <?php $this->output_settings_field_name_and_id('path');?> value="{{path}}" /></td>
172 </tr>
173 <?php
174 return ob_get_clean();
175 }
176
177 public function credentials_test($posted_settings) {
178
179 if (empty($posted_settings['user'])) {
180 printf(__("Failure: No %s was given.", 'updraftplus'), __('username', 'updraftplus'));
181 return;
182 }
183
184 if (empty($posted_settings['password'])) {
185 printf(__("Failure: No %s was given.", 'updraftplus'), __('password', 'updraftplus'));
186 return;
187 }
188
189 if (empty($posted_settings['tenant'])) {
190 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'));
191 return;
192 }
193
194 if (empty($posted_settings['authurl'])) {
195 printf(__("Failure: No %s was given.", 'updraftplus'), __('authentication URI', 'updraftplus'));
196 return;
197 }
198
199 $opts = array(
200 'user' => $posted_settings['user'],
201 'password' => $posted_settings['password'],
202 'authurl' => $posted_settings['authurl'],
203 'tenant' => $posted_settings['tenant'],
204 'region' => empty($posted_settings['region']) ? '' : $posted_settings['region'],
205 );
206
207 $this->credentials_test_go($opts, $posted_settings['path'], $posted_settings['useservercerts'], $posted_settings['disableverify']);
208 }
209
210 /**
211 * Check whether options have been set up by the user, or not
212 *
213 * @param Array $opts - the potential options
214 *
215 * @return Boolean
216 */
217 public function options_exist($opts) {
218 if (is_array($opts) && $opts['user'] && '' !== $opts['user'] && !empty($opts['authurl'])) return true;
219 return false;
220 }
221 }
222