Skip to content

Instantly share code, notes, and snippets.

@jordantrizz
Created February 16, 2021 20:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordantrizz/d636803b33d9fa4f2ede0cee5968d73a to your computer and use it in GitHub Desktop.
Save jordantrizz/d636803b33d9fa4f2ede0cee5968d73a to your computer and use it in GitHub Desktop.
SQL Truncate on Log Table within cleantalk-spam-protect/lib/Cleantalk/ApbctWP/Firewall/SFW.php
300 /**
301 * Sends and wipe SFW log
302 *
303 * @param $db
304 * @param $log_table
305 * @param string $ct_key API key
306 *
307 * @return array|bool array('error' => STRING)
308 */
309 public static function send_log( $db, $log_table, $ct_key ) {
310
311 //Getting logs
312 $query = "SELECT * FROM " . $log_table . ";";
313 $db->fetch_all( $query );
314
315 if( count( $db->result ) ){
316
317 //Compile logs
318 $data = array();
319 foreach( $db->result as $key => $value ){
320
321 // Converting statuses to API format
322 $value['status'] = $value['status'] === 'DENY_ANTICRAWLER' ? 'BOT_PROTECTION' : $value['status'];
323 $value['status'] = $value['status'] === 'PASS_ANTICRAWLER' ? 'BOT_PROTECTION' : $value['status'];
324 $value['status'] = $value['status'] === 'DENY_ANTICRAWLER_UA' ? 'BOT_PROTECTION' : $value['status'];
325 $value['status'] = $value['status'] === 'PASS_ANTICRAWLER_UA' ? 'BOT_PROTECTION' : $value['status'];
326
327 $value['status'] = $value['status'] === 'DENY_ANTIFLOOD' ? 'FLOOD_PROTECTION' : $value['status'];
328 $value['status'] = $value['status'] === 'PASS_ANTIFLOOD' ? 'FLOOD_PROTECTION' : $value['status'];
329
330 $value['status'] = $value['status'] === 'PASS_SFW__BY_COOKIE' ? null : $value['status'];
331 $value['status'] = $value['status'] === 'PASS_SFW' ? null : $value['status'];
332 $value['status'] = $value['status'] === 'DENY_SFW' ? null : $value['status'];
333
334 $data[] = array(
335 trim( $value['ip'] ), // IP
336 $value['blocked_entries'], // Count showing of block pages
337 $value['all_entries'] - $value['blocked_entries'], // Count passed requests after block pages
338 $value['entries_timestamp'], // Last timestamp
339 $value['status'], // Status
340 $value['ua_name'], // User-Agent name
341 $value['ua_id'], // User-Agent ID
342 );
343
344 }
345 unset( $key, $value );
346
347 //Sending the request
348 $result = API::method__sfw_logs( $ct_key, $data );
349 //Checking answer and deleting all lines from the table
350 if( empty( $result['error'] ) ){
351 if( $result['rows'] == count( $data ) ){
352 $db->execute( "TRUNCATE TABLE " . $log_table . ";" );
353
354 return $result;
355 }
356
357 return array( 'error' => 'SENT_AND_RECEIVED_LOGS_COUNT_DOESNT_MACH' );
358 } else{
359 return $result;
360 }
361
362 } else{
363 return $result = array( 'rows' => 0 );
364 }
365 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment