From db3b8cc718facddc41eca3a9ac7e8052d5b4c693 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Tue, 18 Jun 2019 23:48:20 +0200 Subject: [PATCH] added an option to add password from the connection properties (fixes #637) --- .../editConnectionModal.component.pug | 39 +++++++++++-------- .../editConnectionModal.component.ts | 17 +++++++- .../src/components/promptModal.component.pug | 2 +- .../src/components/promptModal.component.ts | 7 +++- .../components/sshSettingsTab.component.ts | 4 +- terminus-ssh/src/services/ssh.service.ts | 19 ++++++--- 6 files changed, 59 insertions(+), 29 deletions(-) diff --git a/terminus-ssh/src/components/editConnectionModal.component.pug b/terminus-ssh/src/components/editConnectionModal.component.pug index e86d85bf..0a257706 100644 --- a/terminus-ssh/src/components/editConnectionModal.component.pug +++ b/terminus-ssh/src/components/editConnectionModal.component.pug @@ -1,8 +1,7 @@ .modal-body ngb-tabset(type='pills', [activeId]='basic') ngb-tab(id='basic') - ng-template(ngbTabTitle) - | Basic Setting + ng-template(ngbTabTitle) General ng-template(ngbTabContent) .form-group label Name @@ -42,12 +41,22 @@ [(ngModel)]='connection.user', ) - .alert.alert-info.d-flex.bg-transparent.text-white.align-items-center(*ngIf='hasSavedPassword') - .mr-auto There is a saved password for this connection - button.btn.btn-danger.ml-4((click)='clearSavedPassword()') Forget + .form-line + .header + .title Password + .description(*ngIf='!hasSavedPassword') Save a password in the keychain + .description(*ngIf='hasSavedPassword') There is a saved password for this connection + button.btn.btn-outline-success.ml-4(*ngIf='!hasSavedPassword', (click)='setPassword()') + i.fas.fa-key + span Set password + button.btn.btn-danger.ml-4(*ngIf='hasSavedPassword', (click)='clearSavedPassword()') + i.fas.fa-trash-alt + span Forget - .form-group - label Private key + .form-line + .header + .title Private key + .description Path to the private key file .input-group input.form-control( type='text', @@ -59,8 +68,7 @@ i.fas.fa-folder-open ngb-tab(id='advanced') - ng-template(ngbTabTitle) - | Advanced Setting + ng-template(ngbTabTitle) Advanced ng-template(ngbTabContent) .form-group label Keep Alive Interval (Milliseconds) @@ -108,8 +116,7 @@ ngb-tab(id='scripts') - ng-template(ngbTabTitle) - | Login Scripts + ng-template(ngbTabTitle) Login scripts ng-template(ngbTabContent) table tr @@ -130,11 +137,11 @@ [(ngModel)]='script.send' ) td - toggle( + checkbox( [(ngModel)]='script.isRegex', ) td - toggle( + checkbox( [(ngModel)]='script.optional', ) td @@ -159,19 +166,17 @@ [(ngModel)]='newScript.send' ) td - toggle( + checkbox( [(ngModel)]='newScript.isRegex', ) td - toggle( + checkbox( [(ngModel)]='newScript.optional', ) td .input-group.flex-nowrap button.btn.btn-outline-info.ml-0((click)='addScript()') i.fas.fa-check - button.btn.btn-outline-danger.ml-0((click)='clearScript()') - i.fas.fa-trash .modal-footer button.btn.btn-outline-primary((click)='save()') Save diff --git a/terminus-ssh/src/components/editConnectionModal.component.ts b/terminus-ssh/src/components/editConnectionModal.component.ts index 4b1c6540..4621760b 100644 --- a/terminus-ssh/src/components/editConnectionModal.component.ts +++ b/terminus-ssh/src/components/editConnectionModal.component.ts @@ -1,8 +1,9 @@ import { Component } from '@angular/core' -import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' +import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' import { ElectronService, HostAppService } from 'terminus-core' import { PasswordStorageService } from '../services/passwordStorage.service' import { SSHConnection, LoginScript, SSHAlgorithmType } from '../api' +import { PromptModalComponent } from './promptModal.component' import { ALGORITHMS } from 'ssh2-streams/lib/constants' /** @hidden */ @@ -23,6 +24,7 @@ export class EditConnectionModalComponent { private electron: ElectronService, private hostApp: HostAppService, private passwordStorage: PasswordStorageService, + private ngbModal: NgbModal, ) { this.newScript = { expect: '', send: '' } @@ -59,6 +61,19 @@ export class EditConnectionModalComponent { } } + async setPassword () { + const modal = this.ngbModal.open(PromptModalComponent) + modal.componentInstance.prompt = `Password for ${this.connection.user}@${this.connection.host}` + modal.componentInstance.password = true + try { + const result = await modal.result + if (result && result.value) { + this.passwordStorage.savePassword(this.connection, result.value) + this.hasSavedPassword = true + } + } catch { } + } + clearSavedPassword () { this.hasSavedPassword = false this.passwordStorage.deletePassword(this.connection) diff --git a/terminus-ssh/src/components/promptModal.component.pug b/terminus-ssh/src/components/promptModal.component.pug index 0e51382a..1dfb759c 100644 --- a/terminus-ssh/src/components/promptModal.component.pug +++ b/terminus-ssh/src/components/promptModal.component.pug @@ -11,7 +11,7 @@ .d-flex.align-items-start.mt-2 checkbox( *ngIf='showRememberCheckbox', - [(model)]='remember', + [(ngModel)]='remember', text='Remember' ) button.btn.btn-primary.ml-auto( diff --git a/terminus-ssh/src/components/promptModal.component.ts b/terminus-ssh/src/components/promptModal.component.ts index 984f856a..262e0573 100644 --- a/terminus-ssh/src/components/promptModal.component.ts +++ b/terminus-ssh/src/components/promptModal.component.ts @@ -23,10 +23,13 @@ export class PromptModalComponent { } ok () { - this.modalInstance.close(this.value) + this.modalInstance.close({ + value: this.value, + remember: this.remember, + }) } cancel () { - this.modalInstance.close('') + this.modalInstance.close(null) } } diff --git a/terminus-ssh/src/components/sshSettingsTab.component.ts b/terminus-ssh/src/components/sshSettingsTab.component.ts index 1a6ed4bb..e9d6c6f9 100644 --- a/terminus-ssh/src/components/sshSettingsTab.component.ts +++ b/terminus-ssh/src/components/sshSettingsTab.component.ts @@ -43,7 +43,7 @@ export class SSHSettingsTabComponent { } editConnection (connection: SSHConnection) { - const modal = this.ngbModal.open(EditConnectionModalComponent) + const modal = this.ngbModal.open(EditConnectionModalComponent, { size: 'lg' }) modal.componentInstance.connection = Object.assign({}, connection) modal.result.then(result => { Object.assign(connection, result) @@ -77,7 +77,7 @@ export class SSHSettingsTabComponent { modal.result.then(result => { if (result) { for (const connection of this.connections.filter(x => x.group === group.name)) { - connection.group = result + connection.group = result.value } this.config.store.ssh.connections = this.connections this.config.save() diff --git a/terminus-ssh/src/services/ssh.service.ts b/terminus-ssh/src/services/ssh.service.ts index 8971312d..7b35712a 100644 --- a/terminus-ssh/src/services/ssh.service.ts +++ b/terminus-ssh/src/services/ssh.service.ts @@ -82,7 +82,10 @@ export class SSHService { modal.componentInstance.prompt = 'Private key passphrase' modal.componentInstance.password = true try { - privateKeyPassphrase = await modal.result + const result = await modal.result + if (result) { + privateKeyPassphrase = result.value + } } catch (e) { } } } @@ -119,7 +122,8 @@ export class SSHService { const modal = this.ngbModal.open(PromptModalComponent) modal.componentInstance.prompt = prompt.prompt modal.componentInstance.password = !prompt.echo - results.push(await modal.result) + const result = await modal.result + results.push(result ? result.value : '') } finish(results) })) @@ -194,11 +198,14 @@ export class SSHService { modal.componentInstance.password = true modal.componentInstance.showRememberCheckbox = true try { - let password = await modal.result - if (modal.componentInstance.remember) { - savedPassword = password + const result = await modal.result + if (result) { + if (result.remember) { + savedPassword = result.value + } + return result.value } - return password + return '' } catch (_) { return '' }