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 +132 -34 5.38trunk 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.2;
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 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(MCProtectLP::TABLE_NAME))) {
147 + if (!isset($lp_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(WPRProtectLP_V672::TABLE_NAME))) {
97 148 $limit = intval($lp_params['limit']);
98 149 $filter = $lp_params['filter'];
99 - $db->deleteBVTableContent(MCProtectLP::TABLE_NAME, $lp_params['rmfilter']);
100 - $table = $db->getBVTable(MCProtectLP::TABLE_NAME);
101 - $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 + }
102 157 } else {
103 158 $resp["lplogs"] = array("status" => "TABLE_NOT_PRESENT");
104 159 }
105 160 }
@@ -111,14 +166,18 @@
111 166
112 167 if (array_key_exists('fw', $params)) {
113 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(MCProtectFW::TABLE_NAME))) {
170 + if (!isset($fw_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(WPRProtectFW_V672::TABLE_NAME))) {
116 171 $limit = intval($fw_params['limit']);
117 172 $filter = $fw_params['filter'];
118 - $db->deleteBVTableContent(MCProtectFW::TABLE_NAME, $fw_params['rmfilter']);
119 - $table = $db->getBVTable(MCProtectFW::TABLE_NAME);
120 - $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 + }
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
@@ -144,13 +215,17 @@
144 215 if (array_key_exists('actlog', $params)) {
145 216 require_once dirname( __FILE__ ) . '/../../wp_actlog.php';
146 217 $actlog_params = $params['actlog'];
147 218 if (!isset($actlog_params['bv_check_table']) || $db->isTablePresent($db->getBVTable(BVWPActLog::$actlog_table))) {
219 + $table = $db->getBVTable(BVWPActLog::$actlog_table);
148 220 $limit = intval($actlog_params['limit']);
149 221 $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);
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 + }
153 228 } else {
154 229 $resp["actlogs"] = array("status" => "TABLE_NOT_PRESENT");
155 230 }
156 231 }
@@ -161,14 +236,37 @@
161 236 $table = $db->getBVTable($airlift_stats_table);
162 237 if (!isset($airlift_stats_params['bv_check_table']) || $db->isTablePresent($table)) {
163 238 $limit = intval($airlift_stats_params['limit']);
164 239 $filter = $airlift_stats_params['filter'];
165 - $db->deleteBVTableContent($airlift_stats_table, $airlift_stats_params['rmfilter']);
166 - $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 + }
167 246 } else {
168 247 $resp["airlift_stats"] = array("status" => "TABLE_NOT_PRESENT");
169 248 }
170 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 + $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 + }
264 + } else {
265 + $resp["php_error_monitoring"] = array("status" => "TABLE_NOT_PRESENT");
266 + }
267 + }
268 +
171 269 $resp["status"] = "done";
172 270 break;
173 271 case "rmdata":
174 272 require_once dirname( __FILE__ ) . '/../../wp_dynsync.php';
@@ -180,5 +278,5 @@
180 278 }
181 279 return $resp;
182 280 }
183 281 }
184 -endif;
282 +endif;