Skip to content

Commit

Permalink
Merge pull request #59 from vjardin/dev-coa
Browse files Browse the repository at this point in the history
server: fix listen for CoAs without auth, neither acct , add runtime CoA+disconnect example
  • Loading branch information
GIC-de authored Jul 5, 2018
2 parents b396da5 + 48d9a4b commit 3b44c71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
19 changes: 15 additions & 4 deletions example/coa.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
from pyrad.client import Client
from pyrad import dictionary
from pyrad import packet
import sys

if len(sys.argv) != 3:
print ("usage: coa.py {coa|dis} daemon-1234")
sys.exit(1)

ADDRESS = "127.0.0.1"
SECRET = b"Kah3choteereethiejeimaeziecumi"
ATTRIBUTES = {
"Acct-Session-Id": "1337"
}

ATTRIBUTES["NAS-Identifier"] = sys.argv[2]

# create coa client
client = Client(server=ADDRESS, secret=SECRET, dict=dictionary.Dictionary("dictionary"))

Expand All @@ -19,10 +26,14 @@
# create coa request packet
attributes = {k.replace("-", "_"): ATTRIBUTES[k] for k in ATTRIBUTES}

# create coa request
request = client.CreateCoAPacket(**attributes)
# create disconnect request
# request = client.CreateCoAPacket(code=packet.DisconnectRequest, **attributes)
if sys.argv[1] == "coa":
# create coa request
request = client.CreateCoAPacket(**attributes)
elif sys.argv[1] == "dis":
# create disconnect request
request = client.CreateCoAPacket(code=packet.DisconnectRequest, **attributes)
else:
sys.exit(1)

# send request
result = client.SendPacket(request)
Expand Down
8 changes: 5 additions & 3 deletions pyrad/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,17 @@ def _ProcessInput(self, fd):
:param fd: socket to read packet from
:type fd: socket class instance
"""
if fd.fileno() in self._realauthfds:
if self.auth_enabled and fd.fileno() in self._realauthfds:
pkt = self._GrabPacket(lambda data, s=self: s.CreateAuthPacket(packet=data), fd)
self._HandleAuthPacket(pkt)
elif fd.fileno() in self._realacctfds:
elif self.acct_enabled and fd.fileno() in self._realacctfds:
pkt = self._GrabPacket(lambda data, s=self: s.CreateAcctPacket(packet=data), fd)
self._HandleAcctPacket(pkt)
else:
elif self.coa_enabled:
pkt = self._GrabPacket(lambda data, s=self: s.CreateCoAPacket(packet=data), fd)
self._HandleCoaPacket(pkt)
else:
raise ServerPacketError('Received packet for unknown handler')

def Run(self):
"""Main loop.
Expand Down

0 comments on commit 3b44c71

Please sign in to comment.