#!/usr/local/bin/perl

use warnings;
use strict;

my($line);
my(@t);
my($inp);
my($t);
my($i);
my($cnt) = 0;
my($peer);

if ( $#ARGV == -1 ) {
   print "usage: $0 <teldat config file>\n";
   exit(1);
}
$inp=$ARGV[0];

open(INP,$inp) || die "$0: can not read '$inp': $!\n";


while (<INP>) {
    $line=$_;
    chop($line);
    $cnt++;
    next if ( $line !~ /ipsecPeerPreSharedKeyData/ && $line !~ /ipsecPeerDescription/ );

    if ( $line =~ /ipsecPeerDescription/ ) {
	@t = split(/\s+/,$line);
	$peer = $t[3];
	next;
    }

    @t = split(/\s+/,$line);

    # print $t[2]."\n";

    @t = split(/:/,$t[2]);

    $t = '';
    foreach $i (@t) {
	$t .= chr(hex($i));
    }

    print "line $cnt peer $peer '$t'\n";
}

