Password Migration: Difference between revisions
Line 25: | Line 25: | ||
echo ""; | echo ""; | ||
$mydb = mysql_connect('localhost',$user, $pass) or die (' | $mydb = mysql_connect('localhost',$user, $pass) or die ('Error of connection with server'); | ||
mysql_select_db($base); | mysql_select_db($base); | ||
mysql_query("SET CHARACTER SET utf8"); | mysql_query("SET CHARACTER SET utf8"); | ||
Line 31: | Line 31: | ||
$query = "SELECT username,password,name,maildir,quota,domain FROM ".$tabl; | $query = "SELECT username,password,name,maildir,quota,domain FROM ".$tabl; | ||
$dane = mysql_query($query) or die (' | $dane = mysql_query($query) or die ('Error during query for bazy1'.mysql_error()); | ||
$handle = fopen($file, "w"); | $handle = fopen($file, "w"); |
Revision as of 17:21, 30 July 2009
Migrating Users Password from Postfix Admin
Save this script as something.php, make chmod +x something.php and run. Script will export all email accounts into designated file.
#!/usr/bin/php5 // Postfix.admin to Zimbra import // // Created by Jarosław Czarniak on 26-10-2008 // Trivial bug fixed by Luca G. on 18-01-2009 <?php ///////////////////////////////////////////////////////// $user="mysql_login"; $pass="mysql_pass"; $base="mysql_database"; $tabl="mailbox"; //table $file="exported.sh"; ///////////////////////////////////////////////////////// echo "Usage: as \"zimbra\" user on destination server:\n"; echo "# sh ./exported.sh\n\n"; echo ""; $mydb = mysql_connect('localhost',$user, $pass) or die ('Error of connection with server'); mysql_select_db($base); mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8"); $query = "SELECT username,password,name,maildir,quota,domain FROM ".$tabl; $dane = mysql_query($query) or die ('Error during query for bazy1'.mysql_error()); $handle = fopen($file, "w"); while ($row = mysql_fetch_array($dane, MYSQL_NUM)) { $StringData = "zmprov ca ".$row[0]." dsfs123hsdyfgbsdgfbsd displayName '".$row[2]."'\n"; fwrite($handle, $StringData); $StringData = "zmprov ma ".$row[0]." userPassword '{crypt}".$row[1]."'"."\n"; fwrite($handle, $StringData); } ?>
Migrating User Password from Shadow Password to Zimbra
Basically we will use the hash password from /etc/shadow. Get the hash values in between the first and second colon only. Eg:
user1:$1$MWAOIgPB$skcX.nKYV9JSctTR60uat/:13780:0:99999:7:::
Then run this as user zimbra.
zmprov ma user1@domain userPassword '{crypt}$1$MWAOIgPB$skcX.nKYV9JSctTR60uat/'
A simple batch script to migrate bulk shadow password into zimbra password as below:
#!/usr/bin/perl # Usage: as root # ./shadow2zm.pl /etc/shadow > shadow.zm # as zimbra # zmprov < shadow.zm $domain="my.domain.com"; while(<>) { chomp; my ($uname,$pass) = split(/:/); print qq{zmprov ma $uname\@$domain userPassword '{crypt}$pass'\n}; print qq{\n}; }
Credit to bewley from this forum post
./scalper
In some cases above perl script doesn't work very well. And if user doesn't already exist you will get en error. My script will import and create all users from shadow file (with exception of system accounts).
#!/bin/bash # Shadow to Zimbra import # # Created by Jarosław Czarniak on 26-10-2008 # clear echo "Usage: as \"zimbra\" user on destination server" echo "# zmprov < shadow.file" domain="jarsat.pl" # change to your domain! file="shadow.file" x=0 echo ''>$file for linia in `cat /etc/shadow` do user=`echo $linia|cut -f1 -d":"` pass=`echo $linia|cut -f2 -d":"` if [ "$pass" != "*" ] then if [ "$pass" != "!" ] then echo "zmprov ca $user@$domain temppasswordQAZXSW displayName $user">>$file echo "zmprov ma $user@$domain userPassword '{crypt}$pass'">>$file x=$[x+1] fi fi done echo echo echo "$x accounts exported to \"$PWD/$file\"" sleep 5