mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-30 08:19:54 +00:00
more cleanup
This commit is contained in:
parent
d6f163b048
commit
7d25816751
@ -21,7 +21,7 @@ export class SSHSession extends BaseSession {
|
|||||||
|
|
||||||
constructor (private shell: any, conn: SSHConnection) {
|
constructor (private shell: any, conn: SSHConnection) {
|
||||||
super()
|
super()
|
||||||
this.scripts = conn.scripts ? [...conn.scripts] : []
|
this.scripts = conn.scripts || []
|
||||||
}
|
}
|
||||||
|
|
||||||
start () {
|
start () {
|
||||||
@ -31,23 +31,21 @@ export class SSHSession extends BaseSession {
|
|||||||
let dataString = data.toString()
|
let dataString = data.toString()
|
||||||
this.emitOutput(dataString)
|
this.emitOutput(dataString)
|
||||||
|
|
||||||
if (this.scripts && this.scripts.length > 0) {
|
if (this.scripts) {
|
||||||
let found = false
|
let found = false
|
||||||
for (let i = 0; i < this.scripts.length; i++) {
|
for (let script of this.scripts) {
|
||||||
if (dataString.indexOf(this.scripts[i].expect) >= 0) {
|
if (dataString.includes(script.expect)) {
|
||||||
console.log("Executing: " + this.scripts[i].send)
|
console.log('Executing script:', script.send)
|
||||||
this.shell.write(this.scripts[i].send + "\n")
|
this.shell.write(script.send + '\n')
|
||||||
this.scripts.splice(i, 1)
|
this.scripts = this.scripts.filter(x => x !== script)
|
||||||
i--
|
|
||||||
found = true
|
found = true
|
||||||
}
|
} else {
|
||||||
else {
|
break
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
this.executeScripts()
|
this.executeUnconditionalScripts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -58,23 +56,7 @@ export class SSHSession extends BaseSession {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.executeScripts()
|
this.executeUnconditionalScripts()
|
||||||
}
|
|
||||||
|
|
||||||
executeScripts () {
|
|
||||||
if (this.scripts && this.scripts.length > 0) {
|
|
||||||
for (let i = 0; i < this.scripts.length; i++) {
|
|
||||||
if (!this.scripts[i].expect) {
|
|
||||||
console.log("Executing: " + this.scripts[i].send)
|
|
||||||
this.shell.write(this.scripts[i].send + "\n")
|
|
||||||
this.scripts.splice(i, 1)
|
|
||||||
i--
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resize (columns, rows) {
|
resize (columns, rows) {
|
||||||
@ -100,6 +82,20 @@ export class SSHSession extends BaseSession {
|
|||||||
async getWorkingDirectory (): Promise<string> {
|
async getWorkingDirectory (): Promise<string> {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private executeUnconditionalScripts () {
|
||||||
|
if (this.scripts) {
|
||||||
|
for (let script of this.scripts) {
|
||||||
|
if (!script.expect) {
|
||||||
|
console.log('Executing script:', script.send)
|
||||||
|
this.shell.write(script.send + '\n')
|
||||||
|
this.scripts = this.scripts.filter(x => x !== script)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISSHConnectionGroup {
|
export interface ISSHConnectionGroup {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
ng-template(ngbTabTitle)
|
ng-template(ngbTabTitle)
|
||||||
| Basic Setting
|
| Basic Setting
|
||||||
ng-template(ngbTabContent)
|
ng-template(ngbTabContent)
|
||||||
h4 Basic Setting
|
|
||||||
.form-group
|
.form-group
|
||||||
label Name
|
label Name
|
||||||
input.form-control(
|
input.form-control(
|
||||||
@ -59,11 +58,9 @@
|
|||||||
ng-template(ngbTabTitle)
|
ng-template(ngbTabTitle)
|
||||||
| Login Scripts
|
| Login Scripts
|
||||||
ng-template(ngbTabContent)
|
ng-template(ngbTabContent)
|
||||||
h4 Login Scripts
|
|
||||||
.list-group
|
|
||||||
table
|
table
|
||||||
tr
|
tr
|
||||||
th String to wait
|
th String to expect
|
||||||
th String to be sent
|
th String to be sent
|
||||||
th Actions
|
th Actions
|
||||||
tr(*ngFor='let script of connection.scripts')
|
tr(*ngFor='let script of connection.scripts')
|
||||||
@ -79,17 +76,17 @@
|
|||||||
)
|
)
|
||||||
td
|
td
|
||||||
.input-group.flex-nowrap
|
.input-group.flex-nowrap
|
||||||
button.btn.btn-outline-info.ml-0((click)='up(script)')
|
button.btn.btn-outline-info.ml-0((click)='moveScriptUp(script)')
|
||||||
i.fa.fa-arrow-up
|
i.fa.fa-arrow-up
|
||||||
button.btn.btn-outline-info.ml-0((click)='down(script)')
|
button.btn.btn-outline-info.ml-0((click)='moveScriptDown(script)')
|
||||||
i.fa.fa-arrow-down
|
i.fa.fa-arrow-down
|
||||||
button.btn.btn-outline-danger.ml-0((click)='delete(script)')
|
button.btn.btn-outline-danger.ml-0((click)='deleteScript(script)')
|
||||||
i.fa.fa-trash-o
|
i.fa.fa-trash-o
|
||||||
tr
|
tr
|
||||||
td
|
td
|
||||||
input.form-control(
|
input.form-control(
|
||||||
type='text',
|
type='text',
|
||||||
placeholder='Enter a string to wait',
|
placeholder='Enter a string to expect',
|
||||||
[(ngModel)]='newScript.expect'
|
[(ngModel)]='newScript.expect'
|
||||||
)
|
)
|
||||||
td
|
td
|
||||||
@ -100,9 +97,9 @@
|
|||||||
)
|
)
|
||||||
td
|
td
|
||||||
.input-group.flex-nowrap
|
.input-group.flex-nowrap
|
||||||
button.btn.btn-outline-info.ml-0((click)='add()')
|
button.btn.btn-outline-info.ml-0((click)='addScript()')
|
||||||
i.fa.fa-save
|
i.fa.fa-check
|
||||||
button.btn.btn-outline-danger.ml-0((click)='clear()')
|
button.btn.btn-outline-danger.ml-0((click)='clearScript()')
|
||||||
i.fa.fa-trash-o
|
i.fa.fa-trash-o
|
||||||
|
|
||||||
.modal-footer
|
.modal-footer
|
||||||
|
@ -15,7 +15,7 @@ export class EditConnectionModalComponent {
|
|||||||
private electron: ElectronService,
|
private electron: ElectronService,
|
||||||
private hostApp: HostAppService,
|
private hostApp: HostAppService,
|
||||||
) {
|
) {
|
||||||
this.newScript = { expect: "", send: ""}
|
this.newScript = { expect: '', send: '' }
|
||||||
}
|
}
|
||||||
|
|
||||||
selectPrivateKey () {
|
selectPrivateKey () {
|
||||||
@ -38,37 +38,38 @@ export class EditConnectionModalComponent {
|
|||||||
this.modalInstance.dismiss()
|
this.modalInstance.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
up (script: LoginScript) {
|
moveScriptUp (script: LoginScript) {
|
||||||
let index = this.connection.scripts.indexOf(script)
|
let index = this.connection.scripts.indexOf(script)
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
this.connection.scripts.splice(index, 1);
|
this.connection.scripts.splice(index, 1)
|
||||||
this.connection.scripts.splice(index - 1, 0, script);
|
this.connection.scripts.splice(index - 1, 0, script)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
down (script: LoginScript) {
|
moveScriptDown (script: LoginScript) {
|
||||||
let index = this.connection.scripts.indexOf(script)
|
let index = this.connection.scripts.indexOf(script)
|
||||||
if (index >= 0 && index < this.connection.scripts.length - 1) {
|
if (index >= 0 && index < this.connection.scripts.length - 1) {
|
||||||
this.connection.scripts.splice(index, 1);
|
this.connection.scripts.splice(index, 1)
|
||||||
this.connection.scripts.splice(index + 1, 0, script);
|
this.connection.scripts.splice(index + 1, 0, script)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete (script: LoginScript) {
|
deleteScript (script: LoginScript) {
|
||||||
if (confirm(`Delete?`)) {
|
if (confirm(`Delete?`)) {
|
||||||
this.connection.scripts = this.connection.scripts.filter(x => x !== script)
|
this.connection.scripts = this.connection.scripts.filter(x => x !== script)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add () {
|
addScript () {
|
||||||
if (!this.connection.scripts)
|
if (!this.connection.scripts) {
|
||||||
this.connection.scripts = []
|
this.connection.scripts = []
|
||||||
this.connection.scripts.push(Object.assign({}, this.newScript))
|
}
|
||||||
this.clear();
|
this.connection.scripts.push({...this.newScript})
|
||||||
|
this.clearScript()
|
||||||
}
|
}
|
||||||
|
|
||||||
clear () {
|
clearScript () {
|
||||||
this.newScript.expect = ""
|
this.newScript.expect = ''
|
||||||
this.newScript.send = ""
|
this.newScript.send = ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ export class SSHModalComponent {
|
|||||||
|
|
||||||
let connections = this.connections
|
let connections = this.connections
|
||||||
if (this.quickTarget) {
|
if (this.quickTarget) {
|
||||||
connections = connections.filter(connection => (connection.name + connection.group).toLowerCase().indexOf(this.quickTarget) >= 0)
|
connections = connections.filter(connection => (connection.name + connection.group).toLowerCase().includes(this.quickTarget))
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let connection of connections) {
|
for (let connection of connections) {
|
||||||
|
@ -61,7 +61,7 @@ export class SSHSettingsTabComponent {
|
|||||||
editGroup (group: ISSHConnectionGroup) {
|
editGroup (group: ISSHConnectionGroup) {
|
||||||
let modal = this.ngbModal.open(PromptModalComponent)
|
let modal = this.ngbModal.open(PromptModalComponent)
|
||||||
modal.componentInstance.prompt = 'New group name'
|
modal.componentInstance.prompt = 'New group name'
|
||||||
modal.componentInstance.value = group
|
modal.componentInstance.value = group.name
|
||||||
modal.result.then(result => {
|
modal.result.then(result => {
|
||||||
if (result) {
|
if (result) {
|
||||||
for (let connection of this.connections.filter(x => x.group === group.name)) {
|
for (let connection of this.connections.filter(x => x.group === group.name)) {
|
||||||
|
@ -55,7 +55,7 @@ export class SSHService {
|
|||||||
modal.componentInstance.password = true
|
modal.componentInstance.password = true
|
||||||
try {
|
try {
|
||||||
privateKeyPassphrase = await modal.result
|
privateKeyPassphrase = await modal.result
|
||||||
} catch (_err) { }
|
} catch (_err) { } // tslint:disable-line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user