diff --git a/package.json b/package.json index 82ea695..8b978c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wetty", - "version": "1.1.8", + "version": "1.1.9", "description": "WeTTY = Web + TTY. Terminal access in browser over http/https", "homepage": "https://github.com/krishnasrinivas/wetty", "repository": { @@ -47,7 +47,7 @@ "*.json" ] }, - "preferGlobal": "true", + "preferGlobal": true, "dependencies": { "compression": "^1.7.4", "express": "^4.17.1", diff --git a/src/client/copyToClipboard.ts b/src/client/copyToClipboard.ts new file mode 100644 index 0000000..388aade --- /dev/null +++ b/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; \ No newline at end of file diff --git a/src/client/index.ts b/src/client/index.ts index f8afcce..a0026fd 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -4,6 +4,8 @@ import * as io from 'socket.io-client'; import { fit } from 'xterm/lib/addons/fit/fit'; import * as fileType from 'file-type'; import Toastify from 'toastify-js'; + +import copyToClipboard from "./copyToClipboard"; import './wetty.scss'; import './favicon.ico'; @@ -21,8 +23,11 @@ socket.on('connect', () => { const term = new Terminal(); let fileBuffer = []; term.open(document.getElementById('terminal')); - const defaultOptions = { fontSize: 14 }; + const defaultOptions = { + fontSize: 14 + }; let options: object; + try { if (localStorage.options === undefined) { options = defaultOptions; @@ -76,9 +81,18 @@ socket.on('connect', () => { return true; }); + // NOTE copytoclipboard + document.addEventListener('mouseup', () => { + if (term.hasSelection()) + copyToClipboard(term.getSelection()) + }, false); + function resize(): void { fit(term); - socket.emit('resize', { cols: term.cols, rows: term.rows }); + socket.emit('resize', { + cols: term.cols, + rows: term.rows + }); } window.onresize = resize; resize(); @@ -185,7 +199,9 @@ function disconnect(reason: string): void { window.removeEventListener('beforeunload', handler, false); } -function handler(e: { returnValue: string }): string { +function handler(e: { + returnValue: string +}): string { e.returnValue = 'Are you sure?'; return e.returnValue; } diff --git a/src/server/command.ts b/src/server/command.ts index 8f0bd6d..043290e 100644 --- a/src/server/command.ts +++ b/src/server/command.ts @@ -1,5 +1,7 @@ import * as url from 'url'; import { Socket } from 'socket.io'; + +import logger from './logger'; import { SSH } from './interfaces'; const localhost = (host: string): boolean => @@ -68,13 +70,18 @@ function sshOptions( port, '-o', `PreferredAuthentications=${auth}`, - ]; + ]; + logger.info(`Authentication Type: ${auth}`); if (key) { return sshRemoteOptsBase.concat(['-i', key, cmd]); } if (pass) { return ['sshpass', '-p', pass].concat(sshRemoteOptsBase, [cmd]); } + if (auth === 'none') { + sshRemoteOptsBase.splice(sshRemoteOptsBase.indexOf('-o'), 2); + return sshRemoteOptsBase.concat([cmd]); + } if (cmd === '') { return sshRemoteOptsBase; }