[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * Implementation of the Quota API for IMAP servers with a unix quota command. 4 * This requires a modified "quota" command that allows the httpd server 5 * account to get quotas for other users. It also requires that your 6 * web server and imap server be the same server or at least have shared 7 * authentication and file servers (e.g. via NIS/NFS). And last, it (as 8 * written) requires the POSIX PHP extensions. 9 * 10 * You must configure this driver in horde/imp/config/servers.php. The 11 * driver supports the following parameters: 12 * 'quota_path' => Path to the quota binary - REQUIRED 13 * 'grep_path' => Path to the grep binary - REQUIRED 14 * 'partition' => If all user mailboxes are on a single partition, the 15 * partition label. By default, quota will determine 16 * quota information using the user's home directory value. 17 * 18 * $Horde: imp/lib/Quota/command.php,v 1.11.10.13 2007/01/02 13:55:02 jan Exp $ 19 * 20 * Copyright 2002-2007 Eric Jon Rostetter <eric.rostetter@physics.utexas.edu> 21 * 22 * See the enclosed file COPYING for license information (GPL). If you 23 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 24 * 25 * @author Eric Rostetter <eric.rostetter@physics.utexas.edu> 26 * @package IMP_Quota 27 */ 28 class IMP_Quota_command extends IMP_Quota { 29 30 /** 31 * Constructor 32 * 33 * @param array $params Hash containing connection parameters. 34 */ 35 function IMP_Quota_command($params = array()) 36 { 37 $this->_params = array( 38 'quota_path' => 'quota', 39 'grep_path' => 'grep', 40 'partition' => null 41 ); 42 43 $this->_params = array_merge($this->_params, $params); 44 } 45 46 /** 47 * Get the disk block size, if possible. 48 * 49 * We try to find out the disk block size from stat(). If not 50 * available, stat() should return -1 for this value, in which 51 * case we default to 1024 (for historical reasons). There are a 52 * large number of reasons this may fail, such as OS support, 53 * SELinux interference, the file being > 2 GB in size, the file 54 * we're referring to not being readable, etc. 55 */ 56 function blockSize() 57 { 58 $results = stat(__FILE__); 59 if ($results['blksize'] > 1) { 60 $blocksize = $results['blksize']; 61 } else { 62 $blocksize = 1024; 63 } 64 return $blocksize; 65 } 66 67 /** 68 * Get quota information (used/allocated), in bytes. 69 * 70 * @return mixed An associative array. 71 * 'limit' = Maximum quota allowed 72 * 'usage' = Currently used portion of quota (in bytes) 73 * Returns PEAR_Error on failure. 74 */ 75 function getQuota() 76 { 77 $imap_user = $_SESSION['imp']['user']; 78 if (empty($this->_params['partition'])) { 79 $passwd_array = posix_getpwnam($imap_user); 80 list($junk, $search_string, $junk) = explode('/', $passwd_array['dir']); 81 } else { 82 $search_string = $this->_params['partition']; 83 } 84 $cmdline = $this->_params['quota_path'] . ' -u ' . $imap_user . ' | ' . 85 $this->_params['grep_path'] . ' ' . $search_string; 86 exec($cmdline, $quota_data, $return_code); 87 if (($return_code == 0) && (count($quota_data) == 1)) { 88 $quota = split("[[:blank:]]+", trim($quota_data[0])); 89 $blocksize = $this->blockSize(); 90 return array('usage' => $quota[1] * $blocksize, 91 'limit' => $quota[2] * $blocksize); 92 } 93 return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error'); 94 } 95 96 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:30:07 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |