File: vfs.php

package info (click to toggle)
ingo1 1.0.1-1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,368 kB
  • ctags: 921
  • sloc: php: 4,030; xml: 1,182; makefile: 63
file content (85 lines) | stat: -rw-r--r-- 2,675 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
 * Ingo_Driver_vfs:: Implements an Ingo storage driver using Horde VFS.
 *
 * Copyright 2003-2005 Brent J. Nordquist <bjn@horde.org>
 *
 * See the enclosed file LICENSE for license information. If you
 * did not receive this file, see http://www.horde.org/licenses.
 *
 * $Horde: ingo/lib/Driver/vfs.php,v 1.12.10.1 2005/01/03 12:25:38 jan Exp $
 *
 * @author  Brent J. Nordquist <bjn@horde.org>
 * @version $Revision: 1.12.10.1 $
 * @since   Ingo 0.1
 * @package Ingo
 */
class Ingo_Driver_vfs extends Ingo_Driver {

    /**
     * Constructs a new VFS-based storage driver.
     *
     * @access public
     *
     * @param array $params  A hash containing driver parameters.
     */
    function Ingo_Driver_vfs($params = array())
    {
        $default_params = array(
            'hostspec'    =>  'localhost',
            'port'        =>  21,
            'procmailrc'  =>  '.procmailrc',
            'vfstype'     =>  'ftp'
        );
        $this->_params = array_merge($default_params, $params);
    }

    /**
     * Sets a script running on the backend.
     *
     * @param string $script  The filter script
     *
     * @return mixed  True on success, or PEAR_Error on failure.
     */
    function setScriptActive($script, $username, $password)
    {
        if ($this->_params['vfstype'] != 'ftp') {
            return PEAR::raiseError(_(sprintf("VFS type '%s' not yet implemented.", $this->_params['vfstype'])));
        }
        $this->_params['username'] = $username;
        $this->_params['password'] = $password;

        require_once 'VFS.php';
        $vfs = &VFS::singleton($this->_params['vfstype'], $this->_params);
        $res = $vfs->writeData('', $this->_params['procmailrc'], $script);
        $vfs->_disconnect();
        if (is_a($res, 'PEAR_Error')) {
            return $res;
        }
        return true;
    }

    /**
     * Returns the content of the currently active script.
     *
     * @param string $username  The backend username.
     * @param string $password  The backend password.
     *
     * @return string  The complete ruleset of the specified user.
     */
    function getScript($username, $password)
    {
        if ($this->_params['vfstype'] != 'ftp') {
            return PEAR::raiseError(_(sprintf("VFS type '%s' not yet implemented.", $this->_params['vfstype'])));
        }
        $this->_params['username'] = $username;
        $this->_params['password'] = $password;

        require_once 'VFS.php';
        $vfs = &VFS::singleton($this->_params['vfstype'], $this->_params);
        $res = $vfs->read('', $this->_params['procmailrc']);
        $vfs->_disconnect();
        return $res;
    }

}