| @@ -8,8 +8,12 @@ | ||
| 8 | 8 | Text Domain: really-simple-captcha |
| 9 | 9 | Version: 1.9 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 13 | + exit; // Exit if accessed directly. | |
| 14 | +} | |
| 15 | + | |
| 12 | 16 | /* Copyright 2007-2016 Takayuki Miyoshi (email: takayukister at gmail.com) |
| 13 | 17 | |
| 14 | 18 | This program is free software; you can redistribute it and/or modify |
| 15 | 19 | it under the terms of the GNU General Public License as published by |
| @@ -70,9 +74,9 @@ | ||
| 70 | 74 | |
| 71 | 75 | /* Foreground (character) color of CAPTCHA image. RGB color 0-255 */ |
| 72 | 76 | $this->fg = array( 0, 0, 0 ); |
| 73 | 77 | |
| 74 | - //FixIn: 10.0.0.54 | |
| 78 | + // FixIn: 10.0.0.54. | |
| 75 | 79 | if ( ( function_exists( 'get_bk_option' ) ) && ( 'wpbc_theme_dark_1' === get_bk_option( 'booking_form_theme' ) ) ) { |
| 76 | 80 | $this->bg = array( 39, 39, 39 ); |
| 77 | 81 | $this->fg = array( 255, 255, 255 ); |
| 78 | 82 | } |
| @@ -104,9 +108,9 @@ | ||
| 104 | 108 | public function generate_random_word() { |
| 105 | 109 | $word = ''; |
| 106 | 110 | |
| 107 | 111 | for ( $i = 0; $i < $this->char_length; $i++ ) { |
| 108 | - $pos = mt_rand( 0, strlen( $this->chars ) - 1 ); | |
| 112 | + $pos = wp_rand( 0, strlen( $this->chars ) - 1 ); | |
| 109 | 113 | $char = $this->chars[$pos]; |
| 110 | 114 | $word .= $char; |
| 111 | 115 | } |
| 112 | 116 | |
| @@ -135,17 +139,16 @@ | ||
| 135 | 139 | $bg = imagecolorallocate( $im, $this->bg[0], $this->bg[1], $this->bg[2] ); |
| 136 | 140 | $fg = imagecolorallocate( $im, $this->fg[0], $this->fg[1], $this->fg[2] ); |
| 137 | 141 | |
| 138 | 142 | imagefill( $im, 0, 0, $bg ); |
| 139 | - | |
| 143 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.rand_mt_rand | |
| 140 | 144 | $x = $this->base[0] + mt_rand( -2, 2 ); |
| 141 | 145 | |
| 142 | 146 | for ( $i = 0; $i < strlen( $word ); $i++ ) { |
| 143 | 147 | $font = $this->fonts[array_rand( $this->fonts )]; |
| 144 | 148 | $font = $this->normalize_path( $font ); |
| 145 | - | |
| 146 | - imagettftext( $im, $this->font_size, mt_rand( -12, 12 ), $x, | |
| 147 | - $this->base[1] + mt_rand( -2, 2 ), $fg, $font, $word[$i] ); | |
| 149 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.rand_mt_rand | |
| 150 | + imagettftext( $im, $this->font_size, mt_rand( -12, 12 ), $x, $this->base[1] + mt_rand( -2, 2 ), $fg, $font, $word[$i] ); | |
| 148 | 151 | $x += $this->font_char_width; |
| 149 | 152 | } |
| 150 | 153 | |
| 151 | 154 | switch ( $this->img_type ) { |
| @@ -166,8 +169,9 @@ | ||
| 166 | 169 | imagepng( $im, $file ); |
| 167 | 170 | } |
| 168 | 171 | |
| 169 | 172 | imagedestroy( $im ); |
| 173 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_chmod | |
| 170 | 174 | @chmod( $file, $this->file_mode ); |
| 171 | 175 | } |
| 172 | 176 | |
| 173 | 177 | $this->generate_answer_file( $prefix, $word ); |
| @@ -184,9 +188,9 @@ | ||
| 184 | 188 | public function generate_answer_file( $prefix, $word ) { |
| 185 | 189 | $dir = trailingslashit( $this->tmp_dir ); |
| 186 | 190 | $answer_file = $dir . sanitize_file_name( $prefix . '.txt' ); |
| 187 | 191 | $answer_file = $this->normalize_path( $answer_file ); |
| 188 | - | |
| 192 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen | |
| 189 | 193 | if ( $fh = @fopen( $answer_file, 'w' ) ) { |
| 190 | 194 | $word = strtoupper( $word ); |
| 191 | 195 | $salt = wp_generate_password( 64 ); |
| 192 | 196 | $hash = hash_hmac( 'md5', $word, $salt ); |
| @@ -191,13 +195,14 @@ | ||
| 191 | 195 | $salt = wp_generate_password( 64 ); |
| 192 | 196 | $hash = hash_hmac( 'md5', $word, $salt ); |
| 193 | 197 | |
| 194 | 198 | $code = $salt . '|' . $hash; |
| 195 | - | |
| 199 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 196 | 200 | fwrite( $fh, $code ); |
| 201 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose | |
| 197 | 202 | fclose( $fh ); |
| 198 | 203 | } |
| 199 | - | |
| 204 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_chmod | |
| 200 | 205 | @chmod( $answer_file, $this->answer_file_mode ); |
| 201 | 206 | } |
| 202 | 207 | |
| 203 | 208 | /** |
| @@ -217,9 +222,9 @@ | ||
| 217 | 222 | |
| 218 | 223 | $dir = trailingslashit( $this->tmp_dir ); |
| 219 | 224 | $filename = sanitize_file_name( $prefix . '.txt' ); |
| 220 | 225 | $file = $this->normalize_path( $dir . $filename ); |
| 221 | - | |
| 226 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | |
| 222 | 227 | if ( @is_readable( $file ) && ( $code = file_get_contents( $file ) ) ) { |
| 223 | 228 | $code = explode( '|', $code, 2 ); |
| 224 | 229 | |
| 225 | 230 | $salt = $code[0]; |
| @@ -246,9 +251,10 @@ | ||
| 246 | 251 | $filename = sanitize_file_name( $prefix . $suffix ); |
| 247 | 252 | $file = $this->normalize_path( $dir . $filename ); |
| 248 | 253 | |
| 249 | 254 | if ( @is_file( $file ) ) { |
| 250 | - @unlink( $file ); | |
| 255 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink | |
| 256 | + @wp_delete_file( $file ); | |
| 251 | 257 | } |
| 252 | 258 | } |
| 253 | 259 | } |
| 254 | 260 | |
| @@ -266,9 +272,9 @@ | ||
| 266 | 272 | return false; |
| 267 | 273 | } |
| 268 | 274 | |
| 269 | 275 | $is_win = ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ); |
| 270 | - | |
| 276 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_is_writable | |
| 271 | 277 | if ( ! ( $is_win ? win_is_writable( $dir ) : @is_writable( $dir ) ) ) { |
| 272 | 278 | return false; |
| 273 | 279 | } |
| 274 | 280 | |
| @@ -282,12 +288,20 @@ | ||
| 282 | 288 | |
| 283 | 289 | $file = $this->normalize_path( $dir . $filename ); |
| 284 | 290 | |
| 285 | 291 | $stat = @stat( $file ); |
| 292 | + if ( false === $stat || ! isset( $stat['mtime'] ) ) { | |
| 293 | + // A concurrent CAPTCHA cleanup can remove the file after readdir(). | |
| 294 | + continue; | |
| 295 | + } | |
| 296 | + | |
| 286 | 297 | if ( ( $stat['mtime'] + $minutes * 60 ) < time() ) { |
| 287 | - if ( ! @unlink( $file ) ) { | |
| 298 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink | |
| 299 | + if ( ! @wp_delete_file( $file ) ) { | |
| 300 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_chmod | |
| 288 | 301 | @chmod( $file, 0644 ); |
| 289 | - @unlink( $file ); | |
| 302 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink | |
| 303 | + @wp_delete_file( $file ); | |
| 290 | 304 | } |
| 291 | 305 | |
| 292 | 306 | $count += 1; |
| 293 | 307 | } |
| @@ -322,27 +336,44 @@ | ||
| 322 | 336 | return true; |
| 323 | 337 | } |
| 324 | 338 | |
| 325 | 339 | // FixIn: 8.7.7.5 |
| 340 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen | |
| 326 | 341 | if ( $handle = @fopen( $htaccess_file, 'w' ) ) { |
| 327 | 342 | |
| 343 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 328 | 344 | fwrite( $handle, '# apache 2.2' . "\n" ); |
| 345 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 329 | 346 | fwrite( $handle, '<IfModule !mod_authz_core.c>' . "\n" ); |
| 347 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 330 | 348 | fwrite( $handle, ' Order deny,allow' . "\n" ); |
| 349 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 331 | 350 | fwrite( $handle, ' Deny from all' . "\n" ); |
| 351 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 332 | 352 | fwrite( $handle, ' <Files ~ "^[0-9A-Za-z]+\.(jpeg|gif|png)$">' . "\n" ); |
| 353 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 333 | 354 | fwrite( $handle, ' Allow from all' . "\n" ); |
| 355 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 334 | 356 | fwrite( $handle, ' </Files>' . "\n" ); |
| 357 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 335 | 358 | fwrite( $handle, '</IfModule>' . "\n" ); |
| 336 | 359 | |
| 360 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 337 | 361 | fwrite( $handle, '# apache 2.4' . "\n" ); |
| 362 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 338 | 363 | fwrite( $handle, '<IfModule mod_authz_core.c>' . "\n" ); |
| 364 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 339 | 365 | fwrite( $handle, ' Require all denied' . "\n" ); |
| 366 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 340 | 367 | fwrite( $handle, ' <Files ~ "^[0-9A-Za-z]+\.(jpeg|gif|png)$">' . "\n" ); |
| 368 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 341 | 369 | fwrite( $handle, ' Require all granted' . "\n" ); |
| 370 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 342 | 371 | fwrite( $handle, ' </Files>' . "\n" ); |
| 372 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 343 | 373 | fwrite( $handle, '</IfModule>' . "\n" ); |
| 344 | 374 | |
| 375 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose | |
| 345 | 376 | fclose( $handle ); |
| 346 | 377 | } |
| 347 | 378 | |
| 348 | 379 | /* |
| @@ -398,5 +429,5 @@ | ||
| 398 | 429 | $path = str_replace( '\\', '/', $path ); |
| 399 | 430 | $path = preg_replace( '|/+|', '/', $path ); |
| 400 | 431 | return $path; |
| 401 | 432 | } |
| 402 | -} | |
| 433 | +} | |