This commit is contained in:
root 2025-03-12 12:33:05 +01:00
parent 6cdc437d3e
commit 3972860be8
185 changed files with 33 additions and 27 deletions

0
Dokumentation.md Normal file → Executable file
View File

0
LICENSE.md Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
archiv/NETWORK-api-backend_blueprint/.env Normal file → Executable file
View File

0
archiv/NETWORK-api-backend_blueprint/README.md Normal file → Executable file
View File

View File

0
archiv/NETWORK-api-backend_blueprint/requirements.txt Normal file → Executable file
View File

0
archiv/NETWORK-api-backend_blueprint/server.py Normal file → Executable file
View File

View File

0
archiv/backend/myp_backend.db Normal file → Executable file
View File

0
archiv/backend/myp_backend.py Normal file → Executable file
View File

0
archiv/backend/templates/base.html Normal file → Executable file
View File

0
archiv/backend/templates/dashboard.html Normal file → Executable file
View File

0
archiv/backend/templates/login.html Normal file → Executable file
View File

0
archiv/flask-backend/.env Normal file → Executable file
View File

0
archiv/flask-backend/.env.example Normal file → Executable file
View File

0
archiv/flask-backend/Dockerfile Normal file → Executable file
View File

0
archiv/flask-backend/README.md Normal file → Executable file
View File

0
archiv/flask-backend/app/__init__.py Normal file → Executable file
View File

0
archiv/flask-backend/app/api/__init__.py Normal file → Executable file
View File

0
archiv/flask-backend/app/api/jobs.py Normal file → Executable file
View File

0
archiv/flask-backend/app/api/printers.py Normal file → Executable file
View File

0
archiv/flask-backend/app/api/users.py Normal file → Executable file
View File

0
archiv/flask-backend/app/auth/__init__.py Normal file → Executable file
View File

0
archiv/flask-backend/app/auth/routes.py Normal file → Executable file
View File

0
archiv/flask-backend/app/models.py Normal file → Executable file
View File

0
archiv/flask-backend/config.py Normal file → Executable file
View File

0
archiv/flask-backend/docker-compose.yml Normal file → Executable file
View File

0
archiv/flask-backend/migrations/alembic.ini Normal file → Executable file
View File

0
archiv/flask-backend/migrations/env.py Normal file → Executable file
View File

0
archiv/flask-backend/migrations/script.py.mako Normal file → Executable file
View File

View File

0
archiv/flask-backend/requirements.txt Normal file → Executable file
View File

0
archiv/flask-backend/scripts/init_db.py Normal file → Executable file
View File

0
archiv/flask-backend/wsgi.py Normal file → Executable file
View File

0
backend/.gitignore vendored Normal file → Executable file
View File

0
backend/Dockerfile Normal file → Executable file
View File

View File

@ -32,8 +32,8 @@ app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7)
# Steckdosen-Konfiguration
TAPO_USERNAME = os.environ.get('TAPO_USERNAME')
TAPO_PASSWORD = os.environ.get('TAPO_PASSWORD')
# SOCKET_DEVICES Format: {"192.168.1.100": {"number": "1"}, "192.168.1.101": {"number": "2"}, ...}
SOCKET_DEVICES = json.loads(os.environ.get('SOCKET_DEVICES', '{}'))
# PRINTERS Format: {"Printer 1": {"ip": "192.168.1.100"}, "Printer 2": {"ip": "192.168.1.101"}, ...}
PRINTERS = json.loads(os.environ.get('PRINTERS', '{}'))
# Logging
if not os.path.exists('logs'):
@ -111,42 +111,48 @@ def init_db():
# Initialisierung der Steckdosen
def init_sockets():
"""
Initialisiert die Steckdosen-Einträge in der Datenbank basierend auf SOCKET_DEVICES Umgebungsvariable.
Initialisiert die Steckdosen-Einträge in der Datenbank basierend auf PRINTERS Umgebungsvariable.
Stellt sicher, dass alle Steckdosen zu Beginn ausgeschaltet sind.
"""
app.logger.info("Initialisiere Steckdosen aus Umgebungsvariablen")
app.logger.info("Initialisiere Drucker aus Umgebungsvariablen")
db = get_db()
# Alle IP-Adressen aus der Datenbank abrufen
existing_ips = {row['ip_address']: row['id'] for row in db.execute('SELECT id, ip_address FROM socket').fetchall() if row['ip_address']}
# Alle Druckernamen aus der Datenbank abrufen
existing_printers = {row['name']: {'id': row['id'], 'ip': row['ip_address']}
for row in db.execute('SELECT id, name, ip_address FROM socket').fetchall()}
for ip_address, device_config in SOCKET_DEVICES.items():
socket_number = device_config.get('number', '0')
name = f"Printer {socket_number}"
for printer_name, printer_config in PRINTERS.items():
ip_address = printer_config.get('ip', '')
description = f"3D-Drucker mit SmartPlug (IP: {ip_address})"
if ip_address in existing_ips:
# Steckdose existiert bereits, nichts zu tun
app.logger.info(f"Steckdose mit IP {ip_address} existiert bereits in der Datenbank")
socket_id = existing_ips[ip_address]
if printer_name in existing_printers:
# Drucker existiert bereits, überprüfe auf Änderungen an der IP
socket_id = existing_printers[printer_name]['id']
if existing_printers[printer_name]['ip'] != ip_address:
# Aktualisiere die IP-Adresse, wenn sie sich geändert hat
update_socket(socket_id, ip_address=ip_address)
app.logger.info(f"IP-Adresse für Drucker {printer_name} aktualisiert: {ip_address}")
else:
app.logger.info(f"Drucker {printer_name} existiert bereits in der Datenbank")
else:
# Steckdose erstellen, wenn sie noch nicht existiert
socket = create_socket(name=name, description=description, ip_address=ip_address, status=0)
# Drucker erstellen, wenn er noch nicht existiert
socket = create_socket(name=printer_name, description=description, ip_address=ip_address, status=0)
socket_id = socket['id']
app.logger.info(f"Neue Steckdose angelegt: {name} mit IP {ip_address}")
app.logger.info(f"Neuer Drucker angelegt: {printer_name} mit IP {ip_address}")
# Steckdose ausschalten, um sicherzustellen, dass alle Steckdosen im AUS-Zustand starten
try:
turn_off_socket(ip_address)
app.logger.info(f"Steckdose {ip_address} wurde beim Start ausgeschaltet")
except Exception as e:
app.logger.error(f"Fehler beim Ausschalten der Steckdose {ip_address}: {e}")
if ip_address:
try:
turn_off_socket(ip_address)
app.logger.info(f"Steckdose für {printer_name} (IP: {ip_address}) wurde beim Start ausgeschaltet")
except Exception as e:
app.logger.error(f"Fehler beim Ausschalten der Steckdose für {printer_name} (IP: {ip_address}): {e}")
# Initialisiere die Datenbank und Steckdosen beim Starten der Anwendung
with app.app_context():
init_db()
# Nur initialisieren, wenn Steckdosen konfiguriert sind
if SOCKET_DEVICES:
# Nur initialisieren, wenn Drucker konfiguriert sind
if PRINTERS:
init_sockets()
app.teardown_appcontext(close_db)

