Match newline in Cisco-AVPair[*]
Kostas Zorbadelos
kzorba at otenet.gr
Wed Apr 15 18:10:52 CEST 2015
Arran Cudbard-Bell <a.cudbardb at freeradius.org> writes:
Hi,
>> On 15 Apr 2015, at 15:08, Alan DeKok <aland at deployingradius.com> wrote:
>>
>> On Apr 15, 2015, at 9:29 AM, Kostas Zorbadelos <kzorba at otenet.gr> wrote:
>>> I am trying to perform a match against the full Cisco-AVPair string
>>> (Cisco-AVPair[*]) to get a specific part. The exact check I am
>>> performing is
>>
>> It would be better to loop over the Cisco-AVPairs with a "foreach", and the match the one you want.
>
the way I see it, I cannot do a "foreach" in unlang. I would need to
create my own module, right? I perform the check in the accounting {
section, to get my attribute and then update a database.
> No, the way he's doing it should work.
>>
>>> The problem is that the regex I am using matches all newlines, so I get
>>> all Cisco-AVpair[X] after my match.
>>> The regex /client-mac-address=(.*)$/ does not seem to work. Is there any
>>> way to match the newline and get only the mac-address I am interested
>>> in?
>
> Could you provide debug output, I don't really understand what you're trying to say.
>
sites-enabled/default:
...
accounting {
# Calculate the PPPoE Client Mac Address
if ("%{ERX-Pppoe-Description}" =~ /pppoe (.*)/) {
update control {
My-Client-Mac-Address = "%{1}"
}
}
elsif ("%{Cisco-AVPair[*]}" =~ /client-mac-address=(.*)/) {
update control {
My-Client-Mac-Address = "%{1}"
}
}
else {
update control {
My-Client-Mac-Address = "unknown"
}
}
detail
sql
}
Example accounting in detail file (sensitive info stripped):
Wed Apr 15 17:14:13 2015
Acct-Interim-Interval = 5400
Acct-Session-Time = 334800
Acct-Status-Type = Interim-Update
Event-Timestamp = "Apr 15 2015 17:14:13 EEST"
Cisco-AVPair = "parent-if-handle=134530272"
NAS-Port-Type = Wireless-XGP
Cisco-AVPair = "if-handle=135556640"
Cisco-AVPair = "client-mac-address=4ced.de1e.0bca"
ADSL-Agent-Circuit-Id = "0 0/0/0:4096.735 <DSLAM INFO>/0/0/17/0/4"
Cisco-AVPair = "circuit-id-tag=0 0/0/0:4096.735 <DSLAM INFO>/0/0/17/0/4"
Acct-Session-Id = "005c18e1"
NAS-Port = 16777951
NAS-Port-Id = "#0 0/0/0:4096.735 <DSLAM INFO>/0/0/17/0/4#"
Cisco-NAS-Port = "#0 0/0/0:4096.735 <DSLAM INFO>/0/0/17/0/4#"
Called-Station-Id = "XXXXXXXX#"
Calling-Station-Id = "0 0/0/1.735 # 0 0/0/0:4096.735 <DSLAM INFO>/0/0/17/0/4"
User-Name = "XXXXXXX at DOMAIN"
Acct-Authentic = RADIUS
Framed-IP-Address = <user IP>
Cisco-AVPair = "vrf-id=default"
Cisco-AVPair = "accounting-list=default"
Cisco-AVPair = "pppoe-session-id=36256"
Framed-Protocol = PPP
Service-Type = Framed-User
X-Ascend-Connect-Progress = IPNCP-Opened
Cisco-AVPair = "connect-progress=IPCP Open"
Acct-Input-Octets = 3320876
Acct-Input-Packets = 45348
Acct-Output-Octets = 4102631
Acct-Output-Packets = 54145
Cisco-AVPair = "acct-input-octets-ipv4=90704"
Cisco-AVPair = "acct-input-packets-ipv4=513"
Cisco-AVPair = "acct-output-octets-ipv4=696656"
Cisco-AVPair = "acct-output-packets-ipv4=9309"
Cisco-AVPair = "acct-input-octets-ipv6=0"
Cisco-AVPair = "acct-input-packets-ipv6=0"
Cisco-AVPair = "acct-output-octets-ipv6=0"
Cisco-AVPair = "acct-output-packets-ipv6=0"
NAS-Identifier = "XXXXXXXX"
NAS-IP-Address = <NAS IP ADDRESS>
Acct-Delay-Time = 0
Proxy-State = 0x33383236
Acct-Unique-Session-Id = "08e2faefb2ddde79"
Stripped-User-Name = "XXXXXXXX"
Realm = "DOMAIN"
Timestamp = 1429107253
With the above config
My-Client-Mac-Address = "4ced.de1e.0bca\ncircuit-id-tag=0 0/0/0:4096.735 <D..."
In the database I see '\n' as '=0A' as expected.
I guess I can try to rewrite my regex. Any other suggestions, welcome.
Regards,
Kostas
> -Arran
>
> Arran Cudbard-Bell <a.cudbardb at freeradius.org>
> FreeRADIUS development team
>
> FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2
>
More information about the Freeradius-Users
mailing list