Initial commit: enterprise digital platform with portal SSO, DigiServer, IT Assets, NetworkView, Server Monitor
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
"""
|
||||
Configuration settings for DigiServer v2
|
||||
Environment-based configuration with sensible defaults
|
||||
"""
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
class Config:
|
||||
"""Base configuration"""
|
||||
|
||||
# Basic Flask config
|
||||
SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key-change-in-production')
|
||||
|
||||
# Database
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
SQLALCHEMY_ECHO = False
|
||||
|
||||
# File Upload - use absolute paths
|
||||
MAX_CONTENT_LENGTH = 2048 * 1024 * 1024 # 2GB
|
||||
_basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
UPLOAD_FOLDER = os.path.join(_basedir, 'static', 'uploads')
|
||||
UPLOAD_FOLDERLOGO = os.path.join(_basedir, 'static', 'resurse')
|
||||
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'bmp', 'mp4', 'avi', 'mkv', 'mov', 'webm', 'pdf', 'ppt', 'pptx'}
|
||||
|
||||
# Session
|
||||
PERMANENT_SESSION_LIFETIME = timedelta(minutes=30)
|
||||
SESSION_COOKIE_SECURE = False # Set to True in production with HTTPS
|
||||
SESSION_COOKIE_HTTPONLY = True
|
||||
SESSION_COOKIE_SAMESITE = 'Lax'
|
||||
|
||||
# Reverse proxy trust (for Nginx/Caddy with ProxyFix middleware)
|
||||
# These are set by werkzeug.middleware.proxy_fix
|
||||
TRUSTED_PROXIES = os.getenv('TRUSTED_PROXIES', '127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16')
|
||||
PREFERRED_URL_SCHEME = os.getenv('PREFERRED_URL_SCHEME', 'https')
|
||||
|
||||
# Cache
|
||||
SEND_FILE_MAX_AGE_DEFAULT = 300 # 5 minutes for static files
|
||||
|
||||
# Server Info
|
||||
SERVER_VERSION = "2.0.0"
|
||||
BUILD_DATE = "2025-11-12"
|
||||
|
||||
# Pagination
|
||||
ITEMS_PER_PAGE = 20
|
||||
|
||||
# Admin defaults
|
||||
DEFAULT_ADMIN_USER = os.getenv('ADMIN_USER', 'admin')
|
||||
DEFAULT_ADMIN_PASSWORD = os.getenv('ADMIN_PASSWORD', 'Initial01!')
|
||||
|
||||
# Portal internal sync secret — must match INTERNAL_SYNC_SECRET in portal config
|
||||
INTERNAL_SYNC_SECRET = os.getenv('INTERNAL_SYNC_SECRET', 'change-this-internal-secret')
|
||||
|
||||
# URL of the portal login page — users are redirected here if they try to
|
||||
# access DigiServer directly without a portal session.
|
||||
PORTAL_LOGIN_URL = os.getenv('PORTAL_LOGIN_URL', 'http://localhost:8080/login')
|
||||
|
||||
# Set to True to disable DigiServer's own user registration and management UI.
|
||||
# When True, all user accounts are managed exclusively through the portal.
|
||||
PORTAL_MANAGED_USERS = True
|
||||
|
||||
|
||||
class DevelopmentConfig(Config):
|
||||
"""Development configuration"""
|
||||
|
||||
DEBUG = True
|
||||
TESTING = False
|
||||
|
||||
# Database - construct absolute path
|
||||
_basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
SQLALCHEMY_DATABASE_URI = os.getenv(
|
||||
'DATABASE_URL',
|
||||
f'sqlite:///{os.path.join(_basedir, "instance", "dev.db")}'
|
||||
)
|
||||
|
||||
# Cache (simple in-memory for development)
|
||||
CACHE_TYPE = 'simple'
|
||||
CACHE_DEFAULT_TIMEOUT = 60
|
||||
|
||||
# Security (relaxed for development)
|
||||
WTF_CSRF_ENABLED = True
|
||||
WTF_CSRF_TIME_LIMIT = None
|
||||
|
||||
|
||||
class ProductionConfig(Config):
|
||||
"""Production configuration"""
|
||||
|
||||
DEBUG = False
|
||||
TESTING = False
|
||||
TEMPLATES_AUTO_RELOAD = True # Force template reload
|
||||
|
||||
# Database - construct absolute path
|
||||
_basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
SQLALCHEMY_DATABASE_URI = os.getenv(
|
||||
'DATABASE_URL',
|
||||
f'sqlite:///{os.path.join(_basedir, "instance", "dashboard.db")}'
|
||||
)
|
||||
|
||||
# Cache - use simple cache instead of Redis
|
||||
CACHE_TYPE = 'simple'
|
||||
CACHE_DEFAULT_TIMEOUT = 300
|
||||
|
||||
# Security
|
||||
SESSION_COOKIE_SECURE = True
|
||||
SESSION_COOKIE_SAMESITE = 'Lax'
|
||||
WTF_CSRF_ENABLED = True
|
||||
|
||||
|
||||
class TestingConfig(Config):
|
||||
"""Testing configuration"""
|
||||
|
||||
DEBUG = True
|
||||
TESTING = True
|
||||
|
||||
# Database (in-memory for tests)
|
||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'
|
||||
|
||||
# Cache (simple for tests)
|
||||
CACHE_TYPE = 'simple'
|
||||
|
||||
# Security (disabled for tests)
|
||||
WTF_CSRF_ENABLED = False
|
||||
|
||||
|
||||
# Configuration dictionary
|
||||
config = {
|
||||
'development': DevelopmentConfig,
|
||||
'production': ProductionConfig,
|
||||
'testing': TestingConfig,
|
||||
'default': DevelopmentConfig
|
||||
}
|
||||
|
||||
|
||||
def get_config(env=None):
|
||||
"""Get configuration based on environment"""
|
||||
if env is None:
|
||||
env = os.getenv('FLASK_ENV', 'development')
|
||||
return config.get(env, config['default'])
|
||||
Reference in New Issue
Block a user