File: maemo2pwsafe.pl

package info (click to toggle)
passwordsafe 1.12.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 25,980 kB
  • sloc: cpp: 67,939; ansic: 1,696; makefile: 584; perl: 459; sh: 240; xml: 210; javascript: 40
file content (82 lines) | stat: -rwxr-xr-x 2,492 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
#
# Quick hack to convert text files exported by maemo pwsafe clone
# to something that PasswordSafe can import as text.
#
# Thanks to OMOIKANE for requesting this and submitting samples.
#
# Usage: maemo2pwsafe.pl infile > outfile
# where infile is the exported text file, and outfile is the name
# of the file that will be importable by PasswordSafe.
#################################################################
#
# Copyright (c) 2012-2020 Rony Shapiro <ronys@pwsafe.org>.
# All rights reserved. Use of the code is allowed under the
# Artistic License 2.0 terms, as specified in the LICENSE file
# distributed with this code, or available from
# http://www.opensource.org/licenses/artistic-license-2.0.php
#
#################################################################

use strict;
use warnings;

my ($group, $title, $user, $password, $notes);
my $dummy;
my $inNotes = 0;

my $sep = pack("CC", 0xc2, 0xbb);

print "Group/Title\tUsername\tPassword\tNotes\n";

while (<>) {
    if (!$inNotes) {
        if (/^Group:/) {
            ($dummy, $group) = split ": "; chomp $group;
        } elsif (/^Title:/) {
            ($dummy, $title) = split ": "; chomp $title;
            # Following because tr/// can't take a var as the second arg.
            my ($c, $st);
            foreach $c (split //, $title) {
                if ($c ne ".") {
                    $st .= $c;
                } else {
                    $st .= $sep;
                }
            }
            $title = $st;
        } elsif (/^User:/) {
            ($dummy, $user) = split ": "; chomp $user;
        } elsif (/^Password/) {
            ($dummy, $password) = split ": "; chomp $password;
        } elsif (/^Notes/) {
            ($dummy, $notes) = split ": ";
            if ($notes) {
                $inNotes = 1;
            }
        } elsif (/^--$/) {
            $inNotes = 0;
            if ($notes) {chomp $notes;}
            &print_rec($group, $title, $user, $password, $notes);
        }
    } else { # inNotes
        if (/^--$/) {
            $inNotes = 0;
            if ($notes) {
                chomp $notes; chomp $notes;
            }
            &print_rec($group, $title, $user, $password, $notes);
        } else {
            $notes .= $_;
        }
    }
}

exit 0;

sub print_rec {
    my ($g, $t, $u, $p, $n) = @_;
    if (!$n) {$n = "";}
    print "$g.$t\t$u\t$p\t\"$n\"\n";
}