75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
SKE Digital Signage Server
|
|
Main application entry point
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from app import create_app
|
|
from app.extensions import db
|
|
from app.models import User, ServerLog, ScheduledTask
|
|
from app.utils.logger import log_action
|
|
|
|
def main():
|
|
"""Main application entry point"""
|
|
|
|
# Create the Flask application
|
|
app = create_app()
|
|
|
|
# Initialize database and create default admin user if needed
|
|
with app.app_context():
|
|
db.create_all()
|
|
create_default_admin()
|
|
log_action("Server started")
|
|
|
|
# Run the application
|
|
port = int(os.environ.get('PORT', 5000))
|
|
host = os.environ.get('HOST', '0.0.0.0')
|
|
debug = os.environ.get('FLASK_DEBUG', 'False').lower() == 'true'
|
|
|
|
app.run(host=host, port=port, debug=debug)
|
|
|
|
def create_default_admin():
|
|
"""Create default admin user if none exists"""
|
|
from app.extensions import bcrypt
|
|
|
|
admin_username = os.environ.get('ADMIN_USER', 'admin')
|
|
admin_password = os.environ.get('ADMIN_PASSWORD', 'admin123')
|
|
|
|
# Create default admin user
|
|
if not User.query.filter_by(username=admin_username).first():
|
|
hashed_password = bcrypt.generate_password_hash(admin_password).decode('utf-8')
|
|
admin_user = User(
|
|
username=admin_username,
|
|
password=hashed_password,
|
|
role='admin'
|
|
)
|
|
db.session.add(admin_user)
|
|
db.session.commit()
|
|
print(f"Default admin user '{admin_username}' created with password '{admin_password}'")
|
|
log_action(f"Default admin user '{admin_username}' created")
|
|
else:
|
|
print(f"Admin user '{admin_username}' already exists")
|
|
|
|
# Create default super admin user
|
|
sadmin_username = os.environ.get('SADMIN_USER', 'sadmin')
|
|
sadmin_password = os.environ.get('SADMIN_PASSWORD', 'sadmin123')
|
|
|
|
if not User.query.filter_by(username=sadmin_username).first():
|
|
hashed_password = bcrypt.generate_password_hash(sadmin_password).decode('utf-8')
|
|
sadmin_user = User(
|
|
username=sadmin_username,
|
|
password=hashed_password,
|
|
role='sadmin'
|
|
)
|
|
db.session.add(sadmin_user)
|
|
db.session.commit()
|
|
print(f"Default super admin user '{sadmin_username}' created with password '{sadmin_password}'")
|
|
log_action(f"Default super admin user '{sadmin_username}' created")
|
|
else:
|
|
print(f"Super admin user '{sadmin_username}' already exists")
|
|
|
|
if __name__ == '__main__':
|
|
main()
|