Subversion Repositories vgwhois

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #
  2. #  VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois)
  3. #  Main program
  4. #
  5. #  (c) 2010-2019 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de>
  6. #  based on the code (c) 1998-2010 by Juliane Holzt <debian@kju.de>
  7. #  Some early parts by Lutz Donnerhacke <Lutz.Donnerhacke@Jena.Thur.de>
  8. #
  9. #  License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2)
  10. #
  11.  
  12. package VGWhoIs::OID;
  13.  
  14. use warnings;
  15. use strict;
  16.  
  17. # urn:OID:2.0999 -> .2.999
  18. sub VGWhoIs::OID::normalize_oid($) {
  19.         my $string = shift;
  20.  
  21.         # remove urn:oid: and oid:
  22.         $string =~ s/^(urn:oid:|oid:|)//i;
  23.  
  24.         # add leading dot if it does not already exist
  25.         $string =~ s/^\.//;
  26.         $string = '.' . $string;
  27.  
  28.         # remove leading zeros (requires leading dot)
  29.         $string =~ s/\.0*([1-9])/.$1/g;
  30.  
  31.         return $string;
  32. }
  33.  
  34. # %oidpattern = VGWhoIs::OID::getpatternoid()
  35. sub VGWhoIs::OID::getpatternoid {
  36.         my (%pattern);
  37.         my ($method,$host,$additional,$cline,$line);
  38.  
  39.         foreach my $patternfile (VGWhoIs::Core::getpatternfiles()) {
  40.                 open(PATTERN,"<$patternfile") || die "Cannot open $patternfile. STOP.\n";
  41.  
  42.                 while ( defined($line = <PATTERN>) ) {
  43.                         # chomp $line;
  44.                         $line = VGWhoIs::Utils::trim($line);
  45.  
  46.                         if ( $line =~ /^#/ ) {                       # comment
  47.                         } elsif ( ($cline) = $line =~ /^:(.*)$/ ) {  # method declaration
  48.                                 ($method,$host,$additional) = split(/\|/,$cline,3);
  49.                                 $method=''     if !defined $method;
  50.                                 $host=''       if !defined $host;
  51.                                 $additional='' if !defined $additional;
  52.                         } elsif ( $line =~ /^(urn:){0,1}oid:/i ) {
  53.                                 $line = VGWhoIs::OID::normalize_oid($line);
  54.  
  55.                                 $pattern{$line}{'method'} = $method;
  56.                                 $pattern{$line}{'host'}   = $host;
  57.                                 $pattern{$line}{'add'}    = $additional;
  58.                         }
  59.                 }
  60.         }
  61.         return (%pattern);
  62. }
  63.  
  64.  
  65. # ($method, $host, $additional) = VGWhoIs::OID::getmethodoid(@oid);
  66. sub VGWhoIs::OID::getmethodoid {
  67.         my @arcs = @_;
  68.  
  69.         my $method = '';
  70.         my $host = '';
  71.         my $additional = '';
  72.  
  73.         my %pattern = VGWhoIs::OID::getpatternoid();
  74.  
  75.         my $complete_oid = '';
  76.         foreach my $arc (@arcs) {
  77.                 $complete_oid .= '.' if ($complete_oid ne '.');
  78.                 $complete_oid .= $arc;
  79.  
  80.                 $complete_oid = VGWhoIs::OID::normalize_oid($complete_oid);
  81.  
  82.                 $method     = $pattern{$complete_oid}{'method'} if defined $pattern{$complete_oid}{'method'};
  83.                 $host       = $pattern{$complete_oid}{'host'}   if defined $pattern{$complete_oid}{'host'};
  84.                 $additional = $pattern{$complete_oid}{'add'}    if defined $pattern{$complete_oid}{'add'};
  85.         }
  86.  
  87.         $host = $VGWhoIs::Core::mirror{$method.$host} if defined $VGWhoIs::Core::mirror{$method.$host};
  88.  
  89.         $host             =~ s/~oid~/$complete_oid/;
  90.         $additional       =~ s/~oid~/$complete_oid/;
  91.  
  92.         return ($method,$host,$additional);
  93. }
  94.  
  95. 1;
  96.  
  97.