Commit Graph

17 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
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
6dd7114f6d Initial commit for v2.4.3 2025-08-01 14:56:30 +05:00