forked from Fisherworks/flask-remote-terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
95 lines (81 loc) · 2.71 KB
/
index.html
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<html lang="en">
<head>
<meta charset="utf-8">
<title>Web Console</title>
<style>
html {
font-family: arial;
}
</style>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/xterm.css" />
</head>
<body>
<span style="font-size: 1.4em;">Web Console</span>
<span style="font-size: small;">status: <span style="font-size: small;" id="status">connecting...</span></span>
<div style="width: 100%; height: calc(100% - 50px);" id="terminal"></div>
<p style="text-align: right; font-size: small;">
Works for <a href="https://keenetic.ru/ru/">Keenetic</a>
</p>
<!-- xterm -->
<script src="https://unpkg.com/[email protected]/dist/xterm.js"></script>
<script src="https://unpkg.com/[email protected]/dist/addons/fit/fit.js"></script>
<script src="https://unpkg.com/[email protected]/dist/addons/webLinks/webLinks.js"></script>
<script src="https://unpkg.com/[email protected]/dist/addons/fullscreen/fullscreen.js"></script>
<script src="https://unpkg.com/[email protected]/dist/addons/search/search.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
<script>
Terminal.applyAddon(fullscreen)
Terminal.applyAddon(fit)
Terminal.applyAddon(webLinks)
Terminal.applyAddon(search)
const term = new Terminal({
cursorBlink: 5,
macOptionIsMeta: true,
scrollback: 300,
});
term.open(document.getElementById('terminal'));
term.fit()
term.resize(15, 50)
console.log(`size: ${term.cols} columns, ${term.rows} rows`)
// term.toggleFullScreen(true)
term.fit()
term.write("-=Welcome to console terminal!=-\r\n")
term.write("********************************\r\n")
term.on('key', (key, ev) => {
console.log("pressed key", key)
console.log("event", ev)
socket.emit("pty-input", {"input": key}, function(response) {
console.log(response);
});
});
const socket = io.connect('/pty');
const status = document.getElementById("status")
socket.on("pty-output", function(data){
console.log("new output", data)
term.write(data.output)
})
socket.on("connect", () => {
fitToscreen()
status.innerHTML = '<span style="background-color: lightgreen;">connected</span>'
}
)
socket.on("disconnect", () => {
status.innerHTML = '<span style="background-color: #ff8383;">disconnected</span>'
})
function fitToscreen(){
term.fit()
socket.emit("resize", {"cols": term.cols, "rows": term.rows})
}
function debounce(func, wait_ms) {
let timeout
return function(...args) {
const context = this
clearTimeout(timeout)
timeout = setTimeout(() => func.apply(context, args), wait_ms)
}
}
const wait_ms = 50;
window.onresize = debounce(fitToscreen, wait_ms)
</script>
</body>
</html>