| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
otptool - one-time password tool |
| 6 |
|
| 7 |
=head1 SYNOPSIS |
| 8 |
|
| 9 |
otptool URI | - |
| 10 |
|
| 11 |
URI: otpauth:// |
| 12 |
|
| 13 |
If invoked with '-', the URI is read from standard input. |
| 14 |
|
| 15 |
=cut |
| 16 |
|
| 17 |
use utf8; |
| 18 |
use strict; |
| 19 |
use warnings; |
| 20 |
use open qw(:std :utf8); |
| 21 |
|
| 22 |
use Getopt::Long; |
| 23 |
use Pod::Usage; |
| 24 |
use Pass::OTP qw(otp); |
| 25 |
use Pass::OTP::URI qw(parse); |
| 26 |
|
| 27 |
our $VERSION = $Pass::OTP::VERSION; |
| 28 |
my $uri = ''; |
| 29 |
|
| 30 |
Getopt::Long::Configure(qw(auto_version)); |
| 31 |
GetOptions( |
| 32 |
'help|h|?' => sub { pod2usage(-verbose => 2) }, |
| 33 |
) || pod2usage(2); |
| 34 |
|
| 35 |
pod2usage(2) if @ARGV == 0; |
| 36 |
|
| 37 |
if ($ARGV[0] eq '-') { |
| 38 |
$uri = <>; |
| 39 |
} elsif ($ARGV[0] =~ m#^otpauth://#) { |
| 40 |
$uri = $ARGV[0]; |
| 41 |
} else { |
| 42 |
pod2usage(2); |
| 43 |
} |
| 44 |
|
| 45 |
printf("%s\n", otp(parse($uri))); |
| 46 |
exit 0; |
| 47 |
|
| 48 |
__END__ |
| 49 |
=head1 SEE ALSO |
| 50 |
|
| 51 |
L<Pass::OTP> |
| 52 |
|
| 53 |
L<oathtool(1)> |
| 54 |
|
| 55 |
=head1 COPYRIGHT AND LICENSE |
| 56 |
|
| 57 |
Copyright (C) 2020 Jan Baier |
| 58 |
|
| 59 |
This program is free software; you can redistribute it and/or modify it |
| 60 |
under the terms of either: the GNU General Public License as published |
| 61 |
by the Free Software Foundation; or the Artistic License. |
| 62 |
|
| 63 |
See L<http://dev.perl.org/licenses/> for more information. |
| 64 |
|
| 65 |
=cut |