use strict;
use warnings FATAL => q(all);
use JSON;
use URI;
use URI::QueryParam;
use UUID 'uuid';
binmode STDOUT;
my %h = (
db => { version => 3 },
header => {
params => undef,
slots => undef
},
version => 1,
);
while (<>) {
next unless /otpauth:.*/;
my $u = URI->new($&);
push @{ $h{db}->{entries} }, {
icon => undef,
info => {
algorithm => "SHA1",
period => 30,
digits => 6,
secret => $u->query_param('secret'),
},
name => ( $u->path_segments )[-1],
issuer => ( $u->path_segments )[-1],
type => $u->authority,
uuid => uuid(),
note => "",
favorite => JSON::false,
groups => undef,
};
}
for ( @{ $h{db}->{entries} } ) {
$_->{info}->{digits} += 0;
$_->{info}->{period} += 0;
}
my $json = JSON->new;
$json = $json->canonical(1);
print $json->pretty->encode( \%h );