Changeset 30 for trunk


Ignore:
Timestamp:
11/06/09 18:02:00 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint

  • filled out "normal" DNS lookup, still need to fiddle with manual recursion
  • tweak fine details of login handling so we don't get an

"... uninitialized value in string eq ..." in the log

  • logout mostly working - needs additional crosscheck to kick logged-out sessions back to the login screen
  • add username blurb on menu top and as a session param (use this for above)
  • housekeeping on images/
  • misc finetuning and nitpicking of HTML
Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r29 r30  
    1717use CGI::Session;
    1818use Crypt::PasswdMD5;
     19use Net::DNS;
    1920use DBI;
    2021
     
    8687
    8788# handle login redirect
    88 if ($webvar{action} && $webvar{action} eq 'login') {
    89   my $sth = $dbh->prepare("SELECT user_id,group_id,password,firstname,lastname FROM users WHERE username=?");
    90   $sth->execute($webvar{username});
    91   my ($uid,$gid,$pass,$fname,$lname) = $sth->fetchrow_array;
    92   $webvar{loginfailed} = 1 if !defined($uid);
    93 
    94   if ($pass =~ m|^\$1\$([A-Za-z0-9/.]+)\$|) {
    95     $webvar{loginfailed} = 1 if $pass ne unix_md5_crypt($webvar{password},$1);
    96   } else {
    97     $webvar{loginfailed} = 1 if $pass ne $webvar{password};
    98   }
    99 
    100   # set session bits
    101   $session->param('logingroup',$gid);
    102   $session->param('curgroup',$gid);
    103 
    104   changepage(page => "domlist") if !defined($webvar{loginfailed});
     89if ($webvar{action}) {
     90  if ($webvar{action} eq 'login') {
     91    my $sth = $dbh->prepare("SELECT user_id,group_id,password,firstname,lastname FROM users WHERE username=?");
     92    $sth->execute($webvar{username});
     93    my ($uid,$gid,$pass,$fname,$lname) = $sth->fetchrow_array;
     94    $webvar{loginfailed} = 1 if !defined($uid);
     95
     96    if ($pass =~ m|^\$1\$([A-Za-z0-9/.]+)\$|) {
     97      $webvar{loginfailed} = 1 if $pass ne unix_md5_crypt($webvar{password},$1);
     98    } else {
     99      $webvar{loginfailed} = 1 if $pass ne $webvar{password};
     100    }
     101
     102    # set session bits
     103    $session->param('logingroup',$gid);
     104    $session->param('curgroup',$gid);
     105    $session->param('username',$webvar{username});
     106
     107    changepage(page => "domlist") if !defined($webvar{loginfailed});
     108  } elsif ($webvar{action} eq 'logout') {
     109    # delete the session
     110    $session->delete();
     111    $session->flush();
     112
     113    my $newurl = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}";
     114    $newurl =~ s|/[^/]+$|/|;
     115    print "Status: 302\nLocation: $newurl\n\n";
     116    exit;
     117
     118  }
    105119}
    106120
     
    513527  }
    514528
     529} elsif ($webvar{page} eq 'dnsq') {
     530
     531  $page->param(qfor => $webvar{qfor}) if $webvar{qfor};
     532  fill_rectypes($webvar{type} ? $webvar{type} : '');
     533  $page->param(trace => $webvar{trace}) if $webvar{trace};
     534  $page->param(resolver => $webvar{resolver}) if $webvar{resolver};
     535
     536  if ($webvar{qfor}) {
     537    my $resolv = Net::DNS::Resolver->new;
     538    my $query = $resolv->query($webvar{qfor}, $typemap{$webvar{type}});
     539    if ($query) {
     540
     541      $page->param(showresults => 1);
     542
     543      my @answer;
     544      foreach my $rr ($query->answer) {
     545#       next unless $rr->type eq "A" or $rr->type eq 'NS';
     546        my %row;
     547        my ($host,$ttl,$class,$type,$data) =
     548                ($rr->string =~ /^([0-9a-zA-Z_.-]+)\s+(\d+)\s+([A-Za-z]+)\s+([A-Za-z]+)\s+(.+)$/);
     549        $row{host} = $host;
     550        $row{ftype} = $type;
     551        $row{rdata} = $data;
     552        push @answer, \%row;
     553      }
     554      $page->param(answer => \@answer);
     555
     556      my @additional;
     557      foreach my $rr ($query->additional) {
     558#       next unless $rr->type eq "A" or $rr->type eq 'NS';
     559        my %row;
     560        my ($host,$ttl,$class,$type,$data) =
     561                ($rr->string =~ /^([0-9a-zA-Z_.-]+)\s+(\d+)\s+([A-Za-z]+)\s+([A-Za-z]+)\s+(.+)$/);
     562        $row{host} = $host;
     563        $row{ftype} = $type;
     564        $row{rdata} = $data;
     565        push @additional, \%row;
     566      }
     567      $page->param(additional => \@additional);
     568
     569      my @authority;
     570      foreach my $rr ($query->authority) {
     571#       next unless $rr->type eq "A" or $rr->type eq 'NS';
     572        my %row;
     573        my ($host,$ttl,$class,$type,$data) =
     574                ($rr->string =~ /^([0-9a-zA-Z_.-]+)\s+(\d+)\s+([A-Za-z]+)\s+([A-Za-z]+)\s+(.+)$/);
     575        $row{host} = $host;
     576        $row{ftype} = $type;
     577        $row{rdata} = $data;
     578        push @authority, \%row;
     579      }
     580      $page->param(authority => \@authority);
     581
     582      $page->param(usedresolver => $resolv->answerfrom);
     583      $page->param(frtype => $typemap{$webvar{type}});
     584
     585    } else {
     586      $page->param(errmsg => $resolv->errorstring);
     587    }
     588  }
     589  ## done DNS query
     590
    515591}
    516592
     
    521597##common bits
    522598if ($webvar{page} ne 'login') {
     599  $page->param(username => $session->param("username"));
     600
    523601  $page->param(group => $curgroup);
    524602  $page->param(groupname => groupName($dbh,$curgroup));
     
    591669    $newurl .= "&$_=$params{$_}";
    592670  }
     671
     672  # Just In Case
     673  $session->flush();
    593674
    594675  print "Status: 302\nLocation: $newurl\n\n";
  • trunk/images

    • Property svn:ignore set to
      *.png
      *.gif
      *.jpg
      *.bak
  • trunk/templates/domlist.tmpl

    r22 r30  
    5252
    5353</td>
     54</tr>
    5455</table>
  • trunk/templates/menu.tmpl

    r24 r30  
    11<td class="menu">
     2<TMPL_VAR NAME=username> logged in<br />
     3<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&action=logout">Log out</a>
     4<hr>
    25<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=domlist">Domains</a><br />
    36<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=useradmin">Users</a><br />
Note: See TracChangeset for help on using the changeset viewer.