116 Zeilen
3.3 KiB
Python
116 Zeilen
3.3 KiB
Python
import os
|
|
import sys
|
|
import logging
|
|
from datetime import datetime
|
|
|
|
# Add current directory to Python path to ensure modules can be imported
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from flask import Flask, render_template, session
|
|
from flask_session import Session
|
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
|
# Import our configuration and utilities
|
|
import config
|
|
from utils.backup import create_backup
|
|
|
|
app = Flask(__name__)
|
|
# Load configuration from config module
|
|
app.config['SECRET_KEY'] = config.SECRET_KEY
|
|
app.config['SESSION_TYPE'] = config.SESSION_TYPE
|
|
app.config['JSON_AS_ASCII'] = config.JSON_AS_ASCII
|
|
app.config['JSONIFY_MIMETYPE'] = config.JSONIFY_MIMETYPE
|
|
app.config['PERMANENT_SESSION_LIFETIME'] = config.PERMANENT_SESSION_LIFETIME
|
|
app.config['SESSION_COOKIE_HTTPONLY'] = config.SESSION_COOKIE_HTTPONLY
|
|
app.config['SESSION_COOKIE_SECURE'] = config.SESSION_COOKIE_SECURE
|
|
app.config['SESSION_COOKIE_SAMESITE'] = config.SESSION_COOKIE_SAMESITE
|
|
app.config['SESSION_COOKIE_NAME'] = config.SESSION_COOKIE_NAME
|
|
app.config['SESSION_REFRESH_EACH_REQUEST'] = config.SESSION_REFRESH_EACH_REQUEST
|
|
Session(app)
|
|
|
|
# ProxyFix für korrekte IP-Adressen hinter Nginx
|
|
app.wsgi_app = ProxyFix(
|
|
app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1
|
|
)
|
|
|
|
# Configuration is now loaded from config module
|
|
|
|
# Scheduler für automatische Backups
|
|
scheduler = BackgroundScheduler()
|
|
scheduler.start()
|
|
|
|
# Logging konfigurieren
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
# Import and register blueprints
|
|
from routes.auth_routes import auth_bp
|
|
from routes.admin_routes import admin_bp
|
|
from routes.api_routes import api_bp
|
|
from routes.batch_routes import batch_bp
|
|
from routes.customer_routes import customer_bp
|
|
from routes.export_routes import export_bp
|
|
from routes.license_routes import license_bp
|
|
from routes.resource_routes import resource_bp
|
|
from routes.session_routes import session_bp
|
|
|
|
# Register all blueprints
|
|
app.register_blueprint(auth_bp)
|
|
app.register_blueprint(admin_bp)
|
|
app.register_blueprint(api_bp)
|
|
app.register_blueprint(batch_bp)
|
|
app.register_blueprint(customer_bp)
|
|
app.register_blueprint(export_bp)
|
|
app.register_blueprint(license_bp)
|
|
app.register_blueprint(resource_bp)
|
|
app.register_blueprint(session_bp)
|
|
|
|
|
|
# Scheduled Backup Job
|
|
def scheduled_backup():
|
|
"""Erstellt ein automatisches Backup"""
|
|
try:
|
|
backup_file = create_backup()
|
|
logging.info(f"Scheduled backup created: {backup_file}")
|
|
except Exception as e:
|
|
logging.error(f"Scheduled backup failed: {str(e)}")
|
|
|
|
|
|
# Schedule daily backup at 3 AM
|
|
scheduler.add_job(
|
|
func=scheduled_backup,
|
|
trigger="cron",
|
|
hour=3,
|
|
minute=0,
|
|
id='daily_backup',
|
|
name='Daily backup',
|
|
replace_existing=True
|
|
)
|
|
|
|
|
|
# Error handlers
|
|
@app.errorhandler(404)
|
|
def not_found(e):
|
|
return render_template('404.html'), 404
|
|
|
|
|
|
@app.errorhandler(500)
|
|
def server_error(e):
|
|
logging.error(f"Server error: {str(e)}")
|
|
return render_template('500.html'), 500
|
|
|
|
|
|
# Context processors
|
|
@app.context_processor
|
|
def inject_global_vars():
|
|
"""Inject global variables into all templates"""
|
|
return {
|
|
'current_year': datetime.now().year,
|
|
'app_version': '2.0.0',
|
|
'is_logged_in': session.get('logged_in', False),
|
|
'username': session.get('username', '')
|
|
}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0", port=5000) |