added dockerfile

This commit is contained in:
2024-12-15 10:35:09 -05:00
parent b87d377405
commit f2573655b6
3 changed files with 41 additions and 5 deletions
+16
View File
@@ -0,0 +1,16 @@
FROM node:latest
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN mkdir -p /app/secrets && chmod -R 700 /app/secrets
EXPOSE 5164
ENV NODE_ENV=production
CMD ["node", "."]
+11
View File
@@ -0,0 +1,11 @@
services:
app:
build:
context: .
ports:
- "5164:3000"
volumes:
- ./secrets:/app/secrets
environment:
PORT: 3000
NODE_ENV: production
+14 -5
View File
@@ -6,13 +6,12 @@ import expressWs from 'express-ws';
import { spawn } from 'node-pty'; import { spawn } from 'node-pty';
import json from './secrets/config.json' with { type: 'json' }; import json from './secrets/config.json' with { type: 'json' };
const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(fileURLToPath(import.meta.url)),
const __dirname = path.dirname(__filename); PORT = process.env.PORT || 3000,
app = express();
const app = express();
expressWs(app); // enable websockets for the app expressWs(app); // enable websockets for the app
const PORT = 3000;
// configure session // configure session
app.use(session({ app.use(session({
@@ -21,6 +20,7 @@ app.use(session({
saveUninitialized: false saveUninitialized: false
})); }));
// parse form data // parse form data
app.use(express.urlencoded({ extended: true })); app.use(express.urlencoded({ extended: true }));
app.use(express.json({ extended: true })); app.use(express.json({ extended: true }));
@@ -36,11 +36,13 @@ function requireAuth(req, res, next) {
} }
} }
// serve login page // serve login page
app.get('/login', (req, res) => { app.get('/login', (req, res) => {
res.sendFile('login.html', { root: path.join(__dirname, 'HTML') }); res.sendFile('login.html', { root: path.join(__dirname, 'HTML') });
}); });
// process login // process login
app.post('/login', (req, res) => { app.post('/login', (req, res) => {
try { try {
@@ -74,11 +76,13 @@ app.post('/login', (req, res) => {
} }
}); });
// shell interface // shell interface
app.get('/shell', requireAuth, (req, res) => { app.get('/shell', requireAuth, (req, res) => {
res.sendFile('shell.html', { root: path.join(__dirname, 'HTML') }); res.sendFile('shell.html', { root: path.join(__dirname, 'HTML') });
}); });
// logout route // logout route
app.get('/logout', (req, res) => { app.get('/logout', (req, res) => {
req.session.destroy(() => { req.session.destroy(() => {
@@ -86,6 +90,7 @@ app.get('/logout', (req, res) => {
}); });
}); });
// when a websocket is opened at /shell-ws, spawn a fish shell in a pty // when a websocket is opened at /shell-ws, spawn a fish shell in a pty
app.ws('/shell-ws', (ws, req) => { app.ws('/shell-ws', (ws, req) => {
// spawn a fish shell using node-pty with a pseudo-terminal // spawn a fish shell using node-pty with a pseudo-terminal
@@ -110,4 +115,8 @@ app.ws('/shell-ws', (ws, req) => {
ws.on('close', () => shell.kill()); ws.on('close', () => shell.kill());
}); });
app.listen(PORT, () => console.log('server listening on http://localhost:' + PORT));
app.get('/', (req, res) => res.end());
app.listen(PORT, '0.0.0.0', () => console.log('server listening on http://localhost:' + PORT));