diff --git a/Dockerfile b/Dockerfile index 5df601d..7d969af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,13 +8,10 @@ WORKDIR /opt/app COPY . /opt/app/ # Install any needed packages specified in requirements.txt -RUN pip install --no-cache-dir Flask requests python-dotenv beautifulsoup4 +RUN pip install --no-cache-dir Flask requests python-dotenv beautifulsoup4 gunicorn # Make port 8182 available to the world outside this container EXPOSE 8182 -# Define environment variable -ENV FLASK_APP=metaproxy.py - -# Run app.py when the container launches -CMD ["flask", "run", "--host=0.0.0.0", "--port=8182"] +# Run Gunicorn +CMD ["gunicorn", "--bind", "0.0.0.0:8182", "app:app"] diff --git a/metaproxy.py b/app.py similarity index 69% rename from metaproxy.py rename to app.py index 3f70781..c685a9d 100644 --- a/metaproxy.py +++ b/app.py @@ -1,13 +1,39 @@ import os import requests -from flask import Flask, Response, request +from flask import Flask, Response, render_template, request, redirect, url_for from dotenv import load_dotenv from bs4 import BeautifulSoup +app = Flask(__name__) + # Load environment variables from .env file load_dotenv() -app = Flask(__name__) +# Mock data for configuration +config = { + "excluded_countries": os.getenv('EXCLUDED_COUNTRIES', '[]'), + "preferred_protocols": os.getenv('PREFERRED_PROTOCOLS', '["https", "http"]'), + "preferred_types": os.getenv('PREFERRED_TYPES', '["https", "http"]'), + "min_preference": os.getenv('MIN_PREFERENCE', '0') +} + +@app.route('/dash/config', methods=['GET', 'POST']) +def config(): + if request.method == 'POST': + config['excluded_countries'] = request.form['excluded_countries'] + config['preferred_protocols'] = request.form['preferred_protocols'] + config['preferred_types'] = request.form['preferred_types'] + config['min_preference'] = request.form['min_preference'] + return redirect(url_for('config')) + return render_template('config.html', **config) + +@app.route('/dash/stats') +def stats(): + return render_template('stats.html') + +@app.route('/dash/logs') +def logs(): + return render_template('logs.html') @app.route('/metalink') def get_metalink(): diff --git a/docker-compose.yml b/docker-compose.yml index 2a6197c..3dde647 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,4 @@ +version: '3.8' services: metaproxy: @@ -7,5 +8,6 @@ services: volumes: - ./data:/opt/app/data environment: - - FLASK_ENV=development + - FLASK_ENV=production restart: unless-stopped + diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..77e9f32 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,31 @@ + + + + + + MetaProxy Dashboard + + + +
+ +
+ {% block content %} + {% endblock %} +
+
+ + + + + diff --git a/templates/config.html b/templates/config.html new file mode 100644 index 0000000..aca79d7 --- /dev/null +++ b/templates/config.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} + +{% block content %} +
+

Configuration

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+{% endblock %} diff --git a/templates/logs.html b/templates/logs.html new file mode 100644 index 0000000..ac7b58d --- /dev/null +++ b/templates/logs.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} + +{% block content %} +
+

Error Logs

+

Error logs content goes here.

+
+{% endblock %} diff --git a/templates/stats.html b/templates/stats.html new file mode 100644 index 0000000..49ad036 --- /dev/null +++ b/templates/stats.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} + +{% block content %} +
+

Statistics

+

Statistics content goes here.

+
+{% endblock %}