Changeset 477


Ignore:
Timestamp:
03/13/13 17:10:34 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Object conversion of DNSDB.pm, 11 of <mumble>. See #11.

  • convert addDomain(), delZone(), addRDNS(), getZoneCount(), getZoneList() getZoneLocation(), zoneStatus(), and getZonesByCIDR() and callers
  • fix a couple of missed utility calls in dns-rpc.cgi as well
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r476 r477  
    18161816sub addDomain {
    18171817  $errstr = '';
    1818   my $dbh = shift;
     1818  my $self = shift;
     1819  my $dbh = $self->{dbh};
    18191820  return ('FAIL',"Need database handle") if !$dbh;
    18201821  my $domain = shift;
     
    19071908# later we may want to archive it in some way instead (status code 2, for example?)
    19081909sub delZone {
    1909   my $dbh = shift;
     1910  my $self = shift;
     1911  my $dbh = $self->{dbh};
    19101912  my $zoneid = shift;
    19111913  my $revrec = shift;
     
    20472049# Returns a status code and message
    20482050sub addRDNS {
    2049   my $dbh = shift;
     2051  my $self = shift;
     2052  my $dbh = $self->{dbh};
    20502053  my $zone = NetAddr::IP->new(shift);
    20512054
     
    22202223# Returns an integer count of the resulting zone list.
    22212224sub getZoneCount {
    2222   my $dbh = shift;
     2225  my $self = shift;
     2226  my $dbh = $self->{dbh};
    22232227
    22242228  my %args = @_;
     
    22532257# Returns a reference to an array of hashrefs suitable for feeding to HTML::Template
    22542258sub getZoneList {
    2255   my $dbh = shift;
     2259  my $self = shift;
     2260  my $dbh = $self->{dbh};
    22562261
    22572262  my %args = @_;
     
    23112316# Takes a database handle, forward/reverse flag, and zone ID
    23122317sub getZoneLocation {
    2313   my $dbh = shift;
     2318  my $self = shift;
     2319  my $dbh = $self->{dbh};
    23142320  my $revrec = shift;
    23152321  my $zoneid = shift;
     
    42354241# Returns status, or undef on errors.
    42364242sub zoneStatus {
    4237   my $dbh = shift;
     4243  my $self = shift;
     4244  my $dbh = $self->{dbh};
    42384245  my $id = shift;
    42394246  my $revrec = shift;
     
    42874294# Get a list of zone names and IDs that records for a passed CIDR block are within.
    42884295sub getZonesByCIDR {
    4289   my $dbh = shift;
     4296  my $self = shift;
     4297  my $dbh = $self->{dbh};
    42904298  my %args = @_;
    42914299
  • trunk/dns-rpc.cgi

    r476 r477  
    114114  my $argref = shift;
    115115  if (!$argref->{location} && $argref->{defrec} eq 'n') {
    116     $argref->{location} = DNSDB::getZoneLocation($dbh, $argref->{revrec}, $argref->{parent_id});
     116    $argref->{location} = $dnsdb->getZoneLocation($argref->{revrec}, $argref->{parent_id});
    117117  }
    118118}
     
    142142  _commoncheck(\%args, 'y');
    143143
    144   my ($code, $msg) = DNSDB::addDomain($dbh, $args{domain}, $args{group}, $args{state});
     144  my ($code, $msg) = $dnsdb->addDomain($args{domain}, $args{group}, $args{state});
    145145  die $msg if $code eq 'FAIL';
    146146  return $msg;  # domain ID
     
    156156  # Let's be nice;  delete based on zone id OR zone name.  Saves an RPC call round-trip, maybe.
    157157  if ($args{zone} =~ /^\d+$/) {
    158     ($code,$msg) = DNSDB::delZone($dbh, $args{zone}, $args{revrec});
     158    ($code,$msg) = $dnsdb->delZone($args{zone}, $args{revrec});
    159159  } else {
    160160    my $zoneid;
    161     $zoneid = DNSDB::domainID($dbh, $args{zone}) if $args{revrec} eq 'n';
    162     $zoneid = DNSDB::revID($dbh, $args{zone}) if $args{revrec} eq 'y';
    163     die "Can't find zone: $DNSDB::errstr\n" if !$zoneid;
    164     ($code,$msg) = DNSDB::delZone($dbh, $zoneid, $args{revrec});
     161    $zoneid = $dnsdb->domainID($args{zone}) if $args{revrec} eq 'n';
     162    $zoneid = $dnsdb->revID($args{zone}) if $args{revrec} eq 'y';
     163    die "Can't find zone: $dnsdb->errstr\n" if !$zoneid;
     164    ($code,$msg) = $dnsdb->delZone($zoneid, $args{revrec});
    165165  }
    166166  die $msg if $code eq 'FAIL';
     
    178178  _commoncheck(\%args, 'y');
    179179
    180   my ($code, $msg) = DNSDB::addRDNS($dbh, $args{revzone}, $args{revpatt}, $args{group}, $args{state}, $args{defloc});
     180  my ($code, $msg) = $dnsdb->addRDNS($args{revzone}, $args{revpatt}, $args{group}, $args{state}, $args{defloc});
    181181  die "$msg\n" if $code eq 'FAIL';
    182182  return $msg;  # domain ID
     
    431431  my $cidr = new NetAddr::IP $args{cidr};
    432432
    433   my $zonelist = DNSDB::getZonesByCIDR($dbh, %args);
     433  my $zonelist = $dnsdb->getZonesByCIDR(%args);
    434434  if (scalar(@$zonelist) == 0) {
    435435    # enhh....  WTF?
     
    511511
    512512  # much like addOrUpdateRevRec()
    513   my $zonelist = DNSDB::getZonesByCIDR($dbh, %args);
     513  my $zonelist = $dnsdb->getZonesByCIDR(%args);
    514514  my $cidr = new NetAddr::IP $args{cidr};
    515515
     
    633633  _commoncheck(\%args, 'y');
    634634
    635   my @arglist = ($dbh, $args{zoneid});
     635  my @arglist = ($args{zoneid});
    636636  push @arglist, $args{status} if defined($args{status});
    637637
    638   my $status = DNSDB::zoneStatus(@arglist);
     638  my $status = $dnsdb->zoneStatus(@arglist);
    639639}
    640640
     
    645645  _commoncheck(\%args, 'y');
    646646
    647   return DNSDB::getZonesByCIDR($dbh, %args);
     647  return $dnsdb->getZonesByCIDR(%args);
    648648}
    649649
  • trunk/dns.cgi

    r476 r477  
    315315    }
    316316    if ($flag && ($permissions{admin} || $permissions{domain_edit})) {
    317       my $stat = zoneStatus($dbh,$webvar{id},'n',$webvar{zonestatus});
     317      my $stat = $dnsdb->zoneStatus($webvar{id}, 'n', $webvar{zonestatus});
    318318      $page->param(resultmsg => $DNSDB::resultstr);
    319319    } else {
     
    362362  $webvar{makeactive} = 0 if !defined($webvar{makeactive});
    363363
    364   my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0));
     364  my ($code,$msg) = $dnsdb->addDomain($webvar{domain}, $webvar{group}, ($webvar{makeactive} eq 'on' ? 1 : 0));
    365365
    366366  if ($code eq 'OK') {
     
    396396  } elsif ($webvar{del} eq 'ok') {
    397397    my $pargroup = $dnsdb->parentID(id => $webvar{id}, type => 'domain', revrec => $webvar{revrec});
    398     my ($code,$msg) = delZone($dbh, $webvar{id}, $webvar{revrec});
     398    my ($code,$msg) = $dnsdb->delZone($webvar{id}, $webvar{revrec});
    399399    if ($code eq 'OK') {
    400400      changepage(page => "domlist", resultmsg => $msg);
     
    419419    }
    420420    if ($flag && ($permissions{admin} || $permissions{domain_edit})) {
    421       my $stat = zoneStatus($dbh,$webvar{id},'y',$webvar{zonestatus});
     421      my $stat = $dnsdb->zoneStatus($webvar{id}, 'y', $webvar{zonestatus});
    422422      $page->param(resultmsg => $DNSDB::resultstr);
    423423    } else {
     
    464464  }
    465465
    466   my ($code,$msg) = addRDNS($dbh, $webvar{revzone}, $webvar{revpatt}, $webvar{group},
     466  my ($code,$msg) = $dnsdb->addRDNS($webvar{revzone}, $webvar{revpatt}, $webvar{group},
    467467        ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{location});
    468468
     
    497497    my $pargroup = $dnsdb->parentID(id => $webvar{id}, type => 'revzone', revrec => $webvar{revrec});
    498498    my $zone = $dnsdb->revName($webvar{id});
    499     my ($code,$msg) = delZone($dbh, $webvar{id}, 'y');
     499    my ($code,$msg) = $dnsdb->delZone($webvar{id}, 'y');
    500500    if ($code eq 'OK') {
    501501      changepage(page => "revzones", resultmsg => $msg);
     
    625625
    626626    if ($webvar{defrec} eq 'n') {
    627       my $defloc = getZoneLocation($dbh, $webvar{revrec}, $webvar{parentid});
     627      my $defloc = $dnsdb->getZoneLocation($webvar{revrec}, $webvar{parentid});
    628628      fill_loclist($curgroup, $defloc);
    629629    }
     
    635635
    636636    # location check - if user does not have record_locchg, set $webvar{location} to default location for zone
    637     my $parloc = getZoneLocation($dbh, $webvar{revrec}, $webvar{parentid});
     637    my $parloc = $dnsdb->getZoneLocation($webvar{revrec}, $webvar{parentid});
    638638    $webvar{location} = $parloc unless ($permissions{admin} || $permissions{record_locchg});
    639639
     
    993993  fill_grouplist("grouplist");
    994994
    995   my $count = getZoneCount($dbh, (revrec => 'n', curgroup => $curgroup) );
     995  my $count = $dnsdb->getZoneCount(revrec => 'n', curgroup => $curgroup);
    996996
    997997  $page->param(curpage => $webvar{page});
     
    10001000  $page->param(perpage => $perpage);
    10011001
    1002   my $domlist = getZoneList($dbh, (revrec => 'n', curgroup => $curgroup) );
     1002  my $domlist = $dnsdb->getZoneList(revrec => 'n', curgroup => $curgroup);
    10031003  my $rownum = 0;
    10041004  foreach my $dom (@{$domlist}) {
     
    10631063        if $webvar{bulkaction} eq 'move';
    10641064    if ($webvar{bulkaction} eq 'deactivate' || $webvar{bulkaction} eq 'activate') {
    1065       my $stat = zoneStatus($dbh,$webvar{$_},'n',($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff'));
     1065      my $stat = $dnsdb->zoneStatus($webvar{$_}, 'n', ($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff'));
    10661066      $code = (defined($stat) ? 'OK' : 'FAIL');
    10671067      $msg = (defined($stat) ? $DNSDB::resultstr : $DNSDB::errstr);
    10681068    }
    1069     ($code, $msg) = delZone($dbh, $webvar{$_}, 'n')
     1069    ($code, $msg) = $dnsdb->delZone($webvar{$_}, 'n')
    10701070        if $webvar{bulkaction} eq 'delete';
    10711071
     
    20352035  my $childlist = join(',',@childgroups);
    20362036
    2037   my $count = getZoneCount($dbh, (childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec},
    2038         filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ) );
     2037  my $count = $dnsdb->getZoneCount(childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec},
     2038        filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) );
    20392039
    20402040# fill page count and first-previous-next-last-all bits
     
    20672067  $page->param(group => $curgroup);
    20682068
    2069   my $zonelist = getZoneList($dbh, (childlist => $childlist, curgroup => $curgroup,
    2070         revrec => $webvar{revrec},
     2069  my $zonelist = $dnsdb->getZoneList(childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec},
    20712070        filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef),
    20722071        offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder
    2073         ) );
     2072        );
    20742073# probably don't need this, keeping for reference for now
    20752074#  foreach (@$zonelist) {
Note: See TracChangeset for help on using the changeset viewer.