PluginProbe
The WP Remote WordPress Plugin / 4.86
The WP Remote WordPress Plugin v4.86
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.86, at callback/wings/manage.php

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