| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: ManageWP - Worker |
| 4 |
Plugin URI: http://managewp.com/ |
| 5 |
Description: Manage all your blogs from one dashboard |
| 6 |
Author: Prelovac Media |
| 7 |
Version: 3.8.5 |
| 8 |
Author URI: http://www.prelovac.com |
| 9 |
*/ |
| 10 |
|
| 11 |
/************************************************************* |
| 12 |
* |
| 13 |
* init.php |
| 14 |
* |
| 15 |
* Initialize the communication with master |
| 16 |
* |
| 17 |
* |
| 18 |
* Copyright (c) 2011 Prelovac Media |
| 19 |
* www.prelovac.com |
| 20 |
**************************************************************/ |
| 21 |
|
| 22 |
|
| 23 |
define('MMB_WORKER_VERSION', '3.8.5'); |
| 24 |
|
| 25 |
global $wpdb, $mmb_plugin_dir, $mmb_plugin_url; |
| 26 |
|
| 27 |
$mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__)); |
| 28 |
$mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)); |
| 29 |
|
| 30 |
$mmb_actions = array( |
| 31 |
'remove_site' => 'mmb_remove_site', |
| 32 |
'get_stats' => 'mmb_stats_get', |
| 33 |
'backup' => 'mmb_backup_now', |
| 34 |
'restore' => 'mmb_restore_now', |
| 35 |
'optimize_tables' => 'mmb_optimize_tables', |
| 36 |
'check_wp_version' => 'mmb_wp_checkversion', |
| 37 |
'create_post' => 'mmb_post_create', |
| 38 |
'upgrade_plugins' => 'mmb_upgrade_plugins', |
| 39 |
'wp_upgrade' => 'mmb_upgrade_wp', |
| 40 |
'upgrade_themes' => 'mmb_themes_upgrade', |
| 41 |
'upload_plugin_by_url' => 'mmb_plugin_upload_by_url', |
| 42 |
'upload_theme_by_url' => 'mmb_theme_upload_by_url', |
| 43 |
'update_worker' => 'mmb_update_worker_plugin', |
| 44 |
'install_addon' => 'mmb_install_addon' |
| 45 |
); |
| 46 |
|
| 47 |
require_once("$mmb_plugin_dir/helper.class.php"); |
| 48 |
require_once("$mmb_plugin_dir/core.class.php"); |
| 49 |
require_once("$mmb_plugin_dir/plugin.class.php"); |
| 50 |
require_once("$mmb_plugin_dir/theme.class.php"); |
| 51 |
require_once("$mmb_plugin_dir/wp.class.php"); |
| 52 |
require_once("$mmb_plugin_dir/post.class.php"); |
| 53 |
require_once("$mmb_plugin_dir/stats.class.php"); |
| 54 |
require_once("$mmb_plugin_dir/backup.class.php"); |
| 55 |
require_once("$mmb_plugin_dir/installer.class.php"); |
| 56 |
require_once("$mmb_plugin_dir/api.php"); |
| 57 |
|
| 58 |
|
| 59 |
require_once("$mmb_plugin_dir/plugins/search/search.php"); |
| 60 |
require_once("$mmb_plugin_dir/plugins/cleanup/cleanup.php"); |
| 61 |
|
| 62 |
//this is an exmaple plugin for extra_html element |
| 63 |
//require_once("$mmb_plugin_dir/plugins/extra_html_example/extra_html_example.php"); |
| 64 |
|
| 65 |
$mmb_core = new MMB_Core(); |
| 66 |
add_action('init', 'mmb_parse_request'); |
| 67 |
|
| 68 |
if (function_exists('register_activation_hook')) |
| 69 |
register_activation_hook(__FILE__, array( |
| 70 |
$mmb_core, |
| 71 |
'install' |
| 72 |
)); |
| 73 |
|
| 74 |
if (function_exists('register_deactivation_hook')) |
| 75 |
register_deactivation_hook(__FILE__, array( |
| 76 |
$mmb_core, |
| 77 |
'uninstall' |
| 78 |
)); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
function mmb_parse_request() |
| 83 |
{ |
| 84 |
if (!isset($HTTP_RAW_POST_DATA)) { |
| 85 |
$HTTP_RAW_POST_DATA = file_get_contents('php://input'); |
| 86 |
} |
| 87 |
ob_start(); |
| 88 |
|
| 89 |
global $mmb_core, $mmb_actions, $new_actions; |
| 90 |
|
| 91 |
$data = base64_decode($HTTP_RAW_POST_DATA); |
| 92 |
if ($data) |
| 93 |
$num = @extract(unserialize($data)); |
| 94 |
|
| 95 |
if ($action) { |
| 96 |
// mmb_response($mmb_actions, false); |
| 97 |
if (!$mmb_core->check_if_user_exists($params['username'])) |
| 98 |
mmb_response('Username <b>' . $params['username'] . '</b> does not have administrator capabilities. Enter the correct username in the site options.', false); |
| 99 |
|
| 100 |
if ($action == 'add_site') { |
| 101 |
mmb_add_site($params); |
| 102 |
mmb_response('You should never see this.', false); |
| 103 |
} |
| 104 |
|
| 105 |
$auth = $mmb_core->authenticate_message($action . $id, $signature, $id); |
| 106 |
if ($auth === true) { |
| 107 |
if (array_key_exists($action, $mmb_actions) && function_exists($mmb_actions[$action])) |
| 108 |
call_user_func($mmb_actions[$action], $params); |
| 109 |
else |
| 110 |
mmb_response('Action "' . $action . '" does not exist.', false); |
| 111 |
} else { |
| 112 |
mmb_response($auth['error'], false); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
ob_end_clean(); |
| 118 |
} |
| 119 |
|
| 120 |
/* Main response function */ |
| 121 |
|
| 122 |
function mmb_response($response = false, $success = true) |
| 123 |
{ |
| 124 |
$return = array(); |
| 125 |
|
| 126 |
if (empty($response)) |
| 127 |
$return['error'] = 'Empty response.'; |
| 128 |
else if ($success) |
| 129 |
$return['success'] = $response; |
| 130 |
else |
| 131 |
$return['error'] = $response; |
| 132 |
|
| 133 |
header('Content-Type: text/plain'); |
| 134 |
exit(PHP_EOL . base64_encode(serialize($return))); |
| 135 |
} |
| 136 |
|
| 137 |
function mmb_add_site($params) |
| 138 |
{ |
| 139 |
global $mmb_core; |
| 140 |
|
| 141 |
$num = extract($params); |
| 142 |
|
| 143 |
if ($num) { |
| 144 |
if (!get_option('_action_message_id') && !get_option('_worker_public_key')) { |
| 145 |
$public_key = base64_decode($public_key); |
| 146 |
|
| 147 |
if (function_exists('openssl_verify')) { |
| 148 |
$verify = openssl_verify($action . $id, base64_decode($signature), $public_key); |
| 149 |
if ($verify == 1) { |
| 150 |
$mmb_core->set_master_public_key($public_key); |
| 151 |
$mmb_core->set_worker_message_id( $id); |
| 152 |
|
| 153 |
mmb_response($mmb_core->get_stats_instance()->get_initial_stats(), true); |
| 154 |
} else if ($verify == 0) { |
| 155 |
mmb_response('Invalid message signature. Please contact us if you see this message often.', false); |
| 156 |
} else { |
| 157 |
mmb_response('Command not successful. Please try again.', false); |
| 158 |
} |
| 159 |
} else { |
| 160 |
if (!get_option('_worker_nossl_key')) { |
| 161 |
srand(); |
| 162 |
$random_key = md5(base64_encode($public_key) . rand(0, getrandmax())); |
| 163 |
|
| 164 |
$mmb_core->set_random_signature($random_key); |
| 165 |
$mmb_core->set_worker_message_id( $id); |
| 166 |
$mmb_core->set_master_public_key($public_key); |
| 167 |
mmb_response($mmb_core->get_stats_instance()->get_initial_stats(), true); |
| 168 |
} else |
| 169 |
mmb_response('Please deactivate & activate ManageWP Worker plugin on your site, then re-add the site to your dashboard.', false); |
| 170 |
} |
| 171 |
} else { |
| 172 |
mmb_response('Please deactivate & activate ManageWP Worker plugin on your site and re-add the site to your dashboard.', false); |
| 173 |
} |
| 174 |
} else { |
| 175 |
mmb_response('Invalid parameters received. Please try again.', false); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
function mmb_remove_site($params) |
| 180 |
{ |
| 181 |
extract($params); |
| 182 |
global $mmb_core; |
| 183 |
$mmb_core->uninstall(); |
| 184 |
|
| 185 |
include_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 186 |
$plugin_slug = basename(dirname(__FILE__)) . '/' . basename(__FILE__); |
| 187 |
|
| 188 |
if ($deactivate) { |
| 189 |
deactivate_plugins($plugin_slug, true); |
| 190 |
} |
| 191 |
|
| 192 |
if (!is_plugin_active($plugin_slug)) |
| 193 |
mmb_response(array( |
| 194 |
'deactivated' => 'Site removed successfully. <br /><br />ManageWP Worker plugin successfully deactivated.' |
| 195 |
), true); |
| 196 |
else |
| 197 |
mmb_response(array( |
| 198 |
'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>' |
| 199 |
), true); |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
function mmb_stats_get($params) |
| 205 |
{ |
| 206 |
global $mmb_core; |
| 207 |
mmb_response($mmb_core->get_stats_instance()->get($params), true); |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
//Plugins |
| 212 |
|
| 213 |
function mmb_upgrade_plugins($params) |
| 214 |
{ |
| 215 |
global $mmb_core; |
| 216 |
mmb_response($mmb_core->get_plugin_instance()->upgrade_all($params), true); |
| 217 |
} |
| 218 |
|
| 219 |
function mmb_plugin_upload_by_url($params) |
| 220 |
{ |
| 221 |
global $mmb_core; |
| 222 |
$return = $mmb_core->get_plugin_instance()->upload_by_url($params); |
| 223 |
|
| 224 |
|
| 225 |
mmb_response($return['message'], $return['bool']); |
| 226 |
|
| 227 |
} |
| 228 |
|
| 229 |
//Themes |
| 230 |
function mmb_theme_upload_by_url($params) |
| 231 |
{ |
| 232 |
global $mmb_core; |
| 233 |
$return = $mmb_core->get_theme_instance()->upload_theme_by_url($params); |
| 234 |
mmb_response($return['message'], $return['bool']); |
| 235 |
} |
| 236 |
|
| 237 |
function mmb_themes_upgrade($params) |
| 238 |
{ |
| 239 |
global $mmb_core; |
| 240 |
mmb_response($mmb_core->get_theme_instance()->upgrade_all($params), true); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
//wp |
| 245 |
|
| 246 |
function mmb_upgrade_wp($params) |
| 247 |
{ |
| 248 |
global $mmb_core; |
| 249 |
mmb_response($mmb_core->get_wp_instance()->upgrade()); |
| 250 |
} |
| 251 |
|
| 252 |
//post |
| 253 |
function mmb_post_create($params) |
| 254 |
{ |
| 255 |
global $mmb_core; |
| 256 |
$return = $mmb_core->get_post_instance()->create($params); |
| 257 |
if (is_int($return)) |
| 258 |
mmb_response($return, true); |
| 259 |
else |
| 260 |
mmb_response($return, false); |
| 261 |
} |
| 262 |
|
| 263 |
//backup |
| 264 |
function mmb_backup_now($params) |
| 265 |
{ |
| 266 |
global $mmb_core; |
| 267 |
|
| 268 |
$return = $mmb_core->get_backup_instance()->backup($params); |
| 269 |
|
| 270 |
if (is_array($return) && array_key_exists('error', $return)) |
| 271 |
mmb_response($return['error'], false); |
| 272 |
else { |
| 273 |
mmb_response($return, true); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
function mmb_optimize_tables($params) |
| 278 |
{ |
| 279 |
global $mmb_core; |
| 280 |
$return = $mmb_core->get_backup_instance()->optimize_tables(); |
| 281 |
if ($return) |
| 282 |
mmb_response($return, true); |
| 283 |
else |
| 284 |
mmb_response(false, false); |
| 285 |
} |
| 286 |
|
| 287 |
function mmb_restore_now($params) |
| 288 |
{ |
| 289 |
global $mmb_core; |
| 290 |
$return = $mmb_core->get_backup_instance()->restore($params); |
| 291 |
if (is_array($return) && array_key_exists('error', $return)) |
| 292 |
mmb_response($return['error'], false); |
| 293 |
else |
| 294 |
mmb_response($return, true); |
| 295 |
|
| 296 |
} |
| 297 |
|
| 298 |
function mmb_update_worker_plugin($params) |
| 299 |
{ |
| 300 |
global $mmb_core; |
| 301 |
mmb_response($mmb_core->update_worker_plugin($params), true); |
| 302 |
} |
| 303 |
|
| 304 |
function mmb_wp_checkversion($params) |
| 305 |
{ |
| 306 |
include_once(ABSPATH . 'wp-includes/version.php'); |
| 307 |
global $wp_version,$mmb_core; |
| 308 |
mmb_response($wp_version,true); |
| 309 |
} |
| 310 |
|
| 311 |
function mmb_search_posts_by_term($params) |
| 312 |
{ |
| 313 |
|
| 314 |
global $mmb_core; |
| 315 |
$return = $mmb_core->get_search_instance()->search_posts_by_term($params); |
| 316 |
|
| 317 |
if($return){ |
| 318 |
mmb_response(serialize($return),true); |
| 319 |
}else{ |
| 320 |
mmb_response('No posts for term',false); |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
function mmb_install_addon($params) |
| 325 |
{ |
| 326 |
global $mmb_core; |
| 327 |
$return = $mmb_core->get_installer_instance()->install_remote_file($params); |
| 328 |
mmb_response($return,true); |
| 329 |
|
| 330 |
} |
| 331 |
?> |
| 332 |
|