BUG修复
This commit is contained in:
-123
@@ -1,123 +0,0 @@
|
|||||||
<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;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#container-terminal {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<title>Docker Exec Web Console</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="container-terminal"></div>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
function resizeTerminal(term) {
|
|
||||||
const container = document.getElementById('container-terminal');
|
|
||||||
if (!container) {
|
|
||||||
console.error('Container element not found.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 现在使用更精确的测量值,这些值应该基于你的终端设置
|
|
||||||
const style = window.getComputedStyle(container);
|
|
||||||
const charWidth = parseInt(style.getPropertyValue('--xterm-char-width'), 10) || 10;
|
|
||||||
const charHeight = parseInt(style.getPropertyValue('--xterm-char-height'), 10) || 20;
|
|
||||||
|
|
||||||
const width = container.offsetWidth;
|
|
||||||
const height = container.offsetHeight;
|
|
||||||
|
|
||||||
const cols = Math.floor(width / charWidth);
|
|
||||||
console.log(cols);
|
|
||||||
const rows = Math.floor(height / charHeight);
|
|
||||||
|
|
||||||
term.resize(cols, rows);
|
|
||||||
console.log(term);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 token = getQueryVar('token');
|
|
||||||
if (!token) {
|
|
||||||
throw new Error('token not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
let command = getQueryVar('cmd');
|
|
||||||
if (!command) {
|
|
||||||
command = '/bin/bash';
|
|
||||||
}
|
|
||||||
|
|
||||||
let websocket = new WebSocket(
|
|
||||||
"ws://"
|
|
||||||
+ window.location.hostname + ":"
|
|
||||||
+ window.location.port
|
|
||||||
+ window.location.pathname
|
|
||||||
+ "exec/"
|
|
||||||
+ token + ',' + window.btoa(command)
|
|
||||||
);
|
|
||||||
|
|
||||||
websocket.onopen = function () {
|
|
||||||
let term = new Terminal({
|
|
||||||
//cols: 300,
|
|
||||||
//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'));
|
|
||||||
|
|
||||||
resizeTerminal(term);
|
|
||||||
|
|
||||||
window.addEventListener('resize', () => {
|
|
||||||
resizeTerminal(term);
|
|
||||||
});
|
|
||||||
|
|
||||||
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>
|
|
||||||
@@ -35,15 +35,8 @@ func main() {
|
|||||||
|
|
||||||
// if cp := os.Getenv("CONTEXT_PATH"); cp != "" {
|
// if cp := os.Getenv("CONTEXT_PATH"); cp != "" {
|
||||||
contextPath = strings.TrimRight("/console", "/")
|
contextPath = strings.TrimRight("/console", "/")
|
||||||
// }
|
|
||||||
|
|
||||||
http.Handle(contextPath+"/exec/", websocket.Handler(ExecContainer))
|
http.Handle(contextPath+"/exec/", websocket.Handler(ExecContainer))
|
||||||
httpDir := http.FileServer(http.Dir(*localPath))
|
|
||||||
|
|
||||||
//http.Handle(contextPath+"/", http.StripPrefix("/console/", http_dir))
|
|
||||||
http.Handle(contextPath+"/", http.StripPrefix(contextPath+"/", httpDir))
|
|
||||||
// 仅index.html
|
|
||||||
|
|
||||||
if err := http.ListenAndServe(":"+*port, nil); err != nil {
|
if err := http.ListenAndServe(":"+*port, nil); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
-2270
File diff suppressed because it is too large
Load Diff
-4958
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user