Skip to content

Commit

Permalink
some refactoring a error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dominusmars committed Mar 6, 2024
1 parent 5e004b3 commit fb99703
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
39 changes: 22 additions & 17 deletions src/db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,27 +709,32 @@ class DataBase {
}
}
async writeUserFailedPassword(user_id: string, password: string) {
if (!password) {
return false;
}
try {
if (!password) {
return false;
}

let encryptKey = await this.getDbEncryptionKey();
if (!encryptKey) {
this.log.log("Unable to get encryption key");
return false;
}
let user = await this.users.get(user_id).catch(() => undefined);
if (!user) {
return false;
}
let encryptKey = await this.getDbEncryptionKey();
if (!encryptKey) {
this.log.log("Unable to get encryption key");
return false;
}
let user = await this.users.get(user_id).catch(() => undefined);
if (!user) {
return false;
}

let password_encrypted = this.encrypt.encrypt(password, encryptKey);
user.failedPasswords ? user.failedPasswords.push(password_encrypted) : [password_encrypted];
let password_encrypted = this.encrypt.encrypt(password, encryptKey);
user.failedPasswords ? user.failedPasswords.push(password_encrypted) : [password_encrypted];

await this.users.put(user.user_id, user);
this.changes++;
await this.users.put(user.user_id, user);
this.changes++;

return true;
return true;
} catch (error) {
this.log.log((error as Error).message);
return false;
}
}

private async updateDomainUser(username: string, domain: string, passwordHash: string, skip_id: string) {
Expand Down
6 changes: 2 additions & 4 deletions src/front/page/addComputer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ const addComputer = async function () {

async function trySSH(): Promise<void> {
var computer_info = await scanSSH(ip, user, pass);
// console.log(computer_info);
let success = false;
if (typeof computer_info == "object") {
await runningDB.addTargetAndUser(computer_info.hostname, ip, user, pass, computer_info.operatingSystem, computer_info.domain);
log(`Added`, "success");
success = true;
success = await runningDB.addTargetAndUser(computer_info.hostname, ip, user, pass, computer_info.operatingSystem, computer_info.domain);
if (success) log(`Added`, "success");
} else {
log(`Unable to reach computer, Not Added`, "error");
}
Expand Down
3 changes: 1 addition & 2 deletions src/front/page/passwordScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ async function runScriptNetworkSelect(debug?: boolean) {
return false;
});

log(`Selected ${computers.length} targets`);
log(`Selected ${computers.length} targets on ${networks.join(" ")}`);

const { seed } = await inquirer.prompt([
{
Expand All @@ -326,7 +326,6 @@ async function runScriptNetworkSelect(debug?: boolean) {
const runningLog = results.reduce((prev, value) => {
if (!value) return prev;
if (typeof value == "boolean") return prev + "UNKNOWN\n";
// console.log(JSON.stringify(value))

let results = (value as PromiseFulfilledResult<string[]>).value;
let computerLine = "";
Expand Down

0 comments on commit fb99703

Please sign in to comment.