Squirrelmail Global Address Book
Back
From: http://www.mail-archive.com/qmailtoaster-list@qmailtoaster.com/msg14851.html
Below are my way to provide Squirrelmail Global Address Book for my users.
1. create sqweb_gabook.sh and sqweb_gabook.php in one folder
2. chmod +x sqweb_gabook.sh
3. edit parameters on both files
4. run sqweb_gabook.sh for first time
5. edit squirrelmail config to load your newly created global address book. More info: http://www.squirrelmail.org/docs/admin/admin-7.html#ss7.5
6. to provide latest global address book in your Webmail you may want run this script daily or weekly via crontab
This scripts are far more than perfect but atleast it does it job to provide me a global address book for my company domain.
#!/bin/bash # sqweb_gabook.sh # squirrelmail global address book updater # # PakOgah <pakogah@pala.bo-tak.info> # ver 0.1 (2 Aug 2007) # - initial script # ver 0.3 (3 Aug 2007) # - add full path and test if php script exist # - add detail documentation # # need more enhancements # - use 2 script to create one global address book, if it were only 1 script it would be simpler # - these scripts only can generate one global address book for one domain # - and thus 1 global address book is configured with your Squirrelmail # so if your webmail support multidomain, the global address book didn't # - can't update dynamicly if there are changes in email account and/or milist # you have run it again via cron (weekly/daily) # - user which his email address listed can't update his info # (I am setup my squirrelmail with policy no one can change global address book)
# variables section edited here # your domain DOMAIN="pala.bo-tak.info" # where this bash and php script reside SCRIPT_LOC="/root/scripts" MILISDIR="/home/vpopmail/domains/$DOMAIN" FILENAME=$DOMAIN"_gabook" GLOBAL_ABOOK="/var/lib/squirrelmail/$FILENAME"
#=========================== # process here #=========================== echo "#Squirrelmail global address book updater..." rm -f $GLOBAL_ABOOK touch $GLOBAL_ABOOK
# export email address # make sure sqweb_gabook.php is in same folder # there are some variable inside it please change them to suit your need if [ -e $SCRIPT_LOC/sqweb_gabook.php ]; then php $SCRIPT_LOC/sqweb_gabook.php fi
# export milist CWD=`pwd` cd $MILISDIR for milisname in $(ls -1); do if [ -e $milisname/config ]; then echo "$milisname|$milisname|MailingList|[EMAIL PROTECTED]|" >> $GLOBAL_ABOOK fi done
cd $CWD echo "Global Address for $DOMAIN is available at "$GLOBAL_ABOOK echo "Enter the fullpath using Squirrelmail config utility" echo "select 6. Address Books option and configure address book in 3. Global file address book" echo "More info: http://www.squirrelmail.org/docs/admin/admin-7.html#ss7.5";
<?php /* # sqweb_gabook.php # squirrelmail global address book updater # this file is needed by sqweb-gabook.sh # # PakOgah <pakogah@pala.bo-tak.info> # ver 0.1 (2 Aug 2007) # - initial script # ver 0.3 (3 Aug 2007) # - add full path and test if php script exist # - add detail documentation # # need more enhancements # - use 2 script to create one global address book, if it were only 1 script it would be simpler # - these scripts only can generate one global address book for one domain # - and thus 1 global address book is configured with your Squirrelmail # so if your webmail support multidomain, the global address book didn't # - can't update dynamicly if there are changes in email account and/or milist # you have run it again via cron (weekly/daily) # - user which his email address listed can't update his info # (I am setup my squirrelmail with policy no one can change global address book) */ // configuration // your domain name $domainname="pala.bo-tak.info"; // your domain table name inside vpopmail database $tablename="pala_bo_tak_info"; $username="vpopmail"; $password="SsEeCcRrEeTt"; $database="vpopmail"; $hostname="localhost"; $filename=$domainname."_gabook"; $global_abook="/var/lib/squirrelmail/".$filename;
// process $handle = fopen($global_abook, 'a'); $conn = mysql_connect($hostname, $username, $password) or die ('Error connecting to mysql'); mysql_select_db($database);
$query="select pw_name,pw_gecos from $tablename"; $result = mysql_query($query);
while(list($email,$name)= mysql_fetch_row($result)) { $data=$email."|".$name."||".$email."@".$domainname."|\n"; fwrite($handle, $data); } mysql_close($conn); fclose($handle); ?>