Browse Source

ensure invalid settings arnt saved to localstorage

pull/270/head
butlerx 4 years ago
parent
commit
8e81ec9734
No known key found for this signature in database GPG Key ID: B37CA765BAA89170
  1. 39
      src/assets/scss/options.scss
  2. 20
      src/client/wetty/term/confiruragtion.ts
  3. 23
      src/client/wetty/term/confiruragtion/editor.ts
  4. 2
      src/server.ts
  5. 14
      src/server/command/ssh.ts
  6. 4
      src/server/login.ts
  7. 6
      src/server/socketServer/ssl.ts

39
src/assets/scss/options.scss

@ -8,19 +8,17 @@
width: 16px;
z-index: 20;
a {
.toggler {
color: variables.$lgrey;
display: inline-block;
font-size: 16px;
position: absolute;
right: 1em;
top: 0;
z-index: 20;
.toggler {
color: variables.$lgrey;
display: inline-block;
font-size: 16px;
position: absolute;
right: 1em;
top: 0;
z-index: 20;
:hover {
color: variables.$white;
}
:hover {
color: variables.$white;
}
}
@ -38,18 +36,17 @@
top: 1em;
width: 100%;
}
}
#options.opened {
height: 50%;
width: 50%;
.editor {
.error {
color: red;
}
display: flex;
}
.opened {
height: 50%;
width: 50%;
.editor {
display: flex;
}
.error {
color: red;
}
}

20
src/client/wetty/term/confiruragtion.ts

@ -1,8 +1,8 @@
import _ from 'lodash';
import JSON5 from 'json5';
import type { Term } from '../shared/type';
import { copySelected, copyShortcut } from './confiruragtion/clipboard';
import { onInput } from './confiruragtion/editor';
import { editor } from '../../shared/elements';
import { loadOptions } from './confiruragtion/load';
@ -14,23 +14,7 @@ export function configureTerm(term: Term): void {
const config = JSON.stringify(options, null, 2);
if (!_.isNull(editor)) {
editor.value = config;
editor.addEventListener('keyup', () => {
try {
const updated = JSON5.parse(editor.value);
const updatedConf = JSON.stringify(updated, null, 2);
editor.value = updatedConf;
editor.classList.remove('error');
localStorage.options = updatedConf;
Object.keys(updated).forEach(key => {
const value = updated[key];
term.setOption(key, value);
});
term.resizeTerm();
} catch {
// skip
editor.classList.add('error');
}
});
editor.addEventListener('keyup', onInput(term));
const toggle = document.querySelector('#options .toggler');
const optionsElem = document.getElementById('options');
if (!_.isNull(toggle) && !_.isNull(optionsElem)) {

23
src/client/wetty/term/confiruragtion/editor.ts

@ -0,0 +1,23 @@
import JSON5 from 'json5';
import type { Term } from '../../shared/type';
import { editor } from '../../../shared/elements';
export const onInput = (term: Term) => (): void => {
try {
const updated = JSON5.parse(editor.value);
const updatedConf = JSON.stringify(updated, null, 2);
if (localStorage.options === updatedConf) return;
Object.keys(updated).forEach(key => {
const value = updated[key];
term.setOption(key, value);
});
term.resizeTerm();
editor.value = updatedConf;
editor.classList.remove('error');
localStorage.options = updatedConf;
} catch {
// skip
editor.classList.add('error');
}
};

2
src/server.ts

@ -64,7 +64,7 @@ export async function startServer(
});
spawn(socket, args);
} catch (error) {
logger.info('Disconnect signal sent');
logger.info('Disconnect signal sent', { err: error });
}
}
});

14
src/server/command/ssh.ts

@ -2,19 +2,11 @@ import isUndefined from 'lodash/isUndefined.js';
import { logger } from '../../shared/logger.js';
export function sshOptions(
{
pass,
path,
command,
host,
port,
auth,
knownhosts,
}: { [s: string]: string },
{ pass, path, command, host, port, auth, knownHosts }: Record<string, string>,
key?: string,
): string[] {
const cmd = parseCommand(command, path);
const hostChecking = knownhosts !== '/dev/null' ? 'yes' : 'no';
const hostChecking = knownHosts !== '/dev/null' ? 'yes' : 'no';
const sshRemoteOptsBase = [
'ssh',
host,
@ -24,7 +16,7 @@ export function sshOptions(
'-o',
`PreferredAuthentications=${auth}`,
'-o',
`UserKnownHostsFile=${knownhosts}`,
`UserKnownHostsFile=${knownHosts}`,
'-o',
`StrictHostKeyChecking=${hostChecking}`,
];

4
src/server/login.ts

@ -1,6 +1,10 @@
import pty from 'node-pty';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { xterm } from './shared/xterm.js';
const __dirname = resolve(dirname(fileURLToPath(import.meta.url)), '..');
export function login(socket: SocketIO.Socket): Promise<string> {
// Check request-header for username
const remoteUser = socket.request.headers['remote-user'];

6
src/server/socketServer/ssl.ts

@ -1,14 +1,14 @@
import fs from 'fs-extra';
import path from 'path';
import isUndefined from 'lodash/isUndefined.js';
import { resolve } from 'path';
import type { SSL, SSLBuffer } from '../../shared/interfaces';
export async function loadSSL(ssl?: SSL): Promise<SSLBuffer> {
if (isUndefined(ssl) || isUndefined(ssl.key) || isUndefined(ssl.cert))
return {};
const [key, cert]: Buffer[] = await Promise.all([
fs.readFile(path.resolve(ssl.key)),
fs.readFile(path.resolve(ssl.cert)),
fs.readFile(resolve(ssl.key)),
fs.readFile(resolve(ssl.cert)),
]);
return { key, cert };
}

Loading…
Cancel
Save