diff --git a/terminus-ssh/src/api.ts b/terminus-ssh/src/api.ts index df8e53be..ef3435de 100644 --- a/terminus-ssh/src/api.ts +++ b/terminus-ssh/src/api.ts @@ -3,6 +3,7 @@ import { BaseSession } from 'terminus-terminal' export interface LoginScript { expect?: string send: string + isRegex?: boolean } export interface SSHConnection { @@ -37,13 +38,28 @@ export class SSHSession extends BaseSession { if (this.scripts) { let found = false for (let script of this.scripts) { - if (dataString.includes(script.expect)) { - console.log('Executing script:', script.send) - this.shell.write(script.send + '\n') - this.scripts = this.scripts.filter(x => x !== script) - found = true - } else { - break + if (script.isRegex) { + let re = new RegExp(script.expect, "g"); + + if (dataString.match(re)) { + let cmd = dataString.replace(re, script.send); + console.log('Executing script:', cmd) + this.shell.write(cmd + '\n') + this.scripts = this.scripts.filter(x => x !== script) + found = true + } else { + break; + } + } + else { + if (dataString.includes(script.expect)) { + console.log('Executing script:', script.send) + this.shell.write(script.send + '\n') + this.scripts = this.scripts.filter(x => x !== script) + found = true + } else { + break + } } } diff --git a/terminus-ssh/src/components/editConnectionModal.component.pug b/terminus-ssh/src/components/editConnectionModal.component.pug index 50a01663..67c038c1 100644 --- a/terminus-ssh/src/components/editConnectionModal.component.pug +++ b/terminus-ssh/src/components/editConnectionModal.component.pug @@ -94,18 +94,23 @@ tr th String to expect th String to be sent + th Regex th Actions tr(*ngFor='let script of connection.scripts') td input.form-control( - type='text', - [(ngModel)]='script.expect' - ) + type='text', + [(ngModel)]='script.expect' + ) td input.form-control( - type='text', - [(ngModel)]='script.send' - ) + type='text', + [(ngModel)]='script.send' + ) + td + toggle( + [(ngModel)]='script.isRegex', + ) td .input-group.flex-nowrap button.btn.btn-outline-info.ml-0((click)='moveScriptUp(script)') @@ -127,6 +132,10 @@ placeholder='Enter a string to be sent', [(ngModel)]='newScript.send' ) + td + toggle( + [(ngModel)]='newScript.isRegex', + ) td .input-group.flex-nowrap button.btn.btn-outline-info.ml-0((click)='addScript()')