fix attribute importing bugs that borked the passwords
[freeside.git] / bin / generate-raddb
1 #!/usr/bin/perl
2
3 # usage: generate-raddb radius-server/raddb/dictionary* >raddb.pm
4 #  i.e.: generate-raddb ~/src/freeradius-0.2/raddb/dictionary* >FS/raddb.pm
5
6 print <<END;
7 package FS::raddb;
8 use vars qw(%attrib);
9
10 %attrib = (
11 END
12
13 while (<>) {
14   next if /^(#|\s*$|\$INCLUDE\s+)/;
15   next if /^(VALUE|VENDOR|BEGIN\-VENDOR|END\-VENDOR)\s+/;
16   /^(ATTRIBUTE|ATTRIB_NMC)\s+([\w\-\/]+)\s+/ or die $_;
17   $attrib = $2;
18   $dbname = lc($2);
19   $dbname =~ s/[\-\/]/_/g;
20   $dbname = substr($dbname,0,24);
21   while ( exists $hash{$dbname} ) {
22     #warn $dbname;
23     $dbname =~ s/(.)$//;
24     my $w = $1;
25     $w =~ tr/_a-z0-9/a-z0-9_/;
26     $dbname = "$dbname$w";
27   }
28   $hash{$dbname} = $attrib;
29   #print "$2\n";
30 }
31
32 foreach ( keys %hash ) {
33 #  print "$_\n" if length($_)>24;
34 #  print substr($_,0,24),"\n" if length($_)>24; 
35 #  $max = length($_) if length($_)>$max;
36 # have to fudge things since everything >24 is *not* unique
37
38   #print "  '". substr($_,0,24). "' => '$hash{$_}',\n";
39   print "  '$_' => '$hash{$_}',\n";
40 }
41
42 print <<END;
43 );
44
45 1;
46 END
47