diff --git a/database.py b/database.py new file mode 100644 index 0000000..6b495d3 --- /dev/null +++ b/database.py @@ -0,0 +1,45 @@ +import os, sys, sqlite3 + +# Existenz feststellen +if os.path.exists("party.db"): + print("Datei bereits vorhanden") + sys.exit(0) + +# Verbindung zur Datenbank erzeugen +connection = sqlite3.connect("party.db") +cursor = connection.cursor() + +sql = "CREATE TABLE user(" \ + "userID INTEGER NOT NULL UNIQUE PRIMARY KEY, " \ + "username TEXT, " \ + "sessionID INTEGER, " \ + "info TEXT);" +cursor.execute(sql) + +sql = "CREATE TABLE session(" \ + "sessionID INTEGER NOT NULL UNIQUE PRIMARY KEY, " \ + "sessionname TEXT);" +cursor.execute(sql) + +sql = "CREATE TABLE chat(" \ + "sessionID INTEGER " \ + "userID INTEGER " \ + "Chatmessage TEXT, " \ + "Zeit TEXT);" +cursor.execute(sql) + +sql = "CREATE TABLE game(" \ + "sessionID INTEGER " \ + "userID INTEGER " \ + "Spielname TEXT, " \ + "Zeit TEXT);" +cursor.execute(sql) + +sql = "CREATE TABLE planer(" \ + "event TEXT " \ + "zeit INTEGER " \ + "sessionID INTEGER);" +cursor.execute(sql) + + +connection.close() \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..7b14f4d --- /dev/null +++ b/main.py @@ -0,0 +1,143 @@ +from flask import Flask, render_template, jsonify, request, session, redirect +import sqlite3 +import time + +app = Flask(__name__, template_folder='templates/') +date = time.strftime("%d-%m-%Y %H:%M:%S", time.localtime(time.time())) +log = date +app.config['SECRET_KEY'] = 'party' + + +def log_server(log): + log = date + log + datei = open('server.log', 'a') + datei.write('\n' + " " + log) + log = date + datei.close() + +@app.route("/") +def index(): + log_server("called /") + return render_template("index.html") + +@app.route("/chat") +def chat(): + log_server("called /chat") + return render_template("chat.html") + +@app.route("/planer") +def planer(): + log_server("called /planer") + return render_template("planer.html") + +@app.route("/session") +def session(): + log_server("called /session") + return render_template("session.html") + +@app.route("/logout") +def logout(): + log_server("called /logout") + return render_template("logout.html") + +@app.route("/signin") +def signin(): + log_server("called /signin") + return render_template("signin.html") + +@app.route("/password") +def password(): + log_server("called /password") + return render_template("passwort_ver.html") + +@app.route("/create_session") +def create_session(): + log_server("called /create_session") + return render_template("createSession.html") + +@app.route("/get_creat_session", methods=['POST']) +def get_creat_session(): + con = sqlite3.connect("party.db") + cur = con.cursor() + log_server("called /get_creat_session with POST") + + sessionname = request.form['sessionname'] + sessionID = request.form['sessionid'] + l = f"INSERT INTO session VALUES( \'{sessionID}\', \'{sessionname}\');" + + cur.execute(l) + account = cur.fetchone() + return redirect('/session') + + +@app.route("/login") +def login(): + log_server("called /login") + return render_template("login.html") + +@app.route("/stopuhr", methods=['POST']) +def stopuhr(): + con = sqlite3.connect("party.db") + cur = con.cursor() + log_server("called /stopuhr") + spielName = request.form['spielname'] + zeit = request.form['zeit'] + userId = request.form['userid'] + sessionId = request.form['sessionid'] + l = f"INSERT INTO game VALUES( \'{sessionID}\', \'{sessionname}\');" + return render_template("login.html") + +@app.route("/get_event", methods=['POST']) +def get_event(): + con = sqlite3.connect("party.db") + cur = con.cursor() + log_server("called /get_event") + event = request.form['event'] + zeit = request.form['zeit'] + sessionId = request.form['sessionid'] + l = f"INSERT INTO game VALUES( \'{sessionID}\', \'{sessionname}\');" + return render_template("login.html") + +@app.route("/controll") +def controll(): + log_server("called /login") + return render_template("controll.html") + +@app.route("/rgb") +def rgb(): + log_server("called /rgb") + return render_template("404.html") + + +@app.route("/get_login", methods=['POST']) +def get_login(): + con = sqlite3.connect("login.db") + cur = con.cursor() + log_server("called /get_login with POST") + + username = request.form['uname'] + sessionId = request.form['id'] + l = f"select * from user where username = \'{username}\' and id=\'{sessionId}\';" + + cur.execute(l) + account = cur.fetchone() + + if account: + session['loggedin'] = True + # session['username'] = account['username'] + return redirect('/session') + else: + return "{ \"message\": \"Login failed\"'}" + con.close() + +@app.errorhandler(404) +def page_not_found(e): + log_server("called non-existing page") + # note that we set the 404 status explicitly + return render_template('404.html'), 404 + + +def create_app(config_filename): + app.register_error_handler(404, page_not_found) + log_server("created app") + return app diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 663bd1f..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -requests \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..f787c15 --- /dev/null +++ b/run.sh @@ -0,0 +1,8 @@ +python3 database.py +export FLASK_APP=main.py +if [ -z $@ ]; then + echo "please pass browser as argument, pass _, to get rid of this warning" + exit 0 +fi + +sleep 3& $@ 127.0.0.1:5000& flask run \ No newline at end of file diff --git a/setup.py b/setup.py index 0b7a6a7..e330cc4 100644 --- a/setup.py +++ b/setup.py @@ -1,41 +1,23 @@ from argparse import ArgumentParser -import argparse import os import shutil -from webserver import general -sessionname = " " -qinput = " " -typ = " " - - -# Session erstellen +sessionname = "Test Session" +dateiname = sessionname + '.py' def create_session(): - - if not os.path.exists(sessionname): + if not os.path.exists(sessionname): os.makedirs(sessionname) - - if not os.path.exists('sammlung'): - os.makedirs('sammlung') - general(sessionname, typ) -# Bereits bestehende Session laden + shutil.copy('webserver.py', dateiname) + shutil.move(dateiname, sessionname) + + + + +""" def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--help', help='foo help') - args = parser.parse_args() + parser = ArgumentParser(description='Lan Party Management') +""" if __name__ == "__main__": - print("[T]emp Session [C]reate Session") - qinput = input("Modus: ") sessionname = input("Session Name: ") - if (qinput == "T" or qinput == "t"): - typ = "t" - general(sessionname, typ) - - if (qinput == "C" or qinput == "c"): - typ = "n" - create_session() - - - - \ No newline at end of file + create_session() \ No newline at end of file diff --git a/static/img/Balloons.png b/static/img/Balloons.png new file mode 100644 index 0000000..7648aea Binary files /dev/null and b/static/img/Balloons.png differ diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..4aee8f5 --- /dev/null +++ b/templates/404.html @@ -0,0 +1,24 @@ + + + oops something went wrong + + + + + + +
+

404

+

Page not found

+

oops something went wrong

+

This Page you are loocking for doesn't exist or an other error occurred.

+Go back +
+ + \ No newline at end of file diff --git a/templates/chat.html b/templates/chat.html new file mode 100644 index 0000000..f2c77d1 --- /dev/null +++ b/templates/chat.html @@ -0,0 +1,20 @@ + + + + + + + Chat + + + +

Chat

+ + + \ No newline at end of file diff --git a/templates/controll.html b/templates/controll.html new file mode 100644 index 0000000..4773a5f --- /dev/null +++ b/templates/controll.html @@ -0,0 +1,93 @@ + + + ⚙️ controll + + + + + + +
+

Einstellungen

+

Diese können später auch verändert werden

+
+

Setze eine Fabe für die LEDs

+ + + +
+
+

Planer

+

Füge ein Event ein

+
+
+

User Verwaltung

+

An dieser Stelle sollen später die User angezeigt werden, und der Session Admin kann diese dann verwalten

+
+ + + +
+ + \ No newline at end of file diff --git a/templates/createSession.html b/templates/createSession.html new file mode 100644 index 0000000..cfba578 --- /dev/null +++ b/templates/createSession.html @@ -0,0 +1,65 @@ + + + Create Session + + + + + + +

Create Session

+ +
+ + + + + + + +
+ + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..5799c4a --- /dev/null +++ b/templates/index.html @@ -0,0 +1,61 @@ + + + + +🎉 Party + + + + + + + + + + +

Willkommen beim Party-Controller

+ + + +
+ + + + + + + + +
+ + + + diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..54fffe7 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,84 @@ + + + Join Session + + + + + + +

Join Session

+
+

Adios

+
+ + + +
+ + \ No newline at end of file diff --git a/templates/passwort_ver.html b/templates/passwort_ver.html new file mode 100644 index 0000000..7956543 --- /dev/null +++ b/templates/passwort_ver.html @@ -0,0 +1,19 @@ + + + Passwort vergessen + + + + + + +

Please Contact the Session Admin

+ Go back
+ + \ No newline at end of file diff --git a/templates/planer.html b/templates/planer.html new file mode 100644 index 0000000..4614a20 --- /dev/null +++ b/templates/planer.html @@ -0,0 +1,19 @@ + + + + + + + Planer + + + +

Planer

+ + \ No newline at end of file diff --git a/web/index.html b/templates/session.html similarity index 81% rename from web/index.html rename to templates/session.html index 753a785..3d9217e 100644 --- a/web/index.html +++ b/templates/session.html @@ -6,6 +6,7 @@ + - + + + + + +

Party

+

+

Stopuhr

00:00

+ + @@ -206,6 +238,8 @@ margin: 10px;
+ + @@ -232,4 +266,4 @@ margin: 10px; - \ No newline at end of file + diff --git a/templates/signin.html b/templates/signin.html new file mode 100644 index 0000000..aaa5eb6 --- /dev/null +++ b/templates/signin.html @@ -0,0 +1,19 @@ + + + + + + + + + +

Signin

+ + + \ No newline at end of file diff --git a/web/create_user.html b/web/create_user.html deleted file mode 100644 index 7c3442c..0000000 --- a/web/create_user.html +++ /dev/null @@ -1,8 +0,0 @@ - - -Create User - - - - - \ No newline at end of file diff --git a/web/login.html b/web/login.html deleted file mode 100644 index 1bc1f7c..0000000 --- a/web/login.html +++ /dev/null @@ -1,8 +0,0 @@ - - -Login - - - - - \ No newline at end of file diff --git a/webserver.py b/webserver.py deleted file mode 100644 index a782f08..0000000 --- a/webserver.py +++ /dev/null @@ -1,141 +0,0 @@ -from http.server import HTTPServer, BaseHTTPRequestHandler -from argparse import ArgumentParser -import http.server -import socketserver -import time -import logging -import os, sys, sqlite3 -from urllib import parse -import json -import requests -import shutil - -PORT = 8000 -date = time.strftime("%d-%m-%Y %H:%M:%S", time.localtime(time.time())) -log = date -sessionID = "/S1" -dbstatus = "Null" -sessionConfig = "F" -name = "f" -sessionart = " " - -def create_DB(): - if os.path.exists("party.db"): - print("Datei bereits vorhanden") - sys.exit(0) - - # Verbindung zur Datenbank erzeugen - connection = sqlite3.connect("party.db") - - # Datensatz-Cursor erzeugen - cursor = connection.cursor() - - # Erzeuge Tabelle Spiel - sql = "CREATE TABLE spiel(" \ - "username TEXT, " \ - "Spiel TEXT, " \ - "Zeit TEXT, " \ - "info TEXT)" - cursor.execute(sql) - # Erzeuge Tabelle Session - sql = "CREATE TABLE session(" \ - "Sessionname TEXT, " \ - "Spieler TEXT, " \ - "Datum TEXT, " \ - "info TEXT)" - cursor.execute(sql) - - -class Serve(BaseHTTPRequestHandler): -# In Zukunft soll es hier möglich sein, RGB Stripes zu steuern - def led_controll(): - print("in development") - - def log_server(self, log): - datei = open('server.log','a') - datei.write('\n' + " " + log ) - log = date - datei.close() -# Endpoints - def do_GET(self): - if self.path == '/': - self.path = '/web/index.html' - if self.path == '/signin': - self.path == '/web/create_user.html' - if self.path == '/login': - self.path == '/web/login.html' - if self.path == sessionID: - self.path == '/web/session.html' - - - - try: - file_to_open = open(self.path[1:]).read() - self.send_response(200) - log = date + " 200" - # datei.write('\n' + " " + date) - except: - file_to_open = "File not found" - self.send_response(400) - log = date + " " +file_to_open - finally: - - self.log_server(log) - - - self.end_headers() - self.wfile.write(bytes(file_to_open, 'utf-8')) - - parsed = parse.urlparse(self.path) - - def do_POST(self): - - try: - self.send_responses(200) - self.send_header("Content-type", "application/json") - self.end_headers() - - self.wfile(bytes('{"time": "' + date + '"}',"utf-8")) - except: - self.send_response(400) - #print("POST error") - -def general(name, sessionart): - if (sessionart == "n"): - ordner = '/sammlung/' + name - name2 = '2' + name - create_DB() - - try: - httpd = HTTPServer(('0.0.0.0', PORT), Serve) - print("server is now running on http://127.0.0.1:" + str(PORT)) - httpd.serve_forever() - except KeyboardInterrupt: - pass - #Server beenden, und Datein speichern/in Sammlung schieben - httpd.server_close() - print("\nServer stopped.") - print("saving files") - shutil.move('party.db', name) - if os.path.exists('server.log'): - shutil.move('server.log', name) - if not os.path.exists(ordner): - shutil.move(name, 'sammlung') - else: - shutil.copy(name, name2) - shutil.move(name2, 'sammlung') - else: - try: - httpd = HTTPServer(('0.0.0.0', PORT), Serve) - print("server is now running on http://127.0.0.1:" + str(PORT)) - httpd.serve_forever() - except KeyboardInterrupt: - pass - #Server beenden, und Datein speichern/in Sammlung schieben - httpd.server_close() - print("\nServer stopped.") - print("removing files") - os.remove('server.log') - os.remove('party.db') - -