diff --git a/app.py b/app.py index 3479a2f..2c829e4 100644 --- a/app.py +++ b/app.py @@ -11,7 +11,6 @@ from datetime import datetime from pathlib import Path from logging import getLogger import logging -from logging import getLogger from logging.config import dictConfig import toml @@ -31,13 +30,23 @@ from models import Session as DBSession from models import SiteConfig, init_db from steganography import embed_message, extract_message +# Add this function to handle secret key persistence +def get_or_create_secret_key(): + secret_key_file = Path("secret.key") + if secret_key_file.exists(): + return secret_key_file.read_bytes() + else: + secret_key = os.urandom(24) + secret_key_file.write_bytes(secret_key) + return secret_key + DEFAULT_CONFIG = { "server": {"host": "0.0.0.0", "port": 5000}, "directories": {"upload": "uploads", "thumbnail": "thumbnails"}, "admin": {"password": secrets.token_urlsafe(16)}, # Generate secure random password } -# Add this logging configuration before creating the Flask app +# Configure logging dictConfig({ 'version': 1, 'formatters': { @@ -66,8 +75,9 @@ dictConfig({ # Get logger for this module logger = getLogger(__name__) +# Create Flask app with persistent secret key app = Flask(__name__) -app.secret_key = os.urandom(24) +app.secret_key = get_or_create_secret_key() def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS