Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to include 'Class' in Accounting Request? #187

Open
binooetomo opened this issue Oct 31, 2023 · 0 comments
Open

how to include 'Class' in Accounting Request? #187

binooetomo opened this issue Oct 31, 2023 · 0 comments

Comments

@binooetomo
Copy link

Dear All

I make a small modification to https://github.com/pyradius/pyrad/blob/master/example/acct.py to make it send a 'start', some 'Interim-update', and 'stop'

here it is

#!/usr/bin/python
from __future__ import print_function
from pyrad.client import Client
from pyrad.dictionary import Dictionary
import random
import socket
import sys
import pyrad.packet
import time
from uuid import uuid4
# Ref: https://github.com/pyradius/pyrad/blob/master/example/acct.py
secret = b"testing123"
rclass = str(uuid4())

def SendPacket(srv, req):
    try:
        srv.SendPacket(req)
    except pyrad.client.Timeout:
        print("RADIUS server does not reply")
        pass
    except socket.error as error:
        print("Network error: " + error[1])
        pass

srv = Client(server="localhost", secret=secret, dict=Dictionary("dictionary"))

req = srv.CreateAcctPacket(User_Name="wichert")

req["NAS-IP-Address"] = "192.168.1.10"
req["NAS-Port"] = 0
req["NAS-Identifier"] = "trillian"
req["Called-Station-Id"] = "00-04-5F-00-0F-D1"
req["Calling-Station-Id"] = "00-01-24-80-B3-9C"
req["Framed-IP-Address"] = "10.0.0.100"
# req["Class"] = rclass
print("Sending accounting start packet")
req["Acct-Status-Type"] = "Start"
SendPacket(srv, req)


octet = 2
act_time = 0
period = 5
length = 20
for i in range(length):
    octet += 100
    act_time += period
    req["Acct-Status-Type"] = 3
    req["Acct-Input-Octets"] = octet
    req["Acct-Output-Octets"] = octet
    req["Acct-Session-Time"] = act_time
    print("Sending accounting Interim-update")
    SendPacket(srv, req)
    time.sleep(period)

    octet += 100
    act_time += period

print("Sending accounting stop packet")
req["Acct-Status-Type"] = "Stop"
req["Acct-Input-Octets"] = octet
req["Acct-Output-Octets"] = octet
req["Acct-Session-Time"] = act_time
req["Acct-Terminate-Cause"] = random.choice(["User-Request", "Idle-Timeout"])
SendPacket(srv, req)

it work without problem.

but if i include the 'req["Class"] = rclass', it generate traceback

Traceback (most recent call last):
  File "/opt/flaskradius/./test_acct.py", line 35, in <module>
    req["Class"] = rclass
  File "/opt/flaskradius/venv/lib/python3.9/site-packages/pyrad/packet.py", line 359, in __setitem__
    (key, item) = self._EncodeKeyValues(key, item)
  File "/opt/flaskradius/venv/lib/python3.9/site-packages/pyrad/packet.py", line 279, in _EncodeKeyValues
    return (key, [self._EncodeValue(attr, v) for v in values])
  File "/opt/flaskradius/venv/lib/python3.9/site-packages/pyrad/packet.py", line 279, in <listcomp>
    return (key, [self._EncodeValue(attr, v) for v in values])
  File "/opt/flaskradius/venv/lib/python3.9/site-packages/pyrad/packet.py", line 254, in _EncodeValue
    result = tools.EncodeAttr(attr.type, value)
  File "/opt/flaskradius/venv/lib/python3.9/site-packages/pyrad/tools.py", line 185, in EncodeAttr
    return EncodeOctets(value)
  File "/opt/flaskradius/venv/lib/python3.9/site-packages/pyrad/tools.py", line 24, in EncodeOctets
    if str.startswith(b'0x'):
TypeError: startswith first arg must be str or a tuple of str, not bytes

As far as I know, the Radius 'Class' Attribute is a string, and I generate it with --> str(uuid4()).
I need to include 'Class' since I'm trying to build a Flask based app as backend of FreeRadius.

Kindly please tell me how to include 'Class' in radius Accounting Request.

Sincerely
-bino-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant