Initial commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# Externe MySQL-Datenbank
|
||||
DB_HOST=10.10.10.155
|
||||
DB_PORT=3306
|
||||
DB_USER=tu_skyevouchers
|
||||
DB_PASSWORD=5AkYQusc[ju3*05L
|
||||
DB_NAME=skyevouchers
|
||||
|
||||
# Admin-Bereich
|
||||
ADMIN_PASSWORD=uIVa8yJe01w56gLY4JkkBqj5*lt7UL&z
|
||||
|
||||
# Flask Session-Schlüssel (langen zufälligen String verwenden)
|
||||
SECRET_KEY=r@B33sY6jya0u*UcqZ$*0Db9PZORNcHJ
|
||||
|
||||
# Gotify-Benachrichtigungen
|
||||
GOTIFY_URL=https://push.re.dfined.net
|
||||
GOTIFY_TOKEN=AiZmp5jTp0pip70
|
||||
@@ -0,0 +1,16 @@
|
||||
# Externe MySQL-Datenbank
|
||||
DB_HOST=10.10.10.155
|
||||
DB_PORT=3306
|
||||
DB_USER=tu_skyevouchers
|
||||
DB_PASSWORD=5AkYQusc[ju3*05L
|
||||
DB_NAME=skyevouchers
|
||||
|
||||
# Admin-Bereich
|
||||
ADMIN_PASSWORD=uIVa8yJe01w56gLY4JkkBqj5*lt7UL&z
|
||||
|
||||
# Flask Session-Schlüssel (langen zufälligen String verwenden)
|
||||
SECRET_KEY=r@B33sY6jya0u*UcqZ$*0Db9PZORNcHJ
|
||||
|
||||
# Gotify-Benachrichtigungen
|
||||
GOTIFY_URL=https://push.re.dfined.net
|
||||
GOTIFY_TOKEN=AiZmp5jTp0pip70
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM python:3.12-slim
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
COPY . .
|
||||
EXPOSE 5000
|
||||
CMD ["python", "app.py"]
|
||||
@@ -0,0 +1,66 @@
|
||||
# skyevouchers
|
||||
|
||||
Web-App zur Ausgabe von UniFi Hotspot-Vouchers mit Admin-Backend.
|
||||
|
||||
## Features
|
||||
- **Frontend**: Zeigt einen Voucher-Code mit Slot-Maschinen-Animation an
|
||||
- **Einmalig**: Jeder Code kann nur einmal verwendet werden
|
||||
- **Admin** (`/admin`): Passwort-geschütztes Dashboard
|
||||
- Voucher-Import per Paste aus UniFi-Export
|
||||
- Übersicht verfügbarer & verwendeter Vouchers
|
||||
- **Gotify-Benachrichtigung** wenn ≤ 2 Vouchers übrig sind
|
||||
- MySQL-Datenbank
|
||||
|
||||
## Schnellstart mit Docker
|
||||
|
||||
```bash
|
||||
# 1. Repo klonen / Dateien kopieren
|
||||
# 2. .env erstellen
|
||||
cp .env.example .env
|
||||
# .env anpassen (Passwörter, Gotify-URL etc.)
|
||||
|
||||
# 3. Starten
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
Die App läuft dann auf `http://localhost:5000`
|
||||
Admin: `http://localhost:5000/admin`
|
||||
|
||||
## Ohne Docker (lokal)
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Umgebungsvariablen setzen (oder .env manuell sourcen)
|
||||
export DB_HOST=localhost
|
||||
export DB_USER=root
|
||||
export DB_PASSWORD=...
|
||||
export DB_NAME=skyevouchers
|
||||
export ADMIN_PASSWORD=geheim
|
||||
export GOTIFY_URL=http://gotify:8080
|
||||
export GOTIFY_TOKEN=abc123
|
||||
|
||||
python app.py
|
||||
```
|
||||
|
||||
## Vouchers importieren
|
||||
|
||||
1. In UniFi → Vouchers exportieren (als Text kopieren)
|
||||
2. Admin-Bereich öffnen (`/admin`)
|
||||
3. Text in das Import-Feld einfügen → „Vouchers extrahieren & importieren"
|
||||
|
||||
Das Format wird automatisch erkannt: `GUESTS64071-58673 1 day ...`
|
||||
Extrahiert werden Codes im Format `XXXXX-XXXXX`.
|
||||
|
||||
## Umgebungsvariablen
|
||||
|
||||
| Variable | Standard | Beschreibung |
|
||||
|-----------------|---------------------|---------------------------|
|
||||
| `DB_HOST` | `localhost` | MySQL-Host |
|
||||
| `DB_USER` | `root` | MySQL-Benutzer |
|
||||
| `DB_PASSWORD` | *(leer)* | MySQL-Passwort |
|
||||
| `DB_NAME` | `skyevouchers` | Datenbankname |
|
||||
| `ADMIN_PASSWORD`| `admin123` | Admin-Login-Passwort |
|
||||
| `SECRET_KEY` | *(default)* | Flask Session Secret |
|
||||
| `GOTIFY_URL` | `http://localhost:8080` | Gotify-Basis-URL |
|
||||
| `GOTIFY_TOKEN` | *(leer)* | Gotify App-Token |
|
||||
@@ -0,0 +1,186 @@
|
||||
from flask import Flask, render_template, request, jsonify, session, redirect, url_for, flash
|
||||
import mysql.connector
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
import random
|
||||
import string
|
||||
from datetime import datetime
|
||||
from functools import wraps
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = os.environ.get('SECRET_KEY', 'skyevouchers-secret-key-2024')
|
||||
|
||||
# Config
|
||||
DB_CONFIG = {
|
||||
'host': os.environ.get('DB_HOST', 'localhost'),
|
||||
'port': int(os.environ.get('DB_PORT', 3306)),
|
||||
'user': os.environ.get('DB_USER', 'root'),
|
||||
'password': os.environ.get('DB_PASSWORD', ''),
|
||||
'database': os.environ.get('DB_NAME', 'skyevouchers'),
|
||||
}
|
||||
ADMIN_PASSWORD = os.environ.get('ADMIN_PASSWORD', 'admin123')
|
||||
GOTIFY_URL = os.environ.get('GOTIFY_URL', 'http://localhost:8080')
|
||||
GOTIFY_TOKEN = os.environ.get('GOTIFY_TOKEN', '')
|
||||
LOW_VOUCHER_THRESHOLD = 2
|
||||
|
||||
|
||||
def get_db():
|
||||
return mysql.connector.connect(**DB_CONFIG)
|
||||
|
||||
|
||||
def init_db():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
c.execute('''CREATE TABLE IF NOT EXISTS vouchers (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
code VARCHAR(20) NOT NULL UNIQUE,
|
||||
used BOOLEAN DEFAULT FALSE,
|
||||
used_at DATETIME NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def send_gotify_notification(remaining):
|
||||
if not GOTIFY_TOKEN:
|
||||
return
|
||||
try:
|
||||
requests.post(
|
||||
f"{GOTIFY_URL}/message",
|
||||
json={
|
||||
"title": "⚠️ Skye Vouchers – Niedriger Bestand",
|
||||
"message": f"Nur noch {remaining} Voucher(s) verfügbar! Bitte neue Vouchers hinzufügen.",
|
||||
"priority": 8
|
||||
},
|
||||
params={"token": GOTIFY_TOKEN},
|
||||
timeout=5
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def login_required(f):
|
||||
@wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
if not session.get('admin_logged_in'):
|
||||
return redirect(url_for('admin_login'))
|
||||
return f(*args, **kwargs)
|
||||
return decorated
|
||||
|
||||
|
||||
# ── Frontend ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@app.route('/api/get-voucher', methods=['POST'])
|
||||
def get_voucher():
|
||||
conn = get_db()
|
||||
c = conn.cursor(dictionary=True)
|
||||
c.execute('SELECT id, code FROM vouchers WHERE used = FALSE ORDER BY RAND() LIMIT 1')
|
||||
voucher = c.fetchone()
|
||||
if not voucher:
|
||||
conn.close()
|
||||
return jsonify({'error': 'Keine Vouchers mehr verfügbar'}), 404
|
||||
|
||||
c.execute('UPDATE vouchers SET used = TRUE, used_at = %s WHERE id = %s',
|
||||
(datetime.now(), voucher['id']))
|
||||
conn.commit()
|
||||
|
||||
# Check remaining
|
||||
c.execute('SELECT COUNT(*) AS cnt FROM vouchers WHERE used = FALSE')
|
||||
remaining = c.fetchone()['cnt']
|
||||
conn.close()
|
||||
|
||||
if remaining <= LOW_VOUCHER_THRESHOLD:
|
||||
send_gotify_notification(remaining)
|
||||
|
||||
return jsonify({'code': voucher['code']})
|
||||
|
||||
|
||||
# ── Admin ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@app.route('/admin/login', methods=['GET', 'POST'])
|
||||
def admin_login():
|
||||
if request.method == 'POST':
|
||||
if request.form.get('password') == ADMIN_PASSWORD:
|
||||
session['admin_logged_in'] = True
|
||||
return redirect(url_for('admin_dashboard'))
|
||||
flash('Falsches Passwort', 'error')
|
||||
return render_template('admin_login.html')
|
||||
|
||||
|
||||
@app.route('/admin/logout')
|
||||
def admin_logout():
|
||||
session.clear()
|
||||
return redirect(url_for('admin_login'))
|
||||
|
||||
|
||||
@app.route('/admin')
|
||||
@login_required
|
||||
def admin_dashboard():
|
||||
conn = get_db()
|
||||
c = conn.cursor(dictionary=True)
|
||||
c.execute('SELECT COUNT(*) AS cnt FROM vouchers WHERE used = FALSE')
|
||||
available = c.fetchone()['cnt']
|
||||
c.execute('SELECT COUNT(*) AS cnt FROM vouchers WHERE used = TRUE')
|
||||
used_count = c.fetchone()['cnt']
|
||||
c.execute('SELECT COUNT(*) AS cnt FROM vouchers')
|
||||
total = c.fetchone()['cnt']
|
||||
c.execute('SELECT code, used_at FROM vouchers WHERE used = TRUE ORDER BY used_at DESC LIMIT 20')
|
||||
recent_used = c.fetchall()
|
||||
c.execute('SELECT code, created_at FROM vouchers WHERE used = FALSE ORDER BY created_at DESC LIMIT 20')
|
||||
available_vouchers = c.fetchall()
|
||||
conn.close()
|
||||
return render_template('admin_dashboard.html',
|
||||
available=available,
|
||||
used_count=used_count,
|
||||
total=total,
|
||||
recent_used=recent_used,
|
||||
available_vouchers=available_vouchers)
|
||||
|
||||
|
||||
@app.route('/admin/import', methods=['POST'])
|
||||
@login_required
|
||||
def admin_import():
|
||||
text = request.form.get('voucher_text', '')
|
||||
# Extract codes matching xxxxx-xxxxx (5 digits, dash, 5 digits)
|
||||
codes = re.findall(r'\b(\d{5}-\d{5})\b', text)
|
||||
if not codes:
|
||||
flash('Keine gültigen Voucher-Codes gefunden.', 'error')
|
||||
return redirect(url_for('admin_dashboard'))
|
||||
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
imported = 0
|
||||
skipped = 0
|
||||
for code in codes:
|
||||
try:
|
||||
c.execute('INSERT INTO vouchers (code) VALUES (%s)', (code,))
|
||||
imported += 1
|
||||
except mysql.connector.IntegrityError:
|
||||
skipped += 1
|
||||
conn.commit()
|
||||
conn.close()
|
||||
flash(f'{imported} Voucher(s) importiert, {skipped} bereits vorhanden.', 'success')
|
||||
return redirect(url_for('admin_dashboard'))
|
||||
|
||||
|
||||
@app.route('/admin/delete/<int:vid>', methods=['POST'])
|
||||
@login_required
|
||||
def admin_delete(vid):
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
c.execute('DELETE FROM vouchers WHERE id = %s', (vid,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'ok': True})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_db()
|
||||
app.run(debug=True, host='0.0.0.0', port=5000)
|
||||
@@ -0,0 +1,16 @@
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
restart: always
|
||||
ports:
|
||||
- "8088:5000"
|
||||
environment:
|
||||
DB_HOST: ${DB_HOST}
|
||||
DB_PORT: ${DB_PORT:-3306}
|
||||
DB_USER: ${DB_USER}
|
||||
DB_PASSWORD: ${DB_PASSWORD}
|
||||
DB_NAME: ${DB_NAME}
|
||||
ADMIN_PASSWORD: ${ADMIN_PASSWORD:-admin123}
|
||||
GOTIFY_URL: ${GOTIFY_URL:-http://localhost:8080}
|
||||
GOTIFY_TOKEN: ${GOTIFY_TOKEN:-}
|
||||
SECRET_KEY: ${SECRET_KEY:-change-me-in-production}
|
||||
@@ -0,0 +1,3 @@
|
||||
flask>=3.0.0
|
||||
mysql-connector-python>=8.3.0
|
||||
requests>=2.31.0
|
||||
@@ -0,0 +1,241 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Dashboard · skyevouchers</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=Space+Mono:wght@400;700&display=swap');
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
:root {
|
||||
--bg: #07080f; --surface: #0e1018; --surface2: #11141f;
|
||||
--border: #1e2133; --accent: #5b6cff; --accent2: #a78bfa;
|
||||
--glow: rgba(91,108,255,.2); --text: #e8eaf6; --muted: #5a5e7a;
|
||||
--code-bg: #12152a; --success: #4ade80; --warning: #fbbf24; --danger: #f87171;
|
||||
}
|
||||
body {
|
||||
background: var(--bg); color: var(--text);
|
||||
font-family: 'Space Grotesk', sans-serif; min-height: 100vh;
|
||||
}
|
||||
body::before {
|
||||
content: ''; position: fixed; inset: 0;
|
||||
background-image: linear-gradient(rgba(91,108,255,.03) 1px, transparent 1px),
|
||||
linear-gradient(90deg, rgba(91,108,255,.03) 1px, transparent 1px);
|
||||
background-size: 48px 48px; pointer-events: none; z-index: 0;
|
||||
}
|
||||
|
||||
/* Nav */
|
||||
nav {
|
||||
position: sticky; top: 0; z-index: 100;
|
||||
background: rgba(7,8,15,.9); backdrop-filter: blur(12px);
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding: 0 2rem;
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
height: 60px;
|
||||
}
|
||||
.nav-brand {
|
||||
font-family: 'Space Mono', monospace; font-size: .75rem;
|
||||
font-weight: 700; letter-spacing: .3em; text-transform: uppercase; color: var(--muted);
|
||||
}
|
||||
.nav-brand span { color: var(--accent); }
|
||||
.nav-right { display: flex; align-items: center; gap: 1rem; }
|
||||
.badge { font-size: .7rem; background: rgba(91,108,255,.15); color: var(--accent2);
|
||||
padding: .25rem .7rem; border-radius: 999px; border: 1px solid rgba(91,108,255,.3); }
|
||||
.nav-logout {
|
||||
font-size: .8rem; color: var(--muted); text-decoration: none;
|
||||
padding: .4rem .9rem; border: 1px solid var(--border); border-radius: 8px;
|
||||
transition: color .2s, border-color .2s;
|
||||
}
|
||||
.nav-logout:hover { color: var(--danger); border-color: var(--danger); }
|
||||
|
||||
/* Layout */
|
||||
main { position: relative; z-index: 1; padding: 2rem; max-width: 1200px; margin: 0 auto; }
|
||||
|
||||
/* Stats */
|
||||
.stats {
|
||||
display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 1rem; margin-bottom: 2rem;
|
||||
}
|
||||
.stat-card {
|
||||
background: var(--surface); border: 1px solid var(--border);
|
||||
border-radius: 14px; padding: 1.4rem 1.6rem;
|
||||
}
|
||||
.stat-label { font-size: .7rem; letter-spacing: .15em; text-transform: uppercase; color: var(--muted); margin-bottom: .5rem; }
|
||||
.stat-value { font-family: 'Space Mono', monospace; font-size: 2.2rem; font-weight: 700; }
|
||||
.stat-value.green { color: var(--success); }
|
||||
.stat-value.blue { color: var(--accent2); }
|
||||
.stat-value.warn { color: var(--warning); }
|
||||
|
||||
/* Sections */
|
||||
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
|
||||
@media(max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
|
||||
|
||||
.panel {
|
||||
background: var(--surface); border: 1px solid var(--border);
|
||||
border-radius: 16px; overflow: hidden;
|
||||
}
|
||||
.panel-header {
|
||||
padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
}
|
||||
.panel-title { font-size: .8rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
|
||||
.panel-body { padding: 1.5rem; }
|
||||
|
||||
/* Import */
|
||||
textarea {
|
||||
width: 100%; min-height: 160px;
|
||||
background: var(--code-bg); border: 1px solid var(--border);
|
||||
border-radius: 10px; color: var(--text); resize: vertical;
|
||||
font-family: 'Space Mono', monospace; font-size: .8rem; line-height: 1.6;
|
||||
padding: 1rem; outline: none; transition: border-color .2s;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
textarea:focus { border-color: var(--accent); }
|
||||
.btn {
|
||||
padding: .75rem 1.5rem;
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent2));
|
||||
color: #fff; font-family: 'Space Grotesk', sans-serif;
|
||||
font-size: .85rem; font-weight: 600; border: none;
|
||||
border-radius: 10px; cursor: pointer; transition: opacity .2s;
|
||||
box-shadow: 0 0 20px rgba(91,108,255,.25);
|
||||
}
|
||||
.btn:hover { opacity: .9; }
|
||||
.btn-sm {
|
||||
padding: .3rem .7rem; font-size: .75rem; border-radius: 6px;
|
||||
}
|
||||
.btn-danger {
|
||||
background: rgba(248,113,113,.15); color: var(--danger);
|
||||
border: 1px solid rgba(248,113,113,.25);
|
||||
font-family: 'Space Grotesk', sans-serif;
|
||||
font-size: .75rem; font-weight: 500;
|
||||
border-radius: 6px; padding: .3rem .7rem;
|
||||
cursor: pointer; transition: background .2s;
|
||||
}
|
||||
.btn-danger:hover { background: rgba(248,113,113,.25); }
|
||||
|
||||
/* Alerts */
|
||||
.alert { font-size: .85rem; padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1.5rem; }
|
||||
.alert-success { color: var(--success); background: rgba(74,222,128,.08); border: 1px solid rgba(74,222,128,.2); }
|
||||
.alert-error { color: var(--danger); background: rgba(248,113,113,.08); border: 1px solid rgba(248,113,113,.2); }
|
||||
|
||||
/* Table */
|
||||
.table-wrap { overflow-x: auto; max-height: 320px; overflow-y: auto; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
thead th {
|
||||
position: sticky; top: 0;
|
||||
font-size: .7rem; letter-spacing: .1em; text-transform: uppercase;
|
||||
color: var(--muted); font-weight: 600; padding: .6rem 1rem;
|
||||
background: var(--surface); border-bottom: 1px solid var(--border);
|
||||
text-align: left;
|
||||
}
|
||||
tbody tr { border-bottom: 1px solid rgba(30,33,51,.6); transition: background .15s; }
|
||||
tbody tr:last-child { border-bottom: none; }
|
||||
tbody tr:hover { background: rgba(91,108,255,.04); }
|
||||
td { padding: .65rem 1rem; font-size: .85rem; }
|
||||
.code-cell { font-family: 'Space Mono', monospace; font-size: .85rem; color: var(--accent2); letter-spacing: .1em; }
|
||||
.date-cell { color: var(--muted); font-size: .78rem; }
|
||||
.empty { text-align: center; color: var(--muted); padding: 2rem; font-size: .85rem; }
|
||||
|
||||
/* Import full width */
|
||||
.import-panel { margin-bottom: 1.5rem; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav>
|
||||
<div class="nav-brand">sky<span>e</span>vouchers <span style="color:var(--border);margin:0 .5rem">/</span> <span style="color:var(--text)">Admin</span></div>
|
||||
<div class="nav-right">
|
||||
<span class="badge">{{ available }} verfügbar</span>
|
||||
<a href="{{ url_for('admin_logout') }}" class="nav-logout">Abmelden</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main>
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% for cat, msg in messages %}
|
||||
<div class="alert alert-{{ 'success' if cat == 'success' else 'error' }}">{{ msg }}</div>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
|
||||
<!-- Stats -->
|
||||
<div class="stats">
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Verfügbar</div>
|
||||
<div class="stat-value green">{{ available }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Verwendet</div>
|
||||
<div class="stat-value warn">{{ used_count }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Gesamt</div>
|
||||
<div class="stat-value blue">{{ total }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Import -->
|
||||
<div class="panel import-panel">
|
||||
<div class="panel-header">
|
||||
<div class="panel-title">Vouchers importieren</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form method="POST" action="{{ url_for('admin_import') }}">
|
||||
<textarea name="voucher_text" placeholder="UniFi Voucher-Export hier einfügen… Beispiel: GUESTS64071-58673 1 day Single-use…"></textarea>
|
||||
<button type="submit" class="btn">Vouchers extrahieren & importieren</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tables -->
|
||||
<div class="grid2">
|
||||
<!-- Available -->
|
||||
<div class="panel">
|
||||
<div class="panel-header">
|
||||
<div class="panel-title">Verfügbare Vouchers</div>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
{% if available_vouchers %}
|
||||
<table>
|
||||
<thead><tr><th>Code</th><th>Erstellt</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{% for v in available_vouchers %}
|
||||
<tr id="row-avail-{{ loop.index }}">
|
||||
<td class="code-cell">{{ v.code }}</td>
|
||||
<td class="date-cell">{{ v.created_at.strftime('%d.%m.%Y %H:%M') if v.created_at else '—' }}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<div class="empty">Keine verfügbaren Vouchers</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Used -->
|
||||
<div class="panel">
|
||||
<div class="panel-header">
|
||||
<div class="panel-title">Zuletzt verwendet</div>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
{% if recent_used %}
|
||||
<table>
|
||||
<thead><tr><th>Code</th><th>Verwendet am</th></tr></thead>
|
||||
<tbody>
|
||||
{% for v in recent_used %}
|
||||
<tr>
|
||||
<td class="code-cell">{{ v.code }}</td>
|
||||
<td class="date-cell">{{ v.used_at.strftime('%d.%m.%Y %H:%M') if v.used_at else '—' }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<div class="empty">Noch keine Vouchers verwendet</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,82 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin · skyevouchers</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=Space+Mono:wght@400;700&display=swap');
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
:root {
|
||||
--bg: #07080f; --surface: #0e1018; --border: #1e2133;
|
||||
--accent: #5b6cff; --accent2: #a78bfa; --glow: rgba(91,108,255,.35);
|
||||
--text: #e8eaf6; --muted: #5a5e7a; --code-bg: #12152a;
|
||||
}
|
||||
body {
|
||||
min-height: 100vh; background: var(--bg); color: var(--text);
|
||||
font-family: 'Space Grotesk', sans-serif;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
}
|
||||
body::before {
|
||||
content: ''; position: fixed; inset: 0;
|
||||
background-image: linear-gradient(rgba(91,108,255,.04) 1px, transparent 1px),
|
||||
linear-gradient(90deg, rgba(91,108,255,.04) 1px, transparent 1px);
|
||||
background-size: 48px 48px; pointer-events: none;
|
||||
}
|
||||
.card {
|
||||
position: relative; z-index: 1;
|
||||
background: var(--surface); border: 1px solid var(--border);
|
||||
border-radius: 20px; padding: 2.5rem 3rem; width: 100%; max-width: 400px;
|
||||
box-shadow: 0 0 80px rgba(0,0,0,.6), 0 0 120px var(--glow);
|
||||
display: flex; flex-direction: column; gap: 1.5rem;
|
||||
}
|
||||
.logo {
|
||||
font-family: 'Space Mono', monospace; font-size: .7rem; font-weight: 700;
|
||||
letter-spacing: .3em; text-transform: uppercase; color: var(--muted);
|
||||
text-align: center;
|
||||
}
|
||||
.logo span { color: var(--accent); }
|
||||
h1 { font-size: 1.3rem; font-weight: 600; text-align: center; }
|
||||
label { font-size: .8rem; color: var(--muted); letter-spacing: .05em; display: block; margin-bottom: .4rem; }
|
||||
input[type=password] {
|
||||
width: 100%; padding: .85rem 1rem;
|
||||
background: var(--code-bg); border: 1px solid var(--border);
|
||||
border-radius: 10px; color: var(--text);
|
||||
font-family: 'Space Grotesk', sans-serif; font-size: .95rem;
|
||||
outline: none; transition: border-color .2s;
|
||||
}
|
||||
input[type=password]:focus { border-color: var(--accent); }
|
||||
.btn {
|
||||
width: 100%; padding: .9rem;
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent2));
|
||||
color: #fff; font-family: 'Space Grotesk', sans-serif;
|
||||
font-size: .95rem; font-weight: 600; border: none;
|
||||
border-radius: 10px; cursor: pointer;
|
||||
box-shadow: 0 0 30px rgba(91,108,255,.3);
|
||||
transition: opacity .2s;
|
||||
}
|
||||
.btn:hover { opacity: .9; }
|
||||
.alert {
|
||||
font-size: .85rem; color: #f87171; text-align: center;
|
||||
padding: .7rem; background: rgba(248,113,113,.08);
|
||||
border: 1px solid rgba(248,113,113,.2); border-radius: 8px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="card">
|
||||
<div class="logo">sky<span>e</span>vouchers</div>
|
||||
<h1>Admin-Bereich</h1>
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% for cat, msg in messages %}
|
||||
<div class="alert">{{ msg }}</div>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
<form method="POST">
|
||||
<label>Passwort</label>
|
||||
<input type="password" name="password" autofocus required style="margin-bottom:1.2rem">
|
||||
<button type="submit" class="btn">Anmelden</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,383 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>skyevouchers</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=Space+Mono:wght@400;700&display=swap');
|
||||
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
:root {
|
||||
--bg: #07080f;
|
||||
--surface: #0e1018;
|
||||
--border: #1e2133;
|
||||
--accent: #5b6cff;
|
||||
--accent2: #a78bfa;
|
||||
--glow: rgba(91,108,255,.35);
|
||||
--text: #e8eaf6;
|
||||
--muted: #5a5e7a;
|
||||
--code-bg: #12152a;
|
||||
--success: #4ade80;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: 'Space Grotesk', sans-serif;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Background grid */
|
||||
body::before {
|
||||
content: '';
|
||||
position: fixed; inset: 0;
|
||||
background-image:
|
||||
linear-gradient(rgba(91,108,255,.04) 1px, transparent 1px),
|
||||
linear-gradient(90deg, rgba(91,108,255,.04) 1px, transparent 1px);
|
||||
background-size: 48px 48px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Ambient glow */
|
||||
body::after {
|
||||
content: '';
|
||||
position: fixed;
|
||||
top: -20%; left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 700px; height: 500px;
|
||||
background: radial-gradient(ellipse, rgba(91,108,255,.12) 0%, transparent 70%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.stage {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
/* Logo / wordmark */
|
||||
.wordmark {
|
||||
font-family: 'Space Mono', monospace;
|
||||
font-size: .85rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: .05em;
|
||||
color: var(--muted);
|
||||
margin-bottom: 2rem;
|
||||
position: relative;
|
||||
}
|
||||
.wordmark span { color: var(--accent); }
|
||||
|
||||
/* Card */
|
||||
.card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 24px;
|
||||
padding: 2rem 1.5rem;
|
||||
width: 100%;
|
||||
max-width: 480px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 2rem;
|
||||
box-shadow: 0 0 60px rgba(0,0,0,.5), 0 0 120px var(--glow);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.card-label {
|
||||
font-size: .7rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: .2em;
|
||||
text-transform: uppercase;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
/* Slot display */
|
||||
.slot-wrap {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.slot-display {
|
||||
background: var(--code-bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 14px;
|
||||
padding: 1.2rem 1rem;
|
||||
font-family: 'Space Mono', monospace;
|
||||
font-size: clamp(1.1rem, 5.5vw, 2rem);
|
||||
font-weight: 700;
|
||||
letter-spacing: .08em;
|
||||
color: var(--text);
|
||||
text-align: center;
|
||||
min-height: 80px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
transition: border-color .3s, box-shadow .3s;
|
||||
}
|
||||
|
||||
.slot-display.rolling {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 24px var(--glow);
|
||||
}
|
||||
|
||||
.slot-display.done {
|
||||
border-color: var(--success);
|
||||
box-shadow: 0 0 24px rgba(74,222,128,.25);
|
||||
}
|
||||
|
||||
/* Rolling characters */
|
||||
.slot-chars {
|
||||
display: flex;
|
||||
gap: .1em;
|
||||
align-items: center;
|
||||
}
|
||||
.slot-char {
|
||||
display: inline-block;
|
||||
transition: none;
|
||||
}
|
||||
.slot-char.rolling {
|
||||
animation: charRoll .06s linear infinite;
|
||||
}
|
||||
@keyframes charRoll {
|
||||
0% { transform: translateY(0); opacity: 1; }
|
||||
50% { transform: translateY(-4px); opacity: .5; }
|
||||
100% { transform: translateY(0); opacity: 1; }
|
||||
}
|
||||
|
||||
.placeholder-text { color: var(--muted); font-size: 1rem; letter-spacing: .1em; }
|
||||
|
||||
/* Buttons */
|
||||
.btn-primary {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent2));
|
||||
color: #fff;
|
||||
font-family: 'Space Grotesk', sans-serif;
|
||||
font-size: .95rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: .05em;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
transition: opacity .2s, transform .1s, box-shadow .2s;
|
||||
box-shadow: 0 0 30px rgba(91,108,255,.3);
|
||||
}
|
||||
.btn-primary:hover { opacity: .9; box-shadow: 0 0 40px rgba(91,108,255,.5); }
|
||||
.btn-primary:active { transform: scale(.98); }
|
||||
.btn-primary:disabled { opacity: .4; cursor: not-allowed; transform: none; }
|
||||
|
||||
.btn-copy {
|
||||
width: 100%;
|
||||
padding: .85rem;
|
||||
background: transparent;
|
||||
color: var(--accent2);
|
||||
font-family: 'Space Grotesk', sans-serif;
|
||||
font-size: .9rem;
|
||||
font-weight: 500;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
transition: background .2s, border-color .2s, color .2s;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: .5rem;
|
||||
}
|
||||
.btn-copy:hover { background: rgba(167,139,250,.08); border-color: var(--accent2); }
|
||||
.btn-copy.copied { color: var(--success); border-color: var(--success); background: rgba(74,222,128,.06); }
|
||||
|
||||
.actions { width: 100%; display: flex; flex-direction: column; gap: .75rem; }
|
||||
|
||||
.error-msg {
|
||||
font-size: .85rem;
|
||||
color: #f87171;
|
||||
text-align: center;
|
||||
padding: .75rem 1rem;
|
||||
background: rgba(248,113,113,.08);
|
||||
border: 1px solid rgba(248,113,113,.2);
|
||||
border-radius: 10px;
|
||||
width: 100%;
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Footer */
|
||||
.footer {
|
||||
margin-top: 2.5rem;
|
||||
font-size: .7rem;
|
||||
color: var(--muted);
|
||||
letter-spacing: .05em;
|
||||
opacity: .5;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="stage">
|
||||
<div class="wordmark">sky<span>e</span>vouchers.</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-label">WLAN-Zugangscode</div>
|
||||
|
||||
<div class="slot-wrap">
|
||||
<div class="slot-display" id="slotDisplay">
|
||||
<span class="placeholder-text" id="placeholder">— — — — —</span>
|
||||
<div class="slot-chars" id="slotChars" style="display:none"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="error-msg" id="errorMsg"></div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn-primary" id="btnGet">Voucher generieren</button>
|
||||
<button class="btn-copy" id="btnCopy" style="display:none">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
|
||||
<span id="copyLabel">Code kopieren</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">Einmaliger Zugangscode · Für WLAN-Authentifizierung</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
let currentCode = null;
|
||||
let isRolling = false;
|
||||
|
||||
const slotDisplay = document.getElementById('slotDisplay');
|
||||
const slotChars = document.getElementById('slotChars');
|
||||
const placeholder = document.getElementById('placeholder');
|
||||
const btnGet = document.getElementById('btnGet');
|
||||
const btnCopy = document.getElementById('btnCopy');
|
||||
const copyLabel = document.getElementById('copyLabel');
|
||||
const errorMsg = document.getElementById('errorMsg');
|
||||
|
||||
function showError(msg) {
|
||||
errorMsg.textContent = msg;
|
||||
errorMsg.style.display = 'block';
|
||||
}
|
||||
function hideError() {
|
||||
errorMsg.style.display = 'none';
|
||||
}
|
||||
|
||||
function buildSlotChars(code) {
|
||||
slotChars.innerHTML = '';
|
||||
for (const ch of code) {
|
||||
const span = document.createElement('span');
|
||||
span.className = 'slot-char';
|
||||
span.textContent = ch === '-' ? '-' : ch;
|
||||
if (ch !== '-') span.dataset.final = ch;
|
||||
slotChars.appendChild(span);
|
||||
}
|
||||
}
|
||||
|
||||
function randomChar() {
|
||||
return CHARS[Math.floor(Math.random() * CHARS.length)];
|
||||
}
|
||||
|
||||
function animateSlot(finalCode, duration = 1400) {
|
||||
return new Promise(resolve => {
|
||||
placeholder.style.display = 'none';
|
||||
slotChars.style.display = 'flex';
|
||||
buildSlotChars(finalCode);
|
||||
|
||||
const spans = [...slotChars.querySelectorAll('.slot-char[data-final]')];
|
||||
slotDisplay.classList.add('rolling');
|
||||
|
||||
// Start all spinning
|
||||
spans.forEach(s => {
|
||||
s.classList.add('rolling');
|
||||
s.textContent = randomChar();
|
||||
});
|
||||
|
||||
const interval = setInterval(() => {
|
||||
spans.forEach(s => {
|
||||
if (s.classList.contains('rolling')) s.textContent = randomChar();
|
||||
});
|
||||
}, 60);
|
||||
|
||||
// Stop characters one by one with stagger
|
||||
const stagger = duration / (spans.length + 2);
|
||||
spans.forEach((s, i) => {
|
||||
const delay = stagger * (i + 1) + 200;
|
||||
setTimeout(() => {
|
||||
s.classList.remove('rolling');
|
||||
s.textContent = s.dataset.final;
|
||||
}, delay);
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
clearInterval(interval);
|
||||
slotDisplay.classList.remove('rolling');
|
||||
slotDisplay.classList.add('done');
|
||||
resolve();
|
||||
}, duration + 300);
|
||||
});
|
||||
}
|
||||
|
||||
btnGet.addEventListener('click', async () => {
|
||||
if (isRolling) return;
|
||||
isRolling = true;
|
||||
hideError();
|
||||
btnGet.disabled = true;
|
||||
btnCopy.style.display = 'none';
|
||||
slotDisplay.classList.remove('done');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/get-voucher', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Fehler');
|
||||
|
||||
currentCode = data.code;
|
||||
await animateSlot(currentCode);
|
||||
|
||||
btnGet.style.display = 'none';
|
||||
btnCopy.style.display = 'flex';
|
||||
} catch (e) {
|
||||
showError(e.message);
|
||||
btnGet.disabled = false;
|
||||
placeholder.style.display = 'flex';
|
||||
slotChars.style.display = 'none';
|
||||
} finally {
|
||||
isRolling = false;
|
||||
}
|
||||
});
|
||||
|
||||
btnCopy.addEventListener('click', () => {
|
||||
if (!currentCode) return;
|
||||
function onCopied() {
|
||||
copyLabel.textContent = 'Kopiert!';
|
||||
btnCopy.classList.add('copied');
|
||||
setTimeout(() => {
|
||||
copyLabel.textContent = 'Code kopieren';
|
||||
btnCopy.classList.remove('copied');
|
||||
}, 2000);
|
||||
}
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(currentCode).then(onCopied).catch(() => fallbackCopy());
|
||||
} else {
|
||||
fallbackCopy();
|
||||
}
|
||||
function fallbackCopy() {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = currentCode;
|
||||
ta.style.cssText = 'position:fixed;opacity:0;top:0;left:0';
|
||||
document.body.appendChild(ta);
|
||||
ta.focus(); ta.select();
|
||||
try { document.execCommand('copy'); onCopied(); } catch(e) {}
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user