Overview

Packages

  • Horde
    • Icalendar
      • UnitTests
  • Ingo
    • UnitTests
  • None

Classes

  • Horde_Core_Ui_VarRenderer_Ingo
  • Ingo
  • Ingo_Api
  • Ingo_Exception
  • Ingo_Exception_Pear
  • Ingo_LoginTasks_SystemTask_Upgrade
  • Ingo_Script
  • Ingo_Script_Imap
  • Ingo_Script_Imap_Api
  • Ingo_Script_Imap_Live
  • Ingo_Script_Maildrop
  • Ingo_Script_Maildrop_Comment
  • Ingo_Script_Maildrop_Recipe
  • Ingo_Script_Maildrop_Variable
  • Ingo_Script_Procmail
  • Ingo_Script_Procmail_Comment
  • Ingo_Script_Procmail_Recipe
  • Ingo_Script_Procmail_Variable
  • Ingo_Script_Sieve
  • Ingo_Script_Sieve_Action
  • Ingo_Script_Sieve_Action_Addflag
  • Ingo_Script_Sieve_Action_Discard
  • Ingo_Script_Sieve_Action_Fileinto
  • Ingo_Script_Sieve_Action_Flag
  • Ingo_Script_Sieve_Action_Keep
  • Ingo_Script_Sieve_Action_Notify
  • Ingo_Script_Sieve_Action_Redirect
  • Ingo_Script_Sieve_Action_Reject
  • Ingo_Script_Sieve_Action_Removeflag
  • Ingo_Script_Sieve_Action_Stop
  • Ingo_Script_Sieve_Action_Vacation
  • Ingo_Script_Sieve_Comment
  • Ingo_Script_Sieve_Else
  • Ingo_Script_Sieve_Elsif
  • Ingo_Script_Sieve_If
  • Ingo_Script_Sieve_Test
  • Ingo_Script_Sieve_Test_Address
  • Ingo_Script_Sieve_Test_Allof
  • Ingo_Script_Sieve_Test_Anyof
  • Ingo_Script_Sieve_Test_Body
  • Ingo_Script_Sieve_Test_Exists
  • Ingo_Script_Sieve_Test_False
  • Ingo_Script_Sieve_Test_Header
  • Ingo_Script_Sieve_Test_Not
  • Ingo_Script_Sieve_Test_Relational
  • Ingo_Script_Sieve_Test_Size
  • Ingo_Script_Sieve_Test_True
  • Ingo_Storage
  • Ingo_Storage_Blacklist
  • Ingo_Storage_Filters
  • Ingo_Storage_Filters_Sql
  • Ingo_Storage_Forward
  • Ingo_Storage_Mock
  • Ingo_Storage_Prefs
  • Ingo_Storage_Rule
  • Ingo_Storage_Spam
  • Ingo_Storage_Sql
  • Ingo_Storage_Vacation
  • Ingo_Storage_VacationTest
  • Ingo_Storage_Whitelist
  • Ingo_Test
  • Ingo_Transport
  • Ingo_Transport_Ldap
  • Ingo_Transport_Null
  • Ingo_Transport_Sivtest
  • Ingo_Transport_Timsieved
  • Ingo_Transport_Vfs
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Ingo_Transport_Vfs implements an Ingo storage driver using Horde VFS.
  4:  *
  5:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file LICENSE for license information (ASL).  If you
  8:  * did not receive this file, see http://www.horde.org/licenses/apache.
  9:  *
 10:  * @author  Brent J. Nordquist <bjn@horde.org>
 11:  * @author  Jan Schneider <jan@horde.org>
 12:  * @package Ingo
 13:  */
 14: class Ingo_Transport_Vfs extends Ingo_Transport
 15: {
 16:     /**
 17:      * Constructs a new VFS-based storage driver.
 18:      *
 19:      * @param array $params  A hash containing driver parameters.
 20:      */
 21:     public function __construct($params = array())
 22:     {
 23:         $this->_support_shares = true;
 24: 
 25:         $default_params = array(
 26:             'hostspec' => 'localhost',
 27:             'port'     => 21,
 28:             'filename' => '.ingo_filter',
 29:             'vfstype'  => 'ftp',
 30:             'vfs_path' => '',
 31:             'vfs_forward_path' => '',
 32:         );
 33: 
 34:         parent::__construct(array_merge($default_params, $params));
 35:     }
 36: 
 37:     /**
 38:      * Sets a script running on the backend.
 39:      *
 40:      * @param string $script     The filter script.
 41:      * @param array $additional  Any additional scripts that need to uploaded.
 42:      *
 43:      * @throws Ingo_Exception
 44:      */
 45:     public function setScriptActive($script, $additional = array())
 46:     {
 47:         $this->_connect();
 48: 
 49:         try {
 50:             if (!empty($script)) {
 51:                 $this->_vfs->writeData($this->_params['vfs_path'], $this->_params['filename'], $script, true);
 52:             } elseif ($this->_vfs->exists($this->_params['vfs_path'], $this->_params['filename'])) {
 53:                 $this->_vfs->deleteFile($this->_params['vfs_path'], $this->_params['filename']);
 54:             }
 55:             foreach ($additional as $filename => $content) {
 56:                 if (strlen($content)) {
 57:                     $this->_vfs->writeData($this->_params['vfs_path'], $filename, $content, true);
 58:                 } elseif ($this->_vfs->exists($this->_params['vfs_path'], $filename)) {
 59:                     $this->_vfs->deleteFile($this->_params['vfs_path'], $filename);
 60:                 }
 61:             }
 62:         } catch (Horde_Vfs_Exception $e) {
 63:             throw new Ingo_Exception($e);
 64:         }
 65: 
 66:         if (isset($this->_params['file_perms'])) {
 67:             try {
 68:                 if (!empty($script)) {
 69:                     $this->_vfs->changePermissions($this->_params['vfs_path'], $this->_params['filename'], $this->_params['file_perms']);
 70:                 }
 71:                 foreach ($additional as $filename => $content) {
 72:                     if (strlen($content)) {
 73:                         $this->_vfs->changePermissions($this->_params['vfs_path'], $filename, $this->_params['file_perms']);
 74:                     }
 75:                 }
 76:             } catch (Horde_Vfs_Exception $e) {
 77:                 throw new Ingo_Exception($e);
 78:             }
 79:         }
 80:     }
 81: 
 82:     /**
 83:      * Returns the content of the currently active script.
 84:      *
 85:      * @return string  The complete ruleset of the specified user.
 86:      * @throws Ingo_Exception
 87:      */
 88:     public function getScript()
 89:     {
 90:         $this->_connect();
 91:         try {
 92:             return $this->_vfs->read($this->_params['vfs_path'], $this->_params['filename']);
 93:         } catch (Horde_Vfs_Exception $e) {
 94:             throw new Ingo_Exception($e);
 95:         }
 96:     }
 97: 
 98:     /**
 99:      * Connect to the VFS server.
100:      *
101:      * @throws Ingo_Exception
102:      */
103:     protected function _connect()
104:     {
105:         /* Do variable substitution. */
106:         if (!empty($this->_params['vfs_path'])) {
107:             $user = Ingo::getUser();
108:             $domain = Ingo::getDomain();
109:             if ($GLOBALS['session']->get('ingo', 'backend/hordeauth') !== 'full') {
110:                 $pos = strpos($user, '@');
111:                 if ($pos !== false) {
112:                     $domain = substr($user, $pos + 1);
113:                     $user = substr($user, 0, $pos);
114:                 }
115:             }
116:             $this->_params['vfs_path'] = str_replace(
117:                 array('%u', '%d', '%U'),
118:                 array($user, $domain, $this->_params['username']),
119:                 $this->_params['vfs_path']);
120:         }
121: 
122:         if (!empty($this->_vfs)) {
123:             return true;
124:         }
125: 
126:         try {
127:             $this->_vfs = $GLOBALS['injector']
128:                 ->getInstance('Horde_Core_Factory_Vfs')
129:                 ->create('ingo', array('type'   => $this->_params['vfstype'],
130:                                        'params' => $this->_params));
131:         } catch (Horde_Exception $e) {
132:             throw new Ingo_Exception($e);
133:         }
134:     }
135: }
136: 
API documentation generated by ApiGen