PluginProbe
The WP Remote WordPress Plugin / 4.74
The WP Remote WordPress Plugin v4.74
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
← All changes | callback/wings/db.php +50 -212 6.654.74 View file →
@@ -1,19 +1,18 @@
1 1 <?php
2 2
3 3 if (!defined('ABSPATH')) exit;
4 -if (!class_exists('WPRDBCallback')) :
4 +if (!class_exists('BVDBCallback')) :
5 5 require_once dirname( __FILE__ ) . '/../streams.php';
6 6
7 -class WPRDBCallback extends WPRCallbackBase {
7 +class BVDBCallback extends BVCallbackBase {
8 8 public $db;
9 9 public $stream;
10 10 public $account;
11 - public $siteinfo;
12 11
13 12 public static $bvTables = array("fw_requests", "lp_requests", "ip_store");
14 13
15 - const DB_WING_VERSION = 1.5;
14 + const DB_WING_VERSION = 1.1;
16 15
17 16 public function __construct($callback_handler) {
18 17 $this->db = $callback_handler->db;
19 18 $this->account = $callback_handler->account;
@@ -27,11 +26,11 @@
27 26 }
28 27 return $last_ids;
29 28 }
30 29
31 - public function getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, $include_rows = false) {
30 + public function getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, $include_rows = false) {
32 31 $tinfo = array();
33 -
32 +
34 33 $rows_count = $this->db->rowsCount($table);
35 34 $result = array('count' => $rows_count);
36 35 if ($limit == 0) {
37 36 $limit = $rows_count;
@@ -68,139 +67,12 @@
68 67 $result['tinfo'] = $tinfo;
69 68 return $result;
70 69 }
71 70
72 - public function buildPrimaryKeyCursorFilter($pkeys, $last_ids) {
73 - if (empty($pkeys)) return null;
74 - foreach($pkeys as $pk) {
75 - if (!isset($last_ids[$pk]) || $last_ids[$pk] === '') return null;
76 - }
77 -
78 - $conditions = array();
79 - $order_by = array();
80 - foreach($pkeys as $index => $pk) {
81 - $key = "`".$pk."`";
82 - $order_by[] = $key;
83 - $parts = array();
84 - for ($eq_index = 0; $eq_index < $index; $eq_index++) {
85 - $eq_pk = $pkeys[$eq_index];
86 - $eq_key = "`".$eq_pk."`";
87 - $eq_last_id = esc_sql((string) $last_ids[$eq_pk]);
88 - $parts[] = $eq_key." = '".$eq_last_id."'";
89 - }
90 - $last_id = esc_sql((string) $last_ids[$pkeys[$index]]);
91 - $parts[] = $key." > '".$last_id."'";
92 - $condition = implode(" AND ", $parts);
93 - $conditions[] = ($index == 0) ? $condition : "(".$condition.")";
94 - }
95 - return " WHERE ".implode(" OR ", $conditions)." ORDER BY ".implode(",", $order_by);
96 - }
97 -
98 - public function getTableDataByCursor($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, $include_rows = false, $cursor_mode = false) {
99 - $tinfo = array();
100 -
101 - $rows_count = $this->db->rowsCount($table);
102 - $result = array('count' => $rows_count);
103 - if ($limit == 0) {
104 - $limit = $rows_count;
105 - }
106 - $srows = 1;
107 - $current_filter = $filter;
108 - $cursor_active = ($cursor_mode === true && !empty($pkeys));
109 - $query_offset = $offset;
110 - while (($limit > 0) && ($srows > 0)) {
111 - if ($bsize > $limit)
112 - $bsize = $limit;
113 - $rows = $this->db->getTableContent($table, '*', $current_filter, $bsize, $query_offset);
114 - $srows = sizeof($rows);
115 - $data = array();
116 - $data["table_name"] = $tname;
117 - $data["offset"] = $offset;
118 - $data["size"] = $srows;
119 - $serialized_rows = serialize($rows);
120 - $data['md5'] = md5($serialized_rows);
121 - $data['length'] = strlen($serialized_rows);
122 - array_push($tinfo, $data);
123 - if (!empty($pkeys) && $srows > 0) {
124 - $end_row = end($rows);
125 - $last_ids = $this->getLastID($pkeys, $end_row);
126 - $data['last_ids'] = $last_ids;
127 - $result['last_ids'] = $last_ids;
128 - if ($cursor_active) {
129 - $cursor_filter = $this->buildPrimaryKeyCursorFilter($pkeys, $last_ids);
130 - if ($cursor_filter !== null) {
131 - $current_filter = $cursor_filter;
132 - } else {
133 - $current_filter = $filter;
134 - $cursor_active = false;
135 - }
136 - }
137 - }
138 - if ($include_rows) {
139 - $data["rows"] = $rows;
140 - $str = serialize($data);
141 - $this->stream->writeStream($str);
142 - }
143 - $offset += $srows;
144 - $limit -= $srows;
145 - $query_offset = $cursor_active ? 0 : $offset;
146 - }
147 - $result['size'] = $offset;
148 - $result['tinfo'] = $tinfo;
149 - return $result;
150 - }
151 -
152 - public function streamQueryResult($identifier, $query, $pkeys) {
153 - $data = array();
154 - $data["identifier"] = $identifier;
155 - $data["query"] = $query;
156 -
157 - $data["query_start_time"] = time();
158 - $rows = $this->db->getResult($query);
159 - $srows = sizeof($rows);
160 - $data["size"] = $srows;
161 - $data["query_end_time"] = time();
162 - if (!empty($pkeys) && $srows > 0) {
163 - $end_row = end($rows);
164 - $last_ids = $this->getLastID($pkeys, $end_row);
165 - $data['last_ids'] = $last_ids;
166 - }
167 - $result = array_merge($data);
168 - $data["rows"] = $rows;
169 - $serialized_rows = serialize($data);
170 - $this->stream->writeStream($serialized_rows);
171 - $result['length'] = strlen($serialized_rows);
172 - return $result;
173 - }
174 -
175 - function getRandomData($totalSize, $bsize) {
176 - if ($bsize == 0) {
177 - $bsize = $totalSize;
178 - }
179 -
180 - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
181 - $charactersLength = strlen($characters);
182 -
183 - while ($totalSize > 0) {
184 - if ($bsize > $totalSize) {
185 - $bsize = $totalSize;
186 - }
187 -
188 - $randomString = '';
189 - for ($i = 0; $i < $bsize; $i++) {
190 - $randomString .= $characters[rand(0, $charactersLength - 1)]; // phpcs:ignore WordPress.WP.AlternativeFunctions.rand_rand
191 - }
192 -
193 - $this->stream->writeStream($randomString);
194 - $totalSize -= $bsize;
195 - }
196 - return array("status" => "true");
197 - }
198 -
199 71 public function getCreateTableQueries($tables) {
200 72 $resp = array();
201 73 foreach($tables as $table) {
202 - $tname = $table;
74 + $tname = urldecode($table);
203 75 $resp[$tname] = array("create" => $this->db->showTableCreate($table));
204 76 }
205 77 return $resp;
206 78 }
@@ -207,9 +79,9 @@
207 79
208 80 public function checkTables($tables, $type) {
209 81 $resp = array();
210 82 foreach($tables as $table) {
211 - $tname = $table;
83 + $tname = urldecode($table);
212 84 $resp[$tname] = array("status" => $this->db->checkTable($table, $type));
213 85 }
214 86 return $resp;
215 87 }
@@ -216,11 +88,10 @@
216 88
217 89 public function describeTables($tables) {
218 90 $resp = array();
219 91 foreach($tables as $table) {
220 - $tname = $table;
92 + $tname = urldecode($table);
221 93 $resp[$tname] = array("description" => $this->db->describeTable($table));
222 - $resp[$tname]["primary_keys_index"] = $this->db->showTableIndex($table);
223 94 }
224 95 return $resp;
225 96 }
226 97
@@ -226,9 +97,9 @@
226 97
227 98 public function checkTablesExist($tables) {
228 99 $resp = array();
229 100 foreach($tables as $table) {
230 - $tname = $table;
101 + $tname = urldecode($table);
231 102 $resp[$tname] = array("tblexists" => $this->db->isTablePresent($table));
232 103 }
233 104 return $resp;
234 105 }
@@ -235,9 +106,9 @@
235 106
236 107 public function getTablesRowCount($tables) {
237 108 $resp = array();
238 109 foreach($tables as $table) {
239 - $tname = $table;
110 + $tname = urldecode($table);
240 111 $resp[$tname] = array("count" => $this->db->rowsCount($table));
241 112 }
242 113 return $resp;
243 114 }
@@ -244,26 +115,18 @@
244 115
245 116 public function getTablesKeys($tables) {
246 117 $resp = array();
247 118 foreach($tables as $table) {
248 - $tname = $table;
119 + $tname = urldecode($table);
249 120 $resp[$tname] = array("keys" => $this->db->tableKeys($table));
250 121 }
251 122 return $resp;
252 123 }
253 124
254 - public function multiGetResult($queries) {
255 - $resp = array();
256 - foreach($queries as $query) {
257 - array_push($resp, $this->db->getResult($query));
258 - }
259 - return $resp;
260 - }
261 -
262 125 public function process($request) {
263 126 $db = $this->db;
264 127 $params = $request->params;
265 - $stream_init_info = WPRStream::startStream($this->account, $request);
128 + $stream_init_info = BVStream::startStream($this->account, $request);
266 129
267 130 if (array_key_exists('stream', $stream_init_info)) {
268 131 $this->stream = $stream_init_info['stream'];
269 132 switch ($request->method) {
@@ -273,27 +136,26 @@
273 136 case "tblstatus":
274 137 $resp = array("statuses" => $db->showTableStatus());
275 138 break;
276 139 case "tablekeys":
277 - $table = $params['table'];
140 + $table = urldecode($params['table']);
278 141 $resp = array("table_keys" => $db->tableKeys($table));
279 142 break;
280 143 case "describetable":
281 - $table = $params['table'];
144 + $table = urldecode($params['table']);
282 145 $resp = array("table_description" => $db->describeTable($table));
283 - $resp["primary_keys_index"] = $db->showTableIndex($table);
284 146 break;
285 147 case "checktable":
286 - $table = $params['table'];
287 - $type = $params['type'];
148 + $table = urldecode($params['table']);
149 + $type = urldecode($params['type']);
288 150 $resp = array("status" => $db->checkTable($table, $type));
289 151 break;
290 152 case "repairtable":
291 - $table = $params['table'];
153 + $table = urldecode($params['table']);
292 154 $resp = array("status" => $db->repairTable($table));
293 155 break;
294 156 case "gettcrt":
295 - $table = $params['table'];
157 + $table = urldecode($params['table']);
296 158 $resp = array("create" => $db->showTableCreate($table));
297 159 break;
298 160 case "tblskys":
299 161 $tables = $params['tables'];
@@ -312,9 +174,9 @@
312 174 $resp = $this->getTablesRowCount($tables);
313 175 break;
314 176 case "chktabls":
315 177 $tables = $params['tables'];
316 - $type = $params['type'];
178 + $type = urldecode($params['type']);
317 179 $resp = $this->checkTables($tables, $type);
318 180 break;
319 181 case "chktablsxist":
320 182 $tables = $params['tables'];
@@ -320,18 +182,18 @@
320 182 $tables = $params['tables'];
321 183 $resp = $this->checkTablesExist($tables);
322 184 break;
323 185 case "getrowscount":
324 - $table = $params['table'];
186 + $table = urldecode($params['table']);
325 187 $resp = array("count" => $db->rowsCount($table));
326 188 break;
327 189 case "gettablecontent":
328 190 $result = array();
329 - $table = $params['table'];
330 - $fields = $params['fields'];
331 - $filter = (array_key_exists('filter', $params)) ? $params['filter'] : "";
332 - $limit = intval($params['limit']);
333 - $offset = intval($params['offset']);
191 + $table = urldecode($params['table']);
192 + $fields = urldecode($params['fields']);
193 + $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : "";
194 + $limit = intval(urldecode($params['limit']));
195 + $offset = intval(urldecode($params['offset']));
334 196 $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array();
335 197 $result['timestamp'] = time();
336 198 $result['tablename'] = $table;
337 199 $rows = $db->getTableContent($table, $fields, $filter, $limit, $offset);
@@ -369,21 +231,17 @@
369 231 $resp[$identifier] = $result;
370 232 }
371 233 break;
372 234 case "tableinfo":
373 - $table = $params['table'];
374 - $offset = intval($params['offset']);
375 - $limit = intval($params['limit']);
376 - $bsize = intval($params['bsize']);
377 - $filter = (array_key_exists('filter', $params)) ? $params['filter'] : "";
378 - $tname = $params['tname'];
235 + $table = urldecode($params['table']);
236 + $offset = intval(urldecode($params['offset']));
237 + $limit = intval(urldecode($params['limit']));
238 + $bsize = intval(urldecode($params['bsize']));
239 + $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : "";
240 + $rcount = intval(urldecode($params['rcount']));
241 + $tname = urldecode($params['tname']);
379 242 $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array();
380 - $cursor_mode = (array_key_exists('cursor_mode', $params)) ? $params['cursor_mode'] : false;
381 - if ($cursor_mode === true) {
382 - $resp = $this->getTableDataByCursor($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, false, $cursor_mode);
383 - } else {
384 - $resp = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, false);
385 - }
243 + $resp = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, false);
386 244 break;
387 245 case "getmulttables":
388 246 $result = array();
389 247 $tableParams = $params['table_params'];
@@ -388,32 +246,29 @@
388 246 $result = array();
389 247 $tableParams = $params['table_params'];
390 248 $resp = array();
391 249 foreach($tableParams as $tableParam) {
392 - $table = $tableParam['table'];
393 - $tname = $tableParam['tname'];
394 - $filter = (array_key_exists('filter', $tableParam)) ? $tableParam['filter'] : "";
395 - $limit = intval($tableParam['limit']);
396 - $offset = intval($tableParam['offset']);
397 - $bsize = intval($tableParam['bsize']);
250 + $table = urldecode($tableParam['table']);
251 + $tname = urldecode($tableParam['tname']);
252 + $rcount = intval(urldecode($tableParam['rcount']));
253 + $filter = (array_key_exists('filter', $tableParam)) ? urldecode($tableParam['filter']) : "";
254 + $limit = intval(urldecode($tableParam['limit']));
255 + $offset = intval(urldecode($tableParam['offset']));
256 + $bsize = intval(urldecode($tableParam['bsize']));
398 257 $pkeys = (array_key_exists('pkeys', $tableParam)) ? $tableParam['pkeys'] : array();
399 - $resp[$tname] = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, true);
258 + $resp[$tname] = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, true);
400 259 }
401 260 break;
402 261 case "uploadrows":
403 - $table = $params['table'];
404 - $offset = intval($params['offset']);
405 - $limit = intval($params['limit']);
406 - $bsize = intval($params['bsize']);
407 - $filter = (array_key_exists('filter', $params)) ? $params['filter'] : "";
408 - $tname = $params['tname'];
262 + $table = urldecode($params['table']);
263 + $offset = intval(urldecode($params['offset']));
264 + $limit = intval(urldecode($params['limit']));
265 + $bsize = intval(urldecode($params['bsize']));
266 + $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : "";
267 + $rcount = intval(urldecode($params['rcount']));
268 + $tname = urldecode($params['tname']);
409 269 $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array();
410 - $cursor_mode = (array_key_exists('cursor_mode', $params)) ? $params['cursor_mode'] : false;
411 - if ($cursor_mode === true) {
412 - $resp = $this->getTableDataByCursor($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, true, $cursor_mode);
413 - } else {
414 - $resp = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, true);
415 - }
270 + $resp = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, true);
416 271 break;
417 272 case "tblexists":
418 273 $resp = array("tblexists" => $db->isTablePresent($params['table']));
419 274 break;
@@ -429,25 +284,8 @@
429 284 break;
430 285 case "altrtbl":
431 286 $resp = array("altrtbl" => $db->alterBVTable($params['query'], $params['query']));
432 287 break;
433 - case "mltigtrslt":
434 - $resp = array("mltigtrslt" => $this->multiGetResult($params['queries']));
435 - break;
436 - case "mltiqrsstrm":
437 - $queries = $params['queries'];
438 - $result = array();
439 - foreach ($queries as $qparams) {
440 - $identifier = $qparams['identifier'];
441 - $query = $qparams['query'];
442 - $pkeys = (array_key_exists('pkeys', $qparams)) ? $qparams['pkeys'] : array();
443 - array_push($result, $this->streamQueryResult($identifier, $query, $pkeys));
444 - }
445 - $resp = array('mltqrsstrm' => $result);
446 - break;
447 - case "getrndmdata":
448 - $resp = array("getrndmdata" => $this->getRandomData($params['size'], $params['batch_size']));
449 - break;
450 288 case "tbls":
451 289 $resp = array();
452 290
453 291 if (array_key_exists('truncate', $params))
@@ -475,5 +313,5 @@
475 313 }
476 314 return $resp;
477 315 }
478 316 }
479 -endif;
317 +endif;