Last active
November 28, 2020 13:43
-
-
Save oxyflour/7a40d9047d6804d672c404bcae215c3c to your computer and use it in GitHub Desktop.
guacamole lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Client, Keyboard, Mouse, WebSocketTunnel } from 'guacamole-common-js' | |
async function start() { | |
const req = await fetch('/token'), | |
token = await req.text(), | |
client = new Client(new WebSocketTunnel(`http://localhost:8088/?token=${token}`)), | |
elem = client.getDisplay().getElement() | |
document.body.appendChild(elem) | |
client.connect({ }) | |
const mouse = new Mouse(elem) | |
mouse.onmousedown = mouse.onmouseup = mouse.onmousemove = state => client.sendMouseState(state) | |
const keyboard = new Keyboard(elem) | |
keyboard.onkeydown = key => client.sendKeyEvent(1, key) | |
keyboard.onkeyup = key => client.sendKeyEvent(0, key) | |
window.onunload = () => client.disconnect() | |
} | |
start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Guacamole = require('guacamole-lite'), | |
http = require('http'), | |
crypto = require('crypto'), | |
koa = require('koa'), | |
static = require('koa-static'), | |
route = require('koa-route'), | |
app = new koa() | |
const crypt = { | |
cypher: 'AES-256-CBC', | |
key: 'MySuperSecretKeyForParamsToken12', | |
} | |
function encrypt(value) { | |
const iv = crypto.randomBytes(16), | |
cipher = crypto.createCipheriv(crypt.cypher, crypt.key, iv), | |
crypted = cipher.update(JSON.stringify(value), 'utf8', 'base64') + cipher.final('base64'), | |
data = { iv: iv.toString('base64'), value: crypted } | |
return Buffer.from(JSON.stringify(data)).toString('base64') | |
} | |
app.use(route.get('/token', async ctx => { | |
ctx.body = encrypt({ | |
connection: { | |
type: 'rdp', | |
settings: { | |
hostname: 'nuc7.yff.me', | |
username: 'oxyflour', | |
password: 'xxxxxx', | |
security: 'any', | |
'ignore-cert': true, | |
} | |
} | |
}) | |
})) | |
app.use(static('dist')) | |
const server = http.createServer(app.callback()), | |
guaca = new Guacamole({ server }, { port: 4822 }, { crypt }) | |
server.listen(8088) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment