Changeset 273 for branches/dns/cgi-bin


Ignore:
Timestamp:
08/09/05 17:15:26 (19 years ago)
Author:
Kris Deugau
Message:

/branches/dns

Updates to main.cgi to pass rDNS data in to IPDB core
Updates to IPDB.pm to insert rDNS data into dns table
Added subst_rDNS function to IPDB.pm to take template string

and substitute printf-like patterns with IP data

Location:
branches/dns/cgi-bin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/dns/cgi-bin/IPDB.pm

    r262 r273  
    184184# Does all of the magic of actually allocating a netblock
    185185# Requires database handle, block to allocate, custid, type, city,
    186 #       description, notes, circuit ID, block to allocate from,
     186#       description, notes, circuit ID, block to allocate from,
     187#       rDNS for the block/IP
    187188# Returns a success code and optional error message.
    188189sub allocateBlock {
    189   my ($dbh,undef,undef,$custid,$type,$city,$desc,$notes,$circid) = @_;
     190  my ($dbh,undef,undef,$custid,$type,$city,$desc,$notes,$circid,$rdns) = @_;
    190191 
    191192  my $cidr = new NetAddr::IP $_[1];
     
    223224        " where ip='$cidr'");
    224225      $sth->execute;
     226
     227      # rDNS change is an update as the pool should have set "unassigned..."
     228      # rDNS on all IPs already.
     229      $msg = "Unable to update rDNS assigning $cidr to $custid";
     230      $sth = $dbh->prepare("update dns set hostname='$rdns',auto='n' where ip='$cidr'");
     231      $sth->execute;
     232
    225233      $dbh->commit;
    226234    };
     
    405413# Note that this is NOT done in a transaction, that's why it's a private
    406414# function and should ONLY EVER get called from allocateBlock()
     415# We also do the rDNS for the pool here to save some sanity.
    407416sub initPool {
    408   my ($dbh,undef,$type,$city,$class) = @_;
     417  my ($dbh,undef,$type,$city,$class,$rdns,$domain) = @_;
    409418  my $pool = new NetAddr::IP $_[1];
    410419
     
    424433    $sth = $dbh->prepare("insert into poolips (pool,ip,custid,city,type)".
    425434        " values ('$pool', ?, '6750400', '$city', '$type')");
     435    my $sth2 = $dbh->prepare("insert into dns (ip,hostname) values (?, ?)");
    426436    my @poolip_list = $pool->hostenum;
    427437    if ($class eq 'all') { # (DSL-ish block - *all* IPs available
    428438      if ($pool->addr !~ /\.0$/) {      # .0 causes weirdness.
    429439        $sth->execute($pool->addr);
     440        # Insert rDNS entry
     441        $sth2->execute($pool->addr,subst_rDNS($rdns,$pool->addr).".".$domain);
    430442      }
    431443      for (my $i=0; $i<=$#poolip_list; $i++) {
    432444        $sth->execute($poolip_list[$i]->addr);
     445        # Insert rDNS entry
     446        $sth2->execute($poolip_list[$i]->addr,
     447                subst_rDNS($rdns,$poolip_list[$i]->addr).".".$domain);
    433448      }
    434449      $pool--;
    435450      if ($pool->addr !~ /\.255$/) {    # .255 can cause weirdness.
    436451        $sth->execute($pool->addr);
     452        # Insert rDNS entry
     453        $sth2->execute($pool->addr,subst_rDNS($rdns,$pool->addr).".".$domain);
    437454      }
    438455    } else { # (real netblock)
    439456      for (my $i=1; $i<=$#poolip_list; $i++) {
    440457        $sth->execute($poolip_list[$i]->addr);
     458        # Insert rDNS entry
     459        $sth2->execute($poolip_list[$i]->addr,
     460                subst_rDNS($rdns,$poolip_list[$i]->addr).".".$domain);
    441461      }
    442462    }
     
    628648}
    629649
     650
     651## IPDB::subst_rDNS()
     652# Substitute tokens in a template string for rDNS entries
     653sub subst_rDNS {
     654  my ($template,$ip) = $@;
     655
     656  my ($o1,$o2,$o3,$o4) = ($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)/);
     657  $rdns =~ s/\%o1\%/$o1/;
     658  $rdns =~ s/\%o2\%/$o2/;
     659  $rdns =~ s/\%o3\%/$o3/;
     660  $rdns =~ s/\%o4\%/$o4/;
     661  $rdns =~ s/\%d\%/$o1$-o2-$o3-$o4/;
     662
     663  return $rdns;
     664} # end subst_rDNS()
     665
    630666# Indicates module loaded OK.  Required by Perl.
    6316671;
  • branches/dns/cgi-bin/main.cgi

    r262 r273  
    641641  my $cidr;
    642642  my $alloc_from;
     643  my $rdns;
    643644
    644645  # Going to manually validate some items.
     
    781782  $html =~ s|\$\$CITY\$\$|$webvar{city}|g;
    782783  $html =~ s|\$\$CUSTID\$\$|$webvar{custid}|g;
     784  $html =~ s|\$\$RDNS\$\$|$rdns|g;
    783785  $webvar{circid} = desanitize($webvar{circid});
    784786  $html =~ s|\$\$CIRCID\$\$|$webvar{circid}|g;
Note: See TracChangeset for help on using the changeset viewer.