=================================================================== RCS file: /cvs/palm/Palm-Keyring/examples/cgi/bin/keyring.cgi,v retrieving revision 1.1 retrieving revision 1.6 diff -u -r1.1 -r1.6 --- palm/Palm-Keyring/examples/cgi/bin/keyring.cgi 2009/06/11 21:40:45 1.1 +++ palm/Palm-Keyring/examples/cgi/bin/keyring.cgi 2012/06/10 04:48:05 1.6 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $RedRiver$ +# $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,14 +23,20 @@ use Palm::Keyring; use Template; -my $base_path = '/keyring'; -my $keyring_path = catdir($base_path, 'rings'); -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( $base_path, 'templates' ) } ); -my $pjx = new CGI::Ajax( +my $tt = Template->new( { INCLUDE_PATH => catdir('../templates') } ); +my $pjx = new CGI::Ajax( changeFile => \&change_file, changeCategory => \&change_category, changeRecord => \&change_record, @@ -41,7 +45,7 @@ #$pjx->JSDEBUG(1); #$pjx->DEBUG(1); -my $password = $query->param('password'); +my $password = $query->param('unlock_password'); my $file = $query->param('file') || ''; my $category = $query->param('category'); my $record = $query->param('record'); @@ -51,28 +55,30 @@ } $file = canonpath($file) if $file; - -if ( $file =~ /^ \Q$keyring_path\E /xms ) { +if ( $file =~ /^ \Q$path[0]\E /xms ) { $dir = dirname($file); } -else { - $dir = catdir( $keyring_path, $dir ); - files() if !$file; +$dir = canonpath($dir) if $dir; +if ( $dir =~ m{/\.\.//}xms ) { + error('Invalid Dir [$dir]'); + $dir = ''; +} - if ( !$file ) { - error("no file in [$dir]!"); - } +files() if !$file; - if ( $dir && $file ) { - if ( !-d $dir ) { - error("Path [$dir] does not exist!"); - } - $file = catfile( $dir, basename($file) ); - } +if ( !$file ) { + error("No Keyrings in [$dir]!"); } +if ( $dir && $file ) { + $file = catfile( $dir, basename($file) ); + error("Dir [$dir] does not exist!") if !-d $dir; + error("File [$file] does not exist!") if !-e $file; +} + print $pjx->build_html( $query, \&Show_HTML ); + #print $query->header(), Show_HTML(); sub Show_HTML { @@ -107,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( 'password', $password ) + . $query->hidden( 'unlock_password', $password ) . $query->submit( -name => 'lock', -value => 'Lock', ); } + else { + $message = "$message
Invalid Password"; + } } - return 'Password: ' - . $query->password_field( - -name => 'password', - -value => '', - -override => 1, + return 'Locked - Enter Password to Unlock: ' . $query->br() + . $message . $query->password_field( + -name => 'unlock_password', + -value => '', + -override => 1, ); } @@ -148,7 +159,7 @@ -default => $file, -onChange => "changeFile(" . "['file']," - . "['passwords','files','categories','lists','records','errors']);", + . "['unlock_passwords','files','categories','lists','records','errors']);", ); } else { @@ -176,11 +187,14 @@ return $query->popup_menu( -name => 'category', - -values => [ sort { $a <=> $b } keys %categories ], + -values => [ + sort { lc( $categories{$a} ) cmp lc( $categories{$b} ) } + keys %categories + ], -default => $category, -labels => \%categories, -onChange => "changeCategory(" - . "['password','file','category']," + . "['unlock_password','file','category']," . "['lists','errors'], 'POST');", ); } @@ -207,9 +221,8 @@ ], -default => [$record], -labels => \%records, - -size => 25, -onChange => "changeRecord(" - . "['password','file','record']," + . "['unlock_password','file','record']," . "['records','errors'], 'POST');", ); } @@ -246,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}; } @@ -267,13 +280,20 @@ $label = 'Last Change'; } + my $type = 'textfield'; + if ($key eq 'notes') { + $type = 'textarea'; + } + $output - .= $label . ': ' - . $query->textfield( + .= $label . ': ' . + #$acct{$key}{data} . + $query->$type( -name => 'acct_' . $key, -value => $acct{$key}{data}, -override => 1, - ) . $query->br; + ) . + $query->br; } return $output;