Changeset 473 for trunk


Ignore:
Timestamp:
03/12/13 17:39:47 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

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

  • update domainName(), revName(), userFullName(), groupName() and parentID(), and callers
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r472 r473  
    17591759  my $entname;
    17601760  if ($type eq 'domain') {
    1761     $entname = domainName($dbh, $id);
     1761    $entname = $self->domainName($id);
    17621762  } elsif ($type eq 'revzone') {
    1763     $entname = revName($dbh, $id);
     1763    $entname = $self->revName($id);
    17641764  } elsif ($type eq 'user') {
    1765     $entname = userFullName($dbh, $id, '%u');
     1765    $entname = $self->userFullName($id, '%u');
    17661766  } elsif ($type eq 'group') {
    1767     $entname = groupName($dbh, $id);
     1767    $entname = $self->groupName($id);
    17681768  }
    17691769
    17701770  my ($oldgid) = $dbh->selectrow_array("SELECT group_id FROM $par_tbl{$type} WHERE $id_col{$type}=?",
    17711771        undef, ($id));
    1772   my $oldgname = groupName($dbh, $oldgid);
    1773   my $newgname = groupName($dbh, $newgrp);
     1772  my $oldgname = $self->groupName($oldgid);
     1773  my $newgname = $self->groupName($newgrp);
    17741774
    17751775  return ('FAIL', "Can't move things into a group that doesn't exist") if !$newgname;
     
    19161916  my $msg = '';
    19171917  my $failmsg = '';
    1918   my $zone = ($revrec eq 'n' ? domainName($dbh, $zoneid) : revName($dbh, $zoneid));
     1918  my $zone = ($revrec eq 'n' ? $self->domainName($zoneid) : $self->revName($zoneid));
    19191919
    19201920  return ('FAIL', ($revrec eq 'n' ? 'Domain' : 'Reverse zone')." ID $zoneid doesn't exist") if !$zone;
     
    19241924  $loghash{domain_id} = $zoneid if $revrec eq 'n';
    19251925  $loghash{rdns_id} = $zoneid if $revrec eq 'y';
    1926   $loghash{group_id} = parentID($dbh,
    1927         (id => $zoneid, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec) );
     1926  $loghash{group_id} = $self->parentID(
     1927        id => $zoneid, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec);
    19281928
    19291929  # Wrap all the SQL in a transaction
     
    19861986sub domainName {
    19871987  $errstr = '';
    1988   my $dbh = shift;
     1988  my $self = shift;
     1989  my $dbh = $self->{dbh};
    19891990  my $domid = shift;
    19901991  my ($domname) = $dbh->selectrow_array("SELECT domain FROM domains WHERE domain_id=?", undef, ($domid) );
     
    20002001sub revName {
    20012002  $errstr = '';
    2002   my $dbh = shift;
     2003  my $self = shift;
     2004  my $dbh = $self->{dbh};
    20032005  my $revid = shift;
    20042006  my ($revname) = $dbh->selectrow_array("SELECT revnet FROM revzones WHERE rdns_id=?", undef, ($revid) );
     
    20132015sub domainID {
    20142016  $errstr = '';
    2015   my $dbh = shift;
     2017  my $self = shift;
     2018  my $dbh = $self->{dbh};
    20162019  my $domain = shift;
    20172020  my ($domid) = $dbh->selectrow_array("SELECT domain_id FROM domains WHERE lower(domain) = lower(?)",
     
    20272030sub revID {
    20282031  $errstr = '';
    2029   my $dbh = shift;
     2032  my $self = shift;
     2033  my $dbh = $self->{dbh};
    20302034  my $revzone = shift;
    20312035  my ($revid) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet=?", undef, ($revzone) );
     
    24392443
    24402444  # collect some pieces for logging and error messages
    2441   my $groupname = groupName($dbh,$groupid);
    2442   my $parid = parentID($dbh, (id => $groupid, type => 'group'));
     2445  my $groupname = $self->groupName($groupid);
     2446  my $parid = $self->parentID(id => $groupid, type => 'group');
    24432447
    24442448  # Wrap all the SQL in a transaction
     
    25222526sub groupName {
    25232527  $errstr = '';
    2524   my $dbh = shift;
     2528  my $self = shift;
     2529  my $dbh = $self->{dbh};
    25252530  my $groupid = shift;
    25262531  my $sth = $dbh->prepare("SELECT group_name FROM groups WHERE group_id=?");
     
    26252630sub groupID {
    26262631  $errstr = '';
    2627   my $dbh = shift;
     2632  my $self = shift;
     2633  my $dbh = $self->{dbh};
    26282634  my $group = shift;
    26292635  my ($grpid) = $dbh->selectrow_array("SELECT group_id FROM groups WHERE group_name=?", undef, ($group) );
     
    29602966sub userFullName {
    29612967  $errstr = '';
    2962   my $dbh = shift;
     2968  my $self = shift;
     2969  my $dbh = $self->{dbh};
    29632970  my $userid = shift;
    29642971  my $fullformat = shift || '%f %l (%u)';
     
    30053012
    30063013      my %loghash;
    3007       $loghash{group_id} = parentID($dbh, (id => $id, type => 'user'));
     3014      $loghash{group_id} = $self->parentID(id => $id, type => 'user');
    30083015      $loghash{entry} = $resultstr;
    30093016      _log($dbh, %loghash);
     
    33433350# Returns a two-element list with a result code and message
    33443351sub updateSOA {
    3345   my $dbh = shift;
     3352  my $self = shift;
     3353  my $dbh = $self->{dbh};
    33463354  my $defrec = shift;
    33473355  my $revrec = shift;
     
    33493357  my %soa = @_;
    33503358
    3351   my $oldsoa = getSOA($dbh, $defrec, $revrec, $soa{id});
     3359  my $oldsoa = $self->getSOA($defrec, $revrec, $soa{id});
    33523360
    33533361  my $msg;
     
    33563364    $logdata{domain_id} = $soa{id} if $revrec eq 'n';
    33573365    $logdata{rdns_id} = $soa{id} if $revrec eq 'y';
    3358     $logdata{group_id} = parentID($dbh, (id => $soa{id}, revrec => $revrec,
    3359         type => ($revrec eq 'n' ? 'domain' : 'revzone') ) );
     3366    $logdata{group_id} = $self->parentID(id => $soa{id}, revrec => $revrec,
     3367        type => ($revrec eq 'n' ? 'domain' : 'revzone') );
    33603368  } else {
    33613369    $logdata{group_id} = $soa{id};
    33623370  }
    3363   my $parname = ($defrec eq 'y' ? groupName($dbh, $soa{id}) :
    3364                 ($revrec eq 'n' ? domainName($dbh, $soa{id}) : revName($dbh, $soa{id})) );
     3371  my $parname = ($defrec eq 'y' ? $self->groupName($soa{id}) :
     3372                ($revrec eq 'n' ? $self->domainName($soa{id}) : $self->revName($soa{id})) );
    33653373
    33663374  # Allow transactions, and raise an exception on errors so we can catch it later.
     
    36123620  }
    36133621  $logdata{group_id} = $id if $defrec eq 'y';
    3614   $logdata{group_id} = parentID($dbh,
    3615                 (id => $id, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec) )
     3622  $logdata{group_id} = $self->parentID(id => $id, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec)
    36163623        if $defrec eq 'n';
    36173624  $logdata{entry} = "Added ".($defrec eq 'y' ? 'default record' : 'record');
     
    37813788  }
    37823789  $logdata{group_id} = $parid if $defrec eq 'y';
    3783   $logdata{group_id} = parentID($dbh,
    3784                 (id => $parid, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec) )
     3790  $logdata{group_id} = $self->parentID(id => $parid, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec)
    37853791        if $defrec eq 'n';
    37863792  $logdata{entry} = "Updated ".($defrec eq 'y' ? 'default record' : 'record')." from\n";
     
    39133919  $logdata{rdns_id} = $oldrec->{rdns_id};
    39143920  $logdata{group_id} = $oldrec->{group_id} if $defrec eq 'y';
    3915   $logdata{group_id} = parentID($dbh,
    3916                 (id => $oldrec->{domain_id}, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec) )
     3921  $logdata{group_id} = $self->parentID(id => $oldrec->{domain_id}, type => ($revrec eq 'n' ? 'domain' : 'revzone'),
     3922        revrec => $revrec)
    39173923        if $defrec eq 'n';
    39183924  $logdata{entry} = "Deleted ".($defrec eq 'y' ? 'default record ' : 'record ').
     
    40934099# Returns the ID or undef on failure
    40944100sub parentID {
    4095   my $dbh = shift;
     4101  my $self = shift;
     4102  my $dbh = $self->{dbh};
    40964103
    40974104  my %args = @_;
     
    42424249
    42434250##fixme  switch to more consise "Enabled <domain"/"Disabled <domain>" as with users?
    4244       $resultstr = "Changed ".($revrec eq 'n' ? domainName($dbh, $id) : revName($dbh, $id)).
     4251      $resultstr = "Changed ".($revrec eq 'n' ? $self->domainName($id) : $self->revName($id)).
    42454252        " state to ".($newstatus ? 'active' : 'inactive');
    42464253
     
    42484255      $loghash{domain_id} = $id if $revrec eq 'n';
    42494256      $loghash{rdns_id} = $id if $revrec eq 'y';
    4250       $loghash{group_id} = parentID($dbh,
    4251         (id => $id, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec) );
     4257      $loghash{group_id} = $self->parentID(id => $id, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec);
    42524258      $loghash{entry} = $resultstr;
    42534259      _log($dbh, %loghash);
  • trunk/dns.cgi

    r470 r473  
    392392
    393393    $page->param(del_getconf => 1);
    394     $page->param(domain => domainName($dbh,$webvar{id}));
     394    $page->param(domain => $dnsdb->domainName($webvar{id}));
    395395
    396396  } elsif ($webvar{del} eq 'ok') {
    397     my $pargroup = parentID($dbh, (id => $webvar{id}, type => 'domain', revrec => $webvar{revrec}));
     397    my $pargroup = $dnsdb->parentID(id => $webvar{id}, type => 'domain', revrec => $webvar{revrec});
    398398    my ($code,$msg) = delZone($dbh, $webvar{id}, $webvar{revrec});
    399399    if ($code eq 'OK') {
     
    492492
    493493    $page->param(del_getconf => 1);
    494     $page->param(revzone => revName($dbh,$webvar{id}));
     494    $page->param(revzone => $dnsdb->revName($webvar{id}));
    495495
    496496  } elsif ($webvar{del} eq 'ok') {
    497     my $pargroup = parentID($dbh, (id => $webvar{id}, type => 'revzone', revrec => $webvar{revrec}));
    498     my $zone = revName($dbh, $webvar{id});
     497    my $pargroup = $dnsdb->parentID(id => $webvar{id}, type => 'revzone', revrec => $webvar{revrec});
     498    my $zone = $dnsdb->revName($webvar{id});
    499499    my ($code,$msg) = delZone($dbh, $webvar{id}, 'y');
    500500    if ($code eq 'OK') {
     
    569569# fill the page-count and first-previous-next-last-all details
    570570    fill_pgcount($count,"records",
    571         ($webvar{defrec} eq 'y' ? "group ".groupName($dbh,$webvar{id}) :
    572                 ($webvar{revrec} eq 'y' ? revName($dbh,$webvar{id}) : domainName($dbh,$webvar{id}))
     571        ($webvar{defrec} eq 'y' ? "group ".$dnsdb->groupName($webvar{id}) :
     572                ($webvar{revrec} eq 'y' ? $dnsdb->revName($webvar{id}) : $dnsdb->domainName($webvar{id}))
    573573        ));
    574574    fill_fpnla($count);  # should put some params on this sub...
     
    724724
    725725  if ($webvar{defrec} eq 'y') {
    726     $page->param(dohere => "default records in group ".groupName($dbh,$webvar{parentid}));
     726    $page->param(dohere => "default records in group ".$dnsdb->groupName($webvar{parentid}));
    727727  } else {
    728     $page->param(dohere => domainName($dbh,$webvar{parentid})) if $webvar{revrec} eq 'n';
    729     $page->param(dohere => revName($dbh,$webvar{parentid})) if $webvar{revrec} eq 'y';
     728    $page->param(dohere => $dnsdb->domainName($webvar{parentid})) if $webvar{revrec} eq 'n';
     729    $page->param(dohere => $dnsdb->revName($webvar{parentid})) if $webvar{revrec} eq 'y';
    730730  }
    731731
     
    929929    changepage(page => "grpman");
    930930  }
    931   $page->param(delgroupname => groupName($dbh, $webvar{id}));
     931  $page->param(delgroupname => $dnsdb->groupName($webvar{id}));
    932932
    933933} elsif ($webvar{page} eq 'edgroup') {
     
    968968        changepage(page => "grpman", warnmsg =>
    969969                "You can only grant permissions you hold.  Default permissions in group ".
    970                 groupName($dbh, $webvar{gid})." updated with reduced access");
     970                $dnsdb->groupName($webvar{gid})." updated with reduced access");
    971971      } else {
    972972        changepage(page => "grpman", resultmsg => $msg);
     
    978978  }
    979979  $page->param(gid => $webvar{gid});
    980   $page->param(grpmeddle => groupName($dbh, $webvar{gid}));
     980  $page->param(grpmeddle => $dnsdb->groupName($webvar{gid}));
    981981  my %grpperms;
    982982  getPermissions($dbh, 'group', $webvar{gid}, \%grpperms);
     
    996996
    997997  $page->param(curpage => $webvar{page});
    998   fill_pgcount($count,'domains',groupName($dbh,$curgroup));
     998  fill_pgcount($count, 'domains', $dnsdb->groupName($curgroup));
    999999  fill_fpnla($count);
    10001000  $page->param(perpage => $perpage);
     
    10261026    changepage(page => "domlist", errmsg => "You are not permitted to bulk-move domains")
    10271027        unless ($permissions{admin} || ($permissions{domain_edit} && $permissions{domain_create} && $permissions{domain_delete}));
    1028     my $newgname = groupName($dbh,$webvar{destgroup});
     1028    my $newgname = $dnsdb->groupName($webvar{destgroup});
    10291029    $page->param(action => "Move to group $newgname");
    10301030  } elsif ($webvar{bulkaction} eq 'deactivate' || $webvar{bulkaction} eq 'activate') {
     
    10561056      next;
    10571057    }
    1058     $row{domain} = domainName($dbh,$webvar{$_});
     1058    $row{domain} = $dnsdb->domainName($webvar{$_});
    10591059
    10601060    # Do the $webvar{bulkaction}
     
    13171317  if (!defined($webvar{del})) {
    13181318    $page->param(del_getconf => 1);
    1319     $page->param(user => userFullName($dbh,$webvar{id}));
     1319    $page->param(user => $dnsdb->userFullName($webvar{id}));
    13201320  } elsif ($webvar{del} eq 'ok') {
    13211321    my ($code,$msg) = delUser($dbh, $webvar{id});
     
    16271627      goto DONELOG;
    16281628    }
    1629     $page->param(logfor => 'user '.userFullName($dbh,$id));
     1629    $page->param(logfor => 'user '.$dnsdb->userFullName($id));
    16301630  } elsif ($webvar{ltype} && $webvar{ltype} eq 'dom') {
    16311631    $id = $webvar{id};
     
    16341634      goto DONELOG;
    16351635    }
    1636     $page->param(logfor => 'domain '.domainName($dbh,$id));
     1636    $page->param(logfor => 'domain '.$dnsdb->domainName($id));
    16371637  } elsif ($webvar{ltype} && $webvar{ltype} eq 'rdns') {
    16381638    $id = $webvar{id};
     
    16411641      goto DONELOG;
    16421642    }
    1643     $page->param(logfor => 'reverse zone '.revName($dbh,$id));
     1643    $page->param(logfor => 'reverse zone '.$dnsdb->revName($id));
    16441644  } else {
    16451645    # Default to listing curgroup log
    1646     $page->param(logfor => 'group '.groupName($dbh,$id));
     1646    $page->param(logfor => 'group '.$dnsdb->groupName($id));
    16471647    # note that scope limitations are applied via the change-group check;
    16481648    # group log is always for the "current" group
     
    16991699
    17001700  $page->param(group => $curgroup);
    1701   $page->param(groupname => groupName($dbh,$curgroup));
    1702   $page->param(logingrp => groupName($dbh,$logingroup));
     1701  $page->param(groupname => $dnsdb->groupName($curgroup));
     1702  $page->param(logingrp => $dnsdb->groupName($logingroup));
    17031703  $page->param(logingrp_num => $logingroup);
    17041704
     
    17711771  foreach (@childlist) {
    17721772    my %row;
    1773     $row{grpname} = groupName($dbh,$_);
     1773    $row{grpname} = $dnsdb->groupName($_);
    17741774    $row{grpnum} = $_;
    17751775    $row{whereami} = $uri_self;
     
    18471847#  $page->param(group   => $DNSDB::group);
    18481848  $page->param(isgrp => 1) if $defrec eq 'y';
    1849   $page->param(parent => ($defrec eq 'y' ? groupName($dbh, $id) :
    1850         ($revrec eq 'n' ? domainName($dbh, $id) : revName($dbh, $id)) ) );
     1849  $page->param(parent => ($defrec eq 'y' ? $dnsdb->groupName($id) :
     1850        ($revrec eq 'n' ? $dnsdb->domainName($id) : $dnsdb->revName($id)) ) );
    18511851
    18521852# defaults
     
    19261926# prefill <domain> or DOMAIN in "Host" space for new records
    19271927  if ($webvar{revrec} eq 'n') {
    1928     my $domroot = ($webvar{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$webvar{parentid}));
     1928    my $domroot = ($webvar{defrec} eq 'y' ? 'DOMAIN' : $dnsdb->domainName($webvar{parentid}));
    19291929    $page->param(name   => ($webvar{name} ? $webvar{name} : $domroot));
    19301930    $page->param(address        => $webvar{address});
     
    19361936    my $domroot = ($webvar{defrec} eq 'y' ? 'ADMINDOMAIN' : ".$config{domain}");
    19371937    $page->param(name   => ($webvar{name} ? $webvar{name} : $domroot));
    1938     my $zname = ($webvar{defrec} eq 'y' ? 'ZONE' : revName($dbh,$webvar{parentid}));
     1938    my $zname = ($webvar{defrec} eq 'y' ? 'ZONE' : $dnsdb->revName($webvar{parentid}));
    19391939    $zname =~ s|\d*/\d+$||;
    19401940    $page->param(address        => ($webvar{address} ? $webvar{address} : $zname));
     
    20392039
    20402040# fill page count and first-previous-next-last-all bits
    2041   fill_pgcount($count,($webvar{revrec} eq 'n' ? 'domains' : 'revzones'),groupName($dbh,$curgroup));
     2041  fill_pgcount($count,($webvar{revrec} eq 'n' ? 'domains' : 'revzones'),$dnsdb->groupName($curgroup));
    20422042  fill_fpnla($count);
    20432043
     
    21512151      $row{groupval} = $_;
    21522152      $row{groupactive} = ($_ == $cur);
    2153       $row{groupname} = $indent.groupName($dbh, $_);
     2153      $row{groupname} = $indent.$dnsdb->groupName($_);
    21542154      push @{$grplist}, \%row;
    21552155      getgroupdrop($_, $cur, $grplist, $indent.'&nbsp;&nbsp;&nbsp;&nbsp;');
     
    21592159  my @grouplist;
    21602160  push @grouplist, { groupval => $logingroup, groupactive => $logingroup == $curgroup,
    2161         groupname => groupName($dbh, $logingroup) };
     2161        groupname => $dnsdb->groupName($logingroup) };
    21622162  getgroupdrop($logingroup, $curgroup, \@grouplist);
    21632163
  • trunk/textrecs.cgi

    r468 r473  
    5858
    5959my $zone;
    60 $zone = ($webvar{revrec} eq 'n' ? domainName($dbh, $webvar{id}) : revName($dbh, $webvar{id}))
     60$zone = ($webvar{revrec} eq 'n' ? $dnsdb->domainName($webvar{id}) : $dnsdb->revName($webvar{id}))
    6161        if $webvar{defrec} eq 'n';
    62 $zone = "group ".groupName($dbh, $webvar{id}) if $webvar{defrec} eq 'y';
     62$zone = "group ".$dnsdb->groupName($webvar{id}) if $webvar{defrec} eq 'y';
    6363
    6464##fixme:  do we support both HTML-plain and true plaintext?  could be done, with another $webvar{}
Note: See TracChangeset for help on using the changeset viewer.