mirror of
https://github.com/UNITRONIX/BetterDesk.git
synced 2026-09-10 01:27:11 +00:00
d717331041
Multiple updates to improve cross-platform path handling, credential persistence, and folder assignment tracking. - betterdesk.ps1: Check both console and RustDesk credential locations when backing up; save reset admin password to both console and RustDesk locations, create console data dir if missing, and print info messages. - web-nodejs/reset-password.js & scripts/reset-password.js: Use platform-aware default DB/data paths (Windows/Linux), consider extra env vars, and default to a data subdirectory when not found. - web-nodejs/routes/rustdesk-api.routes.js: Await async generateAccessToken calls to ensure tokens are generated before continuing. - web-nodejs/services/dbAdapter.js: Update assignDeviceToFolder for SQLite and Postgres to maintain a device_folder_assignments table (insert/update or delete as appropriate) and remove assignments when folders are deleted; also fix a Postgres JSONB cast. These changes unify credential storage, improve Windows support, fix an async bug, and add explicit folder assignment tracking used by getAllFolderAssignments.
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
const bcrypt = require('./node_modules/bcrypt');
|
|
const Database = require('better-sqlite3');
|
|
const path = require('path');
|
|
|
|
// Platform-aware default path (C:\BetterDesk on Windows, /opt/rustdesk on Linux)
|
|
const isWindows = process.platform === 'win32';
|
|
const defaultPath = isWindows ? 'C:\\BetterDesk\\db_v2.sqlite3' : '/opt/rustdesk/db_v2.sqlite3';
|
|
const DB_PATH = process.env.DB_PATH || defaultPath;
|
|
const NEW_PASSWORD = process.argv[2] || 'admin';
|
|
|
|
async function resetPassword() {
|
|
const hash = await bcrypt.hash(NEW_PASSWORD, 12);
|
|
|
|
const db = new Database(DB_PATH);
|
|
|
|
const result = db.prepare('UPDATE users SET password_hash = ? WHERE username = ?').run(hash, 'admin');
|
|
|
|
if (result.changes > 0) {
|
|
console.log('Password reset successful!');
|
|
console.log('Username: admin');
|
|
console.log('Password:', NEW_PASSWORD);
|
|
} else {
|
|
console.log('No admin user found, creating one...');
|
|
db.prepare('INSERT INTO users (username, password_hash, role) VALUES (?, ?, ?)').run('admin', hash, 'admin');
|
|
console.log('Admin user created!');
|
|
console.log('Username: admin');
|
|
console.log('Password:', NEW_PASSWORD);
|
|
}
|
|
|
|
db.close();
|
|
}
|
|
|
|
resetPassword().catch(console.error);
|