Browse Source

Authentication type none added & Copy to Clipboard on double cli… (#207)

* authentication none introduced

* Added Copy to Clipboard on double click of text 

This is to mimic the behaviour of select to copy on double click feature of Unix terminals

* Logger added instead of console.log

* CopyToClipboard seperated, yarn lint done, consistent return ignored to return any

* Consistent return type introduced
pull/162/head
SouraDutta 5 years ago
committed by Cian Butler
parent
commit
8baf892c17
  1. 4
      package.json
  2. 26
      src/client/copyToClipboard.ts
  3. 22
      src/client/index.ts
  4. 9
      src/server/command.ts

4
package.json

@ -1,6 +1,6 @@
{ {
"name": "wetty", "name": "wetty",
"version": "1.1.8", "version": "1.1.9",
"description": "WeTTY = Web + TTY. Terminal access in browser over http/https", "description": "WeTTY = Web + TTY. Terminal access in browser over http/https",
"homepage": "https://github.com/krishnasrinivas/wetty", "homepage": "https://github.com/krishnasrinivas/wetty",
"repository": { "repository": {
@ -47,7 +47,7 @@
"*.json" "*.json"
] ]
}, },
"preferGlobal": "true", "preferGlobal": true,
"dependencies": { "dependencies": {
"compression": "^1.7.4", "compression": "^1.7.4",
"express": "^4.17.1", "express": "^4.17.1",

26
src/client/copyToClipboard.ts

@ -0,0 +1,26 @@
// NOTE text selection on double click or select
const copyToClipboard = (text: string) : boolean => {
if (window.clipboardData && window.clipboardData.setData) {
window.clipboardData.setData("Text", text);
return true;
} if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
const textarea = document.createElement("textarea");
textarea.textContent = text;
textarea.style.position = "fixed";
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand("copy");
return true;
} catch (ex) {
console.warn("Copy to clipboard failed.", ex);
return false;
} finally {
document.body.removeChild(textarea);
}
}
console.warn("Copy to clipboard failed.");
return false;
}
export default copyToClipboard;

22
src/client/index.ts

@ -4,6 +4,8 @@ import * as io from 'socket.io-client';
import { fit } from 'xterm/lib/addons/fit/fit'; import { fit } from 'xterm/lib/addons/fit/fit';
import * as fileType from 'file-type'; import * as fileType from 'file-type';
import Toastify from 'toastify-js'; import Toastify from 'toastify-js';
import copyToClipboard from "./copyToClipboard";
import './wetty.scss'; import './wetty.scss';
import './favicon.ico'; import './favicon.ico';
@ -21,8 +23,11 @@ socket.on('connect', () => {
const term = new Terminal(); const term = new Terminal();
let fileBuffer = []; let fileBuffer = [];
term.open(document.getElementById('terminal')); term.open(document.getElementById('terminal'));
const defaultOptions = { fontSize: 14 }; const defaultOptions = {
fontSize: 14
};
let options: object; let options: object;
try { try {
if (localStorage.options === undefined) { if (localStorage.options === undefined) {
options = defaultOptions; options = defaultOptions;
@ -76,9 +81,18 @@ socket.on('connect', () => {
return true; return true;
}); });
// NOTE copytoclipboard
document.addEventListener('mouseup', () => {
if (term.hasSelection())
copyToClipboard(term.getSelection())
}, false);
function resize(): void { function resize(): void {
fit(term); fit(term);
socket.emit('resize', { cols: term.cols, rows: term.rows }); socket.emit('resize', {
cols: term.cols,
rows: term.rows
});
} }
window.onresize = resize; window.onresize = resize;
resize(); resize();
@ -185,7 +199,9 @@ function disconnect(reason: string): void {
window.removeEventListener('beforeunload', handler, false); window.removeEventListener('beforeunload', handler, false);
} }
function handler(e: { returnValue: string }): string { function handler(e: {
returnValue: string
}): string {
e.returnValue = 'Are you sure?'; e.returnValue = 'Are you sure?';
return e.returnValue; return e.returnValue;
} }

9
src/server/command.ts

@ -1,5 +1,7 @@
import * as url from 'url'; import * as url from 'url';
import { Socket } from 'socket.io'; import { Socket } from 'socket.io';
import logger from './logger';
import { SSH } from './interfaces'; import { SSH } from './interfaces';
const localhost = (host: string): boolean => const localhost = (host: string): boolean =>
@ -68,13 +70,18 @@ function sshOptions(
port, port,
'-o', '-o',
`PreferredAuthentications=${auth}`, `PreferredAuthentications=${auth}`,
]; ];
logger.info(`Authentication Type: ${auth}`);
if (key) { if (key) {
return sshRemoteOptsBase.concat(['-i', key, cmd]); return sshRemoteOptsBase.concat(['-i', key, cmd]);
} }
if (pass) { if (pass) {
return ['sshpass', '-p', pass].concat(sshRemoteOptsBase, [cmd]); return ['sshpass', '-p', pass].concat(sshRemoteOptsBase, [cmd]);
} }
if (auth === 'none') {
sshRemoteOptsBase.splice(sshRemoteOptsBase.indexOf('-o'), 2);
return sshRemoteOptsBase.concat([cmd]);
}
if (cmd === '') { if (cmd === '') {
return sshRemoteOptsBase; return sshRemoteOptsBase;
} }

Loading…
Cancel
Save