Commit 44ca8ce7 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parents
Pipeline #159 canceled with stages
const radius = require('radius');
const dgram = require('dgram');
const secret = 'secret'; // Replace with your shared secret
const port = 1812; // Default RADIUS authentication port
const server = dgram.createSocket('udp4');
server.on('message', (msg, rinfo) => {
const packet = radius.decode({ packet: msg, secret });
if (packet.code !== 'Access-Request') {
console.error('Invalid packet type: ' + packet.code);
return;
}
const username = packet.attributes['User-Name'];
const password = packet.attributes['User-Password'];
console.log('Received access request from:', username);
// Perform your user authentication logic here
const isAuthenticated = authenticateUser(username, password);
let response;
if (isAuthenticated) {
response = radius.encode_response({
packet,
code: 'Access-Accept',
secret,
});
console.log('Access granted for:', username);
} else {
response = radius.encode_response({
packet,
code: 'Access-Reject',
secret,
});
console.log('Access denied for:', username);
}
server.send(response, 0, response.length, rinfo.port, rinfo.address);
});
server.on('listening', () => {
const address = server.address();
console.log('RADIUS server listening on port', address.port);
});
server.bind(port);
function authenticateUser(username, password) {
// Replace this function with your actual authentication logic
return username === 'ali' && password === 'ali';
}
{
"name": "untitled28",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"radius": "^1.1.4"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment