This commit is contained in:
fingadumbledore 2022-10-19 10:58:01 +02:00
parent 204fa34c02
commit 6e09268a3f
20 changed files with 685 additions and 192 deletions

45
database.py Normal file
View File

@ -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()

143
main.py Normal file
View File

@ -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

View File

@ -1 +0,0 @@
requests

8
run.sh Executable file
View File

@ -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

View File

@ -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()
create_session()

BIN
static/img/Balloons.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB

24
templates/404.html Normal file
View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<head>
<title>oops something went wrong</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
Body {
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
</style>
</head>
<body>
<center>
<h1>404</h1>
<h2>Page not found</h2>
<h2>oops something went wrong</h2>
<p>This Page you are loocking for doesn't exist or an other error occurred.</p>
<a href="javascript:history.back()">Go back</a>
</center>
</body>
</html>

20
templates/chat.html Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat</title>
<style>
Body {
background-image: linear-gradient(to right, rgb(89, 89, 175), rgb(38, 134, 62))
}
</style>
</head>
<body>
<center><h1>Chat</h1></center>
</body>
</html>

93
templates/controll.html Normal file
View File

@ -0,0 +1,93 @@
<html>
<head>
<title> &#x2699;&#xFE0F; controll</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
Body {
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
button {
background-color: #4CAF50;
width: 10%;
color: orange;
padding: 15px;
margin: 10px 0px;
border: none;
cursor: pointer;
border-radius: 12px;
}
input[type=text], input[type=password] {
width: 20%;
margin: 8px 0;
padding: 12px 20px;
display: inline-block;
border: 2px solid green;
box-sizing: border-box;
border-radius: 12px;
color: #839c87;
}
button:hover {
opacity: 0.7;
}
.cancelbtn {
width: auto;
background-color: red;
border: 2px solid red;
padding: 10px 18px;
margin: 10px 5px;
}
.container {
padding: 25px;
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
</style>
</head>
<body>
<center>
<h1>Einstellungen</h1>
<p>Diese können später auch verändert werden</p>
<div id="LED">
<h3>Setze eine Fabe für die LEDs</h3>
<label for="colorpicker">Led Streifen:</label>
<input type="color" id="colorpicker" value="#0000ff">
</div>
<div id="Planer">
<h3>Planer</h3>
<p>Füge ein Event ein</p>
<form class="modal-content animate" action="http://127.0.0.1:5000/get_event" method="POST">
<div class="container">
<input type="text" placeholder="Tomb Raider spielen" name="event" required>
<input type="text" placeholder="15:30" name="zeit" required>
<button type="submit">hinzufügen</button>
<a href="javascript:history.back()">
<button type="button" class="cancelbtn"> Cancel</button>
</div>
</div>
<div id="userVerwaltung">
<h1>User Verwaltung</h1>
<p>An dieser Stelle sollen später die User angezeigt werden, und der Session Admin kann diese dann verwalten</p>
</div>
<button onclick="save()">Änderungen speichern</button>
<script>
function save(){
}
</script>
</center>
</body>
</html>

View File

@ -0,0 +1,65 @@
<html>
<head>
<title>Create Session</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
Body {
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
button {
background-color: #4CAF50;
width: 100%;
color: orange;
padding: 15px;
margin: 10px 0px;
border: none;
cursor: pointer;
border-radius: 12px;
}
form {
}
input[type=text], input[type=password] {
width: 100%;
margin: 8px 0;
padding: 12px 20px;
display: inline-block;
border: 2px solid green;
box-sizing: border-box;
}
button:hover {
opacity: 0.7;
}
.cancelbtn {
width: auto;
padding: 10px 18px;
margin: 10px 5px;
}
.container {
padding: 25px;
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
</style>
</head>
<body>
<center><h1>Create Session</h1></center>
<form class="modal-content animate" action="http://127.0.0.1:5000//get_creat_session" method="POST">
<div class="container">
<label>Session name : </label>
<input type="text" placeholder="Enter Session name" name="sessionname" required>
<label>Session Id : </label>
<input type="text" placeholder="Session Id" name="sessionid" required>
<button type="submit">create</button>
<a href="javascript:history.back()">
<button type="button" class="cancelbtn"> Cancel</button>
</div>
</form>
</body>
</html>

61
templates/index.html Normal file
View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="de">
<html>
<head>
<title>&#127881; Party</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<style>
body {font-family: Arial, Helvetica, sans-serif;
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
button {
background-color: #4CAF50;
width: 100%;
color: orange;
padding: 15px;
margin: 10px 0px;
border: none;
cursor: pointer;
border-radius: 12px;
}
footer {
text-align: center;
padding: 3px;
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175));
color: black;
}
</style>
<body>
<center><h1>Willkommen beim Party-Controller</h1></center>
<a href="http://127.0.0.1:5000/login">
<button class="btn btn-primary btn-lg">Join Session</button>
</a>
<a href="http://127.0.0.1:5000/create_session">
<button class="btn btn-primary btn-lg">Create Session</button>
</a>
<center><img src="/static/img/Balloons.png" width="250" height="600"></center>
<footer>
<p>Version: 0.1</p>
<p>Created By fingadumbledore<br>
<a target="_blank" href="https://www.github.com/fingadumbledore/party">github</a></p>
</footer>
</body>
</html>

84
templates/login.html Normal file
View File

@ -0,0 +1,84 @@
<html>
<head>
<title>Join Session</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
Body {
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
button {
background-color: #4CAF50;
width: 100%;
color: orange;
padding: 15px;
margin: 10px 0px;
border: none;
cursor: pointer;
border-radius: 12px;
}
input[type=text], input[type=password] {
width: 100%;
margin: 8px 0;
padding: 12px 20px;
display: inline-block;
border: 2px solid green;
box-sizing: border-box;
border-radius: 12px;
color: #839c87;
}
button:hover {
opacity: 0.7;
}
.cancelbtn {
width: auto;
padding: 10px 18px;
margin: 10px 5px;
}
.container {
padding: 25px;
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
</style>
</head>
<body>
<center><h1>Join Session</h1></center>
<form class="modal-content animate" action="http://127.0.0.1:5000/get_login" method="POST">
<div class="container">
<label>SessionId : </label>
<input type="text" placeholder="Enter Username" name="username" required>
<label>Session Id : </label>
<input type="text" placeholder="Session Id" name="id" required>
<button type="submit">Login</button>
<a href="javascript:history.back()">
<button type="button" class="cancelbtn"> Cancel</button>
</div>
</form>
<script src="html5-qrcode.min.js"></script>
<div style="width: 500px" id="reader"></div>
<script>
var html5QrcodeScanner = new Html5QrcodeScanner(
"reader", { fps: 10, qrbox: 250 });
function onScanSuccess(decodedText, decodedResult) {
// Handle on success condition with the decoded text or result.
console.log(`Scan result: ${decodedText}`, decodedResult);
// ...
html5QrcodeScanner.clear();
// ^ this will stop the scanner (video feed) and clear the scan area.
}
html5QrcodeScanner.render(onScanSuccess);
</script>
</body>
</html>

35
templates/logout.html Normal file
View File

@ -0,0 +1,35 @@
<html>
<head>
<title>logout</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
Body {
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
button {
background-color: #4CAF50;
width: 100%;
color: orange;
padding: 15px;
margin: 10px 0px;
border: none;
cursor: pointer;
border-radius: 12px;
}
</style>
</head>
<body>
<center>
<h1>Adios</h1>
<a href="http://127.0.0.1:5000/">
<button class="btn btn-primary btn-lg">Home</button>
</a>
</center>
</body>
</html>

View File

@ -0,0 +1,19 @@
<html>
<head>
<title>Passwort vergessen</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
Body {
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
</style>
</head>
<body>
<center><h1>Please Contact the Session Admin</h1>
<a href="javascript:history.back()">Go back</a></center>
</body>
</html>

19
templates/planer.html Normal file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Planer</title>
<style>
Body {
background-image: linear-gradient(to right, rgb(89, 89, 175), rgb(38, 134, 62))
}
</style>
</head>
<body>
<center><h1>Planer</h1></center>
</body>
</html>

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<script>
var modal = document.getElementById('id01');
@ -81,6 +82,10 @@ window.onload = function () {
}
</script>
<style>
a {
text-decoration: none;
}
body {font-family: Arial, Helvetica, sans-serif;
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
@ -155,7 +160,7 @@ text-decoration:none;
cursor:pointer;
font-size:1.2em;
padding:18px 10px;
width:180px;
width:80px;
margin: 10px;
outline: none;
&:hover{
@ -190,15 +195,42 @@ margin: 10px;
color: white;
}
input[type=text], input[type=password] {
width: 30%;
margin: 8px 0;
padding: 12px 20px;
display: inline-block;
border: 2px solid green;
box-sizing: border-box;
border-radius: 12px;
color: #839c87;
}
</style>
<body>
<a href="http://127.0.0.1:5000/logout">
<button class="btn btn-primary btn-lg">Logout</button>
</a>
<a href="http://127.0.0.1:5000/controll">&#x2699;</a>
<center><h1>Party</h1></center>
<center> <div id="current_date"></p>
<script>
date = new Date();
year = date.getFullYear();
month = date.getMonth() + 1;
day = date.getDate();
document.getElementById("current_date").innerHTML = month + "/" + day + "/" + year;
</script></div><center>
<div class="wrapper">
<h3>Stopuhr</h3>
<p><span id="seconds">00</span>:<span id="tens">00</span></p>
<label>Enter Game name:</label>
<input type="text" name="name">
<button id="button-start">Start</button>
<button id="button-stop">Stop</button>
<button id="button-reset">Reset</button>
@ -206,6 +238,8 @@ margin: 10px;
</div>
<iframe id="ifr" src="/chat" width="750" height="500" frameBorder="0" src= pfad></iframe>
<table id="customers">
@ -232,4 +266,4 @@ margin: 10px;
<tr>
</body>
</html>
</html>

19
templates/signin.html Normal file
View File

@ -0,0 +1,19 @@
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
Body {
background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
</style>
</head>
<body>
<h1>Signin</h1>
</body>
</html>

View File

@ -1,8 +0,0 @@
<!DOCTYPE html>
<head>
<titl>Create User</titl>
</head>
<body>
</body>
</html>

View File

@ -1,8 +0,0 @@
<!DOCTYPE html>
<head>
<titl>Login</titl>
</head>
<body>
</body>
</html>

View File

@ -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')