Changeset 3385766
- Timestamp:
- 10/28/2025 10:39:06 AM (4 months ago)
- Location:
- code-quality-control-tool
- Files:
-
- 6 edited
- 1 copied
-
tags/2.2 (copied) (copied from code-quality-control-tool/trunk)
-
tags/2.2/code-quality-control-tool.php (modified) (2 diffs)
-
tags/2.2/error_logger.php (modified) (2 diffs)
-
tags/2.2/readme.txt (modified) (1 diff)
-
trunk/code-quality-control-tool.php (modified) (2 diffs)
-
trunk/error_logger.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
code-quality-control-tool/tags/2.2/code-quality-control-tool.php
r3303032 r3385766 427 427 register_uninstall_hook(__FILE__, 'cqctphp_delete_plugin'); 428 428 function cqctphp_delete_plugin() { 429 $log_file = WP_CONTENT_DIR . '/_php_errors.log'; 429 $log_folder = WP_CONTENT_DIR . '/code-quality-logs'; 430 PHPCodeControl_general::ensurePrivateDir($log_folder); 431 432 $log_file = $log_folder . '/_php_errors.log'; 430 433 if (file_exists($log_file)) unlink($log_file); 431 434 } … … 494 497 } 495 498 499 /** 500 * Creates a directory (if not exists) and places a .htaccess file inside 501 * to block direct access to its contents. 502 * 503 * @param string $dir Absolute or relative directory path 504 * @param int $mode Permissions for the directory (default 0755) 505 * @throws RuntimeException on creation/write errors 506 */ 507 public static function ensurePrivateDir(string $dir, int $mode = 0755): void 508 { 509 // Normalize the path 510 $dir = rtrim($dir, DIRECTORY_SEPARATOR); 511 512 // If directory does not exist — create it (including intermediate directories) 513 if (!is_dir($dir)) { 514 // Keep in mind that real permissions are affected by umask: $mode & ~umask() 515 if (!mkdir($dir, $mode, true) && !is_dir($dir)) { 516 throw new RuntimeException("Failed to create directory: {$dir}"); 517 } 518 } 519 520 // Check if directory is writable 521 if (!is_writable($dir)) { 522 throw new RuntimeException("Directory exists but is not writable: {$dir}"); 523 } 524 525 // Path to .htaccess 526 $htaccessPath = $dir . DIRECTORY_SEPARATOR . '.htaccess'; 527 528 // .htaccess content for Apache 2.4+ (modern syntax) 529 // Alternative (for older Apache): "Deny from all" 530 $htaccess = <<<HTA 531 # Deny direct access to this directory 532 # Apache 2.4+: 533 Require all denied 534 535 # Backwards compatibility: 536 <IfModule !mod_authz_core.c> 537 Deny from all 538 </IfModule> 539 HTA; 540 541 // Write the file (overwrite if exists) 542 if (file_put_contents($htaccessPath, $htaccess, LOCK_EX) === false) { 543 throw new RuntimeException("Failed to write .htaccess to: {$htaccessPath}"); 544 } 545 546 // (Optional) set secure permissions on .htaccess 547 @chmod($htaccessPath, 0644); 548 } 549 496 550 // Get log file path 497 551 public static function GetLogFile() { 498 return WP_CONTENT_DIR . '/_php_errors.log'; 552 $log_folder = WP_CONTENT_DIR . '/code-quality-logs'; 553 self::ensurePrivateDir($log_folder); 554 return $log_folder . '/_php_errors.log'; 499 555 } 500 556 501 557 // Get counter file path 502 558 public static function GetErrorCounterFile() { 503 return WP_CONTENT_DIR . '/_php_errors.count.log'; 559 $log_folder = WP_CONTENT_DIR . '/code-quality-logs'; 560 self::ensurePrivateDir($log_folder); 561 return $log_folder . '/_php_errors.count.log'; 504 562 } 505 563 506 564 // Get settings file path 507 565 public static function GetSettingsFile() { 508 return WP_CONTENT_DIR . '/_php_code_control.ini'; 566 $log_folder = WP_CONTENT_DIR . '/code-quality-logs'; 567 self::ensurePrivateDir($log_folder); 568 return $log_folder . '/_php_code_control.ini'; 509 569 } 510 570 -
code-quality-control-tool/tags/2.2/error_logger.php
r3303032 r3385766 7 7 { 8 8 $WP_CONTENT_DIR = dirname(dirname(dirname(__FILE__))); 9 9 10 $WP_CONTENT_DIR = $WP_CONTENT_DIR . '/code-quality-logs'; 11 PHPCodeControl_logger::ensurePrivateDir($WP_CONTENT_DIR); 10 12 11 13 $settings = parse_ini_file($WP_CONTENT_DIR.'/_php_code_control.ini'); 12 14 13 15 // Check if active 14 16 if (!isset($settings['is_active']) && $settings['is_active'] == 0) return; … … 152 154 153 155 $old_error_handler_5FB609D0735B = set_error_handler("cqctphp_start_phptrace_error_handler"); 156 157 158 class PHPCodeControl_logger { 159 160 /** 161 * Creates a directory (if not exists) and places a .htaccess file inside 162 * to block direct access to its contents. 163 * 164 * @param string $dir Absolute or relative directory path 165 * @param int $mode Permissions for the directory (default 0755) 166 * @throws RuntimeException on creation/write errors 167 */ 168 public static function ensurePrivateDir(string $dir, int $mode = 0755): void 169 { 170 // Normalize the path 171 $dir = rtrim($dir, DIRECTORY_SEPARATOR); 172 173 // If directory does not exist — create it (including intermediate directories) 174 if (!is_dir($dir)) { 175 // Keep in mind that real permissions are affected by umask: $mode & ~umask() 176 if (!mkdir($dir, $mode, true) && !is_dir($dir)) { 177 throw new RuntimeException("Failed to create directory: {$dir}"); 178 } 179 } 180 181 // Check if directory is writable 182 if (!is_writable($dir)) { 183 throw new RuntimeException("Directory exists but is not writable: {$dir}"); 184 } 185 186 // Path to .htaccess 187 $htaccessPath = $dir . DIRECTORY_SEPARATOR . '.htaccess'; 188 189 // .htaccess content for Apache 2.4+ (modern syntax) 190 // Alternative (for older Apache): "Deny from all" 191 $htaccess = <<<HTA 192 # Deny direct access to this directory 193 # Apache 2.4+: 194 Require all denied 195 196 # Backwards compatibility: 197 <IfModule !mod_authz_core.c> 198 Deny from all 199 </IfModule> 200 HTA; 201 202 // Write the file (overwrite if exists) 203 if (file_put_contents($htaccessPath, $htaccess, LOCK_EX) === false) { 204 throw new RuntimeException("Failed to write .htaccess to: {$htaccessPath}"); 205 } 206 207 // (Optional) set secure permissions on .htaccess 208 @chmod($htaccessPath, 0644); 209 } 210 } -
code-quality-control-tool/tags/2.2/readme.txt
r3303032 r3385766 4 4 Requires at least: 3.0 5 5 Tested up to: 6.8 6 Stable tag: 2. 16 Stable tag: 2.2 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
code-quality-control-tool/trunk/code-quality-control-tool.php
r3303032 r3385766 427 427 register_uninstall_hook(__FILE__, 'cqctphp_delete_plugin'); 428 428 function cqctphp_delete_plugin() { 429 $log_file = WP_CONTENT_DIR . '/_php_errors.log'; 429 $log_folder = WP_CONTENT_DIR . '/code-quality-logs'; 430 PHPCodeControl_general::ensurePrivateDir($log_folder); 431 432 $log_file = $log_folder . '/_php_errors.log'; 430 433 if (file_exists($log_file)) unlink($log_file); 431 434 } … … 494 497 } 495 498 499 /** 500 * Creates a directory (if not exists) and places a .htaccess file inside 501 * to block direct access to its contents. 502 * 503 * @param string $dir Absolute or relative directory path 504 * @param int $mode Permissions for the directory (default 0755) 505 * @throws RuntimeException on creation/write errors 506 */ 507 public static function ensurePrivateDir(string $dir, int $mode = 0755): void 508 { 509 // Normalize the path 510 $dir = rtrim($dir, DIRECTORY_SEPARATOR); 511 512 // If directory does not exist — create it (including intermediate directories) 513 if (!is_dir($dir)) { 514 // Keep in mind that real permissions are affected by umask: $mode & ~umask() 515 if (!mkdir($dir, $mode, true) && !is_dir($dir)) { 516 throw new RuntimeException("Failed to create directory: {$dir}"); 517 } 518 } 519 520 // Check if directory is writable 521 if (!is_writable($dir)) { 522 throw new RuntimeException("Directory exists but is not writable: {$dir}"); 523 } 524 525 // Path to .htaccess 526 $htaccessPath = $dir . DIRECTORY_SEPARATOR . '.htaccess'; 527 528 // .htaccess content for Apache 2.4+ (modern syntax) 529 // Alternative (for older Apache): "Deny from all" 530 $htaccess = <<<HTA 531 # Deny direct access to this directory 532 # Apache 2.4+: 533 Require all denied 534 535 # Backwards compatibility: 536 <IfModule !mod_authz_core.c> 537 Deny from all 538 </IfModule> 539 HTA; 540 541 // Write the file (overwrite if exists) 542 if (file_put_contents($htaccessPath, $htaccess, LOCK_EX) === false) { 543 throw new RuntimeException("Failed to write .htaccess to: {$htaccessPath}"); 544 } 545 546 // (Optional) set secure permissions on .htaccess 547 @chmod($htaccessPath, 0644); 548 } 549 496 550 // Get log file path 497 551 public static function GetLogFile() { 498 return WP_CONTENT_DIR . '/_php_errors.log'; 552 $log_folder = WP_CONTENT_DIR . '/code-quality-logs'; 553 self::ensurePrivateDir($log_folder); 554 return $log_folder . '/_php_errors.log'; 499 555 } 500 556 501 557 // Get counter file path 502 558 public static function GetErrorCounterFile() { 503 return WP_CONTENT_DIR . '/_php_errors.count.log'; 559 $log_folder = WP_CONTENT_DIR . '/code-quality-logs'; 560 self::ensurePrivateDir($log_folder); 561 return $log_folder . '/_php_errors.count.log'; 504 562 } 505 563 506 564 // Get settings file path 507 565 public static function GetSettingsFile() { 508 return WP_CONTENT_DIR . '/_php_code_control.ini'; 566 $log_folder = WP_CONTENT_DIR . '/code-quality-logs'; 567 self::ensurePrivateDir($log_folder); 568 return $log_folder . '/_php_code_control.ini'; 509 569 } 510 570 -
code-quality-control-tool/trunk/error_logger.php
r3303032 r3385766 7 7 { 8 8 $WP_CONTENT_DIR = dirname(dirname(dirname(__FILE__))); 9 9 10 $WP_CONTENT_DIR = $WP_CONTENT_DIR . '/code-quality-logs'; 11 PHPCodeControl_logger::ensurePrivateDir($WP_CONTENT_DIR); 10 12 11 13 $settings = parse_ini_file($WP_CONTENT_DIR.'/_php_code_control.ini'); 12 14 13 15 // Check if active 14 16 if (!isset($settings['is_active']) && $settings['is_active'] == 0) return; … … 152 154 153 155 $old_error_handler_5FB609D0735B = set_error_handler("cqctphp_start_phptrace_error_handler"); 156 157 158 class PHPCodeControl_logger { 159 160 /** 161 * Creates a directory (if not exists) and places a .htaccess file inside 162 * to block direct access to its contents. 163 * 164 * @param string $dir Absolute or relative directory path 165 * @param int $mode Permissions for the directory (default 0755) 166 * @throws RuntimeException on creation/write errors 167 */ 168 public static function ensurePrivateDir(string $dir, int $mode = 0755): void 169 { 170 // Normalize the path 171 $dir = rtrim($dir, DIRECTORY_SEPARATOR); 172 173 // If directory does not exist — create it (including intermediate directories) 174 if (!is_dir($dir)) { 175 // Keep in mind that real permissions are affected by umask: $mode & ~umask() 176 if (!mkdir($dir, $mode, true) && !is_dir($dir)) { 177 throw new RuntimeException("Failed to create directory: {$dir}"); 178 } 179 } 180 181 // Check if directory is writable 182 if (!is_writable($dir)) { 183 throw new RuntimeException("Directory exists but is not writable: {$dir}"); 184 } 185 186 // Path to .htaccess 187 $htaccessPath = $dir . DIRECTORY_SEPARATOR . '.htaccess'; 188 189 // .htaccess content for Apache 2.4+ (modern syntax) 190 // Alternative (for older Apache): "Deny from all" 191 $htaccess = <<<HTA 192 # Deny direct access to this directory 193 # Apache 2.4+: 194 Require all denied 195 196 # Backwards compatibility: 197 <IfModule !mod_authz_core.c> 198 Deny from all 199 </IfModule> 200 HTA; 201 202 // Write the file (overwrite if exists) 203 if (file_put_contents($htaccessPath, $htaccess, LOCK_EX) === false) { 204 throw new RuntimeException("Failed to write .htaccess to: {$htaccessPath}"); 205 } 206 207 // (Optional) set secure permissions on .htaccess 208 @chmod($htaccessPath, 0644); 209 } 210 } -
code-quality-control-tool/trunk/readme.txt
r3303032 r3385766 4 4 Requires at least: 3.0 5 5 Tested up to: 6.8 6 Stable tag: 2. 16 Stable tag: 2.2 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.