1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /*!
24 \brief user plugin
25 \author Cajus Pollmeier <pollmeier@gonicus.de>
26 \version 2.00
27 \date 24.07.2003
29 This class provides the functionality to read and write all attributes
30 relevant for person, organizationalPerson, inetOrgPerson and gosaAccount
31 from/to the LDAP. It does syntax checking and displays the formulars required.
32 */
34 class user extends plugin
35 {
36 /* Definitions */
37 var $plHeadline= "Generic";
38 var $plDescription= "Edit organizational user settings";
40 /* Plugin specific values */
41 var $base= "";
42 var $orig_base= "";
43 var $cn= "";
44 var $new_dn= "";
45 var $personalTitle= "";
46 var $academicTitle= "";
47 var $homePostalAddress= "";
48 var $homePhone= "";
49 var $labeledURI= "";
50 var $o= "";
51 var $ou= "";
52 var $departmentNumber= "";
53 var $employeeNumber= "";
54 var $employeeType= "";
55 var $roomNumber= "";
56 var $telephoneNumber= "";
57 var $facsimileTelephoneNumber= "";
58 var $mobile= "";
59 var $pager= "";
60 var $l= "";
61 var $st= "";
62 var $postalAddress= "";
63 var $dateOfBirth;
64 var $use_dob= "0";
65 var $gender="0";
66 var $preferredLanguage="0";
68 var $jpegPhoto= "*removed*";
69 var $photoData= "";
70 var $old_jpegPhoto= "";
71 var $old_photoData= "";
72 var $cert_dialog= FALSE;
73 var $picture_dialog= FALSE;
74 var $pwObject= NULL;
76 var $userPKCS12= "";
77 var $userSMIMECertificate= "";
78 var $userCertificate= "";
79 var $certificateSerialNumber= "";
80 var $old_certificateSerialNumber= "";
81 var $old_userPKCS12= "";
82 var $old_userSMIMECertificate= "";
83 var $old_userCertificate= "";
85 var $gouvernmentOrganizationalUnit= "";
86 var $houseIdentifier= "";
87 var $street= "";
88 var $postalCode= "";
89 var $vocation= "";
90 var $ivbbLastDeliveryCollective= "";
91 var $gouvernmentOrganizationalPersonLocality= "";
92 var $gouvernmentOrganizationalUnitDescription= "";
93 var $gouvernmentOrganizationalUnitSubjectArea= "";
94 var $functionalTitle= "";
95 var $role= "";
96 var $publicVisible= "";
98 var $orig_dn;
99 var $dialog;
101 /* variables to trigger password changes */
102 var $pw_storage= "md5";
103 var $last_pw_storage= "unset";
104 var $had_userCertificate= FALSE;
106 var $view_logged = FALSE;
108 /* attribute list for save action */
109 var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
110 "homePostalAddress", "homePhone", "labeledURI", "ou", "o", "dateOfBirth", "gender","preferredLanguage",
111 "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
112 "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
113 "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate");
115 var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson",
116 "gosaAccount");
118 /* attributes that are part of the government mode */
119 var $govattrs= array("gouvernmentOrganizationalUnit", "houseIdentifier", "vocation",
120 "ivbbLastDeliveryCollective", "gouvernmentOrganizationalPersonLocality",
121 "gouvernmentOrganizationalUnitDescription","gouvernmentOrganizationalUnitSubjectArea",
122 "functionalTitle", "certificateSerialNumber", "publicVisible", "street", "role",
123 "postalCode");
125 var $multiple_support = TRUE;
127 var $governmentmode = FALSE;
129 /* constructor, if 'dn' is set, the node loads the given
130 'dn' from LDAP */
131 function user (&$config, $dn= NULL)
132 {
133 $this->config= $config;
134 /* Configuration is fine, allways */
135 if($this->config->get_cfg_value("honourIvbbAttributes") == "true"){
136 $this->governmentmode = TRUE;
137 $this->attributes=array_merge($this->attributes,$this->govattrs);
138 }
140 /* Load base attributes */
141 plugin::plugin ($config, $dn);
143 $this->orig_dn = $this->dn;
144 $this->new_dn = $dn;
146 if ($this->governmentmode){
147 /* Fix public visible attribute if unset */
148 if (!isset($this->attrs['publicVisible'])){
149 $this->publicVisible == "nein";
150 }
151 }
153 /* Load government mode attributes */
154 if ($this->governmentmode){
155 /* Copy all attributs */
156 foreach ($this->govattrs as $val){
157 if (isset($this->attrs["$val"][0])){
158 $this->$val= $this->attrs["$val"][0];
159 }
160 }
161 }
163 /* Create me for new accounts */
164 if ($dn == "new"){
165 $this->is_account= TRUE;
166 }
168 /* Make hash default to md5 if not set in config */
169 $hash= $this->config->get_cfg_value("passwordDefaultHash", "crypt/md5");
171 /* Load data from LDAP? */
172 if ($dn !== NULL){
174 /* Do base conversation */
175 if ($this->dn == "new"){
176 $ui= get_userinfo();
177 $this->base= dn2base($ui->dn);
178 } else {
179 $this->base= dn2base($dn);
180 }
182 /* get password storage type */
183 if (isset ($this->attrs['userPassword'][0])){
184 /* Initialize local array */
185 $matches= array();
186 if (preg_match ("/^{[^}]+}/", $this->attrs['userPassword'][0])){
187 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
188 if(is_object($tmp)){
189 $this->pw_storage= $tmp->get_hash();
190 }
192 } else {
193 if ($this->attrs['userPassword'][0] != ""){
194 $this->pw_storage= "clear";
195 } else {
196 $this->pw_storage= $hash;
197 }
198 }
199 } else {
200 /* Preset with vaule from configuration */
201 $this->pw_storage= $hash;
202 }
204 /* Load extra attributes: certificate and picture */
205 $this->load_cert();
206 $this->load_picture();
207 if ($this->userCertificate != ""){
208 $this->had_userCertificate= TRUE;
209 }
210 }
212 /* Reset password storage indicator, used by password_change_needed() */
213 if ($dn == "new"){
214 $this->last_pw_storage= "unset";
215 } else {
216 $this->last_pw_storage= $this->pw_storage;
217 }
219 /* Generate dateOfBirth entry */
220 if (isset ($this->attrs['dateOfBirth'])){
221 /* This entry is ISO 8601 conform */
222 list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
224 $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
225 $this->use_dob= "1";
226 } else {
227 $this->use_dob= "0";
228 }
230 /* Put gender attribute to upper case */
231 if (isset ($this->attrs['gender'])){
232 $this->gender= strtoupper($this->attrs['gender'][0]);
233 }
235 $this->orig_base = $this->base;
236 }
241 /* execute generates the html output for this node */
242 function execute()
243 {
244 /* Call parent execute */
245 plugin::execute();
247 /* Log view */
248 if($this->is_account && !$this->view_logged){
249 $this->view_logged = TRUE;
250 new log("view","users/".get_class($this),$this->dn);
251 }
253 $smarty= get_smarty();
255 /* Fill calendar */
256 if ($this->dateOfBirth == "0"){
257 $date= getdate();
258 } else {
259 if(is_array($this->dateOfBirth)){
260 $date = $this->dateOfBirth;
262 // Trigger on dates like 1985-04-01, getdate only understands timestamps
263 } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
264 $date= getdate(strtotime($this->dateOfBirth));
266 } else {
267 $date = getdate($this->dateOfBirth);
268 }
269 }
271 $days= array();
272 for($d= 1; $d<32; $d++){
273 $days[$d]= $d;
274 }
275 $years= array();
277 if(($date['year']-100)<1901){
278 $start = 1901;
279 }else{
280 $start = $date['year']-100;
281 }
283 $end = $start +100;
285 for($y= $start; $y<=$end; $y++){
286 $years[]= $y;
287 }
288 $years['-']= "- ";
289 $months= msgPool::months();
290 $months['-'] = '- ';
292 $smarty->assign("day", $date["mday"]);
293 $smarty->assign("days", $days);
294 $smarty->assign("months", $months);
295 $smarty->assign("month", $date["mon"]-1);
296 $smarty->assign("years", $years);
297 $smarty->assign("year", $date["year"]);
299 /* Assign sex */
300 $sex= array(0 => " ", "F" => _("female"), "M" => _("male"));
301 $smarty->assign("gender_list", $sex);
302 $language= array_merge(array(0 => " ") ,get_languages(TRUE));
303 $smarty->assign("preferredLanguage_list", $language);
305 /* Get random number for pictures */
306 srand((double)microtime()*1000000);
307 $smarty->assign("rand", rand(0, 10000));
310 /* Do we represent a valid gosaAccount? */
311 if (!$this->is_account){
312 $str = "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
313 msgPool::noValidExtension("GOsa")."</b>";
314 return($str);
315 }
317 /* Base select dialog */
318 $once = true;
319 foreach($_POST as $name => $value){
320 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
321 $once = false;
322 $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
323 $this->dialog->setCurrentBase($this->base);
324 }
325 }
327 /* Password configure dialog handling */
328 if(is_object($this->pwObject) && $this->pwObject->display){
329 $output= $this->pwObject->configure();
330 if ($output != ""){
331 $this->dialog= TRUE;
332 return $output;
333 }
334 $this->dialog= false;
335 }
337 /* Dialog handling */
338 if(is_object($this->dialog)){
339 /* Must be called before save_object */
340 $this->dialog->save_object();
342 if($this->dialog->isClosed()){
343 $this->dialog = false;
344 }elseif($this->dialog->isSelected()){
346 /* check if selected base is allowed to move to / create a new object */
347 $tmp = $this->get_allowed_bases();
348 if(isset($tmp[$this->dialog->isSelected()])){
349 $this->base = $this->dialog->isSelected();
350 }
351 $this->dialog= false;
352 }else{
353 return($this->dialog->execute());
354 }
355 }
357 /* Want password method editing? */
358 if ($this->acl_is_writeable("userPassword")){
359 if (isset($_POST['edit_pw_method'])){
360 if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
361 $temp= passwordMethod::get_available_methods();
362 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
363 }
364 $this->pwObject->display = TRUE;
365 $this->dialog= TRUE;
366 return ($this->pwObject->configure());
367 }
368 }
370 /* Want picture edit dialog? */
371 if($this->acl_is_writeable("userPicture")) {
372 if (isset($_POST['edit_picture'])){
373 /* Save values for later recovery, in case some presses
374 the cancel button. */
375 $this->old_jpegPhoto= $this->jpegPhoto;
376 $this->old_photoData= $this->photoData;
377 $this->picture_dialog= TRUE;
378 $this->dialog= TRUE;
379 }
380 }
382 /* Remove picture? */
383 if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))) ){
384 if (isset($_POST['picture_remove'])){
385 $this->set_picture ();
386 $this->jpegPhoto= "*removed*";
387 $this->is_modified= TRUE;
388 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
389 }
390 }
392 /* Save picture */
393 if (isset($_POST['picture_edit_finish'])){
395 /* Check for clean upload */
396 if ($_FILES['picture_file']['name'] != ""){
397 if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
398 msg_dialog::display(_("Error"), _("Cannot upload file!"), ERROR_DIALOG);
399 }else{
400 /* Activate new picture */
401 $this->set_picture($_FILES['picture_file']['tmp_name']);
402 }
403 }
404 $this->picture_dialog= FALSE;
405 $this->dialog= FALSE;
406 $this->is_modified= TRUE;
407 }
410 /* Cancel picture */
411 if (isset($_POST['picture_edit_cancel'])){
413 /* Restore values */
414 $this->jpegPhoto= $this->old_jpegPhoto;
415 $this->photoData= $this->old_photoData;
417 /* Update picture */
418 session::set('binary',$this->photoData);
419 session::set('binarytype',"image/jpeg");
420 $this->picture_dialog= FALSE;
421 $this->dialog= FALSE;
422 }
424 /* Toggle dateOfBirth information */
425 if (isset($_POST['set_dob'])){
426 $this->use_dob= ($this->use_dob == "0")?"1":"0";
427 }
430 /* Want certificate= */
431 if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
433 /* Save original values for later reconstruction */
434 foreach (array("certificateSerialNumber", "userCertificate",
435 "userSMIMECertificate", "userPKCS12") as $val){
437 $oval= "old_$val";
438 $this->$oval= $this->$val;
439 }
441 $this->cert_dialog= TRUE;
442 $this->dialog= TRUE;
443 }
446 /* Cancel certificate dialog */
447 if (isset($_POST['cert_edit_cancel'])){
449 /* Restore original values in case of 'cancel' */
450 foreach (array("certificateSerialNumber", "userCertificate",
451 "userSMIMECertificate", "userPKCS12") as $val){
453 $oval= "old_$val";
454 $this->$val= $this->$oval;
455 }
456 $this->cert_dialog= FALSE;
457 $this->dialog= FALSE;
458 }
461 /* Remove certificate? */
462 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
463 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
464 if (isset($_POST["remove_$val"])){
466 /* Reset specified cert*/
467 $this->$val= "";
468 $this->is_modified= TRUE;
469 }
470 }
471 }
473 /* Upload new cert and close dialog? */
474 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
476 $fail =false;
478 if (isset($_POST['cert_edit_finish'])){
480 /* for all certificates do */
481 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
482 as $val){
484 /* Check for clean upload */
485 if (array_key_exists($val."_file", $_FILES) &&
486 array_key_exists('name', $_FILES[$val."_file"]) &&
487 $_FILES[$val."_file"]['name'] != "" &&
488 is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
489 $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
490 }
491 }
493 /* Save serial number */
494 if (isset($_POST["certificateSerialNumber"]) &&
495 $_POST["certificateSerialNumber"] != ""){
497 if (!tests::is_id($_POST["certificateSerialNumber"])){
498 $fail = true;
499 msg_dialog::display(_("Error"), msgPool::invalid(_("Serial number"),$_POST["certificateSerialNumber"],"/[0-9]/"),ERROR_DIALOG);
501 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
502 if ($this->$cert != ""){
503 $smarty->assign("$cert"."_state", "true");
504 } else {
505 $smarty->assign("$cert"."_state", "");
506 }
507 }
508 }
510 $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
511 $this->is_modified= TRUE;
512 }
513 if(!$fail){
514 $this->cert_dialog= FALSE;
515 $this->dialog= FALSE;
516 }
517 }
518 }
519 /* Display picture dialog */
520 if ($this->picture_dialog){
521 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
522 }
524 /* Display cert dialog */
525 if ($this->cert_dialog){
526 $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
527 $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
528 $smarty->assign("certificateSerialNumber",$this->certificateSerialNumber);
530 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
531 if ($this->$cert != ""){
532 /* import certificate */
533 $certificate = new certificate;
534 $certificate->import($this->$cert);
536 /* Read out data*/
537 $timeto = $certificate->getvalidto_date();
538 $timefrom = $certificate->getvalidfrom_date();
541 /* Additional info if start end time is '0' */
542 $add_str_info = "";
543 if($timeto == 0 && $timefrom == 0){
544 $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
545 }
547 $str = "<table summary=\"\" border=0>
548 <tr>
549 <td style='vertical-align:top'>CN</td>
550 <td>".preg_replace("/ /", " ", $certificate->getname())."</td>
551 </tr>
552 </table><br>".
554 sprintf(_("Certificate is valid from %s to %s and is currently %s."),
555 "<b>".date('d M Y',$timefrom)."</b>",
556 "<b>".date('d M Y',$timeto)."</b>",
557 $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
558 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
560 $smarty->assign($cert."info",$str);
561 $smarty->assign($cert."_state","true");
562 } else {
563 $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
564 $smarty->assign($cert."_state","");
565 }
566 }
568 if($this->governmentmode){
569 $smarty->assign("honourIvbbAttributes", "true");
570 }else{
571 $smarty->assign("honourIvbbAttributes", "false");
572 }
573 $smarty->assign("governmentmode", $this->governmentmode);
574 return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
575 }
577 /* Prepare password hashes */
578 if ($this->pw_storage == ""){
579 $this->pw_storage= $this->config->get_cfg_value("hash");
580 }
582 $temp= passwordMethod::get_available_methods();
583 $is_configurable= FALSE;
584 $hashes = $temp['name'];
585 if(isset($temp[$this->pw_storage])){
586 $test= new $temp[$this->pw_storage]($this->config);
587 $is_configurable= $test->is_configurable();
588 }else{
589 new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
590 }
593 /* Create password methods array */
594 $pwd_methods = array();
595 foreach($hashes as $id => $name){
596 if(!empty($temp['desc'][$id])){
597 $pwd_methods[$name] = $name." (".$temp['desc'][$id].")";
598 }else{
599 $pwd_methods[$name] = $name;
600 }
601 }
603 /* Load attributes and acl's */
604 $ui =get_userinfo();
605 foreach($this->attributes as $val){
606 $smarty->assign("$val", $this->$val);
607 if(in_array($val,$this->multi_boxes)){
608 $smarty->assign("use_".$val,TRUE);
609 }else{
610 $smarty->assign("use_".$val,FALSE);
611 }
612 }
613 foreach(array("base","pw_storage","edit_picture") as $val){
614 if(in_array($val,$this->multi_boxes)){
615 $smarty->assign("use_".$val,TRUE);
616 }else{
617 $smarty->assign("use_".$val,FALSE);
618 }
619 }
621 /* Set acls */
622 $tmp = $this->plinfo();
623 foreach($tmp['plProvidedAcls'] as $val => $translation){
624 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
625 }
627 $smarty->assign("pwmode", $pwd_methods);
628 $smarty->assign("pwmode_select", $this->pw_storage);
629 $smarty->assign("pw_configurable", $is_configurable);
630 $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !session::is_set('edit'))));
631 $smarty->assign("base_select", $this->base);
633 if(!session::is_set('edit')){
634 $smarty->assign("CertificatesACL","");
635 }else{
636 $smarty->assign("CertificatesACL", $this->getacl("Certificate"));
637 }
639 $smarty->assign("userPictureACL", $this->getacl("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
640 $smarty->assign("userPicture_is_readable", $this->acl_is_readable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
642 /* Create base acls */
643 $tmp = @$this->allowedBasesToMoveTo();
644 $smarty->assign("bases", $tmp);
646 /* Save government mode attributes */
647 if($this->governmentmode){
648 $smarty->assign("governmentmode", "true");
649 $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
650 "internet,ivbv", "internet,testa", "internet,ivbv,testa");
651 $smarty->assign("ivbbmodes", $ivbbmodes);
652 foreach ($this->govattrs as $val){
653 $smarty->assign("$val", $this->$val);
654 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
655 }
656 } else {
657 $smarty->assign("governmentmode", "false");
658 }
660 /* Special mode for uid */
661 $uidACL= $this->getacl("uid",(!is_object($this->parent) && !session::is_set('edit')));
662 if (isset ($this->dn)){
663 if ($this->dn != "new"){
664 $uidACL= preg_replace("/w/","",$uidACL);
665 }
666 } else {
667 $uidACL= preg_replace("/w/","",$uidACL);
668 }
670 $smarty->assign("uidACL", $uidACL);
671 $smarty->assign("is_template", $this->is_template);
672 $smarty->assign("use_dob", $this->use_dob);
674 if (isset($this->parent)){
675 if (isset($this->parent->by_object['phoneAccount']) &&
676 $this->parent->by_object['phoneAccount']->is_account){
677 $smarty->assign("has_phoneaccount", "true");
678 } else {
679 $smarty->assign("has_phoneaccount", "false");
680 }
681 } else {
682 $smarty->assign("has_phoneaccount", "false");
683 }
684 $smarty->assign("multiple_support" , $this->multiple_support_active);
685 return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
686 }
689 /* remove object from parent */
690 function remove_from_parent()
691 {
692 /* Only remove valid accounts */
693 if(!$this->initially_was_account) return;
695 /* Remove password extension */
696 $temp= passwordMethod::get_available_methods();
698 /* Remove password method from user account */
699 if(isset($temp[$this->pw_storage]) && class_available($temp[$this->pw_storage])){
700 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
701 $this->pwObject->remove_from_parent();
702 }
704 /* Remove user */
705 $ldap= $this->config->get_ldap_link();
706 $ldap->rmdir ($this->dn);
707 if (!$ldap->success()){
708 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
709 }
711 new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
713 /* Delete references to groups */
714 $ldap->cd ($this->config->current['BASE']);
715 $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
716 while ($ldap->fetch()){
717 $g= new group($this->config, $ldap->getDN());
718 $g->removeUser($this->uid);
719 $g->save ();
720 }
722 /* Delete references to object groups */
723 $ldap->cd ($this->config->current['BASE']);
724 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
725 while ($ldap->fetch()){
726 $og= new ogroup($this->config, $ldap->getDN());
727 unset($og->member[$this->dn]);
728 $og->save ();
729 }
731 /* Delete references to roles */
732 $ldap->cd ($this->config->current['BASE']);
733 $ldap->search ("(&(objectClass=organizationalRole)(roleOccupant=".LDAP::prepare4filter($this->dn)."))", array("cn"));
734 while ($ldap->fetch()){
735 $role= new roleGeneric($this->config, $ldap->getDN());
736 $key = array_search($this->dn,$role->roleOccupant);
737 if($key !== FALSE){
738 unset($role->roleOccupant[$key]);
739 $role->reload();
740 $role->save ();
741 }
742 }
744 /* If needed, let the password method do some cleanup */
745 $tmp = new passwordMethod($this->config);
746 $available = $tmp->get_available_methods();
747 if (in_array_ics($this->pw_storage, $available['name'])){
748 $test= new $available[$this->pw_storage]($this->config);
749 $test->attrs= $this->attrs;
750 $test->dn= $this->dn;
751 $test->remove_from_parent();
752 }
754 /* Remove ACL dependencies too */
755 $tmp = new acl($this->config,$this->parent,$this->dn);
756 $tmp->remove_acl();
758 /* Optionally execute a command after we're done */
759 $this->handle_post_events("remove",array("uid" => $this->uid));
760 }
763 /* Save data to object */
764 function save_object()
765 {
766 if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
768 /* Make a backup of the current selected base */
769 $base_tmp = $this->base;
771 /* Parents save function */
772 plugin::save_object ();
774 /* Save government mode attributes */
775 if ($this->governmentmode){
776 foreach ($this->govattrs as $val){
777 if ($this->acl_is_writeable($val,(!is_object($this->parent) && !session::is_set('edit'))) && isset($_POST["$val"])){
778 $data= stripcslashes($_POST["$val"]);
779 if ($data != $this->$val){
780 $this->is_modified= TRUE;
781 }
782 $this->$val= $data;
783 }
784 }
785 }
787 /* In template mode, the uid is autogenerated... */
788 if ($this->is_template){
789 $this->uid= strtolower($this->sn);
790 $this->givenName= $this->sn;
791 }
793 /* Save base and pw_storage, since these are no LDAP attributes */
794 if (isset($_POST['base'])){
796 $tmp = $this->get_allowed_bases();
797 if(isset($tmp[$_POST['base']])){
798 $base= validate($_POST['base']);
799 if ($base != $this->base){
800 $this->is_modified= TRUE;
801 }
802 $this->base= $base;
803 }else{
804 $this->base = $base_tmp;
805 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
806 }
807 }
809 /* Get pw_storage mode */
810 if (isset($_POST['pw_storage'])){
811 foreach(array("pw_storage") as $val){
812 if(isset($_POST[$val])){
813 $data= validate($_POST[$val]);
814 if ($data != $this->$val){
815 $this->is_modified= TRUE;
816 }
817 $this->$val= $data;
818 }
819 }
820 }
822 if($this->pw_storage != $this->last_pw_storage && isset($_POST['pw_storage'])){
823 if ($this->acl_is_writeable("userPassword")){
824 $temp= passwordMethod::get_available_methods();
825 if (!is_object($this->pwObject) || !($this->pwObject instanceOf $temp[$this->pw_storage])){
826 foreach($temp as $id => $data){
827 if(isset($data['name']) && $data['name'] == $this->pw_storage && $data['is_configurable']){
828 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
829 break;
830 }
831 }
832 }
833 }
834 }
836 /* Save current cn
837 */
838 $this->cn = $this->givenName." ".$this->sn;
839 }
840 }
842 function rebind($ldap, $referral)
843 {
844 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
845 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
846 $this->error = "Success";
847 $this->hascon=true;
848 $this->reconnect= true;
849 return (0);
850 } else {
851 $this->error = "Could not bind to " . $credentials['ADMIN'];
852 return NULL;
853 }
854 }
857 /* Save data to LDAP, depending on is_account we save or delete */
858 function save()
859 {
860 /* Only force save of changes ....
861 If this attributes aren't changed, avoid saving.
862 */
864 if($this->gender=="0") $this->gender ="";
865 if($this->preferredLanguage=="0") $this->preferredLanguage ="";
867 /* First use parents methods to do some basic fillup in $this->attrs */
868 plugin::save ();
870 if ($this->use_dob == "1"){
871 /* If it is an array, the generic page has never been loaded - so there's no difference. Using an array would cause an error btw. */
872 if(!is_array($this->attrs['dateOfBirth'])) {
873 $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
874 }
875 }
877 /* Remove additional objectClasses */
878 $tmp= array();
879 foreach ($this->attrs['objectClass'] as $key => $set){
880 $found= false;
881 foreach (array("ivbbentry", "gosaUserTemplate") as $val){
882 if (preg_match ("/^$set$/i", $val)){
883 $found= true;
884 break;
885 }
886 }
887 if (!$found){
888 $tmp[]= $set;
889 }
890 }
892 /* Replace the objectClass array. This is done because of the
893 separation into government and normal mode. */
894 $this->attrs['objectClass']= $tmp;
896 /* Add objectClasss for template mode? */
897 if ($this->is_template){
898 $this->attrs['objectClass'][]= "gosaUserTemplate";
899 }
901 /* Hard coded government mode? */
902 if ($this->governmentmode){
903 $this->attrs['objectClass'][]= "ivbbentry";
905 /* Copy standard attributes */
906 foreach ($this->govattrs as $val){
907 if ($this->$val != ""){
908 $this->attrs["$val"]= $this->$val;
909 } elseif (!$this->is_new) {
910 $this->attrs["$val"]= array();
911 }
912 }
914 /* Remove attribute if set to "nein" */
915 if ($this->publicVisible == "nein"){
916 $this->attrs['publicVisible']= array();
917 if($this->is_new){
918 unset($this->attrs['publicVisible']);
919 }else{
920 $this->attrs['publicVisible']=array();
921 }
923 }
925 }
927 /* Special handling for attribute userCertificate needed */
928 if ($this->userCertificate != ""){
929 $this->attrs["userCertificate;binary"]= $this->userCertificate;
930 $remove_userCertificate= false;
931 } else {
932 $remove_userCertificate= true;
933 }
935 /* Special handling for dateOfBirth value */
936 if ($this->use_dob != "1"){
937 if ($this->is_new) {
938 unset($this->attrs["dateOfBirth"]);
939 } else {
940 $this->attrs["dateOfBirth"]= array();
941 }
942 }
943 if (!$this->gender){
944 if ($this->is_new) {
945 unset($this->attrs["gender"]);
946 } else {
947 $this->attrs["gender"]= array();
948 }
949 }
950 if (!$this->preferredLanguage){
951 if ($this->is_new) {
952 unset($this->attrs["preferredLanguage"]);
953 } else {
954 $this->attrs["preferredLanguage"]= array();
955 }
956 }
958 /* Special handling for attribute jpegPhote needed, scale image via
959 image magick to 147x200 pixels and inject resulting data. */
960 if ($this->jpegPhoto == "*removed*"){
962 /* Reset attribute to avoid writing *removed* as value */
963 $this->attrs["jpegPhoto"] = array();
965 } else {
967 /* Fallback if there's no image magick inside PHP */
968 if (!function_exists("imagick_blob2image")){
969 /* Get temporary file name for conversation */
970 $fname = tempnam (TEMP_DIR, "GOsa");
972 /* Open file and write out photoData */
973 $fp = fopen ($fname, "w");
974 fwrite ($fp, $this->photoData);
975 fclose ($fp);
977 /* Build conversation query. Filename is generated automatically, so
978 we do not need any special security checks. Exec command and save
979 output. For PHP safe mode, you'll need a configuration which respects
980 image magick as executable... */
981 $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
982 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
983 $query, "Execute");
985 /* Read data written by convert */
986 $output= "";
987 $sh= popen($query, 'r');
988 while (!feof($sh)){
989 $output.= fread($sh, 4096);
990 }
991 pclose($sh);
993 unlink($fname);
995 /* Save attribute */
996 $this->attrs["jpegPhoto"] = $output;
998 } else {
1000 /* Load the new uploaded Photo */
1001 if(!$handle = imagick_blob2image($this->photoData)) {
1002 new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
1003 }
1005 /* Resizing image to 147x200 and blur */
1006 if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
1007 new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
1008 }
1010 /* Converting image to JPEG */
1011 if(!imagick_convert($handle,"JPEG")) {
1012 new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
1013 }
1015 /* Creating binary Code for the Image */
1016 if(!$dump = imagick_image2blob($handle)){
1017 new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
1018 }
1020 /* Sending Image */
1021 $output= $dump;
1023 /* Save attribute */
1024 $this->attrs["jpegPhoto"] = $output;
1025 }
1027 }
1029 /* This only gets called when user is renaming himself */
1030 $ldap= $this->config->get_ldap_link();
1031 if ($this->dn != $this->new_dn){
1033 /* Write entry on new 'dn' */
1034 $this->update_acls($this->dn,$this->new_dn);
1035 $this->move($this->dn, $this->new_dn);
1037 /* Happen to use the new one */
1038 change_ui_dn($this->dn, $this->new_dn);
1039 $this->dn= $this->new_dn;
1040 }
1043 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1044 new entries. So do a check first... */
1045 $ldap->cat ($this->dn, array('dn'));
1046 if ($ldap->fetch()){
1047 $mode= "modify";
1048 } else {
1049 $mode= "add";
1050 $ldap->cd($this->config->current['BASE']);
1051 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1052 }
1054 /* Set password to some junk stuff in case of templates */
1055 if ($this->is_template){
1056 $temp= passwordMethod::get_available_methods();
1057 foreach($temp as $id => $data){
1058 if(isset($data['name']) && $data['name'] == $this->pw_storage){
1059 $tmp = new $temp[$this->pw_storage]($this->config,$this->dn);
1060 $tmp->set_hash($this->pw_storage);
1061 $this->attrs['userPassword'] = $tmp->create_template_hash($this->attrs);
1062 break;
1063 }
1064 }
1065 }
1067 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1068 $this->attributes, "Save via $mode");
1070 /* Finally write data with selected 'mode' */
1071 $this->cleanup();
1073 /* Update current locale settings, if we have edited ourselves */
1074 $ui = session::get('ui');
1075 if(isset($this->attrs['preferredLanguage']) && $this->dn == $ui->dn){
1076 $ui->language = $this->preferredLanguage;
1077 session::set('ui',$ui);
1078 session::set('Last_init_lang',"update");
1079 }
1081 $ldap->cd ($this->dn);
1082 $ldap->$mode ($this->attrs);
1083 if (!$ldap->success()){
1084 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1085 return (1);
1086 }
1088 /* Remove ACL dependencies too */
1089 if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1090 $tmp = new acl($this->config,$this->parent,$this->dn);
1091 $tmp->update_acl_membership($this->orig_dn,$this->dn);
1092 }
1094 if($mode == "modify"){
1095 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1096 }else{
1097 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1098 }
1100 /* Remove cert?
1101 For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1102 to work around myself. */
1103 if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1105 /* Reset array, assemble new, this should be reworked */
1106 $this->attrs= array();
1107 $this->attrs['userCertificate;binary']= array();
1109 /* Prepare connection */
1110 if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1111 die ("Could not connect to LDAP server");
1112 }
1113 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1114 if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("ldapFollowReferrals") == "true") {
1115 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1116 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1117 }
1118 if($this->config->get_cfg_value("ldapTLS") == "true"){
1119 ldap_start_tls($ds);
1120 }
1121 if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1122 $this->config->current['PASSWORD']))) {
1123 die ("Could not bind to LDAP");
1124 }
1126 /* Modify using attrs */
1127 ldap_mod_del($ds,$this->dn,$this->attrs);
1128 ldap_close($ds);
1129 }
1131 /* If needed, let the password method do some cleanup */
1132 if ($this->pw_storage != $this->last_pw_storage){
1133 $tmp = new passwordMethod($this->config);
1134 $available = $tmp->get_available_methods();
1135 if (in_array_ics($this->last_pw_storage, $available['name'])){
1136 $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1137 $test->attrs= $this->attrs;
1138 $test->remove_from_parent();
1139 }
1140 }
1142 /* Maybe the current password method want's to do some changes... */
1143 if (is_object($this->pwObject)){
1144 $this->pwObject->save($this->dn);
1145 }
1147 /* Optionally execute a command after we're done */
1148 if ($mode == "add"){
1149 $this->handle_post_events("add", array("uid" => $this->uid));
1150 } elseif ($this->is_modified){
1151 $this->handle_post_events("modify", array("uid" => $this->uid));
1152 }
1154 return (0);
1155 }
1158 function create_initial_rdn($pattern)
1159 {
1160 // Only generate single RDNs
1161 if (preg_match('/\+/', $pattern)){
1162 msg_dialog::display(_("Error"), _("Cannot build RDN: no + allowed to build sub RDN!"), ERROR_DIALOG);
1163 return "";
1164 }
1166 // Extract attribute
1167 $attribute= preg_replace('/=.*$/', '', $pattern);
1168 if (!in_array_ics($attribute, $this->attributes)) {
1169 msg_dialog::display(_("Error"), _("Cannot build RDN: attribute is not defined!"), ERROR_DIALOG);
1170 return "";
1171 }
1173 // Sort attributes for length
1174 $attrl= array();
1175 foreach ($this->attributes as $attr) {
1176 $attrl[$attr]= strlen($attr);
1177 }
1178 arsort($attrl);
1180 // Walk thru sorted attributes and replace them in pattern
1181 foreach ($attrl as $attr => $dummy) {
1182 if (!is_array($this->$attr)){
1183 $pattern= preg_replace("/%$attr/", $this->$attr, $pattern);
1184 } else {
1185 msg_dialog::display(_("Error"), _("Cannot build RDN: invalid attribute parameters!"), ERROR_DIALOG);
1186 break;
1187 }
1188 }
1190 // Internally assign value
1191 $this->$attribute= preg_replace('/^[^=]+=/', '', $pattern);
1193 return $pattern;
1194 }
1197 function update_new_dn()
1198 {
1199 // Alternative way to handle DN
1200 $pattern= $this->config->get_cfg_value("accountRDN");
1201 if ($pattern != "") {
1202 $rdn= $this->create_initial_rdn($pattern);
1203 $attribute= preg_replace('/=.*$/', '', $rdn);
1204 $value= preg_replace('/^[^=]+=$/', '', $rdn);
1206 /* Don't touch dn, if $attribute hasn't changed */
1207 if (isset($this->saved_attributes[$attribute]) && $this->saved_attributes[$attribute] == $this->$attribute &&
1208 $this->orig_base == $this->base ){
1209 $this->new_dn= $this->dn;
1210 } else {
1211 $this->new_dn= $this->create_unique_dn2($rdn, get_people_ou().$this->base);
1212 }
1214 // Original way to handle DN
1215 } else {
1217 $pt= "";
1218 if($this->config->get_cfg_value("personalTitleInDN") == "true"){
1219 if(!empty($this->personalTitle)){
1220 $pt = $this->personalTitle." ";
1221 }
1222 }
1224 $this->cn= $pt.$this->givenName." ".$this->sn;
1226 /* Permissions for that base? */
1227 if ($this->config->get_cfg_value("accountPrimaryAttribute") == "uid"){
1228 $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1229 } else {
1230 /* Don't touch dn, if cn hasn't changed */
1231 if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1232 $this->orig_base == $this->base ){
1233 $this->new_dn= $this->dn;
1234 } else {
1235 $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1236 }
1237 }
1238 }
1239 }
1242 /* Check formular input */
1243 function check()
1244 {
1245 /* Call common method to give check the hook */
1246 $message= plugin::check();
1248 /* Configurable password methods should be configured initially.
1249 */
1250 if($this->last_pw_storage != $this->pw_storage){
1251 $temp= passwordMethod::get_available_methods();
1252 foreach($temp['name'] as $id => $name){
1253 if($name == $this->pw_storage){
1254 if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1255 $message[] = _("The selected password method requires initial configuration!");
1256 }
1257 break;
1258 }
1259 }
1260 }
1262 $this->update_new_dn();
1264 /* Set the new acl base */
1265 if($this->dn == "new") {
1266 $this->set_acl_base($this->base);
1267 }
1269 /* Check if we are allowed to create/move this user
1270 */
1272 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1273 $message[]= msgPool::permCreate();
1274 }elseif($this->orig_dn != "new" && $this->new_dn != $this->orig_dn && !$this->acl_is_moveable($this->base)){
1275 $message[]= msgPool::permMove();
1276 }
1278 /* UID already used? */
1279 $ldap= $this->config->get_ldap_link();
1280 $ldap->cd($this->config->current['BASE']);
1281 $ldap->search("(uid=$this->uid)", array("uid"));
1282 $ldap->fetch();
1283 if ($ldap->count() != 0 && $this->dn == 'new'){
1284 $message[]= msgPool::duplicated(_("Login"));
1285 }
1287 /* In template mode, the uid and givenName are autogenerated... */
1288 if ($this->sn == ""){
1289 $message[]= msgPool::required(_("Name"));
1290 }
1292 if (!$this->is_template){
1293 if ($this->givenName == ""){
1294 $message[]= msgPool::required(_("Given name"));
1295 }
1296 if ($this->uid == ""){
1297 $message[]= msgPool::required(_("Login"));
1298 }
1299 if ($this->config->get_cfg_value("accountPrimaryAttribute") != "uid"){
1300 $ldap->cat($this->new_dn);
1301 if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1302 $message[]= msgPool::duplicated(_("Name"));
1303 }
1304 }
1305 }
1307 /* Check for valid input */
1308 if ($this->is_modified && !tests::is_uid($this->uid)){
1310 if (strict_uid_mode()){
1311 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1312 } else {
1313 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1314 }
1315 }
1316 if (!tests::is_url($this->labeledURI)){
1317 $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1318 }
1320 /* Check phone numbers */
1321 if (!tests::is_phone_nr($this->telephoneNumber)){
1322 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1323 }
1324 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1325 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1326 }
1327 if (!tests::is_phone_nr($this->mobile)){
1328 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1329 }
1330 if (!tests::is_phone_nr($this->pager)){
1331 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1332 }
1334 /* Check for reserved characers */
1335 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1336 $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1337 }
1338 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1339 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1340 }
1342 return $message;
1343 }
1346 /* Indicate whether a password change is needed or not */
1347 function password_change_needed()
1348 {
1349 if(in_array("pw_storage",$this->multi_boxes)){
1350 return(TRUE);
1351 }
1352 return($this->pw_storage != $this->last_pw_storage && !$this->is_template);
1353 }
1356 /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1357 function load_picture()
1358 {
1359 $ldap = $this->config->get_ldap_link();
1360 $ldap->cd ($this->dn);
1361 $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1363 if((!$data) || ($data == "*removed*")){
1365 /* In case we don't get an entry, load a default picture */
1366 $this->set_picture ();
1367 $this->jpegPhoto= "*removed*";
1368 }else{
1370 /* Set picture */
1371 $this->photoData= $data;
1372 session::set('binary',$this->photoData);
1373 session::set('binarytype',"image/jpeg");
1374 $this->jpegPhoto= "";
1375 }
1376 }
1379 /* Load a certificate from LDAP, this is going to be simplified later on */
1380 function load_cert()
1381 {
1382 $ds= ldap_connect($this->config->current['SERVER']);
1383 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1384 if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("ldapFollowReferrals") == "true"){
1385 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1386 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1387 }
1388 if ($this->config->get_cfg_value("ldapTLS") == "true"){
1389 ldap_start_tls($ds);
1390 }
1392 $r= ldap_bind($ds);
1393 $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1395 if ($sr) {
1396 $ei= @ldap_first_entry($ds, $sr);
1398 if ($ei) {
1399 if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1400 $this->userCertificate= "";
1401 } else {
1402 $this->userCertificate= $info[0];
1403 }
1404 }
1405 } else {
1406 $this->userCertificate= "";
1407 }
1409 ldap_unbind($ds);
1410 }
1413 /* Load picture from file to object */
1414 function set_picture($filename ="")
1415 {
1416 if (!is_file($filename) || $filename =="" ){
1417 $filename= "./plugins/users/images/default.jpg";
1418 $this->jpegPhoto= "*removed*";
1419 }
1421 $fd = fopen ($filename, "rb");
1422 $this->photoData= fread ($fd, filesize ($filename));
1423 session::set('binary',$this->photoData);
1424 session::set('binarytype',"image/jpeg");
1425 $this->jpegPhoto= "";
1427 fclose ($fd);
1428 }
1431 /* Load certificate from file to object */
1432 function set_cert($cert, $filename)
1433 {
1434 if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1435 $fd = fopen ($filename, "rb");
1436 if (filesize($filename)>0) {
1437 $this->$cert= fread ($fd, filesize ($filename));
1438 fclose ($fd);
1439 $this->is_modified= TRUE;
1440 } else {
1441 msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1442 }
1443 }
1445 /* Adapt from given 'dn' */
1446 function adapt_from_template($dn, $skip= array())
1447 {
1448 plugin::adapt_from_template($dn, $skip);
1450 /* Get password method from template
1451 */
1452 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
1453 if(is_object($tmp)){
1454 if($tmp->is_configurable()){
1455 $tmp->adapt_from_template($dn);
1456 $this->pwObject = &$tmp;
1457 }
1458 $this->pw_storage= $tmp->get_hash();
1459 }
1461 /* Get base */
1462 $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1464 if($this->governmentmode){
1466 /* Walk through govattrs */
1467 foreach ($this->govattrs as $val){
1469 if (in_array($val, $skip)){
1470 continue;
1471 }
1473 if (isset($this->attrs["$val"][0])){
1475 /* If attribute is set, replace dynamic parts:
1476 %sn, %givenName and %uid. Fill these in our local variables. */
1477 $value= $this->attrs["$val"][0];
1479 foreach (array("sn", "givenName", "uid") as $repl){
1480 if (preg_match("/%$repl/i", $value)){
1481 $value= preg_replace ("/%$repl/i",
1482 $this->parent->$repl, $value);
1483 }
1484 }
1485 $this->$val= $value;
1486 }
1487 }
1488 }
1490 /* Get back uid/sn/givenName - only write if nothing's skipped */
1491 if ($this->parent !== NULL && count($skip) == 0){
1492 $this->uid= $this->parent->uid;
1493 $this->sn= $this->parent->sn;
1494 $this->givenName= $this->parent->givenName;
1495 }
1496 }
1499 /* This avoids that users move themselves out of their rights.
1500 */
1501 function allowedBasesToMoveTo()
1502 {
1503 /* Get bases */
1504 $bases = $this->get_allowed_bases();
1505 return($bases);
1506 }
1509 function getCopyDialog()
1510 {
1511 $str = "";
1513 session::set('binary',$this->photoData);
1514 session::set('binarytype',"image/jpeg");
1516 /* Get random number for pictures */
1517 srand((double)microtime()*1000000);
1518 $rand = rand(0, 10000);
1520 $smarty = get_smarty();
1522 $smarty->assign("passwordTodo","clear");
1524 if(isset($_POST['passwordTodo'])){
1525 $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1526 }
1528 $smarty->assign("sn", $this->sn);
1529 $smarty->assign("givenName",$this->givenName);
1530 $smarty->assign("uid", $this->uid);
1531 $smarty->assign("rand", $rand);
1532 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1535 $ret = array();
1536 $ret['string'] = $str;
1537 $ret['status'] = "";
1538 return($ret);
1539 }
1541 function saveCopyDialog()
1542 {
1543 /* Set_acl_base */
1544 $this->set_acl_base($this->base);
1546 if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1547 $this->set_picture($_FILES['picture_file']['tmp_name']);
1548 }
1550 /* Remove picture? */
1551 if (isset($_POST['picture_remove'])){
1552 $this->jpegPhoto= "*removed*";
1553 $this->set_picture ("./plugins/users/images/default.jpg");
1554 $this->is_modified= TRUE;
1555 }
1557 $attrs = array("uid","givenName","sn");
1558 foreach($attrs as $attr){
1559 if(isset($_POST[$attr])){
1560 $this->$attr = $_POST[$attr];
1561 }
1562 }
1563 }
1566 function PrepareForCopyPaste($source)
1567 {
1568 plugin::PrepareForCopyPaste($source);
1570 /* Reset certificate information addepted from source user
1571 to avoid setting the same user certificate for the destination user. */
1572 $this->userPKCS12= "";
1573 $this->userSMIMECertificate= "";
1574 $this->userCertificate= "";
1575 $this->certificateSerialNumber= "";
1576 $this->old_certificateSerialNumber= "";
1577 $this->old_userPKCS12= "";
1578 $this->old_userSMIMECertificate= "";
1579 $this->old_userCertificate= "";
1580 }
1583 static function plInfo()
1584 {
1586 $govattrs= array(
1587 "gouvernmentOrganizationalUnit" => _("Unit"),
1588 "houseIdentifier" => _("House identifier"),
1589 "vocation" => _("Vocation"),
1590 "ivbbLastDeliveryCollective" => _("Last delivery"),
1591 "gouvernmentOrganizationalPersonLocality" => _("Person locality"),
1592 "gouvernmentOrganizationalUnitDescription" => _("Unit description"),
1593 "gouvernmentOrganizationalUnitSubjectArea" => _("Subject area"),
1594 "functionalTitle" => _("Functional title"),
1595 "certificateSerialNumber" => _("Certificate serial number"),
1596 "publicVisible" => _("Public visible"),
1597 "street" => _("Street"),
1598 "role" => _("Role"),
1599 "postalCode" => _("Postal code"));
1601 $ret = array(
1602 "plShortName" => _("Generic"),
1603 "plDescription" => _("Generic user settings"),
1604 "plSelfModify" => TRUE,
1605 "plDepends" => array(),
1606 "plPriority" => 1,
1607 "plSection" => array("personal" => _("My account")),
1608 "plCategory" => array("users" => array("description" => _("Users"),
1609 "objectClass" => "gosaAccount")),
1611 "plProvidedAcls" => array(
1613 "sn" => _("Surname"),
1614 "givenName" => _("Given name"),
1615 "uid" => _("User identification"),
1616 "personalTitle" => _("Personal title"),
1617 "academicTitle" => _("Academic title"),
1619 "dateOfBirth" => _("Date of birth"),
1620 "gender" => _("Gender"),
1621 "preferredLanguage" => _("Preferred language"),
1622 "base" => _("Base"),
1624 "userPicture" => _("User picture"),
1626 "o" => _("Organization"),
1627 "ou" => _("Department"),
1628 "departmentNumber" => _("Department number"),
1629 "employeeNumber" => _("Employee number"),
1630 "employeeType" => _("Employee type"),
1632 "roomNumber" => _("Room number"),
1633 "telephoneNumber" => _("Telefon number"),
1634 "pager" => _("Pager number"),
1635 "mobile" => _("Mobile number"),
1636 "facsimileTelephoneNumber" => _("Fax number"),
1638 "st" => _("State"),
1639 "l" => _("Location"),
1640 "postalAddress" => _("Postal address"),
1642 "homePostalAddress" => _("Home postal address"),
1643 "homePhone" => _("Home phone number"),
1644 "labeledURI" => _("Homepage"),
1645 "userPassword" => _("User password method"),
1646 "Certificate" => _("User certificates"))
1648 );
1650 /* Append government attributes if required */
1651 global $config;
1652 if($config->get_cfg_value("honourIvbbAttributes") == "true"){
1653 foreach($govattrs as $attr => $desc){
1654 $ret["plProvidedAcls"][$attr] = $desc;
1655 }
1656 }
1657 return($ret);
1658 }
1660 function get_multi_edit_values()
1661 {
1662 $ret = plugin::get_multi_edit_values();
1663 if(in_array("pw_storage",$this->multi_boxes)){
1664 $ret['pw_storage'] = $this->pw_storage;
1665 }
1666 if(in_array("edit_picture",$this->multi_boxes)){
1667 $ret['jpegPhoto'] = $this->jpegPhoto;
1668 $ret['photoData'] = $this->photoData;
1669 $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1670 $ret['old_photoData'] = $this->old_photoData;
1671 }
1672 if(isset($ret['dateOfBirth'])){
1673 unset($ret['dateOfBirth']);
1674 }
1675 if(isset($ret['cn'])){
1676 unset($ret['cn']);
1677 }
1678 $ret['is_modified'] = $this->is_modified;
1679 if(in_array("base",$this->multi_boxes)){
1680 $ret['orig_base']="Changed_by_Multi_Plug";
1681 $ret['base']=$this->base;
1682 }
1683 return($ret);
1684 }
1687 function multiple_save_object()
1688 {
1689 plugin::multiple_save_object();
1691 /* Get pw_storage mode */
1692 if (isset($_POST['pw_storage'])){
1693 foreach(array("pw_storage") as $val){
1694 if(isset($_POST[$val])){
1695 $data= validate(get_post($val));
1696 if ($data != $this->$val){
1697 $this->is_modified= TRUE;
1698 }
1699 $this->$val= $data;
1700 }
1701 }
1702 }
1703 if(isset($_POST['base'])){
1704 $this->base = get_post('base');
1705 }
1707 if(isset($_POST['user_mulitple_edit'])){
1708 foreach(array("base","pw_storage","edit_picture") as $val){
1709 if(isset($_POST["use_".$val])){
1710 $this->multi_boxes[] = $val;
1711 }
1712 }
1713 }
1714 }
1717 function multiple_check()
1718 {
1719 /* Call check() to set new_dn correctly ... */
1720 $message = plugin::multiple_check();
1722 /* Set the new acl base */
1723 if($this->dn == "new") {
1724 $this->set_acl_base($this->base);
1725 }
1726 if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1727 $message[]= msgPool::invalid(_("Homepage"));
1728 }
1729 if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1730 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1731 }
1732 if (!tests::is_phone_nr($this->facsimileTelephoneNumber) && in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1733 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1734 }
1735 if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1736 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1737 }
1738 if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1739 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1740 }
1741 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1742 $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1743 }
1744 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1745 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1746 }
1747 return($message);
1748 }
1752 function multiple_execute()
1753 {
1754 return($this->execute());
1755 }
1758 }
1760 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1761 ?>