missing scripts

This commit is contained in:
jarek committed 2026-01-03 13:21:38 +01:00
1 parent 80c000c601
commit 66e723052d
30 files changed
+3108

No files matched your search

+88
View File
@@ -0,0 +1,88 @@
#!/bin/sh
#
# SQLite: Emergency script to backup the database
# Creates a timestamped copy of the database file
#
# Usage:
# docker exec -it dockhand /app/scripts/emergency/sqlite/backup-db.sh [output_dir]
#
# Example:
# docker exec -it dockhand /app/scripts/emergency/sqlite/backup-db.sh /app/data/backups
#
# Default output: /app/data (same directory as database)
#
set -e
echo "========================================"
echo " Dockhand - Backup Database (SQLite)"
echo "========================================"
echo ""
# Default database path
DB_PATH="${DOCKHAND_DB:-/app/data/db/dockhand.db}"
OUTPUT_DIR="${1:-$(dirname "$DB_PATH")}"
# Check if running locally (not in Docker)
if [ ! -f "$DB_PATH" ] && [ -f "./data/db/dockhand.db" ]; then
DB_PATH="./data/db/dockhand.db"
OUTPUT_DIR="${1:-./data/db}"
fi
if [ ! -f "$DB_PATH" ]; then
echo "Error: Database not found at $DB_PATH"
echo "Set DOCKHAND_DB environment variable to specify the database path"
exit 1
fi
# Generate backup filename with timestamp
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="$OUTPUT_DIR/dockhand_backup_$TIMESTAMP.db"
# Get database size
DB_SIZE=$(ls -lh "$DB_PATH" | awk '{print $5}')
echo "This script will create a backup of the database."
echo ""
echo "Source: $DB_PATH ($DB_SIZE)"
echo "Backup: $BACKUP_FILE"
echo ""
printf "Continue? [y/N]: "
read CONFIRM
case "$CONFIRM" in
[yY]|[yY][eE][sS])
;;
*)
echo "Aborted."
exit 0
;;
esac
echo ""
# Create output directory if needed
mkdir -p "$OUTPUT_DIR"
echo "Creating database backup..."
# Use sqlite3 backup command for safe backup (handles WAL mode)
if command -v sqlite3 >/dev/null 2>&1; then
sqlite3 "$DB_PATH" ".backup '$BACKUP_FILE'"
else
# Fallback to file copy if sqlite3 not available
cp "$DB_PATH" "$BACKUP_FILE"
fi
if [ $? -eq 0 ] && [ -f "$BACKUP_FILE" ]; then
SIZE=$(ls -lh "$BACKUP_FILE" | awk '{print $5}')
echo ""
echo "Backup created successfully!"
echo "Size: $SIZE"
echo ""
echo "To copy from Docker container to host:"
echo " docker cp dockhand:$BACKUP_FILE ./dockhand_backup_$TIMESTAMP.db"
else
echo "Error: Failed to create backup"
exit 1
fi
+62
View File
@@ -0,0 +1,62 @@
#!/bin/sh
#
# SQLite: Emergency script to clear all user sessions
# Use this to force all users to re-login
#
# Usage:
# docker exec -it dockhand /app/scripts/emergency/sqlite/clear-sessions.sh
#
set -e
echo "========================================"
echo " Dockhand - Clear All Sessions (SQLite)"
echo "========================================"
echo ""
echo "This script will clear all user sessions,"
echo "forcing all users to log in again."
echo ""
# Default database path
DB_PATH="${DOCKHAND_DB:-/app/data/db/dockhand.db}"
# Check if running locally (not in Docker)
if [ ! -f "$DB_PATH" ] && [ -f "./data/db/dockhand.db" ]; then
DB_PATH="./data/db/dockhand.db"
fi
if [ ! -f "$DB_PATH" ]; then
echo "Error: Database not found at $DB_PATH"
echo "Set DOCKHAND_DB environment variable to specify the database path"
exit 1
fi
COUNT=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM sessions;")
echo "Database: $DB_PATH"
echo "Active sessions: $COUNT"
echo ""
printf "Continue? [y/N]: "
read CONFIRM
case "$CONFIRM" in
[yY]|[yY][eE][sS])
;;
*)
echo "Aborted."
exit 0
;;
esac
echo ""
echo "Clearing all user sessions..."
sqlite3 "$DB_PATH" "DELETE FROM sessions;"
if [ $? -eq 0 ]; then
echo ""
echo "Cleared $COUNT session(s) successfully."
echo "All users will need to log in again."
else
echo "Error: Failed to clear sessions"
exit 1
fi
+104
View File
@@ -0,0 +1,104 @@
#!/bin/sh
#
# SQLite: Emergency script to create an admin user
# Use this if you're locked out of Dockhand and need to create a new admin
#
# Usage:
# docker exec -it dockhand /app/scripts/emergency/sqlite/create-admin.sh
#
# Default credentials: admin / admin123
# CHANGE THE PASSWORD IMMEDIATELY after logging in!
#
set -e
echo "========================================"
echo " Dockhand - Create Admin User (SQLite)"
echo "========================================"
echo ""
echo "This script will create an admin user with:"
echo " Username: admin"
echo " Password: admin123"
echo ""
echo "If user 'admin' already exists, password will"
echo "be reset and admin privileges restored."
echo ""
# Default database path
DB_PATH="${DOCKHAND_DB:-/app/data/db/dockhand.db}"
# Check if running locally (not in Docker)
if [ ! -f "$DB_PATH" ] && [ -f "./data/db/dockhand.db" ]; then
DB_PATH="./data/db/dockhand.db"
fi
if [ ! -f "$DB_PATH" ]; then
echo "Error: Database not found at $DB_PATH"
echo "Set DOCKHAND_DB environment variable to specify the database path"
exit 1
fi
echo "Database: $DB_PATH"
echo ""
printf "Continue? [y/N]: "
read CONFIRM
case "$CONFIRM" in
[yY]|[yY][eE][sS])
;;
*)
echo "Aborted."
exit 0
;;
esac
# Username and password
USERNAME="admin"
# Password: admin123
# This is an argon2id hash of "admin123" - generated with default argon2 settings
PASSWORD_HASH='$argon2id$v=19$m=65536,t=3,p=4$Jq4am2SfyYKmc0PAHe+yzg$cq/27vK/Qg2eZb/jMDy0ExLDhOG+58cKAximxpG5Dss'
echo ""
echo "Creating admin user..."
# Check if admin user already exists
EXISTING=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM users WHERE username='$USERNAME';")
if [ "$EXISTING" -gt "0" ]; then
echo "User '$USERNAME' already exists."
echo "Resetting password and ensuring active status..."
sqlite3 "$DB_PATH" "UPDATE users SET password_hash='$PASSWORD_HASH', is_active=1 WHERE username='$USERNAME';"
USER_ID=$(sqlite3 "$DB_PATH" "SELECT id FROM users WHERE username='$USERNAME';")
else
echo "Creating new admin user..."
sqlite3 "$DB_PATH" "INSERT INTO users (username, password_hash, is_active, auth_provider, created_at, updated_at) VALUES ('$USERNAME', '$PASSWORD_HASH', 1, 'local', datetime('now'), datetime('now'));"
USER_ID=$(sqlite3 "$DB_PATH" "SELECT id FROM users WHERE username='$USERNAME';")
echo "Admin user created successfully."
fi
# Get the Admin role ID (it's a system role)
ADMIN_ROLE_ID=$(sqlite3 "$DB_PATH" "SELECT id FROM roles WHERE name='Admin';")
if [ -z "$ADMIN_ROLE_ID" ]; then
echo "Warning: Admin role not found in database."
echo "The user was created but may not have admin privileges."
echo "Please check Settings > Auth > Roles after logging in."
else
# Check if user already has Admin role
HAS_ROLE=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM user_roles WHERE user_id=$USER_ID AND role_id=$ADMIN_ROLE_ID;")
if [ "$HAS_ROLE" -eq "0" ]; then
echo "Assigning Admin role..."
sqlite3 "$DB_PATH" "INSERT INTO user_roles (user_id, role_id, created_at) VALUES ($USER_ID, $ADMIN_ROLE_ID, datetime('now'));"
echo "Admin role assigned."
else
echo "User already has Admin role."
fi
fi
echo ""
echo "Credentials:"
echo " Username: admin"
echo " Password: admin123"
echo ""
echo "WARNING: Change the password immediately after logging in!"
+61
View File
@@ -0,0 +1,61 @@
#!/bin/sh
#
# SQLite: Emergency script to disable authentication
# Use this if you're locked out of Dockhand
#
# Usage:
# docker exec -it dockhand /app/scripts/emergency/sqlite/disable-auth.sh
#
set -e
echo "========================================"
echo " Dockhand - Disable Authentication (SQLite)"
echo "========================================"
echo ""
echo "This script will disable authentication,"
echo "allowing access to Dockhand without login."
echo ""
# Default database path
DB_PATH="${DOCKHAND_DB:-/app/data/db/dockhand.db}"
# Check if running locally (not in Docker)
if [ ! -f "$DB_PATH" ] && [ -f "./data/db/dockhand.db" ]; then
DB_PATH="./data/db/dockhand.db"
fi
if [ ! -f "$DB_PATH" ]; then
echo "Error: Database not found at $DB_PATH"
echo "Set DOCKHAND_DB environment variable to specify the database path"
exit 1
fi
echo "Database: $DB_PATH"
echo ""
printf "Continue? [y/N]: "
read CONFIRM
case "$CONFIRM" in
[yY]|[yY][eE][sS])
;;
*)
echo "Aborted."
exit 0
;;
esac
echo ""
echo "Disabling authentication..."
sqlite3 "$DB_PATH" "UPDATE auth_settings SET auth_enabled = 0 WHERE id = 1;"
if [ $? -eq 0 ]; then
echo ""
echo "Authentication disabled successfully."
echo "You can now access Dockhand without logging in."
echo ""
echo "Remember to re-enable authentication in Settings after regaining access."
else
echo "Error: Failed to disable authentication"
exit 1
fi
+80
View File
@@ -0,0 +1,80 @@
#!/bin/sh
#
# SQLite: Emergency script to list all users
# Shows username, admin status, active status, and last login
#
# Usage:
# docker exec -it dockhand /app/scripts/emergency/sqlite/list-users.sh
#
set -e
echo "========================================"
echo " Dockhand - List Users (SQLite)"
echo "========================================"
echo ""
# Default database path
DB_PATH="${DOCKHAND_DB:-/app/data/db/dockhand.db}"
# Check if running locally (not in Docker)
if [ ! -f "$DB_PATH" ] && [ -f "./data/db/dockhand.db" ]; then
DB_PATH="./data/db/dockhand.db"
fi
if [ ! -f "$DB_PATH" ]; then
echo "Error: Database not found at $DB_PATH"
echo "Set DOCKHAND_DB environment variable to specify the database path"
exit 1
fi
# Get user count
USER_COUNT=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM users;")
if [ "$USER_COUNT" -eq "0" ]; then
echo "No users found."
exit 0
fi
# Get Admin role ID for checking admin status
ADMIN_ROLE_ID=$(sqlite3 "$DB_PATH" "SELECT id FROM roles WHERE name='Admin';" 2>/dev/null || echo "")
# Print header
printf "%-4s %-20s %-8s %-8s %-6s %s\n" "ID" "Username" "Admin" "Active" "MFA" "Last Login"
printf "%-4s %-20s %-8s %-8s %-6s %s\n" "----" "--------------------" "--------" "--------" "------" "-------------------"
# List users (check admin status via user_roles table)
sqlite3 -separator '|' "$DB_PATH" "SELECT id, username, is_active, mfa_enabled, COALESCE(last_login, 'Never') FROM users ORDER BY id;" | while IFS='|' read id username is_active mfa_enabled last_login; do
# Check if user has Admin role
if [ -n "$ADMIN_ROLE_ID" ]; then
HAS_ADMIN=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM user_roles WHERE user_id=$id AND role_id=$ADMIN_ROLE_ID;")
if [ "$HAS_ADMIN" -gt "0" ]; then
admin_str="Yes"
else
admin_str="No"
fi
else
admin_str="N/A"
fi
if [ "$is_active" = "1" ]; then
active_str="Yes"
else
active_str="No"
fi
if [ "$mfa_enabled" = "1" ]; then
mfa_str="Yes"
else
mfa_str="No"
fi
printf "%-4s %-20s %-8s %-8s %-6s %s\n" "$id" "$username" "$admin_str" "$active_str" "$mfa_str" "$last_login"
done
echo ""
echo "Total: $USER_COUNT user(s)"
# Show session count
SESSION_COUNT=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM sessions;")
echo "Active sessions: $SESSION_COUNT"
+73
View File
@@ -0,0 +1,73 @@
#!/bin/sh
#
# SQLite: Emergency script to factory reset the database
# WARNING: This will DELETE ALL DATA including users, settings, and activity logs!
#
# Usage:
# docker exec -it dockhand /app/scripts/emergency/sqlite/reset-db.sh
#
set -e
echo "========================================"
echo " Dockhand - Factory Reset Database (SQLite)"
echo "========================================"
echo ""
echo "WARNING: This will DELETE ALL DATA!"
echo ""
echo "This includes:"
echo " - All users and their settings"
echo " - All sessions"
echo " - Authentication settings"
echo " - Activity logs"
echo " - Environment configurations"
echo " - OIDC/SSO settings"
echo ""
echo "The database will be recreated on next startup."
echo ""
# Default database path
DB_PATH="${DOCKHAND_DB:-/app/data/db/dockhand.db}"
# Check if running locally (not in Docker)
if [ ! -f "$DB_PATH" ] && [ -f "./data/db/dockhand.db" ]; then
DB_PATH="./data/db/dockhand.db"
fi
if [ ! -f "$DB_PATH" ]; then
echo "Error: Database not found at $DB_PATH"
echo "Nothing to reset."
exit 0
fi
echo "Database: $DB_PATH"
echo ""
printf "Continue? [y/N]: "
read CONFIRM
case "$CONFIRM" in
[yY]|[yY][eE][sS])
;;
*)
echo "Aborted."
exit 0
;;
esac
echo ""
echo "Creating backup before reset..."
BACKUP_FILE="${DB_PATH}.backup.$(date +%Y%m%d_%H%M%S)"
cp "$DB_PATH" "$BACKUP_FILE"
echo "Backup saved to: $BACKUP_FILE"
echo ""
echo "Deleting database..."
rm -f "$DB_PATH"
rm -f "${DB_PATH}-wal"
rm -f "${DB_PATH}-shm"
echo ""
echo "Database deleted successfully."
echo ""
echo "Restart Dockhand to recreate a fresh database:"
echo " docker restart dockhand"
+123
View File
@@ -0,0 +1,123 @@
#!/bin/sh
#
# SQLite: Emergency script to reset a user's password
# Use this if a user is locked out and needs a password reset
#
# Usage:
# docker exec -it dockhand /app/scripts/emergency/sqlite/reset-password.sh <username> <new_password>
#
# Example:
# docker exec -it dockhand /app/scripts/emergency/sqlite/reset-password.sh admin MyNewPassword123
#
set -e
echo "========================================"
echo " Dockhand - Reset User Password (SQLite)"
echo "========================================"
echo ""
# Check arguments
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <username> <new_password>"
echo ""
echo "Example:"
echo " $0 admin MyNewPassword123"
exit 1
fi
USERNAME="$1"
NEW_PASSWORD="$2"
# Validate password length
if [ ${#NEW_PASSWORD} -lt 8 ]; then
echo "Error: Password must be at least 8 characters"
exit 1
fi
# Default database path
DB_PATH="${DOCKHAND_DB:-/app/data/db/dockhand.db}"
# Check if running locally (not in Docker)
if [ ! -f "$DB_PATH" ] && [ -f "./data/db/dockhand.db" ]; then
DB_PATH="./data/db/dockhand.db"
fi
if [ ! -f "$DB_PATH" ]; then
echo "Error: Database not found at $DB_PATH"
echo "Set DOCKHAND_DB environment variable to specify the database path"
exit 1
fi
# Check if user exists
EXISTING=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM users WHERE username='$USERNAME';")
if [ "$EXISTING" -eq "0" ]; then
echo "Error: User '$USERNAME' not found"
echo ""
echo "Available users:"
sqlite3 "$DB_PATH" "SELECT username FROM users;" | while read user; do
echo " - $user"
done
exit 1
fi
echo "This script will reset the password for user '$USERNAME'."
echo ""
echo "Database: $DB_PATH"
echo "Username: $USERNAME"
echo ""
printf "Continue? [y/N]: "
read CONFIRM
case "$CONFIRM" in
[yY]|[yY][eE][sS])
;;
*)
echo "Aborted."
exit 0
;;
esac
# Generate password hash using node (argon2 is available in the app)
echo ""
echo "Generating password hash..."
# Check if node and argon2 are available
if command -v node >/dev/null 2>&1; then
# Try to use argon2 from node_modules
PASSWORD_HASH=$(node -e "
try {
const argon2 = require('argon2');
argon2.hash('$NEW_PASSWORD').then(h => console.log(h)).catch(e => process.exit(1));
} catch(e) {
process.exit(1);
}
" 2>/dev/null)
if [ -z "$PASSWORD_HASH" ]; then
echo "Error: Could not generate password hash (argon2 not available)"
echo "This script requires Node.js with argon2 module"
exit 1
fi
else
echo "Error: Node.js is required to generate password hash"
exit 1
fi
echo "Resetting password for user '$USERNAME'..."
sqlite3 "$DB_PATH" "UPDATE users SET password_hash='$PASSWORD_HASH', updated_at=datetime('now') WHERE username='$USERNAME';"
if [ $? -eq 0 ]; then
echo ""
echo "Password reset successfully for user '$USERNAME'"
echo ""
# Invalidate sessions
USER_ID=$(sqlite3 "$DB_PATH" "SELECT id FROM users WHERE username='$USERNAME';")
sqlite3 "$DB_PATH" "DELETE FROM sessions WHERE user_id=$USER_ID;" 2>/dev/null || true
echo "All existing sessions have been invalidated."
echo "The user can now log in with the new password."
else
echo "Error: Failed to reset password"
exit 1
fi
+106
View File
@@ -0,0 +1,106 @@
#!/bin/sh
#
# SQLite: Emergency script to restore the database from a backup
# WARNING: This will overwrite the current database!
#
# Usage:
# docker exec -it dockhand /app/scripts/emergency/sqlite/restore-db.sh <backup_file>
#
# Example:
# docker exec -it dockhand /app/scripts/emergency/sqlite/restore-db.sh /app/data/dockhand_backup_20240115_120000.db
#
# To copy backup into container first:
# docker cp ./dockhand_backup.db dockhand:/app/data/
#
set -e
echo "========================================"
echo " Dockhand - Restore Database (SQLite)"
echo "========================================"
echo ""
# Check argument
if [ -z "$1" ]; then
echo "Usage: $0 <backup_file>"
echo ""
echo "Example:"
echo " $0 /app/data/dockhand_backup_20240115_120000.db"
echo ""
echo "To copy backup into container first:"
echo " docker cp ./dockhand_backup.db dockhand:/app/data/"
exit 1
fi
BACKUP_FILE="$1"
# Default database path
DB_PATH="${DOCKHAND_DB:-/app/data/db/dockhand.db}"
# Check if running locally (not in Docker)
if [ ! -f "$DB_PATH" ] && [ -f "./data/db/dockhand.db" ]; then
DB_PATH="./data/db/dockhand.db"
fi
# Check if backup file exists
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
# Verify it's a valid SQLite database
if ! sqlite3 "$BACKUP_FILE" "SELECT 1;" >/dev/null 2>&1; then
echo "Error: File is not a valid SQLite database: $BACKUP_FILE"
exit 1
fi
# Get backup file size
BACKUP_SIZE=$(ls -lh "$BACKUP_FILE" | awk '{print $5}')
echo "WARNING: This will overwrite the current database!"
echo ""
echo "Current database: $DB_PATH"
echo "Backup to restore: $BACKUP_FILE ($BACKUP_SIZE)"
echo ""
printf "Continue? [y/N]: "
read CONFIRM
case "$CONFIRM" in
[yY]|[yY][eE][sS])
;;
*)
echo "Aborted."
exit 0
;;
esac
# Create backup of current database before restoring
if [ -f "$DB_PATH" ]; then
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
PRE_RESTORE_BACKUP="${DB_PATH}.pre-restore.$TIMESTAMP"
echo ""
echo "Creating backup of current database..."
cp "$DB_PATH" "$PRE_RESTORE_BACKUP"
echo "Current database backed up to: $PRE_RESTORE_BACKUP"
fi
echo ""
echo "Restoring database..."
# Remove WAL files if they exist
rm -f "${DB_PATH}-wal"
rm -f "${DB_PATH}-shm"
# Copy backup to database location
cp "$BACKUP_FILE" "$DB_PATH"
if [ $? -eq 0 ]; then
echo ""
echo "Database restored successfully!"
echo ""
echo "Restart Dockhand to apply changes:"
echo " docker restart dockhand"
else
echo "Error: Failed to restore database"
exit 1
fi