View File

@ -45,7 +45,7 @@ CREATE TABLE IF NOT EXISTS session (
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS printer (
CREATE TABLE IF NOT EXISTS socket (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
description TEXT NOT NULL,
@ -53,16 +53,16 @@ CREATE TABLE IF NOT EXISTS printer (
ip_address TEXT
);
CREATE TABLE IF NOT EXISTS print_job (
CREATE TABLE IF NOT EXISTS job (
id TEXT PRIMARY KEY,
printer_id TEXT NOT NULL,
socket_id TEXT NOT NULL,
user_id TEXT NOT NULL,
start_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
duration_in_minutes INTEGER NOT NULL,
comments TEXT,
aborted INTEGER DEFAULT 0,
abort_reason TEXT,
FOREIGN KEY (printer_id) REFERENCES printer (id) ON DELETE CASCADE,
FOREIGN KEY (socket_id) REFERENCES socket (id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE
);
EOF

0
backend/docker-compose.yml Normal file → Executable file
View File

0
docs/.gitkeep Normal file → Executable file
View File

0
docs/Aktueller Stand.md Normal file → Executable file
View File

0
docs/Dokumentation_IHK.md Normal file → Executable file
View File

0
docs/Infrastruktur.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 3.3 MiB

After

Width:  |  Height:  |  Size: 3.3 MiB

0
docs/Infrastruktur.tldr Normal file → Executable file
View File

0
docs/MYP.dbml Normal file → Executable file
View File

0
docs/MYP.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

0
docs/MYP.sql Normal file → Executable file
View File

0
frontend-aenderungen.md Normal file → Executable file
View File

0
packages/reservation-platform/.dockerignore Normal file → Executable file
View File

0
packages/reservation-platform/.env.example Normal file → Executable file
View File

0
packages/reservation-platform/.gitignore vendored Normal file → Executable file
View File

0
packages/reservation-platform/Dockerfile Normal file → Executable file
View File

0
packages/reservation-platform/README.md Normal file → Executable file
View File

0
packages/reservation-platform/biome.json Normal file → Executable file
View File

0
packages/reservation-platform/components.json Normal file → Executable file
View File

0
packages/reservation-platform/docker/caddy/Caddyfile Normal file → Executable file
View File

0
packages/reservation-platform/docker/compose.yml Normal file → Executable file
View File

0
packages/reservation-platform/docker/images/.gitattributes vendored Normal file → Executable file
View File

View File

View File

0
packages/reservation-platform/docs/Admin-Dashboard.md Normal file → Executable file
View File

0
packages/reservation-platform/docs/Architektur.md Normal file → Executable file
View File

View File

0
packages/reservation-platform/docs/Datenbank.md Normal file → Executable file
View File

0
packages/reservation-platform/docs/Installation.md Normal file → Executable file
View File

0
packages/reservation-platform/docs/Nutzung.md Normal file → Executable file
View File

0
packages/reservation-platform/docs/README.md Normal file → Executable file
View File

0
packages/reservation-platform/drizzle.config.ts Normal file → Executable file
View File

View File

View File

View File

0
packages/reservation-platform/next.config.mjs Normal file → Executable file
View File

0
packages/reservation-platform/package.json Normal file → Executable file
View File

0
packages/reservation-platform/pnpm-lock.yaml generated Normal file → Executable file
View File

0
packages/reservation-platform/postcss.config.mjs Normal file → Executable file
View File

0
packages/reservation-platform/public/next.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

0
packages/reservation-platform/public/vercel.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 629 B

After

Width:  |  Height:  |  Size: 629 B

0
packages/reservation-platform/repomix-output.txt Normal file → Executable file
View File

0
packages/reservation-platform/scripts/generate-data.js Normal file → Executable file
View File

View File

View File

View File

View File

0
packages/reservation-platform/src/app/admin/layout.tsx Normal file → Executable file
View File

0
packages/reservation-platform/src/app/admin/page.tsx Normal file → Executable file
View File

View File

View File

View File

View File

View File

View File

View File

Some files were not shown because too many files have changed in this diff Show More