PluginProbe
The WP Remote WordPress Plugin / 4.97
The WP Remote WordPress Plugin v4.97
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 / wings / db.php

db.php in The WP Remote WordPress Plugin 4.97, at callback/wings/db.php

386 lines 11.6 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('BVDBCallback')) :
5 require_once dirname( __FILE__ ) . '/../streams.php';
6
7 class BVDBCallback extends BVCallbackBase {
8 public $db;
9 public $stream;
10 public $account;
11
12 public static $bvTables = array("fw_requests", "lp_requests", "ip_store");
13
14 const DB_WING_VERSION = 1.2;
15
16 public function __construct($callback_handler) {
17 $this->db = $callback_handler->db;
18 $this->account = $callback_handler->account;
19 $this->siteinfo = $callback_handler->siteinfo;
20 }
21
22 public function getLastID($pkeys, $end_row) {
23 $last_ids = array();
24 foreach($pkeys as $pk) {
25 $last_ids[$pk] = $end_row[$pk];
26 }
27 return $last_ids;
28 }
29
30 public function getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, $include_rows = false) {
31 $tinfo = array();
32
33 $rows_count = $this->db->rowsCount($table);
34 $result = array('count' => $rows_count);
35 if ($limit == 0) {
36 $limit = $rows_count;
37 }
38 $srows = 1;
39 while (($limit > 0) && ($srows > 0)) {
40 if ($bsize > $limit)
41 $bsize = $limit;
42 $rows = $this->db->getTableContent($table, '*', $filter, $bsize, $offset);
43 $srows = sizeof($rows);
44 $data = array();
45 $data["table_name"] = $tname;
46 $data["offset"] = $offset;
47 $data["size"] = $srows;
48 $serialized_rows = serialize($rows);
49 $data['md5'] = md5($serialized_rows);
50 $data['length'] = strlen($serialized_rows);
51 array_push($tinfo, $data);
52 if (!empty($pkeys) && $srows > 0) {
53 $end_row = end($rows);
54 $last_ids = $this->getLastID($pkeys, $end_row);
55 $data['last_ids'] = $last_ids;
56 $result['last_ids'] = $last_ids;
57 }
58 if ($include_rows) {
59 $data["rows"] = $rows;
60 $str = serialize($data);
61 $this->stream->writeStream($str);
62 }
63 $offset += $srows;
64 $limit -= $srows;
65 }
66 $result['size'] = $offset;
67 $result['tinfo'] = $tinfo;
68 return $result;
69 }
70
71 public function streamQueryResult($identifier, $query, $pkeys) {
72 $data = array();
73 $data["identifier"] = $identifier;
74 $data["query"] = $query;
75
76 $data["query_start_time"] = time();
77 $rows = $this->db->getResult($query);
78 $srows = sizeof($rows);
79 $data["size"] = $srows;
80 $data["query_end_time"] = time();
81 if (!empty($pkeys) && $srows > 0) {
82 $end_row = end($rows);
83 $last_ids = $this->getLastID($pkeys, $end_row);
84 $data['last_ids'] = $last_ids;
85 }
86 $result = array_merge($data);
87 $data["rows"] = $rows;
88 $serialized_rows = serialize($data);
89 $this->stream->writeStream($serialized_rows);
90 $result['length'] = strlen($serialized_rows);
91 return $result;
92 }
93
94 function getRandomData($totalSize, $bsize) {
95 if ($bsize == 0) {
96 $bsize = $totalSize;
97 }
98
99 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
100 $charactersLength = strlen($characters);
101
102 while ($totalSize > 0) {
103 if ($bsize > $totalSize) {
104 $bsize = $totalSize;
105 }
106
107 $randomString = '';
108 for ($i = 0; $i < $bsize; $i++) {
109 $randomString .= $characters[rand(0, $charactersLength - 1)];
110 }
111
112 $this->stream->writeStream($randomString);
113 $totalSize -= $bsize;
114 }
115 return array("status" => "true");
116 }
117
118 public function getCreateTableQueries($tables) {
119 $resp = array();
120 foreach($tables as $table) {
121 $tname = $table;
122 $resp[$tname] = array("create" => $this->db->showTableCreate($table));
123 }
124 return $resp;
125 }
126
127 public function checkTables($tables, $type) {
128 $resp = array();
129 foreach($tables as $table) {
130 $tname = $table;
131 $resp[$tname] = array("status" => $this->db->checkTable($table, $type));
132 }
133 return $resp;
134 }
135
136 public function describeTables($tables) {
137 $resp = array();
138 foreach($tables as $table) {
139 $tname = $table;
140 $resp[$tname] = array("description" => $this->db->describeTable($table));
141 }
142 return $resp;
143 }
144
145 public function checkTablesExist($tables) {
146 $resp = array();
147 foreach($tables as $table) {
148 $tname = $table;
149 $resp[$tname] = array("tblexists" => $this->db->isTablePresent($table));
150 }
151 return $resp;
152 }
153
154 public function getTablesRowCount($tables) {
155 $resp = array();
156 foreach($tables as $table) {
157 $tname = $table;
158 $resp[$tname] = array("count" => $this->db->rowsCount($table));
159 }
160 return $resp;
161 }
162
163 public function getTablesKeys($tables) {
164 $resp = array();
165 foreach($tables as $table) {
166 $tname = $table;
167 $resp[$tname] = array("keys" => $this->db->tableKeys($table));
168 }
169 return $resp;
170 }
171
172 public function multiGetResult($queries) {
173 $resp = array();
174 foreach($queries as $query) {
175 array_push($resp, $this->db->getResult($query));
176 }
177 return $resp;
178 }
179
180 public function process($request) {
181 $db = $this->db;
182 $params = $request->params;
183 $stream_init_info = BVStream::startStream($this->account, $request);
184
185 if (array_key_exists('stream', $stream_init_info)) {
186 $this->stream = $stream_init_info['stream'];
187 switch ($request->method) {
188 case "gettbls":
189 $resp = array("tables" => $db->showTables());
190 break;
191 case "tblstatus":
192 $resp = array("statuses" => $db->showTableStatus());
193 break;
194 case "tablekeys":
195 $table = $params['table'];
196 $resp = array("table_keys" => $db->tableKeys($table));
197 break;
198 case "describetable":
199 $table = $params['table'];
200 $resp = array("table_description" => $db->describeTable($table));
201 break;
202 case "checktable":
203 $table = $params['table'];
204 $type = $params['type'];
205 $resp = array("status" => $db->checkTable($table, $type));
206 break;
207 case "repairtable":
208 $table = $params['table'];
209 $resp = array("status" => $db->repairTable($table));
210 break;
211 case "gettcrt":
212 $table = $params['table'];
213 $resp = array("create" => $db->showTableCreate($table));
214 break;
215 case "tblskys":
216 $tables = $params['tables'];
217 $resp = $this->getTablesKeys($tables);
218 break;
219 case "getmlticrt":
220 $tables = $params['tables'];
221 $resp = $this->getCreateTableQueries($tables);
222 break;
223 case "desctbls":
224 $tables = $params['tables'];
225 $resp = $this->describeTables($tables);
226 break;
227 case "mltirwscount":
228 $tables = $params['tables'];
229 $resp = $this->getTablesRowCount($tables);
230 break;
231 case "chktabls":
232 $tables = $params['tables'];
233 $type = $params['type'];
234 $resp = $this->checkTables($tables, $type);
235 break;
236 case "chktablsxist":
237 $tables = $params['tables'];
238 $resp = $this->checkTablesExist($tables);
239 break;
240 case "getrowscount":
241 $table = $params['table'];
242 $resp = array("count" => $db->rowsCount($table));
243 break;
244 case "gettablecontent":
245 $result = array();
246 $table = $params['table'];
247 $fields = $params['fields'];
248 $filter = (array_key_exists('filter', $params)) ? $params['filter'] : "";
249 $limit = intval($params['limit']);
250 $offset = intval($params['offset']);
251 $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array();
252 $result['timestamp'] = time();
253 $result['tablename'] = $table;
254 $rows = $db->getTableContent($table, $fields, $filter, $limit, $offset);
255 $srows = sizeof($rows);
256 if (!empty($pkeys) && $srows > 0) {
257 $end_row = end($rows);
258 $result['last_ids'] = $this->getLastID($pkeys, $end_row);
259 }
260 $result["rows"] = $rows;
261 $resp = $result;
262 break;
263 case "multitablecontent":
264 $tableParams = $params['table_params'];
265 $resp = array();
266 foreach($tableParams as $tableParam) {
267 $result = array();
268 $identifier = $tableParam['identifier'];
269 $table = $tableParam['table'];
270 $tname = $tableParam['tname'];
271 $fields = $tableParam['fields'];
272 $filter = (array_key_exists('filter', $tableParam)) ? $tableParam['filter'] : "";
273 $limit = $tableParam['limit'];
274 $offset = $tableParam['offset'];
275 $pkeys = (array_key_exists('pkeys', $tableParam)) ? $tableParam['pkeys'] : array();
276 $result['timestamp'] = time();
277 $result['table_name'] = $tname;
278 $rows = $db->getTableContent($table, $fields, $filter, $limit, $offset);
279 $srows = sizeof($rows);
280 if (!empty($pkeys) && $srows > 0) {
281 $end_row = end($rows);
282 $result['last_ids'] = $this->getLastID($pkeys, $end_row);
283 }
284 $result["rows"] = $rows;
285 $result["size"] = $srows;
286 $resp[$identifier] = $result;
287 }
288 break;
289 case "tableinfo":
290 $table = $params['table'];
291 $offset = intval($params['offset']);
292 $limit = intval($params['limit']);
293 $bsize = intval($params['bsize']);
294 $filter = (array_key_exists('filter', $params)) ? $params['filter'] : "";
295 $tname = $params['tname'];
296 $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array();
297 $resp = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, false);
298 break;
299 case "getmulttables":
300 $result = array();
301 $tableParams = $params['table_params'];
302 $resp = array();
303 foreach($tableParams as $tableParam) {
304 $table = $tableParam['table'];
305 $tname = $tableParam['tname'];
306 $filter = (array_key_exists('filter', $tableParam)) ? $tableParam['filter'] : "";
307 $limit = intval($tableParam['limit']);
308 $offset = intval($tableParam['offset']);
309 $bsize = intval($tableParam['bsize']);
310 $pkeys = (array_key_exists('pkeys', $tableParam)) ? $tableParam['pkeys'] : array();
311 $resp[$tname] = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, true);
312 }
313 break;
314 case "uploadrows":
315 $table = $params['table'];
316 $offset = intval($params['offset']);
317 $limit = intval($params['limit']);
318 $bsize = intval($params['bsize']);
319 $filter = (array_key_exists('filter', $params)) ? $params['filter'] : "";
320 $tname = $params['tname'];
321 $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array();
322 $resp = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, true);
323 break;
324 case "tblexists":
325 $resp = array("tblexists" => $db->isTablePresent($params['table']));
326 break;
327 case "crttbl":
328 $usedbdelta = array_key_exists('usedbdelta', $params);
329 $resp = array("crttbl" => $db->createTable($params['query'], $params['table'], $usedbdelta));
330 break;
331 case "drptbl":
332 $resp = array("drptbl" => $db->dropBVTable($params['table']));
333 break;
334 case "trttbl":
335 $resp = array("trttbl" => $db->truncateBVTable($params['table']));
336 break;
337 case "altrtbl":
338 $resp = array("altrtbl" => $db->alterBVTable($params['query'], $params['query']));
339 break;
340 case "mltigtrslt":
341 $resp = array("mltigtrslt" => $this->multiGetResult($params['queries']));
342 break;
343 case "mltiqrsstrm":
344 $queries = $params['queries'];
345 $result = array();
346 foreach ($queries as $qparams) {
347 $identifier = $qparams['identifier'];
348 $query = $qparams['query'];
349 $pkeys = (array_key_exists('pkeys', $qparams)) ? $qparams['pkeys'] : array();
350 array_push($result, $this->streamQueryResult($identifier, $query, $pkeys));
351 }
352 $resp = array('mltqrsstrm' => $result);
353 break;
354 case "getrndmdata":
355 $resp = array("getrndmdata" => $this->getRandomData($params['size'], $params['batch_size']));
356 break;
357 case "tbls":
358 $resp = array();
359
360 if (array_key_exists('truncate', $params))
361 $resp['truncate'] = $db->truncateTables($params['truncate']);
362
363 if (array_key_exists('drop', $params))
364 $resp['drop'] = $db->dropTables($params['drop']);
365
366 if (array_key_exists('create', $params))
367 $resp['create'] = $db->createTables($params['create']);
368
369 if (array_key_exists('alter', $params))
370 $resp['alter'] = $db->alterTables($params['alter']);
371
372 break;
373 default:
374 $resp = false;
375 }
376 $end_stream_info = $this->stream->endStream();
377 if (!empty($end_stream_info) && is_array($resp)) {
378 $resp = array_merge($resp, $end_stream_info);
379 }
380 } else {
381 $resp = $stream_init_info;
382 }
383 return $resp;
384 }
385 }
386 endif;