Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Appmng/Class.User.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Users Definition
9  *
10  * @author Anakeen 2000
11  * @version $Id: Class.User.php,v 1.65 2008/08/11 14:14:14 marc Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage CORE
15  */
16 /**
17  */
18 
19 include_once ('Class.DbObj.php');
20 include_once ('Class.QueryDb.php');
21 include_once ('Class.Log.php');
22 include_once ('Class.Application.php');
23 include_once ('Class.Group.php');
24 
25 require_once 'PEAR.php';
26 require_once 'Crypt/CHAP.php';
27 
28 define("GALL_ID", 2);
29 define("ANONYMOUS_ID", 3);
30 define("GADMIN_ID", 4);
31 
32 class User extends DbObj
33 {
34  var $fields = array(
35  "id",
36  "iddomain",
37  "lastname",
38  "firstname",
39  "login",
40  "password",
41  "isgroup",
42  "expires",
43  "passdelay",
44  "status",
45  "mail",
46  "ntpasswordhash",
47  "lmpasswordhash",
48  "fid"
49  );
50 
51  var $id_fields = array(
52  "id"
53  );
54 
55  var $dbtable = "users";
56 
57  var $order_by = "lastname, isgroup desc";
58 
59  var $fulltextfields = array(
60  "login",
61  "lastname",
62  "firstname"
63  );
64 
65  var $sqlcreate = "
66 create table users ( id int not null,
67  iddomain int not null,
68  primary key (id),
69  lastname text,
70  firstname text,
71  login text not null,
72  password varchar(30) not null,
73  isgroup char,
74  expires int,
75  passdelay int,
76  status char,
77  mail text,
78  ntpasswordhash text,
79  lmpasswordhash text,
80  fid int);
81 create index users_idx2 on users(lastname);
82 create index users_idx3 on users(login);
83 CREATE UNIQUE INDEX uni_users on users (login,iddomain);
84 create sequence seq_id_users start 10";
85  /**
86  * affect user from login name
87  * @param string $loginDomain login
88  * @return boolean true if ok
89  */
90  function SetLoginName($loginDomain)
91  {
92  include_once ("Class.Domain.php");
93  $loginDomain = trim(mb_strtolower($loginDomain));
94  $query = new QueryDb($this->dbaccess, "User");
95  $query->AddQuery("login='" . pg_escape_string($loginDomain) . "'");
96  $query->order_by = 'iddomain';
97  $list = $query->Query(0, 0, "TABLE");
98  if ($query->nb > 0) {
99  $this->Affect($list[0]);
100  } else {
101  if (preg_match("/(.*)@(.*)/", $loginDomain, $reg)) {
102 
103  $queryd = new QueryDb($this->dbaccess, "Domain");
104  $queryd->AddQuery("name='" . $reg[2] . "'");
105  $list = $queryd->Query();
106 
107  if ($queryd->nb == 1) {
108  $domainId = $list[0]->iddomain;
109  $query->AddQuery("iddomain='$domainId'");
110  $query->AddQuery("login='" . pg_escape_string($reg[1]) . "'");
111  } else {
112  return false;
113  }
114  }
115  return FALSE;
116  }
117 
118  return TRUE;
119  }
120  /**
121  * affect user from its login
122  *
123  * @param string $login login
124  * @deprecated
125  * @return boolean true if ok
126  */
127  function setLogin($login, $domain)
128  {
129  $login = mb_strtolower($login);
130  $domain = mb_strtolower($domain);
131  $query = new QueryDb($this->dbaccess, "User");
132 
133  $query->basic_elem->sup_where = array(
134  "login='" . pg_escape_string($login) . "'",
135  "iddomain=$domain"
136  );
137 
138  $list = $query->Query(0, 0, "TABLE");
139 
140  if ($query->nb != 0) {
141  $this->Affect($list[0]);
142  } else {
143  return FALSE;
144  }
145 
146  return TRUE;
147  }
148  /**
149  * affect user from its document id
150  *
151  * @param int $fid
152  * @return boolean true if ok
153  */
154  function setFid($fid)
155  {
156  $query = new QueryDb($this->dbaccess, "User");
157  $query->AddQuery(sprintf("fid = %d", $fid));
158  $list = $query->Query(0, 0, "TABLE");
159  if ($query->nb != 0) {
160  $this->Affect($list[0]);
161  } else {
162  return false;
163  }
164  return true;
165  }
166 
167  function PreInsert()
168  {
169  if ($this->Setlogin($this->login, $this->iddomain)) return "this login exists";
170  if ($this->login == "") return _("login must not be empty");
171  if ($this->id == "") {
172  $res = pg_exec($this->dbid, "select nextval ('seq_id_users')");
173  $arr = pg_fetch_array($res, 0);
174  $this->id = $arr["nextval"];
175  }
176 
177  if (isset($this->isgroup) && ($this->isgroup == "Y")) {
178  $this->password_new = "no"; // no passwd for group
179 
180  } else {
181  $this->isgroup = "N";
182  }
183 
184  $this->login = mb_strtolower($this->login);
185 
186  if (isset($this->password_new) && ($this->password_new != "")) {
187  $this->computepass($this->password_new, $this->password);
188  if ($this->id == 1) {
189  $this->setAdminHtpasswd($this->password_new);
190  }
191  }
192  //expires and passdelay
193  $this->GetExpires();
194  }
195 
196  function PostInsert()
197  {
198  //Add default group to user
199  $group = new group($this->dbaccess);
200  $group->iduser = $this->id;
201  $gid = 2; //2 = default group
202  if ($this->iddomain > 1) {
203  $qu = new QueryDb($this->dbaccess, "User");
204  $qu->AddQuery("login='all'");
205  $qu->AddQuery("iddomain=" . $this->iddomain);
206  $qu->AddQuery("id !=" . $this->id);
207  $lu = $qu->Query(0, 0, "TABLE");
208  if ($lu) {
209  $gid = $lu[0]["id"];
210  }
211  }
212 
213  $group->idgroup = $gid;
214  // not added here it is added by freedom (generally)
215  // if (! $this->fid) $group->Add();
216  $err = $this->FreedomWhatUser();
217 
218  return $err;
219  }
220 
221  function PostUpdate()
222  {
223  return $this->FreedomWhatUser();
224  }
225 
226  function PreUpdate()
227  {
228  if (isset($this->password_new) && ($this->password_new != "")) {
229  if (function_exists("mhash")) {
230  $this->cryptEngine = new Crypt_CHAP_MSv1;
231  $this->ntpasswordhash = strtoupper(bin2hex($this->cryptEngine->ntPasswordHash($this->password_new)));
232  $this->lmpasswordhash = strtoupper(bin2hex($this->cryptEngine->lmPasswordHash($this->password_new)));
233  }
234  $this->computepass($this->password_new, $this->password);
235  if ($this->id == 1) {
236  $this->setAdminHtpasswd($this->password_new);
237  }
238  }
239  //expires and passdelay
240  $this->GetExpires();
241  }
242 
243  function PostDelete()
244  {
245 
246  include_once ("WHAT/Class.Session.php");
247  // delete reference in group table
248  $group = new Group($this->dbaccess, $this->id);
249  $ugroups = $group->groups;
250  $err = $group->Delete();
251  if ($err == "") {
252  if (usefreedomuser()) {
253  refreshGroups($ugroups, true);
254  }
255  }
256 
257  global $action;
258  $action->session->CloseUsers($this->id);
259 
260  return $msg;
261  }
262 
263  function CheckLogin($login, $domain, $whatid)
264  {
265  $query = new QueryDb($this->dbaccess, "User");
266 
267  $query->basic_elem->sup_where = array(
268  "login='" . pg_escape_string($login) . "'",
269  "iddomain=$domain"
270  );
271 
272  $list = $query->Query();
273  if ($query->nb == 0 or ($query->nb == 1 and $list[0]->id == $whatid)) {
274  return true;
275  } else {
276  return false;
277  }
278  }
279  /**
280  * return display name of a user
281  * @param int $uid user identificator
282  * @return string firstname and lastname
283  */
284  static function getDisplayName($uid)
285  {
286  static $tdn = array();
287 
288  $uid = intval($uid);
289  if ($uid > 0) {
290  if (isset($tdn[$uid])) return $tdn[$uid];
291  $dbid = getDbId(getDbAccess());
292  $res = pg_exec($dbid, "select firstname, lastname from users where id=$uid");
293  if (pg_num_rows($res) > 0) {
294  $arr = pg_fetch_array($res, 0);
295  if ($arr["firstname"]) $tdn[$uid] = $arr["firstname"] . ' ' . $arr["lastname"];
296  else $tdn[$uid] = $arr["lastname"];
297  return $tdn[$uid];
298  }
299  return false;
300  }
301  }
302  /**
303  * update user from IUSER document
304  * @param int $fid document id
305  * @param string $login login
306  * @param int $iddomain mail domain identificator
307  */
308  function SetUsers($fid, $lname, $fname, $expires, $passdelay, $login, $status, $pwd1, $pwd2, $iddomain, $extmail)
309  {
310 
311  $this->lastname = $lname;
312  $this->firstname = $fname;
313  $this->status = $status;
314  if ($this->login == "") $this->login = $login;
315  //don't modify password in database even if force constraint
316  if ($pwd1 == $pwd2 and $pwd1 <> "") {
317  $this->password_new = $pwd2;
318  }
319  if (($iddomain > 1) && ($this->iddomain != $iddomain) && ($this->iddomain < 2)) $needmail = true;
320  else $needmail = false;
321 
322  if ($iddomain == 1) $iddomain = 0; // no use local domain now
323  if ($iddomain == 0) {
324  if ($extmail != "") {
325  $this->mail = trim($extmail);
326  }
327  $this->iddomain = "0";
328  } else {
329  if ($iddomain == 1) {
330  $this->mail = ""; // no mail
331  $this->iddomain = $iddomain;
332  } elseif ($this->iddomain != $iddomain) {
333  If ($this->iddomain > 1) {
334  // need change mail account
335  include_once ("Class.MailAccount.php");
336  $uacc = new MailAccount(GetParam("MAILDB") , $this->id);
337  if ($uacc->isAffected()) {
338  $uacc->iddomain = $iddomain;
339  $uacc->modify();
340  }
341  }
342  $this->iddomain = $iddomain;
343  $this->mail = $this->getMail();
344  }
345  }
346 
347  if ($expires > 0) $this->expires = $expires;
348  if ($passdelay > 0) $this->passdelay = $passdelay;
349  elseif ($passdelay == - 1) { // suppress expire date
350  $this->expires = 0;
351  $this->passdelay = 0;
352  }
353 
354  $this->fid = $fid;
355  if (!$this->isAffected()) {
356  $err = $this->Add();
357  } else {
358  $err = $this->Modify();
359  }
360 
361  if ($err == "") {
362  if ($needmail) {
363  include_once ("Class.MailAccount.php");
364  $this->iddomain = $iddomain;
365  // create mail account
366  $mailapp = new Application();
367  if ($mailapp->Exists("MAILADMIN")) {
368  $mailapp->Set("MAILADMIN", $action->parent);
369  $uacc = new MailAccount($mailapp->GetParam("MAILDB"));
370  $uacc->iddomain = $this->iddomain;
371  $uacc->iduser = $this->id;
372  $uacc->login = $this->login;
373  $err = $uacc->Add(true);
374  if ($err == "") {
375  $this->mail = $this->getMail();
376 
377  $err = $this->Modify(true);
378  }
379  }
380  }
381  }
382  return $err;
383  }
384  /**
385  * update user from FREEDOM IUSER document
386  * @param int $fid document id
387  * @param string $login login
388  * @param int $iddomain mail domain identificator
389  */
390  function SetGroups($fid, $gname, $login, $iddomain)
391  {
392  if ($gname != "") $this->lastname = $gname;
393  if (($this->login == "") && ($login != "")) $this->login = $login;
394 
395  $this->iddomain = $iddomain;
396  if ($this->iddomain == 0) {
397  $this->iddomain = 1;
398  }
399 
400  $this->mail = $this->getMail();
401  $this->fid = $fid;
402  if (!$this->isAffected()) {
403  $this->isgroup = "Y";
404  $err = $this->Add();
405  } else {
406  $err = $this->Modify();
407  }
408 
409  return $err;
410  }
411  //Add and Update expires and passdelay for password
412  //Call in PreUpdate and PreInsert
413  function GetExpires()
414  {
415  if (intval($this->passdelay) == 0) {
416  $this->expires = "0";
417  $this->passdelay = "0";
418  } // neither expire
419  else if (intval($this->expires) == 0) {
420  $this->expires = time() + $this->passdelay;
421  }
422  }
423 
424  function FreedomWhatUser()
425  {
426  if (usefreedomuser()) {
427  $dbaccess = GetParam("FREEDOM_DB");
428  if ($dbaccess == "") return _("no freedom DB access");
429  if ($this->fid <> "") {
430  $iuser = new_Doc($dbaccess, $this->fid);
431 
432  $err = $iuser->RefreshDocUser();
433  } //Update from what
434  else {
435  include_once ("FDL/Lib.Dir.php");
436  if ($this->famid != "") $fam = $this->famid;
437  elseif ($this->isgroup == "Y") $fam = "IGROUP";
438  else $fam = "IUSER";;
439  $filter = array(
440  "us_whatid = '" . $this->id . "'"
441  );
442  $tdoc = getChildDoc($dbaccess, 0, 0, "ALL", $filter, 1, "LIST", $fam);
443  if (count($tdoc) == 0) {
444  //Create a new doc IUSER
445  $iuser = createDoc($dbaccess, $fam);
446  $iuser->SetValue("US_WHATID", $this->id);
447  $iuser->Add();
448  $this->fid = $iuser->id;
449  $this->modify(true, array(
450  'fid'
451  ) , true);
452  $err = $iuser->RefreshDocUser();
453  } else {
454  $this->fid = $tdoc[0]->id;
455  $this->modify(true, array(
456  'fid'
457  ) , true);
458  $err = $tdoc[0]->RefreshDocUser();
459  }
460  }
461  return $err;
462  }
463  }
464  // --------------------------------------------------------------------
465  function computepass($pass, &$passk)
466  {
467  $salt_space = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./";
468  srand((double)microtime() * 1000000);
469  $salt = $salt_space[rand(0, strlen($salt_space) - 1) ];
470  $salt.= $salt_space[rand(0, strlen($salt_space) - 1) ];
471  $passk = crypt($pass, $salt);
472  }
473 
474  function checkpassword($pass)
475  {
476  if ($this->isgroup == 'Y') return false; // don't log in group
477  return ($this->checkpass($pass, $this->password));
478  }
479  // --------------------------------------------------------------------
480  function checkpass($pass, $passk)
481  {
482  $salt = substr($passk, 0, 2);
483  $passres = crypt($pass, $salt);
484  return ($passres == $passk);
485  }
486  /**
487  * return mail adress
488  * @param bool $reinit recompute adress from mail account
489  * @return string mail address empty if no mail
490  */
491  function getMail()
492  {
493  return $this->mail;
494  }
495  function PostInit()
496  {
497 
498  $group = new group($this->dbaccess);
499  // Create admin user
500  $this->iddomain = 0;
501  $this->id = 1;
502  $this->lastname = "Master";
503  $freedomctx = getFreedomContext();
504  if ($freedomctx == "") $this->firstname = "Dynacase Platform";
505  else $this->firstname = ucfirst("$freedomctx");
506  $this->password_new = "anakeen";
507  $this->login = "admin";
508  $this->Add(true);
509  $group->iduser = $this->id;
510  // Create default group
511  $this->iddomain = 1;
512  $this->id = GALL_ID;
513  $this->lastname = "Utilisateurs";
514  $this->firstname = "";
515  $this->login = "all";
516  $this->isgroup = "Y";
517  $this->Add(true);
518  $group->idgroup = $this->id;
519  $group->Add(true);
520  // Create anonymous user
521  $this->iddomain = 0;
522  $this->id = ANONYMOUS_ID;
523  $this->lastname = "anonymous";
524  $this->firstname = "guest";
525  $this->login = "anonymous";
526  $this->isgroup = "N";
527  $this->Add(true);
528  // Create admin group
529  $this->iddomain = 1;
530  $this->id = GADMIN_ID;
531  $this->lastname = "Administrateurs";
532  $this->firstname = "";
533  $this->login = "gadmin";
534  $this->isgroup = "Y";
535  $this->Add(true);
536  $group->idgroup = GALL_ID;
537  $group->iduser = GADMIN_ID;
538  $group->Add(true);
539  // Store error messages
540 
541  }
542  // get All Users (not group)
543  function GetUserList($qtype = "LIST", $start = 0, $slice = 0, $filteruser = false)
544  {
545  $query = new QueryDb($this->dbaccess, "User");
546  $query->order_by = "lastname";
547  $query->AddQuery("(isgroup != 'Y') OR (isgroup isnull)");
548  if ($filteruser) $query->AddQuery("(login ~* '" . pg_escape_string($filteruser) . "')" . " or " . "(lastname ~* '" . pg_escape_string($filteruser) . "')");
549  return ($query->Query($start, $slice, $qtype));
550  }
551  // get All groups
552  function GetGroupList($qtype = "LIST")
553  {
554  $query = new QueryDb($this->dbaccess, "User");
555  $query->order_by = "lastname";
556  $query->AddQuery("isgroup = 'Y'");
557  return ($query->Query(0, 0, $qtype));
558  }
559  // get All users & groups
560  function GetUserAndGroupList($qtype = "LIST")
561  {
562  $query = new QueryDb($this->dbaccess, "User");
563  $query->order_by = "isgroup desc, lastname";
564  return ($query->Query(0, 0, $qtype));
565  }
566  /**
567  * get All ascendant group ids of the user object
568  */
569  function GetGroupsId()
570  {
571  $query = new QueryDb($this->dbaccess, "Group");
572  $query->AddQuery("iduser='{$this->id}'");
573 
574  $list = $query->Query(0, 0, "TABLE");
575  $groupsid = array();
576 
577  if ($query->nb > 0) {
578  while (list($k, $v) = each($list)) {
579  $groupsid[$v["idgroup"]] = $v["idgroup"];
580  }
581  }
582 
583  return $groupsid;
584  }
585  /**
586  * for group :: get All user & groups ids in all descendant(recursive);
587  * @param int $id group identificator
588  * @return array of user array
589  */
590  function GetRUsersList($id, $r = array())
591  {
592  $query = new QueryDb($this->dbaccess, "User");
593  $list = $query->Query(0, 0, "TABLE", "select users.* from users, groups where " . "groups.iduser=users.id and " . "idgroup=$id ;");
594 
595  $uid = array();
596 
597  if ($query->nb > 0) {
598  foreach ($list as $k => $v) {
599  $uid[$v["id"]] = $v;
600  if ($v["isgroup"] == "Y") {
601  if (!in_array($v["id"], $r)) {
602  array_push($r, $v["id"]);
603  $uid+= $this->GetRUsersList($v["id"], $r);
604  }
605  }
606  }
607  }
608 
609  return $uid;
610  }
611  /**
612  * for group :: get All direct user & groups ids
613  * @param int $id group identificator
614  * @param bool $onlygroup set to true if you want only child groups
615  */
616  function GetUsersGroupList($gid, $onlygroup = false)
617  {
618  $query = new QueryDb($this->dbaccess, "User");
619  $optgroup = '';
620  if ($onlygroup) $optgroup = " and users.isgroup='Y' ";
621 
622  $list = $query->Query(0, 0, "TABLE", "select users.* from users, groups where " . "groups.iduser=users.id and " . "idgroup=$gid $optgroup;");
623 
624  $uid = array();
625  if ($query->nb > 0) {
626  foreach ($list as $k => $v) {
627  $uid[$v["id"]] = $v;
628  }
629  }
630 
631  return $uid;
632  }
633  /**
634  * return all user members (recursive)
635  * @return array of user values ["login"=>, "id"=>, "fid"=>,...)
636  */
637  public function getUserMembers()
638  {
639  $tr = array();
640 
641  $g = new Group($this->dbaccess);
642  $lg = $g->getChildsGroupId($this->id);
643  $lg[] = $this->id;
644  $cond = getSqlCond($lg, "idgroup", true);
645  if (!$cond) $cond = "true";
646 
647  $condname = "";
648 
649  $sort = 'lastname';
650  $sql = sprintf("SELECT distinct on (%s, users.id) users.id, users.login, users.firstname , users.lastname, users.mail,users.fid from users, groups where %s and (groups.iduser=users.id) %s and isgroup != 'Y' order by %s", $sort, $cond, $condname, $sort);
651 
652  $err = simpleQuery($this->dbaccess, $sql, $result);
653  if ($err != "") return $err;
654  return $result;
655  }
656  /**
657  * verify if user is member of group (recursive)
658  * @return boolean
659  */
660  public function isMember($uid)
661  {
662  $tr = array();
663 
664  $g = new Group($this->dbaccess);
665  $lg = $g->getChildsGroupId($this->id);
666  $lg[] = $this->id;
667  $cond = getSqlCond($lg, "idgroup", true);
668  if (!$cond) $cond = "true";
669 
670  $sql = sprintf("select users.id from users, groups where %s and (groups.iduser=users.id) and users.id=%d and isgroup != 'Y'", $cond, $uid);
671 
672  $err = simpleQuery($this->dbaccess, $sql, $result, true, true);
673 
674  return ($result != '');
675  }
676  // only use for group
677  // get user member of group
678  function getGroupUserList($qtype = "LIST", $withgroup = false)
679  {
680  $query = new QueryDb($this->dbaccess, "User");
681  $query->order_by = "isgroup desc, lastname";
682  $selgroup = "and (isgroup != 'Y' or isgroup is null)";
683  if ($withgroup) $selgroup = "";
684  return ($query->Query(0, 0, $qtype, "select users.* from users, groups where " . "groups.iduser=users.id and " . "idgroup={$this->id} {$selgroup};"));
685  }
686  /**
687  * Get user token for open access
688  * @param int $expire set expiration delay in seconds (false if nether expire)
689  * @param bool $oneshot set to true to use one token is consumed/deleted when used
690  */
691  function getUserToken($expire = false, $oneshot = false, $context = array())
692  {
693  if ($expire === false) {
694  $expire = 3600 * 24 * 365 * 20;
695  }
696  if ($context && (count($context) > 0)) {
697  $scontext = serialize($context);
698  } else $scontext = '';
699 
700  if (!$this->isAffected()) return false;
701  include_once ('WHAT/Class.UserToken.php');
702  include_once ('WHAT/Class.QueryDb.php');
703  $create = false;
704  if (!$oneshot) {
705  $q = new QueryDb($this->dbaccess, "UserToken");
706  $q->addQuery("userid=" . $this->id);
707  if ($scontext) $q->addQuery("context='" . pg_escape_string($scontext) . "'");
708  $tu = $q->Query(0, 0, "TABLE");
709  $create = ($q->nb == 0);
710  } else {
711  $create = true;
712  }
713 
714  if ($create) {
715  // create one
716  $uk = new UserToken("");
717  $uk->deleteExpired();
718  $uk->userid = $this->id;
719  $uk->token = $uk->genToken();
720  $uk->expire = $uk->setExpiration($expire);
721  $uk->expendable = $oneshot;
722  $uk->context = $scontext;
723  $err = $uk->add();
724  $token = $uk->token;
725  } else {
726  $token = $tu[0]["token"];
727  }
728  return $token;
729  }
730  /**
731  * Set password for the admin account in the `admin' subdir
732  * @param string $admin_passwd the password
733  */
735  {
736  include_once ('WHAT/Lib.Prefix.php');
737 
738  global $pubdir;
739 
740  if( $this->id != 1 ) {
741  $err = sprintf("Method %s can only be used on the admin user.", __FUNCTION__);
742  return $err;
743  }
744 
745  $adminDir = $pubdir . DIRECTORY_SEPARATOR . 'admin';
746  $tmpFile = @tempnam($adminDir, '.htpasswd');
747  if ($tmpFile === false) {
748  $err = sprintf("Error creating temporary file in '%s'.", $adminDir);
749  return $err;
750  }
751  if (chmod($tmpFile, 0600) === false) {
752  $err = sprintf("Error setting mode 0600 on temporary file '%s'.", $tmpFile);
753  unlink($tmpFile);
754  return $err;
755  }
756  $passwdLine = sprintf("%s:{SHA}%s", 'admin', base64_encode(sha1($admin_passwd, true)));
757  if (file_put_contents($tmpFile, $passwdLine) === false) {
758  $err = sprintf("Error writing to temporary file '%s'.", $tmpFile);
759  unlink($tmpFile);
760  return $err;
761  }
762  $htpasswdFile = $adminDir . DIRECTORY_SEPARATOR . '.htpasswd';
763  if (rename($tmpFile, $htpasswdFile) === false) {
764  $err = sprintf("Error renaming temporary file '%s' to '%s'.", $tmpFile, $htpasswdFile);
765  unlink($tmpFile);
766  return $err;
767  }
768  return '';
769  }
770 }
771 ?>
← centre documentaire © anakeen - published under CC License - Dynacase