-1

I have been searching for an answer to import flat files for radius accounting records into a seperate MYSQL server (not hosted on the same radius server). We have months worth of reply-detail logs, auth-detail logs and detail logs from 4 different servers that needs to be imported.

A typical reply packet looks as follows - I used a dummy ip for demonstration purposes.

Thu Jul 23 00:00:13 2015 Packet-Type = Access-Request Framed-Protocol = PPP User-Name = "[email protected]" CHAP-Password = 0x0111d9dr56ve5c417e42962f0d58f0c89 NAS-Port-Type = Ethernet NAS-Port = 4587858 NAS-Port-Id = "1/0/0/531" Service-Type = Framed-User NAS-IP-Address = 1.1.1.1 Acct-Session-Id = "00460152" CHAP-Challenge = 0x03298b01bef9dc99e7d33e4038462a8e Message-Authenticator = 0x321aaa0d3eac236f771a4caf4ad84874 Proxy-State = 0x313239

Thu Jul 23 00:00:14 2015 Packet-Type = Access-Request Framed-Protocol = PPP User-Name = "[email protected]" CHAP-Password = 0x02b0764233ba26c11994d61cfe663668b0 NAS-Port = 655324 NAS-Port-Id = "Uniq-Sess-ID869" Connect-Info = "1000000000" NAS-Port-Type = Virtual Service-Type = Framed-User NAS-IP-Address = 1.1.1.1 Acct-Session-Id = "0009FFDC" CHAP-Challenge = 0xb2627204f7c8982beaf12f59cd1e8620 Message-Authenticator = 0x3f1dba6b5d8b9ee0a0963ce76233086b Proxy-State = 0x3638

I need a script that can parse the flat file to something like this. I am currently busy with a perl script to achieve this, but if there is an existing script to do this even better.

Header fields: Date; Packet-Type;PPP;Framed-Protocol; User-Name; CHAP-Password ;NAS-Port;NAS-Port-Type ;NAS-Port;Connect-Info ;NAS-Port-Id ;Service-Type;NAS-IP-Address; Acct-Session-Id;CHAP-Challenge; Message-Authenticator; Proxy-State

Thu Jul 23 00:00:13 2015; Access-Request;PPP; "[email protected]"; 0x0111d9dr56ve5c417e42962f0d58f0c89;Ethernet;4587858;;"1/0/0/531";Framed-User;1.1.1.1; "00460152";0x03298b01bef9dc99e7d33e4038462a8e; 0x321aaa0d3eac236f771a4caf4ad84874; 0x313239

Thu Jul 23 00:00:14 2015;Access-Request; PPP;"[email protected]"; 0x02b0764233ba26c11994d61cfe663668b0;655324; "Uniq-Sess-ID869";"1000000000";Framed-User; 1.1.1.1; "0009FFDC"; 0xb2627204f7c8982beaf12f59cd1e8620; 0x3f1dba6b5d8b9ee0a0963ce76233086b; 0x3638

2
  • Check this module. Hope this will help you Logfile::Radius.
    – serenesat
    Jul 29, 2015 at 9:32
  • 1
    @Mila Please post your script which you have already tried along with achieved output, instead of requesting for the existing script/solution. We will try to help in case if you stuck somewhere.
    – Amareesh
    Jul 29, 2015 at 10:21

2 Answers 2

0

I have done a lot of RADIUS stuff in the past including writing a FreeRADIUS database maintenance module, so I thought I'd write something up to get you going. You'll just have to do some research on how to read from a file as opposed to the <DATA> file handle.

#!/usr/bin/perl
use warnings;
use strict;

my %entries;

while (<DATA>){

    next if /^$/;

    my ($date, $rest) = split /(?<=\d{2}:\d{2}:\d{2} \d{4}) /;

    $date =~ s/\s+$//;
    $rest =~ s/\s+=\s+/=/g;

    my @packet = split /\s+/, $rest;

    my @headers;
    my $data;

    for (@packet){
        push @headers, (split /=/)[0];
        $data .= '; ' . (split /=/)[1];
    }
    $entries{header} = "Header fields: " . join('; ', @headers);
    push @{$entries{data}}, "$date$data";
}


print "\n$entries{header}\n\n";

for (@{$entries{data}}){
    print "$_\n\n";
}

__DATA__
Thu Jul 23 00:00:13 2015 Packet-Type = Access-Request Framed-Protocol = PPP User-Name = "[email protected]" CHAP-Password = 0x0111d9dr56ve5c417e42962f0d58f0c89 NAS-Port-Type = Ethernet NAS-Port = 4587858 NAS-Port-Id = "1/0/0/531" Service-Type = Framed-User NAS-IP-Address = 1.1.1.1 Acct-Session-Id = "00460152" CHAP-Challenge = 0x03298b01bef9dc99e7d33e4038462a8e Message-Authenticator = 0x321aaa0d3eac236f771a4caf4ad84874 Proxy-State = 0x313239

Thu Jul 23 00:00:14 2015 Packet-Type = Access-Request Framed-Protocol = PPP User-Name = "[email protected]" CHAP-Password = 0x02b0764233ba26c11994d61cfe663668b0 NAS-Port = 655324 NAS-Port-Id = "Uniq-Sess-ID869" Connect-Info = "1000000000" NAS-Port-Type = Virtual Service-Type = Framed-User NAS-IP-Address = 1.1.1.1 Acct-Session-Id = "0009FFDC" CHAP-Challenge = 0xb2627204f7c8982beaf12f59cd1e8620 Message-Authenticator = 0x3f1dba6b5d8b9ee0a0963ce76233086b Proxy-State = 0x3638
0

Just read them back in using the detail listener.

Paste the text below into sites-enabled/detail (or sites-available/detail and symlink that to sites-enabled), and fixup filename to point to where your detail files live.

It will process them sequentially, running each packet through the SQL module, and removing the files when all packets have been processed (you'll want to keep a backup).

server read-detail.example.com {
    listen {
        type = detail
        filename = "${radacctdir}/detail.example.com/detail-*:*"
        load_factor = 10
        track = yes
    }
    preacct {
      acct_unique
    }
    accounting {
      sql
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.