ok
Browse files- Dockerfile +8 -2
- app.js +3 -2
- public/index.html +1 -0
- start.sh +1 -1
Dockerfile
CHANGED
|
@@ -47,7 +47,13 @@ RUN mkdir -p /etc/dropbear \
|
|
| 47 |
&& chown -R user:user /etc/dropbear
|
| 48 |
|
| 49 |
# 更改目录所有权
|
| 50 |
-
RUN chown -R user:user /app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# 暴露 Web 应用端口和 Dropbear SSH 端口
|
| 53 |
EXPOSE 7860 2202
|
|
@@ -60,4 +66,4 @@ RUN chmod +x /start.sh
|
|
| 60 |
USER user
|
| 61 |
|
| 62 |
# 使用启动脚本
|
| 63 |
-
CMD ["/start.sh"]
|
|
|
|
| 47 |
&& chown -R user:user /etc/dropbear
|
| 48 |
|
| 49 |
# 更改目录所有权
|
| 50 |
+
RUN chown -R user:user /app /etc/dropbear \
|
| 51 |
+
&& chmod 700 /etc/dropbear \
|
| 52 |
+
&& chmod 600 /etc/dropbear/*
|
| 53 |
+
|
| 54 |
+
# 使用 gosu 来运行 start.sh
|
| 55 |
+
RUN apt-get update && apt-get install -y gosu \
|
| 56 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 57 |
|
| 58 |
# 暴露 Web 应用端口和 Dropbear SSH 端口
|
| 59 |
EXPOSE 7860 2202
|
|
|
|
| 66 |
USER user
|
| 67 |
|
| 68 |
# 使用启动脚本
|
| 69 |
+
CMD ["gosu", "user", "/start.sh"]
|
app.js
CHANGED
|
@@ -6,14 +6,15 @@ const port = 7860;
|
|
| 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', async (req, res) => {
|
| 15 |
const conn = new Client();
|
| 16 |
-
|
| 17 |
try {
|
| 18 |
await new Promise((resolve, reject) => {
|
| 19 |
conn.on('ready', resolve)
|
|
|
|
| 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 |
+
// SSH 命令执行
|
| 15 |
app.post('/ssh', async (req, res) => {
|
| 16 |
const conn = new Client();
|
| 17 |
+
|
| 18 |
try {
|
| 19 |
await new Promise((resolve, reject) => {
|
| 20 |
conn.on('ready', resolve)
|
public/index.html
CHANGED
|
@@ -13,6 +13,7 @@
|
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<h1>Web SSH</h1>
|
|
|
|
| 16 |
<input type="text" id="command" placeholder="Enter SSH command">
|
| 17 |
<button onclick="executeCommand()">Execute</button>
|
| 18 |
<div id="output"></div>
|
|
|
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<h1>Web SSH</h1>
|
| 16 |
+
<p>This application allows you to execute SSH commands on the server. Enter your command below and click "Execute".</p>
|
| 17 |
<input type="text" id="command" placeholder="Enter SSH command">
|
| 18 |
<button onclick="executeCommand()">Execute</button>
|
| 19 |
<div id="output"></div>
|
start.sh
CHANGED
|
@@ -17,7 +17,7 @@ fi
|
|
| 17 |
|
| 18 |
# 启动 Dropbear,使用 2202 端口,允许密码认证,后台运行
|
| 19 |
echo "Starting Dropbear..."
|
| 20 |
-
dropbear -R -p 2202 -w -E &
|
| 21 |
|
| 22 |
# 检查 Dropbear 是否成功启动
|
| 23 |
for i in {1..10}; do
|
|
|
|
| 17 |
|
| 18 |
# 启动 Dropbear,使用 2202 端口,允许密码认证,后台运行
|
| 19 |
echo "Starting Dropbear..."
|
| 20 |
+
dropbear -R -p 2202 -w -E -F &
|
| 21 |
|
| 22 |
# 检查 Dropbear 是否成功启动
|
| 23 |
for i in {1..10}; do
|