mirror of
https://github.com/Eugeny/tabby.git
synced 2025-09-24 09:06:03 +00:00
optional script
This commit is contained in:
@@ -4,6 +4,7 @@ export interface LoginScript {
|
|||||||
expect?: string
|
expect?: string
|
||||||
send: string
|
send: string
|
||||||
isRegex?: boolean
|
isRegex?: boolean
|
||||||
|
optional?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SSHConnection {
|
export interface SSHConnection {
|
||||||
@@ -38,26 +39,36 @@ 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) {
|
||||||
|
let match = false
|
||||||
|
let cmd = ""
|
||||||
if (script.isRegex) {
|
if (script.isRegex) {
|
||||||
let re = new RegExp(script.expect, "g");
|
let re = new RegExp(script.expect, "g")
|
||||||
|
|
||||||
if (dataString.match(re)) {
|
if (dataString.match(re)) {
|
||||||
let cmd = dataString.replace(re, script.send);
|
cmd = dataString.replace(re, script.send)
|
||||||
console.log('Executing script:', cmd)
|
match = true
|
||||||
this.shell.write(cmd + '\n')
|
|
||||||
this.scripts = this.scripts.filter(x => x !== script)
|
|
||||||
found = true
|
found = true
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (dataString.includes(script.expect)) {
|
if (dataString.includes(script.expect)) {
|
||||||
console.log('Executing script:', script.send)
|
cmd = script.send
|
||||||
this.shell.write(script.send + '\n')
|
match = true
|
||||||
this.scripts = this.scripts.filter(x => x !== script)
|
|
||||||
found = true
|
found = true
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -95,6 +95,7 @@
|
|||||||
th String to expect
|
th String to expect
|
||||||
th String to be sent
|
th String to be sent
|
||||||
th Regex
|
th Regex
|
||||||
|
th Optional
|
||||||
th Actions
|
th Actions
|
||||||
tr(*ngFor='let script of connection.scripts')
|
tr(*ngFor='let script of connection.scripts')
|
||||||
td
|
td
|
||||||
@@ -111,6 +112,10 @@
|
|||||||
toggle(
|
toggle(
|
||||||
[(ngModel)]='script.isRegex',
|
[(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)')
|
||||||
@@ -136,6 +141,10 @@
|
|||||||
toggle(
|
toggle(
|
||||||
[(ngModel)]='newScript.isRegex',
|
[(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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user