########## Password change for Neomail ################################################# ## Author: Mauricio Terrats ## Requirements: Ensim, Linux & Dwmail 4.2.3 as Local server (http://www.dominion-web.com/products/dwmail/) ## Quick Installation: Create /path/to/dwmail/includes/ensim_quota_sync.php, paste the code, chmod to 755, ## add it to CRON (example provided below), modify /path/to/dwmail/includes/class_imap.inc.php and folderpane.inc.php, ## wait till CRON runs the script for the first time or run it manually as *root ######################################################################################## ########## ##### File /path/to/dwmail/includes/ensim_quota_sync.php ##### Don't forget to "chmod 755 ensim_quota_sync.php" (without quotes :P) ########## #!/usr/bin/php -q /dev/null 2>&1 // Issues? uncomment echo's for debug $domains = explode("\n",trim(`sitelookup -a domain`)); if (!is_array($domains)) die("No domains found!"); foreach ($domains as $domain) { $users = array(); $domain_root = "/home/virtual/$domain"; $domain_passwd = $domain_root . "/etc/passwd"; // as this script runs as root it shouldn't bother if (!is_readable($domain_passwd)) continue; $lines = file($domain_passwd); // echo "Getting quotas from $domain ...\n"; if (!is_array($lines)) continue; foreach ($lines as $line) { list($uname,$junk,$uid,$gid,$junk,$junk) = explode(":",$line); // we need to skip system users and any other bogus information if ($uid <= 502 || !$uname || !$gid) continue; // get users quota list($used,$limit) = explode(" ",trim(`quota -u $uid | tail -n 1 | awk '{print $2 ,$3}'`)); // echo "\t$uname ($uid/$gid) QUOTA: ($used KB/$limit KB)\n"; $users[] = array($uid,$uname,$used,$limit); } // create a lock file if (!touch($domain_root."/.dwensim.lck")) die("Unable to create lock file for $domain"); // empty previous file and pull all the data (nasty way) $tmpout = `> $domain_root/dwensim-quotas.txt`; foreach ($users as $uline) $tmpout .= `echo "$uline[0] $uline[1] $uline[2] $uline[3]" >> $domain_root/dwensim-quotas.txt`; if ($tmpout) echo "Warning: $tmpout\n"; // remove lock file unlink($domain_root."/.dwensim.lck"); } echo "DONE!\n"; ?> ########## ##### Add this function at the end of the class /path/to/dwmail/includes/class_imap.inc.php ########## function GetQuotaEnsimLocalLinux() { // this might not work on high security sites // we assume $username and $domain are clean of strange chars ;) list($username,$domain) = explode("@",$_SESSION['sess_u']); // if something is missing return an empty array if (!$username or !$domain) return array("STORAGE" => array("usage"=>0,"limit"=>0)); $cache_quota = "/home/virtual/$domain/dwensim-quotas.txt"; // if we can't read by any reason the file passwd we return an empty array if (!is_readable($cache_quota)) return array("STORAGE" => array("usage"=>0,"limit"=>0)); // walk through the cache file for the user and get its quota list($used,$limit) = explode(" ",trim(`cat $cache_quota | grep " $username " | awk '{print $3, $4}'`)); // we build the array expected and we send it back ;) $quota["STORAGE"] = array("usage" => $used, "limit" => $limit); return $quota; } ########## ##### Take a look at line 179 from /path/to/dwmail/includes/folderpane.inc.php and replace the first for the second ########## //$quota_values = $IMAPConnection->GetQuota(); $quota_values = $IMAPConnection->GetQuotaEnsimLocalLinux(); That's all!