#!/usr/bin/perl use XML::Twig; use Tie::IxHash; my $spooldir = shift; die "usage: $0 \n\n" unless (-d $spooldir); my $twig = XML::Twig->new(); my $output = XML::Twig::Elt->new('Openfire'); $output->set_pretty_print('indented'); opendir(DIR, $spooldir) or die "unable to open $spooldir: $!"; for my $file (readdir(DIR)) { next unless ($file =~ /\.xml$/); my $filename = $spooldir . '/' . $file; my ($mtime, $ctime, $username, $password, $email, $name); $username = XML::Twig::Elt->new('Username'); $username->set_text('default'); $password = XML::Twig::Elt->new('Password'); $password->set_text('default'); my $userxml = XML::Twig::Elt->new('User'); my $rosterxml = XML::Twig::Elt->new('Roster'); $name = XML::Twig::Elt->new('Name'); $email = XML::Twig::Elt->new('Email'); $twig->parsefile($filename); my $root = $twig->root; my @stat = stat($filename); $mtime = XML::Twig::Elt->new('ModifiedDate'); $mtime->set_text($stat[9]); $ctime = XML::Twig::Elt->new('CreationDate'); $ctime->set_text($stat[10]); for my $pass ($root->children('password')) { if ($pass->att('xmlns') eq 'jabber:iq:auth') { $password->set_text($pass->text()); } } for my $query ($root->children('query')) { # username/password "registration" if ($query->att('xmlns') eq 'jabber:iq:register') { for my $sibling ($query->children('username')) { $username->set_text($sibling->text()); } for my $sibling ($query->children('password')) { $password->set_text($sibling->text()); } for my $sibling ($query->children('name')) { $name->set_text($sibling->text()); } for my $sibling ($query->children('email')) { $email->set_text($sibling->text()); } } # roster information if ($query->att('xmlns') eq 'jabber:iq:roster') { for my $item ($query->children('item')) { my $jid = $item->att('jid'); my $subscription = $item->att('subscription'); my $name = $item->att('name'); my $xml = XML::Twig::Elt->new('Item'); $xml->set_keep_atts_order(1); $xml->set_att('jid', $jid) if ($jid); if ($subscription eq 'both') { $xml->set_att('askstatus', '-1'); $xml->set_att('recvstatus', '-1'); $xml->set_att('substatus', '3'); } elsif ($subscription eq 'none') { $xml->set_att('substatus', '0'); $xml->set_att('askstatus', '0'); $xml->set_att('recvstatus', '-1'); } elsif ($subscription eq 'to') { $xml->set_att('substatus', '1'); $xml->set_att('askstatus', '0'); $xml->set_att('recvstatus', '-1'); } elsif ($subscription eq 'from') { $xml->set_att('substatus', '2'); $xml->set_att('askstatus', '0'); $xml->set_att('recvstatus', '-1'); } $xml->set_att('name', $name) if ($name); my @groups = ($item->children('group')); if (@groups) { for my $group ($item->children('group')) { my $groupxml = XML::Twig::Elt->new('Group'); $groupxml->set_text($group->text); $groupxml->paste('last_child', $xml); } } else { my $groupxml = XML::Twig::Elt->new('Group'); $groupxml->paste('last_child', $xml); } $xml->paste('last_child', $rosterxml); } } } $username->paste('last_child', $userxml); $password->paste('last_child', $userxml); $email->paste('last_child', $userxml); $name->paste('last_child', $userxml); $ctime->paste('last_child', $userxml); $mtime->paste('last_child', $userxml); $rosterxml->paste('last_child', $userxml); $userxml->paste('last_child', $output); } print '', "\n\n"; $output->print; __END__ Sample input schema: mypassword user mypassword jabberim:prefs hex-string 0 hash-string Friends Replaced by new connection Sample output schema: user mypassword user@input-server full name 1125442154664 1125442154664 Friends