From 93108d2aae8352f147c9ccef6d94f918aa668808 Mon Sep 17 00:00:00 2001 From: NI Date: Sun, 15 Nov 2020 21:31:10 +0800 Subject: [PATCH] Allowing Connectors to save SessionInfo (which includes login secrets) to persistent storage when user is connecting via a Remote Preset --- ui/commands/commands.js | 16 +++++++----- ui/commands/history.js | 21 ++++++++++++---- ui/commands/ssh.js | 54 ++++++++++++++++++++++++++++++++++++----- ui/commands/telnet.js | 54 ++++++++++++++++++++++++++++++++++++----- ui/home.vue | 3 +++ 5 files changed, 125 insertions(+), 23 deletions(-) diff --git a/ui/commands/commands.js b/ui/commands/commands.js index 771f1a8..1a11beb 100644 --- a/ui/commands/commands.js +++ b/ui/commands/commands.js @@ -620,11 +620,11 @@ class Builder { this.represeter = (n) => { return command.represet(n); }; - this.wizarder = (n, i, r, u, y, x, l) => { - return command.wizard(n, i, r, u, y, x, l); + this.wizarder = (n, i, r, u, y, x, l, p) => { + return command.wizard(n, i, r, u, y, x, l, p); }; - this.executer = (n, i, r, u, y, x, l) => { - return command.execute(n, i, r, u, y, x, l); + this.executer = (n, i, r, u, y, x, l, p) => { + return command.execute(n, i, r, u, y, x, l, p); }; this.launchCmd = (n, i, r, u, y, x) => { return command.launch(n, i, r, u, y, x); @@ -685,12 +685,13 @@ class Builder { * @param {history.History} history * @param {presets.Preset} preset * @param {object} session + * @param {boolean} keepSession * @param {function} done Callback which will be called when wizard is done * * @returns {Wizard} Command wizard * */ - wizard(streams, controls, history, preset, session, done) { + wizard(streams, controls, history, preset, session, keepSession, done) { let subs = new subscribe.Subscribe(); return new Wizard( @@ -698,6 +699,7 @@ class Builder { new Info(this), preset, session, + keepSession, streams, subs, controls, @@ -716,12 +718,13 @@ class Builder { * @param {history.History} history * @param {object} config * @param {object} session + * @param {boolean} saveSession * @param {function} done Callback which will be called when wizard is done * * @returns {Wizard} Command wizard * */ - execute(streams, controls, history, config, session, done) { + execute(streams, controls, history, config, session, saveSession, done) { let subs = new subscribe.Subscribe(); return new Wizard( @@ -729,6 +732,7 @@ class Builder { new Info(this), config, session, + saveSession, streams, subs, controls, diff --git a/ui/commands/history.js b/ui/commands/history.js index be135b0..735a697 100644 --- a/ui/commands/history.js +++ b/ui/commands/history.js @@ -71,9 +71,11 @@ export class History { * @param {Date} lastUsed Last used * @param {object} data Data * @param {object} sessionData Data which only available for current session + * @param {boolean} keepSession Whether or not to keep session data when + * putting the item to the persistent storage * */ - save(uname, title, lastUsed, info, data, sessionData) { + save(uname, title, lastUsed, info, data, sessionData, keepSession) { const unameIdx = this.indexOf(uname); if (unameIdx >= 0) { @@ -87,7 +89,8 @@ export class History { color: info.color(), last: lastUsed.getTime(), data: data, - session: sessionData + session: sessionData, + keepSession: keepSession, }); if (this.records.length > this.maxItems) { @@ -140,8 +143,11 @@ export class History { } this.records[i].session = null; + this.records[i].keepSession = false; break; } + + this.store(); } /** @@ -162,7 +168,8 @@ export class History { color: this.records[i].color, last: new Date(this.records[i].last), data: this.records[i].data, - session: this.records[i].session + session: this.records[i].session, + keepSession: this.records[i].keepSession, }); } @@ -185,7 +192,9 @@ export class History { type: this.records[i].type, color: this.records[i].color, last: this.records[i].last, - data: this.records[i].data + data: this.records[i].data, + session: this.records[i].keepSession ? this.records[i].session : null, + keepSession: this.records[i].keepSession, }); } @@ -210,7 +219,9 @@ export class History { type: records[i].type, color: records[i].color, last: records[i].last, - data: records[i].data + data: records[i].data, + session: records[i].session, + keepSession: records[i].keepSession, }); } diff --git a/ui/commands/ssh.js b/ui/commands/ssh.js index d566a49..2d2753c 100644 --- a/ui/commands/ssh.js +++ b/ui/commands/ssh.js @@ -509,9 +509,19 @@ class Wizard { * @param {subscribe.Subscribe} subs * @param {controls.Controls} controls * @param {history.History} history + * @param {boolean} saveSession * */ - constructor(info, preset, session, streams, subs, controls, history) { + constructor( + info, + preset, + session, + saveSession, + streams, + subs, + controls, + history + ) { this.info = info; this.preset = preset; this.hasStarted = false; @@ -521,6 +531,7 @@ class Wizard { : { credential: "", }; + this.saveSession = saveSession; this.step = subs; this.controls = controls.get("SSH"); this.history = history; @@ -668,7 +679,8 @@ class Wizard { new Date(), self.info, configInput, - sessionData + sessionData, + self.saveSession ); }, async "connect.fingerprint"(rd, sd) { @@ -899,17 +911,28 @@ class Executer extends Wizard { * @param {command.Info} info * @param {config} config * @param {object} session + * @param {boolean} saveSession * @param {streams.Streams} streams * @param {subscribe.Subscribe} subs * @param {controls.Controls} controls * @param {history.History} history * */ - constructor(info, config, session, streams, subs, controls, history) { + constructor( + info, + config, + session, + saveSession, + streams, + subs, + controls, + history + ) { super( info, presets.emptyPreset(), session, + saveSession, streams, subs, controls, @@ -961,15 +984,34 @@ export class Command { return "#3c8"; } - wizard(info, preset, session, streams, subs, controls, history) { - return new Wizard(info, preset, session, streams, subs, controls, history); + wizard(info, preset, session, saveSession, streams, subs, controls, history) { + return new Wizard( + info, + preset, + session, + saveSession, + streams, + subs, + controls, + history + ); } - execute(info, config, session, streams, subs, controls, history) { + execute( + info, + config, + session, + saveSession, + streams, + subs, + controls, + history + ) { return new Executer( info, config, session, + saveSession, streams, subs, controls, diff --git a/ui/commands/telnet.js b/ui/commands/telnet.js index e0a6799..3c2b6e5 100644 --- a/ui/commands/telnet.js +++ b/ui/commands/telnet.js @@ -247,18 +247,29 @@ class Wizard { * @param {command.Info} info * @param {presets.Preset} preset * @param {object} session + * @param {boolean} saveSession * @param {streams.Streams} streams * @param {subscribe.Subscribe} subs * @param {controls.Controls} controls * @param {history.History} history * */ - constructor(info, preset, session, streams, subs, controls, history) { + constructor( + info, + preset, + session, + saveSession, + streams, + subs, + controls, + history + ) { this.info = info; this.preset = preset; this.hasStarted = false; this.streams = streams; this.session = session; + this.saveSession = saveSession; this.step = subs; this.controls = controls.get("Telnet"); this.history = history; @@ -375,7 +386,8 @@ class Wizard { new Date(), self.info, configInput, - sessionData + sessionData, + self.saveSession ); }, async "connect.failed"(rd) { @@ -457,17 +469,28 @@ class Executor extends Wizard { * @param {command.Info} info * @param {object} config * @param {object} session + * @param {boolean} saveSession * @param {streams.Streams} streams * @param {subscribe.Subscribe} subs * @param {controls.Controls} controls * @param {history.History} history * */ - constructor(info, config, session, streams, subs, controls, history) { + constructor( + info, + config, + session, + saveSession, + streams, + subs, + controls, + history + ) { super( info, presets.emptyPreset(), session, + saveSession, streams, subs, controls, @@ -516,15 +539,34 @@ export class Command { return "#6ac"; } - wizard(info, preset, session, streams, subs, controls, history) { - return new Wizard(info, preset, session, streams, subs, controls, history); + wizard(info, preset, session, saveSession, streams, subs, controls, history) { + return new Wizard( + info, + preset, + session, + saveSession, + streams, + subs, + controls, + history + ); } - execute(info, config, session, streams, subs, controls, history) { + execute( + info, + config, + session, + saveSession, + streams, + subs, + controls, + history + ) { return new Executor( info, config, session, + saveSession, streams, subs, controls, diff --git a/ui/home.vue b/ui/home.vue index f8e038e..12a8b93 100644 --- a/ui/home.vue +++ b/ui/home.vue @@ -344,6 +344,7 @@ export default { self.connector.historyRec, presets.emptyPreset(), null, + false, () => {} ), }; @@ -365,6 +366,7 @@ export default { self.connector.historyRec, preset.preset, null, + true, () => {} ), }; @@ -409,6 +411,7 @@ export default { self.connector.historyRec, known.data, known.session, + known.keepSession, () => { self.connector.knowns = self.connector.historyRec.all(); }