feat: add real-time HTTPS status detection on admin config page
- Detect actual HTTPS status from current request (scheme + X-Forwarded-Proto) - Auto-sync database when HTTPS status mismatch is detected - Show real-time connection info (protocol, host, port) - Display helpful message when accessing via HTTPS but config shows disabled - Add CSS styling for detection status display - Users now see accurate HTTPS status even if database wasn't in sync
This commit is contained in:
16
app/blueprints/admin.py
Executable file → Normal file
16
app/blueprints/admin.py
Executable file → Normal file
@@ -858,8 +858,22 @@ def https_config():
|
|||||||
try:
|
try:
|
||||||
config = HTTPSConfig.get_config()
|
config = HTTPSConfig.get_config()
|
||||||
|
|
||||||
|
# Detect actual current HTTPS status
|
||||||
|
# Check if current connection is HTTPS
|
||||||
|
is_https_active = request.scheme == 'https' or request.headers.get('X-Forwarded-Proto') == 'https'
|
||||||
|
current_host = request.host.split(':')[0] # Remove port if present
|
||||||
|
|
||||||
|
# If HTTPS is active but database shows disabled, sync it
|
||||||
|
if is_https_active and config and not config.https_enabled:
|
||||||
|
# Update database to reflect actual HTTPS status
|
||||||
|
config.https_enabled = True
|
||||||
|
db.session.commit()
|
||||||
|
log_action('info', f'HTTPS status auto-corrected to enabled (detected from request)')
|
||||||
|
|
||||||
return render_template('admin/https_config.html',
|
return render_template('admin/https_config.html',
|
||||||
config=config)
|
config=config,
|
||||||
|
is_https_active=is_https_active,
|
||||||
|
current_host=current_host)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_action('error', f'Error loading HTTPS config page: {str(e)}')
|
log_action('error', f'Error loading HTTPS config page: {str(e)}')
|
||||||
flash('Error loading HTTPS configuration page.', 'danger')
|
flash('Error loading HTTPS configuration page.', 'danger')
|
||||||
|
|||||||
@@ -13,6 +13,21 @@
|
|||||||
<!-- Status Display -->
|
<!-- Status Display -->
|
||||||
<div class="card status-card">
|
<div class="card status-card">
|
||||||
<h2>Current Status</h2>
|
<h2>Current Status</h2>
|
||||||
|
|
||||||
|
<!-- Real-time HTTPS detection -->
|
||||||
|
<div class="status-detection">
|
||||||
|
<p class="detection-info">
|
||||||
|
<strong>🔍 Detected Connection:</strong>
|
||||||
|
{% if is_https_active %}
|
||||||
|
<span class="badge badge-success">🔒 HTTPS ({{ request.scheme.upper() }})</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="badge badge-warning">🔓 HTTP</span>
|
||||||
|
{% endif %}
|
||||||
|
<br>
|
||||||
|
<small>Current host: <code>{{ current_host }}</code> via {{ request.host }}</small>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% if config and config.https_enabled %}
|
{% if config and config.https_enabled %}
|
||||||
<div class="status-enabled">
|
<div class="status-enabled">
|
||||||
<span class="status-badge">✅ HTTPS ENABLED</span>
|
<span class="status-badge">✅ HTTPS ENABLED</span>
|
||||||
@@ -29,8 +44,15 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<div class="status-disabled">
|
<div class="status-disabled">
|
||||||
<span class="status-badge-inactive">⚠️ HTTPS DISABLED</span>
|
<span class="status-badge-inactive">⚠️ HTTPS DISABLED</span>
|
||||||
<p>The application is currently running on HTTP only (port 80)</p>
|
{% if is_https_active %}
|
||||||
<p>Enable HTTPS below to secure your application.</p>
|
<p style="color: #156b2e; background: #d1f0e0; padding: 10px; border-radius: 4px; margin: 10px 0;">
|
||||||
|
✅ <strong>Note:</strong> You are currently accessing this page via HTTPS, but the configuration shows as disabled.
|
||||||
|
This configuration will be automatically updated. Please refresh the page.
|
||||||
|
</p>
|
||||||
|
{% else %}
|
||||||
|
<p>The application is currently running on HTTP only (port 80)</p>
|
||||||
|
<p>Enable HTTPS below to secure your application.</p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
@@ -195,6 +217,39 @@
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.status-detection {
|
||||||
|
background: #f0f7ff;
|
||||||
|
border-left: 4px solid #0066cc;
|
||||||
|
padding: 15px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detection-info {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 4px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-success {
|
||||||
|
background: #d1f0e0;
|
||||||
|
color: #156b2e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-warning {
|
||||||
|
background: #fff3cd;
|
||||||
|
color: #856404;
|
||||||
|
}
|
||||||
|
|
||||||
.status-card {
|
.status-card {
|
||||||
margin-bottom: 30px;
|
margin-bottom: 30px;
|
||||||
border-left: 5px solid #ddd;
|
border-left: 5px solid #ddd;
|
||||||
|
|||||||
Reference in New Issue
Block a user