PluginProbe
The WP Remote WordPress Plugin / 5.88
The WP Remote WordPress Plugin v5.88
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 / watch.php

watch.php in The WP Remote WordPress Plugin 5.88, at callback/wings/watch.php

285 lines 10.5 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('BVWatchCallback')) :
5
6 class BVWatchCallback extends BVCallbackBase {
7 public $db;
8 public $settings;
9
10 const WATCH_WING_VERSION = 1.6;
11
12 public function __construct($callback_handler) {
13 $this->db = $callback_handler->db;
14 $this->settings = $callback_handler->settings;
15 }
16
17 public function getData($table, $limit = 0, $filter = "") {
18 $result = array();
19 $data = array();
20 $rows = $this->db->getTableContent($table, '*', $filter, $limit);
21 $last_id = 0;
22 foreach ($rows as $row) {
23 $result[] = $row;
24 $last_id = $row['id'];
25 }
26 $data['last_id'] = $last_id;
27 $data['rows'] = $result;
28 return $data;
29 }
30
31 public function deleteBvDynamicEvents($filter = "") {
32 $name = BVWPDynSync::$dynsync_table;
33 return $this->db->deleteBVTableContent($name, $filter);
34 }
35
36 public function setWatchTime() {
37 return $this->settings->updateOption('bvwatchtime', time());
38 }
39
40 // we use fread to read limited fw_prepend_log, with wp function, we will load entire fw_prepend_log at once which may have perfromance issues
41 public function getFWPrependLog($params) {
42 $result = array();
43 $fname = $params['fname'];
44 $limit = intval($params['limit']);
45 $filesystem = WPRHelper::get_direct_filesystem();
46
47 if ($filesystem->exists($fname)) {
48
49 $result['exists'] = true;
50 $tmpfname = $fname."tmp";
51
52 if (!$filesystem->move($fname, $tmpfname, true)) {
53
54 $result = array('status' => 'Error', 'message' => 'UNABLE_TO_RENAME_LOGFILE');
55
56 } else {
57
58 if ($filesystem->exists($tmpfname)) {
59
60 $fsize = $filesystem->size($tmpfname);
61 $result["size"] = $fsize;
62
63 if ($fsize <= $limit) {
64
65 $result['content'] = $filesystem->get_contents($tmpfname);
66
67 } else {
68 $handle = fopen($tmpfname, "rb"); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
69 $result['content'] = fread($handle, $limit); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fread
70 $result['incomplete'] = true;
71 fclose($handle); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
72 }
73
74 $result['tmpfile'] = unlink($tmpfname);
75 } else {
76 $result['tmpfile'] = 'DOES_NOT_EXISTS';
77 }
78
79 }
80 }
81
82 return $result;
83 }
84
85 // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_fsockopen, WordPress.WP.AlternativeFunctions.file_system_operations_fwrite, WordPress.WP.AlternativeFunctions.file_system_operations_fclose
86 public function getDomainInfo($params) {
87 $domain = $params["domain"];
88 if (empty($domain)) {
89 return array('domainData' => "DOMAIN_NOT_PRESENT");
90 }
91
92 $whoisServer = $params["host"];
93 if (empty($whoisServer)) {
94 return array('domainData' => "WHOIS_SERVER_NOT_PRESENT : $domain");
95 }
96
97 $conn = @fsockopen($whoisServer, $params["port"], $errno, $errstr, $params["timeout"]);
98 if (!$conn) {
99 return array('domainData' => "UNABLE_TO_CONNECT_TO_WHOIS_SERVER : $whoisServer : DOMAIN : $domain : ERROR : $errstr ($errno)");
100 }
101
102 try {
103 fwrite($conn, "$domain\r\n");
104
105 $response = '';
106 while (!feof($conn)) {
107 $response .= fgets($conn, 1024);
108 }
109
110 fclose($conn);
111 } catch (Exception $e) {
112 fclose($conn);
113 return array('domainData' => "ERROR_WHILE_FETCHING_DATA : " . $e->getMessage());
114 }
115
116 return array('domainData' => $response);
117 }
118 // phpcs:enable WordPress.WP.AlternativeFunctions.file_system_operations_fsockopen, WordPress.WP.AlternativeFunctions.file_system_operations_fwrite, WordPress.WP.AlternativeFunctions.file_system_operations_fclose
119
120 public function process($request) {
121 $db = $this->db;
122 $settings = $this->settings;
123 $this->setWatchTime();
124 $params = $request->params;
125
126 switch ($request->method) {
127 case "getdata":
128 $resp = array();
129
130 if (isset($params['domain_params']) && is_array($params['domain_params'])) {
131 $resp = array_merge($resp, $this->getDomainInfo($params['domain_params']));
132 }
133
134 if (array_key_exists('lp', $params)) {
135 require_once dirname( __FILE__ ) . '/../../protect/lp.php';
136 $lp_params = $params['lp'];
137 if (!isset($lp_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(WPRProtectLP_V588::TABLE_NAME))) {
138 $limit = intval($lp_params['limit']);
139 $filter = $lp_params['filter'];
140 $offset = isset($lp_params['offset']) ? intval($lp_params['offset']) : 0;
141 $table = $db->getBVTable(WPRProtectLP_V588::TABLE_NAME);
142 $auto_increment = $db->getAutoIncrement($table);
143
144
145 if ($auto_increment && ($auto_increment < $offset) && $lp_params['enforce_auto_incr_check']) {
146 $resp["lplogs"] = array("auto_increment" => $auto_increment, "offset_reset_required" => true);
147 } else {
148 $db->deleteBVTableContent(WPRProtectLP_V588::TABLE_NAME, $lp_params['rmfilter']);
149 $resp["lplogs"] = $this->getData($table, $limit, $filter);
150 }
151 } else {
152 $resp["lplogs"] = array("status" => "TABLE_NOT_PRESENT");
153 }
154 }
155
156 if (array_key_exists('prelog', $params)) {
157 $prelog_params = $params['prelog'];
158 $resp["prelog"] = $this->getFWPrependLog($prelog_params);
159 }
160
161 if (array_key_exists('fw', $params)) {
162 require_once dirname( __FILE__ ) . '/../../protect/fw.php';
163 $fw_params = $params['fw'];
164 if (!isset($fw_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(WPRProtectFW_V588::TABLE_NAME))) {
165 $limit = intval($fw_params['limit']);
166 $filter = $fw_params['filter'];
167 $offset = isset($fw_params['offset']) ? intval($fw_params['offset']) : 0;
168 $table = $db->getBVTable(WPRProtectFW_V588::TABLE_NAME);
169 $auto_increment = $db->getAutoIncrement($table);
170
171 if ($auto_increment && ($auto_increment < $offset) && $fw_params['enforce_auto_incr_check']) {
172 $resp["fwlogs"] = array("auto_increment" => $auto_increment, "offset_reset_required" => true);
173 } else {
174 $db->deleteBVTableContent(WPRProtectFW_V588::TABLE_NAME, $fw_params['rmfilter']);
175 $resp["fwlogs"] = $this->getData($table, $limit, $filter);
176 }
177
178 } else {
179 $resp["fwlogs"] = array("status" => "TABLE_NOT_PRESENT");
180 }
181 }
182
183 if (array_key_exists('dynevent', $params)) {
184 require_once dirname( __FILE__ ) . '/../../wp_dynsync.php';
185 $isdynsyncactive = $settings->getOption('bvDynSyncActive');
186 if ($isdynsyncactive == 'yes') {
187 if (!isset($params['bv_check_table']) || $db->isTablePresent($db->getBVTable(BVWPDynSync::$dynsync_table))) {
188 $limit = intval($params['limit']);
189 $filter = $params['filter'];
190 $offset = isset($params['offset']) ? intval($params['offset']) : 0;
191 $table = $db->getBVTable(BVWPDynSync::$dynsync_table);
192 $auto_increment = $db->getAutoIncrement($table);
193
194 if ($auto_increment && ($auto_increment < $offset) && $params['enforce_auto_incr_check']) {
195 $resp = array("auto_increment" => $auto_increment, "offset_reset_required" => true);
196 } else {
197 $this->deleteBvDynamicEvents($params['rmfilter']);
198 $data = $this->getData($table, $limit, $filter);
199
200 $resp['last_id'] = $data['last_id'];
201 $resp['events'] = $data['rows'];
202 $resp['timestamp'] = time();
203 $resp["status"] = true;
204 }
205 }
206 }
207 }
208
209 if (array_key_exists('actlog', $params)) {
210 require_once dirname( __FILE__ ) . '/../../wp_actlog.php';
211 $actlog_params = $params['actlog'];
212 if (!isset($actlog_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(BVWPActLog::$actlog_table))) {
213 $table = $db->getBVTable(BVWPActLog::$actlog_table);
214 $limit = intval($actlog_params['limit']);
215 $filter = $actlog_params['filter'];
216 $offset = isset($actlog_params['offset']) ? intval($actlog_params['offset']) : 0;
217 $auto_increment = $db->getAutoIncrement($table);
218
219 if ($auto_increment && ($auto_increment < $offset) && $actlog_params['enforce_auto_incr_check']) {
220 $resp["actlogs"] = array("auto_increment" => $auto_increment, "offset_reset_required" => true);
221 } else {
222 $db->deleteBVTableContent(BVWPActLog::$actlog_table, $actlog_params['rmfilter']);
223 $resp["actlogs"] = $this->getData($table, $limit, $filter);
224 }
225 } else {
226 $resp["actlogs"] = array("status" => "TABLE_NOT_PRESENT");
227 }
228 }
229
230 if (array_key_exists('airlift_stats', $params)) {
231 $airlift_stats_table = "airlift_stats";
232 $airlift_stats_params = $params['airlift_stats'];
233 $table = $db->getBVTable($airlift_stats_table);
234 if (!isset($airlift_stats_params['bv_check_table']) || $db->isTablePresent($table)) {
235 $limit = intval($airlift_stats_params['limit']);
236 $filter = $airlift_stats_params['filter'];
237 $offset = isset($airlift_stats_params['offset']) ? intval($airlift_stats_params['offset']) : 0;
238 $auto_increment = $db->getAutoIncrement($table);
239
240 if ($auto_increment && ($auto_increment < $offset) && $airlift_stats_params['enforce_auto_incr_check']) {
241 $resp["airlift_stats"] = array("auto_increment" => $auto_increment, "offset_reset_required" => true);
242 } else {
243 $db->deleteBVTableContent($airlift_stats_table, $airlift_stats_params['rmfilter']);
244 $resp["airlift_stats"] = $this->getData($table, $limit, $filter);
245 }
246 } else {
247 $resp["airlift_stats"] = array("status" => "TABLE_NOT_PRESENT");
248 }
249 }
250
251 if (array_key_exists('php_error_monitoring', $params)) {
252 require_once dirname( __FILE__ ) . '/../../php_error_monitoring/monitoring.php';
253 $php_error_monit_params = $params['php_error_monitoring'];
254 $table = $db->getBVTable(WPRWPPHPErrorMonitoring::ERROR_TABLE);
255 if (!isset($php_error_monit_params['bv_check_table']) || $db->isTablePresent($table)) {
256 $limit = intval($php_error_monit_params['limit']);
257 $filter = $php_error_monit_params['filter'];
258 $offset = isset($php_error_monit_params['offset']) ? intval($php_error_monit_params['offset']) : 0;
259 $auto_increment = $db->getAutoIncrement($table);
260
261 if ($auto_increment && ($auto_increment < $offset) && $php_error_monit_params['enforce_auto_incr_check']) {
262 $resp["php_error_monitoring"] = array("auto_increment" => $auto_increment, "offset_reset_required" => true);
263 } else {
264 $db->deleteBVTableContent(WPRWPPHPErrorMonitoring::ERROR_TABLE, $php_error_monit_params['rmfilter']);
265 $resp["php_error_monitoring"] = $this->getData($table, $limit, $filter);
266 }
267 } else {
268 $resp["php_error_monitoring"] = array("status" => "TABLE_NOT_PRESENT");
269 }
270 }
271
272 $resp["status"] = "done";
273 break;
274 case "rmdata":
275 require_once dirname( __FILE__ ) . '/../../wp_dynsync.php';
276 $filter = $params['filter'];
277 $resp = array("status" => $this->deleteBvDynamicEvents($filter));
278 break;
279 default:
280 $resp = false;
281 }
282 return $resp;
283 }
284 }
285 endif;