ok
Browse files- Dockerfile +0 -6
- app.js +13 -2
- public/index.html +38 -0
Dockerfile
CHANGED
@@ -33,12 +33,6 @@ RUN dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key || true
|
|
33 |
# 更改目录所有权
|
34 |
RUN chown -R user:user /app /etc/dropbear
|
35 |
|
36 |
-
# 切换到新用户
|
37 |
-
USER user
|
38 |
-
|
39 |
-
# 暴露 Web 应用端口和 Dropbear SSH 端口
|
40 |
-
EXPOSE 7860 2202
|
41 |
-
|
42 |
# 启动脚本
|
43 |
COPY start.sh /start.sh
|
44 |
RUN chmod +x /start.sh
|
|
|
33 |
# 更改目录所有权
|
34 |
RUN chown -R user:user /app /etc/dropbear
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
# 启动脚本
|
37 |
COPY start.sh /start.sh
|
38 |
RUN chmod +x /start.sh
|
app.js
CHANGED
@@ -4,22 +4,33 @@ const app = express();
|
|
4 |
const port = 7860;
|
5 |
|
6 |
app.use(express.json());
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
app.post('/ssh', (req, res) => {
|
9 |
const conn = new Client();
|
10 |
conn.on('ready', () => {
|
11 |
conn.exec(req.body.command, (err, stream) => {
|
12 |
-
if (err)
|
|
|
|
|
|
|
13 |
let data = '';
|
14 |
stream.on('close', (code, signal) => {
|
15 |
conn.end();
|
16 |
-
res.
|
17 |
}).on('data', (chunk) => {
|
18 |
data += chunk;
|
19 |
}).stderr.on('data', (chunk) => {
|
20 |
data += chunk;
|
21 |
});
|
22 |
});
|
|
|
|
|
23 |
}).connect({
|
24 |
host: 'localhost',
|
25 |
port: 2202,
|
|
|
4 |
const port = 7860;
|
5 |
|
6 |
app.use(express.json());
|
7 |
+
app.use(express.static('public'));
|
8 |
+
|
9 |
+
// 添加根路径处理
|
10 |
+
app.get('/', (req, res) => {
|
11 |
+
res.sendFile(__dirname + '/public/index.html');
|
12 |
+
});
|
13 |
|
14 |
app.post('/ssh', (req, res) => {
|
15 |
const conn = new Client();
|
16 |
conn.on('ready', () => {
|
17 |
conn.exec(req.body.command, (err, stream) => {
|
18 |
+
if (err) {
|
19 |
+
res.status(500).json({ error: err.message });
|
20 |
+
return;
|
21 |
+
}
|
22 |
let data = '';
|
23 |
stream.on('close', (code, signal) => {
|
24 |
conn.end();
|
25 |
+
res.json({ output: data });
|
26 |
}).on('data', (chunk) => {
|
27 |
data += chunk;
|
28 |
}).stderr.on('data', (chunk) => {
|
29 |
data += chunk;
|
30 |
});
|
31 |
});
|
32 |
+
}).on('error', (err) => {
|
33 |
+
res.status(500).json({ error: err.message });
|
34 |
}).connect({
|
35 |
host: 'localhost',
|
36 |
port: 2202,
|
public/index.html
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Web SSH</title>
|
7 |
+
<style>
|
8 |
+
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
|
9 |
+
#output { white-space: pre-wrap; background-color: #f0f0f0; padding: 10px; border-radius: 5px; }
|
10 |
+
</style>
|
11 |
+
</head>
|
12 |
+
<body>
|
13 |
+
<h1>Web SSH</h1>
|
14 |
+
<input type="text" id="command" placeholder="Enter SSH command">
|
15 |
+
<button onclick="executeCommand()">Execute</button>
|
16 |
+
<div id="output"></div>
|
17 |
+
|
18 |
+
<script>
|
19 |
+
async function executeCommand() {
|
20 |
+
const command = document.getElementById('command').value;
|
21 |
+
const output = document.getElementById('output');
|
22 |
+
output.textContent = 'Executing command...';
|
23 |
+
|
24 |
+
try {
|
25 |
+
const response = await fetch('/ssh', {
|
26 |
+
method: 'POST',
|
27 |
+
headers: { 'Content-Type': 'application/json' },
|
28 |
+
body: JSON.stringify({ command })
|
29 |
+
});
|
30 |
+
const data = await response.json();
|
31 |
+
output.textContent = data.output || data.error;
|
32 |
+
} catch (error) {
|
33 |
+
output.textContent = 'Error: ' + error.message;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
</script>
|
37 |
+
</body>
|
38 |
+
</html>
|