Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ CLEANUP_SCANNED_IMAGES=true
# SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
SLACK_WEBHOOK_URL=


# Google Analytics Tag ID (gtag.js)
# Example: G-XXXXXXXXXX
GOOGLE_TAG_ID=
9 changes: 6 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
os.makedirs(os.path.dirname(app.config['FEEDBACK_FILE']), exist_ok=True)

@app.context_processor
def inject_static_version():
"""Make static version available in all templates for cache busting."""
return {'static_version': STATIC_VERSION}
def inject_global_vars():
"""Make global variables available in all templates."""
return {
'static_version': STATIC_VERSION,
'google_tag_id': os.getenv('GOOGLE_TAG_ID', '')
}

def get_slack_webhook_url() -> str:
return os.getenv('SLACK_WEBHOOK_URL', '').strip()
Expand Down
3 changes: 2 additions & 1 deletion reporter/html_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def generate_standalone_html(report_dict):
js_pattern = r'<script[^>]*src=["\'].*?app\.js.*?["\'][^>]*>\s*</script>'
html_content = re.sub(js_pattern, js_placeholder, html_content)

# Clean up ALL remaining Jinja tags (static_version etc)
# Clean up ALL remaining Jinja tags (static_version, google_tag_id etc)
# This must happen before data injection
html_content = re.sub(r'\{\{\s*.*?\s*\}\}', "", html_content)
html_content = re.sub(r'\{%\s*.*?\s*%\}', "", html_content)

# NOW inject the JS content and the actual data
# Use a safe way to build the script tag without f-string interpolation issues for JS content
Expand Down
11 changes: 11 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>InfraScan - Advanced Infrastructure Auditor</title>
{% if google_tag_id %}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ google_tag_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());

gtag('config', '{{ google_tag_id }}');
</script>
{% endif %}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
Expand Down
Loading