mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-15 08:59:58 +00:00
Merge pull request #437 from Domain/master
Support regex and optional script
This commit is contained in:
commit
153cd1ec9a
@ -3,6 +3,8 @@ import { BaseSession } from 'terminus-terminal'
|
|||||||
export interface LoginScript {
|
export interface LoginScript {
|
||||||
expect?: string
|
expect?: string
|
||||||
send: string
|
send: string
|
||||||
|
isRegex?: boolean
|
||||||
|
optional?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SSHConnection {
|
export interface SSHConnection {
|
||||||
@ -37,15 +39,37 @@ export class SSHSession extends BaseSession {
|
|||||||
if (this.scripts) {
|
if (this.scripts) {
|
||||||
let found = false
|
let found = false
|
||||||
for (let script of this.scripts) {
|
for (let script of this.scripts) {
|
||||||
if (dataString.includes(script.expect)) {
|
let match = false
|
||||||
console.log('Executing script:', script.send)
|
let cmd = ''
|
||||||
this.shell.write(script.send + '\n')
|
if (script.isRegex) {
|
||||||
this.scripts = this.scripts.filter(x => x !== script)
|
let re = new RegExp(script.expect, 'g')
|
||||||
|
if (dataString.match(re)) {
|
||||||
|
cmd = dataString.replace(re, script.send)
|
||||||
|
match = true
|
||||||
found = true
|
found = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (dataString.includes(script.expect)) {
|
||||||
|
cmd = script.send
|
||||||
|
match = true
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
console.log('Executing script: "' + cmd + '"')
|
||||||
|
this.shell.write(cmd + '\n')
|
||||||
|
this.scripts = this.scripts.filter(x => x !== script)
|
||||||
|
} else {
|
||||||
|
if (script.optional) {
|
||||||
|
console.log('Skip optional script: ' + script.expect)
|
||||||
|
found = true
|
||||||
|
this.scripts = this.scripts.filter(x => x !== script)
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
this.executeUnconditionalScripts()
|
this.executeUnconditionalScripts()
|
||||||
|
@ -94,6 +94,8 @@
|
|||||||
tr
|
tr
|
||||||
th String to expect
|
th String to expect
|
||||||
th String to be sent
|
th String to be sent
|
||||||
|
th Regex
|
||||||
|
th Optional
|
||||||
th Actions
|
th Actions
|
||||||
tr(*ngFor='let script of connection.scripts')
|
tr(*ngFor='let script of connection.scripts')
|
||||||
td
|
td
|
||||||
@ -106,6 +108,14 @@
|
|||||||
type='text',
|
type='text',
|
||||||
[(ngModel)]='script.send'
|
[(ngModel)]='script.send'
|
||||||
)
|
)
|
||||||
|
td
|
||||||
|
toggle(
|
||||||
|
[(ngModel)]='script.isRegex',
|
||||||
|
)
|
||||||
|
td
|
||||||
|
toggle(
|
||||||
|
[(ngModel)]='script.optional',
|
||||||
|
)
|
||||||
td
|
td
|
||||||
.input-group.flex-nowrap
|
.input-group.flex-nowrap
|
||||||
button.btn.btn-outline-info.ml-0((click)='moveScriptUp(script)')
|
button.btn.btn-outline-info.ml-0((click)='moveScriptUp(script)')
|
||||||
@ -127,6 +137,14 @@
|
|||||||
placeholder='Enter a string to be sent',
|
placeholder='Enter a string to be sent',
|
||||||
[(ngModel)]='newScript.send'
|
[(ngModel)]='newScript.send'
|
||||||
)
|
)
|
||||||
|
td
|
||||||
|
toggle(
|
||||||
|
[(ngModel)]='newScript.isRegex',
|
||||||
|
)
|
||||||
|
td
|
||||||
|
toggle(
|
||||||
|
[(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()')
|
||||||
|
@ -83,5 +83,7 @@ export class EditConnectionModalComponent {
|
|||||||
clearScript () {
|
clearScript () {
|
||||||
this.newScript.expect = ''
|
this.newScript.expect = ''
|
||||||
this.newScript.send = ''
|
this.newScript.send = ''
|
||||||
|
this.newScript.isRegex = false
|
||||||
|
this.newScript.optional = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user