I forgot the stupid file :-[ .
Here it is.
#!/usr/bin/perl # $|=1;
$clients=shift||'/usr/local/etc/raddb/clients.conf';
# Customize for your default domain
$domain='incentre.net';
printf("client,secret,shortname,clienttype,login,password\n");
open CLIENTS, "<$clients"
or die "Could not open $clients file\n";
while(<CLIENTS>){
chomp;
s/^\s*//g;
s/\s*#.*//g;
if (!/^\s*$/ && /=/) {
($key,$val)=(split /\s*=\s*/,$_);
$client_secret = $val if ($key eq 'secret');
$client_short = $val if ($key eq 'shortname');
$client_type = $val if ($key eq 'nastype');
$client_login = $val if ($key eq 'login');
$client_password = $val if ($key eq 'password');
} else {
if (/\{/) {
s/.*client\s+([^\s]*)\s+\{.*$/\1/;
if (/^\d+\.\d+\.\d+\.\d+/) {
$client = $_;
} else {
if (/\./ || /localhost/) {
$name = $_ ;
} else {
$name = $_.".".$domain;
}
$addr = gethostbyname $name;
($a,$b,$c,$d)=unpack('C4',$addr);
$client = "$a.$b.$c.$d";
#DEBUG# print $name." = ".$client."\n";
}
# $client = $_;
} else {
if (/\}/) {
@client_info =
($client_secret,$client_short,$client_type,$client_login,$client_password);
$client_data = join(',',@client_info);
$client_array{$client} .= $client_data;
}
}
}
}
close CLIENTS;
# Display data from %client_array associative array.
foreach $nas (sort keys(%client_array)) {
$data = $client_array{$nas};
($secret,$shortname,$type,%login,$password) = split(',',$data);
printf("%s,%s,%s,%s,%s,%s\n",$nas,$secret,$shortname,$type,$login,$password);
}
