Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
radius
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
radius
Commits
4b15f7e5
Commit
4b15f7e5
authored
May 04, 2023
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
7bad5fd2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
15 deletions
+33
-15
app.js
app.js
+33
-15
No files found.
app.js
View file @
4b15f7e5
...
...
@@ -4,13 +4,15 @@ let redis = require('./redis')
redis
.
init
()
const
secret
=
'
secret
'
;
// Replace with your shared secret
const
port
=
1812
;
// Default RADIUS authentication port
const
portAcc
=
1813
;
// Default RADIUS authentication port
let
reject
=
'
Access-Reject
'
let
accept
=
'
Access-Accept
'
let
maxConnection
=
2
const
server
=
dgram
.
createSocket
(
'
udp4
'
);
const
serverAuth
=
dgram
.
createSocket
(
'
udp4
'
);
const
serverAccounting
=
dgram
.
createSocket
(
'
udp4
'
);
server
.
on
(
'
message
'
,
(
msg
,
rinfo
)
=>
{
server
Auth
.
on
(
'
message
'
,
(
msg
,
rinfo
)
=>
{
const
packet
=
radius
.
decode
({
packet
:
msg
,
secret
});
if
(
packet
.
code
!==
'
Access-Request
'
)
{
...
...
@@ -25,18 +27,36 @@ server.on('message', (msg, rinfo) => {
let
ip
=
packet
.
attributes
[
'
Calling-Station-Id
'
]
let
user
=
{
username
,
password
,
ip
}
// console.log('Received access request from:', username);
doAuth
(
packet
,
user
,
rinfo
)
});
server
.
on
(
'
listening
'
,
()
=>
{
const
address
=
server
.
address
();
console
.
log
(
'
RADIUS server listening on port
'
,
address
.
port
);
serverAuth
.
on
(
'
listening
'
,
()
=>
{
const
address
=
serverAuth
.
address
();
console
.
log
(
'
RADIUS server Auth listening on port
'
,
address
.
port
);
});
serverAccounting
.
on
(
'
message
'
,
(
msg
,
rinfo
)
=>
{
const
packet
=
radius
.
decode
({
packet
:
msg
,
secret
});
console
.
log
(
packet
)
if
(
packet
.
code
!==
'
Access-Request
'
)
{
console
.
error
(
'
Invalid packet type:
'
+
packet
.
code
);
return
;
}
});
serverAccounting
.
on
(
'
listening
'
,
()
=>
{
const
address
=
serverAuth
.
address
();
console
.
log
(
'
RADIUS server Accounting listening on port
'
,
address
.
port
);
});
server
.
bind
(
port
);
serverAccounting
.
bind
(
portAcc
);
serverAuth
.
bind
(
port
);
async
function
doAuth
(
packet
,
user
,
rinfo
)
{
let
existsUser
=
authenticateUser
(
user
.
username
)
...
...
@@ -46,18 +66,16 @@ async function doAuth(packet, user, rinfo) {
return
}
let
keys
=
await
redis
.
getAllKeysByUUID
(
user
.
username
)
console
.
log
(
keys
)
for
(
let
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
if
(
user
.
username
+
'
_
'
+
user
.
ip
===
keys
[
i
])
{
for
(
let
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
if
(
user
.
username
+
'
_
'
+
user
.
ip
===
keys
[
i
])
{
console
.
log
(
'
uuid with
'
+
user
.
username
+
'
with ip:
'
+
user
.
ip
+
'
granted
'
)
sendResponsePacket
(
packet
,
rinfo
,
accept
)
redis
.
addIp
(
user
.
username
,
user
.
ip
)
return
}
}
if
(
keys
.
length
>=
2
)
{
if
(
keys
.
length
>=
maxConnection
)
{
console
.
log
(
'
uuid with
'
+
user
.
username
+
'
with ip:
'
+
user
.
ip
+
'
reach limits
'
)
sendResponsePacket
(
packet
,
rinfo
,
reject
)
return
...
...
@@ -83,5 +101,5 @@ function sendResponsePacket(packet, rinfo, code) {
});
server
.
send
(
response
,
0
,
response
.
length
,
rinfo
.
port
,
rinfo
.
address
);
server
Auth
.
send
(
response
,
0
,
response
.
length
,
rinfo
.
port
,
rinfo
.
address
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment