ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
File.php
Go to the documentation of this file.
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
31require_once "File/Passwd.php";
35require_once "Auth/Container.php";
39require_once "PEAR.php";
40
59{
60
61 // {{{ properties
62
68 var $pwfile = '';
69
75 var $options = array();
76
77 // }}}
78 // {{{ Auth_Container_File() [constructor]
79
87 $this->_setDefaults();
88
89 // Only file is a valid option here
90 if(is_array($filename)) {
91 $this->pwfile = $filename['file'];
93 } else {
94 $this->pwfile = $filename;
95 }
96 }
97
98 // }}}
99 // {{{ fetchData()
100
108 function fetchData($user, $pass)
109 {
110 $this->log('Auth_Container_File::fetchData() called.', AUTH_LOG_DEBUG);
111 return File_Passwd::staticAuth($this->options['type'], $this->pwfile, $user, $pass);
112 }
113
114 // }}}
115 // {{{ listUsers()
116
122 function listUsers()
123 {
124 $this->log('Auth_Container_File::listUsers() called.', AUTH_LOG_DEBUG);
125
126 $pw_obj = &$this->_load();
127 if (PEAR::isError($pw_obj)) {
128 return array();
129 }
130
131 $users = $pw_obj->listUser();
132 if (!is_array($users)) {
133 return array();
134 }
135
136 foreach ($users as $key => $value) {
137 $retVal[] = array("username" => $key,
138 "password" => $value['passwd'],
139 "cvsuser" => $value['system']);
140 }
141
142 $this->log('Found '.count($retVal).' users.', AUTH_LOG_DEBUG);
143
144 return $retVal;
145 }
146
147 // }}}
148 // {{{ addUser()
149
159 function addUser($user, $pass, $additional='')
160 {
161 $this->log('Auth_Container_File::addUser() called.', AUTH_LOG_DEBUG);
162 $params = array($user, $pass);
163 if (is_array($additional)) {
164 foreach ($additional as $item) {
165 $params[] = $item;
166 }
167 } else {
169 }
170
171 $pw_obj = &$this->_load();
172 if (PEAR::isError($pw_obj)) {
173 return false;
174 }
175
176 $res = call_user_func_array(array(&$pw_obj, 'addUser'), $params);
177 if (PEAR::isError($res)) {
178 return false;
179 }
180
181 $res = $pw_obj->save();
182 if (PEAR::isError($res)) {
183 return false;
184 }
185
186 return true;
187 }
188
189 // }}}
190 // {{{ removeUser()
191
198 function removeUser($user)
199 {
200 $this->log('Auth_Container_File::removeUser() called.', AUTH_LOG_DEBUG);
201 $pw_obj = &$this->_load();
202 if (PEAR::isError($pw_obj)) {
203 return false;
204 }
205
206 $res = $pw_obj->delUser($user);
207 if (PEAR::isError($res)) {
208 return false;
209 }
210
211 $res = $pw_obj->save();
212 if (PEAR::isError($res)) {
213 return false;
214 }
215
216 return true;
217 }
218
219 // }}}
220 // {{{ changePassword()
221
228 function changePassword($username, $password)
229 {
230 $this->log('Auth_Container_File::changePassword() called.', AUTH_LOG_DEBUG);
231 $pw_obj = &$this->_load();
232 if (PEAR::isError($pw_obj)) {
233 return false;
234 }
235
236 $res = $pw_obj->changePasswd($username, $password);
237 if (PEAR::isError($res)) {
238 return false;
239 }
240
241 $res = $pw_obj->save();
242 if (PEAR::isError($res)) {
243 return false;
244 }
245
246 return true;
247 }
248
249 // }}}
250 // {{{ _load()
251
257 function &_load()
258 {
259 static $pw_obj;
260
261 if (!isset($pw_obj)) {
262 $this->log('Instanciating File_Password object of type '.$this->options['type'], AUTH_LOG_DEBUG);
263 $pw_obj = File_Passwd::factory($this->options['type']);
264 if (PEAR::isError($pw_obj)) {
265 return $pw_obj;
266 }
267
268 $pw_obj->setFile($this->pwfile);
269
270 $res = $pw_obj->load();
271 if (PEAR::isError($res)) {
272 return $res;
273 }
274 }
275
276 return $pw_obj;
277 }
278
279 // }}}
280 // {{{ _setDefaults()
281
288 function _setDefaults()
289 {
290 $this->options['type'] = 'Cvs';
291 }
292
293 // }}}
294 // {{{ _parseOptions()
295
302 function _parseOptions($array)
303 {
304 foreach ($array as $key => $value) {
305 if (isset($this->options[$key])) {
306 $this->options[$key] = $value;
307 }
308 }
309 }
310
311 // }}}
312
313}
314?>
const AUTH_LOG_DEBUG
Auth Log level - DEBUG.
Definition: Auth.php:59
$filename
Definition: buildRTE.php:89
Auth_Container_File($filename)
Constructor of the container class.
Definition: File.php:86
_setDefaults()
Set some default options.
Definition: File.php:288
changePassword($username, $password)
Change password for user in the storage container.
Definition: File.php:228
_parseOptions($array)
Parse options passed to the container class.
Definition: File.php:302
addUser($user, $pass, $additional='')
Add a new user to the storage container.
Definition: File.php:159
removeUser($user)
Remove user from the storage container.
Definition: File.php:198
fetchData($user, $pass)
Authenticate an user.
Definition: File.php:108
& _load()
Load and initialize the File_Passwd object.
Definition: File.php:257
listUsers()
List all available users.
Definition: File.php:122
log($message, $level=AUTH_LOG_DEBUG)
Log a message to the Auth log.
Definition: Container.php:246
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
$params
Definition: example_049.php:96
$additional
Definition: goto.php:89