Changeset 55 for trunk


Ignore:
Timestamp:
12/31/09 17:55:43 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

Started adding logging calls
Fixed user add sub in DNSDB.pm so that it writes encrypted passwords
Added sub to check user credentials rather than keeping that process in the main program

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r51 r55  
    6767our %reverse_typemap;
    6868
     69
    6970##
    7071## Initialization and cleanup subs
    7172##
     73
    7274
    7375## DNSDB::connectDB()
     
    154156  }
    155157} # end initGlobals
     158
     159
     160## DNSDB::_log()
     161# Log an action
     162# Internal sub
     163# Takes a database handle, <foo>, <bar>
     164sub _log {
     165} # end _log
    156166
    157167
     
    489499    my $sth = $dbh->prepare("INSERT INTO users (group_id,username,password,firstname,lastname,phone,type,status) ".
    490500        "VALUES (?,?,?,?,?,?,?,?)");
    491     $sth->execute($group,$username,$pass,$fname,$lname,$phone,$type,$state);
     501    $sth->execute($group,$username,unix_md5_crypt($pass),$fname,$lname,$phone,$type,$state);
    492502
    493503    # get the ID...
     
    510520  }
    511521} # end addUser
     522
     523
     524## DNSDB::checkUser()
     525# Check user/pass combo on login
     526sub checkUser {
     527  my $dbh = shift;
     528  my $user = shift;
     529  my $pass = shift;
     530
     531  my $sth = $dbh->prepare("SELECT user_id,group_id,password,firstname,lastname FROM users WHERE username=?");
     532  $sth->execute($user);
     533  my ($uid,$gid,$pass,$fname,$lname) = $sth->fetchrow_array;
     534  my $loginfailed = 1 if !defined($uid);
     535
     536  if ($pass =~ m|^\$1\$([A-Za-z0-9/.]+)\$|) {
     537    $loginfailed = 1 if $pass ne unix_md5_crypt($pass,$1);
     538  } else {
     539    $loginfailed = 1 if $pass ne $pass;
     540  }
     541
     542  # nnnngggg
     543  return ($uid, $gid);
     544} # end checkUser
    512545
    513546
  • trunk/dns.cgi

    r54 r55  
    275275
    276276    if ($code eq 'OK') {
     277##fixme:  need more magic to get proper group - if domain was fiddled
     278# from search-subgroups listing, may not be "current" group
     279      logaction($webvar{parentid}, $session->param("username"), $webvar{group},
     280        "Added '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}");
    277281      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
    278282    } else {
     
    315319
    316320    if ($code eq 'OK') {
     321##fixme:  need more magic to get proper group - if domain was fiddled
     322# from search-subgroups listing, may not be "current" group
     323      logaction($webvar{parentid}, $session->param("username"), $webvar{group},
     324        "Updated '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}");
    317325      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
    318326    } else {
     
    358366
    359367  if ($code eq 'OK') {
     368##fixme:  need more magic to get proper group - if domain was fiddled
     369# from search-subgroups listing, may not be "current" group
     370    logaction($webvar{parentid}, $session->param("username"), $webvar{group},
     371        "Added '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}");
    360372    showdomain($webvar{defrec},$webvar{parentid});
    361373# NB: should **really** redirect here, in case of reload.  >_<  eyowch.
     
    429441    fillsoa($webvar{defrec},$webvar{id});
    430442  } else {
     443    logaction(0, $session->param("username"), $webvar{group},
     444        "Updated SOA (ns $webvar{prins}, contact $webvar{contact}, refresh $webvar{refresh},".
     445        " retry $webvar{retry}, expire $webvar{expire}, minTTL $webvar{minttl}, TTL $webvar{ttl}");
    431446    changepage(page => "reclist", id => $webvar{id}, defrec => $webvar{defrec});
    432447    $page->param(update_failed => 0);
     
    436451
    437452} elsif ($webvar{page} eq 'adddomain') {
    438   # Need some magic here.
    439 
    440 ##fixme:  Group should be variable
     453
    441454  my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0));
    442455
    443 # hokay, a bit of magic to decide which page we hit.
    444456  if ($code eq 'OK') {
    445 # redirect to dns.cgi?etc&page=reclist
     457    logaction($msg, $session->param("username"), $webvar{group}, "Added domain $webvar{domain}");
    446458    changepage(page => "reclist", id => $msg);
    447 #    $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");
    448 #    showdomain(0,$msg);
    449459  } else {
    450460# oooh, yeah, this is supposed to be a redirect.  er, maybe.  whee.
     
    467477        # not gonna provide the 4th param: template-or-clone flag, just yet
    468478    my ($code,$msg) = addGroup($dbh, $webvar{newgroup}, $webvar{pargroup});
    469     changepage(page => "grpman") if $code eq 'OK';
     479    if $code eq 'OK' {
     480      logaction(0, $session->param("username"), $webvar{pargroup}, "Added group $webvar{newgroup}");
     481      changepage(page => "grpman");
     482    }
    470483    $page->param(add_failed => 1);
    471484    $page->param(errmsg => $msg);
     
    500513      listgroups();
    501514    } else {
     515##fixem: need more magic to correctly determine the group this action happens in
     516      logaction(0, $session->param("username"), $webvar{curgroup}, "Deleted group $webvar{id}");
    502517      # success.  go back to the domain list, do not pass "GO"
    503518      changepage(page => "grpman");
     
    539554# hokay, a bit of magic to decide which page we hit.
    540555  if ($code eq 'OK') {
     556    logaction(0, $session->param("username"), $webvar{group},
     557        "Added user $webvar{uname} ($webvar{fname} $webvar{lname})");
    541558    changepage(page => "useradmin");
    542559  } else {
     
    12601277  }
    12611278  $page->param(usertable => \@userlist);
    1262 }
     1279} # end list_users()
     1280
    12631281
    12641282# Generate all of the glop necessary to add or not the appropriate marker/flag for
     
    12931311
    12941312} # end fill_colheads()
     1313
     1314
     1315sub logaction {
     1316  my ($domid,$username,$groupid,$entry);
     1317
     1318  my $sth = dbh->prepare("SELECT user_id, firstname || ' ' || lastname FROM users WHERE username=?");
     1319  $sth->execute($username);
     1320  my ($user_id, $fullname) = $sth->fetchrow_array;
     1321
     1322  $sth = $dbh->prepare("INSERT INTO log (domain_id,user_id,group_id,email,name,entry) ".
     1323        "VALUES (?,?,?,?,?,?)");
     1324  $sth->execute($domid,$userid,$groupid,$username,$fullname,$entry);
     1325
     1326} # end logaction()
Note: See TracChangeset for help on using the changeset viewer.