added an option to add password from the connection properties (fixes #637)

This commit is contained in:
Eugene Pankov
2019-06-18 23:48:20 +02:00
parent 77058c0472
commit db3b8cc718
6 changed files with 59 additions and 29 deletions

View File

@@ -1,8 +1,7 @@
.modal-body .modal-body
ngb-tabset(type='pills', [activeId]='basic') ngb-tabset(type='pills', [activeId]='basic')
ngb-tab(id='basic') ngb-tab(id='basic')
ng-template(ngbTabTitle) ng-template(ngbTabTitle) General
| Basic Setting
ng-template(ngbTabContent) ng-template(ngbTabContent)
.form-group .form-group
label Name label Name
@@ -42,12 +41,22 @@
[(ngModel)]='connection.user', [(ngModel)]='connection.user',
) )
.alert.alert-info.d-flex.bg-transparent.text-white.align-items-center(*ngIf='hasSavedPassword') .form-line
.mr-auto There is a saved password for this connection .header
button.btn.btn-danger.ml-4((click)='clearSavedPassword()') Forget .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 .form-line
label Private key .header
.title Private key
.description Path to the private key file
.input-group .input-group
input.form-control( input.form-control(
type='text', type='text',
@@ -59,8 +68,7 @@
i.fas.fa-folder-open i.fas.fa-folder-open
ngb-tab(id='advanced') ngb-tab(id='advanced')
ng-template(ngbTabTitle) ng-template(ngbTabTitle) Advanced
| Advanced Setting
ng-template(ngbTabContent) ng-template(ngbTabContent)
.form-group .form-group
label Keep Alive Interval (Milliseconds) label Keep Alive Interval (Milliseconds)
@@ -108,8 +116,7 @@
ngb-tab(id='scripts') ngb-tab(id='scripts')
ng-template(ngbTabTitle) ng-template(ngbTabTitle) Login scripts
| Login Scripts
ng-template(ngbTabContent) ng-template(ngbTabContent)
table table
tr tr
@@ -130,11 +137,11 @@
[(ngModel)]='script.send' [(ngModel)]='script.send'
) )
td td
toggle( checkbox(
[(ngModel)]='script.isRegex', [(ngModel)]='script.isRegex',
) )
td td
toggle( checkbox(
[(ngModel)]='script.optional', [(ngModel)]='script.optional',
) )
td td
@@ -159,19 +166,17 @@
[(ngModel)]='newScript.send' [(ngModel)]='newScript.send'
) )
td td
toggle( checkbox(
[(ngModel)]='newScript.isRegex', [(ngModel)]='newScript.isRegex',
) )
td td
toggle( checkbox(
[(ngModel)]='newScript.optional', [(ngModel)]='newScript.optional',
) )
td td
.input-group.flex-nowrap .input-group.flex-nowrap
button.btn.btn-outline-info.ml-0((click)='addScript()') button.btn.btn-outline-info.ml-0((click)='addScript()')
i.fas.fa-check i.fas.fa-check
button.btn.btn-outline-danger.ml-0((click)='clearScript()')
i.fas.fa-trash
.modal-footer .modal-footer
button.btn.btn-outline-primary((click)='save()') Save button.btn.btn-outline-primary((click)='save()') Save

View File

@@ -1,8 +1,9 @@
import { Component } from '@angular/core' 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 { ElectronService, HostAppService } from 'terminus-core'
import { PasswordStorageService } from '../services/passwordStorage.service' import { PasswordStorageService } from '../services/passwordStorage.service'
import { SSHConnection, LoginScript, SSHAlgorithmType } from '../api' import { SSHConnection, LoginScript, SSHAlgorithmType } from '../api'
import { PromptModalComponent } from './promptModal.component'
import { ALGORITHMS } from 'ssh2-streams/lib/constants' import { ALGORITHMS } from 'ssh2-streams/lib/constants'
/** @hidden */ /** @hidden */
@@ -23,6 +24,7 @@ export class EditConnectionModalComponent {
private electron: ElectronService, private electron: ElectronService,
private hostApp: HostAppService, private hostApp: HostAppService,
private passwordStorage: PasswordStorageService, private passwordStorage: PasswordStorageService,
private ngbModal: NgbModal,
) { ) {
this.newScript = { expect: '', send: '' } 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 () { clearSavedPassword () {
this.hasSavedPassword = false this.hasSavedPassword = false
this.passwordStorage.deletePassword(this.connection) this.passwordStorage.deletePassword(this.connection)

View File

@@ -11,7 +11,7 @@
.d-flex.align-items-start.mt-2 .d-flex.align-items-start.mt-2
checkbox( checkbox(
*ngIf='showRememberCheckbox', *ngIf='showRememberCheckbox',
[(model)]='remember', [(ngModel)]='remember',
text='Remember' text='Remember'
) )
button.btn.btn-primary.ml-auto( button.btn.btn-primary.ml-auto(

View File

@@ -23,10 +23,13 @@ export class PromptModalComponent {
} }
ok () { ok () {
this.modalInstance.close(this.value) this.modalInstance.close({
value: this.value,
remember: this.remember,
})
} }
cancel () { cancel () {
this.modalInstance.close('') this.modalInstance.close(null)
} }
} }

View File

@@ -43,7 +43,7 @@ export class SSHSettingsTabComponent {
} }
editConnection (connection: SSHConnection) { editConnection (connection: SSHConnection) {
const modal = this.ngbModal.open(EditConnectionModalComponent) const modal = this.ngbModal.open(EditConnectionModalComponent, { size: 'lg' })
modal.componentInstance.connection = Object.assign({}, connection) modal.componentInstance.connection = Object.assign({}, connection)
modal.result.then(result => { modal.result.then(result => {
Object.assign(connection, result) Object.assign(connection, result)
@@ -77,7 +77,7 @@ export class SSHSettingsTabComponent {
modal.result.then(result => { modal.result.then(result => {
if (result) { if (result) {
for (const connection of this.connections.filter(x => x.group === group.name)) { 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.store.ssh.connections = this.connections
this.config.save() this.config.save()

View File

@@ -82,7 +82,10 @@ export class SSHService {
modal.componentInstance.prompt = 'Private key passphrase' modal.componentInstance.prompt = 'Private key passphrase'
modal.componentInstance.password = true modal.componentInstance.password = true
try { try {
privateKeyPassphrase = await modal.result const result = await modal.result
if (result) {
privateKeyPassphrase = result.value
}
} catch (e) { } } catch (e) { }
} }
} }
@@ -119,7 +122,8 @@ export class SSHService {
const modal = this.ngbModal.open(PromptModalComponent) const modal = this.ngbModal.open(PromptModalComponent)
modal.componentInstance.prompt = prompt.prompt modal.componentInstance.prompt = prompt.prompt
modal.componentInstance.password = !prompt.echo modal.componentInstance.password = !prompt.echo
results.push(await modal.result) const result = await modal.result
results.push(result ? result.value : '')
} }
finish(results) finish(results)
})) }))
@@ -194,11 +198,14 @@ export class SSHService {
modal.componentInstance.password = true modal.componentInstance.password = true
modal.componentInstance.showRememberCheckbox = true modal.componentInstance.showRememberCheckbox = true
try { try {
let password = await modal.result const result = await modal.result
if (modal.componentInstance.remember) { if (result) {
savedPassword = password if (result.remember) {
savedPassword = result.value
} }
return password return result.value
}
return ''
} catch (_) { } catch (_) {
return '' return ''
} }