Repository navigation
Expand file tree
/
Copy pathserver_coa.py
More file actions
executable file
·65 lines (50 loc) · 1.78 KB
/
Copy pathserver_coa.py
File metadata and controls
executable file
·65 lines (50 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sys
from loguru import logger
from pyrad2 import dictionary, server
from pyrad2.constants import PacketType
class FakeCoA(server.Server):
def handle_coa_packet(self, pkt):
"""Accounting packet handler.
Function that is called when a valid
accounting packet has been received.
:param pkt: packet to process
:type pkt: Packet class instance
"""
logger.info("Received a coa request {}", pkt.code)
logger.info(" Attributes: ")
for attr in pkt.keys():
logger.info(" {}: {}", attr, pkt[attr])
reply = self.create_reply_packet(pkt)
reply.code = PacketType.CoAACK
self.send_reply_packet(pkt.fd, reply)
def handle_disconnect_packet(self, pkt):
logger.info("Received a disconnect request {}", pkt.code)
logger.info(" Attributes: ")
for attr in pkt.keys():
logger.info(" {}: {}", attr, pkt[attr])
reply = self.create_reply_packet(pkt)
# try ACK or NACK
reply.code = PacketType.DisconnectACK
self.send_reply_packet(pkt.fd, reply)
if __name__ == "__main__":
# prctl.set_name("radius-FakeCoA-client")
if len(sys.argv) != 2:
print("usage: client-coa.py 3799")
sys.exit(1)
bindport = int(sys.argv[1])
# create server/coa only and read dictionary
# bind and listen only on 127.0.0.1:argv[1]
coa = FakeCoA(
addresses=["127.0.0.1"],
dict=dictionary.Dictionary("dictionary"),
coaport=bindport,
auth_enabled=False,
acct_enabled=False,
coa_enabled=True,
)
# add peers (address, secret, name)
coa.hosts["127.0.0.1"] = server.RemoteHost(
"127.0.0.1", b"Kah3choteereethiejeimaeziecumi", "localhost"
)
# start
coa.run()