diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 8faeb333..e162695c 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -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 diff --git a/VERSION b/VERSION index e3a4f193..fae692e4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.0 \ No newline at end of file +2.2.1 \ No newline at end of file diff --git a/betterdesk.ps1 b/betterdesk.ps1 index 8ba33ac4..84cac6df 100644 --- a/betterdesk.ps1 +++ b/betterdesk.ps1 @@ -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!" diff --git a/betterdesk.sh b/betterdesk.sh index b2e73ed2..24924cc0 100644 --- a/betterdesk.sh +++ b/betterdesk.sh @@ -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 diff --git a/web-nodejs/config/config.js b/web-nodejs/config/config.js index d769c7de..8aebc61a 100644 --- a/web-nodejs/config/config.js +++ b/web-nodejs/config/config.js @@ -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