Bump to v2.2.1: Node.js console env/admin fixes

Bump release to v2.2.1 and fix Node.js web-console installation and update flow. Changes include: generate and persist a random DEFAULT_ADMIN_PASSWORD for the Node.js console, always write a .env with corrected path variables (RUSTDESK_DIR/KEYS_PATH/DB_PATH/DATA_DIR/HBBS_API_URL), save admin creds to .admin_credentials and display them after install/update, load .env from systemd using EnvironmentFile and expose needed envs in the service unit, and ensure Do-Update installs services and creates the admin. The create_admin_user logic now detects Node.js vs Flask consoles (reading stored Node.js creds or creating Flask DB user). Also update web-nodejs config to accept multiple env var names and use a safe default for KEYS_PATH, and refresh project docs/version metadata.
This commit is contained in:
UNITRONIX
2026-02-17 21:53:24 +01:00
parent 32e29723e4
commit fd217bc385
5 changed files with 221 additions and 64 deletions
+11 -3
View File
@@ -7,12 +7,12 @@
## 📊 Stan Projektu (aktualizacja: 2026-02-17)
### Wersja Skryptów ALL-IN-ONE (v2.2.0)
### Wersja Skryptów ALL-IN-ONE (v2.2.1)
| Plik | Wersja | Platforma | Status |
|------|--------|-----------|--------|
| `betterdesk.sh` | v2.2.0 | Linux | ✅ ALL-IN-ONE + Node.js/Flask choice + Auto mode |
| `betterdesk.ps1` | v2.2.0 | Windows | ✅ ALL-IN-ONE + Node.js/Flask choice + Auto mode |
| `betterdesk.sh` | v2.2.1 | Linux | ✅ ALL-IN-ONE + Node.js/Flask choice + Auto mode |
| `betterdesk.ps1` | v2.2.1 | Windows | ✅ ALL-IN-ONE + Node.js/Flask choice + Auto mode |
| `betterdesk-docker.sh` | v2.0.0 | Docker | ✅ Interaktywny ALL-IN-ONE |
### Konsole Webowe
@@ -47,6 +47,14 @@ Windows:
## 🚀 Skrypty ALL-IN-ONE (v2.2.0)
### Nowe funkcje w v2.2.1
-**Poprawka konfiguracji Node.js** - zmienne środowiskowe w .env są teraz poprawnie ustawione (RUSTDESK_DIR, KEYS_PATH, DATA_DIR)
-**Poprawka hasła admina** - hasło jest teraz poprawnie przekazywane do konsoli Node.js przy instalacji
-**Poprawka usług systemd** - usługa Node.js teraz ładuje plik .env z EnvironmentFile
-**Poprawka aktualizacji** - do_update teraz aktualizuje usługi systemd i tworzy admina
-**Poprawka QR code** - ścieżki do kluczy są teraz poprawnie konfigurowane
### Nowe funkcje w v2.2.0
-**Wybór konsoli Node.js/Flask** - interaktywny wybór podczas instalacji
+1 -1
View File
@@ -1 +1 @@
2.2.0
2.2.1
+104 -31
View File
@@ -57,7 +57,7 @@ param(
# Configuration
#===============================================================================
$script:VERSION = "2.2.0"
$script:VERSION = "2.2.1"
$script:ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Auto mode flags
@@ -626,21 +626,43 @@ function Install-NodeJsConsole {
New-Item -ItemType Directory -Path $dataDir -Force | Out-Null
}
# Create .env file if not exists
# Generate admin password for Node.js console
$nodejsAdminPassword = Generate-RandomPassword
# Create .env file (always update to ensure correct paths)
$envFile = Join-Path $script:CONSOLE_PATH ".env"
if (-not (Test-Path $envFile)) {
$sessionSecret = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 32 | ForEach-Object {[char]$_})
$envContent = @"
$sessionSecret = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 64 | ForEach-Object {[char]$_})
$envContent = @"
# BetterDesk Node.js Console Configuration
PORT=5000
RUSTDESK_PATH=$script:RUSTDESK_PATH
API_PORT=$script:API_PORT
NODE_ENV=production
# RustDesk paths (critical for key/QR code generation)
RUSTDESK_DIR=$script:RUSTDESK_PATH
KEYS_PATH=$script:RUSTDESK_PATH
DB_PATH=$script:RUSTDESK_PATH\db_v2.sqlite3
PUB_KEY_PATH=$script:RUSTDESK_PATH\id_ed25519.pub
API_KEY_PATH=$script:RUSTDESK_PATH\.api_key
# Auth database location
DATA_DIR=$dataDir
# HBBS API
HBBS_API_URL=http://localhost:$script:API_PORT/api
# Default admin credentials (used only on first startup)
DEFAULT_ADMIN_USERNAME=admin
DEFAULT_ADMIN_PASSWORD=$nodejsAdminPassword
# Session
SESSION_SECRET=$sessionSecret
"@
Set-Content -Path $envFile -Value $envContent
Print-Info "Created .env configuration file"
}
Set-Content -Path $envFile -Value $envContent
Print-Info "Created .env configuration file"
# Save Node.js admin credentials for display
$credsFile = Join-Path $dataDir ".admin_credentials"
"admin:$nodejsAdminPassword" | Out-File -FilePath $credsFile -Encoding UTF8
$script:CONSOLE_TYPE = "nodejs"
Print-Success "Node.js Web Console installed"
@@ -1151,9 +1173,53 @@ print("Database migrations completed")
function Create-AdminUser {
Print-Step "Creating admin user..."
$adminPassword = Generate-RandomPassword
# Detect console type
$currentConsoleType = ""
if (Test-Path (Join-Path $script:CONSOLE_PATH "server.js")) {
$currentConsoleType = "nodejs"
} elseif (Test-Path (Join-Path $script:CONSOLE_PATH "app.py")) {
$currentConsoleType = "flask"
} else {
Print-Warning "No console detected, skipping admin creation"
return $null
}
$pythonScript = @"
if ($currentConsoleType -eq "nodejs") {
# Node.js console - admin is created automatically on startup
# Read the password saved during Install-NodeJsConsole
$dataDir = Join-Path $script:CONSOLE_PATH "data"
$credsFile = Join-Path $dataDir ".admin_credentials"
if (Test-Path $credsFile) {
$creds = Get-Content $credsFile -Raw
$adminPassword = ($creds -split ':')[1].Trim()
Write-Host ""
Write-Host "============================================================" -ForegroundColor Green
Write-Host " PANEL LOGIN CREDENTIALS " -ForegroundColor Green
Write-Host "============================================================" -ForegroundColor Green
Write-Host " Login: " -NoNewline; Write-Host "admin" -ForegroundColor White
Write-Host " Password: " -NoNewline; Write-Host $adminPassword -ForegroundColor White
Write-Host "============================================================" -ForegroundColor Green
Write-Host ""
# Also save to main RustDesk path for consistency
$mainCredsFile = Join-Path $script:RUSTDESK_PATH ".admin_credentials"
"admin:$adminPassword" | Out-File -FilePath $mainCredsFile -Encoding UTF8
Print-Info "Credentials saved in: $mainCredsFile"
return $adminPassword
} else {
Print-Warning "No Node.js admin credentials found"
Print-Info "Default credentials: admin / admin"
Print-Info "Please change password after first login!"
return "admin"
}
} else {
# Flask console - create admin in db_v2.sqlite3
$adminPassword = Generate-RandomPassword
$pythonScript = @"
import sqlite3
import bcrypt
from datetime import datetime
@@ -1177,25 +1243,26 @@ else:
conn.close()
"@
$pythonScript | python
Write-Host ""
Write-Host "============================================================" -ForegroundColor Green
Write-Host " PANEL LOGIN CREDENTIALS " -ForegroundColor Green
Write-Host "============================================================" -ForegroundColor Green
Write-Host " Login: " -NoNewline; Write-Host "admin" -ForegroundColor White
Write-Host " Password: " -NoNewline; Write-Host $adminPassword -ForegroundColor White
Write-Host "============================================================" -ForegroundColor Green
Write-Host ""
# Save credentials
$credentialsFile = Join-Path $script:RUSTDESK_PATH ".admin_credentials"
"admin:$adminPassword" | Out-File -FilePath $credentialsFile -Encoding UTF8
Print-Info "Credentials saved in: $credentialsFile"
return $adminPassword
$pythonScript | python
Write-Host ""
Write-Host "============================================================" -ForegroundColor Green
Write-Host " PANEL LOGIN CREDENTIALS " -ForegroundColor Green
Write-Host "============================================================" -ForegroundColor Green
Write-Host " Login: " -NoNewline; Write-Host "admin" -ForegroundColor White
Write-Host " Password: " -NoNewline; Write-Host $adminPassword -ForegroundColor White
Write-Host "============================================================" -ForegroundColor Green
Write-Host ""
# Save credentials
$credentialsFile = Join-Path $script:RUSTDESK_PATH ".admin_credentials"
"admin:$adminPassword" | Out-File -FilePath $credentialsFile -Encoding UTF8
Print-Info "Credentials saved in: $credentialsFile"
return $adminPassword
}
}
function Start-Services {
@@ -1458,6 +1525,12 @@ function Do-Update {
if (-not (Install-Console)) { Print-Error "Console update failed"; return }
Run-Migrations
# Update scheduled tasks/services with latest configuration
Setup-ScheduledTasks
# Ensure admin user exists (especially for Node.js console migration)
Create-AdminUser | Out-Null
Start-Services
Print-Success "Update completed!"
+103 -28
View File
@@ -31,7 +31,7 @@
set -e
# Version
VERSION="2.2.0"
VERSION="2.2.1"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Auto mode flag
@@ -902,18 +902,41 @@ install_nodejs_console() {
# Create data directory for databases
mkdir -p "$CONSOLE_PATH/data"
# Create .env file if not exists
if [ ! -f "$CONSOLE_PATH/.env" ]; then
cat > "$CONSOLE_PATH/.env" << EOF
# Generate admin password for Node.js console
local nodejs_admin_password
nodejs_admin_password=$(openssl rand -base64 12 | tr -d '/+=' | head -c 16)
# Create .env file (always update to ensure correct paths)
cat > "$CONSOLE_PATH/.env" << EOF
# BetterDesk Node.js Console Configuration
PORT=5000
RUSTDESK_PATH=$RUSTDESK_PATH
API_PORT=$API_PORT
NODE_ENV=production
# RustDesk paths (critical for key/QR code generation)
RUSTDESK_DIR=$RUSTDESK_PATH
KEYS_PATH=$RUSTDESK_PATH
DB_PATH=$RUSTDESK_PATH/db_v2.sqlite3
PUB_KEY_PATH=$RUSTDESK_PATH/id_ed25519.pub
API_KEY_PATH=$RUSTDESK_PATH/.api_key
# Auth database location
DATA_DIR=$CONSOLE_PATH/data
# HBBS API
HBBS_API_URL=http://localhost:$API_PORT/api
# Default admin credentials (used only on first startup)
DEFAULT_ADMIN_USERNAME=admin
DEFAULT_ADMIN_PASSWORD=$nodejs_admin_password
# Session
SESSION_SECRET=$(openssl rand -hex 32)
EOF
print_info "Created .env configuration file"
fi
print_info "Created .env configuration file"
# Save Node.js admin credentials for display
echo "admin:$nodejs_admin_password" > "$CONSOLE_PATH/data/.admin_credentials"
chmod 600 "$CONSOLE_PATH/data/.admin_credentials"
# Set permissions
chown -R root:root "$CONSOLE_PATH"
@@ -1174,10 +1197,14 @@ After=network.target rustdesksignal.service
Type=simple
User=root
WorkingDirectory=$CONSOLE_PATH
EnvironmentFile=-$CONSOLE_PATH/.env
ExecStart=/usr/bin/node server.js
Environment=NODE_ENV=production
Environment=RUSTDESK_PATH=$RUSTDESK_PATH
Environment=API_PORT=$API_PORT
Environment=RUSTDESK_DIR=$RUSTDESK_PATH
Environment=KEYS_PATH=$RUSTDESK_PATH
Environment=DATA_DIR=$CONSOLE_PATH/data
Environment=DB_PATH=$RUSTDESK_PATH/db_v2.sqlite3
Environment=HBBS_API_URL=http://localhost:$API_PORT/api
Environment=PORT=5000
Restart=always
RestartSec=5
@@ -1246,11 +1273,52 @@ run_migrations() {
create_admin_user() {
print_step "Creating admin user..."
local admin_password
admin_password=$(openssl rand -base64 12 | tr -d '/+=' | head -c 16)
# Detect console type
local current_console_type=""
if [ -f "$CONSOLE_PATH/server.js" ]; then
current_console_type="nodejs"
elif [ -f "$CONSOLE_PATH/app.py" ]; then
current_console_type="flask"
else
print_warning "No console detected, skipping admin creation"
return
fi
# Create admin via Python
python3 << EOF
if [ "$current_console_type" = "nodejs" ]; then
# Node.js console - admin is created automatically on startup
# Read the password saved during install_nodejs_console
local creds_file="$CONSOLE_PATH/data/.admin_credentials"
if [ -f "$creds_file" ]; then
local admin_password
admin_password=$(cat "$creds_file" | cut -d':' -f2)
echo ""
echo -e "${GREEN}╔════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ PANEL LOGIN CREDENTIALS ║${NC}"
echo -e "${GREEN}╠════════════════════════════════════════════════════════╣${NC}"
echo -e "${GREEN}║ Login: ${WHITE}admin${GREEN}${NC}"
echo -e "${GREEN}║ Password: ${WHITE}${admin_password}${GREEN}${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════╝${NC}"
echo ""
# Also save to main RustDesk path for consistency
echo "admin:$admin_password" > "$RUSTDESK_PATH/.admin_credentials"
chmod 600 "$RUSTDESK_PATH/.admin_credentials"
print_info "Credentials saved in: $RUSTDESK_PATH/.admin_credentials"
else
print_warning "No Node.js admin credentials found"
print_info "Default credentials: admin / admin"
print_info "Please change password after first login!"
fi
else
# Flask console - create admin in db_v2.sqlite3
local admin_password
admin_password=$(openssl rand -base64 12 | tr -d '/+=' | head -c 16)
# Create admin via Python
python3 << EOF
import sqlite3
import bcrypt
from datetime import datetime
@@ -1285,20 +1353,21 @@ else:
conn.close()
EOF
echo ""
echo -e "${GREEN}╔════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ PANEL LOGIN CREDENTIALS ║${NC}"
echo -e "${GREEN}╠════════════════════════════════════════════════════════╣${NC}"
echo -e "${GREEN}║ Login: ${WHITE}admin${GREEN}${NC}"
echo -e "${GREEN}║ Password: ${WHITE}${admin_password}${GREEN}${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════╝${NC}"
echo ""
# Save credentials
echo "admin:$admin_password" > "$RUSTDESK_PATH/.admin_credentials"
chmod 600 "$RUSTDESK_PATH/.admin_credentials"
print_info "Credentials saved in: $RUSTDESK_PATH/.admin_credentials"
echo ""
echo -e "${GREEN}╔════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ PANEL LOGIN CREDENTIALS ║${NC}"
echo -e "${GREEN}╠════════════════════════════════════════════════════════╣${NC}"
echo -e "${GREEN}║ Login: ${WHITE}admin${GREEN}${NC}"
echo -e "${GREEN}║ Password: ${WHITE}${admin_password}${GREEN}${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════╝${NC}"
echo ""
# Save credentials
echo "admin:$admin_password" > "$RUSTDESK_PATH/.admin_credentials"
chmod 600 "$RUSTDESK_PATH/.admin_credentials"
print_info "Credentials saved in: $RUSTDESK_PATH/.admin_credentials"
fi
}
start_services() {
@@ -1393,6 +1462,12 @@ do_update() {
install_console
run_migrations
# Update systemd services with latest configuration
setup_services
# Ensure admin user exists (especially for Node.js console migration)
create_admin_user
# Start services with verification
start_services_with_verification
+2 -1
View File
@@ -13,8 +13,9 @@ const isProduction = NODE_ENV === 'production';
const isDocker = fs.existsSync('/.dockerenv') || process.env.DOCKER === 'true';
// Base paths
// Support multiple env var names for compatibility with different install scripts
const DATA_DIR = process.env.DATA_DIR || (isDocker ? '/app/data' : path.join(__dirname, '..', 'data'));
const KEYS_PATH = process.env.KEYS_PATH || process.env.RUSTDESK_DIR || (isDocker ? '/opt/rustdesk' : path.join(__dirname, '..', '..'));
const KEYS_PATH = process.env.KEYS_PATH || process.env.RUSTDESK_DIR || process.env.RUSTDESK_PATH || (isDocker ? '/opt/rustdesk' : '/opt/rustdesk');
const RUSTDESK_DIR = KEYS_PATH;
// Database path