diff -r 0fde44ae8f1d -r fb6344bb32dc redisplay --- a/redisplay Wed Feb 12 22:54:50 2014 +0100 +++ b/redisplay Wed Feb 12 23:05:45 2014 +0100 @@ -1,14 +1,25 @@ #! /usr/bin/perl # Heiko Schlittermann +# needs qrencode use 5.014; use warnings; use Sys::Hostname; +use Pod::Usage; +use Getopt::Long; + +our $VERSION = 0.1; sub url_encode { - shift =~ s/(?i:([^a-z]))/sprintf '%%%02x', ord $1/rge; + return shift =~ s/(?i:([^a-z]))/sprintf '%%%02x', ord $1/rge; } sub main { + + GetOptions( + 'h|help' => sub { pod2usage(-exit => 0, -verbose => 1) }, + 'm|man' => sub { pod2usage(-exit => 0, -verbose => 2) }, + ) or pod2usage; + if (@ARGV) { splice @ARGV, 1 } else { @ARGV = ("$ENV{HOME}/.google_authenticator") } @@ -18,7 +29,7 @@ my ($secret) = $google =~ /\A(\S+)/ or die "$0: Can't read secret from $ARGV.\n"; - my ($method) = map { lc } $google =~ /^"\s(.)\S+_AUTH$/m + my ($method) = map { lc } $google =~ /^"\s+(.)\S+_AUTH$/m or die "$0: Can't read method (time/hash) from $ARGV.\n"; my $user = $ENV{USER} // $ENV{LOGNAME} // getpwuid $>; @@ -27,14 +38,37 @@ open(my $o, '>&STDOUT'); if (-t STDIN) { open STDOUT, '|qrencode -t ansi256' - or die "$0: Can't open qrencode: $!\n"; + or die "$0: Can't open helper binary `qrencode': $!\n"; } printf "otpauth://%sotp/%s?secret=%s\n", $method, url_encode("$user\@$host"), $secret; close(STDOUT); - + return 0; } exit main unless caller; + +=head1 NAME + + redisplay - redisplay the google authenticator qr code + +=head1 SYNOPSIS + + redisplay [secretfile] + +=head1 DESCRIPTION + +B reads the F<.google_authenticator> file, extracts +the information an redisplays an ANSI256 QR code. + +The external B tool needs to be present in your PATH. + +=head1 AUTHOR + +Heiko Schlittermann L. The + +Source is at L + +=cut