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

178 lines 7.0 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 use OpenCloud\OpenStack;
7
8 require_once(UPDRAFTPLUS_DIR.'/methods/openstack-base.php');
9
10 class UpdraftPlus_BackupModule_openstack extends UpdraftPlus_BackupModule_openstack_base {
11
12 public function __construct() {
13 # 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)
14 parent::__construct('openstack', 'OpenStack', 'OpenStack (Swift)', '');
15 }
16
17 # $opts: 'tenant', 'user', 'password', 'authurl', (optional) 'region'
18 public function get_service($opts, $useservercerts = false, $disablesslverify = null) {
19
20 # 'tenant', 'user', 'password', 'authurl', 'path', (optional) 'region'
21 extract($opts);
22
23 if (null === $disablesslverify) $disablesslverify = UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify');
24
25 if (empty($user) || empty($password) || empty($authurl)) throw new Exception(__('Authorisation failed (check your credentials)', 'updraftplus'));
26
27 require_once(UPDRAFTPLUS_DIR.'/oc/autoload.php');
28 global $updraftplus;
29 $updraftplus->log("OpenStack authentication URL: ".$authurl);
30
31 $client = new OpenStack($authurl, array(
32 'username' => $user,
33 'password' => $password,
34 'tenantName' => $tenant
35 ));
36 $this->client = $client;
37
38 if ($disablesslverify) {
39 $client->setSslVerification(false);
40 } else {
41 if ($useservercerts) {
42 $client->setConfig(array($client::SSL_CERT_AUTHORITY, 'system'));
43 } else {
44 $client->setSslVerification(UPDRAFTPLUS_DIR.'/includes/cacert.pem', true, 2);
45 }
46 }
47
48 $client->authenticate();
49
50 if (empty($region)) {
51 $catalog = $client->getCatalog();
52 if (!empty($catalog)) {
53 $items = $catalog->getItems();
54 if (is_array($items)) {
55 foreach ($items as $item) {
56 $name = $item->getName();
57 $type = $item->getType();
58 if ('swift' != $name || 'object-store' != $type) continue;
59 $eps = $item->getEndpoints();
60 if (!is_array($eps)) continue;
61 foreach ($eps as $ep) {
62 if (is_object($ep) && !empty($ep->region)) {
63 $region = $ep->region;
64 }
65 }
66 }
67 }
68 }
69 }
70
71 $this->region = $region;
72
73 return $client->objectStoreService('swift', $region);
74
75 }
76
77 public function get_credentials() {
78 return array('updraft_openstack');
79 }
80
81 public function get_opts() {
82 global $updraftplus;
83 $opts = $updraftplus->get_job_option('updraft_openstack');
84 if (!is_array($opts)) $opts = array('user' => '', 'authurl' => '', 'password' => '', 'tenant' => '', 'path' => '', 'region' => '');
85 return $opts;
86 }
87
88 public function config_print_middlesection() {
89 $opts = $this->get_opts();
90 ?>
91 <tr class="updraftplusmethod <?php echo $this->method;?>">
92 <th></th>
93 <td>
94 <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="http://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>
95 </td>
96 </tr>
97
98 <tr class="updraftplusmethod <?php echo $this->method;?>">
99 <th><?php echo ucfirst(__('authentication URI', 'updraftplus'));?>:</th>
100 <td><input type="text" autocomplete="off" style="width: 364px" id="updraft_openstack_authurl" name="updraft_openstack[authurl]" value="<?php echo htmlspecialchars($opts['authurl']) ?>" />
101 <br>
102 <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>
103 </td>
104 </tr>
105
106 <tr class="updraftplusmethod <?php echo $this->method;?>">
107 <th><a href="http://docs.openstack.org/grizzly/openstack-compute/admin/content/users-and-projects.html" title="<?php _e('Follow this link for more information', 'updraftplus');?>"><?php _e('Tenant', 'updraftplus');?></a>:</th>
108 <td><input type="text" autocomplete="off" style="width: 364px" id="updraft_openstack_tenant" name="updraft_openstack[tenant]" value="<?php echo htmlspecialchars($opts['tenant']) ?>" />
109 </td>
110 </tr>
111
112 <tr class="updraftplusmethod <?php echo $this->method;?>">
113 <th><?php _e('Region', 'updraftplus');?>:</th>
114 <td><input type="text" autocomplete="off" style="width: 364px" id="updraft_openstack_region" name="updraft_openstack[region]" value="<?php echo htmlspecialchars($opts['region']) ?>" />
115 <br>
116 <em><?php _e('Leave this blank, and a default will be chosen.', 'updraftplus');?></em>
117 </td>
118 </tr>
119
120 <tr class="updraftplusmethod <?php echo $this->method;?>">
121 <th><?php _e('Username', 'updraftplus');?>:</th>
122 <td><input type="text" autocomplete="off" style="width: 364px" id="updraft_openstack_user" name="updraft_openstack[user]" value="<?php echo htmlspecialchars($opts['user']) ?>" />
123 </td>
124 </tr>
125
126 <tr class="updraftplusmethod <?php echo $this->method;?>">
127 <th><?php _e('Password', 'updraftplus');?>:</th>
128 <td><input type="<?php echo apply_filters('updraftplus_admin_secret_field_type', 'text'); ?>" autocomplete="off" style="width: 364px" id="updraft_openstack_password" name="updraft_openstack[password]" value="<?php echo htmlspecialchars($opts['password']); ?>" />
129 </td>
130 </tr>
131
132 <tr class="updraftplusmethod <?php echo $this->method;?>">
133 <th><?php echo __('Container', 'updraftplus');?>:</th>
134 <td><input type="text" style="width: 364px" name="updraft_openstack[path]" id="updraft_openstack_path" value="<?php echo htmlspecialchars($opts['path']); ?>" /></td>
135 </tr>
136 <?php
137 }
138
139 // The default value is needed only to satisfy PHP strict standards
140 public function config_print_javascript_onready($keys = array()) {
141 parent::config_print_javascript_onready(array('tenant', 'user', 'password', 'authurl', 'region'));
142 }
143
144 public function credentials_test() {
145
146 if (empty($_POST['user'])) {
147 printf(__("Failure: No %s was given.",'updraftplus'), __('username','updraftplus'));
148 die;
149 }
150
151 if (empty($_POST['password'])) {
152 printf(__("Failure: No %s was given.",'updraftplus'), __('password','updraftplus'));
153 die;
154 }
155
156 if (empty($_POST['tenant'])) {
157 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'));
158 die;
159 }
160
161 if (empty($_POST['authurl'])) {
162 printf(__("Failure: No %s was given.",'updraftplus'), __('authentication URI', 'updraftplus'));
163 die;
164 }
165
166 $opts = array(
167 'user' => stripslashes($_POST['user']),
168 'password' => stripslashes($_POST['password']),
169 'authurl' => stripslashes($_POST['authurl']),
170 'tenant' => stripslashes($_POST['tenant']),
171 'region' => (!empty($_POST['region'])) ? $_POST['region'] : '',
172 );
173
174 $this->credentials_test_go($opts, stripslashes($_POST['path']), $_POST['useservercerts'], $_POST['disableverify']);
175 }
176
177 }
178