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 /* The attribute gotoLastSystemLogin represents the timestamp of the last
41 successfull login on the users workstation.
42 Read the FAQ to get a hint about how to configure this.
43 */
44 var $gotoLastSystemLogin = "";
46 /* Plugin specific values */
47 var $base= "";
48 var $orig_base= "";
49 var $cn= "";
50 var $new_dn= "";
51 var $personalTitle= "";
52 var $academicTitle= "";
53 var $homePostalAddress= "";
54 var $homePhone= "";
55 var $labeledURI= "";
56 var $o= "";
57 var $ou= "";
58 var $departmentNumber= "";
59 var $employeeNumber= "";
60 var $employeeType= "";
61 var $roomNumber= "";
62 var $telephoneNumber= "";
63 var $facsimileTelephoneNumber= "";
64 var $mobile= "";
65 var $pager= "";
66 var $l= "";
67 var $st= "";
68 var $postalAddress= "";
69 var $dateOfBirth;
70 var $use_dob= "0";
71 var $gender="0";
72 var $preferredLanguage="0";
74 var $jpegPhoto= "*removed*";
75 var $photoData= "";
76 var $old_jpegPhoto= "";
77 var $old_photoData= "";
78 var $cert_dialog= FALSE;
79 var $picture_dialog= FALSE;
80 var $pwObject= NULL;
82 var $userPKCS12= "";
83 var $userSMIMECertificate= "";
84 var $userCertificate= "";
85 var $certificateSerialNumber= "";
86 var $old_certificateSerialNumber= "";
87 var $old_userPKCS12= "";
88 var $old_userSMIMECertificate= "";
89 var $old_userCertificate= "";
91 var $gouvernmentOrganizationalUnit= "";
92 var $houseIdentifier= "";
93 var $street= "";
94 var $postalCode= "";
95 var $vocation= "";
96 var $ivbbLastDeliveryCollective= "";
97 var $gouvernmentOrganizationalPersonLocality= "";
98 var $gouvernmentOrganizationalUnitDescription= "";
99 var $gouvernmentOrganizationalUnitSubjectArea= "";
100 var $functionalTitle= "";
101 var $role= "";
102 var $publicVisible= "";
104 var $orig_dn;
105 var $dialog;
107 /* variables to trigger password changes */
108 var $pw_storage= "md5";
109 var $last_pw_storage= "unset";
110 var $had_userCertificate= FALSE;
112 var $view_logged = FALSE;
114 /* attribute list for save action */
115 var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
116 "homePostalAddress", "homePhone", "labeledURI", "ou", "o", "dateOfBirth", "gender","preferredLanguage",
117 "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
118 "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
119 "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate");
121 var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson",
122 "gosaAccount");
124 /* attributes that are part of the government mode */
125 var $govattrs= array("gouvernmentOrganizationalUnit", "houseIdentifier", "vocation",
126 "ivbbLastDeliveryCollective", "gouvernmentOrganizationalPersonLocality",
127 "gouvernmentOrganizationalUnitDescription","gouvernmentOrganizationalUnitSubjectArea",
128 "functionalTitle", "certificateSerialNumber", "publicVisible", "street", "role",
129 "postalCode");
131 var $multiple_support = TRUE;
133 var $governmentmode = FALSE;
135 /* constructor, if 'dn' is set, the node loads the given
136 'dn' from LDAP */
137 function user (&$config, $dn= NULL)
138 {
139 $this->config= $config;
140 /* Configuration is fine, allways */
141 if($this->config->get_cfg_value("honourIvbbAttributes") == "true"){
142 $this->governmentmode = TRUE;
143 $this->attributes=array_merge($this->attributes,$this->govattrs);
144 }
146 /* Load base attributes */
147 plugin::plugin ($config, $dn);
149 /* If gotoLastSystemLogin is available read it from ldap and create a readable
150 date time string, fallback to sambaLogonTime if available.
151 */
152 if(isset($this->attrs['gotoLastSystemLogin'][0]) && preg_match("/^[0-9]*$/",$this->attrs['gotoLastSystemLogin'][0])){
153 $this->gotoLastSystemLogin = date("d.m.Y H:i:s", strtotime($this->attrs['gotoLastSystemLogin'][0]));
154 } else if(isset($this->attrs['sambaLogonTime'][0]) && preg_match("/^[0-9]*$/",$this->attrs['sambaLogonTime'][0])){
155 $this->gotoLastSystemLogin = date("d.m.Y H:i:s", $this->attrs['sambaLogonTime'][0]);
156 }
158 $this->orig_dn = $this->dn;
159 $this->new_dn = $dn;
161 if ($this->governmentmode){
162 /* Fix public visible attribute if unset */
163 if (!isset($this->attrs['publicVisible'])){
164 $this->publicVisible == "nein";
165 }
166 }
168 /* Load government mode attributes */
169 if ($this->governmentmode){
170 /* Copy all attributs */
171 foreach ($this->govattrs as $val){
172 if (isset($this->attrs["$val"][0])){
173 $this->$val= $this->attrs["$val"][0];
174 }
175 }
176 }
178 /* Create me for new accounts */
179 if ($dn == "new"){
180 $this->is_account= TRUE;
181 }
183 /* Make hash default to md5 if not set in config */
184 $hash= $this->config->get_cfg_value("passwordDefaultHash", "crypt/md5");
186 /* Load data from LDAP? */
187 if ($dn !== NULL){
189 /* Do base conversation */
190 if ($this->dn == "new"){
191 $ui= get_userinfo();
192 $this->base= dn2base($ui->dn);
193 } else {
194 $this->base= dn2base($dn);
195 }
197 /* get password storage type */
198 if (isset ($this->attrs['userPassword'][0])){
199 /* Initialize local array */
200 $matches= array();
201 if (preg_match ("/^{[^}]+}/", $this->attrs['userPassword'][0])){
202 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
203 if(is_object($tmp)){
204 $this->pw_storage= $tmp->get_hash();
205 }
207 } else {
208 if ($this->attrs['userPassword'][0] != ""){
209 $this->pw_storage= "clear";
210 } else {
211 $this->pw_storage= $hash;
212 }
213 }
214 } else {
215 /* Preset with vaule from configuration */
216 $this->pw_storage= $hash;
217 }
219 /* Load extra attributes: certificate and picture */
220 $this->load_cert();
221 $this->load_picture();
222 if ($this->userCertificate != ""){
223 $this->had_userCertificate= TRUE;
224 }
225 }
227 /* Reset password storage indicator, used by password_change_needed() */
228 if ($dn == "new"){
229 $this->last_pw_storage= "unset";
230 } else {
231 $this->last_pw_storage= $this->pw_storage;
232 }
234 /* Generate dateOfBirth entry */
235 if (isset ($this->attrs['dateOfBirth'])){
236 /* This entry is ISO 8601 conform */
237 list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
239 $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
240 $this->use_dob= "1";
241 } else {
242 $this->use_dob= "0";
243 }
245 /* Put gender attribute to upper case */
246 if (isset ($this->attrs['gender'])){
247 $this->gender= strtoupper($this->attrs['gender'][0]);
248 }
250 $this->orig_base = $this->base;
251 }
256 /* execute generates the html output for this node */
257 function execute()
258 {
259 /* Call parent execute */
260 plugin::execute();
262 /* Log view */
263 if($this->is_account && !$this->view_logged){
264 $this->view_logged = TRUE;
265 new log("view","users/".get_class($this),$this->dn);
266 }
268 $smarty= get_smarty();
269 $smarty->assign("gotoLastSystemLogin",$this->gotoLastSystemLogin);
271 /* Fill calendar */
272 if ($this->dateOfBirth == "0"){
273 $date= getdate();
274 } else {
275 if(is_array($this->dateOfBirth)){
276 $date = $this->dateOfBirth;
278 // Trigger on dates like 1985-04-01, getdate only understands timestamps
279 } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
280 $date= getdate(strtotime($this->dateOfBirth));
282 } else {
283 $date = getdate($this->dateOfBirth);
284 }
285 }
287 $days= array();
288 for($d= 1; $d<32; $d++){
289 $days[$d]= $d;
290 }
291 $years= array();
293 if(($date['year']-100)<1901){
294 $start = 1901;
295 }else{
296 $start = $date['year']-100;
297 }
299 $end = $start +100;
301 for($y= $start; $y<=$end; $y++){
302 $years[]= $y;
303 }
304 $years['-']= "- ";
305 $months= msgPool::months();
306 $months['-'] = '- ';
308 $smarty->assign("day", $date["mday"]);
309 $smarty->assign("days", $days);
310 $smarty->assign("months", $months);
311 $smarty->assign("month", $date["mon"]-1);
312 $smarty->assign("years", $years);
313 $smarty->assign("year", $date["year"]);
315 /* Assign sex */
316 $sex= array(0 => " ", "F" => _("female"), "M" => _("male"));
317 $smarty->assign("gender_list", $sex);
318 $language= array_merge(array(0 => " ") ,get_languages(TRUE));
319 $smarty->assign("preferredLanguage_list", $language);
321 /* Get random number for pictures */
322 srand((double)microtime()*1000000);
323 $smarty->assign("rand", rand(0, 10000));
326 /* Do we represent a valid gosaAccount? */
327 if (!$this->is_account){
328 $str = "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
329 msgPool::noValidExtension("GOsa")."</b>";
330 return($str);
331 }
333 /* Base select dialog */
334 $once = true;
335 foreach($_POST as $name => $value){
336 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
337 $once = false;
338 $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
339 $this->dialog->setCurrentBase($this->base);
340 }
341 }
343 /* Password configure dialog handling */
344 if(is_object($this->pwObject) && $this->pwObject->display){
345 $output= $this->pwObject->configure();
346 if ($output != ""){
347 $this->dialog= TRUE;
348 return $output;
349 }
350 $this->dialog= false;
351 }
353 /* Dialog handling */
354 if(is_object($this->dialog)){
355 /* Must be called before save_object */
356 $this->dialog->save_object();
358 if($this->dialog->isClosed()){
359 $this->dialog = false;
360 }elseif($this->dialog->isSelected()){
362 /* check if selected base is allowed to move to / create a new object */
363 $tmp = $this->get_allowed_bases();
364 if(isset($tmp[$this->dialog->isSelected()])){
365 $this->base = $this->dialog->isSelected();
366 }
367 $this->dialog= false;
368 }else{
369 return($this->dialog->execute());
370 }
371 }
373 /* Want password method editing? */
374 if ($this->acl_is_writeable("userPassword")){
375 if (isset($_POST['edit_pw_method'])){
376 if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
377 $temp= passwordMethod::get_available_methods();
378 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
379 }
380 $this->pwObject->display = TRUE;
381 $this->dialog= TRUE;
382 return ($this->pwObject->configure());
383 }
384 }
386 /* Want picture edit dialog? */
387 if($this->acl_is_writeable("userPicture")) {
388 if (isset($_POST['edit_picture'])){
389 /* Save values for later recovery, in case some presses
390 the cancel button. */
391 $this->old_jpegPhoto= $this->jpegPhoto;
392 $this->old_photoData= $this->photoData;
393 $this->picture_dialog= TRUE;
394 $this->dialog= TRUE;
395 }
396 }
398 /* Remove picture? */
399 if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))) ){
400 if (isset($_POST['picture_remove'])){
401 $this->set_picture ();
402 $this->jpegPhoto= "*removed*";
403 $this->is_modified= TRUE;
404 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
405 }
406 }
408 /* Save picture */
409 if (isset($_POST['picture_edit_finish'])){
411 /* Check for clean upload */
412 if ($_FILES['picture_file']['name'] != ""){
413 if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
414 msg_dialog::display(_("Error"), _("Cannot upload file!"), ERROR_DIALOG);
415 }else{
416 /* Activate new picture */
417 $this->set_picture($_FILES['picture_file']['tmp_name']);
418 }
419 }
420 $this->picture_dialog= FALSE;
421 $this->dialog= FALSE;
422 $this->is_modified= TRUE;
423 }
426 /* Cancel picture */
427 if (isset($_POST['picture_edit_cancel'])){
429 /* Restore values */
430 $this->jpegPhoto= $this->old_jpegPhoto;
431 $this->photoData= $this->old_photoData;
433 /* Update picture */
434 session::set('binary',$this->photoData);
435 session::set('binarytype',"image/jpeg");
436 $this->picture_dialog= FALSE;
437 $this->dialog= FALSE;
438 }
440 /* Toggle dateOfBirth information */
441 if (isset($_POST['set_dob'])){
442 $this->use_dob= ($this->use_dob == "0")?"1":"0";
443 }
446 /* Want certificate= */
447 if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
449 /* Save original values for later reconstruction */
450 foreach (array("certificateSerialNumber", "userCertificate",
451 "userSMIMECertificate", "userPKCS12") as $val){
453 $oval= "old_$val";
454 $this->$oval= $this->$val;
455 }
457 $this->cert_dialog= TRUE;
458 $this->dialog= TRUE;
459 }
462 /* Cancel certificate dialog */
463 if (isset($_POST['cert_edit_cancel'])){
465 /* Restore original values in case of 'cancel' */
466 foreach (array("certificateSerialNumber", "userCertificate",
467 "userSMIMECertificate", "userPKCS12") as $val){
469 $oval= "old_$val";
470 $this->$val= $this->$oval;
471 }
472 $this->cert_dialog= FALSE;
473 $this->dialog= FALSE;
474 }
477 /* Remove certificate? */
478 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
479 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
480 if (isset($_POST["remove_$val"])){
482 /* Reset specified cert*/
483 $this->$val= "";
484 $this->is_modified= TRUE;
485 }
486 }
487 }
489 /* Upload new cert and close dialog? */
490 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
492 $fail =false;
494 if (isset($_POST['cert_edit_finish'])){
496 /* for all certificates do */
497 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
498 as $val){
500 /* Check for clean upload */
501 if (array_key_exists($val."_file", $_FILES) &&
502 array_key_exists('name', $_FILES[$val."_file"]) &&
503 $_FILES[$val."_file"]['name'] != "" &&
504 is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
505 $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
506 }
507 }
509 /* Save serial number */
510 if (isset($_POST["certificateSerialNumber"]) &&
511 $_POST["certificateSerialNumber"] != ""){
513 if (!tests::is_id($_POST["certificateSerialNumber"])){
514 $fail = true;
515 msg_dialog::display(_("Error"), msgPool::invalid(_("Serial number"),$_POST["certificateSerialNumber"],"/[0-9]/"),ERROR_DIALOG);
517 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
518 if ($this->$cert != ""){
519 $smarty->assign("$cert"."_state", "true");
520 } else {
521 $smarty->assign("$cert"."_state", "");
522 }
523 }
524 }
526 $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
527 $this->is_modified= TRUE;
528 }
529 if(!$fail){
530 $this->cert_dialog= FALSE;
531 $this->dialog= FALSE;
532 }
533 }
534 }
535 /* Display picture dialog */
536 if ($this->picture_dialog){
537 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
538 }
540 /* Display cert dialog */
541 if ($this->cert_dialog){
542 $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
543 $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
544 $smarty->assign("certificateSerialNumber",$this->certificateSerialNumber);
546 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
547 if ($this->$cert != ""){
548 /* import certificate */
549 $certificate = new certificate;
550 $certificate->import($this->$cert);
552 /* Read out data*/
553 $timeto = $certificate->getvalidto_date();
554 $timefrom = $certificate->getvalidfrom_date();
557 /* Additional info if start end time is '0' */
558 $add_str_info = "";
559 if($timeto == 0 && $timefrom == 0){
560 $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
561 }
563 $str = "<table summary=\"\" border=0>
564 <tr>
565 <td style='vertical-align:top'>CN</td>
566 <td>".preg_replace("/ /", " ", $certificate->getname())."</td>
567 </tr>
568 </table><br>".
570 sprintf(_("Certificate is valid from %s to %s and is currently %s."),
571 "<b>".date('d M Y',$timefrom)."</b>",
572 "<b>".date('d M Y',$timeto)."</b>",
573 $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
574 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
576 $smarty->assign($cert."info",$str);
577 $smarty->assign($cert."_state","true");
578 } else {
579 $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
580 $smarty->assign($cert."_state","");
581 }
582 }
584 if($this->governmentmode){
585 $smarty->assign("honourIvbbAttributes", "true");
586 }else{
587 $smarty->assign("honourIvbbAttributes", "false");
588 }
589 $smarty->assign("governmentmode", $this->governmentmode);
590 return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
591 }
593 /* Prepare password hashes */
594 if ($this->pw_storage == ""){
595 $this->pw_storage= $this->config->get_cfg_value("hash");
596 }
598 $temp= passwordMethod::get_available_methods();
599 $is_configurable= FALSE;
600 $hashes = $temp['name'];
601 if(isset($temp[$this->pw_storage])){
602 $test= new $temp[$this->pw_storage]($this->config);
603 $is_configurable= $test->is_configurable();
604 }else{
605 new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
606 }
609 /* Create password methods array */
610 $pwd_methods = array();
611 foreach($hashes as $id => $name){
612 if(!empty($temp['desc'][$id])){
613 $pwd_methods[$name] = $name." (".$temp['desc'][$id].")";
614 }else{
615 $pwd_methods[$name] = $name;
616 }
617 }
619 /* Load attributes and acl's */
620 $ui =get_userinfo();
621 foreach($this->attributes as $val){
622 $smarty->assign("$val", $this->$val);
623 if(in_array($val,$this->multi_boxes)){
624 $smarty->assign("use_".$val,TRUE);
625 }else{
626 $smarty->assign("use_".$val,FALSE);
627 }
628 }
629 foreach(array("base","pw_storage","edit_picture") as $val){
630 if(in_array($val,$this->multi_boxes)){
631 $smarty->assign("use_".$val,TRUE);
632 }else{
633 $smarty->assign("use_".$val,FALSE);
634 }
635 }
637 /* Set acls */
638 $tmp = $this->plinfo();
639 foreach($tmp['plProvidedAcls'] as $val => $translation){
640 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
641 }
643 $smarty->assign("pwmode", $pwd_methods);
644 $smarty->assign("pwmode_select", $this->pw_storage);
645 $smarty->assign("pw_configurable", $is_configurable);
646 $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !session::is_set('edit'))));
647 $smarty->assign("base_select", $this->base);
649 if(!session::is_set('edit')){
650 $smarty->assign("CertificatesACL","");
651 }else{
652 $smarty->assign("CertificatesACL", $this->getacl("Certificate"));
653 }
655 $smarty->assign("userPictureACL", $this->getacl("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
656 $smarty->assign("userPicture_is_readable", $this->acl_is_readable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
658 /* Create base acls */
659 $tmp = @$this->allowedBasesToMoveTo();
660 $smarty->assign("bases", $tmp);
662 /* Save government mode attributes */
663 if($this->governmentmode){
664 $smarty->assign("governmentmode", "true");
665 $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
666 "internet,ivbv", "internet,testa", "internet,ivbv,testa");
667 $smarty->assign("ivbbmodes", $ivbbmodes);
668 foreach ($this->govattrs as $val){
669 $smarty->assign("$val", $this->$val);
670 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
671 }
672 } else {
673 $smarty->assign("governmentmode", "false");
674 }
676 /* Special mode for uid */
677 $uidACL= $this->getacl("uid",(!is_object($this->parent) && !session::is_set('edit')));
678 if (isset ($this->dn)){
679 if ($this->dn != "new"){
680 $uidACL= preg_replace("/w/","",$uidACL);
681 }
682 } else {
683 $uidACL= preg_replace("/w/","",$uidACL);
684 }
686 $smarty->assign("uidACL", $uidACL);
687 $smarty->assign("is_template", $this->is_template);
688 $smarty->assign("use_dob", $this->use_dob);
690 if (isset($this->parent)){
691 if (isset($this->parent->by_object['phoneAccount']) &&
692 $this->parent->by_object['phoneAccount']->is_account){
693 $smarty->assign("has_phoneaccount", "true");
694 } else {
695 $smarty->assign("has_phoneaccount", "false");
696 }
697 } else {
698 $smarty->assign("has_phoneaccount", "false");
699 }
700 $smarty->assign("multiple_support" , $this->multiple_support_active);
701 return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
702 }
705 /* remove object from parent */
706 function remove_from_parent()
707 {
708 /* Only remove valid accounts */
709 if(!$this->initially_was_account) return;
711 /* Remove password extension */
712 $temp= passwordMethod::get_available_methods();
714 /* Remove password method from user account */
715 if(isset($temp[$this->pw_storage]) && class_available($temp[$this->pw_storage])){
716 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
717 $this->pwObject->remove_from_parent();
718 }
720 /* Remove user */
721 $ldap= $this->config->get_ldap_link();
722 $ldap->rmdir ($this->dn);
723 if (!$ldap->success()){
724 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
725 }
727 new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
729 /* Delete references to groups */
730 $ldap->cd ($this->config->current['BASE']);
731 $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
732 while ($ldap->fetch()){
733 $g= new group($this->config, $ldap->getDN());
734 $g->removeUser($this->uid);
735 $g->save ();
736 }
738 /* Delete references to object groups */
739 $ldap->cd ($this->config->current['BASE']);
740 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
741 while ($ldap->fetch()){
742 $og= new ogroup($this->config, $ldap->getDN());
743 unset($og->member[$this->dn]);
744 $og->save ();
745 }
747 /* Delete references to roles */
748 $ldap->cd ($this->config->current['BASE']);
749 $ldap->search ("(&(objectClass=organizationalRole)(roleOccupant=".LDAP::prepare4filter($this->dn)."))", array("cn"));
750 while ($ldap->fetch()){
751 $role= new roleGeneric($this->config, $ldap->getDN());
752 $key = array_search($this->dn,$role->roleOccupant);
753 if($key !== FALSE){
754 unset($role->roleOccupant[$key]);
755 $role->reload();
756 $role->save ();
757 }
758 }
760 /* If needed, let the password method do some cleanup */
761 $tmp = new passwordMethod($this->config);
762 $available = $tmp->get_available_methods();
763 if (in_array_ics($this->pw_storage, $available['name'])){
764 $test= new $available[$this->pw_storage]($this->config);
765 $test->attrs= $this->attrs;
766 $test->dn= $this->dn;
767 $test->remove_from_parent();
768 }
770 /* Remove ACL dependencies too */
771 $tmp = new acl($this->config,$this->parent,$this->dn);
772 $tmp->remove_acl();
774 /* Optionally execute a command after we're done */
775 $this->handle_post_events("remove",array("uid" => $this->uid));
776 }
779 /* Save data to object */
780 function save_object()
781 {
782 if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
784 /* Make a backup of the current selected base */
785 $base_tmp = $this->base;
787 /* Parents save function */
788 plugin::save_object ();
790 /* Save government mode attributes */
791 if ($this->governmentmode){
792 foreach ($this->govattrs as $val){
793 if ($this->acl_is_writeable($val,(!is_object($this->parent) && !session::is_set('edit'))) && isset($_POST["$val"])){
794 $data= stripcslashes($_POST["$val"]);
795 if ($data != $this->$val){
796 $this->is_modified= TRUE;
797 }
798 $this->$val= $data;
799 }
800 }
801 }
803 /* In template mode, the uid is autogenerated... */
804 if ($this->is_template){
805 $this->uid= strtolower($this->sn);
806 $this->givenName= $this->sn;
807 }
809 /* Save base and pw_storage, since these are no LDAP attributes */
810 if (isset($_POST['base'])){
812 $tmp = $this->get_allowed_bases();
813 if(isset($tmp[$_POST['base']])){
814 $base= validate($_POST['base']);
815 if ($base != $this->base){
816 $this->is_modified= TRUE;
817 }
818 $this->base= $base;
819 }else{
820 $this->base = $base_tmp;
821 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
822 }
823 }
825 /* Get pw_storage mode */
826 if (isset($_POST['pw_storage'])){
827 foreach(array("pw_storage") as $val){
828 if(isset($_POST[$val])){
829 $data= validate($_POST[$val]);
830 if ($data != $this->$val){
831 $this->is_modified= TRUE;
832 }
833 $this->$val= $data;
834 }
835 }
836 }
838 if($this->pw_storage != $this->last_pw_storage && isset($_POST['pw_storage'])){
839 if ($this->acl_is_writeable("userPassword")){
840 $temp= passwordMethod::get_available_methods();
841 if (!is_object($this->pwObject) || !($this->pwObject instanceOf $temp[$this->pw_storage])){
842 foreach($temp as $id => $data){
843 if(isset($data['name']) && $data['name'] == $this->pw_storage && $data['is_configurable']){
844 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
845 break;
846 }
847 }
848 }
849 }
850 }
852 /* Save current cn
853 */
854 $this->cn = $this->givenName." ".$this->sn;
855 }
856 }
858 function rebind($ldap, $referral)
859 {
860 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
861 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
862 $this->error = "Success";
863 $this->hascon=true;
864 $this->reconnect= true;
865 return (0);
866 } else {
867 $this->error = "Could not bind to " . $credentials['ADMIN'];
868 return NULL;
869 }
870 }
873 /* Save data to LDAP, depending on is_account we save or delete */
874 function save()
875 {
876 /* Only force save of changes ....
877 If this attributes aren't changed, avoid saving.
878 */
880 if($this->gender=="0") $this->gender ="";
881 if($this->preferredLanguage=="0") $this->preferredLanguage ="";
883 /* First use parents methods to do some basic fillup in $this->attrs */
884 plugin::save ();
886 if ($this->use_dob == "1"){
887 /* 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. */
888 if(!is_array($this->attrs['dateOfBirth'])) {
889 $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
890 }
891 }
893 /* Remove additional objectClasses */
894 $tmp= array();
895 foreach ($this->attrs['objectClass'] as $key => $set){
896 $found= false;
897 foreach (array("ivbbentry", "gosaUserTemplate") as $val){
898 if (preg_match ("/^$set$/i", $val)){
899 $found= true;
900 break;
901 }
902 }
903 if (!$found){
904 $tmp[]= $set;
905 }
906 }
908 /* Replace the objectClass array. This is done because of the
909 separation into government and normal mode. */
910 $this->attrs['objectClass']= $tmp;
912 /* Add objectClasss for template mode? */
913 if ($this->is_template){
914 $this->attrs['objectClass'][]= "gosaUserTemplate";
915 }
917 /* Hard coded government mode? */
918 if ($this->governmentmode){
919 $this->attrs['objectClass'][]= "ivbbentry";
921 /* Copy standard attributes */
922 foreach ($this->govattrs as $val){
923 if ($this->$val != ""){
924 $this->attrs["$val"]= $this->$val;
925 } elseif (!$this->is_new) {
926 $this->attrs["$val"]= array();
927 }
928 }
930 /* Remove attribute if set to "nein" */
931 if ($this->publicVisible == "nein"){
932 $this->attrs['publicVisible']= array();
933 if($this->is_new){
934 unset($this->attrs['publicVisible']);
935 }else{
936 $this->attrs['publicVisible']=array();
937 }
939 }
941 }
943 /* Special handling for attribute userCertificate needed */
944 if ($this->userCertificate != ""){
945 $this->attrs["userCertificate;binary"]= $this->userCertificate;
946 $remove_userCertificate= false;
947 } else {
948 $remove_userCertificate= true;
949 }
951 /* Special handling for dateOfBirth value */
952 if ($this->use_dob != "1"){
953 if ($this->is_new) {
954 unset($this->attrs["dateOfBirth"]);
955 } else {
956 $this->attrs["dateOfBirth"]= array();
957 }
958 }
959 if (!$this->gender){
960 if ($this->is_new) {
961 unset($this->attrs["gender"]);
962 } else {
963 $this->attrs["gender"]= array();
964 }
965 }
966 if (!$this->preferredLanguage){
967 if ($this->is_new) {
968 unset($this->attrs["preferredLanguage"]);
969 } else {
970 $this->attrs["preferredLanguage"]= array();
971 }
972 }
974 /* Special handling for attribute jpegPhote needed, scale image via
975 image magick to 147x200 pixels and inject resulting data. */
976 if ($this->jpegPhoto == "*removed*"){
978 /* Reset attribute to avoid writing *removed* as value */
979 $this->attrs["jpegPhoto"] = array();
981 } else {
983 /* Fallback if there's no image magick inside PHP */
984 if (!function_exists("imagick_blob2image")){
985 /* Get temporary file name for conversation */
986 $fname = tempnam (TEMP_DIR, "GOsa");
988 /* Open file and write out photoData */
989 $fp = fopen ($fname, "w");
990 fwrite ($fp, $this->photoData);
991 fclose ($fp);
993 /* Build conversation query. Filename is generated automatically, so
994 we do not need any special security checks. Exec command and save
995 output. For PHP safe mode, you'll need a configuration which respects
996 image magick as executable... */
997 $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
998 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
999 $query, "Execute");
1001 /* Read data written by convert */
1002 $output= "";
1003 $sh= popen($query, 'r');
1004 while (!feof($sh)){
1005 $output.= fread($sh, 4096);
1006 }
1007 pclose($sh);
1009 unlink($fname);
1011 /* Save attribute */
1012 $this->attrs["jpegPhoto"] = $output;
1014 } else {
1016 /* Load the new uploaded Photo */
1017 if(!$handle = imagick_blob2image($this->photoData)) {
1018 new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
1019 }
1021 /* Resizing image to 147x200 and blur */
1022 if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
1023 new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
1024 }
1026 /* Converting image to JPEG */
1027 if(!imagick_convert($handle,"JPEG")) {
1028 new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
1029 }
1031 /* Creating binary Code for the Image */
1032 if(!$dump = imagick_image2blob($handle)){
1033 new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
1034 }
1036 /* Sending Image */
1037 $output= $dump;
1039 /* Save attribute */
1040 $this->attrs["jpegPhoto"] = $output;
1041 }
1043 }
1045 /* This only gets called when user is renaming himself */
1046 $ldap= $this->config->get_ldap_link();
1047 if ($this->dn != $this->new_dn){
1049 /* Write entry on new 'dn' */
1050 $this->update_acls($this->dn,$this->new_dn);
1051 $this->move($this->dn, $this->new_dn);
1053 /* Happen to use the new one */
1054 change_ui_dn($this->dn, $this->new_dn);
1055 $this->dn= $this->new_dn;
1056 }
1059 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1060 new entries. So do a check first... */
1061 $ldap->cat ($this->dn, array('dn'));
1062 if ($ldap->fetch()){
1063 $mode= "modify";
1064 } else {
1065 $mode= "add";
1066 $ldap->cd($this->config->current['BASE']);
1067 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1068 }
1070 /* Set password to some junk stuff in case of templates */
1071 if ($this->is_template){
1072 $temp= passwordMethod::get_available_methods();
1073 foreach($temp as $id => $data){
1074 if(isset($data['name']) && $data['name'] == $this->pw_storage){
1075 $tmp = new $temp[$this->pw_storage]($this->config,$this->dn);
1076 $tmp->set_hash($this->pw_storage);
1077 $this->attrs['userPassword'] = $tmp->create_template_hash($this->attrs);
1078 break;
1079 }
1080 }
1081 }
1083 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1084 $this->attributes, "Save via $mode");
1086 /* Finally write data with selected 'mode' */
1087 $this->cleanup();
1089 /* Update current locale settings, if we have edited ourselves */
1090 $ui = session::get('ui');
1091 if(isset($this->attrs['preferredLanguage']) && $this->dn == $ui->dn){
1092 $ui->language = $this->preferredLanguage;
1093 session::set('ui',$ui);
1094 session::set('Last_init_lang',"update");
1095 }
1097 $ldap->cd ($this->dn);
1098 $ldap->$mode ($this->attrs);
1099 if (!$ldap->success()){
1100 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1101 return (1);
1102 }
1104 /* Remove ACL dependencies too */
1105 if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1106 $tmp = new acl($this->config,$this->parent,$this->dn);
1107 $tmp->update_acl_membership($this->orig_dn,$this->dn);
1108 }
1110 if($mode == "modify"){
1111 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1112 }else{
1113 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1114 }
1116 /* Remove cert?
1117 For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1118 to work around myself. */
1119 if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1121 /* Reset array, assemble new, this should be reworked */
1122 $this->attrs= array();
1123 $this->attrs['userCertificate;binary']= array();
1125 /* Prepare connection */
1126 if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1127 die ("Could not connect to LDAP server");
1128 }
1129 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1130 if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("ldapFollowReferrals") == "true") {
1131 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1132 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1133 }
1134 if($this->config->get_cfg_value("ldapTLS") == "true"){
1135 ldap_start_tls($ds);
1136 }
1137 if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1138 $this->config->current['PASSWORD']))) {
1139 die ("Could not bind to LDAP");
1140 }
1142 /* Modify using attrs */
1143 ldap_mod_del($ds,$this->dn,$this->attrs);
1144 ldap_close($ds);
1145 }
1147 /* If needed, let the password method do some cleanup */
1148 if ($this->pw_storage != $this->last_pw_storage){
1149 $tmp = new passwordMethod($this->config);
1150 $available = $tmp->get_available_methods();
1151 if (in_array_ics($this->last_pw_storage, $available['name'])){
1152 $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1153 $test->attrs= $this->attrs;
1154 $test->remove_from_parent();
1155 }
1156 }
1158 /* Maybe the current password method want's to do some changes... */
1159 if (is_object($this->pwObject)){
1160 $this->pwObject->save($this->dn);
1161 }
1163 /* Optionally execute a command after we're done */
1164 if ($mode == "add"){
1165 $this->handle_post_events("add", array("uid" => $this->uid));
1166 } elseif ($this->is_modified){
1167 $this->handle_post_events("modify", array("uid" => $this->uid));
1168 }
1170 return (0);
1171 }
1174 function create_initial_rdn($pattern)
1175 {
1176 // Only generate single RDNs
1177 if (preg_match('/\+/', $pattern)){
1178 msg_dialog::display(_("Error"), _("Cannot build RDN: no + allowed to build sub RDN!"), ERROR_DIALOG);
1179 return "";
1180 }
1182 // Extract attribute
1183 $attribute= preg_replace('/=.*$/', '', $pattern);
1184 if (!in_array_ics($attribute, $this->attributes)) {
1185 msg_dialog::display(_("Error"), _("Cannot build RDN: attribute is not defined!"), ERROR_DIALOG);
1186 return "";
1187 }
1189 // Sort attributes for length
1190 $attrl= array();
1191 foreach ($this->attributes as $attr) {
1192 $attrl[$attr]= strlen($attr);
1193 }
1194 arsort($attrl);
1196 // Walk thru sorted attributes and replace them in pattern
1197 foreach ($attrl as $attr => $dummy) {
1198 if (!is_array($this->$attr)){
1199 $pattern= preg_replace("/%$attr/", $this->$attr, $pattern);
1200 } else {
1201 msg_dialog::display(_("Error"), _("Cannot build RDN: invalid attribute parameters!"), ERROR_DIALOG);
1202 break;
1203 }
1204 }
1206 // Internally assign value
1207 $this->$attribute= preg_replace('/^[^=]+=/', '', $pattern);
1209 return $pattern;
1210 }
1213 function update_new_dn()
1214 {
1215 // Alternative way to handle DN
1216 $pattern= $this->config->get_cfg_value("accountRDN");
1217 if ($pattern != "") {
1218 $rdn= $this->create_initial_rdn($pattern);
1219 $attribute= preg_replace('/=.*$/', '', $rdn);
1220 $value= preg_replace('/^[^=]+=$/', '', $rdn);
1222 /* Don't touch dn, if $attribute hasn't changed */
1223 if (isset($this->saved_attributes[$attribute]) && $this->saved_attributes[$attribute] == $this->$attribute &&
1224 $this->orig_base == $this->base ){
1225 $this->new_dn= $this->dn;
1226 } else {
1227 $this->new_dn= $this->create_unique_dn2($rdn, get_people_ou().$this->base);
1228 }
1230 // Original way to handle DN
1231 } else {
1233 $pt= "";
1234 if($this->config->get_cfg_value("personalTitleInDN") == "true"){
1235 if(!empty($this->personalTitle)){
1236 $pt = $this->personalTitle." ";
1237 }
1238 }
1240 $this->cn= $pt.$this->givenName." ".$this->sn;
1242 /* Permissions for that base? */
1243 if ($this->config->get_cfg_value("accountPrimaryAttribute") == "uid"){
1244 $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1245 } else {
1246 /* Don't touch dn, if cn hasn't changed */
1247 if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1248 $this->orig_base == $this->base ){
1249 $this->new_dn= $this->dn;
1250 } else {
1251 $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1252 }
1253 }
1254 }
1255 }
1258 /* Check formular input */
1259 function check()
1260 {
1261 /* Call common method to give check the hook */
1262 $message= plugin::check();
1264 /* Configurable password methods should be configured initially.
1265 */
1266 if($this->last_pw_storage != $this->pw_storage){
1267 $temp= passwordMethod::get_available_methods();
1268 foreach($temp['name'] as $id => $name){
1269 if($name == $this->pw_storage){
1270 if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1271 $message[] = _("The selected password method requires initial configuration!");
1272 }
1273 break;
1274 }
1275 }
1276 }
1278 $this->update_new_dn();
1280 /* Set the new acl base */
1281 if($this->dn == "new") {
1282 $this->set_acl_base($this->base);
1283 }
1285 /* Check if we are allowed to create/move this user
1286 */
1288 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1289 $message[]= msgPool::permCreate();
1290 }elseif($this->orig_dn != "new" && $this->new_dn != $this->orig_dn && !$this->acl_is_moveable($this->base)){
1291 $message[]= msgPool::permMove();
1292 }
1294 /* UID already used? */
1295 $ldap= $this->config->get_ldap_link();
1296 $ldap->cd($this->config->current['BASE']);
1297 $ldap->search("(uid=$this->uid)", array("uid"));
1298 $ldap->fetch();
1299 if ($ldap->count() != 0 && $this->dn == 'new'){
1300 $message[]= msgPool::duplicated(_("Login"));
1301 }
1303 /* In template mode, the uid and givenName are autogenerated... */
1304 if ($this->sn == ""){
1305 $message[]= msgPool::required(_("Name"));
1306 }
1308 if (!$this->is_template){
1309 if ($this->givenName == ""){
1310 $message[]= msgPool::required(_("Given name"));
1311 }
1312 if ($this->uid == ""){
1313 $message[]= msgPool::required(_("Login"));
1314 }
1315 if ($this->config->get_cfg_value("accountPrimaryAttribute") != "uid"){
1316 $ldap->cat($this->new_dn);
1317 if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1318 $message[]= msgPool::duplicated(_("Name"));
1319 }
1320 }
1321 }
1323 /* Check for valid input */
1324 if ($this->is_modified && !tests::is_uid($this->uid)){
1326 if (strict_uid_mode()){
1327 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1328 } else {
1329 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1330 }
1331 }
1332 if (!tests::is_url($this->labeledURI)){
1333 $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1334 }
1336 /* Check phone numbers */
1337 if (!tests::is_phone_nr($this->telephoneNumber)){
1338 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1339 }
1340 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1341 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1342 }
1343 if (!tests::is_phone_nr($this->mobile)){
1344 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1345 }
1346 if (!tests::is_phone_nr($this->pager)){
1347 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1348 }
1350 /* Check for reserved characers */
1351 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1352 $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1353 }
1354 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1355 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1356 }
1358 return $message;
1359 }
1362 /* Indicate whether a password change is needed or not */
1363 function password_change_needed()
1364 {
1365 if(in_array("pw_storage",$this->multi_boxes)){
1366 return(TRUE);
1367 }
1368 return($this->pw_storage != $this->last_pw_storage && !$this->is_template);
1369 }
1372 /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1373 function load_picture()
1374 {
1375 $ldap = $this->config->get_ldap_link();
1376 $ldap->cd ($this->dn);
1377 $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1379 if((!$data) || ($data == "*removed*")){
1381 /* In case we don't get an entry, load a default picture */
1382 $this->set_picture ();
1383 $this->jpegPhoto= "*removed*";
1384 }else{
1386 /* Set picture */
1387 $this->photoData= $data;
1388 session::set('binary',$this->photoData);
1389 session::set('binarytype',"image/jpeg");
1390 $this->jpegPhoto= "";
1391 }
1392 }
1395 /* Load a certificate from LDAP, this is going to be simplified later on */
1396 function load_cert()
1397 {
1398 $ds= ldap_connect($this->config->current['SERVER']);
1399 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1400 if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("ldapFollowReferrals") == "true"){
1401 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1402 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1403 }
1404 if ($this->config->get_cfg_value("ldapTLS") == "true"){
1405 ldap_start_tls($ds);
1406 }
1408 $r= ldap_bind($ds);
1409 $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1411 if ($sr) {
1412 $ei= @ldap_first_entry($ds, $sr);
1414 if ($ei) {
1415 if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1416 $this->userCertificate= "";
1417 } else {
1418 $this->userCertificate= $info[0];
1419 }
1420 }
1421 } else {
1422 $this->userCertificate= "";
1423 }
1425 ldap_unbind($ds);
1426 }
1429 /* Load picture from file to object */
1430 function set_picture($filename ="")
1431 {
1432 if (!is_file($filename) || $filename =="" ){
1433 $filename= "./plugins/users/images/default.jpg";
1434 $this->jpegPhoto= "*removed*";
1435 }
1437 $fd = fopen ($filename, "rb");
1438 $this->photoData= fread ($fd, filesize ($filename));
1439 session::set('binary',$this->photoData);
1440 session::set('binarytype',"image/jpeg");
1441 $this->jpegPhoto= "";
1443 fclose ($fd);
1444 }
1447 /* Load certificate from file to object */
1448 function set_cert($cert, $filename)
1449 {
1450 if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1451 $fd = fopen ($filename, "rb");
1452 if (filesize($filename)>0) {
1453 $this->$cert= fread ($fd, filesize ($filename));
1454 fclose ($fd);
1455 $this->is_modified= TRUE;
1456 } else {
1457 msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1458 }
1459 }
1461 /* Adapt from given 'dn' */
1462 function adapt_from_template($dn, $skip= array())
1463 {
1464 plugin::adapt_from_template($dn, $skip);
1466 /* Get password method from template
1467 */
1468 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
1469 if(is_object($tmp)){
1470 if($tmp->is_configurable()){
1471 $tmp->adapt_from_template($dn);
1472 $this->pwObject = &$tmp;
1473 }
1474 $this->pw_storage= $tmp->get_hash();
1475 }
1477 /* Get base */
1478 $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1480 if($this->governmentmode){
1482 /* Walk through govattrs */
1483 foreach ($this->govattrs as $val){
1485 if (in_array($val, $skip)){
1486 continue;
1487 }
1489 if (isset($this->attrs["$val"][0])){
1491 /* If attribute is set, replace dynamic parts:
1492 %sn, %givenName and %uid. Fill these in our local variables. */
1493 $value= $this->attrs["$val"][0];
1495 foreach (array("sn", "givenName", "uid") as $repl){
1496 if (preg_match("/%$repl/i", $value)){
1497 $value= preg_replace ("/%$repl/i",
1498 $this->parent->$repl, $value);
1499 }
1500 }
1501 $this->$val= $value;
1502 }
1503 }
1504 }
1506 /* Get back uid/sn/givenName - only write if nothing's skipped */
1507 if ($this->parent !== NULL && count($skip) == 0){
1508 $this->uid= $this->parent->uid;
1509 $this->sn= $this->parent->sn;
1510 $this->givenName= $this->parent->givenName;
1511 }
1512 }
1515 /* This avoids that users move themselves out of their rights.
1516 */
1517 function allowedBasesToMoveTo()
1518 {
1519 /* Get bases */
1520 $bases = $this->get_allowed_bases();
1521 return($bases);
1522 }
1525 function getCopyDialog()
1526 {
1527 $str = "";
1529 session::set('binary',$this->photoData);
1530 session::set('binarytype',"image/jpeg");
1532 /* Get random number for pictures */
1533 srand((double)microtime()*1000000);
1534 $rand = rand(0, 10000);
1536 $smarty = get_smarty();
1538 $smarty->assign("passwordTodo","clear");
1540 if(isset($_POST['passwordTodo'])){
1541 $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1542 }
1544 $smarty->assign("sn", $this->sn);
1545 $smarty->assign("givenName",$this->givenName);
1546 $smarty->assign("uid", $this->uid);
1547 $smarty->assign("rand", $rand);
1548 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1551 $ret = array();
1552 $ret['string'] = $str;
1553 $ret['status'] = "";
1554 return($ret);
1555 }
1557 function saveCopyDialog()
1558 {
1559 /* Set_acl_base */
1560 $this->set_acl_base($this->base);
1562 if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1563 $this->set_picture($_FILES['picture_file']['tmp_name']);
1564 }
1566 /* Remove picture? */
1567 if (isset($_POST['picture_remove'])){
1568 $this->jpegPhoto= "*removed*";
1569 $this->set_picture ("./plugins/users/images/default.jpg");
1570 $this->is_modified= TRUE;
1571 }
1573 $attrs = array("uid","givenName","sn");
1574 foreach($attrs as $attr){
1575 if(isset($_POST[$attr])){
1576 $this->$attr = $_POST[$attr];
1577 }
1578 }
1579 }
1582 function PrepareForCopyPaste($source)
1583 {
1584 plugin::PrepareForCopyPaste($source);
1586 /* Reset certificate information addepted from source user
1587 to avoid setting the same user certificate for the destination user. */
1588 $this->userPKCS12= "";
1589 $this->userSMIMECertificate= "";
1590 $this->userCertificate= "";
1591 $this->certificateSerialNumber= "";
1592 $this->old_certificateSerialNumber= "";
1593 $this->old_userPKCS12= "";
1594 $this->old_userSMIMECertificate= "";
1595 $this->old_userCertificate= "";
1596 }
1599 static function plInfo()
1600 {
1602 $govattrs= array(
1603 "gouvernmentOrganizationalUnit" => _("Unit"),
1604 "houseIdentifier" => _("House identifier"),
1605 "vocation" => _("Vocation"),
1606 "ivbbLastDeliveryCollective" => _("Last delivery"),
1607 "gouvernmentOrganizationalPersonLocality" => _("Person locality"),
1608 "gouvernmentOrganizationalUnitDescription" => _("Unit description"),
1609 "gouvernmentOrganizationalUnitSubjectArea" => _("Subject area"),
1610 "functionalTitle" => _("Functional title"),
1611 "certificateSerialNumber" => _("Certificate serial number"),
1612 "publicVisible" => _("Public visible"),
1613 "street" => _("Street"),
1614 "role" => _("Role"),
1615 "postalCode" => _("Postal code"));
1617 $ret = array(
1618 "plShortName" => _("Generic"),
1619 "plDescription" => _("Generic user settings"),
1620 "plSelfModify" => TRUE,
1621 "plDepends" => array(),
1622 "plPriority" => 1,
1623 "plSection" => array("personal" => _("My account")),
1624 "plCategory" => array("users" => array("description" => _("Users"),
1625 "objectClass" => "gosaAccount")),
1627 "plProvidedAcls" => array(
1629 "sn" => _("Surname"),
1630 "givenName" => _("Given name"),
1631 "uid" => _("User identification"),
1632 "personalTitle" => _("Personal title"),
1633 "academicTitle" => _("Academic title"),
1635 "dateOfBirth" => _("Date of birth"),
1636 "gender" => _("Gender"),
1637 "preferredLanguage" => _("Preferred language"),
1638 "base" => _("Base"),
1640 "userPicture" => _("User picture"),
1642 "o" => _("Organization"),
1643 "ou" => _("Department"),
1644 "departmentNumber" => _("Department number"),
1645 "employeeNumber" => _("Employee number"),
1646 "employeeType" => _("Employee type"),
1648 "roomNumber" => _("Room number"),
1649 "telephoneNumber" => _("Telefon number"),
1650 "pager" => _("Pager number"),
1651 "mobile" => _("Mobile number"),
1652 "facsimileTelephoneNumber" => _("Fax number"),
1654 "st" => _("State"),
1655 "l" => _("Location"),
1656 "postalAddress" => _("Postal address"),
1658 "homePostalAddress" => _("Home postal address"),
1659 "homePhone" => _("Home phone number"),
1660 "labeledURI" => _("Homepage"),
1661 "userPassword" => _("User password method"),
1662 "Certificate" => _("User certificates"))
1664 );
1666 /* Append government attributes if required */
1667 global $config;
1668 if($config->get_cfg_value("honourIvbbAttributes") == "true"){
1669 foreach($govattrs as $attr => $desc){
1670 $ret["plProvidedAcls"][$attr] = $desc;
1671 }
1672 }
1673 return($ret);
1674 }
1676 function get_multi_edit_values()
1677 {
1678 $ret = plugin::get_multi_edit_values();
1679 if(in_array("pw_storage",$this->multi_boxes)){
1680 $ret['pw_storage'] = $this->pw_storage;
1681 }
1682 if(in_array("edit_picture",$this->multi_boxes)){
1683 $ret['jpegPhoto'] = $this->jpegPhoto;
1684 $ret['photoData'] = $this->photoData;
1685 $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1686 $ret['old_photoData'] = $this->old_photoData;
1687 }
1688 if(isset($ret['dateOfBirth'])){
1689 unset($ret['dateOfBirth']);
1690 }
1691 if(isset($ret['cn'])){
1692 unset($ret['cn']);
1693 }
1694 $ret['is_modified'] = $this->is_modified;
1695 if(in_array("base",$this->multi_boxes)){
1696 $ret['orig_base']="Changed_by_Multi_Plug";
1697 $ret['base']=$this->base;
1698 }
1699 return($ret);
1700 }
1703 function multiple_save_object()
1704 {
1705 plugin::multiple_save_object();
1707 /* Get pw_storage mode */
1708 if (isset($_POST['pw_storage'])){
1709 foreach(array("pw_storage") as $val){
1710 if(isset($_POST[$val])){
1711 $data= validate(get_post($val));
1712 if ($data != $this->$val){
1713 $this->is_modified= TRUE;
1714 }
1715 $this->$val= $data;
1716 }
1717 }
1718 }
1719 if(isset($_POST['base'])){
1720 $this->base = get_post('base');
1721 }
1723 if(isset($_POST['user_mulitple_edit'])){
1724 foreach(array("base","pw_storage","edit_picture") as $val){
1725 if(isset($_POST["use_".$val])){
1726 $this->multi_boxes[] = $val;
1727 }
1728 }
1729 }
1730 }
1733 function multiple_check()
1734 {
1735 /* Call check() to set new_dn correctly ... */
1736 $message = plugin::multiple_check();
1738 /* Set the new acl base */
1739 if($this->dn == "new") {
1740 $this->set_acl_base($this->base);
1741 }
1742 if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1743 $message[]= msgPool::invalid(_("Homepage"));
1744 }
1745 if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1746 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1747 }
1748 if (!tests::is_phone_nr($this->facsimileTelephoneNumber) && in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1749 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1750 }
1751 if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1752 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1753 }
1754 if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1755 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1756 }
1757 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1758 $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1759 }
1760 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1761 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1762 }
1763 return($message);
1764 }
1768 function multiple_execute()
1769 {
1770 return($this->execute());
1771 }
1774 }
1776 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1777 ?>