PluginProbe
The WP Remote WordPress Plugin / 6.76
The WP Remote WordPress Plugin v6.76
6.76 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 All 54 releases
← All changes | callback/wings/watch.php +137 -37 4.976.76 View file →
@@ -1,14 +1,14 @@
1 1 <?php
2 2
3 3 if (!defined('ABSPATH')) exit;
4 -if (!class_exists('BVWatchCallback')) :
4 +if (!class_exists('WPRWatchCallback')) :
5 5
6 -class BVWatchCallback extends BVCallbackBase {
6 +class WPRWatchCallback extends WPRCallbackBase {
7 7 public $db;
8 8 public $settings;
9 9
10 - const WATCH_WING_VERSION = 1.1;
10 + const WATCH_WING_VERSION = 1.7;
11 11
12 12 public function __construct($callback_handler) {
13 13 $this->db = $callback_handler->db;
14 14 $this->settings = $callback_handler->settings;
@@ -36,38 +36,36 @@
36 36 public function setWatchTime() {
37 37 return $this->settings->updateOption('bvwatchtime', time());
38 38 }
39 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
40 41 public function getFWPrependLog($params) {
41 42 $result = array();
42 43 $fname = $params['fname'];
43 44 $limit = intval($params['limit']);
44 45
45 - if (file_exists($fname)) {
46 + if (WPRWPFileSystem::getInstance()->exists($fname) === true) {
46 47
47 48 $result['exists'] = true;
48 49 $tmpfname = $fname."tmp";
49 50
50 - if (!@rename($fname, $tmpfname)) {
51 -
51 + if (WPRWPFileSystem::getInstance()->move($fname, $tmpfname, true) === false) {
52 52 $result = array('status' => 'Error', 'message' => 'UNABLE_TO_RENAME_LOGFILE');
53 53
54 54 } else {
55 55
56 - if (file_exists($tmpfname)) {
56 + if (WPRWPFileSystem::getInstance()->exists($tmpfname) === true) {
57 57
58 - $fsize = filesize($tmpfname);
58 + $fsize = WPRWPFileSystem::getInstance()->size($tmpfname);
59 59 $result["size"] = $fsize;
60 60
61 61 if ($fsize <= $limit) {
62 -
63 - $result['content'] = file_get_contents($tmpfname);
64 -
62 + $result['content'] = WPRWPFileSystem::getInstance()->getContents($tmpfname);
65 63 } else {
66 - $handle = fopen($tmpfname, "rb");
67 - $result['content'] = fread($handle, $limit);
64 + $handle = fopen($tmpfname, "rb"); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
65 + $result['content'] = fread($handle, $limit); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fread
68 66 $result['incomplete'] = true;
69 - fclose($handle);
67 + fclose($handle); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
70 68 }
71 69
72 70 $result['tmpfile'] = unlink($tmpfname);
73 71 } else {
@@ -79,8 +77,57 @@
79 77
80 78 return $result;
81 79 }
82 80
81 + // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_fsockopen, WordPress.WP.AlternativeFunctions.file_system_operations_fwrite, WordPress.WP.AlternativeFunctions.file_system_operations_fclose
82 + public function getDomainInfo($params) {
83 + $domain = $params["domain"];
84 + if (empty($domain)) {
85 + return array('domainData' => "DOMAIN_NOT_PRESENT");
86 + }
87 +
88 + $whoisServer = $params["host"];
89 + if (empty($whoisServer)) {
90 + return array('domainData' => "WHOIS_SERVER_NOT_PRESENT : $domain");
91 + }
92 +
93 + $conn = @fsockopen($whoisServer, $params["port"], $errno, $errstr, $params["timeout"]);
94 + if (!$conn) {
95 + return array('domainData' => "UNABLE_TO_CONNECT_TO_WHOIS_SERVER : $whoisServer : DOMAIN : $domain : ERROR : $errstr ($errno)");
96 + }
97 +
98 + try {
99 + fwrite($conn, "$domain\r\n");
100 +
101 + $response = '';
102 + while (!feof($conn)) {
103 + $response .= fgets($conn, 1024);
104 + }
105 +
106 + fclose($conn);
107 + } catch (Exception $e) {
108 + fclose($conn);
109 + return array('domainData' => "ERROR_WHILE_FETCHING_DATA : " . $e->getMessage());
110 + }
111 +
112 + return array('domainData' => $response);
113 + }
114 + // phpcs:enable WordPress.WP.AlternativeFunctions.file_system_operations_fsockopen, WordPress.WP.AlternativeFunctions.file_system_operations_fwrite, WordPress.WP.AlternativeFunctions.file_system_operations_fclose
115 +
116 + public function getOffsetResetInfo($params, $offset, $table, $col_name = "id") {
117 + if (!isset($params['enforce_auto_incr_check']) || !($params['enforce_auto_incr_check'] === true)) {
118 + return array();
119 + }
120 + $last_id = $this->db->getLastRowId($col_name, $table);
121 + if ($last_id === null) {
122 + return array("error" => "UNABLE_TO_FETCH_LAST_ROW_ID");
123 + } else if ($last_id < $offset) {
124 + return array("last_row_id" => $last_id, "offset_reset_required" => true);
125 + } else {
126 + return array();
127 + }
128 + }
129 +
83 130 public function process($request) {
84 131 $db = $this->db;
85 132 $settings = $this->settings;
86 133 $this->setWatchTime();
@@ -89,17 +136,25 @@
89 136 switch ($request->method) {
90 137 case "getdata":
91 138 $resp = array();
92 139
140 + if (isset($params['domain_params']) && is_array($params['domain_params'])) {
141 + $resp = array_merge($resp, $this->getDomainInfo($params['domain_params']));
142 + }
143 +
93 144 if (array_key_exists('lp', $params)) {
94 - require_once dirname( __FILE__ ) . '/../../protect/wp/lp/config.php';
145 + require_once dirname( __FILE__ ) . '/../../protect/lp.php';
95 146 $lp_params = $params['lp'];
96 - if (!isset($lp_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(BVWPLPConfig::$requests_table))) {
147 + if (!isset($lp_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(WPRProtectLP_V676::TABLE_NAME))) {
97 148 $limit = intval($lp_params['limit']);
98 149 $filter = $lp_params['filter'];
99 - $db->deleteBVTableContent(BVWPLPConfig::$requests_table, $lp_params['rmfilter']);
100 - $table = $db->getBVTable(BVWPLPConfig::$requests_table);
101 - $resp["lplogs"] = $this->getData($table, $limit, $filter);
150 + $offset = isset($lp_params['offset']) ? intval($lp_params['offset']) : 0;
151 + $table = $db->getBVTable(WPRProtectLP_V676::TABLE_NAME);
152 + $resp["lplogs"] = $this->getOffsetResetInfo($lp_params, $offset, $table);
153 + if (empty($resp["lplogs"])) {
154 + $db->deleteBVTableContent(WPRProtectLP_V676::TABLE_NAME, $lp_params['rmfilter']);
155 + $resp["lplogs"] = $this->getData($table, $limit, $filter);
156 + }
102 157 } else {
103 158 $resp["lplogs"] = array("status" => "TABLE_NOT_PRESENT");
104 159 }
105 160 }
@@ -109,16 +164,20 @@
109 164 $resp["prelog"] = $this->getFWPrependLog($prelog_params);
110 165 }
111 166
112 167 if (array_key_exists('fw', $params)) {
113 - require_once dirname( __FILE__ ) . '/../../protect/fw/config.php';
168 + require_once dirname( __FILE__ ) . '/../../protect/fw.php';
114 169 $fw_params = $params['fw'];
115 - if (!isset($fw_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(BVFWConfig::$requests_table))) {
170 + if (!isset($fw_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(WPRProtectFW_V676::TABLE_NAME))) {
116 171 $limit = intval($fw_params['limit']);
117 172 $filter = $fw_params['filter'];
118 - $db->deleteBVTableContent(BVFWConfig::$requests_table, $fw_params['rmfilter']);
119 - $table = $db->getBVTable(BVFWConfig::$requests_table);
120 - $resp["fwlogs"] = $this->getData($table, $limit, $filter);
173 + $offset = isset($fw_params['offset']) ? intval($fw_params['offset']) : 0;
174 + $table = $db->getBVTable(WPRProtectFW_V676::TABLE_NAME);
175 + $resp["fwlogs"] = $this->getOffsetResetInfo($fw_params, $offset, $table);
176 + if (empty($resp["fwlogs"])){
177 + $db->deleteBVTableContent(WPRProtectFW_V676::TABLE_NAME, $fw_params['rmfilter']);
178 + $resp["fwlogs"] = $this->getData($table, $limit, $filter);
179 + }
121 180 } else {
122 181 $resp["fwlogs"] = array("status" => "TABLE_NOT_PRESENT");
123 182 }
124 183 }
@@ -129,15 +188,27 @@
129 188 if ($isdynsyncactive == 'yes') {
130 189 if (!isset($params['bv_check_table']) || $db->isTablePresent($db->getBVTable(BVWPDynSync::$dynsync_table))) {
131 190 $limit = intval($params['limit']);
132 191 $filter = $params['filter'];
133 - $this->deleteBvDynamicEvents($params['rmfilter']);
192 + $offset = isset($params['offset']) ? intval($params['offset']) : 0;
134 193 $table = $db->getBVTable(BVWPDynSync::$dynsync_table);
135 - $data = $this->getData($table, $limit, $filter);
136 - $resp['last_id'] = $data['last_id'];
137 - $resp['events'] = $data['rows'];
138 - $resp['timestamp'] = time();
139 - $resp["status"] = true;
194 + $offset_reset_info = $this->getOffsetResetInfo($params, $offset, $table);
195 + if (empty($offset_reset_info)) {
196 + $this->deleteBvDynamicEvents($params['rmfilter']);
197 + $data = $this->getData($table, $limit, $filter);
198 +
199 + $resp['last_id'] = $data['last_id'];
200 + $resp['events'] = $data['rows'];
201 + $resp['timestamp'] = time();
202 + $resp["status"] = true;
203 + } else {
204 + if (array_key_exists("error", $offset_reset_info)) {
205 + $resp["error"] = $offset_reset_info["error"];
206 + } else {
207 + $resp["offset_reset_required"] = $offset_reset_info["offset_reset_required"];
208 + $resp["last_row_id"] = $offset_reset_info["last_row_id"];
209 + }
210 + }
140 211 }
141 212 }
142 213 }
143 214
@@ -143,14 +214,20 @@
143 214
144 215 if (array_key_exists('actlog', $params)) {
145 216 require_once dirname( __FILE__ ) . '/../../wp_actlog.php';
146 217 $actlog_params = $params['actlog'];
147 - if (!isset($actlog_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(BVWPActLog::$actlog_table))) {
218 + if (!is_array($actlog_params) || !isset($actlog_params['limit'], $actlog_params['filter'], $actlog_params['rmfilter'])) {
219 + $resp["actlogs"] = array("status" => "INVALID_PARAMETERS");
220 + } elseif (!isset($actlog_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(BVWPActLog::$actlog_table))) {
221 + $table = $db->getBVTable(BVWPActLog::$actlog_table);
148 222 $limit = intval($actlog_params['limit']);
149 223 $filter = $actlog_params['filter'];
150 - $db->deleteBVTableContent(BVWPActLog::$actlog_table, $actlog_params['rmfilter']);
151 - $table = $db->getBVTable(BVWPActLog::$actlog_table);
152 - $resp["actlogs"] = $this->getData($table, $limit, $filter);
224 + $offset = isset($actlog_params['offset']) ? intval($actlog_params['offset']) : 0;
225 + $resp["actlogs"] = $this->getOffsetResetInfo($actlog_params, $offset, $table);
226 + if (empty($resp["actlogs"])) {
227 + $db->deleteBVTableContent(BVWPActLog::$actlog_table, $actlog_params['rmfilter']);
228 + $resp["actlogs"] = $this->getData($table, $limit, $filter);
229 + }
153 230 } else {
154 231 $resp["actlogs"] = array("status" => "TABLE_NOT_PRESENT");
155 232 }
156 233 }
@@ -161,14 +238,37 @@
161 238 $table = $db->getBVTable($airlift_stats_table);
162 239 if (!isset($airlift_stats_params['bv_check_table']) || $db->isTablePresent($table)) {
163 240 $limit = intval($airlift_stats_params['limit']);
164 241 $filter = $airlift_stats_params['filter'];
165 - $db->deleteBVTableContent($airlift_stats_table, $airlift_stats_params['rmfilter']);
166 - $resp["airlift_stats"] = $this->getData($table, $limit, $filter);
242 + $offset = isset($airlift_stats_params['offset']) ? intval($airlift_stats_params['offset']) : 0;
243 + $resp["airlift_stats"] = $this->getOffsetResetInfo($airlift_stats_params, $offset, $table);
244 + if (empty($resp["airlift_stats"])) {
245 + $db->deleteBVTableContent($airlift_stats_table, $airlift_stats_params['rmfilter']);
246 + $resp["airlift_stats"] = $this->getData($table, $limit, $filter);
247 + }
167 248 } else {
168 249 $resp["airlift_stats"] = array("status" => "TABLE_NOT_PRESENT");
169 250 }
170 251 }
252 +
253 + if (array_key_exists('php_error_monitoring', $params)) {
254 + require_once dirname( __FILE__ ) . '/../../php_error_monitoring/monitoring.php';
255 + $php_error_monit_params = $params['php_error_monitoring'];
256 + $table = $db->getBVTable(WPRWPPHPErrorMonitoring::ERROR_TABLE);
257 + if (!isset($php_error_monit_params['bv_check_table']) || $db->isTablePresent($table)) {
258 + $limit = intval($php_error_monit_params['limit']);
259 + $filter = $php_error_monit_params['filter'];
260 + $offset = isset($php_error_monit_params['offset']) ? intval($php_error_monit_params['offset']) : 0;
261 + $resp["php_error_monitoring"] = $this->getOffsetResetInfo($php_error_monit_params, $offset, $table);
262 + if (empty($resp["php_error_monitoring"])) {
263 + $db->deleteBVTableContent(WPRWPPHPErrorMonitoring::ERROR_TABLE, $php_error_monit_params['rmfilter']);
264 + $resp["php_error_monitoring"] = $this->getData($table, $limit, $filter);
265 + }
266 + } else {
267 + $resp["php_error_monitoring"] = array("status" => "TABLE_NOT_PRESENT");
268 + }
269 + }
270 +
171 271 $resp["status"] = "done";
172 272 break;
173 273 case "rmdata":
174 274 require_once dirname( __FILE__ ) . '/../../wp_dynsync.php';
@@ -180,5 +280,5 @@
180 280 }
181 281 return $resp;
182 282 }
183 283 }
184 -endif;
284 +endif;