Skip to content

Commit

Permalink
SSH remember password, some OSC
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed May 19, 2024
1 parent f4642b3 commit daf3d76
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
19 changes: 18 additions & 1 deletion Protest/Front/ssh.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Ssh extends Terminal {
}

ConnectDialog(target, isNew=false) { //overrides
const dialog = this.DialogBox("180px");
const dialog = this.DialogBox("208px");
if (dialog === null) return;

const okButton = dialog.okButton;
Expand Down Expand Up @@ -58,7 +58,24 @@ class Ssh extends Terminal {
passwordInput.style.width = "calc(100% - 120px)";
innerBox.append(passwordLabel, passwordInput);

const rememberPasswordCheckBox = document.createElement("input");
rememberPasswordCheckBox.type = "checkbox";
innerBox.appendChild(rememberPasswordCheckBox);
this.AddCheckBoxLabel(innerBox, rememberPasswordCheckBox, "Remember password").style.margin = "8px 0px 0px 4px";

if ("password" in this.params) {
rememberPasswordCheckBox.checked = true;
passwordInput.value = this.params.password;
}

okButton.onclick = ()=> {
if (rememberPasswordCheckBox.checked) {
this.params.password = passwordInput.value;
}
else {
delete this.params.password;
}

dialog.Close();
this.ConnectViaCredentials(
hostInput.value.trim(),
Expand Down
1 change: 0 additions & 1 deletion Protest/Front/terminal.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
position: absolute;
width: 8px;
height: 18px;
font-size: 15px;
}

.terminal-status-box {
Expand Down
49 changes: 42 additions & 7 deletions Protest/Front/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class Terminal extends Window {

//case "\x09": break; //tab

case "\x0a": //lf
case "\n": //lf 0x0a
char.innerHTML = "<br>";
this.cursor.x = 0;
this.cursor.y++;
Expand All @@ -350,8 +350,15 @@ class Terminal extends Window {
//case "\x0b": break; //vertical tab
//case "\x0c": break; //new page.

case "\x0d": //cr
if (i+1 < data.length && data[i+1] === "\x0a") {
case "\r": //cr 0x0d
if (i+2 < data.length && data[i+1]==="\r" && data[i+2]==="\n") {
char.innerHTML = "<br>";
this.cursor.x = 0;
this.cursor.y++;
i+=2;
break;
}
else if (i+1 < data.length && data[i+1]==="\n") {
char.innerHTML = "<br>";
this.cursor.x = 0;
this.cursor.y++;
Expand Down Expand Up @@ -539,8 +546,6 @@ class Terminal extends Window {
break;
}

console.log(fullSequence);

return fullSequence.length + 1;
}

Expand All @@ -554,8 +559,38 @@ class Terminal extends Window {
HandleOSC(data, index) { //Operating System Command
if (index >= data.length) return 2;

console.warn(`Unknown OCS: ${data[index+2]}`);
return 2;
const oscEnd = data.indexOf("\x07", index + 2);
const stEnd = data.indexOf("\x1b\\", index + 2);
let end = Math.min(oscEnd !== -1 ? oscEnd : data.length, stEnd !== -1 ? stEnd : data.length);

if (end === data.length) {
console.warn("Incomplete OSC sequence");
return 2;
}

const sequence = data.slice(index + 2, end);
const [command, ...params] = sequence.split(";");

console.log(command, params);

switch (command) {
case "0":
case "2": //set title
this.SetTitle(`Secure shell - ${this.params.host} - ${params.join(";")}`);
break;

case "10": //set foreground color
break;

case "11": //set background color
break;

default:
console.warn(`Unhandled OSC command: ${command}`);
break;
}

return end - index + 1;
}

MapColorId(id) {
Expand Down

0 comments on commit daf3d76

Please sign in to comment.