[BACK]Return to keyring.cgi CVS log [TXT][DIR] Up to [local] / palm / Palm-Keyring / examples / cgi / bin

Diff for /palm/Palm-Keyring/examples/cgi/bin/keyring.cgi between version 1.1 and 1.6

version 1.1, 2009/06/11 21:40:45 version 1.6, 2012/06/10 04:48:05
Line 1 
Line 1 
 #!/usr/bin/perl  #!/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  # keyring.cgi *** Update and modify keyring files
 #  #
Line 13 
Line 13 
 use strict;  use strict;
 use warnings;  use warnings;
   
 use Data::Dumper;  
   
 use feature 'state';  use feature 'state';
   
 use CGI;  use CGI;
Line 25 
Line 23 
 use Palm::Keyring;  use Palm::Keyring;
 use Template;  use Template;
   
 my $base_path = '/keyring';  my @path = '/users';
 my $keyring_path = catdir($base_path, 'rings');  if ($ENV{'PATH_INFO'} && $ENV{'PATH_INFO'} ne '/') {
 my $dir       = $ENV{'PATH_INFO'} || '/';      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 $query = CGI->new();
 my $tt  my $tt    = Template->new( { INCLUDE_PATH => catdir('../templates') } );
     = Template->new( { INCLUDE_PATH => catdir( $base_path, 'templates' ) } );  my $pjx   = new CGI::Ajax(
 my $pjx = new CGI::Ajax(  
     changeFile     => \&change_file,      changeFile     => \&change_file,
     changeCategory => \&change_category,      changeCategory => \&change_category,
     changeRecord   => \&change_record,      changeRecord   => \&change_record,
Line 41 
Line 45 
 #$pjx->JSDEBUG(1);  #$pjx->JSDEBUG(1);
 #$pjx->DEBUG(1);  #$pjx->DEBUG(1);
   
 my $password = $query->param('password');  my $password = $query->param('unlock_password');
 my $file     = $query->param('file') || '';  my $file     = $query->param('file') || '';
 my $category = $query->param('category');  my $category = $query->param('category');
 my $record   = $query->param('record');  my $record   = $query->param('record');
Line 51 
Line 55 
 }  }
   
 $file = canonpath($file) if $file;  $file = canonpath($file) if $file;
   if ( $file =~ /^ \Q$path[0]\E /xms ) {
 if ( $file =~ /^ \Q$keyring_path\E /xms ) {  
     $dir = dirname($file);      $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 ) {  files() if !$file;
         error("no file in [$dir]!");  
     }  
   
     if ( $dir && $file ) {  if ( !$file ) {
         if ( !-d $dir ) {      error("No Keyrings in [$dir]!");
             error("Path [$dir] does not exist!");  
         }  
         $file = catfile( $dir, basename($file) );  
     }  
 }  }
   
   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 $pjx->build_html( $query, \&Show_HTML );
   
 #print $query->header(), Show_HTML();  #print $query->header(), Show_HTML();
   
 sub Show_HTML {  sub Show_HTML {
Line 107 
Line 113 
 }  }
   
 sub password {  sub password {
       my $message = '';
     if ($password) {      if ($password) {
         my $pdb = open_pdb();          my $pdb = open_pdb();
         eval { $pdb->Password($password) };          my $valid = eval { $pdb->Password($password) };
         if ($@) {          if ($@) {
             error($@);              error($@);
               $message = "Error: $@";
         }          }
         else {          elsif ($valid) {
             return              return
                   'Unlocked: '                    'Unlocked: '
                 . $query->hidden( 'password', $password )                  . $query->hidden( 'unlock_password', $password )
                 . $query->submit( -name => 'lock', -value => 'Lock', );                  . $query->submit( -name => 'lock', -value => 'Lock', );
         }          }
           else {
               $message = "$message<br>Invalid Password";
           }
     }      }
   
     return 'Password: '      return 'Locked - Enter Password to Unlock: ' . $query->br()
         . $query->password_field(          . $message . $query->password_field(
         -name     => 'password',              -name     => 'unlock_password',
         -value    => '',              -value    => '',
         -override => 1,              -override => 1,
         );          );
 }  }
   
Line 148 
Line 159 
                 -default  => $file,                  -default  => $file,
                 -onChange => "changeFile("                  -onChange => "changeFile("
                     . "['file'],"                      . "['file'],"
                     . "['passwords','files','categories','lists','records','errors']);",                      . "['unlock_passwords','files','categories','lists','records','errors']);",
             );              );
         }          }
         else {          else {
Line 176 
Line 187 
   
     return $query->popup_menu(      return $query->popup_menu(
         -name     => 'category',          -name     => 'category',
         -values   => [ sort { $a <=> $b } keys %categories ],          -values   => [
               sort { lc( $categories{$a} ) cmp lc( $categories{$b} ) }
                   keys %categories
           ],
         -default  => $category,          -default  => $category,
         -labels   => \%categories,          -labels   => \%categories,
         -onChange => "changeCategory("          -onChange => "changeCategory("
             . "['password','file','category'],"              . "['unlock_password','file','category'],"
             . "['lists','errors'], 'POST');",              . "['lists','errors'], 'POST');",
     );      );
 }  }
Line 207 
Line 221 
         ],          ],
         -default  => [$record],          -default  => [$record],
         -labels   => \%records,          -labels   => \%records,
         -size     => 25,  
         -onChange => "changeRecord("          -onChange => "changeRecord("
             . "['password','file','record'],"              . "['unlock_password','file','record'],"
             . "['records','errors'], 'POST');",              . "['records','errors'], 'POST');",
     );      );
 }  }
Line 246 
Line 259 
                 my $d = $acct{$label}{data};                  my $d = $acct{$label}{data};
                 $acct{$label}{data} = sprintf "%04d/%02d/%02d",                  $acct{$label}{data} = sprintf "%04d/%02d/%02d",
                     $d->{year} + 1900,                      $d->{year} + 1900,
                     $d->{month},                      $d->{month} + 1,
                     $d->{day};                      $d->{day};
             }              }
   
Line 267 
Line 280 
             $label = 'Last Change';              $label = 'Last Change';
         }          }
   
           my $type = 'textfield';
           if ($key eq 'notes') {
               $type = 'textarea';
           }
   
         $output          $output
             .= $label . ': '              .= $label . ': ' .
             . $query->textfield(              #$acct{$key}{data} .
               $query->$type(
             -name     => 'acct_' . $key,              -name     => 'acct_' . $key,
             -value    => $acct{$key}{data},              -value    => $acct{$key}{data},
             -override => 1,              -override => 1,
             ) . $query->br;              ) .
               $query->br;
     }      }
   
     return $output;      return $output;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.6

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>