Changeset 3492575
- Timestamp:
- 03/27/2026 11:10:14 AM (30 hours ago)
- Location:
- tnc-toolbox
- Files:
-
- 21 added
- 5 edited
-
tags/2.1.4 (added)
-
tags/2.1.4/assets (added)
-
tags/2.1.4/assets/index.php (added)
-
tags/2.1.4/assets/styles-config.css (added)
-
tags/2.1.4/assets/tnc-icon-light.png (added)
-
tags/2.1.4/core (added)
-
tags/2.1.4/core/core.php (added)
-
tags/2.1.4/core/index.php (added)
-
tags/2.1.4/core/settings.php (added)
-
tags/2.1.4/index.php (added)
-
tags/2.1.4/license.txt (added)
-
tags/2.1.4/locale (added)
-
tags/2.1.4/locale/index.php (added)
-
tags/2.1.4/readme.txt (added)
-
tags/2.1.4/tnc-toolbox.php (added)
-
tags/2.1.4/vendor (added)
-
tags/2.1.4/vendor/alerts-slack.php (added)
-
tags/2.1.4/vendor/cache-purge.php (added)
-
tags/2.1.4/vendor/cpanel-uapi.php (added)
-
tags/2.1.4/vendor/detection.php (added)
-
tags/2.1.4/vendor/index.php (added)
-
trunk/core/core.php (modified) (1 diff)
-
trunk/core/settings.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/tnc-toolbox.php (modified) (3 diffs)
-
trunk/vendor/detection.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tnc-toolbox/trunk/core/core.php
r3488521 r3492575 51 51 52 52 /** 53 * Auto-detect web stack and switch if necessary 54 * 55 * Only runs once per day to avoid repeated checks. 53 * Auto-detect web stack and correct if needed 54 * 55 * Only runs if the user has never explicitly saved a stack choice. 56 * Once the user saves settings, their choice is always respected. 57 * 58 * On plugin update to v2.1.3+, runs immediately to correct sites 59 * that were wrongly auto-switched to LiteSpeed by earlier detection. 56 60 */ 57 61 public function auto_detect_web_stack() { 58 // Only check once per day 59 $last_check = get_transient('tnc_web_stack_check'); 60 if ($last_check) { 61 return; 62 // Never override an explicit user choice 63 if (TNC_Detection::is_user_configured()) { 64 return; 65 } 66 67 // Run once immediately after update to fix wrongly-switched sites, 68 // then check once per day after that 69 $check_version = get_option('tnc_web_stack_check_version', ''); 70 if ($check_version !== TNCTOOLBOX_VERSION) { 71 // Version changed — run detection now and update marker 72 delete_transient('tnc_web_stack_check'); 73 update_option('tnc_web_stack_check_version', TNCTOOLBOX_VERSION); 74 } else { 75 $last_check = get_transient('tnc_web_stack_check'); 76 if ($last_check) { 77 return; 78 } 62 79 } 63 80 64 81 $result = TNC_Detection::auto_detect_and_switch_stack(); 65 82 if ($result) { 66 // Log the auto-switch67 83 if (defined('WP_DEBUG') && WP_DEBUG) { 68 84 error_log(sprintf( 69 'TNC Toolbox: Auto- switched web stack from %s to %s (detected: %s)',85 'TNC Toolbox: Auto-corrected web stack from %s to %s (detected: %s)', 70 86 $result['previous'], 71 87 $result['switched_to'], -
tnc-toolbox/trunk/core/settings.php
r3488521 r3492575 124 124 */ 125 125 private function save_settings() { 126 // Web stack selection 126 // Web stack selection - mark as explicit user choice 127 127 $web_stack = sanitize_text_field($_POST['tnc_web_stack'] ?? 'nginx'); 128 TNC_Detection::set_web_stack($web_stack );128 TNC_Detection::set_web_stack($web_stack, true); 129 129 130 130 // Sanitise inputs (always save these to preserve credentials) … … 187 187 $detected_server = TNC_Detection::detect_web_server(); 188 188 $is_litespeed = TNC_Detection::is_litespeed_stack(); 189 190 // Check for auto-detection mismatch and notify 189 $is_compatible = TNC_Detection::is_detection_compatible(); 190 191 // Only auto-switch on first run if user has never saved settings 191 192 $auto_switch = TNC_Detection::auto_detect_and_switch_stack(); 192 193 if ($auto_switch) { 193 $web_stack = $auto_switch['switched_to']; // Update for display194 $web_stack = $auto_switch['switched_to']; 194 195 $is_litespeed = true; 196 $is_compatible = true; 195 197 } 196 198 ?> … … 200 202 <p><strong>Configure your web stack settings. Supports ea-NGINX (cPanel) and LiteSpeed (OpenLiteSpeed/Enterprise).</strong><br> 201 203 <?php if ($detected_server): ?> 202 Detected server: <code><?php echo esc_html(ucfirst($detected_server)); ?></code> 204 Detected Server: <code><?php echo esc_html($detected_server); ?></code> 205 <?php if ($detected_server === 'apache' && $web_stack === 'nginx'): ?> 206 <em>(expected for ea-NGINX — PHP runs under Apache behind NGINX reverse proxy)</em> 207 <?php endif; ?> 203 208 <?php endif; ?> 204 209 </p> … … 207 212 <?php if ($auto_switch): ?> 208 213 <div class="notice notice-info is-dismissible"> 209 <p><strong>Web stack auto- switched!</strong> Detected LiteSpeed server but was configured for NGINX. Automatically switched to LiteSpeed stack. Your cPanel credentials are preserved if you need to switch back.</p>214 <p><strong>Web stack auto-detected!</strong> LiteSpeed server detected — configured for LiteSpeed stack. You can change this below if needed.</p> 210 215 </div> 211 216 <?php endif; ?> … … 232 237 </option> 233 238 </select> 234 <?php if ( $detected_server && $detected_server !== $web_stack): ?>239 <?php if (!$is_compatible): ?> 235 240 <p class="description" style="color: #d63638;"> 236 ⚠ Detected <strong><?php echo esc_html( ucfirst($detected_server)); ?></strong> but configured for <strong><?php echo esc_html(ucfirst($web_stack)); ?></strong>241 ⚠ Detected <strong><?php echo esc_html($detected_server); ?></strong> but configured for <strong><?php echo esc_html(TNC_Detection::get_stack_name($web_stack)); ?></strong>. Please verify your selection. 237 242 </p> 238 243 <?php endif; ?> -
tnc-toolbox/trunk/readme.txt
r3488521 r3492575 6 6 Tags: NGINX, LiteSpeed, Cache Purge, Web Performance, Automatic Purge, Freeware 7 7 Tested up to: 6.9 8 Stable tag: 2.1. 38 Stable tag: 2.1.4 9 9 License: GPLv3 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 159 159 160 160 == Changelog == 161 162 = 2.1.4: Mar 27, 2026 = 163 * Auto-switch: Bidirectional, rather than "to LSWS only" 164 * Auto-switch: Don't switch if user has overridden stack 165 * Auto-switch: Refine detection to Server identifier only 161 166 162 167 = 2.1.3: Mar 23, 2026 = -
tnc-toolbox/trunk/tnc-toolbox.php
r3488521 r3492575 6 6 * @author The Network Crew Pty Ltd (Merlot Digital) 7 7 * @license gplv3 8 * @version 2.1. 38 * @version 2.1.4 9 9 * 10 10 * @wordpress-plugin … … 12 12 * Plugin URI: https://merlot.digital 13 13 * Description: Multi-stack caching for WordPress: ea-NGINX (cPanel) and LiteSpeed. Auto-detects web server! 14 * Version: 2.1. 314 * Version: 2.1.4 15 15 * Author: The Network Crew Pty Ltd (Merlot Digital) 16 16 * Author URI: https://tnc.works … … 30 30 31 31 // Plugin version 32 define('TNCTOOLBOX_VERSION', '2.1. 3');32 define('TNCTOOLBOX_VERSION', '2.1.4'); 33 33 34 34 // Plugin Root File -
tnc-toolbox/trunk/vendor/detection.php
r3488521 r3492575 31 31 32 32 /** 33 * Option name to track if user has explicitly chosen a stack 34 */ 35 const STACK_SET_BY_USER_KEY = 'tnc_web_stack_user_set'; 36 37 /** 33 38 * Web stack constants 34 39 */ … … 53 58 * Set the web stack type 54 59 * 55 * @param string $stack Stack type ('nginx' or 'litespeed') 60 * @param string $stack Stack type ('nginx' or 'litespeed') 61 * @param bool $by_user Whether this was explicitly set by the user via settings 56 62 * @return bool True on success 57 63 */ 58 public static function set_web_stack( $stack ) {64 public static function set_web_stack( $stack, $by_user = false ) { 59 65 $valid_stacks = array( self::STACK_NGINX, self::STACK_LITESPEED ); 60 66 if ( ! in_array( $stack, $valid_stacks, true ) ) { 61 67 $stack = self::STACK_NGINX; 62 68 } 69 if ( $by_user ) { 70 update_option( self::STACK_SET_BY_USER_KEY, true ); 71 } 63 72 return update_option( self::WEB_STACK_KEY, $stack ); 64 73 } 65 74 66 75 /** 76 * Check whether the user has ever explicitly saved a stack choice 77 * 78 * @return bool True if the user has explicitly chosen a stack 79 */ 80 public static function is_user_configured() { 81 return (bool) get_option( self::STACK_SET_BY_USER_KEY, false ); 82 } 83 84 /** 67 85 * Detect current web server software 68 86 * 69 * Checks multiple indicators for LiteSpeed since OpenLiteSpeed 70 * may report as Apache in SERVER_SOFTWARE while using LSAPI for PHP. 87 * Uses SERVER_SOFTWARE header only — this is a reliable indicator. 88 * 89 * - LiteSpeed/OpenLiteSpeed: SERVER_SOFTWARE contains "LiteSpeed" 90 * - ea-NGINX (cPanel): SERVER_SOFTWARE is "Apache" (PHP runs under 91 * Apache behind the NGINX reverse proxy — this is expected) 71 92 * 72 93 * @return string|false Returns 'litespeed', 'nginx', 'apache', or false if unknown … … 75 96 $server_software = isset( $_SERVER['SERVER_SOFTWARE'] ) ? strtolower( $_SERVER['SERVER_SOFTWARE'] ) : ''; 76 97 77 // Check SERVER_SOFTWARE for litespeed first98 // LiteSpeed/OpenLiteSpeed identify themselves in SERVER_SOFTWARE 78 99 if ( strpos( $server_software, 'litespeed' ) !== false ) { 79 100 return 'litespeed'; 80 101 } 81 102 82 // LiteSpeed SAPI check - php_sapi_name() returns 'litespeed' when using LSPHP/LSAPI 83 // This is the most reliable check for OpenLiteSpeed 84 $sapi_name = strtolower( php_sapi_name() ); 85 if ( strpos( $sapi_name, 'litespeed' ) !== false ) { 86 return 'litespeed'; 87 } 88 89 // Check for LITESPEED constant (set by LiteSpeed Cache plugin or LSAPI) 90 if ( defined( 'LITESPEED' ) || defined( 'LSCACHE_ADV' ) ) { 91 return 'litespeed'; 92 } 93 94 // Check for LiteSpeed-specific server variables 95 if ( isset( $_SERVER['X_LSCACHE'] ) || isset( $_SERVER['HTTP_X_LSCACHE'] ) ) { 96 return 'litespeed'; 97 } 98 99 // Now check other servers 103 // NGINX as primary server (not ea-NGINX, which proxies to Apache) 100 104 if ( strpos( $server_software, 'nginx' ) !== false ) { 101 105 return 'nginx'; 102 106 } 107 108 // Apache — this also covers ea-NGINX (cPanel) where PHP runs 109 // under Apache behind the NGINX reverse proxy 103 110 if ( strpos( $server_software, 'apache' ) !== false ) { 104 111 return 'apache'; … … 109 116 110 117 /** 111 * Auto-detect and update web stack if mismatched 112 * 113 * If server is LiteSpeed but config says nginx, auto-switch to litespeed. 114 * Credentials are preserved - not deleted. 118 * Auto-detect and correct web stack configuration 119 * 120 * Only switches automatically if the user has never explicitly saved 121 * a stack choice. Once a user saves settings, their choice is respected 122 * and auto-detection becomes advisory only (shown on the settings page). 123 * 124 * Handles both directions: 125 * - LiteSpeed detected + configured nginx → switch to litespeed 126 * - Non-LiteSpeed detected + configured litespeed → switch back to nginx 127 * (fixes sites wrongly auto-switched by earlier buggy detection) 115 128 * 116 129 * @return array|false Returns change info if stack was auto-switched, false otherwise 117 130 */ 118 131 public static function auto_detect_and_switch_stack() { 132 // Never override an explicit user choice 133 if ( self::is_user_configured() ) { 134 return false; 135 } 136 119 137 $detected = self::detect_web_server(); 120 138 $configured = self::get_web_stack(); 121 139 122 // If LiteSpeed detected but configured for nginx, auto-switch140 // LiteSpeed detected but configured for nginx → switch to litespeed 123 141 if ( $detected === 'litespeed' && $configured === self::STACK_NGINX ) { 124 self::set_web_stack( self::STACK_LITESPEED );142 self::set_web_stack( self::STACK_LITESPEED, false ); 125 143 return array( 126 144 'detected' => $detected, … … 130 148 } 131 149 150 // Not LiteSpeed but configured as litespeed → switch back to nginx 151 // This corrects sites wrongly auto-switched by earlier detection logic 152 if ( $detected !== 'litespeed' && $configured === self::STACK_LITESPEED ) { 153 self::set_web_stack( self::STACK_NGINX, false ); 154 return array( 155 'detected' => $detected ? $detected : 'unknown', 156 'previous' => $configured, 157 'switched_to' => self::STACK_NGINX, 158 ); 159 } 160 132 161 return false; 133 162 } … … 149 178 public static function is_nginx_stack() { 150 179 return self::get_web_stack() === self::STACK_NGINX; 180 } 181 182 /** 183 * Check if the detected server matches the configured stack 184 * 185 * On ea-NGINX (cPanel), PHP runs under Apache behind the NGINX reverse 186 * proxy, so detection returns 'apache'. This is a known expected mismatch 187 * and should NOT trigger a warning. 188 * 189 * @return bool True if detection and config are compatible 190 */ 191 public static function is_detection_compatible() { 192 $detected = self::detect_web_server(); 193 $configured = self::get_web_stack(); 194 195 // No detection = no mismatch to warn about 196 if ( ! $detected ) { 197 return true; 198 } 199 200 // Direct match 201 if ( $detected === $configured ) { 202 return true; 203 } 204 205 // ea-NGINX: PHP reports Apache because it runs behind NGINX reverse proxy 206 // This is expected and not a mismatch 207 if ( $detected === 'apache' && $configured === self::STACK_NGINX ) { 208 return true; 209 } 210 211 return false; 151 212 } 152 213
Note: See TracChangeset
for help on using the changeset viewer.