larxius commited on
Commit
ce37757
·
verified ·
1 Parent(s): 1863d83

Update backend/config.py

Browse files
Files changed (1) hide show
  1. backend/config.py +151 -0
backend/config.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import os
3
+ sys.path.insert(0, os.path.abspath('backend'))
4
+
5
+ from bs4 import BeautifulSoup
6
+ from celery import Celery
7
+ from celery.schedules import crontab
8
+ from collections import defaultdict
9
+ from scanners.base_scanner import (
10
+ active_scan_logs, add_log, get_scan_logs, parse_domain,
11
+ cleanup_scan_logs, schedule_log_cleanup, emit_scan_progress
12
+ )
13
+ from scanners import get_pipeline, get_phases, build_scanner, apply_scan_options
14
+ try:
15
+ from backend.utils.fuzzer_engine import ContextAwareFuzzer
16
+ except ImportError:
17
+ from utils.fuzzer_engine import ContextAwareFuzzer
18
+ from cryptography import x509
19
+ from cryptography.hazmat.backends import default_backend
20
+ from datetime import datetime, timezone
21
+ from datetime import datetime, timezone, timedelta
22
+ from datetime import datetime, timezone, timezone
23
+ from dotenv import load_dotenv
24
+ load_dotenv()
25
+
26
+ import stripe
27
+ from flask import Blueprint, request, jsonify, current_app, send_from_directory
28
+ from werkzeug.utils import secure_filename
29
+ from flask import Blueprint, send_file, jsonify, request
30
+ from flask import Flask
31
+ from flask import jsonify
32
+ from flask import render_template
33
+ from flask import request, abort, g, Response, make_response
34
+ from flask_cors import CORS
35
+ from flask_limiter import Limiter
36
+ from flask_limiter.util import get_remote_address
37
+ from flask_socketio import SocketIO, emit, join_room, leave_room
38
+ from flask_sqlalchemy import SQLAlchemy
39
+ from functools import wraps
40
+ from markupsafe import escape # always available with Flask
41
+ from reportlab.lib import colors
42
+ from reportlab.lib.pagesizes import letter
43
+ from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
44
+ from reportlab.pdfgen import canvas
45
+ from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, PageBreak, Image, Flowable
46
+ from reportlab.graphics.shapes import Drawing
47
+ from reportlab.graphics.charts.barcharts import VerticalBarChart
48
+ from sqlalchemy import event
49
+ from sqlalchemy import func
50
+ from sqlalchemy import inspect, text
51
+ from sqlalchemy import text
52
+ from sqlalchemy.engine import Engine
53
+ from typing import Any
54
+ from typing import Any, Callable
55
+ from typing import Callable
56
+ from typing import Literal
57
+ from urllib.parse import urljoin, urlparse
58
+ from urllib.parse import urlparse
59
+ import base64
60
+ import bcrypt
61
+ import concurrent.futures
62
+ from backend.utils.email_service import (
63
+ send_welcome_email,
64
+ send_scan_started,
65
+ send_scan_completed,
66
+ send_scan_failed,
67
+ send_critical_alert
68
+ )
69
+
70
+ import hashlib
71
+ import html
72
+ import io
73
+ import itertools
74
+ import json
75
+ import jwt
76
+ import math
77
+ import os
78
+ import re
79
+ import re, time, ipaddress, os, hashlib, threading
80
+ import requests
81
+ import socket
82
+ import sqlite3
83
+ import ssl
84
+ import statistics
85
+ import threading
86
+ import time
87
+ import traceback
88
+ import urllib.error
89
+ import urllib.parse
90
+ import urllib.request
91
+ import urllib3
92
+ import uuid
93
+ import ipaddress
94
+
95
+
96
+
97
+
98
+
99
+ # --- From config.py ---
100
+
101
+ def _is_redis_running(url_or_host):
102
+ # Parse hostname and port
103
+ host = "localhost"
104
+ port = 6379
105
+ if "://" in url_or_host:
106
+ parts = url_or_host.split("://")[1].split("/")[0].split(":")
107
+ host = parts[0]
108
+ if len(parts) > 1:
109
+ port = int(parts[1])
110
+ try:
111
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
112
+ s.settimeout(0.5)
113
+ s.connect((host, port))
114
+ s.close()
115
+ return True
116
+ except Exception:
117
+ return False
118
+
119
+ class Config:
120
+ SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL') or 'sqlite:///wss.db'
121
+ SQLALCHEMY_TRACK_MODIFICATIONS = False
122
+
123
+ # Connection pooling for high concurrency
124
+ SQLALCHEMY_ENGINE_OPTIONS = {
125
+ 'pool_size': 20,
126
+ 'max_overflow': 10,
127
+ 'pool_recycle': 1800,
128
+ 'pool_pre_ping': True
129
+ } if not SQLALCHEMY_DATABASE_URI.startswith('sqlite') else {
130
+ 'connect_args': {'check_same_thread': False}
131
+ }
132
+
133
+ CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL', 'redis://localhost:6379/0')
134
+ CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND', 'redis://localhost:6379/0')
135
+
136
+ # Local fallback for uploads. In production, files are stored in Firebase
137
+ # Storage (see backend/utils/firebase_storage.py).
138
+ UPLOAD_FOLDER = os.getenv('UPLOAD_FOLDER', os.path.join(os.getcwd(), 'uploads', 'logos'))
139
+ MAX_CONTENT_LENGTH = 5 * 1024 * 1024 # 5 MB max upload
140
+
141
+ # Firebase Cloud Storage (for logos, PDFs, and general file uploads)
142
+ FIREBASE_CREDENTIALS = os.getenv('FIREBASE_CREDENTIALS', '')
143
+ FIREBASE_STORAGE_BUCKET = os.getenv('FIREBASE_STORAGE_BUCKET', '')
144
+
145
+ # Fallback to local memory limiter if Redis is offline
146
+ if _is_redis_running(CELERY_BROKER_URL):
147
+ RATELIMIT_STORAGE_URI = CELERY_BROKER_URL
148
+ else:
149
+ RATELIMIT_STORAGE_URI = 'memory://'
150
+
151
+