-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathindex.html
executable file
·94 lines (80 loc) · 1.87 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
<html lang="en">
<head>
<link rel="stylesheet" href="xterm/xterm.css"/>
<script src="xterm/xterm.js"></script>
<style>
body {
padding: 0;
margin: 5px;
background-color: #000;
}
#container-terminal {
width: 800px;
height: 450px;
margin: 0;
padding: 0;
}
</style>
<title>Docker Exec Web Console</title>
</head>
<body>
<div id="container-terminal"></div>
<script type="text/javascript">
function getQueryVar(variable) {
const query = window.location.search.substring(1);
const vars = query.split("&");
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split("=");
if (pair[0] === variable) {
return pair[1];
}
}
return false;
}
let containerId = getQueryVar('cid');
if (!containerId) {
containerId = prompt('Container ID');
}
let command = getQueryVar('cmd');
if (!command) {
command = '/bin/bash';
}
let websocket = new WebSocket(
"ws://"
+ window.location.hostname + ":"
+ window.location.port
+ window.location.pathname
+ "exec/"
+ containerId + ',' + window.btoa(command)
);
websocket.onopen = function () {
let term = new Terminal({
//cols: 100,
//rows: 30,
screenKeys: true,
useStyle: true,
cursorBlink: true,
});
term.on('data', function (data) {
websocket.send(data);
});
term.on('title', function (title) {
document.title = title;
});
term.open(document.getElementById('container-terminal'));
websocket.onmessage = function (evt) {
term.write(evt.data);
}
websocket.onclose = function () {
term.write("Session terminated");
term.destroy();
}
websocket.onerror = function (evt) {
if (typeof console.log == "function") {
console.log(evt)
}
}
}
</script>
</body>
</html>