Commit Graph

4892 Commits

Author SHA1 Message Date
usmannasir cfeac42527 Add X-API-Key header support for AI Scanner file operations
- Added extract_auth_token() function to handle both Bearer and X-API-Key authentication
- Updated all file operation endpoints to support X-API-Key headers:
  - list_files()
  - get_file_content()
  - scanner_backup_file()
  - scanner_get_file()
  - scanner_replace_file()
  - scanner_rename_file()
  - scanner_delete_file()
- Maintains backward compatibility with existing Bearer token authentication
- Added test script to verify both authentication methods work correctly
- Enables permanent API key authentication for file fixes (no more expired token issues)

This change allows the platform to fix files using the permanent CyberPanel API key
instead of temporary file access tokens that expire after ~1 hour.
2025-10-27 13:29:30 +05:00
usmannasir a60c48276d Add debug logging for API key validation
- Log first 20 chars of API key being checked
- Helps debug 'API key not found in settings' errors
- Shows which token is being validated
2025-10-26 17:55:40 +05:00
usmannasir 1169b872cf Fix backup error checking in rename and delete endpoints
- Add error checking for mkdir command (check result == 1)
- Add error checking for cp backup command (check result == 1)
- Strip trailing slash from wp_path to avoid double slashes
- Return proper error messages when backup fails
- Prevents rename/delete if backup fails
- Fixes: 'Failed to backup file before quarantine' error
2025-10-26 17:52:45 +05:00
usmannasir 95be6ea49d Use /tmp for temp files instead of /home/cyberpanel
- Write temp files to /tmp (accessible by all users)
- Website user can read from /tmp for cat command
- No permission issues with cross-directory operations
- Simplifies file operations (no intermediate copy needed)
- Clean up temp file with os.remove() as root
- Fixes: Files becoming empty due to permission issues
2025-10-26 17:15:26 +05:00
usmannasir 7beaa0492f Add debug logging for file replacement operation
- Log temp file size before replacement
- Log exact replace command being executed
- Log replace command result
- Helps debug why files are becoming empty after replace
2025-10-26 17:10:13 +05:00
usmannasir f6fd2192c5 Add shell=True for cat redirection command
- Shell redirection requires shell=True parameter in executioner
- Without shell=True, the > is treated as literal argument
- Fixes: File contents not being replaced
2025-10-26 17:05:58 +05:00
usmannasir fd1c53ffa4 Use cat redirection instead of cp for file replacement
- Change from cp to 'cat temp > target' for replacing file contents
- cat redirection is more reliable for overwriting existing files
- Ensures file contents are actually replaced
- Fixes: Files not being replaced even though cp returns success
2025-10-26 17:05:20 +05:00
usmannasir 8ef95418a2 Fix replace-file to use cp for all file operations
- Write to /home/cyberpanel temp first (no user permission issues)
- Copy from /home/cyberpanel to user directory using executioner
- Use cp instead of mv for final file replacement (more reliable)
- Clean up temp files after successful operations
- Fixes: File corruption due to failed mv command via lscpd
2025-10-26 16:44:09 +05:00
usmannasir 993c68441a Fix 'os' import error in replace-file cleanup
- Remove redundant 'import os' inside try block
- os module already imported at top of file
- Fixes: local variable 'os' referenced before assignment
2025-10-26 15:24:57 +05:00
usmannasir 856c29184e Fix replace-file API to use temp file approach instead of here-document
- Write content to /home/cyberpanel/scanner_temp_{scan_id}_{timestamp}.tmp first
- Use Python open() instead of shell here-document to avoid:
  - lscpd connection reset for large files (>2KB)
  - EOF_MARKER conflicts in file content
  - Shell command size limits
- Copy temp file to user directory using executioner with user context
- Clean up CyberPanel temp file after copy
- Fixes: [Errno 104] Connection reset by peer when writing large files
2025-10-26 15:18:26 +05:00
usmannasir e65109feca Fix security middleware to allow file content in API endpoints
- Add bypass check for 'content' field INSIDE isAPIEndpoint block
- Prevents blocking of legitimate JavaScript/PHP code in replace-file API
- Bypass list includes: content, fileContent, configData, rewriteRules, modSecRules
- Security check still applies to other fields in API requests
- Fixes: Replace-file API being blocked by security middleware
2025-10-26 15:08:34 +05:00
usmannasir 7ba205864a Fix executioner return value checks in all file operation endpoints
- Fix scanner_replace_file: cp, write, and mv checks
- Fix scanner_rename_file: mv check
- Fix scanner_delete_file: cp and rm checks
- All executioner calls now check for 1 (success) instead of 0
- Fix double slash in replace backup path
2025-10-26 14:31:48 +05:00
usmannasir a11a942cba Fix backup API executioner return value checks
- executioner() returns 1 for success, 0 for failure (inverted)
- Fix mkdir check: if mkdir_result != 1 (was != 0)
- Fix cp check: if cp_result[0] != 1 (was != 0)
- Fix double slash in backup path by stripping trailing slash from wp_path
- Add logging to show mkdir_result value for debugging
2025-10-26 14:23:32 +05:00
usmannasir 8ffd11fa08 Fix file operation endpoints to use website externalApp correctly
- Add external_app field to AuthWrapper class
- Get externalApp from website object during authentication
  - For FileAccessToken: Use Websites.externalApp
  - For API Key: Use WPSites.owner.externalApp
- Update all 5 file operation endpoints to use file_token.external_app
  - scanner_backup_file
  - scanner_get_file
  - scanner_replace_file
  - scanner_rename_file
  - scanner_delete_file
- Ensures externalApp matches wp_path since they come from same source
- Fixes backup API failing due to incorrect user context
2025-10-26 14:14:17 +05:00
usmannasir f870494bcb add aiscanner file patcher 2025-10-26 13:56:03 +05:00
usmannasir 9f101d4e4c add aiscanner file patcher 2025-10-26 12:38:25 +05:00
usmannasir 0100d3ea5b add aiscanner file patcher 2025-10-26 01:56:36 +05:00
usmannasir 369f6d539b Fix acme.sh not creating domain configurations in /root/.acme.sh/
Separate acme.sh certificate issuance and installation steps to ensure
domain configurations are properly stored. Previously, combining --issue
with --cert-file/--key-file/--fullchain-file in a single command caused
acme.sh to skip storing domain configs, breaking automatic renewals and
requiring manual certificate recreation for domain aliases.
2025-10-22 12:53:05 +05:00
usmannasir 4983decba5 bug fix: ssl timeout issues 2025-10-19 23:51:55 +05:00
usmannasir 46e40d6822 Fix permission race condition in fixPermissions function
Fixes #1583 - Ubuntu 24 permission issues causing 404 errors

Changes:
- Move main public_html permission setting to END of fixPermissions function
- Ensures public_html maintains user:nogroup ownership (not user:user)
- Prevents child domain processing from interfering with main directory permissions
- Changed all async popenExecutioner calls to sync executioner calls
- Reordered operations: permissions first, then ownership

This fixes the issue where clicking "Fix Permissions" in file manager
would incorrectly change public_html group from nogroup to the user's group,
causing 404 errors on Ubuntu 24.
2025-10-16 16:11:28 +05:00
usmannasir acc6cad623 Fix permission issues on Ubuntu 24 causing 404 errors
Fixes #1583

The fixPermissions function in file manager was causing sites to become
inaccessible after running "Fix Permissions" on Ubuntu 24. The root causes:

1. Async execution (popenExecutioner) caused race conditions where commands
   executed in unpredictable order
2. The public_html directory group was incorrectly changed from 'nogroup'
   to the user's group, breaking web server access

Changes:
- Changed all async popenExecutioner calls to sync executioner calls
- Reordered commands to set permissions before ownership
- Ensured public_html directory maintains correct group ownership (nogroup)
- Added comments to clarify the purpose of each step

