Browse Source

Implementing server as standalone docker image

Kirk Trombley 5 years ago
parent
commit
c776453483
5 changed files with 24 additions and 130 deletions
  1. 0 68
      index.html
  2. 16 0
      server/Dockerfile
  3. 3 7
      server/app.py
  4. 5 10
      server/requirements.txt
  5. 0 45
      templates/embedded_body.html

+ 0 - 68
index.html

@@ -1,68 +0,0 @@
-<!doctype html>
-<title>Teamspeak Server Status</title>
-<style>
-    body {
-        margin: 0px 0px 0px 0px;
-        padding: 0px 0px 0px 0px;
-        font-family: verdana, arial, helvetica, sans-serif;
-        color: #ccc;
-        background-color: #333;
-    }
-    #bounceBox {
-        position: absolute;
-        top: 0;
-        right: 0;
-        bottom: 0;
-        left: 0;
-    }
-    #bouncer {
-        position: absolute;
-    }
-</style>
-<script>
-    // JS adapted from
-    // https://stackoverflow.com/questions/6152522/how-can-i-make-a-paragraph-bounce-around-in-a-div
-    let vx = 3;
-    let vy = 2;
-    const buffer = 5;
-
-    const hitLR = (el, bounding) => {
-        if (el.offsetLeft <= buffer && vx < 0) {
-            vx = -1 * vx;
-        }
-        if ((el.offsetLeft + el.offsetWidth) >= (bounding.offsetWidth - buffer)) {
-            vx = -1 * vx;
-        }
-        if (el.offsetTop <= buffer && vy < 0) {
-            vy = -1 * vy;
-        }
-        if ((el.offsetTop + el.offsetHeight) >= (bounding.offsetHeight - buffer)) {
-            vy = -1 * vy;
-        }
-    }
-
-    const mover = (el, bounding) => {
-        hitLR(el, bounding);
-        el.style.left = el.offsetLeft + vx + 'px';
-        el.style.top = el.offsetTop + vy + 'px';
-        setTimeout(function() {
-            mover(el, bounding);
-        }, 30);
-    }
-
-    setTimeout(() => mover(
-        document.getElementById("bouncer"),
-        document.getElementById("bounceBox")
-    ), 30);
-
-    // makes the iframe have the appropriate height
-    const resizeIframe = (obj) => {
-        obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
-        obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px';
-    }
-</script>
-<body>
-    <div id="bounceBox">
-        <iframe id="bouncer" frameborder="0" src="https://kirkleon.ddns.net/teamspeak/page" scrolling="no" onload="resizeIframe(this)"></iframe>
-    </div>
-</body>

+ 16 - 0
server/Dockerfile

@@ -0,0 +1,16 @@
+FROM python:3.8
+
+RUN pip install --upgrade pip gunicorn
+
+ENV TS_SECRET_FILE /secret/secret.toml
+
+WORKDIR /app
+
+EXPOSE 5000
+
+ADD requirements.txt .
+RUN pip install -r requirements.txt
+
+ADD app.py .
+
+CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:5000"]

+ 3 - 7
server/app.py

@@ -2,12 +2,13 @@
 
 import tempfile
 import os.path
+import os
 from telnetlib import Telnet
 from collections import defaultdict
 from datetime import timedelta
 
 import toml
-from flask import Flask, jsonify, render_template, request
+from flask import Flask, jsonify, request
 from flask_cors import CORS
 
 IDLE_TIMEOUT = timedelta(minutes=5)
@@ -16,7 +17,7 @@ REFRESH_RATE = 60 # seconds
 app = Flask(__name__)
 CORS(app)
 
-with open("secret.toml") as infile:
+with open(os.environ.get("TS_SECRET_FILE", "secret.toml")) as infile:
     cfg = toml.load(infile)
 for k in ("host", "port", "user", "pass"):
     app.config[k] = cfg[k]
@@ -148,11 +149,6 @@ def get_status():
     return jsonify({"users": [u.replace(r"\s", " ") for u in get_users()[0]]})
 
 
-@app.route("/page")
-def get_status_page():
-    return render_template("embedded_body.html", users={k: [u.replace(r"\s", " ") for u in v] for k, v in get_users()[1].items()}, refresh_rate=REFRESH_RATE)
-
-
 @app.route("/audiobot", methods=["POST"])
 def message_audiobot():
     temp_dir = tempfile.mkdtemp()

+ 5 - 10
server/requirements.txt

@@ -1,14 +1,9 @@
-certifi==2019.3.9
-chardet==3.0.4
-Click==7.0
-Flask==1.0.3
+click==7.1.1
+Flask==1.1.2
 Flask-Cors==3.0.8
-idna==2.8
 itsdangerous==1.1.0
-Jinja2==2.10.1
+Jinja2==2.11.1
 MarkupSafe==1.1.1
-requests==2.22.0
-six==1.12.0
+six==1.14.0
 toml==0.10.0
-urllib3==1.25.3
-Werkzeug==0.15.4
+Werkzeug==1.0.1

+ 0 - 45
templates/embedded_body.html

@@ -1,45 +0,0 @@
-<!-- This page is used as an iframe in the main page -->
-<!-- This allows it to auto-refresh without interrupting the bouncing -->
-<meta http-equiv="refresh" content="{{ refresh_rate }}">
-<style>
-    h1 {
-        font-size: 24px;
-        line-height: 44px;
-        font-weight: bold;
-        margin-top: 0;
-        margin-bottom: 0;
-    }
-    h2 {
-        font-size: 18px;
-        line-height: 20px;
-        margin-top: 0;
-        margin-left: 15px;
-        margin-bottom: -10px;
-    }
-</style>
-<script type="text/javascript">
-    // Inherits the styling from the page embedding this
-    window.onload = function() {
-        if (parent) {
-            var oHead = document.getElementsByTagName("head")[0];
-            var arrStyleSheets = parent.document.getElementsByTagName("style");
-            for (var i = 0; i < arrStyleSheets.length; i++)
-                oHead.appendChild(arrStyleSheets[i].cloneNode(true));
-        }
-    }
-</script>
-<body>
-    <h1>TeamSpeak Server Status</h1>
-    {% if users|length == 0 %}
-    No one in teamspeak!
-    {% else %}
-        {% for channel, people in users.items() %}
-            <h2>{{ channel }}</h2>
-            <ul>
-            {% for user in people %}
-                <li>{{ user }}</li>
-            {% endfor %}
-            </ul>
-        {% endfor %}
-    {% endif %}
-</body>