larxius commited on
Commit
9e0fa4c
·
verified ·
1 Parent(s): 02cbfe4

Update backend_structured/routes.py

Browse files
Files changed (1) hide show
  1. backend_structured/routes.py +42 -0
backend_structured/routes.py CHANGED
@@ -2126,6 +2126,48 @@ def generate_pdf_report(current_user, scan_id):
2126
  return jsonify({'message': f'Server error: {str(e)}'}), 500
2127
 
2128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2129
  # --- From webhook.py ---
2130
 
2131
  def send_webhook_alert(webhook_url, scan, vulnerabilities, crit_count, high_count):
 
2126
  return jsonify({'message': f'Server error: {str(e)}'}), 500
2127
 
2128
 
2129
+ @reports_bp.route('/<scan_id>/public-pdf', methods=['GET'])
2130
+ def generate_public_pdf_report(scan_id):
2131
+ """Direct unauthenticated access to stream/render PDF report natively in browser."""
2132
+ scan = db.session.get(Scan, scan_id)
2133
+ if not scan:
2134
+ return jsonify({'message': 'Scan session not found!'}), 404
2135
+
2136
+ try:
2137
+ vulns = Vulnerability.query.filter_by(scan_id=scan_id).order_by(Vulnerability.cvss_score.desc()).all()
2138
+
2139
+ try:
2140
+ pdf_bytes_data = generate_scan_pdf(scan, vulns)
2141
+ except Exception as e:
2142
+ import traceback
2143
+ with open('pdf_error.log', 'w') as f:
2144
+ traceback.print_exc(file=f)
2145
+ return jsonify({'message': f'PDF Generation failed: {str(e)}'}), 500
2146
+
2147
+ pdf_bytes = io.BytesIO(pdf_bytes_data)
2148
+ pdf_bytes.seek(0)
2149
+
2150
+ parsed = urlparse(scan.target_url)
2151
+ domain = parsed.netloc or parsed.path
2152
+ if ':' in domain:
2153
+ domain = domain.split(':')[0]
2154
+
2155
+ date_str = scan.completed_at.strftime('%Y%m%d_%H%M') if scan.completed_at else 'Unknown'
2156
+ filename = f"{domain}_Scan_Report_{date_str}.pdf"
2157
+
2158
+ return send_file(
2159
+ pdf_bytes,
2160
+ mimetype='application/pdf',
2161
+ as_attachment=False,
2162
+ download_name=filename
2163
+ )
2164
+ except Exception as e:
2165
+ import traceback
2166
+ traceback.print_exc()
2167
+ return jsonify({'message': f'Server error: {str(e)}'}), 500
2168
+
2169
+
2170
+
2171
  # --- From webhook.py ---
2172
 
2173
  def send_webhook_alert(webhook_url, scan, vulnerabilities, crit_count, high_count):