| @@ -32,15 +32,13 @@ | ||
| 32 | 32 | } |
| 33 | 33 | define('CODE_PROFILER_LOG', CODE_PROFILER_UPLOAD_DIR .'/log.php'); |
| 34 | 34 | define('CODE_PROFILER_TMP_IOSTATS_LOG', 'iostats.tmp'); |
| 35 | 35 | define('CODE_PROFILER_TMP_SUMMARY_LOG', 'summary.tmp'); |
| 36 | -define('CODE_PROFILER_TMP_RERUN_LOG', 'rerun.tmp'); | |
| 37 | 36 | define('CODE_PROFILER_TMP_CALLS_LOG', 'calls.tmp'); |
| 38 | 37 | define('CODE_PROFILER_TMP_DISKIO_LOG', 'diskio.tmp'); |
| 39 | 38 | define('CODE_PROFILER_TMP_CONNECTIONS_LOG', 'connections.tmp'); |
| 40 | 39 | define('CODE_PROFILER_UPDATE_NOTICE', '<div class="updated notice is-dismissible"><p>%s</p></div>'); |
| 41 | 40 | define('CODE_PROFILER_ERROR_NOTICE', '<div class="error notice is-dismissible"><p>%s</p></div>'); |
| 42 | -define('CODE_PROFILER_WARNING_NOTICE', '<div class="notice notice-warning"><p>%s</p></div>'); | |
| 43 | 41 | if (! defined('CODE_PROFILER_MUPLUGIN') ) { |
| 44 | 42 | // MU plugin's name can be defined in the wp-config.php |
| 45 | 43 | define('CODE_PROFILER_MUPLUGIN', '0----code-profiler.php'); |
| 46 | 44 | } |
| @@ -54,21 +52,21 @@ | ||
| 54 | 52 | global $wp_version; |
| 55 | 53 | if (! defined('CODE_PROFILER_UA') ) { // UA signatures can be user-defined in the wp-config.php |
| 56 | 54 | define ('CODE_PROFILER_UA', [ |
| 57 | 55 | esc_html__('Desktop', 'code-profiler') => [ |
| 58 | - 'Firefox' => 'Mozilla/5.0 (Linux x86_64; rv:149.0) Gecko/20100101 Firefox/149.0', | |
| 56 | + 'Firefox' => 'Mozilla/5.0 (Linux x86_64; rv:135.0) Gecko/20100101 Firefox/135.0', | |
| 59 | 57 | 'Chrome' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,'. |
| 60 | - ' like Gecko) Chrome/147.0.0.0 Safari/537.36', | |
| 58 | + ' like Gecko) Chrome/133.0.0.0 Safari/537.36', | |
| 61 | 59 | 'Edge' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,'. |
| 62 | - ' like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/Chrome/147.0.7727.50' | |
| 60 | + ' like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/131.0.2903.86' | |
| 63 | 61 | ], |
| 64 | 62 | esc_html__('Mobile', 'code-profiler') => [ |
| 65 | - 'Android Phone' => 'Mozilla/5.0 (Android 16; Mobile; rv:68.0) Gecko/68.0 Firefox/149.0', | |
| 66 | - 'Android Tablet' => 'Mozilla/5.0 (Linux; Android 16.0; SAMSUNG-SM-T377A Build/NMF26X)'. | |
| 67 | - ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.7727.50 Mobile Safari/537.36', | |
| 68 | - 'iPhone' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15'. | |
| 69 | - ' (KHTML, like Gecko) Version/26.0 Mobile/15E148 Safari/604.1', | |
| 70 | - 'iPad' => 'Mozilla/5.0 (iPad; CPU OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15'. | |
| 63 | + 'Android Phone' => 'Mozilla/5.0 (Android 15; Mobile; rv:68.0) Gecko/68.0 Firefox/135.0', | |
| 64 | + 'Android Tablet' => 'Mozilla/5.0 (Linux; Android 15.0; SAMSUNG-SM-T377A Build/NMF26X)'. | |
| 65 | + ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Mobile Safari/537.36', | |
| 66 | + 'iPhone' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15'. | |
| 67 | + ' (KHTML, like Gecko) Version/17_7_2 Mobile/15E148 Safari/604.1', | |
| 68 | + 'iPad' => 'Mozilla/5.0 (iPad; CPU OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15'. | |
| 71 | 69 | ' (KHTML, like Gecko) GSA/213.0.449417121 Mobile/15E148 Safari/605.1.15' |
| 72 | 70 | ], |
| 73 | 71 | esc_html__('Bot', 'code-profiler') => [ |
| 74 | 72 | 'Google Bot' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', |
| @@ -129,123 +127,34 @@ | ||
| 129 | 127 | // Update version in the DB and check if options must be updated. |
| 130 | 128 | |
| 131 | 129 | function code_profiler_init_update() { |
| 132 | 130 | |
| 133 | - if ( ( $cp_options = get_option('code-profiler') ) == false ) { | |
| 134 | - /** | |
| 135 | - * "Automatic conversion of false to array is deprecated" since PHP 8.1 | |
| 136 | - */ | |
| 137 | - $cp_options = []; | |
| 138 | - } | |
| 131 | + $cp_options = get_option('code-profiler'); | |
| 132 | + if ( empty( $cp_options['version'] ) || | |
| 133 | + version_compare( $cp_options['version'], CODE_PROFILER_VERSION, '<') ) { | |
| 139 | 134 | |
| 140 | - if ( empty( $cp_options['version'] ) ) { | |
| 141 | 135 | $cp_options['version'] = CODE_PROFILER_VERSION; |
| 142 | - update_option('code-profiler', $cp_options ); | |
| 143 | 136 | |
| 144 | - } elseif ( version_compare( $cp_options['version'], CODE_PROFILER_VERSION, '<') ) { | |
| 145 | - | |
| 146 | 137 | // Version 1.1 |
| 147 | - if ( version_compare( $cp_options['version'], '1.1', '<' ) ) { | |
| 148 | - if (! isset( $cp_options['enable_wpcli'] ) ) { | |
| 149 | - $cp_options['enable_wpcli'] = 1; | |
| 150 | - } | |
| 138 | + if (! isset( $cp_options['enable_wpcli'] ) ) { | |
| 139 | + $cp_options['enable_wpcli'] = 1; | |
| 151 | 140 | } |
| 152 | 141 | |
| 153 | 142 | // Version 1.2 |
| 154 | - if ( version_compare( $cp_options['version'], '1.2', '<' ) ) { | |
| 155 | - if (! isset( $cp_options['disable_wpcron'] ) ) { | |
| 156 | - $cp_options['disable_wpcron'] = 1; | |
| 157 | - } | |
| 143 | + if (! isset( $cp_options['disable_wpcron'] ) ) { | |
| 144 | + $cp_options['disable_wpcron'] = 1; | |
| 158 | 145 | } |
| 159 | 146 | |
| 160 | 147 | // Version 1.3.1 |
| 161 | - if ( version_compare( $cp_options['version'], '1.3.1', '<' ) ) { | |
| 162 | - if (! isset( $cp_options['http_response'] ) ) { | |
| 163 | - $cp_options['http_response'] = '^(?:3|4|5)\d{2}$'; | |
| 164 | - } | |
| 148 | + if (! isset( $cp_options['http_response'] ) ) { | |
| 149 | + $cp_options['http_response'] = '^(?:3|4|5)\d{2}$'; | |
| 165 | 150 | } |
| 166 | 151 | |
| 167 | 152 | // Version 1.5 |
| 168 | - if ( version_compare( $cp_options['version'], '1.5', '<' ) ) { | |
| 169 | - if (! isset( $cp_options['accuracy'] ) ) { | |
| 170 | - $cp_options['accuracy'] = 1; | |
| 171 | - } | |
| 153 | + if (! isset( $cp_options['accuracy'] ) ) { | |
| 154 | + $cp_options['accuracy'] = 1; | |
| 172 | 155 | } |
| 173 | 156 | |
| 174 | - // Version 1.7.5 | |
| 175 | - if ( version_compare( $cp_options['version'], '1.7.5', '<' ) ) { | |
| 176 | - if (! isset( $cp_options['php_error'] ) ) { | |
| 177 | - $cp_options['php_error'] = 1; | |
| 178 | - } | |
| 179 | - } | |
| 180 | - | |
| 181 | - // Version 1.8 | |
| 182 | - if ( version_compare( $cp_options['version'], '1.8', '<' ) ) { | |
| 183 | - if ( isset( $cp_options['mem_where'] ) ) { | |
| 184 | - $cp_options['mem']['x_end'] = $cp_options['mem_where']; | |
| 185 | - unset( $cp_options['mem_where'] ); | |
| 186 | - } | |
| 187 | - if ( isset( $cp_options['mem_post'] ) ) { | |
| 188 | - $cp_options['mem']['post'] = $cp_options['mem_post']; | |
| 189 | - unset( $cp_options['mem_post'] ); | |
| 190 | - } | |
| 191 | - if ( isset( $cp_options['mem_user'] ) ) { | |
| 192 | - $cp_options['mem']['x_auth'] = $cp_options['mem_user']; | |
| 193 | - unset( $cp_options['mem_user'] ); | |
| 194 | - } | |
| 195 | - if ( isset( $cp_options['mem_username'] ) ) { | |
| 196 | - $cp_options['mem']['username'] = $cp_options['mem_username']; | |
| 197 | - unset( $cp_options['mem_username'] ); | |
| 198 | - } | |
| 199 | - if ( isset( $cp_options['mem_method'] ) ) { | |
| 200 | - $cp_options['mem']['method'] = $cp_options['mem_method']; | |
| 201 | - unset( $cp_options['mem_method'] ); | |
| 202 | - } | |
| 203 | - if ( isset( $cp_options['mem_theme'] ) ) { | |
| 204 | - $cp_options['mem']['theme'] = $cp_options['mem_theme']; | |
| 205 | - unset( $cp_options['mem_theme'] ); | |
| 206 | - } | |
| 207 | - if ( isset( $cp_options['ua'] ) ) { | |
| 208 | - $cp_options['mem']['user_agent'] = $cp_options['ua']; | |
| 209 | - unset( $cp_options['ua'] ); | |
| 210 | - } | |
| 211 | - if ( isset( $cp_options['cookies'] ) ) { | |
| 212 | - $cp_options['mem']['cookies'] = $cp_options['cookies']; | |
| 213 | - unset( $cp_options['cookies'] ); | |
| 214 | - } | |
| 215 | - if ( isset( $cp_options['mem_content_type'] ) ) { | |
| 216 | - $cp_options['mem']['content_type'] = $cp_options['mem_content_type']; | |
| 217 | - unset( $cp_options['mem_content_type'] ); | |
| 218 | - } | |
| 219 | - if ( isset( $cp_options['payload'] ) ) { | |
| 220 | - $cp_options['mem']['payload'] = $cp_options['payload']; | |
| 221 | - unset( $cp_options['payload'] ); | |
| 222 | - } | |
| 223 | - if ( isset( $cp_options['custom_headers'] ) ) { | |
| 224 | - $cp_options['mem']['custom_headers'] = $cp_options['custom_headers']; | |
| 225 | - unset( $cp_options['custom_headers'] ); | |
| 226 | - } | |
| 227 | - if ( isset( $cp_options['exclusions'] ) ) { | |
| 228 | - $cp_options['mem']['exclusions'] = $cp_options['exclusions']; | |
| 229 | - unset( $cp_options['exclusions'] ); | |
| 230 | - } | |
| 231 | - } | |
| 232 | - | |
| 233 | - // Version 1.8.1 | |
| 234 | - if ( version_compare( $cp_options['version'], '1.8.1', '<' ) ) { | |
| 235 | - CodeProfiler_WPCron::install(); | |
| 236 | - } | |
| 237 | - | |
| 238 | - /** | |
| 239 | - * Version 1.9.2 | |
| 240 | - */ | |
| 241 | - if ( version_compare( $cp_options['version'], '1.9.2', '<' ) ) { | |
| 242 | - unset( $cp_options['warn_composer'] ); | |
| 243 | - } | |
| 244 | - | |
| 245 | - // Adjust current version | |
| 246 | - $cp_options['version'] = CODE_PROFILER_VERSION; | |
| 247 | - | |
| 248 | 157 | // Update version in the DB |
| 249 | 158 | update_option('code-profiler', $cp_options ); |
| 250 | 159 | } |
| 251 | 160 | |
| @@ -258,17 +167,13 @@ | ||
| 258 | 167 | |
| 259 | 168 | function code_profiler_check_uploadsdir() { |
| 260 | 169 | |
| 261 | 170 | if (! file_exists( CODE_PROFILER_UPLOAD_DIR ) ) { |
| 262 | - wp_mkdir_p( CODE_PROFILER_UPLOAD_DIR ); | |
| 171 | + mkdir( CODE_PROFILER_UPLOAD_DIR, 0755 ); | |
| 263 | 172 | } |
| 264 | - if (! is_writable( CODE_PROFILER_UPLOAD_DIR ) || ! is_dir( CODE_PROFILER_UPLOAD_DIR ) ) { | |
| 265 | - wp_die( | |
| 266 | - sprintf( | |
| 267 | - __('Error: The %s folder cannot be created or is read only', 'code-profiler'), | |
| 268 | - esc_html( CODE_PROFILER_UPLOAD_DIR ) .'/' | |
| 269 | - ) | |
| 270 | - ); | |
| 173 | + if (! is_writable( CODE_PROFILER_UPLOAD_DIR ) ) { | |
| 174 | + // PHP running as an Apache module? | |
| 175 | + chmod( CODE_PROFILER_UPLOAD_DIR, 0777 ); | |
| 271 | 176 | } |
| 272 | 177 | if (! file_exists( CODE_PROFILER_UPLOAD_DIR .'/index.html') ) { |
| 273 | 178 | touch( CODE_PROFILER_UPLOAD_DIR .'/index.html'); |
| 274 | 179 | } |
| @@ -383,8 +288,9 @@ | ||
| 383 | 288 | 'chart_type' => 'x', |
| 384 | 289 | 'chart_max_plugins' => 25, |
| 385 | 290 | 'hide_empty_value' => 1, |
| 386 | 291 | 'table_max_rows' => 30, |
| 292 | + 'warn_composer' => 1, | |
| 387 | 293 | 'enable_wpcli' => 1, |
| 388 | 294 | 'disable_wpcron' => 1, |
| 389 | 295 | 'http_response' => '^(?:3|4|5)\d{2}$', |
| 390 | 296 | 'accuracy' => 1, |
| @@ -428,28 +334,13 @@ | ||
| 428 | 334 | |
| 429 | 335 | } catch ( Exception $e ) { } |
| 430 | 336 | |
| 431 | 337 | $cp_options = get_option('code-profiler'); |
| 432 | - /** | |
| 433 | - * Disable WP-CRON. | |
| 434 | - */ | |
| 435 | 338 | if (! empty( $cp_options['disable_wpcron'] ) ) { |
| 436 | 339 | if (! defined('DISABLE_WP_CRON') ) { |
| 437 | 340 | define('DISABLE_WP_CRON', true ); |
| 438 | 341 | } |
| 439 | 342 | } |
| 440 | - /** | |
| 441 | - * Enable PHP error logging. | |
| 442 | - */ | |
| 443 | - if (! empty( $cp_options['php_error'] ) ) { | |
| 444 | - ini_set('log_errors', 1 ); | |
| 445 | - $phplog = ini_get('error_log'); | |
| 446 | - if ( empty( $phplog ) || $phplog === false ) { | |
| 447 | - ini_set('error_log', WP_CONTENT_DIR .'/debug.log'); | |
| 448 | - } else { | |
| 449 | - ini_set('error_log', $phplog ); | |
| 450 | - } | |
| 451 | - } | |
| 452 | 343 | } |
| 453 | 344 | |
| 454 | 345 | // ===================================================================== |
| 455 | 346 | // Verify the security key when running the profiler. |
| @@ -457,10 +348,10 @@ | ||
| 457 | 348 | function code_profiler_verify_key() { |
| 458 | 349 | |
| 459 | 350 | $response = [ |
| 460 | 351 | 'status' => 'error', |
| 461 | - // We cannot load translation here. | |
| 462 | - 'message' => 'Security keys do not match. Reload the page and try again (%s)' | |
| 352 | + 'message' => __('Security keys do not match. Reload the page and try again (%s)', | |
| 353 | + 'code-profiler') | |
| 463 | 354 | ]; |
| 464 | 355 | |
| 465 | 356 | if ( empty( $_REQUEST['profiler_key'] ) ) { |
| 466 | 357 | $response['message'] = sprintf( $response['message'], '001'); |
| @@ -467,18 +358,8 @@ | ||
| 467 | 358 | |
| 468 | 359 | } else { |
| 469 | 360 | $file = CODE_PROFILER_UPLOAD_DIR .'/key_'. sha1( $_REQUEST['profiler_key'] ) .'.tmp'; |
| 470 | 361 | if ( file_exists( $file ) ) { |
| 471 | - /** | |
| 472 | - * We limit the TTL to max $expire seconds to match code_profiler_cleantmpfiles(). | |
| 473 | - */ | |
| 474 | - $now = time(); | |
| 475 | - $expire = 20; // seconds | |
| 476 | - if ( filemtime( $file ) + $expire < $now ) { | |
| 477 | - $response['message'] = sprintf( $response['message'], '003'); | |
| 478 | - wp_send_json( $response ); | |
| 479 | - } | |
| 480 | - | |
| 481 | 362 | // Delete it and accept the request |
| 482 | 363 | unlink( $file ); |
| 483 | 364 | return; |
| 484 | 365 | } |
| @@ -484,8 +365,9 @@ | ||
| 484 | 365 | } |
| 485 | 366 | $response['message'] = sprintf( $response['message'], '002'); |
| 486 | 367 | } |
| 487 | 368 | wp_send_json( $response ); |
| 369 | + | |
| 488 | 370 | } |
| 489 | 371 | |
| 490 | 372 | // ===================================================================== |
| 491 | 373 | // Write message to the log. |
| @@ -726,28 +608,9 @@ | ||
| 726 | 608 | |
| 727 | 609 | $glob = code_profiler_glob( CODE_PROFILER_UPLOAD_DIR, '\.tmp$', true ); |
| 728 | 610 | |
| 729 | 611 | if ( is_array( $glob ) ) { |
| 730 | - | |
| 731 | - $now = time(); | |
| 732 | 612 | foreach( $glob as $file ) { |
| 733 | - /** | |
| 734 | - * Temporary files deletion: | |
| 735 | - * - +20 seconds for temp sessions (to match the TTL checked at runtime). | |
| 736 | - * - +10 minutes for unmatched temp profiles. | |
| 737 | - */ | |
| 738 | - if ( strpos( $file, CODE_PROFILER_UPLOAD_DIR .'/key_') === 0 ) { | |
| 739 | - if ( filemtime( $file ) + 20 > $now ) { | |
| 740 | - continue; | |
| 741 | - } | |
| 742 | - } else { | |
| 743 | - if ( filemtime( $file ) + 60 * 10 > $now ) { | |
| 744 | - continue; | |
| 745 | - } | |
| 746 | - } | |
| 747 | - /** | |
| 748 | - * Delete all temp files. | |
| 749 | - */ | |
| 750 | 613 | unlink( $file ); |
| 751 | 614 | } |
| 752 | 615 | } |
| 753 | 616 | } |
| @@ -796,17 +659,14 @@ | ||
| 796 | 659 | ). |
| 797 | 660 | '</span>'; |
| 798 | 661 | } |
| 799 | 662 | |
| 800 | - | |
| 801 | 663 | // ===================================================================== |
| 802 | -// Hide/display an element depending on some value. | |
| 664 | +// Display/hide an element depending on some value | |
| 803 | 665 | |
| 804 | -function code_profiler_showhide( $var, $val ) { | |
| 666 | +function code_profiler_hide( $var, $val ) { | |
| 805 | 667 | |
| 806 | 668 | if ( $var == $val ) { |
| 807 | - echo " style='display:block'"; | |
| 808 | - } else { | |
| 809 | 669 | echo " style='display:none'"; |
| 810 | 670 | } |
| 811 | 671 | } |
| 812 | 672 | |
| @@ -836,64 +696,8 @@ | ||
| 836 | 696 | ]; |
| 837 | 697 | } |
| 838 | 698 | } |
| 839 | 699 | return $list; |
| 840 | -} | |
| 841 | - | |
| 842 | -// ===================================================================== | |
| 843 | -// Retrieve all available cron events. | |
| 844 | - | |
| 845 | -function code_profiler_get_crons() { | |
| 846 | - | |
| 847 | - $list = []; | |
| 848 | - | |
| 849 | - $wp_crons = _get_cron_array(); | |
| 850 | - | |
| 851 | - if ( empty( $wp_crons ) ) { | |
| 852 | - return $list; | |
| 853 | - } | |
| 854 | - | |
| 855 | - foreach ( $wp_crons as $timestamp => $cronhooks ) { | |
| 856 | - foreach ( $cronhooks as $hook => $keys ) { | |
| 857 | - $list[] = $hook; | |
| 858 | - } | |
| 859 | - } | |
| 860 | - sort( $list ); | |
| 861 | - return $list; | |
| 862 | -} | |
| 863 | - | |
| 864 | -// ===================================================================== | |
| 865 | -// Create a file with the ABSPATH. | |
| 866 | - | |
| 867 | -function code_profiler_create_tmpfile() { | |
| 868 | - | |
| 869 | - $tmp_folder = dirname( __DIR__ ) .'/tmp'; | |
| 870 | - $tmp_file = "$tmp_folder/profiler.inc.php"; | |
| 871 | - | |
| 872 | - if (! is_dir( $tmp_folder ) ) { | |
| 873 | - $res = @ mkdir( $tmp_folder ); | |
| 874 | - if ( false === $res ) { | |
| 875 | - return sprintf( | |
| 876 | - __('Cannot create temporary folder: [%s]. Any attempt to profile a cron event will likely fail.', 'code-profiler'), | |
| 877 | - $tmp_folder | |
| 878 | - ); | |
| 879 | - } | |
| 880 | - } | |
| 881 | - | |
| 882 | - if (! is_file( "$tmp_folder/index.html" ) ) { | |
| 883 | - touch( "$tmp_folder/index.html" ); | |
| 884 | - } | |
| 885 | - | |
| 886 | - $res = @ file_put_contents( | |
| 887 | - $tmp_file, | |
| 888 | - "<?php\nconst ABSPATH = '". ABSPATH ."';\n" | |
| 889 | - ); | |
| 890 | - if ( false === $res ) { | |
| 891 | - return sprintf( | |
| 892 | - __('Cannot create temporary file: [%s]. Any attempt to profile a cron event will likely fail.', 'code-profiler'), | |
| 893 | - $tmp_file | |
| 894 | - ); | |
| 895 | - } | |
| 896 | 700 | } |
| 897 | 701 | |
| 898 | 702 | // ===================================================================== |
| 899 | 703 | // EOF |