This ensures the file manager's "Fix Permissions" feature works correctly
on Ubuntu 24 while maintaining proper security.
2025-10-16 14:50:28 +05:00
usmannasir 9d0d5fbd35 Fix backup restore permission error and improve SFTP fallback
- Ensure /home/cyberpanel directory exists with proper permissions before download
- Set directory permissions to 755 to allow application write access
- Refactor SCP/SFTP fallback logic to work regardless of debug mode
- Add better status messages during download process
2025-10-15 04:30:43 +05:00
usmannasir 32db00d1ae Fix backup file moving to handle compressed database backups
- Check for .sql.gz files first, then fallback to .sql
- Also move .backup.json metadata files alongside compressed backups
- Maintains backward compatibility with legacy .sql backups
2025-10-15 00:56:45 +05:00
usmannasir 7864ef63c1 Remove strict exit code checking in database restore functions
- MySQL restore may return warnings that don't indicate actual failure
- Database restoration verification is handled by subsequent password operations
- Improves reliability of compressed backup restoration
2025-10-15 00:53:31 +05:00
usmannasir 10edef5d87 Fix compressed database backup verification logic
- Changed from checking exit code to verifying file existence and size
- Resolves issue where successful mysqldump was incorrectly reported as failed
- Ensures backup file is created and not empty before marking as successful
2025-10-15 00:50:55 +05:00
usmannasir cac2e09fce Enhance database backup with compression support and backward compatibility
- Added configurable compression for database backups using gzip streaming
- Implemented auto-detection in restore function for compressed and uncompressed formats
- Added performance optimizations including --single-transaction and --extended-insert
- Created configuration file for gradual feature rollout with safe defaults
- Added helper functions for checking system capabilities and configuration
- Included comprehensive test suite to verify backward compatibility
- Maintained 100% backward compatibility with existing backup infrastructure
2025-10-14 19:54:11 +05:00
usmannasir b6f20a6a5e Add storage stats, last backup info, and error logs to ManageOCBackups page
- Add comprehensive backup account overview with visual stats cards
- Display storage usage (total, used, available, percentage) from platform API
- Show last backup run timestamp and status (success/failed)
- Display total backups count and failed backups count
- Add recent backup error logs table with timestamp, website, and error message
- Fetch all stats from platform.cyberpersons.com/Billing/GetBackupStats endpoint
- Beautiful gradient cards for visual presentation of stats
- Progress bar for storage usage visualization
- Conditional display of error logs (only shown if errors exist)
- Add account info card showing SFTP user and plan name
- Graceful fallback to N/A if platform API is unavailable
- Comprehensive error logging for API failures
2025-10-14 19:11:38 +05:00
usmannasir fb02243245 Improve One-Click Backup verification with multi-method approach
- Implement timestamp-based filename verification (Method 1)
- Add file size validation with 1KB minimum requirement (Method 2)
- Filter to only check today's backup directory for accuracy (Method 3)
- Add optional SHA256 checksum verification for integrity (Method 5)
- Use find command with size filter for efficient SSH verification
- Fallback to SFTP with comprehensive file validation
- Enhanced logging for all verification steps and failures
- Remove unused 'Yesterday' variable that was never used
- Prevents false positives from old backup files
- Detects corrupted/incomplete backups via size check
2025-10-14 18:49:41 +05:00
usmannasir c9b711d5bd Fix critical bug in One-Click Backup failure notification logic
- Fix inverted .find() logic that sent notifications when backups SUCCEEDED
- Add 'status': 'failed' field required by platform API
- Change HTTP to HTTPS for BackupFailedNotify endpoint
- Add comprehensive error handling and logging
- Add 30-second timeout on API requests
- Properly handle actualDomain vs site.domain.domain cases
2025-10-14 16:23:41 +05:00
usmannasir 6381a9ee55 Refactor DeployAccount to eliminate code duplication and improve error handling
- Remove duplicate code blocks that handled success and "already deployed" cases
- Consolidate deployment logic into single code path
- Add validation for backup plan state before deployment
- Add specific exception handling for API requests and JSON parsing
- Add timeout to API requests (30 seconds)
- Change API endpoint from HTTP to HTTPS for security
- Improve error messages with actionable guidance
- Add comprehensive logging for all error paths
- Clarify return status: status=1 only on full success, status=0 on any failure
- Add early validation for missing SSH public key
- Handle edge case where account is deployed but destination creation fails
2025-10-14 15:35:02 +05:00
usmannasir 4da45eebf1 Improve exception handling in One-Click Backup fetchOCSites function
- Add specific exception handlers for common failure scenarios
- Support multiple SSH key formats (RSA, Ed25519, ECDSA, DSS)
- Add SSH key validation before connection attempts
- Add connection timeout and proper cleanup with finally block
- Provide actionable error messages for users
- Handle empty backup folders as success instead of error
- Add comprehensive logging for all error paths
- Improve path parsing with bounds checking
2025-10-14 15:31:42 +05:00
usmannasir 7cbb563d9c fix some ux on list wp sites 2025-10-13 13:09:06 +05:00
usmannasir 77e66cfe3d fix design of wp manager home 2025-10-13 00:24:45 +05:00
usmannasir 1ef188a20a bug fix: python 3.6 compatibility 2025-10-10 17:59:01 +05:00
usmannasir ac6db0e575 bug fix: python 3.6 compatibility 2025-10-10 17:26:50 +05:00
usmannasir e4b2584ae0 Fix AlmaLinux 8 installation: Add python-dotenv to requirements (v2.4.4)
- Install python-dotenv in virtual environment during CyberPanel setup
- Fixes Django's inability to load .env file on AlmaLinux 8
- Resolves "Access denied for user 'cyberpanel'@'localhost'" errors
- Added to all installation paths (normal, DEV, and after_install)

