示例#1
0
 /**
  * Returns the user's quota for servers with a unix quota command.
  *
  * This may require a modified "quota" command that allows the httpd
  * server account to get quotas for other users...  It requires that your
  * web server and user server be the same server or at least have shared
  * authentication and file servers (e.g. via NIS/NFS).  And last, it (as
  * written) requires the posix php extensions.
  *
  * If your quota command wraps the output onto two lines, then this module
  * will only work if you have a grep which supports the -A switch, and you
  * append an -A1 switch to your grep_path (e.g. '/bin/grep -A1').
  *
  * @return array  A quota array, elements are used bytes and limit bytes.
  *
  * @throws Horde_Exception if posix extension is missing.
  */
 public function getQuota()
 {
     $information = $this->_getAccount();
     $homedir = $information['dir'];
     // If we want mount point translations, then translate the login dir
     // name to a mount point.  If not, then simply parse out the device
     // name from the login directory, and use that instead.
     if ($this->_params['translateMountPoint'] && file_exists($this->_params['translationTable'])) {
         $sysTab = File_Fstab::singleton($this->_params['translationTable']);
         do {
             $entry = $sysTab->getEntryForPath($homedir);
             $homedir = dirname($homedir);
             if ($homedir == '.' || empty($homedir)) {
                 $homedir = '/';
             }
         } while (is_a($entry, 'PEAR_Error'));
         $mountPoint = $entry->device;
     } else {
         $homedir = explode('/', $homedir);
         $mountPoint = '/' . $homedir[1];
     }
     $cmdline = sprintf('%s -u %s 2>&1 | %s %s', $this->_params['quota_path'], $this->getUserName(), $this->_params['grep_path'], $mountPoint);
     exec($cmdline, $quota_data, $return_code);
     if ($return_code == 0 && !empty($quota_data[0])) {
         // In case of quota output wrapping on two lines, we concat the
         // second line of results, if any, here.
         if (!empty($quota_data[1])) {
             $quota_data[0] .= $quota_data[1];
         }
         // Now parse out the quota info and return it.
         $quota = preg_split('/\\s+/', trim($quota_data[0]));
         return array('used' => $quota[1] * 1024, 'limit' => $quota[2] * 1024);
     }
     return array();
 }
示例#2
0
 /**
  * Constructor
  *
  * @param $options array Class options
  * @see File_Fstab::setOptions()
  * @return void
  */
 function System_Mount($options = false)
 {
     $pc = get_parent_class($this);
     // This is a bit ugly.
     if (!$options) {
         $options = array();
     }
     $opts = array_merge($this->_defaultMountOptions, $options);
     // Get a static mtab instance
     $mtab =& PEAR::getStaticProperty('System_Mount', 'mtab');
     $mtab = File_Fstab::singleton($opts['mtabFile']);
     parent::$pc($opts);
     // Make sure the entryClass knows how to mount/unmount
     $options =& PEAR::getStaticProperty('System_Mount', 'options');
     $options = $this->options;
 }
示例#3
0
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @category  File Formats
 * @package   File_Fstab
 * @author    Ian Eure <*****@*****.**>
 * @copyright 2004, 2005 Ian Eure
 * @license   http://www.php.net/license/3_0.txt  PHP License 3.0
 * @version   CVS: $Revision$
 * @version   Release: @version@
 * @link      http://pear.php.net/package/File_Fstab
 */
require_once 'File/Fstab.php';
// Get an instance for the system's fstab.
$sysTab = File_Fstab::singleton('/etc/fstab');
// Get the entry for the root partition.
$rootEnt =& $sysTab->getEntryForPath('/');
// See how error handling is set.
if ($rootEnt->hasMountOption('errors')) {
    print "Error handling for / is: " . $rootEnt->mountOptions['errors'] . "\n";
} else {
    print "Error handling for / is undefined.\n";
}
// Change fstype for /
print "Chanking fstype for " . $rootEnt->getDeviceUUIDOrLabel() . " (mounted on " . $rootEnt->getMountPoint() . ") to reiserfs\n";
$rootEnt->fsType = 'reiserfs';
// Create a new entry.
print "Adding entry for CD-ROM\n";
$ent = new File_Fstab_Entry();
$ent->device = '/dev/cdrom';