Merge pull request #1 from Sudo-JHare/well-known-updates

.well-known updates
This commit is contained in:
Joshua Hare 2025-05-26 16:18:20 +10:00 committed by GitHub
commit 4d712b64f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 277 additions and 94 deletions

163
app.py
View File

@ -71,7 +71,7 @@ def create_app():
},
"host": "localhost:5001",
"basePath": "/oauth2",
"schemes": ["http"]
"schemes": ["https"]
}
swagger_config = {
"specs": [
@ -106,18 +106,15 @@ def create_app():
def get_config_value(key, default):
try:
# Ensure the session is fresh
database.session.expire_all()
config = Configuration.query.filter_by(key=key).first()
if config:
logger.debug(f"Retrieved {key} from database (exact match): {config.value}")
return int(config.value) if key in ['TOKEN_DURATION', 'PROXY_TIMEOUT', 'REFRESH_TOKEN_DURATION'] else config.value
# Try case-insensitive match
config = Configuration.query.filter(Configuration.key.ilike(key)).first()
if config:
logger.debug(f"Retrieved {key} from database (case-insensitive match): {config.value}")
return int(config.value) if key in ['TOKEN_DURATION', 'PROXY_TIMEOUT', 'REFRESH_TOKEN_DURATION'] else config.value
# Fallback: Direct database query
result = database.session.execute(
text("SELECT value FROM configurations WHERE key = :key"),
{"key": key}
@ -235,6 +232,23 @@ def create_app():
response_data = None
response_mode = session.get('response_mode', 'inline')
logger.debug(f"Session contents before form submission: {session}")
try:
smart_config_url = url_for('smart_proxy.smart_configuration', _external=True)
response = requests.get(smart_config_url)
response.raise_for_status()
smart_config = response.json()
logger.debug(f"SMART configuration for test client: {smart_config}")
except requests.RequestException as e:
logger.error(f"Error fetching SMART configuration: {e}")
flash(f"Error fetching SMART configuration: {e}", "error")
smart_config = {
'authorization_endpoint': url_for('smart_proxy.authorize', _external=True),
'scopes_supported': current_app.config['ALLOWED_SCOPES'].split(),
'response_types_supported': ['code'],
'code_challenge_methods_supported': ['S256']
}
if form.validate_on_submit():
client_id = form.client_id.data
app = RegisteredApp.query.filter_by(client_id=client_id).first()
@ -243,29 +257,35 @@ def create_app():
return redirect(url_for('test_client'))
response_mode = form.response_mode.data if hasattr(form, 'response_mode') and form.response_mode.data else 'inline'
session['response_mode'] = response_mode
scopes = ' '.join(set(app.scopes.split()))
app_scopes = set(app.scopes.split())
supported_scopes = set(smart_config.get('scopes_supported', []))
scopes = ' '.join(app_scopes.intersection(supported_scopes))
if not scopes:
flash("No valid scopes available for this client.", "error")
return redirect(url_for('test_client'))
code_verifier = secrets.token_urlsafe(32)
code_challenge = base64.urlsafe_b64encode(
hashlib.sha256(code_verifier.encode('ascii')).digest()
).decode('ascii').rstrip('=')
session['code_verifier'] = code_verifier
redirect_uri = app.get_default_redirect_uri().lower()
auth_url = url_for(
'smart_proxy.authorize',
client_id=client_id,
redirect_uri=redirect_uri,
scope=scopes,
response_type='code',
state='test_state_123',
aud=current_app.config['FHIR_SERVER_URL'] + current_app.config['METADATA_ENDPOINT'],
code_challenge=code_challenge,
code_challenge_method='S256',
_external=True
)
logger.info(f"Redirecting to authorization URL for client '{client_id}'")
logger.info(f"Code verifier for client '{client_id}': {code_verifier}")
auth_url = smart_config.get('authorization_endpoint', url_for('smart_proxy.authorize', _external=True))
auth_params = {
'client_id': client_id,
'redirect_uri': redirect_uri,
'scope': scopes,
'response_type': 'code',
'state': 'test_state_123',
'aud': current_app.config['FHIR_SERVER_URL'] + current_app.config['METADATA_ENDPOINT'],
'code_challenge': code_challenge,
'code_challenge_method': 'S256'
}
logger.info(f"Constructing auth URL: {auth_url} with params: {auth_params}")
session['post_auth_redirect'] = redirect_uri
return redirect(auth_url)
return redirect(f"{auth_url}?{'&'.join(f'{k}={v}' for k, v in auth_params.items())}")
if 'code' in request.args and 'state' in request.args:
code = request.args.get('code')
state = request.args.get('state')
@ -288,6 +308,7 @@ def create_app():
finally:
session.pop('post_auth_redirect', None)
session.pop('response_mode', None)
try:
apps = RegisteredApp.query.filter(
(RegisteredApp.is_test_app == False) |
@ -299,7 +320,8 @@ def create_app():
logger.error(f"Error fetching apps for test client: {e}", exc_info=True)
flash("Could not load applications. Please try again later.", "error")
apps = []
return render_template('test_client.html', form=form, apps=apps, response_data=response_data, response_mode=response_mode)
return render_template('test_client.html', form=form, apps=apps, response_data=response_data, response_mode=response_mode, smart_config=smart_config)
@app.route('/test-server', methods=['GET', 'POST'])
def test_server():
@ -312,42 +334,76 @@ def create_app():
form = ServerTestForm()
response_data = None
try:
smart_config_url = url_for('smart_proxy.smart_configuration', _external=True)
response = requests.get(smart_config_url)
response.raise_for_status()
smart_config = response.json()
logger.debug(f"SMART configuration for test server: {smart_config}")
except requests.RequestException as e:
logger.error(f"Error fetching SMART configuration: {e}")
flash(f"Error fetching SMART configuration: {e}", "error")
smart_config = {
'authorization_endpoint': url_for('smart_proxy.authorize', _external=True),
'scopes_supported': current_app.config['ALLOWED_SCOPES'].split(),
'response_types_supported': ['code'],
'code_challenge_methods_supported': ['S256']
}
if form.validate_on_submit():
try:
client_id = form.client_id.data
client_secret = form.client_secret.data
redirect_uri = form.redirect_uri.data
scopes = ' '.join(set(form.scopes.data.split()))
requested_scopes = set(form.scopes.data.split())
supported_scopes = set(smart_config.get('scopes_supported', []))
valid_scopes = requested_scopes.intersection(supported_scopes)
if not valid_scopes:
flash("No valid scopes provided.", "error")
return render_template('test_server.html', form=form, response_data=response_data, smart_config=smart_config)
scopes = ' '.join(valid_scopes)
app = RegisteredApp.query.filter_by(client_id=client_id).first()
if not app or not app.check_client_secret(client_secret):
flash("Invalid client ID or secret.", "error")
return render_template('test_server.html', form=form, response_data=response_data, smart_config=smart_config)
if not app.check_redirect_uri(redirect_uri):
flash("Invalid redirect URI for this client.", "error")
return render_template('test_server.html', form=form, response_data=response_data, smart_config=smart_config)
code_verifier = secrets.token_urlsafe(32)
code_challenge = base64.urlsafe_b64encode(
hashlib.sha256(code_verifier.encode('ascii')).digest()
).decode('ascii').rstrip('=')
session['server_test_code_verifier'] = code_verifier
session['server_test_client_secret'] = client_secret
auth_url = url_for(
'smart_proxy.authorize',
client_id=client_id,
redirect_uri=redirect_uri,
scope=scopes,
response_type='code',
state='server_test_state',
aud=current_app.config['FHIR_SERVER_URL'] + current_app.config['METADATA_ENDPOINT'],
code_challenge=code_challenge,
code_challenge_method='S256',
_external=True
)
auth_url = smart_config.get('authorization_endpoint', url_for('smart_proxy.authorize', _external=True))
auth_params = {
'client_id': client_id,
'redirect_uri': redirect_uri,
'scope': scopes,
'response_type': 'code',
'state': 'server_test_state',
'aud': current_app.config['FHIR_SERVER_URL'] + current_app.config['METADATA_ENDPOINT'],
'code_challenge': code_challenge,
'code_challenge_method': 'S256'
}
session['server_test_redirect_uri'] = redirect_uri
return redirect(auth_url)
return redirect(f"{auth_url}?{'&'.join(f'{k}={v}' for k, v in auth_params.items())}")
except Exception as e:
flash(f"Error initiating authorization: {e}", "error")
logger.error(f"Error in test-server: {e}", exc_info=True)
if 'code' in request.args and 'state' in request.args and request.args.get('state') == 'server_test_state':
code = request.args.get('code')
redirect_uri = session.get('server_test_redirect_uri')
client_secret = session.get('server_test_client_secret')
code_verifier = session.get('server_test_code_verifier')
if redirect_uri and client_secret and code_verifier:
token_url = url_for('smart_proxy.issue_token', _external=True)
token_url = smart_config.get('token_endpoint', url_for('smart_proxy.issue_token', _external=True))
token_data = {
'grant_type': 'authorization_code',
'code': code,
@ -369,7 +425,8 @@ def create_app():
session.pop('server_test_redirect_uri', None)
session.pop('server_test_client_secret', None)
session.pop('server_test_code_verifier', None)
return render_template('test_server.html', form=form, response_data=response_data)
return render_template('test_server.html', form=form, response_data=response_data, smart_config=smart_config)
@app.route('/configure/security', methods=['GET', 'POST'])
def security_settings():
@ -382,14 +439,10 @@ def create_app():
'refresh_token_duration': refresh_token_duration,
'allowed_scopes': allowed_scopes
}
logger.debug(f"Security form data: {form_data}")
form.process(data=form_data)
# Fallback: Directly set form field values
form.token_duration.data = token_duration
form.refresh_token_duration.data = refresh_token_duration
form.allowed_scopes.data = allowed_scopes
logger.debug(f"Security form fields after process: {list(form._fields.keys())}")
logger.debug(f"Security form values before render: token_duration={form.token_duration.data}, refresh_token_duration={form.refresh_token_duration.data}, allowed_scopes={form.allowed_scopes.data}")
if form.validate_on_submit():
try:
configs = [
@ -423,13 +476,9 @@ def create_app():
'fhir_server_url': fhir_server_url,
'proxy_timeout': proxy_timeout
}
logger.debug(f"Proxy settings form data: {form_data}")
form.process(data=form_data)
# Fallback: Directly set form field values
form.fhir_server_url.data = fhir_server_url
form.proxy_timeout.data = proxy_timeout
logger.debug(f"Proxy settings form fields after process: {list(form._fields.keys())}")
logger.debug(f"Proxy settings form values before render: fhir_server_url={form.fhir_server_url.data}, proxy_timeout={form.proxy_timeout.data}")
if form.validate_on_submit():
try:
configs = [
@ -451,7 +500,7 @@ def create_app():
database.session.rollback()
logger.error(f"Error updating proxy settings: {e}", exc_info=True)
flash(f"Error updating proxy settings: {e}", "error")
return render_template('configure/proxy_settings.html', form=form, fhir_server_url=app.config['FHIR_SERVER_URL'])
return render_template('configure/proxy_settings.html', form=form)
@app.route('/configure/server-endpoints', methods=['GET', 'POST'])
def server_endpoints():
@ -464,14 +513,10 @@ def create_app():
'capability_endpoint': capability_endpoint,
'resource_base_endpoint': resource_base_endpoint
}
logger.debug(f"Server endpoints form data: {form_data}")
form.process(data=form_data)
# Fallback: Directly set form field values
form.metadata_endpoint.data = metadata_endpoint
form.capability_endpoint.data = capability_endpoint
form.resource_base_endpoint.data = resource_base_endpoint
logger.debug(f"Server endpoints form fields after process: {list(form._fields.keys())}")
logger.debug(f"Server endpoints form values before render: metadata_endpoint={form.metadata_endpoint.data}, capability_endpoint={form.capability_endpoint.data}, resource_base_endpoint={form.resource_base_endpoint.data}")
if form.validate_on_submit():
try:
configs = [
@ -508,6 +553,20 @@ def create_app():
flash(f"Error updating endpoint settings: {e}", "error")
return render_template('configure/server_endpoints.html', form=form)
@app.route('/test-smart-config', methods=['GET'])
def test_smart_config():
try:
smart_config_url = url_for('smart_proxy.smart_configuration', _external=True)
response = requests.get(smart_config_url)
response.raise_for_status()
config_data = response.json()
logger.debug(f"SMART configuration fetched: {config_data}")
return render_template('test_smart_config.html', config_data=config_data)
except requests.RequestException as e:
logger.error(f"Error fetching SMART configuration: {e}")
flash(f"Error fetching SMART configuration: {e}", "error")
return render_template('test_smart_config.html', config_data=None)
@app.route('/api-docs')
@swag_from({
'tags': ['Documentation'],
@ -540,3 +599,7 @@ def create_app():
logger.info("FHIRVINE Flask application created and configured.")
return app
if __name__ == '__main__':
app = create_app()
app.run(debug=True, port=5001)

View File

@ -3,22 +3,27 @@
{% block title %}About - {{ site_name }}{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="container mt-4">
<h1 class="text-center mb-4">About FHIRVINE SMART Proxy</h1>
<div class="row justify-content-center">
<div class="col-md-8">
<h1 class="text-center mb-4">About {{ site_name }}</h1>
<div class="card shadow-sm">
<div class="card-body">
<p>{{ site_name }} is a SMART on FHIR SSO proxy designed to facilitate secure app integration with FHIR servers.</p>
<p>FHIRVINE is a modular SMART on FHIR Single Sign-On (SSO) Proxy designed to facilitate secure authentication and authorization for FHIR-based applications.</p>
<h5>Features</h5>
<ul>
<li>Secure OAuth2 authorization flows with PKCE support.</li>
<li>App gallery for managing registered applications.</li>
<li>Proxy FHIR API requests to backend servers.</li>
<li>Light and dark theme support.</li>
<li>Register and manage SMART on FHIR applications.</li>
<li>Test client and server-side OAuth2 flows.</li>
<li>Configure proxy settings and FHIR server endpoints.</li>
<li>Support for PKCE and secure token management.</li>
</ul>
<p>Built with Flask, Bootstrap, and Authlib. Learn more about SMART on FHIR at <a href="https://www.hl7.org/fhir/smart-app-launch/" target="_blank">HL7 SMART on FHIR</a>.</p>
<a href="{{ url_for('index') }}" class="btn btn-primary">Back to Home</a>
<h5>Developer</h5>
<p>Developed by <a href="https://github.com/Sudo-JHare">Sudo-JHare</a>. Source code available on <a href="https://github.com/Sudo-JHare/FHIRVINE-Smart-Proxy">GitHub</a>.</p>
<h5>Contact</h5>
<p>Report issues or contribute at <a href="https://github.com/Sudo-JHare/FHIRVINE-Smart-Proxy/issues">GitHub Issues</a>.</p>
<div class="text-center mt-4">
<a href="{{ url_for('index') }}" class="btn btn-primary">Back to Home</a>
</div>
</div>
</div>
</div>

View File

@ -15,6 +15,13 @@
<p class="text-muted text-center small mb-4">
Configure security settings for OAuth2 authentication.
</p>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
<form method="POST" action="{{ url_for('security_settings') }}" novalidate>
{{ form.hidden_tag() }}
{{ render_field(form.token_duration, value=form.token_duration.data) }}

View File

@ -15,6 +15,13 @@
<p class="text-muted text-center small mb-4">
Configure endpoints for the upstream FHIR server and view available SMART endpoints.
</p>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
<form method="POST" action="{{ url_for('server_endpoints') }}" novalidate>
{{ form.hidden_tag() }}
{{ render_field(form.metadata_endpoint) }}
@ -28,7 +35,7 @@
<hr class="my-4">
<h5>Available SMART Endpoints</h5>
<ul class="list-group mb-4">
<li class="list-group-item"><strong>Configuration:</strong> <code>/.well-known/smart-configuration</code> - SMART on FHIR discovery</li>
<li class="list-group-item"><strong>Configuration:</strong> <code>/oauth2/.well-known/smart-configuration</code> - SMART on FHIR discovery</li>
<li class="list-group-item"><strong>Authorization:</strong> <code>/oauth2/authorize</code> - Initiate OAuth2 flow</li>
<li class="list-group-item"><strong>Token:</strong> <code>/oauth2/token</code> - Exchange code for token</li>
<li class="list-group-item"><strong>Revoke:</strong> <code>/oauth2/revoke</code> - Revoke tokens</li>

View File

@ -1,5 +1,7 @@
{% extends "base.html" %}
{% block title %}Authorize Application - {{ site_name }}{% endblock %}
{% block content %}
<div class="container mt-4">
<div class="row justify-content-center">

View File

@ -1,14 +1,18 @@
{% extends "base.html" %}
{% block title %}404 - Not Found - {{ site_name }}{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="container mt-4">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6">
<div class="alert alert-warning text-center" role="alert">
<h4 class="alert-heading"><i class="bi bi-exclamation-triangle-fill me-2"></i>Page Not Found</h4>
<p>The page you are looking for does not exist.</p>
<hr>
<a href="{{ url_for('index') }}" class="btn btn-secondary">Return Home</a>
<div class="col-md-8">
<div class="card shadow-sm">
<div class="card-body text-center">
<h1 class="display-1 text-danger">404</h1>
<h2>Page Not Found</h2>
<p class="text-muted mb-4">The page you're looking for doesn't exist or has been moved.</p>
<a href="{{ url_for('index') }}" class="btn btn-primary">Return to Home</a>
</div>
</div>
</div>
</div>

View File

@ -1,14 +1,18 @@
{% extends "base.html" %}
{% block title %}500 - Server Error - {{ site_name }}{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="container mt-4">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6">
<div class="alert alert-danger text-center" role="alert">
<h4 class="alert-heading"><i class="bi bi-exclamation-triangle-fill me-2"></i>Internal Server Error</h4>
<p>Something went wrong on our end. Please try again later.</p>
<hr>
<a href="{{ url_for('index') }}" class="btn btn-secondary">Return Home</a>
<div class="col-md-8">
<div class="card shadow-sm">
<div class="card-body text-center">
<h1 class="display-1 text-danger">500</h1>
<h2>Internal Server Error</h2>
<p class="text-muted mb-4">Something went wrong on our end. Please try again later.</p>
<a href="{{ url_for('index') }}" class="btn btn-primary">Return to Home</a>
</div>
</div>
</div>
</div>

View File

@ -1,20 +1,19 @@
{% extends "base.html" %}
{% block title %}Authentication Error - {{ site_name }}{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="container mt-4">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6">
<div class="alert alert-danger text-center" role="alert">
<h4 class="alert-heading"><i class="bi bi-exclamation-triangle-fill me-2"></i>Authorization Error</h4>
<p>An error occurred during the authorization process.</p>
<hr>
<p class="mb-0 small"><strong>Details:</strong> {{ error | e }}</p> {# Display the error message #}
<div class="col-md-8">
<div class="card shadow-sm">
<div class="card-body text-center">
<h2 class="text-danger">Authentication Error</h2>
<p class="text-muted mb-4">{{ error }}</p>
<a href="{{ url_for('index') }}" class="btn btn-primary">Return to Home</a>
</div>
</div>
<div class="text-center mt-3">
<a href="{{ url_for('index') }}" class="btn btn-secondary">Return Home</a>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -1,18 +1,36 @@
{% extends "base.html" %}
{% from "_formhelpers.html" import render_field %}
{% block title %}Proxy Settings - {{ site_name }}{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="container mt-4">
<div class="row justify-content-center">
<div class="col-md-8">
<h1 class="text-center mb-4">Proxy Settings</h1>
<div class="col-md-8 col-lg-6">
<div class="card shadow-sm">
<div class="card-header">
<h2 class="text-center mb-0">Proxy Settings</h2>
</div>
<div class="card-body">
<h5>FHIR Server URL</h5>
<p class="text-muted">Current FHIR Server: <code>{{ fhir_server_url }}</code></p>
<p class="text-warning">Editing the FHIR server URL requires environment variable changes. Please update <code>FHIR_SERVER_URL</code> in your <code>.env</code> file and restart the application.</p>
<a href="{{ url_for('index') }}" class="btn btn-primary">Back to Home</a>
<p class="text-muted text-center small mb-4">
Configure the upstream FHIR server and proxy settings.
</p>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
<form method="POST" action="{{ url_for('proxy_settings') }}" novalidate>
{{ form.hidden_tag() }}
{{ render_field(form.fhir_server_url, value=form.fhir_server_url.data) }}
{{ render_field(form.proxy_timeout, value=form.proxy_timeout.data) }}
<div class="d-grid gap-2 mt-4">
{{ form.submit(class="btn btn-primary btn-lg") }}
<a href="{{ url_for('index') }}" class="btn btn-outline-secondary btn-lg">Cancel</a>
</div>
</form>
</div>
</div>
</div>

View File

@ -1,5 +1,7 @@
{% extends "base.html" %}
{% block title %}Test Client Launch - {{ site_name }}{% endblock %}
{% block content %}
<div class="container mt-4">
<div class="row justify-content-center">
@ -12,6 +14,21 @@
<p class="text-muted text-center small mb-4">
Select a registered application to test its SMART on FHIR launch or register a test app.
</p>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
{% if smart_config %}
<h5 class="mb-3">SMART Configuration</h5>
<pre class="border p-3 bg-light" style="max-height: 400px; overflow-y: auto;">
{{ smart_config | tojson(indent=2) }}
</pre>
{% else %}
<p class="text-danger mb-3">Could not load SMART configuration.</p>
{% endif %}
<form method="POST" action="{{ url_for('test_client') }}" novalidate>
{{ form.hidden_tag() }}
<div class="mb-3">

View File

@ -1,6 +1,8 @@
{% extends "base.html" %}
{% from "_formhelpers.html" import render_field %}
{% block title %}Test Server - {{ site_name }}{% endblock %}
{% block content %}
<div class="container mt-4">
<div class="row justify-content-center">
@ -13,6 +15,21 @@
<p class="text-muted text-center small mb-4">
Test FHIRVINE as an OAuth2 server by simulating an external client.
</p>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
{% if smart_config %}
<h5 class="mb-3">SMART Configuration</h5>
<pre class="border p-3 bg-light" style="max-height: 400px; overflow-y: auto;">
{{ smart_config | tojson(indent=2) }}
</pre>
{% else %}
<p class="text-danger mb-3">Could not load SMART configuration.</p>
{% endif %}
<form method="POST" action="{{ url_for('test_server') }}" novalidate>
{{ form.hidden_tag() }}
{{ render_field(form.client_id) }}

View File

@ -0,0 +1,40 @@
{% extends "base.html" %}
{% block title %}Test SMART Configuration - {{ site_name }}{% endblock %}
{% block content %}
<div class="container mt-4">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6">
<div class="card shadow-sm">
<div class="card-header">
<h2 class="text-center mb-0">Test SMART Configuration</h2>
</div>
<div class="card-body">
<p class="text-muted text-center small mb-4">
Fetch and display the SMART on FHIR configuration from <code>/oauth2/.well-known/smart-configuration</code>.
</p>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
{% if config_data %}
<h5>SMART Configuration</h5>
<pre class="border p-3 bg-light" style="max-height: 400px; overflow-y: auto;">
{{ config_data | tojson(indent=2) }}
</pre>
{% else %}
<p class="text-danger">No configuration data available. Please try again.</p>
{% endif %}
<div class="d-grid gap-2 mt-4">
<a href="{{ url_for('index') }}" class="btn btn-primary">Back to Home</a>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}