-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_env.py
More file actions
85 lines (67 loc) · 2.05 KB
/
setup_env.py
File metadata and controls
85 lines (67 loc) · 2.05 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
import secrets
import string
import os
def generate_password(length=32):
alphabet = string.ascii_letters + string.digits + "!@#$%^&*()-_=+"
return ''.join(secrets.choice(alphabet) for i in range(length))
def generate_alphanumeric(length=32):
alphabet = string.ascii_letters + string.digits
return ''.join(secrets.choice(alphabet) for i in range(length))
def main():
env_file = ".env"
if os.path.exists(env_file):
print(f"Warning: {env_file} already exists.")
overwrite = input("Do you want to overwrite it? (y/N): ")
if overwrite.lower() != 'y':
print("Aborting.")
return
print("Generating secure credentials...")
# Generate secrets
mysql_root_password = generate_password()
mysql_password = generate_password()
redis_password = generate_password()
security_salt = generate_alphanumeric(32)
crypt_key = generate_alphanumeric(32) # MISP encryption key
# Default values
mysql_user = "misp"
mysql_database = "misp"
base_url = "https://localhost:8443"
env_content = f"""# MISP Environment Variables
# Generated by setup_env.py
# Base URL
BASE_URL='{base_url}'
# Session Configuration
PHP_SESSION_COOKIE_SECURE='true'
PHP_SESSION_COOKIE_SAMESITE='Lax'
PHP_SESSION_DEFAULTS='redis'
# Database
MYSQL_HOST='db'
MYSQL_PORT='3306'
MYSQL_USER='{mysql_user}'
MYSQL_PASSWORD='{mysql_password}'
MYSQL_ROOT_PASSWORD='{mysql_root_password}'
MYSQL_DATABASE='{mysql_database}'
# Redis
REDIS_HOST='redis'
REDIS_PORT='6379'
REDIS_PASSWORD='{redis_password}'
ENABLE_REDIS_EMPTY_PASSWORD='false'
# MISP Security
SECURITY_SALT='{security_salt}'
CRYPT_KEY='{crypt_key}'
# MISP Modules
MISP_MODULES_FQDN='http://misp-modules'
# SMTP
SMTP_FQDN='mail'
SMTP_PORT='25'
# Guard
GUARD_PORT='8888'
GUARD_ARGS='--ssl-insecure'
"""
with open(env_file, "w") as f:
f.write(env_content)
print(f"Successfully created {env_file} with secure defaults.")
print("Please review the file and adjust BASE_URL if needed.")
if __name__ == "__main__":
main()