Migrate from jabberd2 to Wildfire

Hey,

I’'m going to switch to a new server (hardware) and so thinking about to also change the jabber server software.

A friend commended me wildfire so here I am :).

Is there a script which takes my MySQL Data of jabberd2 and imports it directly to the MySQL Database of wildfire or

creates a Xml which I then can import with the import / export plugin?

Or is there another way, I’'ve not stumbled over yet?

Ciao Ephraim

Hi,

you may want to read http://www.jivesoftware.org/community/thread.jspa?messageID=120452 and send a private message to Jeff.

LG

thx. I send him a pn

ciao Ephraim

Hmm no answer yet … BUT here is a script for everyone how wants to do the same … But I give no warranty for anything !!!

That one who makes use of this, does it on it’‘s own risk. of course isn’'t it

Have tried to indent it here, but does not work , and haven’'t found a Code BB-Tag

Have fun with your wildfire server!

The Script creates a xml file and prompts for download which can be imported by the current import / export plugin.

Just create a file, e.g. wildfire.php, put the code inside this and up it onto your server. Then call it with your favourite browser.

You will be prompted to type in your Jabber Database, your Jabber Database user and its password, and the realm which you want to export from

the jabberd2 database. After this press send and after a minute or so you will be prompted to download a file called export.xml. This file can then directly be uploaded and imported via the wildfire current import / export plugin.

This works for jabberd2 configured with MySQL.

Ciao Ephraim


<?php
function GetVar($name, $default = "") {
     return ( isset($_POST[$name]) ? $_POST[$name] :
               ( isset($_GET[$name]) ? $_GET[$name]  :
                    $default));
}
function MyEntities($string) {
     $string = str_replace("&", "&amp;", $string);
     $string = str_replace("<", "&lt;", $string);
     $string = str_replace(">", "&gt;", $string);
     $string = str_replace("''", "&apos;", $string);
     $string = str_replace("\"", "&quot;", $string);
     return $string;
}
if(GetVar("action") == "export") {
     $realm = GetVar("realm");
     $con = mysql_connect(GetVar("server"), GetVar("user"), GetVar("pw"));
     if($con) {
          mysql_select_db(GetVar("db"));
          $query = "SELECT ar.username as username, ar.realm as realm, ar.password as pw, ri.jid as jid, ";
          $query .= "ri.name as contact, ri.to as sub, ri.from as recv, ri.ask as ask, rg.group as groupname ";
          $query .= "FROM `authreg` as ar ";
          $query .= "JOIN `roster-items` as ri on CONCAT(ar.username, ''@'', ar.realm) = ri.`collection-owner` ";
          $query .= "LEFT OUTER JOIN `roster-groups` as rg on ri.`collection-owner` = rg.`collection-owner` AND ri.jid = rg.jid ";
          $query .= "WHERE ar.realm = ''$realm'' ";
          $query .= "ORDER BY ar.username";
          $result = mysql_query($query, $con);
          if($result) {
               $content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<Wildfire>\n";
               $lastUser = "";
               while($row = mysql_fetch_object($result)) {
                    if($row->username != $lastUser) {
                         if($lastUser != "") {
                              $content .= "\t\t</Roster>\n";
                              $content .= "\t</User>\n";
                         }
                         $lastUser = $row->username;
                         $content .= "\t<User>\n";
                         $content .= "\t\t<Username>$lastUser</Username>\n";
                         $content .= "\t\t<Password>".MyEntities($row->pw)."</Password>\n";
                         $content .= "\t\t<Email></Email>\n";
                         $content .= "\t\t<Name></Name>\n";
                         $content .= "\t\t<CreationDate>".time()."</CreationDate>\n";
                         $content .= "\t\t<ModifiedDate>".time()."</ModifiedDate>\n";
                         $content .= "\t\t<Roster>\n";
                    }
                    $content .= "\t\t\t<Item jid=\"".$row->jid."\" askstatus=\"".($row->ask == 0 ? -1 : 0)."\" recvstatus=\"".($row->recv == 0 ? 1 : -1)."\" substatus=\"".($row->sub == 1 ? 3 : 0)."\" name=\"".MyEntities($row->contact)."\">\n";
                    if($row->groupname != "")
                         $content .= "\t\t\t\t<Group>".MyEntities($row->groupname)."</Group>\n";
                    else
                         $content .= "\t\t\t\t<Group></Group>\n";
                    $content .= "\t\t\t</Item>\n";
               }                if($lastUser != "") {
                    $content .= "\t\t</Roster>\n";
                    $content .= "\t</User>\n";
               }
               $content .= "</Wildfire>\n";
                    header(''Content-type: application/force-download'');
                    header(''Content-Transfer-Encoding: Binary'');
                    header(''Content-length: ''.strlen($content)*2);
                    header(''Content-disposition: attachment; filename=export.xml'');
               echo utf8_encode($content);
          }
          else {
               echo "Nothing found with realm $realm.<br/>MySQL reported this error:<br/>".mysql_error($con);
          }
     }
}else {?>
<form method="post" action="">
Jabber Domain (jabber.example.org, the realm): <input name="realm"/><br/>
MySQL Server Host: <input name="server" value="localhost"/><br/>
MySQL Server Db: <input name="db" value="jabberd2"/><br/>
MySQL Server User: <input name="user" value="jabberd2"/><br/>
MySQL Server Password: <input type="password" name="pw" value=""/><br/>
<input type="submit" name="action" value="export"/>
</form>
<?
}
?>

Message was edited by: Ephraim

null

Message was edited by: Ephraim

I am new to php and wildfire so please bare with me.

When trying to use the script I ame getting errors of .

PHP Parse error: syntax error, unexpected T_VARIABLE, expecting ‘’,’’ or ‘’)’’ in /var/www/html/jabber.php on line 3

Is am unsure as to what needs to be done here can you please help.

Thank you

Didn’'t looked at the script after posting

the $_POST and $_GET stuff needs [ … ] brakets after wards.

so

return ( isset($_POST [ $name ] ) ? $_POST [ $name ] :

( isset($_GET [ $name ] ) ? $_GET [ $name ] :

$default));

Changed my Script Post too !

Cya Ephraim

Message was edited by: Ephraim

Hi,

posting it within …$_POST : may help:

<php>...$_POST[$name] : </php>

LG

Thx … changed it

Ciao Ephraim

I suggest using a “LEFT OUTER JOIN” instead of “JOIN” between ‘‘roster-items’’ and ‘‘roster-groups’’. For me the normal join omitted contacts (and accounts) if a contact has no group (or an account has no grouped contacts).

Like it is now?

Thx.

Ciao Ephraim