Skip to content

Commit

Permalink
Fix: Parsing and compiling CSV with Firewall and BFP log.
Browse files Browse the repository at this point in the history
  • Loading branch information
safronik authored and safronik committed Jan 11, 2021
1 parent d0cd23e commit 9854bbb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions uniforce/lib/Cleantalk/USP/Uniforce/Firewall/BFP.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ public static function update_log( $fw_result ) {
isset($log[8]) ? intval( $log[8] ) + 1 : 1,
);

file_put_contents( $log_path, implode(',', $log), LOCK_EX );
$fd = fopen( $log_path, 'w' );
flock( $fd, LOCK_EX );
fputcsv( $fd, $log );
fclose( $fd );

}

Expand All @@ -228,8 +231,9 @@ public static function send_log( $ct_key ){
$data = array();

foreach( $log_files as $log_file ){

$log = file_get_contents( $log_dir_path . DS . $log_file );
$log = explode( ',', $log );
$log = str_getcsv( $log );

if( strval( $log[8] ) > 0 ){
for( $i = 0; strval( $log[8] ) > $i; $i ++ ){
Expand Down
2 changes: 1 addition & 1 deletion uniforce/lib/Cleantalk/USP/Uniforce/Firewall/FW.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static function send_log( $ct_key ){
foreach ( $log_files as $log_file ){

$log = file_get_contents( $log_dir_path . DS . $log_file );
$log = explode( ',', $log );
$log = str_getcsv( $log );

//Compile log
$to_data = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function update_log( $fw_result ){
if( file_exists( $log_path ) ){

$log = file_get_contents($log_path);
$log = explode(',', $log);
$log = str_getcsv( $log );

$all_entries = isset($log[5]) ? $log[5] : 0;

Expand Down Expand Up @@ -107,7 +107,10 @@ public static function update_log( $fw_result ){

}

file_put_contents( $log_path, implode(',', $log), LOCK_EX );
$fd = fopen( $log_path, 'w' );
flock( $fd, LOCK_EX );
fputcsv( $fd, $log );
fclose( $fd );
}

/**
Expand Down

0 comments on commit 9854bbb

Please sign in to comment.