OpenPKG CVS Repository
  http://cvs.openpkg.org/
  ____________________________________________________________________________

  Server: cvs.openpkg.org                  Name:   Thomas Lotterer
  Root:   /v/openpkg/cvs                   Email:  [EMAIL PROTECTED]
  Module: openpkg-registry                 Date:   22-Nov-2005 12:30:16
  Branch: HEAD                             Handle: 2005112211301500

  Modified files:
    openpkg-registry        registry-ui.pl

  Log:
    modularize user identification by supporting constant, naive and basic
    auth modes

  Summary:
    Revision    Changes     Path
    1.3         +88 -24     openpkg-registry/registry-ui.pl
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: openpkg-registry/registry-ui.pl
  ============================================================================
  $ cvs diff -u -r1.2 -r1.3 registry-ui.pl
  --- openpkg-registry/registry-ui.pl   19 Nov 2005 22:13:07 -0000      1.2
  +++ openpkg-registry/registry-ui.pl   22 Nov 2005 11:30:15 -0000      1.3
  @@ -44,8 +44,19 @@
   my $progvers="0.0.16";
   my $progdate="19-Nov-2005";
   
  -#   catch and hold time
  -my $time = time();
  +#   configuration
  +#
  +my $cfg = {};
  +
  +#   user identification
  +#
  +#   constant  - no authentication at all, assume single constant default user
  +#   naive     - no authentication at all, ask for username and just trust it
  +#   basicauth - believe in webserver's basic authentication
  +#   ase       - OSSP affiliation services environment
  +#
  +$cfg->{identification}->{mode} = "basicauth";
  +$cfg->{identification}->{default} = "[EMAIL PROTECTED]"; #anonymous
   
   #   create objects
   my $cgi  = new CGI;
  @@ -73,6 +84,30 @@
       );
   }
   
  +sub identifyusername()
  +{
  +    my $username;
  +    $username = undef;
  +
  +    if    ($cfg->{identification}->{mode} eq "ase") {
  +        die "FIXME ase not implemented";
  +    }
  +    elsif ($cfg->{identification}->{mode} eq "basicauth") {
  +        $username = $ENV{'REMOTE_USER'};
  +    }
  +    elsif ($cfg->{identification}->{mode} eq "naive") {
  +        $username = $cgi->cookie("username");
  +    }
  +    elsif ($cfg->{identification}->{mode} eq "constant") {
  +        $username = $cfg->{identification}->{default};
  +    }
  +    else {
  +        die "misconfigured identification 
mode=\"".$cfg->{identification}->{mode}."\"";
  +    }
  +    $username = undef if ($username =~ m|^[ ]+$|);
  +    return $username;
  +}
  +
   #   first check for pages which do not require database access
   #
   if    ($cgi->param("page") eq "css") {
  @@ -734,7 +769,7 @@
   sub viewassociationform()
   {
       my ($html, $username);
  -    $username = $cgi->cookie('username');
  +    $username = &identifyusername();
       $html = '';
       $html .= $cgi->start_form();
       $html .= $cgi->delete(-name=>'page');
  @@ -749,18 +784,32 @@
   {
       my $html;
       $html .= '';
  -    $html .= $cgi->start_form();
  -    $html .= $cgi->delete(-name=>'page');
  -    $html .= $cgi->hidden(-name=>'page', -value => "login");
  -    $html .= $cgi->submit('submit','login');
  -    $html .= $cgi->textfield(
  -        -name      => 'username',
  -        -override  => 1,
  -        -size      => 50,
  -        -maxlength => 50,
  -        -default   => '[EMAIL PROTECTED]',
  -    ) . "\n";
  -    $html .= $cgi->end_form;
  +    if    ($cfg->{identification}->{mode} eq "ase") {
  +        die #FIXME
  +    }
  +    elsif ($cfg->{identification}->{mode} eq "basicauth") {
  +        # nop
  +    }
  +    elsif ($cfg->{identification}->{mode} eq "naive") {
  +        $html .= $cgi->start_form();
  +        $html .= $cgi->delete(-name=>'page');
  +        $html .= $cgi->hidden(-name=>'page', -value => "login");
  +        $html .= $cgi->submit('submit','login');
  +        $html .= $cgi->textfield(
  +            -name      => 'username',
  +            -override  => 1,
  +            -size      => 50,
  +            -maxlength => 50,
  +            -default   => $cfg->{identification}->{default},
  +        ) . "\n";
  +        $html .= $cgi->end_form;
  +        }
  +    elsif ($cfg->{identification}->{mode} eq "constant") {
  +        # nop
  +    }
  +    else {
  +        die "misconfigured identification 
mode=\"".$cfg->{identification}->{mode}."\"";
  +    }
       return $html;
   }
   
  @@ -789,11 +838,26 @@
   sub viewlogoutform()
   {
       my $html;
  -    $html .= $cgi->start_form();
  -    $html .= $cgi->delete(-name=>'page');
  -    $html .= $cgi->hidden(-name=>'page', -value => "logout");
  -    $html .= $cgi->submit('submit','logout');
  -    $html .= $cgi->end_form;
  +    $html = '';
  +    if    ($cfg->{identification}->{mode} eq "ase") {
  +        die #FIXME
  +    }
  +    elsif ($cfg->{identification}->{mode} eq "basicauth") {
  +        # nop
  +    }
  +    elsif ($cfg->{identification}->{mode} eq "naive") {
  +        $html .= $cgi->start_form();
  +        $html .= $cgi->delete(-name=>'page');
  +        $html .= $cgi->hidden(-name=>'page', -value => "logout");
  +        $html .= $cgi->submit('submit','logout');
  +        $html .= $cgi->end_form;
  +    }
  +    elsif ($cfg->{identification}->{mode} eq "constant") {
  +        # nop
  +    }
  +    else {
  +        die "misconfigured identification 
mode=\"".$cfg->{identification}->{mode}."\"";
  +    }
       return $html;
   }
   
  @@ -837,8 +901,8 @@
   
       $html = '';
   
  -    $username = $cgi->cookie('username');
  -    if (not defined $username or $username =~ m|^[ ]+$|) {
  +    $username = &identifyusername();
  +    if (not defined $username) {
           $html .= "<blink>Please login first</blink>";
           return $html;
       }
  @@ -919,8 +983,8 @@
       my $username;
   
       $html = '';
  -    $username = $cgi->cookie('username');
  -    if (not defined $username or $username =~ m|^[ ]+$|) {
  +    $username = &identifyusername();
  +    if (not defined $username) {
           $html .= "<blink>Please login first</blink>";
           return $html;
       }
  @@ .
______________________________________________________________________
The OpenPKG Project                                    www.openpkg.org
CVS Repository Commit List                     openpkg-cvs@openpkg.org

Reply via email to