This commit is contained in:
laurentlemercier 2024-12-27 09:23:59 +01:00 committed by GitHub
commit ec982ecf30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 56 additions and 19 deletions

View file

@ -20,3 +20,6 @@ services:
environment: environment:
# Tell Dockge where is your stacks directory # Tell Dockge where is your stacks directory
- DOCKGE_STACKS_DIR=/opt/stacks - DOCKGE_STACKS_DIR=/opt/stacks
# Usefull for interactive action within the container
stdin_open: true # docker run -i
tty: true # docker run -t

View file

@ -6,6 +6,7 @@ import { DockgeServer } from "../backend/dockge-server";
import { log } from "../backend/log"; import { log } from "../backend/log";
import { io } from "socket.io-client"; import { io } from "socket.io-client";
import { BaseRes } from "../common/util-common"; import { BaseRes } from "../common/util-common";
import { generatePasswordHash } from "../backend/password-hash";
console.log("== Dockge Reset Password Tool =="); console.log("== Dockge Reset Password Tool ==");
@ -29,35 +30,67 @@ export const main = async () => {
} }
try { try {
let user ;
// No need to actually reset the password for testing, just make sure no connection problem. It is ok for now. // No need to actually reset the password for testing, just make sure no connection problem. It is ok for now.
if (!process.env.TEST_BACKEND) { if (!process.env.TEST_BACKEND) {
const user = await R.findOne("user"); user = await R.findOne("user");
if (! user) {
throw new Error("user not found, have you installed?"); if (! user ) {
if ( !process.env.USER ) {
throw new Error("user not found or provided, have you installed? Try to set USER and PASSWORD variables ...");
} else {
console.log("Trying to initialise user : " + process.env.USER);
user = R.dispense("user");
user.username = process.env.USER;
user.password = generatePasswordHash(process.env.PASSWORD);
await R.store(user);
console.log("User/Password set successfully");
// Reset all sessions by reset jwt secret
await server.initJWTSecret();
console.log("JWT reset successfully.");
// Disconnect all other socket clients of the user
await disconnectAllSocketClients(user.username, user.password);
console.log("You may have to restart");
exit;
}
}
} }
console.log("Found user: " + user.username); let password = "";
let confirmPassword = " ";
while (true) { while (true) {
let password = await question("New Password: ");
let confirmPassword = await question("Confirm New Password: "); if (process.env.PASSWORD) {
console.log("Found password : " + process.env.PASSWORD) ;
password = process.env.PASSWORD ;
confirmPassword = process.env.PASSWORD ;
} else {
console.log("No found password: " ) ;
password = await question("New Password: ");
confirmPassword = await question("Confirm New Password: ");
}
if (password === confirmPassword) { if (password === confirmPassword) {
await User.resetPassword(user.id, password); await User.resetPassword(user.id, password);
console.log("Password reset successfully.");
// Reset all sessions by reset jwt secret // Reset all sessions by reset jwt secret
await server.initJWTSecret(); await server.initJWTSecret();
console.log("Password reset successfully."); console.log("JWT reset successfully.");
// Disconnect all other socket clients of the user // Disconnect all other socket clients of the user
await disconnectAllSocketClients(user.username, password); await disconnectAllSocketClients(user.username, password);
break;
} else { } else {
console.log("Passwords do not match, please try again."); console.log("Passwords do not match, please try again.");
break;
} }
} break;
} }
} catch (e) { } catch (e) {
if (e instanceof Error) { if (e instanceof Error) {
@ -127,3 +160,4 @@ function disconnectAllSocketClients(username : string, password : string) : Prom
if (!process.env.TEST_BACKEND) { if (!process.env.TEST_BACKEND) {
main(); main();
} }