#!/usr/bin/perl -w

use strict;
use MIME::Base64;

my @data;
while(<>) {
	chomp;
print "## read: $_\n";
	push @data,$_;
}

my $skip = 1;

# skip "don't save password for host" list
while(@data && $skip) {
	my $d = shift @data;
print "## $d\n";
	$skip = 0 if ($d eq ".");
}

while(@data) {

	my $host = shift @data;

	my $user_fld = shift @data;
	$user_fld =~ s/^.*?=//g;
	$user_fld =~ s/=.*$//g;

	my $user = shift @data;
	if ($user =~ /^\~([A-Za-z0-9\+\=\/]+)/) {
		$user = decode_base64($1),"\n";
	} else {
		die "can't decode username '$user'!";
	}

	my $passwd_fld = shift @data;
	$passwd_fld =~ s/^.*?=//g;
	$passwd_fld =~ s/=.*$//g;

	my $passwd = shift @data;
	if ($passwd =~ /^\~([A-Za-z0-9\+\=\/]+)/) {
		$passwd = decode_base64($1),"\n";
	} else {
		die "can't decode password '$passwd'!";
	}

	printf("%30s -- %10s: %10s %10s: %10s\n",$host,$user_fld,$user,$passwd_fld,$passwd);

	my $sep = shift @data;
	if ($sep ne ".") {
		die "can't find separator! [$sep]";
	}

}
