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. 7
      src/server/command.ts

4
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",

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 * 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;
}

7
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 =>
@ -69,12 +71,17 @@ function sshOptions(
'-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;
}

Loading…
Cancel
Save