Skip to content

Commit 9854bbb

Browse files
safroniksafronik
authored andcommitted
Fix: Parsing and compiling CSV with Firewall and BFP log.
1 parent d0cd23e commit 9854bbb

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

uniforce/lib/Cleantalk/USP/Uniforce/Firewall/BFP.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ public static function update_log( $fw_result ) {
203203
isset($log[8]) ? intval( $log[8] ) + 1 : 1,
204204
);
205205

206-
file_put_contents( $log_path, implode(',', $log), LOCK_EX );
206+
$fd = fopen( $log_path, 'w' );
207+
flock( $fd, LOCK_EX );
208+
fputcsv( $fd, $log );
209+
fclose( $fd );
207210

208211
}
209212

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

230233
foreach( $log_files as $log_file ){
234+
231235
$log = file_get_contents( $log_dir_path . DS . $log_file );
232-
$log = explode( ',', $log );
236+
$log = str_getcsv( $log );
233237

234238
if( strval( $log[8] ) > 0 ){
235239
for( $i = 0; strval( $log[8] ) > $i; $i ++ ){

uniforce/lib/Cleantalk/USP/Uniforce/Firewall/FW.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public static function send_log( $ct_key ){
164164
foreach ( $log_files as $log_file ){
165165

166166
$log = file_get_contents( $log_dir_path . DS . $log_file );
167-
$log = explode( ',', $log );
167+
$log = str_getcsv( $log );
168168

169169
//Compile log
170170
$to_data = array(

uniforce/lib/Cleantalk/USP/Uniforce/Firewall/FirewallModule.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function update_log( $fw_result ){
7373
if( file_exists( $log_path ) ){
7474

7575
$log = file_get_contents($log_path);
76-
$log = explode(',', $log);
76+
$log = str_getcsv( $log );
7777

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

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

108108
}
109109

110-
file_put_contents( $log_path, implode(',', $log), LOCK_EX );
110+
$fd = fopen( $log_path, 'w' );
111+
flock( $fd, LOCK_EX );
112+
fputcsv( $fd, $log );
113+
fclose( $fd );
111114
}
112115

113116
/**

0 commit comments

Comments
 (0)