Substring using Unlang?
I've been looking at the options and it looks like the easiest will be to use perl or similar external module as it can't be done easily in FR 2.2.x For our subscriber authentication we use in certain situations the ADSL Remote ID as the Subscriber ID on the NAS. The issue with this is the Subscriber ID is limited on our NAS to 32 chars, any longer than that and the subscriber doesn't come up. With certain providers we connect up to they pass a ADSL Remote ID value longer than 32 chars. I was hoping there would be a way to trim / substring from the left the string and return that. In pseudo code it would be something like: if (length(ADSL-Agent-Remote-Id) > 31) { update reply { strncat(SubscriberID, ADSL-Agent-Remote-Id + (strlen(ADSL-Agent-Remote-Id) - 31), 31) } } else { update reply { SubscriberID := ADSL-Agent-Remote-Id } } Where in effect if the string is longer than 31 chars take the right most 31 chars and only return that. It's pretty simple in perl. And I suspect that is the only way to do it. This can't be done in Unlang or similar interpreted language within freeradius itself? Cheers Peter
On 10.07.2013 05:20, Peter Lambrechtsen wrote:
In pseudo code it would be something like:
if (length(ADSL-Agent-Remote-Id) > 31) {
update reply { strncat(SubscriberID, ADSL-Agent-Remote-Id + (strlen(ADSL-Agent-Remote-Id) - 31), 31) } } else { update reply { SubscriberID := ADSL-Agent-Remote-Id } }
Where in effect if the string is longer than 31 chars take the right most 31 chars and only return that.
if ( ADSL-Agent-Remote-Id =~ /(.{0,31})$/ ) { update reply { SubscriberID := "%{1}" } } that should do it. Olivier -- Olivier Beytrison Network & Security Engineer, HES-SO Fribourg Mail: olivier@heliosnet.org
On 10.07.2013 07:48, Olivier Beytrison wrote:
if ( ADSL-Agent-Remote-Id =~ /(.{0,31})$/ ) {
if ( ADSL-Agent-Remote-Id =~ /(.{1,32})$/ ) { that's even better as it won't match an empty attribute (you never know ...) -- Olivier Beytrison Network & Security Engineer, HES-SO Fribourg Mail: olivier@heliosnet.org
On Wed, Jul 10, 2013 at 6:34 PM, Olivier Beytrison <olivier@heliosnet.org> wrote:
On 10.07.2013 07:48, Olivier Beytrison wrote:
if ( ADSL-Agent-Remote-Id =~ /(.{0,31})$/ ) {
if ( ADSL-Agent-Remote-Id =~ /(.{1,32})$/ ) {
that's even better as it won't match an empty attribute (you never know ...)
Thank you so much for that, my regex fu was failing me and I should have known better :). Works a treat and has sorted out my problem. Now to writing a simple shell script to pick up on this as I am also logging the full request they send to a separate "why are you sending us this" detail log file and then going to send an automated email to our upstream provider whenever they send us something unexpected :) Again many thanks.
On 13 Jul 2013, at 00:14, Peter Lambrechtsen <peter@crypt.co.nz> wrote:
On Wed, Jul 10, 2013 at 6:34 PM, Olivier Beytrison <olivier@heliosnet.org> wrote:
On 10.07.2013 07:48, Olivier Beytrison wrote:
if ( ADSL-Agent-Remote-Id =~ /(.{0,31})$/ ) {
if ( ADSL-Agent-Remote-Id =~ /(.{1,32})$/ ) {
Though you know you're not specifying offset and length, so you didn't need to increment the second number ;) Arran Cudbard-Bell <a.cudbardb@freeradius.org> FreeRADIUS Development Team
On Sat, Jul 13, 2013 at 11:36 AM, Arran Cudbard-Bell <a.cudbardb@freeradius.org> wrote:
On 13 Jul 2013, at 00:14, Peter Lambrechtsen <peter@crypt.co.nz> wrote:
On Wed, Jul 10, 2013 at 6:34 PM, Olivier Beytrison <olivier@heliosnet.org> wrote:
On 10.07.2013 07:48, Olivier Beytrison wrote:
if ( ADSL-Agent-Remote-Id =~ /(.{0,31})$/ ) {
if ( ADSL-Agent-Remote-Id =~ /(.{1,32})$/ ) {
Though you know you're not specifying offset and length, so you didn't need to increment the second number ;)
Yep... Once my brain kicked back into thinking regex it all came back so 1,31 is the right one for us :) IMHO those sorts of use cases really should be logged in the unlang wiki or have a generic "regex examples" wiki page as those sorts of problems come up all the time and it would be nice to direct people to one place that has a lot of good re-usable examples. Might go create a page when I have some downtime in the next few weeks.
participants (3)
-
Arran Cudbard-Bell -
Olivier Beytrison -
Peter Lambrechtsen