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

203 lines 7.8 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_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'));
34
35 include_once(UPDRAFTPLUS_DIR.'/vendor/autoload.php');
36 global $updraftplus;
37 $updraftplus->log("OpenStack authentication URL: ".$authurl);
38
39 $client = new OpenStack($authurl, array(
40 'username' => $user,
41 'password' => $password,
42 'tenantName' => $tenant
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)) {
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');
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 * This outputs the html to the settings page for the Openstack settings.
114 *
115 * @param Array $opts - this is an array of Openstack settings
116 */
117 public function config_print_middlesection() {
118 $opts = $this->get_options();
119
120 $classes = $this->get_css_classes();
121 ?>
122 <tr class="<?php echo $classes; ?>">
123 <th></th>
124 <td>
125 <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/");?>"><?php _e('Also, you should read this important FAQ.', 'updraftplus'); ?></a></p>
126 </td>
127 </tr>
128
129 <tr class="<?php echo $classes; ?>">
130 <th><?php echo ucfirst(__('authentication URI', 'updraftplus'));?>:</th>
131 <td><input data-updraft_settings_test="authurl" type="text" autocomplete="off" style="width: 364px" <?php $this->output_settings_field_name_and_id('authurl');?> value="<?php echo htmlspecialchars($opts['authurl']); ?>" />
132 <br>
133 <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>
134 </td>
135 </tr>
136
137 <tr class="<?php echo $classes; ?>">
138 <th><a href="http://docs.openstack.org/openstack-ops/content/projects_users.html" title="<?php _e('Follow this link for more information', 'updraftplus');?>"><?php _e('Tenant', 'updraftplus');?></a>:</th>
139 <td><input data-updraft_settings_test="tenant" type="text" autocomplete="off" style="width: 364px" <?php $this->output_settings_field_name_and_id('tenant');?> value="<?php echo htmlspecialchars($opts['tenant']); ?>" />
140 </td>
141 </tr>
142
143 <tr class="<?php echo $classes; ?>">
144 <th><?php _e('Region', 'updraftplus');?>:</th>
145 <td><input data-updraft_settings_test="region" type="text" autocomplete="off" style="width: 364px" <?php $this->output_settings_field_name_and_id('region');?> value="<?php echo htmlspecialchars($opts['region']); ?>" />
146 <br>
147 <em><?php _e('Leave this blank, and a default will be chosen.', 'updraftplus');?></em>
148 </td>
149 </tr>
150
151 <tr class="<?php echo $classes; ?>">
152 <th><?php _e('Username', 'updraftplus');?>:</th>
153 <td><input data-updraft_settings_test="user" type="text" autocomplete="off" style="width: 364px" <?php $this->output_settings_field_name_and_id('user');?> value="<?php echo htmlspecialchars($opts['user']); ?>" />
154 </td>
155 </tr>
156
157 <tr class="<?php echo $classes; ?>">
158 <th><?php _e('Password', 'updraftplus');?>:</th>
159 <td><input data-updraft_settings_test="password" type="<?php echo apply_filters('updraftplus_admin_secret_field_type', 'password'); ?>" autocomplete="off" style="width: 364px" <?php $this->output_settings_field_name_and_id('password');?> value="<?php echo htmlspecialchars($opts['password']); ?>" />
160 </td>
161 </tr>
162
163 <tr class="<?php echo $classes; ?>">
164 <th><?php echo __('Container', 'updraftplus');?>:</th>
165 <td><input data-updraft_settings_test="path" type="text" style="width: 364px" <?php $this->output_settings_field_name_and_id('path');?> value="<?php echo htmlspecialchars($opts['path']); ?>" /></td>
166 </tr>
167 <?php
168 }
169
170 public function credentials_test($posted_settings) {
171
172 if (empty($posted_settings['user'])) {
173 printf(__("Failure: No %s was given.", 'updraftplus'), __('username', 'updraftplus'));
174 return;
175 }
176
177 if (empty($posted_settings['password'])) {
178 printf(__("Failure: No %s was given.", 'updraftplus'), __('password', 'updraftplus'));
179 return;
180 }
181
182 if (empty($posted_settings['tenant'])) {
183 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'));
184 return;
185 }
186
187 if (empty($posted_settings['authurl'])) {
188 printf(__("Failure: No %s was given.", 'updraftplus'), __('authentication URI', 'updraftplus'));
189 return;
190 }
191
192 $opts = array(
193 'user' => stripslashes($posted_settings['user']),
194 'password' => stripslashes($posted_settings['password']),
195 'authurl' => stripslashes($posted_settings['authurl']),
196 'tenant' => stripslashes($posted_settings['tenant']),
197 'region' => (!empty($posted_settings['region'])) ? $posted_settings['region'] : '',
198 );
199
200 $this->credentials_test_go($opts, stripslashes($posted_settings['path']), $posted_settings['useservercerts'], $posted_settings['disableverify']);
201 }
202 }
203