Option to ignore old CDRs, RT#81480
[freeside.git] / bin / generate-raddb
index 1d0053a..1617dc1 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/perl
 
 # usage: generate-raddb radius-server/raddb/dictionary* >raddb.pm
-#  i.e.: generate-raddb ~/src/freeradius-0.2/raddb/dictionary* >FS/raddb.pm
-
+#  i.e.: generate-raddb ~/freeradius/freeradius-1.0.5/share/dictionary* ~/wirelessoceans/dictionary.ip3networks ~/wtxs/dictionary.mot.canopy >raddb.pm.new
 print <<END;
 package FS::raddb;
 use vars qw(%attrib);
@@ -11,25 +10,43 @@ use vars qw(%attrib);
 END
 
 while (<>) {
-  next if /^(#|\s*$|\$INCLUDE\s+)/;
-  next if /^(VALUE|VENDOR|BEGIN\-VENDOR|END\-VENDOR)\s+/;
-  /^(ATTRIBUTE|ATTRIB_NMC)\s+([\w\-]+)\s+/ or die $_;
+  next if /^\s*$/;
+  next if /^\s*(#|\$INCLUDE\s+)/;
+  next if /^(VALUE|VENDOR|BEGIN\-(VENDOR|TLV)|END\-(VENDOR|TLV))\s+/;
+  /^(ATTRIBUTE|ATTRIB_NMC)\s+([\w\-\/\.]+)\s+/ or die $_;
   $attrib = $2;
   $dbname = lc($2);
-  $dbname =~ s/\-/_/g;
+  $dbname =~ s/[\-\/]/_/g;
+  $dbname = substr($dbname,0,24);
+  while ( exists $hash{$dbname} ) {
+    #warn $dbname;
+    $dbname =~ s/(.)$//;
+    my $w = $1;
+    $w =~ tr/_a-z0-9/a-z0-9_/;
+    $dbname = "$dbname$w";
+  }
   $hash{$dbname} = $attrib;
   #print "$2\n";
 }
 
-foreach ( keys %hash ) {
+foreach ( sort keys %hash ) {
 #  print "$_\n" if length($_)>24;
 #  print substr($_,0,24),"\n" if length($_)>24; 
 #  $max = length($_) if length($_)>$max;
-#everything >24 is still unique, at least with freeradius comprehensive dataset
-  print "  '". substr($_,0,24). "' => '$hash{$_}',\n";
+# have to fudge things since everything >24 is *not* unique
+
+  #print "  '". substr($_,0,24). "' => '$hash{$_}',\n";
+  print "  '$_' ". ( " " x (24-length($_) ) ). "=> '$hash{$_}',\n";
 }
 
 print <<END;
+
+  #(RADIATOR?)
+  #'authentication_type'      => 'Authentication-Type',
+
+  #Canopy? (Kellin)
+  'motorola_canopy_gateway'   => 'Motorola-Canopy-Gateway',
+
 );
 
 1;