PluginProbe
The WP Remote WordPress Plugin / 4.79
The WP Remote WordPress Plugin v4.79
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / callback / wings / manage.php

manage.php in The WP Remote WordPress Plugin 4.79, at callback/wings/manage.php

547 lines 16.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('ABSPATH')) exit;
4 if (!class_exists('BVManageCallback')) :
5 class BVManageCallback extends BVCallbackBase {
6 public $settings;
7 public $skin;
8
9 const MANAGE_WING_VERSION = 1.0;
10
11 public function __construct($callback_handler) {
12 $this->settings = $callback_handler->settings;
13 }
14
15 function getError($err) {
16 return $this->objectToArray($err);
17 }
18
19 function is_pantheon() {
20 return (!empty($_ENV['PANTHEON_ENVIRONMENT']) && $_ENV['PANTHEON_ENVIRONMENT'] !== 'dev');
21 }
22
23 function isServerWritable() {
24 if ($this->is_pantheon()) {
25 return false;
26 }
27
28 if ((!defined('FTP_HOST') || !defined('FTP_USER')) && (get_filesystem_method(array(), false) != 'direct')) {
29 return false;
30 } else {
31 return true;
32 }
33 }
34
35 function include_files() {
36 @include_once ABSPATH.'wp-admin/includes/file.php';
37 @include_once ABSPATH.'wp-admin/includes/plugin.php';
38 @include_once ABSPATH.'wp-admin/includes/theme.php';
39 @include_once ABSPATH.'wp-admin/includes/misc.php';
40 @include_once ABSPATH.'wp-admin/includes/template.php';
41 @include_once ABSPATH.'wp-includes/pluggable.php';
42 @include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
43 @include_once ABSPATH.'wp-admin/includes/user.php';
44 @include_once ABSPATH.'wp-includes/registration.php';
45 @include_once ABSPATH.'wp-admin/includes/upgrade.php';
46 @include_once ABSPATH.'wp-admin/includes/update.php';
47 @require_once ABSPATH.'wp-admin/includes/update-core.php';
48 }
49
50 function edit($args) {
51 $result = array();
52 if ($args['type'] == 'plugins') {
53 $result['plugins'] = $this->editPlugins($args);
54 } elseif ($args['type'] == 'themes') {
55 $result['themes'] = $this->editThemes($args);
56 } elseif ($args['type'] == 'users') {
57 $result['users'] = $this->editWpusers($args);
58 }
59 return $result;
60 }
61
62 function editPlugins($args) {
63 $result = array();
64 $plugins = $args['items'];
65 foreach ($plugins as $plugin) {
66 if (array_key_exists('network', $plugin)) {
67 $networkwide = $plugin['network'];
68 } else {
69 $networkwide = false;
70 }
71 switch ($args['action']) {
72 case 'activate':
73 $res = activate_plugin($plugin['file'], '', $networkwide);
74 break;
75 case 'deactivate':
76 $res = deactivate_plugins(array($plugin['file']), false, $networkwide);
77 break;
78 case 'delete':
79 $res = delete_plugins(array($plugin['file']));
80 break;
81 case 'deactivate_delete':
82 $res = deactivate_plugins(array($plugin['file']), false, $networkwide);
83 if ($res || is_wp_error($res))
84 break;
85 $res = delete_plugins(array($plugin['file']));
86 default:
87 break;
88 }
89 if (is_wp_error($res)) {
90 $res = array('status' => "Error", 'message' => $res->get_error_message());
91 } elseif ($res === false) {
92 $res = array('status' => "Error", 'message' => "Failed to perform action.");
93 } else {
94 $res = array('status' => "Done");
95 }
96 $result[$plugin['file']] = $res;
97 }
98 return $result;
99 }
100
101 function editThemes($args) {
102 $result = array();
103 $themes = $args['items'];
104 foreach ($themes as $theme) {
105 switch ($args['action']) {
106 case 'activate':
107 $res = switch_theme($theme['template'], $theme['stylesheet']);
108 break;
109 case 'delete':
110 $res = delete_theme($theme['stylesheet']);
111 break;
112 default:
113 break;
114 }
115
116 if (is_wp_error($res)) {
117 $res = array('status' => "Error", 'message' => $res->get_error_message());
118 } elseif ($res === false) {
119 $res = array('status' => "Error", 'message' => "Failed to perform action.");
120 } else {
121 $res = array( 'status' => "Done");
122 }
123 $result[$theme['template']] = $res;
124 }
125 return $result;
126 }
127
128 function editWpusers($args) {
129 $result = array();
130 $items = $args['items'];
131 foreach ($items as $item) {
132 $res = array();
133 $user = get_user_by('id', $item['id']);
134 if ($user) {
135 switch ($args['action']) {
136 case 'changerole':
137 $data = array();
138 $data['role'] = $item['newrole'];
139 $data['ID'] = $user->ID;
140 $res = wp_update_user($data);
141 break;
142 case 'changepass':
143 $data = array();
144 $data['user_pass'] = $item['newpass'];
145 $data['ID'] = $user->ID;
146 $res = wp_update_user($data);
147 break;
148 case 'delete':
149 if (array_key_exists('reassign', $args)) {
150 $user_to = get_user_by('id', $args['reassign']);
151 if ($user_to != false) {
152 $res = wp_delete_user($user->ID, $user_to->ID);
153 } else {
154 $res = array('status' => "Error", 'message' => 'Reassigned user doesnot exists');
155 }
156 } else {
157 $res = wp_delete_user($user->ID);
158 }
159 break;
160 }
161 if (is_wp_error($res)) {
162 $res = array('status' => "Error", 'message' => $res->get_error_message());
163 } else {
164 $res = array( 'status' => "Done");
165 }
166 } else {
167 $res = array('status' => "Error", 'message' => "Unable to find user");
168 }
169 $result[$item['id']] = $res;
170 }
171 return $result;
172 }
173
174 function addUser($args) {
175 if (username_exists($args['user_login'])) {
176 return array('status' => "Error", 'message' => "Username already exists");
177 }
178 if (email_exists($args['user_email'])) {
179 return array('status' => "Error", 'message' => "Email already exists");
180 }
181 $result = wp_insert_user($args);
182 if ( !is_wp_error( $result ) ) {
183 return array('status' => "Done", 'user_id' => $result);
184 } else {
185 return array('status' => "Error", 'message' => $this->getError($result));
186 }
187 }
188
189 function upgrade($params = null, $has_bv_skin = false) {
190 $result = array();
191 $premium_upgrades = array();
192 if (array_key_exists('core', $params) && !empty($params['core'])) {
193 $result['core'] = $this->upgradeCore($params['core']);
194 }
195 if (array_key_exists('translations', $params) && !empty($params['translations'])) {
196 $result['translations'] = $this->upgradeTranslations($params['translations'], $has_bv_skin);
197 }
198 if (array_key_exists('plugins', $params) && !empty($params['plugins'])) {
199 $files = array();
200 foreach ($params['plugins'] as $plugin) {
201 $files[] = $plugin['file'];
202 }
203 if (!empty($files)) {
204 $result['plugins'] = $this->upgradePlugins($files, $has_bv_skin);
205 }
206 }
207 if (array_key_exists('themes', $params) && !empty($params['themes'])) {
208 $stylesheets = array();
209 foreach ($params['themes'] as $theme) {
210 $stylesheets[] = $theme['stylesheet'];
211 }
212 if (!empty($stylesheets)) {
213 $result['themes'] = $this->upgradeThemes($stylesheets, $has_bv_skin);
214 }
215 }
216 return $result;
217 }
218
219 function get_translation_updates() {
220 $updates = array();
221 $transients = array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' );
222 foreach ( $transients as $transient => $type ) {
223 $transient = $this->settings->getTransient( $transient );
224 if ( empty( $transient->translations ) )
225 continue;
226
227 foreach ( $transient->translations as $translation ) {
228 $updates[] = (object) $translation;
229 }
230 }
231 return $updates;
232 }
233
234 function upgradeTranslations($translations, $has_bv_skin = false) {
235 $language_updates = $this->get_translation_updates();
236 $valid_updates = array();
237 $result = array();
238 if (!empty($language_updates)) {
239 foreach($language_updates as $update) {
240 if ($update && in_array($update->package, $translations)) {
241 $valid_updates[] = $update;
242 }
243 }
244 }
245 if (!empty($valid_updates)) {
246 if (class_exists('Language_Pack_Upgrader')) {
247 if ($has_bv_skin) {
248 require_once( "bv_upgrader_skin.php" );
249 $skin = new BVUpgraderSkin("upgrade_translations");
250 $this->skin = $skin;
251 } else {
252 $skin = new Language_Pack_Upgrader_Skin(array());
253 }
254 $upgrader = new Language_Pack_Upgrader($skin);
255 $result = $upgrader->bulk_upgrade($valid_updates);
256 if (is_array($result) && !empty($result)) {
257 foreach ($result as $translate_tmp => $translate_info) {
258 if (is_wp_error($translate_info) || empty($translate_info)) {
259 $error = (!empty($translate_info)) ? is_wp_error($translate_info) : "Upgrade failed";
260 return array('status' => "Error", 'message' => $error);
261 }
262 }
263 }
264 return array('status' => "Done");
265 }
266 }
267 return array('status' => "Error", 'message' => "Upgrade failed");
268 }
269
270 function upgradeCore($args) {
271 global $wp_filesystem, $wp_version;
272 $core = $this->settings->getTransient('update_core');
273 $core_update_index = intval($args['coreupdateindex']);
274 if (isset($core->updates) && !empty($core->updates)) {
275 $to_update = $core->updates[$core_update_index];
276 } else {
277 return array('status' => "Error", "message" => "Updates not available");
278 }
279 $resp = array("Core_Upgrader", class_exists('Core_Upgrader'));
280 if (version_compare($wp_version, '3.1.9', '>')) {
281 $core = new Core_Upgrader();
282 $result = $core->upgrade($to_update);
283 if (is_wp_error($result)) {
284 return array('status' => "Error", "message" => $this->getError($result));
285 } else {
286 return array('status' => 'Done');
287 }
288 } else {
289 $resp = array("wp_update_core", function_exists('wp_update_core'));
290 if (function_exists('wp_update_core')) {
291 $result = wp_update_core($to_update);
292 if (is_wp_error($result)) {
293 return array('status' => "Error", "message" => $this->getError($result));
294 } else {
295 return array('status' => 'Done');
296 }
297 }
298
299 $resp = array("WP_Upgrader", class_exists('WP_Upgrader'));
300 if (class_exists('WP_Upgrader')) {
301 $upgrader = new WP_Upgrader();
302
303 $res = $upgrader->fs_connect(
304 array(
305 ABSPATH,
306 WP_CONTENT_DIR,
307 )
308 );
309 if (is_wp_error($res)) {
310 return array('status' => "Error", "message" => $this->getError($res));
311 }
312
313 $wp_dir = trailingslashit($wp_filesystem->abspath());
314
315 $core_package = false;
316 if (isset($to_update->package) && !empty($to_update->package)) {
317 $core_package = $to_update->package;
318 } elseif (isset($to_update->packages->full) && !empty($to_update->packages->full)) {
319 $core_package = $to_update->packages->full;
320 }
321
322 $download = $upgrader->download_package($core_package);
323 if (is_wp_error($download)) {
324 return array('status' => "Error", "message" => $this->getError($download));
325 }
326 $working_dir = $upgrader->unpack_package($download);
327 if (is_wp_error($working_dir)) {
328 return array('status' => "Error", "message" => $this->getError($working_dir));
329 }
330
331 if (!$wp_filesystem->copy($working_dir.'/wordpress/wp-admin/includes/update-core.php', $wp_dir.'wp-admin/includes/update-core.php', true)) {
332 $wp_filesystem->delete($working_dir, true);
333 return array('status' => "Error", "message" => "Unable to move files.");
334 }
335
336 $wp_filesystem->chmod($wp_dir.'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
337
338 $result = update_core($working_dir, $wp_dir);
339
340 if (is_wp_error($result)) {
341 return array('status' => "Error", "message" => $this->getError($result));
342 }
343 return array('status' => 'Done');
344 }
345 }
346 }
347
348 function upgradePlugins($plugins, $has_bv_skin = false) {
349 $result = array();
350 if (class_exists('Plugin_Upgrader')) {
351 if ($has_bv_skin) {
352 require_once( "bv_upgrader_skin.php" );
353 $skin = new BVUpgraderSkin("plugin_upgrade");
354 $this->skin = $skin;
355 } else {
356 $skin = new Bulk_Plugin_Upgrader_Skin();
357 }
358 $upgrader = new Plugin_Upgrader($skin);
359 $result = $upgrader->bulk_upgrade($plugins);
360 }
361 foreach($plugins as $file) {
362 $res = $result[$file];
363 if (!$res || is_wp_error($res)) {
364 $result[$file] = array('status' => "Error");
365 } else {
366 $result[$file] = array('status' => "Done");
367 }
368 }
369 return $result;
370 }
371
372 function upgradeThemes($themes, $has_bv_skin = false) {
373 $result = array();
374 if (class_exists('Theme_Upgrader')) {
375 if ($has_bv_skin) {
376 require_once( "bv_upgrader_skin.php" );
377 $skin = new BVUpgraderSkin("theme_upgrade");
378 $this->skin = $skin;
379 } else {
380 $skin = new Bulk_Theme_Upgrader_Skin();
381 }
382 $upgrader = new Theme_Upgrader($skin);
383 $result = $upgrader->bulk_upgrade($themes);
384 }
385 foreach($themes as $stylesheet) {
386 $res = $result[$stylesheet];
387 if (!$res || is_wp_error($res)) {
388 $result[$stylesheet] = array('status' => "Error");
389 } else {
390 $result[$stylesheet] = array('status' => "Done");
391 }
392 }
393 return $result;
394 }
395
396 function install($params, $has_bv_skin = false) {
397 $result = array();
398 if (isset($params['plugins'])) {
399 foreach ($params['plugins'] as $plugin) {
400 if (!array_key_exists('plugins', $result))
401 $result["plugins"] = array();
402 $plugin['dest'] = WP_PLUGIN_DIR;
403 $res = $this->installPackage($plugin, $has_bv_skin);
404 $pluginName = $plugin['package'];
405 $result["plugins"][$pluginName] = $res;
406 }
407 }
408 if (isset($params['themes'])) {
409 foreach ($params['themes'] as $theme) {
410 if (!array_key_exists('themes', $result))
411 $result["themes"] = array();
412 $theme['dest'] = WP_CONTENT_DIR.'/themes';
413 $res = $this->installPackage($theme, $has_bv_skin);
414 $themeName = $theme['package'];
415 $result["themes"][$themeName] = $res;
416 }
417 }
418 return $result;
419 }
420
421 function installPackage($params, $has_bv_skin = false) {
422 global $wp_filesystem;
423
424 if (!isset($params['package']) || empty($params['package'])) {
425 return array('status' => "Error", 'message' => "No package is sent");
426 }
427 $valid_domain_regex = "/^(http|https):\/\/[\-\w]*\.(blogvault\.net|w\.org|wp\.org|wordpress\.org)\//";
428 if (preg_match($valid_domain_regex, $params['package']) !== 1) {
429 return array('status' => "Error", 'message' => "Invalid package domain");
430 }
431 if ($has_bv_skin) {
432 require_once( "bv_upgrader_skin.php" );
433 $skin = new BVUpgraderSkin("installer", $params['package']);
434 $this->skin = $skin;
435 } else {
436 $skin = new WP_Upgrader_Skin();
437 }
438 $upgrader = new WP_Upgrader($skin);
439 $upgrader->init();
440 $destination = $params['dest'];
441 $clear_destination = isset($params['cleardest']) ? $params['cleardest'] : false;
442 $package_url = $params['package'];
443 $key = basename($package_url);
444 $res = $upgrader->run(
445 array(
446 'package' => $package_url,
447 'destination' => $destination,
448 'clear_destination' => $clear_destination,
449 'clear_working' => true,
450 'hook_extra' => array(),
451 )
452 );
453 if (is_wp_error($res)) {
454 $res = array('status' => "Error", 'message' => $this->getError($res));
455 } else {
456 $res = array( 'status' => "Done");
457 }
458 return $res;
459 }
460
461 function getPremiumUpdates() {
462 return apply_filters( 'mwp_premium_update_notification', array() );
463 }
464
465 function getPremiumUpgradesInfo() {
466 return apply_filters( 'mwp_premium_perform_update', array() );
467 }
468
469 function autoLogin($username, $isHttps) {
470 $user = get_user_by('login', $username);
471 if ($user != FALSE) {
472 wp_set_current_user( $user->ID );
473 if ($isHttps) {
474 wp_set_auth_cookie( $user->ID, false, true );
475 } else {
476 # As we are not sure about wp-cofig.php settings for sure login
477 wp_set_auth_cookie( $user->ID, false, true );
478 wp_set_auth_cookie( $user->ID, false, false );
479 }
480 $redirect_to = get_admin_url();
481 wp_safe_redirect( $redirect_to );
482 exit;
483 }
484 }
485
486 function upgrade_db(){
487 if (function_exists('wp_upgrade')) {
488 wp_upgrade();
489 return "DONE";
490 } else {
491 return "NOUPGRADERFUNCTION";
492 }
493 }
494
495 function process($request) {
496 global $wp_filesystem;
497 $this->include_files();
498
499 if (!$this->is_pantheon() && !$wp_filesystem) {
500 WP_Filesystem();
501 }
502
503 $params = $request->params;
504 $resp = array();
505 switch ($request->method) {
506 case "adusr":
507 $resp = array("adduser" => $this->addUser($params['args']));
508 break;
509 case "upgrde":
510 $has_bv_skin = array_key_exists('bvskin', $params);
511 $resp = array("upgrades" => $this->upgrade($params['args'], $has_bv_skin));
512 break;
513 case "edt":
514 $resp = array("edit" => $this->edit($params['args']));
515 break;
516 case "instl":
517 $has_bv_skin = array_key_exists('bvskin', $params);
518 $resp = array("install" => $this->install($params['args'], $has_bv_skin));
519 break;
520 case "getpremiumupdates":
521 $resp = array("premiumupdates" => $this->getPremiumUpdates());
522 break;
523 case "getpremiumupgradesinfo":
524 $resp = array("premiumupgradesinfo" => $this->getPremiumUpgradesInfo());
525 break;
526 case "wrteble":
527 $resp = array("writeable" => $this->isServerWritable());
528 break;
529 case "atolgn":
530 $isHttps = false;
531 if (array_key_exists('https', $params))
532 $isHttps = true;
533 $resp = array("autologin" => $this->autoLogin($params['username'], $isHttps));
534 break;
535 case "updatedb":
536 $resp = array("status" => $this->upgrade_db());
537 break;
538 default:
539 $resp = false;
540 }
541 if ($this->skin && is_array($resp)) {
542 $resp = array_merge($resp, $this->skin->status);
543 }
544 return $resp;
545 }
546 }
547 endif;