PluginProbe
The WP Remote WordPress Plugin / trunk
The WP Remote WordPress Plugin vtrunk
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/watch.php +82 -36 5.68trunk 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.4;
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,9 @@
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
83 82 public function getDomainInfo($params) {
84 83 $domain = $params["domain"];
85 84 if (empty($domain)) {
86 85 return array('domainData' => "DOMAIN_NOT_PRESENT");
@@ -111,9 +110,24 @@
111 110 }
112 111
113 112 return array('domainData' => $response);
114 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 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 +
116 130 public function process($request) {
117 131 $db = $this->db;
118 132 $settings = $this->settings;
119 133 $this->setWatchTime();
@@ -129,14 +143,18 @@
129 143
130 144 if (array_key_exists('lp', $params)) {
131 145 require_once dirname( __FILE__ ) . '/../../protect/lp.php';
132 146 $lp_params = $params['lp'];
133 - if (!isset($lp_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(WPRProtectLP_V568::TABLE_NAME))) {
147 + if (!isset($lp_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(WPRProtectLP_V672::TABLE_NAME))) {
134 148 $limit = intval($lp_params['limit']);
135 149 $filter = $lp_params['filter'];
136 - $db->deleteBVTableContent(WPRProtectLP_V568::TABLE_NAME, $lp_params['rmfilter']);
137 - $table = $db->getBVTable(WPRProtectLP_V568::TABLE_NAME);
138 - $resp["lplogs"] = $this->getData($table, $limit, $filter);
150 + $offset = isset($lp_params['offset']) ? intval($lp_params['offset']) : 0;
151 + $table = $db->getBVTable(WPRProtectLP_V672::TABLE_NAME);
152 + $resp["lplogs"] = $this->getOffsetResetInfo($lp_params, $offset, $table);
153 + if (empty($resp["lplogs"])) {
154 + $db->deleteBVTableContent(WPRProtectLP_V672::TABLE_NAME, $lp_params['rmfilter']);
155 + $resp["lplogs"] = $this->getData($table, $limit, $filter);
156 + }
139 157 } else {
140 158 $resp["lplogs"] = array("status" => "TABLE_NOT_PRESENT");
141 159 }
142 160 }
@@ -148,14 +166,18 @@
148 166
149 167 if (array_key_exists('fw', $params)) {
150 168 require_once dirname( __FILE__ ) . '/../../protect/fw.php';
151 169 $fw_params = $params['fw'];
152 - if (!isset($fw_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(WPRProtectFW_V568::TABLE_NAME))) {
170 + if (!isset($fw_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(WPRProtectFW_V672::TABLE_NAME))) {
153 171 $limit = intval($fw_params['limit']);
154 172 $filter = $fw_params['filter'];
155 - $db->deleteBVTableContent(WPRProtectFW_V568::TABLE_NAME, $fw_params['rmfilter']);
156 - $table = $db->getBVTable(WPRProtectFW_V568::TABLE_NAME);
157 - $resp["fwlogs"] = $this->getData($table, $limit, $filter);
173 + $offset = isset($fw_params['offset']) ? intval($fw_params['offset']) : 0;
174 + $table = $db->getBVTable(WPRProtectFW_V672::TABLE_NAME);
175 + $resp["fwlogs"] = $this->getOffsetResetInfo($fw_params, $offset, $table);
176 + if (empty($resp["fwlogs"])){
177 + $db->deleteBVTableContent(WPRProtectFW_V672::TABLE_NAME, $fw_params['rmfilter']);
178 + $resp["fwlogs"] = $this->getData($table, $limit, $filter);
179 + }
158 180 } else {
159 181 $resp["fwlogs"] = array("status" => "TABLE_NOT_PRESENT");
160 182 }
161 183 }
@@ -166,15 +188,27 @@
166 188 if ($isdynsyncactive == 'yes') {
167 189 if (!isset($params['bv_check_table']) || $db->isTablePresent($db->getBVTable(BVWPDynSync::$dynsync_table))) {
168 190 $limit = intval($params['limit']);
169 191 $filter = $params['filter'];
170 - $this->deleteBvDynamicEvents($params['rmfilter']);
192 + $offset = isset($params['offset']) ? intval($params['offset']) : 0;
171 193 $table = $db->getBVTable(BVWPDynSync::$dynsync_table);
172 - $data = $this->getData($table, $limit, $filter);
173 - $resp['last_id'] = $data['last_id'];
174 - $resp['events'] = $data['rows'];
175 - $resp['timestamp'] = time();
176 - $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 + }
177 211 }
178 212 }
179 213 }
180 214
@@ -181,13 +215,17 @@
181 215 if (array_key_exists('actlog', $params)) {
182 216 require_once dirname( __FILE__ ) . '/../../wp_actlog.php';
183 217 $actlog_params = $params['actlog'];
184 218 if (!isset($actlog_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(BVWPActLog::$actlog_table))) {
219 + $table = $db->getBVTable(BVWPActLog::$actlog_table);
185 220 $limit = intval($actlog_params['limit']);
186 221 $filter = $actlog_params['filter'];
187 - $db->deleteBVTableContent(BVWPActLog::$actlog_table, $actlog_params['rmfilter']);
188 - $table = $db->getBVTable(BVWPActLog::$actlog_table);
189 - $resp["actlogs"] = $this->getData($table, $limit, $filter);
222 + $offset = isset($actlog_params['offset']) ? intval($actlog_params['offset']) : 0;
223 + $resp["actlogs"] = $this->getOffsetResetInfo($actlog_params, $offset, $table);
224 + if (empty($resp["actlogs"])) {
225 + $db->deleteBVTableContent(BVWPActLog::$actlog_table, $actlog_params['rmfilter']);
226 + $resp["actlogs"] = $this->getData($table, $limit, $filter);
227 + }
190 228 } else {
191 229 $resp["actlogs"] = array("status" => "TABLE_NOT_PRESENT");
192 230 }
193 231 }
@@ -198,10 +236,14 @@
198 236 $table = $db->getBVTable($airlift_stats_table);
199 237 if (!isset($airlift_stats_params['bv_check_table']) || $db->isTablePresent($table)) {
200 238 $limit = intval($airlift_stats_params['limit']);
201 239 $filter = $airlift_stats_params['filter'];
202 - $db->deleteBVTableContent($airlift_stats_table, $airlift_stats_params['rmfilter']);
203 - $resp["airlift_stats"] = $this->getData($table, $limit, $filter);
240 + $offset = isset($airlift_stats_params['offset']) ? intval($airlift_stats_params['offset']) : 0;
241 + $resp["airlift_stats"] = $this->getOffsetResetInfo($airlift_stats_params, $offset, $table);
242 + if (empty($resp["airlift_stats"])) {
243 + $db->deleteBVTableContent($airlift_stats_table, $airlift_stats_params['rmfilter']);
244 + $resp["airlift_stats"] = $this->getData($table, $limit, $filter);
245 + }
204 246 } else {
205 247 $resp["airlift_stats"] = array("status" => "TABLE_NOT_PRESENT");
206 248 }
207 249 }
@@ -212,10 +254,14 @@
212 254 $table = $db->getBVTable(WPRWPPHPErrorMonitoring::ERROR_TABLE);
213 255 if (!isset($php_error_monit_params['bv_check_table']) || $db->isTablePresent($table)) {
214 256 $limit = intval($php_error_monit_params['limit']);
215 257 $filter = $php_error_monit_params['filter'];
216 - $db->deleteBVTableContent(WPRWPPHPErrorMonitoring::ERROR_TABLE, $php_error_monit_params['rmfilter']);
217 - $resp["php_error_monitoring"] = $this->getData($table, $limit, $filter);
258 + $offset = isset($php_error_monit_params['offset']) ? intval($php_error_monit_params['offset']) : 0;
259 + $resp["php_error_monitoring"] = $this->getOffsetResetInfo($php_error_monit_params, $offset, $table);
260 + if (empty($resp["php_error_monitoring"])) {
261 + $db->deleteBVTableContent(WPRWPPHPErrorMonitoring::ERROR_TABLE, $php_error_monit_params['rmfilter']);
262 + $resp["php_error_monitoring"] = $this->getData($table, $limit, $filter);
263 + }
218 264 } else {
219 265 $resp["php_error_monitoring"] = array("status" => "TABLE_NOT_PRESENT");
220 266 }
221 267 }
@@ -232,5 +278,5 @@
232 278 }
233 279 return $resp;
234 280 }
235 281 }
236 -endif;
282 +endif;