Changeset 59


Ignore:
Timestamp:
01/14/10 17:54:44 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

Unkinked a few bugs in logging (creation and display)
Unkinked a few bugs in code that never got tested after it was modified

(add record) - need to test other bits

Fleshed out log display stub
Noted Net::DNS dep in INSTALL
Light display tweaks in log template, userlist template+CSS

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/INSTALL

    r58 r59  
    66 Net::Whois::Raw
    77 Text::Wrap (core) - for WHOIS response linewrapping
    8 
     8 Net::DNS
  • trunk/dns.cgi

    r57 r59  
    251251} elsif ($webvar{page} eq 'record') {
    252252
     253$debugenv = 1;
     254
    253255  if ($webvar{recact} eq 'new') {
    254256
    255257    $page->param(todo => "Add record to");
    256258    $page->param(recact => "add");
    257     fill_rectypes();
     259    $page->param(parentid => $webvar{parentid});
     260    $page->param(defrec => $webvar{defrec});
     261
     262    fill_recdata();
    258263
    259264  } elsif ($webvar{recact} eq 'add') {
     
    267272      }
    268273    }
     274
    269275    my ($code,$msg) = addRec(@recargs);
    270276
    271277    if ($code eq 'OK') {
    272 ##fixme:  need more magic to get proper group - if domain was fiddled
    273 # from search-subgroups listing, may not be "current" group
    274 
    275 # SELECT group_id FROM domains WHERE domain_id=?;
    276 # sth->execute($webvar{parentid});
    277 ##log
    278278      if ($webvar{defrec} eq 'y') {
    279279        logaction(0, $session->param("username"), $webvar{parentid},
     
    285285      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
    286286    } else {
    287 
    288287      $page->param(failed       => 1);
    289288      $page->param(errmsg       => $msg);
     
    295294      $page->param(id           => $webvar{id});
    296295      fill_recdata();   # populate the form... er, mostly.
     296      if ($webvar{defrec} eq 'y') {
     297        logaction(0, $session->param("username"), $webvar{parentid},
     298                "Failed adding default record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}");
     299      } else {
     300        logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
     301                "Failed adding record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}");
     302      }
    297303    }
    298304
     
    348354      $page->param(id           => $webvar{id});
    349355      fill_recdata();
     356      if ($webvar{defrec} eq 'y') {
     357        logaction(0, $session->param("username"), $webvar{parentid},
     358                "Failed updating default record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}");
     359      } else {
     360        logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
     361                "Failed updating record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}");
     362      }
    350363    }
    351364  }
     
    695708##fixme put in some real log-munching stuff
    696709##fixme need to add bits to *create* log entries...
    697   my $sth = $dbh->prepare("SELECT * FROM log");
    698   $sth->execute;
     710  my $sql = "SELECT user_id, email, name, entry, date_trunc('second',stamp) FROM log WHERE ";
     711  my $id = $curgroup;
     712  if ($webvar{ltype} && $webvar{ltype} eq 'dom') {
     713    $sql .= "domain_id=?";
     714    $id = $webvar{id};
     715  } else {
     716    # Default to listing curgroup log
     717    $sql .= "group_id=?";
     718  }
     719  my $sth = $dbh->prepare($sql);
     720  $sth->execute($id);
    699721  my @logbits;
    700   while (my @data = $sth->fetchrow_array) {
     722  while (my ($uid, $email, $name, $entry, $stamp) = $sth->fetchrow_array) {
    701723    my %row;
    702724# (1,1,1,'test@test','Test','frobbed the whatsit',now());
    703     $row{userfname} = $data[4];
    704     $row{userid} = $data[1];
    705     $row{useremail} = $data[3];
    706     $row{logentry} = $data[5];
    707     $row{logtime} = $data[6];
     725    $row{userfname} = $name;
     726    $row{userid} = $uid;
     727    $row{useremail} = $email;
     728    $row{logentry} = $entry;
     729    ($row{logtime}) = ($stamp =~ /^(.+)-\d\d$/);
    708730    push @logbits, \%row;
    709731  }
     
    12631285
    12641286sub logaction {
    1265   my ($domid,$username,$groupid,$entry) = shift;
    1266 
    1267   my $sth = dbh->prepare("SELECT user_id, firstname || ' ' || lastname FROM users WHERE username=?");
     1287  my $domid = shift;
     1288  my $username = shift;
     1289  my $groupid = shift;
     1290  my $entry = shift;
     1291
     1292##fixme: ooohhh, nasty.  what if we get a failure *here*?    PTHBTT!
     1293  my $sth = $dbh->prepare("SELECT user_id, firstname || ' ' || lastname FROM users WHERE username=?");
    12681294  $sth->execute($username);
    12691295  my ($user_id, $fullname) = $sth->fetchrow_array;
     
    12721298        "VALUES (?,?,?,?,?,?)");
    12731299  $sth->execute($domid,$user_id,$groupid,$username,$fullname,$entry);
    1274 
    12751300} # end logaction()
    12761301
    1277 #sub parentID($dbh, $id, $idtype, $partype[, $defrec])
     1302##fixme:  generalize to return appropriate id on all cases (ie, use $partype)
    12781303sub parentID {
    12791304  my $id = shift;
     
    12851310
    12861311  if ($idtype eq 'dom') {
    1287     return $id if $defrec eq 'y';
     1312    return $id if $defrec eq 'y';  # "domain" + default records, we're really looking at a group.
    12881313    $sql = "SELECT group_id FROM domains WHERE domain_id=?";
    12891314  } elsif ($idtype eq 'rec') {
    1290     if ($defrec && $defrec eq 'y') {
     1315    if ($defrec eq 'y') {
     1316      $sql = "SELECT group_id FROM default_records WHERE record_id=?";
    12911317    } else {
    12921318      return
     
    13021328    return "FOO", "BAR";  # can't get here.... we think.
    13031329  }
    1304 }
     1330  my $sth = $dbh->prepare($sql);
     1331  $sth->execute($id);
     1332  my ($retid) = $sth->fetchrow_array;
     1333  return $retid if $retid;
     1334  # ahh! fall of the edge of the world if things went sideways
     1335  ##fixme:  really need to do a little more error handling, I think
     1336} # end parentID()
  • trunk/templates/dns.css

    r48 r59  
    8080        border-bottom: 1px solid #666666;
    8181        width: 1%;
     82        white-space: nowrap;
     83}
     84td.data_nowrap {
    8285        white-space: nowrap;
    8386}
  • trunk/templates/log.tmpl

    r47 r59  
    88
    99<table border="0" width="70%">
    10 <tr><th colspan="5" align="center">Log entries for domain</th></tr>
     10<tr><th colspan="5" align="center">Log entries for <TMPL_VAR NAME=logfor></th></tr>
    1111  <tr class="darkrowheader">
    1212      <td>Name</td>
  • trunk/templates/useradmin.tmpl

    r51 r59  
    3232<tr class="row<TMPL_VAR name=bg>">
    3333        <td align="left"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=useradmin&amp;action=chuser&amp;user=<TMPL_VAR NAME=userid>"><TMPL_VAR NAME=username></a></td>
    34         <td><TMPL_VAR name=userfull></td>
     34        <td class="data_nowrap"><TMPL_VAR name=userfull></td>
    3535        <td><TMPL_VAR name=usertype></td>
    3636        <td><TMPL_VAR name=usergroup></td>
Note: See TracChangeset for help on using the changeset viewer.