mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-17 09:59:58 +00:00
Support login scripts. Fix #344
This commit is contained in:
parent
4b1ba7863f
commit
2ea2c02845
@ -1,5 +1,10 @@
|
|||||||
import { BaseSession } from 'terminus-terminal'
|
import { BaseSession } from 'terminus-terminal'
|
||||||
|
|
||||||
|
export interface LoginScript {
|
||||||
|
expect?: string
|
||||||
|
send: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface SSHConnection {
|
export interface SSHConnection {
|
||||||
name?: string
|
name?: string
|
||||||
host: string
|
host: string
|
||||||
@ -7,18 +12,48 @@ export interface SSHConnection {
|
|||||||
user: string
|
user: string
|
||||||
password?: string
|
password?: string
|
||||||
privateKey?: string
|
privateKey?: string
|
||||||
|
scripts?: LoginScript[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SSHSession extends BaseSession {
|
export class SSHSession extends BaseSession {
|
||||||
constructor (private shell: any) {
|
scripts?: LoginScript[]
|
||||||
|
|
||||||
|
constructor (private shell: any, conn: SSHConnection) {
|
||||||
super()
|
super()
|
||||||
|
this.scripts = conn.scripts.slice(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
start () {
|
start () {
|
||||||
this.open = true
|
this.open = true
|
||||||
|
|
||||||
this.shell.on('data', data => {
|
this.shell.on('data', data => {
|
||||||
this.emitOutput(data.toString())
|
let dataString = data.toString()
|
||||||
|
this.emitOutput(dataString)
|
||||||
|
|
||||||
|
if (this.scripts && this.scripts.length > 0)
|
||||||
|
{
|
||||||
|
let found = false
|
||||||
|
for (let i = 0; i < this.scripts.length; i++)
|
||||||
|
{
|
||||||
|
if (dataString.indexOf(this.scripts[i].expect) >= 0)
|
||||||
|
{
|
||||||
|
console.log("Executing: " + this.scripts[i].send)
|
||||||
|
this.shell.write(this.scripts[i].send + "\n")
|
||||||
|
this.scripts.splice(i, 1)
|
||||||
|
i--
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
this.executeScripts()
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.shell.on('end', () => {
|
this.shell.on('end', () => {
|
||||||
@ -26,6 +61,28 @@ export class SSHSession extends BaseSession {
|
|||||||
this.destroy()
|
this.destroy()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.executeScripts()
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
.modal-body
|
.modal-body
|
||||||
|
ngb-tabset(type='tabs', [activeId]='basic')
|
||||||
|
ngb-tab(id='basic')
|
||||||
|
ng-template(ngbTabTitle)
|
||||||
|
| Basic Setting
|
||||||
|
ng-template(ngbTabContent)
|
||||||
|
h4 Basic Setting
|
||||||
.form-group
|
.form-group
|
||||||
label Name
|
label Name
|
||||||
input.form-control(
|
input.form-control(
|
||||||
@ -40,6 +46,56 @@
|
|||||||
button.btn.btn-secondary((click)='selectPrivateKey()')
|
button.btn.btn-secondary((click)='selectPrivateKey()')
|
||||||
i.fa.fa-folder-open
|
i.fa.fa-folder-open
|
||||||
|
|
||||||
|
ngb-tab(id='scripts')
|
||||||
|
ng-template(ngbTabTitle)
|
||||||
|
| Login Scripts
|
||||||
|
ng-template(ngbTabContent)
|
||||||
|
h4 Login Scripts
|
||||||
|
.list-group
|
||||||
|
table
|
||||||
|
tr
|
||||||
|
th String to wait
|
||||||
|
th String to be sent
|
||||||
|
th Actions
|
||||||
|
tr(*ngFor='let script of connection.scripts')
|
||||||
|
td
|
||||||
|
input.form-control(
|
||||||
|
type='text',
|
||||||
|
value='{{script.expect}}',
|
||||||
|
)
|
||||||
|
td
|
||||||
|
input.form-control(
|
||||||
|
type='text',
|
||||||
|
value='{{script.send}}',
|
||||||
|
)
|
||||||
|
td
|
||||||
|
.input-group
|
||||||
|
button.btn.btn-outline-info.ml-0((click)='up(script)')
|
||||||
|
i.fa.fa-arrow-up
|
||||||
|
button.btn.btn-outline-info.ml-0((click)='down(script)')
|
||||||
|
i.fa.fa-arrow-down
|
||||||
|
button.btn.btn-outline-danger.ml-0((click)='delete(script)')
|
||||||
|
i.fa.fa-trash-o
|
||||||
|
tr
|
||||||
|
td
|
||||||
|
input.form-control(
|
||||||
|
type='text',
|
||||||
|
placeholder='Enter a string to wait',
|
||||||
|
[(ngModel)]='newScript.expect'
|
||||||
|
)
|
||||||
|
td
|
||||||
|
input.form-control(
|
||||||
|
type='text',
|
||||||
|
placeholder='Enter a string to be sent',
|
||||||
|
[(ngModel)]='newScript.send'
|
||||||
|
)
|
||||||
|
td
|
||||||
|
.input-group
|
||||||
|
button.btn.btn-outline-info.ml-0((click)='add()')
|
||||||
|
i.fa.fa-save
|
||||||
|
button.btn.btn-outline-danger.ml-0((click)='clear()')
|
||||||
|
i.fa.fa-trash-o
|
||||||
|
|
||||||
.modal-footer
|
.modal-footer
|
||||||
button.btn.btn-outline-primary((click)='save()') Save
|
button.btn.btn-outline-primary((click)='save()') Save
|
||||||
button.btn.btn-outline-danger((click)='cancel()') Cancel
|
button.btn.btn-outline-danger((click)='cancel()') Cancel
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
import { Component } from '@angular/core'
|
import { Component } from '@angular/core'
|
||||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { ElectronService, HostAppService } from 'terminus-core'
|
import { ElectronService, HostAppService } from 'terminus-core'
|
||||||
import { SSHConnection } from '../api'
|
import { SSHConnection, LoginScript } from '../api'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: require('./editConnectionModal.component.pug'),
|
template: require('./editConnectionModal.component.pug'),
|
||||||
})
|
})
|
||||||
export class EditConnectionModalComponent {
|
export class EditConnectionModalComponent {
|
||||||
connection: SSHConnection
|
connection: SSHConnection
|
||||||
|
newScript: LoginScript
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private modalInstance: NgbActiveModal,
|
private modalInstance: NgbActiveModal,
|
||||||
private electron: ElectronService,
|
private electron: ElectronService,
|
||||||
private hostApp: HostAppService,
|
private hostApp: HostAppService,
|
||||||
) { }
|
) {
|
||||||
|
this.newScript = { expect: "", send: ""}
|
||||||
|
}
|
||||||
|
|
||||||
selectPrivateKey () {
|
selectPrivateKey () {
|
||||||
let path = this.electron.dialog.showOpenDialog(
|
let path = this.electron.dialog.showOpenDialog(
|
||||||
@ -34,4 +37,40 @@ export class EditConnectionModalComponent {
|
|||||||
cancel () {
|
cancel () {
|
||||||
this.modalInstance.dismiss()
|
this.modalInstance.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
up (script: LoginScript) {
|
||||||
|
let index = this.connection.scripts.indexOf(script)
|
||||||
|
if (index > 0)
|
||||||
|
{
|
||||||
|
this.connection.scripts.splice(index, 1);
|
||||||
|
this.connection.scripts.splice(index - 1, 0, script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
down (script: LoginScript) {
|
||||||
|
let index = this.connection.scripts.indexOf(script)
|
||||||
|
if (index >= 0 && index < this.connection.scripts.length - 1)
|
||||||
|
{
|
||||||
|
this.connection.scripts.splice(index, 1);
|
||||||
|
this.connection.scripts.splice(index + 1, 0, script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete (script: LoginScript) {
|
||||||
|
if (confirm(`Delete?`)) {
|
||||||
|
this.connection.scripts = this.connection.scripts.filter(x => x !== script)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
add () {
|
||||||
|
if (!this.connection.scripts)
|
||||||
|
this.connection.scripts = []
|
||||||
|
this.connection.scripts.push(Object.assign({}, this.newScript))
|
||||||
|
this.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
clear () {
|
||||||
|
this.newScript.expect = ""
|
||||||
|
this.newScript.send = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ export class SSHSettingsTabComponent {
|
|||||||
port: 22,
|
port: 22,
|
||||||
user: 'root',
|
user: 'root',
|
||||||
}
|
}
|
||||||
|
|
||||||
let modal = this.ngbModal.open(EditConnectionModalComponent)
|
let modal = this.ngbModal.open(EditConnectionModalComponent)
|
||||||
modal.componentInstance.connection = connection
|
modal.componentInstance.connection = connection
|
||||||
modal.result.then(result => {
|
modal.result.then(result => {
|
||||||
|
@ -148,7 +148,7 @@ export class SSHService {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
let session = new SSHSession(shell)
|
let session = new SSHSession(shell, connection)
|
||||||
|
|
||||||
return this.zone.run(() => this.app.openNewTab(
|
return this.zone.run(() => this.app.openNewTab(
|
||||||
TerminalTabComponent,
|
TerminalTabComponent,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user