Files
Hellas-Wawi/README.md
Bjoern Welker aa0de2fe4a feat: add payment tracking for orders
- Add payment method selection (PayPal/Bar) to order form
- Store payment_method and payment_status in database
- Add payment status badges in admin orders view
- Add "mark as paid" functionality for admins
- PayPal account configurable via PAYPAL_ACCOUNT env variable
- Frontend loads PayPal account dynamically from /wawi/config endpoint
- Update email notifications to include payment method

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-09 08:28:33 +01:00

187 lines
6.0 KiB
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Hellas Bestand & WaWi
## Überblick
Dieses Repository enthält:
- **WaWiApp** (Flask + SQLite) für Artikelverwaltung, Ausbuchen, Verkäufe und Bestellungen.
- **LiveShopAnsicht** (`index.html`) lädt Daten aus der WaWiApp.
- **ImportScript** für Daten aus der ursprünglichen `hellas_bestand.html`.
## Struktur
- `wawi/app.py` FlaskApp (CRUD, Ausbuchen, Verkäufe, Benutzerverwaltung)
- `wawi/templates/` HTMLTemplates der WaWiApp
- `wawi/static/` Styles + Logo
- `wawi/hellas.db` SQLiteDatenbank (wird automatisch erstellt)
- `wawi/import_from_html.py` Import aus `hellas_bestand.html`
- `index.html` LiveShopAnsicht (ruft `/wawi/proxy/bestand`)
## WaWi lokal starten
```bash
cd wawi
python3 -m venv .venv
source .venv/bin/activate
pip install flask gunicorn
python app.py
```
Standardzugriff: Login über Benutzerverwaltung (siehe unten).
## Developer (ENV variablen)
Diese App liest Konfiguration ausschließlich aus Umgebungsvariablen.
Für lokale Entwicklung kannst du sie direkt im Shell-Session setzen oder
eine `.env`-Datei in dein Startup-Script laden.
Minimal sinnvoll für lokal:
- `SECRET_KEY` Session-Secret (beliebiger String)
- `APP_USER` / `APP_PASSWORD` initialer Admin-User
- `URL_PREFIX` leer lassen, wenn lokal ohne Sub-Pfad
Für Bestellungen per Mail zusätzlich:
- `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASS`
- `SMTP_FROM`, `ORDER_TO`
Optional:
- `APP_API_KEY` Schutz fuer `/wawi/api/bestand` und `/wawi/order`
- `COOKIE_SECURE` `0` fuer http lokal, `1` fuer https
- `PAYPAL_ACCOUNT` PayPal-E-Mail für Bestellformular (z.B. `paypal@beispiel.de`)
## Benutzerverwaltung
Beim ersten Start wird **ein Admin** aus ENV erzeugt:
- `APP_USER` (default: `admin`)
- `APP_PASSWORD` (default: `admin`)
Passwörter werden **gehasht** gespeichert.
Über `/users` können weitere Benutzer angelegt und Passwörter zurückgesetzt werden.
## Import aus hellas_bestand.html
```bash
cd wawi
python import_from_html.py /pfad/zu/hellas_bestand.html --truncate
```
## LiveShopAnsicht (index.html)
`index.html` lädt den Bestand aus der WaWiApp:
- APIProxy: `/wawi/proxy/bestand`
- Konfiguration: `/wawi/config` (lädt PayPal-Konto aus ENV)
Wenn du diese Datei auf einem Webserver auslieferst, stelle sicher, dass die WaWiApp unter `/wawi` erreichbar ist.
Wenn du Bestellungen direkt aus `index.html` abschickst, muss der `X-Order-Key` bzw. `?key=` dem `APP_API_KEY` entsprechen.
Der Key wird in `index.html` im ScriptBlock gesetzt: `const ORDER_KEY = ""`. Trage dort deinen Key ein (oder leer lassen, wenn kein API-Key erforderlich).
Das PayPal-Konto wird automatisch aus der ENV-Variable `PAYPAL_ACCOUNT` geladen.
## Umgebungsvariablen (ENV)
**Pflicht/Empfohlen für Produktion**
- `SECRET_KEY` SessionSecret
- `APP_USER` / `APP_PASSWORD` initialer AdminUser
- `URL_PREFIX` z. B. `/wawi` (wenn hinter SubPfad)
**EMail (Bestellungen)**
- `SMTP_HOST` SMTPServer
- `SMTP_PORT` z. B. `587`
- `SMTP_USER` / `SMTP_PASS` SMTP Login
- `SMTP_FROM` Absender (z. B. `bestand@hellas.welker.me`)
- `ORDER_TO` Empfänger, mehrere per Komma
**Optional**
- `APP_API_KEY` gemeinsamer APIKey für `/wawi/api/bestand` **und** `/wawi/order`
- `COOKIE_SECURE` `1` (default) setzt SecureCookie, `0` deaktiviert für http
- `PAYPAL_ACCOUNT` PayPal-E-Mail-Adresse für Bestellungen (wird im Bestellformular angezeigt)
## Deployment (systemd + Gunicorn)
1) App nach `/var/www/hellas/wawi` kopieren
2) venv erstellen:
```bash
cd /var/www/hellas/wawi
python3 -m venv .venv
source .venv/bin/activate
pip install flask gunicorn
```
3) ServiceDatei anlegen: `/etc/systemd/system/hellas.service`
```
[Unit]
Description=Hellas WaWi
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/hellas/wawi
Environment="PATH=/var/www/hellas/wawi/.venv/bin"
Environment="URL_PREFIX=/wawi"
Environment="SECRET_KEY=DEIN_SECRET"
Environment="APP_USER=admin"
Environment="APP_PASSWORD=starkesPasswort"
Environment="SMTP_HOST=smtp.example.com"
Environment="SMTP_PORT=587"
Environment="SMTP_USER=dein_user"
Environment="SMTP_PASS=dein_pass"
Environment="SMTP_FROM=bestand@example.com"
Environment="ORDER_TO=admin@example.com, zweite@example.com"
Environment="APP_API_KEY=api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Environment="PAYPAL_ACCOUNT=dein-paypal@beispiel.de"
ExecStart=/var/www/hellas/wawi/.venv/bin/gunicorn -w 3 -b 127.0.0.1:8000 app:app
Restart=always
[Install]
WantedBy=multi-user.target
```
4) Aktivieren:
```bash
sudo systemctl daemon-reload
sudo systemctl enable --now hellas
```
## Nginx (ReverseProxy + ShopSeite)
Beispiel `/etc/nginx/sites-available/hellas`:
```
server {
listen 80;
server_name hellas.welker.me;
location = / {
root /var/www/hellas;
try_files /index.html =404;
}
location /wawi/ {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
Aktivieren:
```bash
sudo ln -s /etc/nginx/sites-available/hellas /etc/nginx/sites-enabled/hellas
sudo nginx -t
sudo systemctl reload nginx
```
## SSL (Lets Encrypt)
```bash
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d hellas.welker.me
```
## Dateirechte (SQLite + Uploads)
```bash
sudo chown -R www-data:www-data /var/www/hellas/wawi
sudo chmod 750 /var/www/hellas/wawi
sudo chmod 640 /var/www/hellas/wawi/hellas.db
sudo mkdir -p /var/www/hellas/wawi/static/uploads
sudo chown -R www-data:www-data /var/www/hellas/wawi/static/uploads
```
## FixPermissions Script (inkl. Uploads)
`/root/fix_wawi_permissions.sh` sollte auch das UploadVerzeichnis setzen:
```bash
#!/bin/sh
set -e
chown -R www-data:www-data /var/www/hellas/wawi
chmod 750 /var/www/hellas/wawi
chmod 640 /var/www/hellas/wawi/hellas.db
mkdir -p /var/www/hellas/wawi/static/uploads
chown -R www-data:www-data /var/www/hellas/wawi/static/uploads
systemctl restart hellas
```