-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·88 lines (74 loc) · 2.02 KB
/
index.html
File metadata and controls
executable file
·88 lines (74 loc) · 2.02 KB
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
<html>
<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">
var term, websocket, containerId = '', command = '';
function getQueryVar(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0; i<vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return false;
}
containerId = getQueryVar('cid');
if (!containerId) {
containerId = prompt('Container ID');
}
command = getQueryVar('cmd');
if (!command) {
command = '/bin/bash';
}
websocket = new WebSocket("ws://" + window.location.hostname + ":" + window.location.port + window.location.pathname + "exec/" + containerId + ',' + window.btoa(command));
websocket.onopen = function(evt) {
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(evt) {
term.write("Session terminated");
term.destroy();
}
websocket.onerror = function(evt) {
if (typeof console.log == "function") {
console.log(evt)
}
}
}
</script>
</body>
</html>