diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..050df56 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +# Use the official Python image from the Docker Hub +FROM python:3.11-slim AS build + +# Set the working directory in the container +WORKDIR /app + +# Install build tools and libraries +RUN apt-get update && apt-get install -y \ + build-essential \ + libffi-dev \ + libssl-dev \ + python3-dev \ + cargo \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Install Rust +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +# Copy the current directory contents into the container at /app +COPY . /app + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Stage 2: Runtime stage +FROM python:3.11-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy only the necessary files from the build stage +COPY --from=build /app /app +COPY --from=build /root/.cargo /root/.cargo + +# Install runtime dependencies +RUN apt-get update && apt-get install -y \ + libffi-dev \ + libssl-dev \ + && rm -rf /var/lib/apt/lists/* + +# Install Gunicorn +RUN pip install gunicorn + +# Make port 5000 available to the world outside this container +EXPOSE 5000 + +# Run the clear_db script, then the initialization script, and then Gunicorn +CMD ["sh", "-c", "python clear_db.py && python init_db.py && gunicorn -w 4 -b 0.0.0.0:5000 app:app"] \ No newline at end of file diff --git a/__pycache__/app.cpython-311.pyc b/__pycache__/app.cpython-311.pyc index 0c17199..035afd5 100644 Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ diff --git a/app.py b/app.py index 7c64a35..f57292e 100644 --- a/app.py +++ b/app.py @@ -9,8 +9,8 @@ from flask_migrate import Migrate app = Flask(__name__) -# Set the secret key to a fixed value -app.config['SECRET_KEY'] = 'Ana_Are_Multe_Mere-Si_Nu_Are_Pere' +# Set the secret key from environment variable or use a default value +app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'Ana_Are_Multe_Mere-Si_Nu_Are_Pere') # Configurare baza de date SQLite app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///dashboard.db' @@ -239,6 +239,15 @@ def delete_group_content(content_id): db.session.commit() return redirect(url_for('manage_group', group_id=group_id)) +@app.route('/group//delete', methods=['POST']) +@login_required +@admin_required +def delete_group(group_id): + group = Group.query.get_or_404(group_id) + db.session.delete(group) + db.session.commit() + return redirect(url_for('dashboard')) + @app.route('/player/') @login_required def player_page(player_id): diff --git a/clear_db.py b/clear_db.py new file mode 100644 index 0000000..6988a70 --- /dev/null +++ b/clear_db.py @@ -0,0 +1,10 @@ +from app import app, db + +def clear_database(): + with app.app_context(): + db.drop_all() + db.create_all() + print("Database cleared and structure recreated.") + +if __name__ == '__main__': + clear_database() \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a95f6d5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3.8' + +services: + web: + image: digi_signage_server_app:latest + ports: + - "7100:5000" + environment: + - FLASK_APP=app.py + - FLASK_RUN_HOST=0.0.0.0 + - ADMIN_USER=admin + - ADMIN_PASSWORD=Matei + - SECRET_KEY=Ma_Duc_Dupa_Merele_Lui_Ana + volumes: + - .:/app + command: sh -c "python clear_db.py && python init_db.py && gunicorn -w 4 -b 0.0.0.0:5000 app:app" \ No newline at end of file diff --git a/init_db.py b/init_db.py new file mode 100644 index 0000000..d05e9e9 --- /dev/null +++ b/init_db.py @@ -0,0 +1,20 @@ +import os +from app import app, db, User, bcrypt + +def create_admin_user(): + admin_username = os.getenv('ADMIN_USER', 'admin') + admin_password = os.getenv('ADMIN_PASSWORD', 'admin') + hashed_password = bcrypt.generate_password_hash(admin_password).decode('utf-8') + + if not User.query.filter_by(username=admin_username).first(): + admin_user = User(username=admin_username, password=hashed_password, role='admin') + db.session.add(admin_user) + db.session.commit() + print(f"Admin user '{admin_username}' created with password '{admin_password}'") + else: + print(f"Admin user '{admin_username}' already exists") + +if __name__ == '__main__': + with app.app_context(): + db.create_all() + create_admin_user() \ No newline at end of file diff --git a/instance/dashboard.db b/instance/dashboard.db index 9c5bd0d..f79e5f3 100644 Binary files a/instance/dashboard.db and b/instance/dashboard.db differ diff --git a/requirements.txt b/requirements.txt index d11fd33..87f0dab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ bcrypt==4.2.1 blinker==1.9.0 click==8.1.8 Flask==3.1.0 -Flask-Bcrypt==1.0.1 + Flask-Login==0.6.3 Flask-Migrate==4.1.0 Flask-SQLAlchemy==3.1.1 @@ -15,3 +15,5 @@ MarkupSafe==3.0.2 SQLAlchemy==2.0.37 typing_extensions==4.12.2 Werkzeug==3.1.3 +gunicorn==20.1.0 +Flask-Bcrypt==1.0.1 \ No newline at end of file diff --git a/templates/dashboard.html b/templates/dashboard.html index 03bc970..e86e88f 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -81,6 +81,11 @@
Manage Group Full Screen + {% if current_user.role == 'admin' %} +
+ +
+ {% endif %}
{% endfor %}