diff --git a/aiScanner/aiScannerManager.py b/aiScanner/aiScannerManager.py index aa95bd572..2c15a9d8d 100644 --- a/aiScanner/aiScannerManager.py +++ b/aiScanner/aiScannerManager.py @@ -66,6 +66,10 @@ class AIScannerManager: else: self.logger.writeToFile(f'[AIScannerManager.scannerHome] API balance call failed, keeping stored balance: {current_balance}') + # Check VPS free scans availability + server_ip = ACLManager.fetchIP() + vps_info = self.check_vps_free_scans(server_ip) + # Get user's websites for scan selection from websiteFunctions.models import Websites try: @@ -86,6 +90,8 @@ class AIScannerManager: 'current_balance': current_balance, 'websites': websites, 'is_payment_configured': scanner_settings.is_payment_configured, + 'vps_info': vps_info, + 'server_ip': server_ip, } self.logger.writeToFile(f'[AIScannerManager.scannerHome] Context built successfully, rendering template') @@ -255,6 +261,7 @@ class AIScannerManager: scan_type=scan_type, status='pending' ) + server_ip = ACLManager.fetchIP() # Create file access token FileAccessToken.objects.create( @@ -275,7 +282,8 @@ class AIScannerManager: callback_url, file_access_token, file_access_base_url, - scan_id + scan_id, + server_ip ) if scan_response: @@ -562,7 +570,7 @@ class AIScannerManager: self.logger.writeToFile(f'[AIScannerManager.get_account_balance] Exception: {str(e)}') return None - def submit_wordpress_scan(self, api_key, domain, scan_type, callback_url, file_access_token, file_access_base_url, scan_id): + def submit_wordpress_scan(self, api_key, domain, scan_type, callback_url, file_access_token, file_access_base_url, scan_id, server_ip): """Submit scan request to AI Scanner API""" try: payload = { @@ -571,7 +579,8 @@ class AIScannerManager: 'cyberpanel_callback': callback_url, 'file_access_token': file_access_token, 'file_access_base_url': file_access_base_url, - 'scan_id': scan_id + 'scan_id': scan_id, + 'server_ip': server_ip } self.logger.writeToFile(f'[AIScannerManager.submit_wordpress_scan] Submitting scan {scan_id} for {domain}') @@ -634,6 +643,30 @@ class AIScannerManager: except Exception as e: self.logger.writeToFile(f'[AIScannerManager.get_scan_results] Error: {str(e)}') return None + + def check_vps_free_scans(self, server_ip): + """Check if server IP belongs to VPS hosting and has free scans available""" + try: + self.logger.writeToFile(f'[AIScannerManager.check_vps_free_scans] Checking VPS free scans for IP: {server_ip}') + + response = requests.post( + 'https://platform.cyberpersons.com/ai-scanner/api/vps/check-free-scans/', + json={'ip': server_ip}, + timeout=10 + ) + + self.logger.writeToFile(f'[AIScannerManager.check_vps_free_scans] Response status: {response.status_code}') + + if response.status_code == 200: + data = response.json() + self.logger.writeToFile(f'[AIScannerManager.check_vps_free_scans] Response data: {data}') + return data + else: + self.logger.writeToFile(f'[AIScannerManager.check_vps_free_scans] API error: {response.text}') + return {'success': False, 'is_vps': False, 'error': 'API call failed'} + except Exception as e: + self.logger.writeToFile(f'[AIScannerManager.check_vps_free_scans] Error: {str(e)}') + return {'success': False, 'is_vps': False, 'error': str(e)} def setup_add_payment_method(self, api_key, user_email, cyberpanel_host): """Setup additional payment method with AI Scanner API""" diff --git a/aiScanner/templates/aiScanner/scanner.html b/aiScanner/templates/aiScanner/scanner.html index e2b757cba..1711cca07 100644 --- a/aiScanner/templates/aiScanner/scanner.html +++ b/aiScanner/templates/aiScanner/scanner.html @@ -32,7 +32,7 @@ AI Security Scanner - CyberPanel {% endif %} - {% if not is_payment_configured %} + {% if not is_payment_configured and not vps_info.is_vps %}
@@ -67,9 +67,34 @@ AI Security Scanner - CyberPanel
- {% else %} + {% endif %} + + + {% if vps_info.is_vps and vps_info.has_free_scans %} +
+
+
+

VPS Free Scans Available

+

Great news! Your CyberPanel VPS hosting includes {{ vps_info.free_scans_available }} free AI security scans this month ({{ vps_info.scans_used_this_month }}/{{ vps_info.free_scans_per_month }} used).

+ {% if not is_payment_configured %} +

You can still add a payment method below for additional scans beyond your free allowance.

+ {% endif %} +
+
+
+ {% elif vps_info.is_vps and not vps_info.has_free_scans %} +
+
+
+

Free Scans Exhausted

+

You've used all {{ vps_info.free_scans_per_month }} free AI security scans for this month. Setup payment to continue scanning.

+
+
+
+ {% endif %} + {% if is_payment_configured or vps_info.is_vps %}
@@ -79,11 +104,21 @@ AI Security Scanner - CyberPanel
-

${{ current_balance|floatformat:4 }}

-

Available Credit

+ {% if vps_info.is_vps and vps_info.has_free_scans %} +

{{ vps_info.free_scans_available }}

+

Free Scans Available

+ {% if is_payment_configured %} + Plus ${{ current_balance|floatformat:4 }} credit + {% endif %} + {% else %} +

${{ current_balance|floatformat:4 }}

+

Available Credit

+ {% endif %} + {% if is_payment_configured %} + {% endif %}
@@ -126,18 +161,35 @@ AI Security Scanner - CyberPanel

Payment Methods + {% if not vps_info.is_vps or is_payment_configured %} + {% else %} + + {% endif %}

+ {% if vps_info.is_vps and not is_payment_configured %} +

+ + Payment setup is optional for VPS users. You have {{ vps_info.free_scans_available }} free scans available. +

+ {% else %}

Your account uses automatic billing. Add multiple payment methods for backup security.

+ {% endif %}
+ {% if is_payment_configured %}

Payment methods will be managed through the platform.

+ {% else %} +

No payment methods configured yet.

+ {% endif %}
@@ -179,9 +231,19 @@ AI Security Scanner - CyberPanel
- + {% else %} + + {% endif %}
@@ -193,7 +255,7 @@ AI Security Scanner - CyberPanel {% endif %} - {% if is_payment_configured and recent_scans %} + {% if recent_scans and (is_payment_configured or vps_info.is_vps) %}