PluginProbe
ManageWP Worker / 3.8.4
ManageWP Worker v3.8.4
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / init.php

init.php in ManageWP Worker 3.8.4, at init.php

289 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.4
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.4');
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 require_once(ABSPATH . 'wp-includes/class-IXR.php');
31 require_once("$mmb_plugin_dir/helper.class.php");
32 require_once("$mmb_plugin_dir/core.class.php");
33 require_once("$mmb_plugin_dir/plugin.class.php");
34 require_once("$mmb_plugin_dir/theme.class.php");
35 require_once("$mmb_plugin_dir/wp.class.php");
36 require_once("$mmb_plugin_dir/post.class.php");
37 require_once("$mmb_plugin_dir/stats.class.php");
38 require_once("$mmb_plugin_dir/backup.class.php");
39
40 $mmb_core = new MMB_Core();
41 add_action('init', 'mmb_parse_request');
42
43 if (function_exists('register_activation_hook'))
44 register_activation_hook(__FILE__, array(
45 $mmb_core,
46 'install'
47 ));
48
49 if (function_exists('register_deactivation_hook'))
50 register_deactivation_hook(__FILE__, array(
51 $mmb_core,
52 'uninstall'
53 ));
54
55 function mmb_parse_request()
56 {
57 if (!isset($HTTP_RAW_POST_DATA)) {
58 $HTTP_RAW_POST_DATA = file_get_contents('php://input');
59 }
60 ob_start();
61
62 global $mmb_core;
63 $data = base64_decode($HTTP_RAW_POST_DATA);
64 $num = extract(unserialize($data));
65
66 if ($action) {
67 if (!$mmb_core->check_if_user_exists($params['username']))
68 mmb_response('Username <b>' . $params['username'] . '</b> does not have administrator capabilities. Enter the correct username in the site options.', false);
69
70 if ($action == 'add_site') {
71 mmb_add_site($params);
72 mmb_response('You should never see this.', false);
73 }
74
75 $auth = $mmb_core->authenticate_message($action . $id, $signature, $id);
76 if ($auth === true) {
77 $mmb_actions = array(
78 'remove_site' => 'mmb_remove_site',
79 'get_stats' => 'mmb_stats_get',
80 'backup' => 'mmb_backup_now',
81 'restore' => 'mmb_restore_now',
82 'optimize_tables' => 'mmb_optimize_tables',
83 'check_wp_version' => 'mmb_wp_checkversion',
84 'create_post' => 'mmb_post_create',
85 'upgrade_plugins' => 'mmb_upgrade_plugins',
86 'wp_upgrade' => 'mmb_upgrade_wp',
87 'upgrade_themes' => 'mmb_themes_upgrade',
88 'upload_plugin_by_url' => 'mmb_plugin_upload_by_url',
89 'upload_theme_by_url' => 'mmb_theme_upload_by_url',
90 'update_worker' => 'mmb_update_worker_plugin'
91 );
92 if (array_key_exists($action, $mmb_actions) && function_exists($mmb_actions[$action]))
93 call_user_func($mmb_actions[$action], $params);
94 else
95 mmb_response('Action "' . $action . '" does not exist.', false);
96 } else {
97 mmb_response($auth['error'], false);
98 }
99 }
100
101
102 ob_end_clean();
103 }
104
105 /* Main response function */
106
107 function mmb_response($response = false, $success = true)
108 {
109 $return = array();
110
111 if (empty($response))
112 $return['error'] = 'Empty response';
113 else if ($success)
114 $return['success'] = $response;
115 else
116 $return['error'] = $response;
117
118 header('Content-Type: text/plain');
119 exit(PHP_EOL . base64_encode(serialize($return)));
120 }
121
122 function mmb_add_site($params)
123 {
124 global $mmb_core;
125
126 $num = extract($params);
127
128 if ($num) {
129 if (!get_option('_action_message_id') && !get_option('_worker_public_key')) {
130 $public_key = base64_decode($public_key);
131
132 if (function_exists('openssl_verify')) {
133 $verify = openssl_verify($action . $id, base64_decode($signature), $public_key);
134 if ($verify == 1) {
135 $mmb_core->set_master_public_key($public_key);
136 $mmb_core->set_worker_message_id( $id);
137
138 mmb_response($mmb_core->get_stats_instance()->get_initial_stats(), true);
139 } else if ($verify == 0) {
140 mmb_response('Invalid message signature. Please contact us if you see this message often.', false);
141 } else {
142 mmb_response('Command not successful. Please try again.', false);
143 }
144 } else {
145 if (!get_option('_worker_nossl_key')) {
146 srand();
147 $random_key = md5(base64_encode($public_key) . rand(0, getrandmax()));
148
149 $mmb_core->set_random_signature($random_key);
150 $mmb_core->set_worker_message_id( $id);
151 $mmb_core->set_master_public_key($public_key);
152 mmb_response($mmb_core->get_stats_instance()->get_initial_stats(), true);
153 } else
154 mmb_response('Please deactivate & activate ManageWP Worker plugin on your site, then re-add the site to your dashboard.', false);
155 }
156 } else {
157 mmb_response('Please deactivate & activate ManageWP Worker plugin on your site and re-add the site to your dashboard.', false);
158 }
159 } else {
160 mmb_response('Invalid parameters received. Please try again.', false);
161 }
162 }
163
164 function mmb_remove_site($params)
165 {
166 extract($params);
167 global $mmb_core;
168 $mmb_core->uninstall();
169
170 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
171 $plugin_slug = basename(dirname(__FILE__)) . '/' . basename(__FILE__);
172
173 if ($deactivate) {
174 deactivate_plugins($plugin_slug, true);
175 }
176
177 if (!is_plugin_active($plugin_slug))
178 mmb_response(array(
179 'deactivated' => 'Site removed successfully. <br /><br />ManageWP Worker plugin successfully deactivated.'
180 ), true);
181 else
182 mmb_response(array(
183 'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>'
184 ), true);
185
186 }
187
188
189 function mmb_stats_get($params)
190 {
191 global $mmb_core;
192 mmb_response($mmb_core->get_stats_instance()->get($params), true);
193 }
194
195
196 //Plugins
197
198 function mmb_upgrade_plugins($params)
199 {
200 global $mmb_core;
201 mmb_response($mmb_core->get_plugin_instance()->upgrade_all($params), true);
202 }
203
204 function mmb_plugin_upload_by_url($params)
205 {
206 global $mmb_core;
207 $return = $mmb_core->get_plugin_instance()->upload_by_url($params);
208
209
210 mmb_response($return['message'], $return['bool']);
211
212 }
213
214 //Themes
215 function mmb_theme_upload_by_url($params)
216 {
217 global $mmb_core;
218 $return = $mmb_core->get_theme_instance()->upload_theme_by_url($params);
219 mmb_response($return['message'], $return['bool']);
220 }
221
222 function mmb_themes_upgrade($params)
223 {
224 global $mmb_core;
225 mmb_response($mmb_core->get_theme_instance()->upgrade_all($params), true);
226 }
227
228
229 //wp
230
231 function mmb_upgrade_wp($params)
232 {
233 global $mmb_core;
234 mmb_response($mmb_core->get_wp_instance()->upgrade());
235 }
236
237 //post
238 function mmb_post_create($params)
239 {
240 global $mmb_core;
241 $return = $mmb_core->get_post_instance()->create($params);
242 if (is_int($return))
243 mmb_response($return, true);
244 else
245 mmb_response($return, false);
246 }
247
248 //backup
249 function mmb_backup_now($params)
250 {
251 global $mmb_core;
252
253 $return = $mmb_core->get_backup_instance()->backup($params);
254
255 if (is_array($return) && array_key_exists('error', $return))
256 mmb_response($return['error'], false);
257 else {
258 mmb_response($return, true);
259 }
260 }
261
262 function mmb_optimize_tables($params)
263 {
264 global $mmb_core;
265 $return = $mmb_core->get_backup_instance()->optimize_tables();
266 if ($return)
267 mmb_response($return, true);
268 else
269 mmb_response(false, false);
270 }
271
272 function mmb_restore_now($params)
273 {
274 global $mmb_core;
275 $return = $mmb_core->get_backup_instance()->restore($params);
276 if (is_array($return) && array_key_exists('error', $return))
277 mmb_response($return['error'], false);
278 else
279 mmb_response($return, true);
280
281 }
282
283 function mmb_update_worker_plugin($params)
284 {
285 global $mmb_core;
286 mmb_response($mmb_core->update_worker_plugin($params), true);
287 }
288 ?>
289