I give up

This commit is contained in:
2024-12-15 12:16:42 -05:00
parent 4e8a65fcb7
commit e8754fb514
3 changed files with 57 additions and 1048 deletions
+9 -17
View File
@@ -4,7 +4,6 @@ import { fileURLToPath } from 'url';
import session from 'express-session'; import session from 'express-session';
import expressWs from 'express-ws'; import expressWs from 'express-ws';
import { spawn } from 'node-pty'; import { spawn } from 'node-pty';
import linuxpam from 'node-linux-pam';
import json from './secrets/config.json' with { type: 'json' }; import json from './secrets/config.json' with { type: 'json' };
const __dirname = path.dirname(fileURLToPath(import.meta.url)), const __dirname = path.dirname(fileURLToPath(import.meta.url)),
@@ -53,22 +52,15 @@ app.post('/login', async (req, res) => {
if (!username) return res.status(400).send('Username is required'); if (!username) return res.status(400).send('Username is required');
if (!password) return res.status(400).send('Password is required'); if (!password) return res.status(400).send('Password is required');
// authenticate using PAM const { uname, upass } = json;
linuxpam.pamAuthenticate({
username, if (username !== uname) return res.sendStatus(404);
password, else if (password !== upass) return res.sendStatus(401);
serviceName: 'login',
}, (err, success) => { req.session.authenticated = true;
console.log(err); req.session.username = username;
if (err.message.includes('User not known')) res.sendStatus(404);
else if (err.message.includes('Authentication failure')) res.sendStatus(401); return res.redirect('/shell');
else if (success) {
req.session.authenticated = true;
req.session.username = username;
return res.redirect('/shell');
}
else console.error("what?", err, success);
});
} catch (err) { } catch (err) {
console.error(err); console.error(err);
res.status(500).send('Internal server error'); res.status(500).send('Internal server error');
+44 -1029
View File
File diff suppressed because it is too large Load Diff
+4 -2
View File
@@ -11,11 +11,13 @@
"dependencies": { "dependencies": {
"@xterm/addon-fit": "^0.10.0", "@xterm/addon-fit": "^0.10.0",
"@xterm/xterm": "^5.5.0", "@xterm/xterm": "^5.5.0",
"authenticate-pam": "^1.0.5",
"express": "^4.21.2", "express": "^4.21.2",
"express-session": "^1.18.1", "express-session": "^1.18.1",
"express-ws": "^5.0.2", "express-ws": "^5.0.2",
"node-linux-pam": "^0.2.1", "node-pty": "^1.0.0",
"node-pty": "^1.0.0" "passport": "^0.7.0",
"passport-local": "^1.0.0"
}, },
"type": "module" "type": "module"
} }