import os from flask import Flask from flask_sqlalchemy import SQLAlchemy from sqlalchemy import event from sqlalchemy.engine import Engine db = SQLAlchemy() def create_app(): # Create the Flask app and set the template folder (located in app/templates) app = Flask(__name__, template_folder='templates') app.secret_key = 'your_super_secret_key_here' # Configure the SQLite database app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(os.path.abspath(os.path.dirname(__file__)), 'domains.db') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Initialize SQLAlchemy with the app db.init_app(app) # Enable SQLite foreign key support. with app.app_context(): from app import models db.create_all() # Ensure the default password category "General" exists from app.models import PasswordCategory if not PasswordCategory.query.filter_by(name="General").first(): default_category = PasswordCategory(name="General") db.session.add(default_category) db.session.commit() # Ensure default remote categories exist from app.models import RemoteCategory default_remote_cats = ["RDP", "SSL-VPN", "VPN", "MGMT"] for cat in default_remote_cats: if not RemoteCategory.query.filter_by(name=cat).first(): db.session.add(RemoteCategory(name=cat)) db.session.commit() @event.listens_for(Engine, "connect") def set_sqlite_pragma(dbapi_connection, connection_record): cursor = dbapi_connection.cursor() cursor.execute("PRAGMA foreign_keys=ON") cursor.close() # Register blueprints from app.routes.domain import domain_bp app.register_blueprint(domain_bp) from app.routes.ssl import ssl_bp app.register_blueprint(ssl_bp) from app.routes.tools import tools_bp app.register_blueprint(tools_bp) from app.routes.clients import clients_bp app.register_blueprint(clients_bp) return app