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

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

@ -1,8 +1,8 @@
import _ from 'lodash'; import _ from 'lodash';
import JSON5 from 'json5';
import type { Term } from '../shared/type'; import type { Term } from '../shared/type';
import { copySelected, copyShortcut } from './confiruragtion/clipboard'; import { copySelected, copyShortcut } from './confiruragtion/clipboard';
import { onInput } from './confiruragtion/editor';
import { editor } from '../../shared/elements'; import { editor } from '../../shared/elements';
import { loadOptions } from './confiruragtion/load'; import { loadOptions } from './confiruragtion/load';
@ -14,23 +14,7 @@ export function configureTerm(term: Term): void {
const config = JSON.stringify(options, null, 2); const config = JSON.stringify(options, null, 2);
if (!_.isNull(editor)) { if (!_.isNull(editor)) {
editor.value = config; editor.value = config;
editor.addEventListener('keyup', () => { editor.addEventListener('keyup', onInput(term));
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');
}
});
const toggle = document.querySelector('#options .toggler'); const toggle = document.querySelector('#options .toggler');
const optionsElem = document.getElementById('options'); const optionsElem = document.getElementById('options');
if (!_.isNull(toggle) && !_.isNull(optionsElem)) { 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); spawn(socket, args);
} catch (error) { } 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'; import { logger } from '../../shared/logger.js';
export function sshOptions( export function sshOptions(
{ { pass, path, command, host, port, auth, knownHosts }: Record<string, string>,
pass,
path,
command,
host,
port,
auth,
knownhosts,
}: { [s: string]: string },
key?: string, key?: string,
): string[] { ): string[] {
const cmd = parseCommand(command, path); const cmd = parseCommand(command, path);
const hostChecking = knownhosts !== '/dev/null' ? 'yes' : 'no'; const hostChecking = knownHosts !== '/dev/null' ? 'yes' : 'no';
const sshRemoteOptsBase = [ const sshRemoteOptsBase = [
'ssh', 'ssh',
host, host,
@ -24,7 +16,7 @@ export function sshOptions(
'-o', '-o',
`PreferredAuthentications=${auth}`, `PreferredAuthentications=${auth}`,
'-o', '-o',
`UserKnownHostsFile=${knownhosts}`, `UserKnownHostsFile=${knownHosts}`,
'-o', '-o',
`StrictHostKeyChecking=${hostChecking}`, `StrictHostKeyChecking=${hostChecking}`,
]; ];

4
src/server/login.ts

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

6
src/server/socketServer/ssl.ts

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

Loading…
Cancel
Save