PluginProbe
The WP Remote WordPress Plugin / 6.72
The WP Remote WordPress Plugin v6.72
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 / handler.php

handler.php in The WP Remote WordPress Plugin 6.72, at callback/handler.php

193 lines 5.3 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('WPRCallbackHandler')) :
5
6 class WPRCallbackHandler {
7 public $db;
8 public $settings;
9 public $siteinfo;
10 public $request;
11 public $account;
12 public $response;
13 public $bvinfo;
14
15 public function __construct($db, $settings, $siteinfo, $request, $account, $response) {
16 $this->db = $db;
17 $this->settings = $settings;
18 $this->siteinfo = $siteinfo;
19 $this->request = $request;
20 $this->account = $account;
21 $this->response = $response;
22 $this->bvinfo = new WPRInfo($this->settings);
23 }
24
25 public function bvAdmExecuteWithoutUser() {
26 $this->execute(array("bvadmwithoutuser" => true));
27 }
28
29 public function bvAdmExecuteWithUser() {
30 $this->execute(array("bvadmwithuser" => true));
31 }
32
33 public function execute($resp = array()) {
34 $params = $this->request->params;
35 if (array_key_exists('disable_global_cache', $params)) {
36 $GLOBALS['_wp_using_ext_object_cache'] = false;
37 }
38
39 $this->routeRequest();
40 $resp = array(
41 "request_info" => $this->request->info(),
42 "site_info" => $this->siteinfo->info(),
43 "account_info" => $this->account->info(),
44 "bvinfo" => $this->bvinfo->info(),
45 "api_pubkey" => substr(WPRAccount::getApiPublicKey($this->settings), 0, 8)
46 );
47 $this->response->terminate($resp);
48 }
49
50 public function deferExecutionUntilShutdown() {
51 if (function_exists('error_clear_last')) {
52 error_clear_last();
53 }
54 ob_start();
55 remove_action('shutdown', 'wp_ob_end_flush_all', 1);
56 add_action('shutdown', array($this, 'scheduleExecutionAfterShutdown'), PHP_INT_MAX);
57 }
58
59 public function scheduleExecutionAfterShutdown() {
60 register_shutdown_function(array($this, 'executeAfterShutdown'));
61 }
62
63 public function executeAfterShutdown() {
64 if ($this->request->keep_page_output) {
65 $this->removeContentLengthHeader();
66 $this->execute();
67 return;
68 }
69 if ($this->shouldPreserveFrontendResponse()) {
70 return;
71 }
72 $this->discardBufferedOutput();
73 $this->clearFrontendResponseHeaders();
74 $this->execute();
75 }
76
77 private function shouldPreserveFrontendResponse() {
78 if ($this->hasFatalError() || headers_sent()) {
79 return true;
80 }
81 if (!function_exists('http_response_code')) {
82 return false;
83 }
84 $response_code = http_response_code();
85 return $response_code !== false && $response_code !== 200;
86 }
87
88 private function hasFatalError() {
89 $error = error_get_last();
90 $fatal_types = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR);
91 return is_array($error) && in_array($error['type'], $fatal_types, true);
92 }
93
94 private function discardBufferedOutput() {
95 while (ob_get_level() > 0) {
96 if (!@ob_end_clean()) {
97 break;
98 }
99 }
100 }
101
102 private function clearFrontendResponseHeaders() {
103 $this->removeContentLengthHeader();
104 header_remove('Content-Encoding');
105 header_remove('Location');
106 }
107
108 private function removeContentLengthHeader() {
109 if (!headers_sent()) {
110 header_remove('Content-Length');
111 }
112 }
113
114 public function routeRequest() {
115 switch ($this->request->wing) {
116 case 'manage':
117 require_once dirname( __FILE__ ) . '/wings/manage.php';
118 $module = new WPRManageCallback($this);
119 break;
120 case 'fs':
121 require_once dirname( __FILE__ ) . '/wings/fs.php';
122 $module = new WPRFSCallback($this);
123 break;
124 case 'db':
125 require_once dirname( __FILE__ ) . '/wings/db.php';
126 $module = new WPRDBCallback($this);
127 break;
128 case 'info':
129 require_once dirname( __FILE__ ) . '/wings/info.php';
130 $module = new WPRInfoCallback($this);
131 break;
132 case 'dynsync':
133 require_once dirname( __FILE__ ) . '/wings/dynsync.php';
134 $module = new WPRDynSyncCallback($this);
135 break;
136 case 'ipstr':
137 require_once dirname( __FILE__ ) . '/wings/ipstore.php';
138 $module = new WPRIPStoreCallback($this);
139 break;
140 case 'wtch':
141 require_once dirname( __FILE__ ) . '/wings/watch.php';
142 $module = new WPRWatchCallback($this);
143 break;
144 case 'brand':
145 require_once dirname( __FILE__ ) . '/wings/brand.php';
146 $module = new WPRBrandCallback($this);
147 break;
148 case 'pt':
149 require_once dirname( __FILE__ ) . '/wings/protect.php';
150 $module = new WPRProtectCallback($this);
151 break;
152 case 'act':
153 require_once dirname( __FILE__ ) . '/wings/account.php';
154 $module = new WPRAccountCallback($this);
155 break;
156 case 'fswrt':
157 require_once dirname( __FILE__ ) . '/wings/fs_write.php';
158 $module = new WPRFSWriteCallback();
159 break;
160 case 'actlg':
161 require_once dirname( __FILE__ ) . '/wings/actlog.php';
162 $module = new WPRActLogCallback($this);
163 break;
164 case 'speed':
165 require_once dirname( __FILE__ ) . '/wings/speed.php';
166 $module = new WPRSpeedCallback($this);
167 break;
168 case 'scrty':
169 require_once dirname( __FILE__ ) . '/wings/security.php';
170 $module = new WPRSecurityCallback($this);
171 break;
172 default:
173 require_once dirname( __FILE__ ) . '/wings/misc.php';
174 $module = new WPRMiscCallback($this);
175 break;
176 }
177 $resp = $module->process($this->request);
178 if ($resp === false) {
179 $resp = array(
180 "statusmsg" => "Bad Command",
181 "status" => false);
182 }
183 $resp = array(
184 $this->request->wing => array(
185 $this->request->method => $resp
186 )
187 );
188 $this->response->addStatus("callbackresponse", $resp);
189 return 1;
190 }
191 }
192 endif;
193