free scan for vps users

This commit is contained in:
usmannasir
2025-06-26 13:50:51 +05:00
parent 4f4cf35ab6
commit b1715b6ada
2 changed files with 105 additions and 10 deletions

View File

@@ -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"""

View File

@@ -32,7 +32,7 @@ AI Security Scanner - CyberPanel
{% endif %}
<!-- Payment Setup Section -->
{% if not is_payment_configured %}
{% if not is_payment_configured and not vps_info.is_vps %}
<div class="row">
<div class="col-md-12">
<div class="alert alert-info">
@@ -67,9 +67,34 @@ AI Security Scanner - CyberPanel
</div>
</div>
</div>
{% else %}
{% endif %}
<!-- VPS Free Scans Notice -->
{% if vps_info.is_vps and vps_info.has_free_scans %}
<div class="row">
<div class="col-md-12">
<div class="alert alert-success">
<h4><i class="fas fa-gift"></i> VPS Free Scans Available</h4>
<p>Great news! Your CyberPanel VPS hosting includes <strong>{{ vps_info.free_scans_available }} free AI security scans</strong> this month ({{ vps_info.scans_used_this_month }}/{{ vps_info.free_scans_per_month }} used).</p>
{% if not is_payment_configured %}
<p><small class="text-muted">You can still add a payment method below for additional scans beyond your free allowance.</small></p>
{% endif %}
</div>
</div>
</div>
{% elif vps_info.is_vps and not vps_info.has_free_scans %}
<div class="row">
<div class="col-md-12">
<div class="alert alert-warning">
<h4><i class="fas fa-exclamation-triangle"></i> Free Scans Exhausted</h4>
<p>You've used all {{ vps_info.free_scans_per_month }} free AI security scans for this month. Setup payment to continue scanning.</p>
</div>
</div>
</div>
{% endif %}
<!-- Scanner Dashboard -->
{% if is_payment_configured or vps_info.is_vps %}
<div class="row">
<div class="col-md-4">
<div class="panel panel-success">
@@ -79,11 +104,21 @@ AI Security Scanner - CyberPanel
</h4>
</div>
<div class="panel-body text-center">
<h2 class="text-success">${{ current_balance|floatformat:4 }}</h2>
<p class="text-muted">Available Credit</p>
{% if vps_info.is_vps and vps_info.has_free_scans %}
<h2 class="text-success">{{ vps_info.free_scans_available }}</h2>
<p class="text-muted">Free Scans Available</p>
{% if is_payment_configured %}
<small class="text-muted">Plus ${{ current_balance|floatformat:4 }} credit</small>
{% endif %}
{% else %}
<h2 class="text-success">${{ current_balance|floatformat:4 }}</h2>
<p class="text-muted">Available Credit</p>
{% endif %}
{% if is_payment_configured %}
<button class="btn btn-xs btn-default" onclick="refreshBalance()">
<i class="fas fa-sync"></i> Refresh
</button>
{% endif %}
</div>
</div>
</div>
@@ -126,18 +161,35 @@ AI Security Scanner - CyberPanel
<div class="panel-heading">
<h4 class="panel-title">
<i class="fas fa-credit-card"></i> Payment Methods
{% if not vps_info.is_vps or is_payment_configured %}
<button class="btn btn-xs btn-primary pull-right" onclick="addPaymentMethod()">
<i class="fas fa-plus"></i> Add Payment Method
</button>
{% else %}
<button class="btn btn-xs btn-info pull-right" onclick="addPaymentMethod()">
<i class="fas fa-plus"></i> Add Payment (Optional)
</button>
{% endif %}
</h4>
</div>
<div class="panel-body">
{% if vps_info.is_vps and not is_payment_configured %}
<p class="text-muted">
<i class="fas fa-info-circle"></i>
Payment setup is optional for VPS users. You have {{ vps_info.free_scans_available }} free scans available.
</p>
{% else %}
<p class="text-muted">
<i class="fas fa-info-circle"></i>
Your account uses automatic billing. Add multiple payment methods for backup security.
</p>
{% endif %}
<div id="paymentMethodsList">
{% if is_payment_configured %}
<p class="text-muted">Payment methods will be managed through the platform.</p>
{% else %}
<p class="text-muted">No payment methods configured yet.</p>
{% endif %}
</div>
</div>
</div>
@@ -179,9 +231,19 @@ AI Security Scanner - CyberPanel
<div class="col-md-2">
<div class="form-group">
<label>&nbsp;</label>
<button type="submit" class="btn btn-success btn-block" id="scanButton">
<i class="fas fa-search"></i> Start Scan
{% if vps_info.is_vps and not vps_info.has_free_scans and not is_payment_configured %}
<button type="button" class="btn btn-warning btn-block" disabled>
<i class="fas fa-lock"></i> Free Scans Exhausted
</button>
{% else %}
<button type="submit" class="btn btn-success btn-block" id="scanButton">
{% if vps_info.is_vps and vps_info.has_free_scans %}
<i class="fas fa-search"></i> Start Free Scan
{% else %}
<i class="fas fa-search"></i> Start Scan
{% endif %}
</button>
{% endif %}
</div>
</div>
</div>
@@ -193,7 +255,7 @@ AI Security Scanner - CyberPanel
{% endif %}
<!-- Scan History -->
{% if is_payment_configured and recent_scans %}
{% if recent_scans and (is_payment_configured or vps_info.is_vps) %}
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">