Add configuration, utilities, and update server with enhanced monitoring features
- Add config.py for environment configuration management - Add utils.py with utility functions - Add .env.example for environment variable reference - Add routes_example.py as route reference - Add login.html template for authentication - Update server.py with enhancements - Update all dashboard and log templates - Move documentation to 'explanations and old code' directory - Update database schema
This commit is contained in:
81
config.py
Normal file
81
config.py
Normal file
@@ -0,0 +1,81 @@
|
||||
# Configuration file for Server Monitorizare
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
class Config:
|
||||
"""Base configuration"""
|
||||
# Database
|
||||
DATABASE_PATH = os.getenv('DATABASE_PATH', 'data/database.db')
|
||||
|
||||
# Server
|
||||
DEBUG = os.getenv('DEBUG', 'False').lower() == 'true'
|
||||
PORT = int(os.getenv('PORT', 80))
|
||||
HOST = os.getenv('HOST', '0.0.0.0')
|
||||
|
||||
# Security
|
||||
SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key-change-in-production')
|
||||
API_KEY = os.getenv('API_KEY', 'default-api-key')
|
||||
|
||||
# Timeouts & Limits
|
||||
REQUEST_TIMEOUT = int(os.getenv('REQUEST_TIMEOUT', 30))
|
||||
DEVICE_TIMEOUT = int(os.getenv('DEVICE_TIMEOUT', 10))
|
||||
BULK_OPERATION_MAX_THREADS = int(os.getenv('BULK_OPERATION_MAX_THREADS', 10))
|
||||
|
||||
# Logging
|
||||
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO')
|
||||
LOG_FILE = os.getenv('LOG_FILE', 'logs/app.log')
|
||||
LOG_MAX_BYTES = int(os.getenv('LOG_MAX_BYTES', 10485760)) # 10MB
|
||||
LOG_BACKUP_COUNT = int(os.getenv('LOG_BACKUP_COUNT', 10))
|
||||
|
||||
# Caching
|
||||
CACHE_TYPE = os.getenv('CACHE_TYPE', 'simple')
|
||||
CACHE_DEFAULT_TIMEOUT = int(os.getenv('CACHE_DEFAULT_TIMEOUT', 300))
|
||||
|
||||
# Pagination
|
||||
DEFAULT_PAGE_SIZE = int(os.getenv('DEFAULT_PAGE_SIZE', 20))
|
||||
MAX_PAGE_SIZE = int(os.getenv('MAX_PAGE_SIZE', 100))
|
||||
|
||||
# Rate Limiting
|
||||
RATE_LIMIT_ENABLED = os.getenv('RATE_LIMIT_ENABLED', 'True').lower() == 'true'
|
||||
RATE_LIMIT_DEFAULT = os.getenv('RATE_LIMIT_DEFAULT', '200 per day, 50 per hour')
|
||||
|
||||
# Backup
|
||||
BACKUP_ENABLED = os.getenv('BACKUP_ENABLED', 'True').lower() == 'true'
|
||||
BACKUP_DIR = os.getenv('BACKUP_DIR', 'backups')
|
||||
BACKUP_RETENTION = int(os.getenv('BACKUP_RETENTION', 10)) # Keep last N backups
|
||||
|
||||
|
||||
class DevelopmentConfig(Config):
|
||||
"""Development configuration"""
|
||||
DEBUG = True
|
||||
LOG_LEVEL = 'DEBUG'
|
||||
|
||||
|
||||
class ProductionConfig(Config):
|
||||
"""Production configuration"""
|
||||
DEBUG = False
|
||||
LOG_LEVEL = 'INFO'
|
||||
|
||||
|
||||
class TestingConfig(Config):
|
||||
"""Testing configuration"""
|
||||
TESTING = True
|
||||
DATABASE_PATH = ':memory:'
|
||||
CACHE_TYPE = 'null'
|
||||
DEBUG = True
|
||||
|
||||
|
||||
def get_config(env=None):
|
||||
"""Get configuration based on environment"""
|
||||
if env is None:
|
||||
env = os.getenv('FLASK_ENV', 'development')
|
||||
|
||||
config_map = {
|
||||
'development': DevelopmentConfig,
|
||||
'production': ProductionConfig,
|
||||
'testing': TestingConfig,
|
||||
}
|
||||
|
||||
return config_map.get(env, DevelopmentConfig)
|
||||
Reference in New Issue
Block a user