Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9fde0b4b2a | |||
| da7b075cc4 | |||
| 347f258b8f | |||
| 2421f867ed | |||
| 921915e92f | |||
| a4b0866293 |
+3
-1
@@ -10275,12 +10275,14 @@ def admin_damaged_items():
|
||||
flash('Administratorrechte erforderlich.', 'error')
|
||||
return redirect(url_for('login'))
|
||||
|
||||
'''
|
||||
permissions = _get_current_user_permissions()
|
||||
if not _action_access_allowed(permissions, 'can_manage_settings'):
|
||||
flash('Sie haben keine Berechtigung, die Schulstammdaten zu ändern.', 'error')
|
||||
if cfg.MODULES.is_enabled('library'):
|
||||
return redirect(url_for('library_admin'))
|
||||
|
||||
'''
|
||||
|
||||
client = None
|
||||
try:
|
||||
client = MongoClient(MONGODB_HOST, MONGODB_PORT)
|
||||
|
||||
@@ -284,7 +284,6 @@ def _match_inventory(path):
|
||||
if path == '/' or path.startswith('/home'): return True
|
||||
return path.startswith(('/scanner', '/inventory', '/upload_admin', '/manage_filters', '/manage_locations', '/admin_borrowings', '/admin_damaged_items', '/admin/borrowings', '/admin/damaged_items'))
|
||||
|
||||
|
||||
def _match_terminplan(path):
|
||||
if not path:
|
||||
return False
|
||||
@@ -292,7 +291,7 @@ def _match_terminplan(path):
|
||||
|
||||
def _match_library(path):
|
||||
if not path: return False
|
||||
return path.startswith(('/library', '/library_', '/student_cards'))
|
||||
return path.startswith(('/library', '/library_', '/student_cards', '/admin_damaged_items', '/admin_borrowings', '/admin/library'))
|
||||
|
||||
def _match_student_cards(path):
|
||||
if not path: return False
|
||||
|
||||
+67
-20
@@ -258,7 +258,7 @@ sanitized = "".join(c for c in tenant_id if c.isalnum() or c == "_")
|
||||
db_name = f"inventar_{sanitized}"
|
||||
client = MongoClient(settings.MONGODB_HOST, int(settings.MONGODB_PORT))
|
||||
db = client[db_name]
|
||||
hashed_pw = hashlib.sha512("admin123".encode()).hexdigest()
|
||||
hashed_pw = hashlib.scrypt('admin123'.encode(), salt=b'some_salt', n=16384, r=8, p=1).hex()
|
||||
|
||||
action_permissions = {
|
||||
"can_borrow": True,
|
||||
@@ -524,6 +524,8 @@ remove_runtime_port() {
|
||||
local port_list=()
|
||||
local new_ports=()
|
||||
local first_port=""
|
||||
local ports_csv=""
|
||||
|
||||
|
||||
if [ ! -f "$env_file" ]; then
|
||||
return 0
|
||||
@@ -551,7 +553,8 @@ remove_runtime_port() {
|
||||
fi
|
||||
|
||||
first_port="${new_ports[0]}"
|
||||
local ports_csv="$(IFS=,; echo "${new_ports[*]}")"
|
||||
# Das 'local' hier entfernen, da wir es oben deklariert haben:
|
||||
ports_csv="$(IFS=,; echo "${new_ports[*]}")"
|
||||
|
||||
if grep -q '^INVENTAR_HTTP_PORTS=' "$env_file" 2>/dev/null; then
|
||||
sed -i "s|^INVENTAR_HTTP_PORTS=.*|INVENTAR_HTTP_PORTS=$ports_csv|" "$env_file"
|
||||
@@ -566,6 +569,55 @@ remove_runtime_port() {
|
||||
fi
|
||||
}
|
||||
|
||||
show_help() {
|
||||
local script_name
|
||||
script_name="$(basename "$0")"
|
||||
|
||||
echo "=== MULTI-TENANT INVENTAR MANAGER ==="
|
||||
echo ""
|
||||
echo "NUTZUNG:"
|
||||
echo " ./$script_name <befehl> [tenant_id] [optionen]"
|
||||
echo ""
|
||||
echo "VERFÜGBARE BEFEHLE:"
|
||||
echo " add <tenant_id> [port]"
|
||||
echo " Legt einen neuen Tenant an, registriert den Port und initialisiert"
|
||||
echo " die MongoDB-Datenbank mit einem Standard-Admin (admin / admin123)."
|
||||
echo ""
|
||||
echo " trial <tenant_id> [port] [tage]"
|
||||
echo " Erstellt einen temporären Test-Tenant (Standardlaufzeit: 7 Tage)."
|
||||
echo " Dieser läuft nach der festgelegten Zeit ab und wird automatisch gelöscht."
|
||||
echo ""
|
||||
echo " remove [-y|--yes] <tenant_id>"
|
||||
echo " Löscht einen Tenant komplett (Konfiguration, Ports und Datenbank)."
|
||||
echo " Nutze -y oder --yes, um die Bestätigungsabfrage zu überspringen."
|
||||
echo ""
|
||||
echo " restart-tenant <tenant_id>"
|
||||
echo " Startet einen spezifischen Tenant neu, indem alle aktiven Sessions"
|
||||
echo " und der Cache in der MongoDB geleert werden (Sitzungs-Reset)."
|
||||
echo ""
|
||||
echo " restart-all"
|
||||
echo " Führt einen Zero-Downtime Rolling-Restart für alle App-Container durch."
|
||||
echo ""
|
||||
echo " list"
|
||||
echo " Listet alle registrierten Tenants (aus der config.json) sowie alle"
|
||||
echo " aktiven Tenant-Datenbanken (aus der MongoDB) übersichtlich auf."
|
||||
echo ""
|
||||
echo " module <tenant_id> <modulname>=<on|off> [...]"
|
||||
echo " Aktiviert oder deaktiviert bestimmte Features/Module für einen Tenant."
|
||||
echo " Es können mehrere Module gleichzeitig konfiguriert werden."
|
||||
echo ""
|
||||
echo "GLOBALE OPTIONEN:"
|
||||
echo " -h, --help"
|
||||
echo " Zeigt dieses Hilfemenü an."
|
||||
echo ""
|
||||
echo "BEISPIELE:"
|
||||
echo " ./$script_name add schule_muenchen 8081"
|
||||
echo " ./$script_name trial test_user 8082 14"
|
||||
echo " ./$script_name module schule_muenchen inventory=on mail=off"
|
||||
echo " ./$script_name remove --yes test_user"
|
||||
echo ""
|
||||
}
|
||||
|
||||
if [ -z "${1:-}" ]; then
|
||||
show_help
|
||||
fi
|
||||
@@ -609,7 +661,7 @@ sanitized = ''.join(c for c in tenant_id if c.isalnum() or c == '_')
|
||||
db_name = f'inventar_{sanitized}'
|
||||
client = MongoClient(settings.MONGODB_HOST, int(settings.MONGODB_PORT))
|
||||
db = client[db_name]
|
||||
hashed_pw = hashlib.sha512('admin123'.encode()).hexdigest()
|
||||
hashed_pw = hashlib.scrypt('admin123'.encode(), salt=b'some_salt', n=16384, r=8, p=1).hex()
|
||||
if db.users.count_documents({'Username': 'admin'}) == 0:
|
||||
db.users.insert_one({
|
||||
'Username': 'admin',
|
||||
@@ -690,7 +742,7 @@ print(f'Tenant {sys.argv[1]} database initialized. Default admin: admin / admin1
|
||||
;;
|
||||
|
||||
remove)
|
||||
FORCE_REMOVE=false
|
||||
FORCE_REMOVE=true
|
||||
if [ "${2:-}" = "--yes" ] || [ "${2:-}" = "-y" ]; then
|
||||
FORCE_REMOVE=true
|
||||
TENANT_ID="${3:-}"
|
||||
@@ -713,33 +765,27 @@ print(f'Tenant {sys.argv[1]} database initialized. Default admin: admin / admin1
|
||||
echo "Removing tenant '$TENANT_ID'..."
|
||||
APP_CONTAINER=$(docker ps -qf "name=app" | head -n 1)
|
||||
port_to_remove=""
|
||||
|
||||
if port_to_remove="$(remove_tenant_port "$TENANT_ID" 2>/dev/null)"; then
|
||||
:
|
||||
else
|
||||
echo "Warning: tenant '$TENANT_ID' was not found in config.json."
|
||||
fi
|
||||
|
||||
if [ -n "$APP_CONTAINER" ]; then
|
||||
port_to_remove="$(docker exec "$APP_CONTAINER" python3 - "$TENANT_ID" <<'PY'
|
||||
docker exec "$APP_CONTAINER" python3 - "$TENANT_ID" <<'PY'
|
||||
import sys
|
||||
sys.path.insert(0, '/app')
|
||||
sys.path.insert(0, '/app/Web')
|
||||
from tenant import delete_tenant, get_tenant_config
|
||||
from tenant import delete_tenant
|
||||
|
||||
tenant_id = sys.argv[1]
|
||||
tenant_cfg = get_tenant_config(tenant_id)
|
||||
port = tenant_cfg.get('port')
|
||||
|
||||
if not delete_tenant(tenant_id):
|
||||
print(f'Error: failed to delete tenant {tenant_id}', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if port is not None:
|
||||
print(port)
|
||||
print(f'Error: failed to delete tenant {tenant_id} database', file=sys.stderr)
|
||||
PY
|
||||
)"
|
||||
echo "Tenant '$TENANT_ID' database and config removed."
|
||||
else
|
||||
echo "Warning: Application container not running. Tenant database may still exist in MongoDB."
|
||||
if port_to_remove="$(remove_tenant_port "$TENANT_ID" 2>/dev/null)"; then
|
||||
:
|
||||
else
|
||||
echo "Warning: tenant '$TENANT_ID' was not configured in config.json or could not be removed."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$port_to_remove" ]; then
|
||||
@@ -749,6 +795,7 @@ PY
|
||||
if [ -n "$(docker ps -qf 'name=app' | head -n 1)" ]; then
|
||||
restart_app_container
|
||||
fi
|
||||
|
||||
if [ -n "$port_to_remove" ]; then
|
||||
echo "Removed tenant '$TENANT_ID' and cleaned runtime port $port_to_remove."
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user