-
Notifications
You must be signed in to change notification settings - Fork 127
/
Vfs.php
133 lines (123 loc) · 4.19 KB
/
Vfs.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Copyright 2003-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @author Brent J. Nordquist <bjn@horde.org>
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/
/**
* Ingo_Transport_Vfs implements an Ingo transport driver using Horde VFS.
*
* @author Brent J. Nordquist <bjn@horde.org>
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/
class Ingo_Transport_Vfs extends Ingo_Transport_Base
{
/**
* Constructs a new VFS-based storage driver.
*
* @param array $params A hash containing driver parameters.
*/
public function __construct(array $params = array())
{
$default_params = array(
'hostspec' => 'localhost',
'port' => 21,
'filename' => '.ingo_filter',
'vfstype' => 'ftp',
'vfs_path' => '',
'vfs_forward_path' => '',
);
$this->_supportShares = true;
parent::__construct(array_merge($default_params, $params));
}
/**
* Sets a script running on the backend.
*
* @param array $script The filter script information. Passed elements:
* - 'name': (string) the script name.
* - 'recipes': (array) the filter recipe objects.
* - 'script': (string) the filter script.
*
* @throws Ingo_Exception
*/
public function setScriptActive($script)
{
$this->_connect();
try {
if (!empty($script['script'])) {
$this->_vfs->writeData($this->_params['vfs_path'], $script['name'], $script['script'], true);
} elseif ($this->_vfs->exists($this->_params['vfs_path'], $script['name'])) {
$this->_vfs->deleteFile($this->_params['vfs_path'], $script['name']);
}
} catch (Horde_Vfs_Exception $e) {
throw new Ingo_Exception($e);
}
if (isset($this->_params['file_perms'])) {
try {
if (!empty($script['script'])) {
$this->_vfs->changePermissions($this->_params['vfs_path'], $script['name'], $this->_params['file_perms']);
}
} catch (Horde_Vfs_Exception $e) {
throw new Ingo_Exception($e);
}
}
}
/**
* Returns the content of the currently active script.
*
* @return array The complete ruleset of the specified user.
* @throws Ingo_Exception
* @throws Horde_Exception_NotFound
*/
public function getScript()
{
$this->_connect();
try {
if (!$this->_vfs->exists($this->_params['vfs_path'], $this->_params['filename'])) {
throw new Horde_Exception_NotFound();
}
return array(
'name' => $this->_params['filename'],
'script' => $this->_vfs->read($this->_params['vfs_path'], $this->_params['filename'])
);
} catch (Horde_Vfs_Exception $e) {
throw new Ingo_Exception($e);
}
}
/**
* Connect to the VFS server.
*
* @throws Ingo_Exception
*/
protected function _connect()
{
/* Do variable substitution. */
if (!empty($this->_params['vfs_path'])) {
$this->_params['vfs_path'] = str_replace(
array('%u', '%d', '%U', '%u_full'),
array(Ingo::getUser(), Ingo::getDomain(), $this->_params['username'], Ingo::getUser(true)),
$this->_params['vfs_path']);
}
if (!empty($this->_vfs)) {
return;
}
try {
$this->_vfs = $GLOBALS['injector']
->getInstance('Horde_Core_Factory_Vfs')
->create('ingo', array('type' => $this->_params['vfstype'],
'params' => $this->_params));
} catch (Horde_Exception $e) {
throw new Ingo_Exception($e);
}
}
}