This ensures Django can properly load database credentials from .env file
on AlmaLinux 8 systems where python-dotenv was missing.
2025-10-10 01:00:22 +05:00
usmannasir d540b24c8f bug fix: alma8 install 2025-10-10 00:09:42 +05:00
usmannasir 4408ca04c8 bug fix: staging site issue 2025-09-22 18:16:05 +05:00
usmannasir 503c464e48 bug fix: staging site issue 2025-09-22 17:46:10 +05:00
usmannasir f48e7286df bug fix: staging site issue 2025-09-22 16:57:35 +05:00
usmannasir ecd44c9d6a bug fix: staging site issue 2025-09-22 14:08:51 +05:00
usmannasir fb16f4cf56 bug fix: staging site issue 2025-09-22 13:31:20 +05:00
usmannasir 26425dd397 bug fix: allowed host issue 2025-09-15 12:07:15 +05:00
usmannasir d64b53ef63 bug fix: allowed host issue 2025-09-15 11:26:58 +05:00
Usman Nasir 7bd67d3df2
Merge pull request #1501 from master3395/v2.5.5-dev
V2.5.5 dev
2025-09-14 22:14:52 +05:00
Master3395 1fbbf66481 Add contributing guide link to README and improve security notice in SECURITY_INSTALLATION.md 2025-09-13 22:34:03 +02:00
Master3395 7bd66f7f06 Enhance environment variable management and security
- Updated .gitignore to include additional sensitive files and directories.
- Added python-dotenv to requirements for loading environment variables.
- Modified settings.py to load environment variables for sensitive configurations, including SECRET_KEY, DEBUG, and database credentials.
- Implemented secure .env file generation during installation to avoid hardcoding sensitive information.
- Introduced fallback method for settings update if environment generation fails.
2025-09-13 19:07:03 +02:00
Master3395 938fb6442b
Merge pull request #1 from master3395/stable
Update backup controller to include backup frequency and retention data
2025-09-13 18:53:47 +02:00
Master3395 71275c8c56 Merge branch 'v2.5.5-dev' of https://github.com/master3395/cyberpanel into v2.5.5-dev 2025-09-13 18:39:00 +02:00
Master3395 0773d8d9a4 Add cosmetic context processor and update templates for custom CSS
- Introduced a new `cosmetic_context` processor to provide custom CSS data to templates.
- Updated `settings.py` to include the new context processor.
- Modified multiple HTML templates to utilize the `cosmetic` variable for dynamic CSS styling.
- Enhanced user interface elements with improved styling and accessibility features, including ARIA labels for form controls.
2025-09-13 18:38:57 +02:00