Hi,
I wrote a perl script (my first) to share folders based on a mysql table. I really needed this because I had lots of shared folders on a cyrus server and I combined an altered "lam user.%" to get me a list of users with access to folders and inserted the list into the mysql table. The benefit of the script is that you can append entries to the mysql table and it won't re-attempt to share the already shared folders
First you need to create a database on a mysql server and run this script to create the table:
--
-- Table structure for table `share_access`
--
Code:
CREATE TABLE `share_access` (
`ID` smallint(6) NOT NULL auto_increment,
`User` tinytext collate utf8_unicode_ci NOT NULL COMMENT 'the user that gets access',
`Account` varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'The account that gets shared',
`Folder` varchar(255) collate utf8_unicode_ci default NULL COMMENT 'If just a specific folder is to be shared',
`Sync` tinyint(1) default NULL COMMENT 'Has this already been done?',
`permissions` tinytext collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
Code:
#/usr/bin/perl
use DBI;
#db info
$db="DATABASENAME";
$host="MYSQLHOST";
$userid="MYSQLUSER";
$passwd="MYSQLPASS";
$connectionInfo="dbi:mysql:$db;$host";
$zmmailbox = "/opt/zimbra/bin/zmmailbox";
# make connection to database
$dbh = DBI->connect($connectionInfo,$userid,$passwd);
# prepare and execute query-choose all the users chooses all the unsynced users that don't have the same username and folder to be shared (i.e: no need to share something you already have access too)
$query = "SELECT * FROM share_access where `Sync` = 0 and `User` != `Account`";
$sth = $dbh->prepare($query);
$sth->execute();
$sth->bind_columns(\$ID, \$user, \$account, \$folder, \$sync, \$permissions);
while ($sth->fetch())
{
#couple of options so no password required etc...
print `$zmmailbox -z -v -m $account mfg /$folder account $user $permissions`;
#shared folders have the name shared-NAMEOFFOLDER in the target users folder listing
print `$zmmailbox -z -v -m $user createMountpoint /shared-$account $account /$folder`;
#Mark this entry as done so in future runs it isn't attempted again
$query2 = "UPDATE `share_access` SET `sync` = '1' WHERE `ID` = $ID Limit 1;";
$stk = $dbh->prepare($query2);
$stk->execute();
}
$sth->finish();
$dbh->disconnect;