Allowing Connectors to save SessionInfo (which includes login secrets) to persistent storage when user is connecting via a Remote Preset

This commit is contained in:
NI
2020-11-15 21:31:10 +08:00
parent a2d9419989
commit 93108d2aae
5 changed files with 125 additions and 23 deletions

View File

@@ -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,

View File

@@ -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,
});
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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();
}