=================================================================== RCS file: /cvs/palm/Palm-Keyring/examples/cgi/bin/keyring.cgi,v retrieving revision 1.4 retrieving revision 1.6 diff -u -r1.4 -r1.6 --- palm/Palm-Keyring/examples/cgi/bin/keyring.cgi 2009/07/16 21:08:45 1.4 +++ palm/Palm-Keyring/examples/cgi/bin/keyring.cgi 2012/06/10 04:48:05 1.6 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $RedRiver: keyring.cgi,v 1.3 2009/06/16 01:39:09 andrew Exp $ +# $RedRiver: keyring.cgi,v 1.4 2009/07/16 20:08:45 andrew Exp $ ######################################################################## # keyring.cgi *** Update and modify keyring files # @@ -13,8 +13,6 @@ use strict; use warnings; -use Data::Dumper; - use feature 'state'; use CGI; @@ -25,8 +23,16 @@ use Palm::Keyring; use Template; -my $base_path = '/users'; -my $dir = $ENV{'PATH_INFO'} || '/'; +my @path = '/users'; +if ($ENV{'PATH_INFO'} && $ENV{'PATH_INFO'} ne '/') { + push @path, $ENV{'PATH_INFO'}; +} +elsif ( $ENV{'REMOTE_USER'} ) { + push @path, $ENV{'REMOTE_USER'}; + # This is the users subdir; + push @path, 'rings'; +} +my $dir = catdir( @path ); my $query = CGI->new(); my $tt = Template->new( { INCLUDE_PATH => catdir('../templates') } ); @@ -49,20 +55,16 @@ } $file = canonpath($file) if $file; -$dir = canonpath($dir) if $dir; +if ( $file =~ /^ \Q$path[0]\E /xms ) { + $dir = dirname($file); +} +$dir = canonpath($dir) if $dir; if ( $dir =~ m{/\.\.//}xms ) { error('Invalid Dir [$dir]'); $dir = ''; } -if ( $file =~ /^ \Q$base_path\E /xms ) { - $dir = dirname($file); -} -else { - $dir = catdir( $base_path, $dir, 'rings' ); -} - files() if !$file; if ( !$file ) { @@ -111,25 +113,30 @@ } sub password { + my $message = ''; if ($password) { my $pdb = open_pdb(); - eval { $pdb->Password($password) }; + my $valid = eval { $pdb->Password($password) }; if ($@) { error($@); + $message = "Error: $@"; } - else { + elsif ($valid) { return 'Unlocked: ' . $query->hidden( 'unlock_password', $password ) . $query->submit( -name => 'lock', -value => 'Lock', ); } + else { + $message = "$message
Invalid Password"; + } } return 'Locked - Enter Password to Unlock: ' . $query->br() - . $query->password_field( - -name => 'unlock_password', - -value => '', - -override => 1, + . $message . $query->password_field( + -name => 'unlock_password', + -value => '', + -override => 1, ); } @@ -252,7 +259,7 @@ my $d = $acct{$label}{data}; $acct{$label}{data} = sprintf "%04d/%02d/%02d", $d->{year} + 1900, - $d->{month}, + $d->{month} + 1, $d->{day}; } @@ -279,12 +286,14 @@ } $output - .= $label . ': ' - . $query->$type( + .= $label . ': ' . + #$acct{$key}{data} . + $query->$type( -name => 'acct_' . $key, -value => $acct{$key}{data}, -override => 1, - ) . $query->br; + ) . + $query->br; } return $output;