PluginProbe
ManageWP Worker / 3.8.1
ManageWP Worker v3.8.1
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.1, at init.php

263 lines 7.7 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.1
8 Author URI: http://www.prelovac.com
9 */
10
11 // PHP warnings can break our XML stuffs
12 if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
13 error_reporting(E_ERROR);
14 }
15
16 define('MMB_WORKER_VERSION', '3.8.1');
17
18 global $wpdb, $mmb_plugin_dir, $mmb_plugin_url;
19
20 $mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
21 $mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__));
22
23 require_once(ABSPATH . 'wp-includes/class-IXR.php');
24 require_once("$mmb_plugin_dir/helper.class.php");
25 require_once("$mmb_plugin_dir/core.class.php");
26 require_once("$mmb_plugin_dir/plugin.class.php");
27 require_once("$mmb_plugin_dir/theme.class.php");
28 require_once("$mmb_plugin_dir/wp.class.php");
29 require_once("$mmb_plugin_dir/post.class.php");
30 require_once("$mmb_plugin_dir/stats.class.php");
31 require_once("$mmb_plugin_dir/user.class.php");
32 require_once("$mmb_plugin_dir/backup.class.php");
33
34 $mmb_core = new MMB_Core();
35 add_action('init', '_mmb_parse_request');
36
37 if (function_exists('register_activation_hook'))
38 register_activation_hook(__FILE__, array($mmb_core, 'install'));
39
40 if (function_exists('register_deactivation_hook'))
41 register_deactivation_hook(__FILE__, array($mmb_core, 'uninstall'));
42
43 function _mmb_parse_request()
44 {
45 if (!isset($HTTP_RAW_POST_DATA)) {
46 $HTTP_RAW_POST_DATA = file_get_contents('php://input');
47 }
48 ob_start();
49
50 global $mmb_core;
51 $data = base64_decode($HTTP_RAW_POST_DATA);
52 $num = extract(unserialize($data));
53
54 if ($action) {
55 if (!$mmb_core->_check_if_user_exists($params['username']))
56 mmb_response('Username <b>'.$params['username'].'</b> does not have administrator capabilities. Enter the correct username in the site options.', false);
57
58 if ($action == 'add_site') {
59 mmb_add_site($params);
60 mmb_response('You should never see this.', false);
61 }
62
63 $auth = $mmb_core->_authenticate_message($action . $id, $signature, $id);
64 if ($auth === true) {
65 $mmb_actions = array(
66 'remove_site' => 'mmb_remove_site',
67 'get_stats' => 'mmb_stats_get',
68 'backup' => 'mmb_backup_now',
69 'restore' => 'mmb_restore_now',
70 'optimize_tables' => 'mmb_optimize_tables',
71 'check_wp_version' => 'mmb_wp_checkversion',
72 'create_post' => 'mmb_post_create',
73 'upgrade_plugins' => 'mmb_upgrade_plugins',
74 'wp_upgrade' => 'mmb_upgrade_wp',
75 'upgrade_themes' => 'mmb_themes_upgrade',
76 'upload_plugin_by_url' => 'mmb_plugin_upload_by_url',
77 'upload_theme_by_url' => 'mmb_theme_upload_by_url',
78 'update_worker' => 'mmb_update_worker_plugin'
79 );
80 if (array_key_exists($action, $mmb_actions) && function_exists($mmb_actions[$action]))
81 call_user_func($mmb_actions[$action], $params);
82 else
83 mmb_response('Action "' . $action . '" does not exist.', false);
84 } else if(array_key_exists('openssl_activated', $auth)){
85 mmb_response($auth, true);
86 } else {
87 mmb_response($auth['error'], false);
88 }
89 }
90
91
92 ob_end_clean();
93 }
94
95 /* Main response function */
96
97 function mmb_response($response = false, $success = true)
98 {
99 $return = array();
100
101 if (empty($response))
102 $return['error'] = 'Empty response';
103 else if ($success)
104 $return['success'] = $response;
105 else
106 $return['error'] = $response;
107
108 header('Content-Type: text/plain');
109 exit(PHP_EOL.base64_encode(serialize($return)));
110 }
111
112 function mmb_add_site($params)
113 {
114 global $mmb_core;
115
116 $num = extract($params);
117
118 if ($num) {
119 if ( !get_option('_action_message_id') && !get_option('_worker_public_key')) {
120 $public_key = base64_decode($public_key) ;
121
122 if ( function_exists('openssl_verify') ) {
123 $verify = openssl_verify($action . $id, base64_decode($signature), $public_key);
124 if ($verify == 1) {
125 $mmb_core->_set_master_public_key($public_key);
126 $mmb_core->_set_worker_message_id($id);
127
128 mmb_response($mmb_core->get_stats_instance()->get_initial_stats(), true);
129 } else if ($verify == 0) {
130 mmb_response('Invalid message signature (site is probably managed by another account?)', false);
131 } else {
132 mmb_response('Command not successful. Please try again.', false);
133 }
134 } else{
135 if ( !get_option('_worker_nossl_key')) {
136 $random_key = md5(base64_encode($public_key) . rand(0, getrandmax()));
137
138 $mmb_core->_set_random_signature($random_key);
139 $mmb_core->_set_worker_message_id($id);
140 $mmb_core->_set_master_public_key($public_key);
141
142 mmb_response($mmb_core->get_stats_instance()->get_initial_stats(), true);
143 }
144 else mmb_response('Site seems to be already managed by another ManageWP account. Either remove the site from that account, or deactivate & activate the ManageWP Worker plugin to reset.', false);
145 }
146 } else {
147 mmb_response('Site seems to be already managed by another ManageWP account. Either remove the site from that account, or deactivate & activate the ManageWP Worker plugin to reset.', false);
148 }
149 } else {
150 mmb_response('Invalid parameters received. Please try again.', false);
151 }
152 }
153
154 function mmb_remove_site()
155 {
156 global $mmb_core;
157 $mmb_core->uninstall();
158 mmb_response('ManageWP Worker data successfully removed.', true);
159 }
160
161
162 function mmb_stats_get($params)
163 {
164 global $mmb_core;
165 mmb_response($mmb_core->get_stats_instance()->get($params), true);
166 }
167
168
169 //Plugins
170
171 function mmb_upgrade_plugins($params)
172 {
173 global $mmb_core;
174 mmb_response($mmb_core->get_plugin_instance()->upgrade_all($params), true);
175 }
176
177 function mmb_plugin_upload_by_url($params)
178 {
179 global $mmb_core;
180 $return = $mmb_core->get_plugin_instance()->upload_by_url($params);
181
182
183 mmb_response($return['message'],$return['bool'] );
184
185 }
186
187 //Themes
188 function mmb_theme_upload_by_url($params)
189 {
190 global $mmb_core;
191 $return = $mmb_core->get_theme_instance()->upload_theme_by_url($params);
192 mmb_response($return['message'],$return['bool'] );
193 }
194
195 function mmb_themes_upgrade($params)
196 {
197 global $mmb_core;
198 mmb_response($mmb_core->get_theme_instance()->upgrade_all($params), true);
199 }
200
201
202 //wp
203
204 function mmb_upgrade_wp($params)
205 {
206 global $mmb_core;
207 mmb_response($mmb_core->get_wp_instance()->upgrade());
208 }
209
210 //post
211 function mmb_post_create($params)
212 {
213 global $mmb_core;
214 $return = $mmb_core->get_post_instance()->create($params);
215 if (is_int($return))
216 mmb_response($return, true);
217 else
218 mmb_response($return, false);
219 }
220
221 //backup
222 function mmb_backup_now($params)
223 {
224 global $mmb_core;
225 $return = $mmb_core->get_backup_instance()->backup($params);
226
227 if (is_array($return) && array_key_exists('error', $return))
228 mmb_response($return['error'], false);
229 else {
230 $mmb_core->_log($return);
231 mmb_response($return, true);
232 }
233
234 }
235
236 function mmb_optimize_tables($params)
237 {
238 global $mmb_core;
239 $return = $mmb_core->get_backup_instance()->optimize_tables();
240 if ($return)
241 mmb_response($return, true);
242 else
243 mmb_response(false, false);
244 }
245
246 function mmb_restore_now($params)
247 {
248 global $mmb_core;
249 $return = $mmb_core->get_backup_instance()->restore($params);
250 if (is_array($return) && array_key_exists('error', $return))
251 mmb_response($return['error'], false);
252 else
253 mmb_response($return, true);
254
255 }
256
257 function mmb_update_worker_plugin($params)
258 {
259 global $mmb_core;
260 mmb_response($mmb_core->update_worker_plugin($params), true);
261 }
262 ?>
263