File size: 2,895 Bytes
bc0b11f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Centralized configuration management.
All sensitive values are read from environment variables with no hardcoded defaults.
"""

import os
import sys

# ---------------------------------------------------------------------------
# Mail API (YYDS / 215.im)
# ---------------------------------------------------------------------------
MAIL_API_KEY = os.environ.get("MAIL_API_KEY", "")
MAIL_API_BASE_URL = os.environ.get("MAIL_API_BASE_URL", "https://maliapi.215.im/v1")

# ---------------------------------------------------------------------------
# Network proxy (SOCKS5, optional)
# Leave empty to connect directly.
# Format: socks5://user:pass@host:port
# ---------------------------------------------------------------------------
SOCKS5_PROXY = os.environ.get("SOCKS5_PROXY", "")

# ---------------------------------------------------------------------------
# Database
# ---------------------------------------------------------------------------
_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
_DEFAULT_DB = os.path.join(_ROOT, "privy_manager.db")
DB_PATH = os.environ.get("DB_PATH", _DEFAULT_DB)

# ---------------------------------------------------------------------------
# Server ports
# ---------------------------------------------------------------------------
MANAGER_PORT = int(os.environ.get("MANAGER_PORT", "7894"))
API_PORT = int(os.environ.get("API_PORT", "7895"))
API_HOST = os.environ.get("API_HOST", "0.0.0.0")

# ---------------------------------------------------------------------------
# Registration defaults (can be overridden via Web UI)
# ---------------------------------------------------------------------------
DEFAULT_TOTAL = int(os.environ.get("DEFAULT_TOTAL", "10"))
DEFAULT_CONCURRENCY = int(os.environ.get("DEFAULT_CONCURRENCY", "3"))
DEFAULT_TIMEOUT = int(os.environ.get("DEFAULT_TIMEOUT", "180"))
DEFAULT_INTERVAL = int(os.environ.get("DEFAULT_INTERVAL", "5"))
DEFAULT_DOMAIN = os.environ.get("DEFAULT_DOMAIN", "")

# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
def get_proxies():
    """Return proxy dict if SOCKS5_PROXY is configured, otherwise None."""
    if SOCKS5_PROXY:
        return {"http": SOCKS5_PROXY, "https": SOCKS5_PROXY}
    return None


# ---------------------------------------------------------------------------
# Validation
# ---------------------------------------------------------------------------
def validate():
    """Raise SystemExit if required configuration is missing."""
    missing = []
    if not MAIL_API_KEY:
        missing.append("MAIL_API_KEY")
    if missing:
        print(f"ERROR: Missing required environment variables: {', '.join(missing)}", file=sys.stderr)
        print("Copy .env.example to .env and fill in the values.", file=sys.stderr)
        sys.exit(1)