From f92e8f59c41fb951c71a4795e2897f4d194fa4e2 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Sat, 5 Jul 2025 17:04:25 +0500 Subject: [PATCH] bug fix: csf issue --- REFACTORING_NOTES.md | 129 ------------------------------------------- 1 file changed, 129 deletions(-) delete mode 100644 REFACTORING_NOTES.md diff --git a/REFACTORING_NOTES.md b/REFACTORING_NOTES.md deleted file mode 100644 index b3f0f906f..000000000 --- a/REFACTORING_NOTES.md +++ /dev/null @@ -1,129 +0,0 @@ -# CyberPanel Installation Scripts Refactoring - -## Date: January 5, 2025 - -## Overview -This document outlines the refactoring work performed on CyberPanel's installation scripts to consolidate common functionality and improve code maintainability. - -## Files Modified -- `/install/install.py` -- `/install/installCyberPanel.py` -- `/install/install_utils.py` (newly created) - -## Refactoring Summary - -### 1. Created Shared Utility Module -Created `install_utils.py` in the `/install/` directory to house common functions used by both `install.py` and `installCyberPanel.py`. - -### 2. Functions Moved to install_utils.py - -#### System Detection Functions -- **`FetchCloudLinuxAlmaVersionVersion()`** - - Detects CloudLinux and AlmaLinux versions - - Previously duplicated in both files with identical implementations - -- **`get_Ubuntu_release()`** - - Gets Ubuntu release version from `/etc/lsb-release` - - Added parameters to handle minor differences between implementations - -- **`get_distro()`** - - Detects Linux distribution (Ubuntu, CentOS, CentOS 8, OpenEuler) - - Only existed in `install.py`, now shared - -#### Output and Logging -- **`stdOut(message, log=0, do_exit=0, code=os.EX_OK)`** - - Standard output function with timestamps - - **Enhanced with color support**: - - 🔴 Red: Errors, failures, critical issues - - 🟡 Yellow: Warnings and alerts - - 🟢 Green: Success messages - - 🔵 Blue: Running/processing operations - - 🟣 Purple: Default/general messages - - Colors automatically disabled when output is piped - -#### Package Management -- **`get_package_install_command(distro, package_name, options="")`** - - Returns appropriate install command for the distribution - - Handles apt-get, yum, and dnf package managers - -- **`get_package_remove_command(distro, package_name)`** - - Returns appropriate remove command for the distribution - -#### Command Execution -- **`resFailed(distro, res)`** - - Checks if command execution failed based on return code - -- **`call(command, distro, bracket, message, log=0, do_exit=0, code=os.EX_OK, shell=False)`** - - Executes shell commands with retry logic (3 attempts) - - Provides consistent error handling and logging - -#### Password Generation -- **`char_set`** dictionary - - Character sets for password generation (kept for backward compatibility) - -- **`generate_pass(length=14)`** - - Generates cryptographically secure passwords - - Uses `secrets` module instead of `random` for better security - -- **`generate_random_string(length=32, include_special=False)`** - - Flexible string generation with optional special characters - -#### LiteSpeed Management -- **`format_restart_litespeed_command(server_root_path)`** - - Formats the LiteSpeed restart command - -### 3. Distribution Constants -Moved distribution constants to `install_utils.py`: -```python -ubuntu = 0 -centos = 1 -cent8 = 2 -openeuler = 3 -``` - -### 4. Key Improvements - -#### Security Enhancements -- Password generation now uses `secrets` module for cryptographic security -- Removed usage of `random.choice()` for password generation - -#### Code Quality -- Eliminated code duplication across files -- Single source of truth for common functionality -- Consistent error handling and logging - -#### Maintainability -- Centralized utility functions in one location -- Easier to update and maintain shared functionality -- Better organization of code - -#### Visual Improvements -- Added color-coded output for better readability -- Automatic detection of terminal capabilities -- Clear visual distinction between error, warning, success, and info messages - -### 5. Backward Compatibility -All changes maintain backward compatibility: -- Function signatures preserved where possible -- Wrapper functions created in original locations when needed -- `installCyberPanel.py` continues to use `install.preFlightsChecks.call` through import - -### 6. Testing -Created test scripts to verify functionality: -- Color output testing -- Password generation verification -- Ensured all functions work as expected - -## Benefits -1. **Reduced Code Duplication**: Common functions now exist in single location -2. **Improved Security**: Cryptographically secure password generation -3. **Better User Experience**: Color-coded output for easier reading -4. **Easier Maintenance**: Changes to common functions only need to be made once -5. **Consistent Behavior**: Both installation scripts now use identical implementations - -## Future Recommendations -1. Consider moving more shared functionality to `install_utils.py` -2. Add unit tests for utility functions -3. Consider creating additional utility modules for specific domains (e.g., `network_utils.py`, `database_utils.py`) -4. Document function parameters and return values more thoroughly -5. Consider adding configuration file support for installation parameters \ No newline at end of file