-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebssh.ejs
53 lines (37 loc) · 1.08 KB
/
webssh.ejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://127.0.0.1:3000/xterm/dist/xterm.css" />
<script src="http://127.0.0.1:3000/xterm/dist/xterm.js"></script>
<script src="http://127.0.0.1:3000/xterm/dist/addons/attach/attach.js"></script>
<script src="http://127.0.0.1:3000/xterm/dist/addons/fit/fit.js"></script>
</head>
<body>
<div id="terminal"></div>
<script>
var hostip = window.location.pathname.split("/").pop()
var ws = new WebSocket("ws://10.10.0.212:33333/wssh/" + hostip);
Terminal.applyAddon(attach);
Terminal.applyAddon(fit);
var xterm = new Terminal({
cols: 80,
rows: 36,
});
xterm.open(document.getElementById('terminal'));
xterm.attach(ws, true, true);
xterm.fit();
ws.onopen = function (evt) {
ws.send("pwd\n");
};
ws.onclose = function () {
ws.close();
};
ws.onmessage = function (msg) {
xterm.write(msg.data);
};
xterm.on(function (data) {
ws.send(data);
});
</script>
</body>
</html>