Initial stack: FreeRADIUS + Node API + docker-compose

This commit is contained in:
Codex Bot
2025-09-24 14:12:26 -06:00
commit 6ef48911ef
7 changed files with 189 additions and 0 deletions

56
node-api/index.js Normal file
View File

@@ -0,0 +1,56 @@
import express from 'express';
import morgan from 'morgan';
const app = express();
app.use(express.json());
app.use(morgan('dev'));
const VLAN_ID = process.env.VLAN_ID || '2';
const MAX_UP = process.env.MAX_UP || '10000000'; // bits per second
const MAX_DOWN = process.env.MAX_DOWN || '10000000'; // bits per second
// Helper: standard Accept with VLAN + bandwidth
function buildAcceptPayload(extra = {}) {
return {
control: {
'Auth-Type': 'Accept',
...extra.control,
},
reply: {
'Tunnel-Type': 'VLAN',
'Tunnel-Medium-Type': 'IEEE-802',
'Tunnel-Private-Group-Id': String(VLAN_ID),
'WISPr-Bandwidth-Max-Down': String(MAX_DOWN),
'WISPr-Bandwidth-Max-Up': String(MAX_UP),
...extra.reply,
},
};
}
// Authorize endpoint: FreeRADIUS rlm_rest calls this in authorize {}
app.post('/authorize', (req, res) => {
console.log('--- RADIUS Authorize Request ---');
console.log(JSON.stringify(req.body, null, 2));
// Por ahora aprobamos todas las solicitudes válidas (si traen User-Name)
const attrs = (req.body && (req.body.attributes || req.body.request)) || {};
if (!attrs['User-Name'] && !attrs['User-Name*0']) {
// Responder vacío -> no cambia nada; o devolver 204
return res.status(200).json({});
}
return res.status(200).json(buildAcceptPayload());
});
// Accounting endpoint (opcional)
app.post('/accounting', (req, res) => {
console.log('--- RADIUS Accounting ---');
console.log(JSON.stringify(req.body, null, 2));
return res.status(200).json({});
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Node RADIUS REST API listening on :${port}`);
});