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 /* constructor, if 'dn' is set, the node loads the given
128 'dn' from LDAP */
129 function user (&$config, $dn= NULL)
130 {
131 $this->config= $config;
132 /* Configuration is fine, allways */
133 if ($this->config->current['GOVERNMENTMODE']){
134 $this->attributes=array_merge($this->attributes,$this->govattrs);
135 }
137 /* Load base attributes */
138 plugin::plugin ($config, $dn);
140 $this->orig_dn = $this->dn;
141 $this->new_dn = $dn;
143 if ($this->config->current['GOVERNMENTMODE']){
144 /* Fix public visible attribute if unset */
145 if (!isset($this->attrs['publicVisible'])){
146 $this->publicVisible == "nein";
147 }
148 }
150 /* Load government mode attributes */
151 if ($this->config->current['GOVERNMENTMODE']){
152 /* Copy all attributs */
153 foreach ($this->govattrs as $val){
154 if (isset($this->attrs["$val"][0])){
155 $this->$val= $this->attrs["$val"][0];
156 }
157 }
158 }
160 /* Create me for new accounts */
161 if ($dn == "new"){
162 $this->is_account= TRUE;
163 }
165 /* Make hash default to md5 if not set in config */
166 if (!isset($this->config->current['HASH'])){
167 $hash= "md5";
168 } else {
169 $hash= $this->config->current['HASH'];
170 }
172 /* Load data from LDAP? */
173 if ($dn !== NULL){
175 /* Do base conversation */
176 if ($this->dn == "new"){
177 $ui= get_userinfo();
178 $this->base= dn2base($ui->dn);
179 } else {
180 $this->base= dn2base($dn);
181 }
183 /* get password storage type */
184 if (isset ($this->attrs['userPassword'][0])){
185 /* Initialize local array */
186 $matches= array();
187 if (preg_match ("/^{[^}]+}/", $this->attrs['userPassword'][0])){
188 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
189 if(is_object($tmp)){
190 $this->pw_storage= $tmp->get_hash();
191 }
193 } else {
194 if ($this->attrs['userPassword'][0] != ""){
195 $this->pw_storage= "clear";
196 } else {
197 $this->pw_storage= $hash;
198 }
199 }
200 } else {
201 /* Preset with vaule from configuration */
202 $this->pw_storage= $hash;
203 }
205 /* Load extra attributes: certificate and picture */
206 $this->load_cert();
207 $this->load_picture();
208 if ($this->userCertificate != ""){
209 $this->had_userCertificate= TRUE;
210 }
211 }
213 /* Reset password storage indicator, used by password_change_needed() */
214 if ($dn == "new"){
215 $this->last_pw_storage= "unset";
216 } else {
217 $this->last_pw_storage= $this->pw_storage;
218 }
220 /* Generate dateOfBirth entry */
221 if (isset ($this->attrs['dateOfBirth'])){
222 /* This entry is ISO 8601 conform */
223 list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
225 $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
226 $this->use_dob= "1";
227 } else {
228 $this->use_dob= "0";
229 }
231 /* Put gender attribute to upper case */
232 if (isset ($this->attrs['gender'])){
233 $this->gender= strtoupper($this->attrs['gender'][0]);
234 }
236 $this->orig_base = $this->base;
237 }
242 /* execute generates the html output for this node */
243 function execute()
244 {
245 /* Call parent execute */
246 plugin::execute();
248 /* Log view */
249 if($this->is_account && !$this->view_logged){
250 $this->view_logged = TRUE;
251 new log("view","users/".get_class($this),$this->dn);
252 }
254 $smarty= get_smarty();
256 /* Fill calendar */
257 if ($this->dateOfBirth == "0"){
258 $date= getdate();
259 } else {
260 if(is_array($this->dateOfBirth)){
261 $date = $this->dateOfBirth;
263 // Trigger on dates like 1985-04-01, getdate only understands timestamps
264 } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
265 $date= getdate(strtotime($this->dateOfBirth));
267 } else {
268 $date = getdate($this->dateOfBirth);
269 }
270 }
272 $days= array();
273 for($d= 1; $d<32; $d++){
274 $days[$d]= $d;
275 }
276 $years= array();
278 if(($date['year']-100)<1901){
279 $start = 1901;
280 }else{
281 $start = $date['year']-100;
282 }
284 $end = $start +100;
286 for($y= $start; $y<=$end; $y++){
287 $years[]= $y;
288 }
289 $years['-']= "- ";
290 $months= msgPool::months();
291 $months['-'] = '- ';
293 $smarty->assign("day", $date["mday"]);
294 $smarty->assign("days", $days);
295 $smarty->assign("months", $months);
296 $smarty->assign("month", $date["mon"]-1);
297 $smarty->assign("years", $years);
298 $smarty->assign("year", $date["year"]);
300 /* Assign sex */
301 $sex= array(0 => " ", "F" => _("female"), "M" => _("male"));
302 $smarty->assign("gender_list", $sex);
303 $language= array_merge(array(0 => " ") ,get_languages(TRUE));
304 $smarty->assign("preferredLanguage_list", $language);
306 /* Get random number for pictures */
307 srand((double)microtime()*1000000);
308 $smarty->assign("rand", rand(0, 10000));
311 /* Do we represent a valid gosaAccount? */
312 if (!$this->is_account){
313 $str = "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
314 msgPool::noValidExtension("GOsa")."</b>";
315 return($str);
316 }
318 /* Base select dialog */
319 $once = true;
320 foreach($_POST as $name => $value){
321 if(preg_match("/^chooseBase/",$name) && $once){
322 $once = false;
323 $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
324 $this->dialog->setCurrentBase($this->base);
325 }
326 }
328 /* Password configure dialog handling */
329 if(is_object($this->pwObject) && $this->pwObject->display){
330 $output= $this->pwObject->configure();
331 if ($output != ""){
332 $this->dialog= TRUE;
333 return $output;
334 }
335 $this->dialog= false;
336 }
338 /* Dialog handling */
339 if(is_object($this->dialog)){
340 /* Must be called before save_object */
341 $this->dialog->save_object();
343 if($this->dialog->isClosed()){
344 $this->dialog = false;
345 }elseif($this->dialog->isSelected()){
347 /* check if selected base is allowed to move to / create a new object */
348 $tmp = $this->get_allowed_bases();
349 if(isset($tmp[$this->dialog->isSelected()])){
350 $this->base = $this->dialog->isSelected();
351 }
352 $this->dialog= false;
353 }else{
354 return($this->dialog->execute());
355 }
356 }
358 /* Want password method editing? */
359 if ($this->acl_is_writeable("userPassword")){
360 if (isset($_POST['edit_pw_method'])){
361 if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
362 $temp= passwordMethod::get_available_methods();
363 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
364 }
365 $this->pwObject->display = TRUE;
366 $this->dialog= TRUE;
367 return ($this->pwObject->configure());
368 }
369 }
371 /* Want picture edit dialog? */
372 if($this->acl_is_writeable("userPicture")) {
373 if (isset($_POST['edit_picture'])){
374 /* Save values for later recovery, in case some presses
375 the cancel button. */
376 $this->old_jpegPhoto= $this->jpegPhoto;
377 $this->old_photoData= $this->photoData;
378 $this->picture_dialog= TRUE;
379 $this->dialog= TRUE;
380 }
381 }
383 /* Remove picture? */
384 if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))) ){
385 if (isset($_POST['picture_remove'])){
386 $this->set_picture ();
387 $this->jpegPhoto= "*removed*";
388 $this->is_modified= TRUE;
389 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
390 }
391 }
393 /* Save picture */
394 if (isset($_POST['picture_edit_finish'])){
396 /* Check for clean upload */
397 if ($_FILES['picture_file']['name'] != ""){
398 if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
399 msg_dialog::display(_("Error"), _("Cannot upload file!"), ERROR_DIALOG);
400 }else{
401 /* Activate new picture */
402 $this->set_picture($_FILES['picture_file']['tmp_name']);
403 }
404 }
405 $this->picture_dialog= FALSE;
406 $this->dialog= FALSE;
407 $this->is_modified= TRUE;
408 }
411 /* Cancel picture */
412 if (isset($_POST['picture_edit_cancel'])){
414 /* Restore values */
415 $this->jpegPhoto= $this->old_jpegPhoto;
416 $this->photoData= $this->old_photoData;
418 /* Update picture */
419 session::set('binary',$this->photoData);
420 session::set('binarytype',"image/jpeg");
421 $this->picture_dialog= FALSE;
422 $this->dialog= FALSE;
423 }
425 /* Toggle dateOfBirth information */
426 if (isset($_POST['set_dob'])){
427 $this->use_dob= ($this->use_dob == "0")?"1":"0";
428 }
431 /* Want certificate= */
432 if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
434 /* Save original values for later reconstruction */
435 foreach (array("certificateSerialNumber", "userCertificate",
436 "userSMIMECertificate", "userPKCS12") as $val){
438 $oval= "old_$val";
439 $this->$oval= $this->$val;
440 }
442 $this->cert_dialog= TRUE;
443 $this->dialog= TRUE;
444 }
447 /* Cancel certificate dialog */
448 if (isset($_POST['cert_edit_cancel'])){
450 /* Restore original values in case of 'cancel' */
451 foreach (array("certificateSerialNumber", "userCertificate",
452 "userSMIMECertificate", "userPKCS12") as $val){
454 $oval= "old_$val";
455 $this->$val= $this->$oval;
456 }
457 $this->cert_dialog= FALSE;
458 $this->dialog= FALSE;
459 }
462 /* Remove certificate? */
463 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
464 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
465 if (isset($_POST["remove_$val"])){
467 /* Reset specified cert*/
468 $this->$val= "";
469 $this->is_modified= TRUE;
470 }
471 }
472 }
474 /* Upload new cert and close dialog? */
475 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
477 $fail =false;
479 if (isset($_POST['cert_edit_finish'])){
481 /* for all certificates do */
482 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
483 as $val){
485 /* Check for clean upload */
486 if (array_key_exists($val."_file", $_FILES) &&
487 array_key_exists('name', $_FILES[$val."_file"]) &&
488 $_FILES[$val."_file"]['name'] != "" &&
489 is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
490 $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
491 }
492 }
494 /* Save serial number */
495 if (isset($_POST["certificateSerialNumber"]) &&
496 $_POST["certificateSerialNumber"] != ""){
498 if (!tests::is_id($_POST["certificateSerialNumber"])){
499 $fail = true;
500 msg_dialog::display(_("Error"), msgPool::invalid(_("Serial number"),$_POST["certificateSerialNumber"],"/[0-9]/"),ERROR_DIALOG);
502 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
503 if ($this->$cert != ""){
504 $smarty->assign("$cert"."_state", "true");
505 } else {
506 $smarty->assign("$cert"."_state", "");
507 }
508 }
509 }
511 $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
512 $this->is_modified= TRUE;
513 }
514 if(!$fail){
515 $this->cert_dialog= FALSE;
516 $this->dialog= FALSE;
517 }
518 }
519 }
520 /* Display picture dialog */
521 if ($this->picture_dialog){
522 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
523 }
525 /* Display cert dialog */
526 if ($this->cert_dialog){
527 $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
528 $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
529 $smarty->assign("certificateSerialNumber",$this->certificateSerialNumber);
531 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
532 if ($this->$cert != ""){
533 /* import certificate */
534 $certificate = new certificate;
535 $certificate->import($this->$cert);
537 /* Read out data*/
538 $timeto = $certificate->getvalidto_date();
539 $timefrom = $certificate->getvalidfrom_date();
542 /* Additional info if start end time is '0' */
543 $add_str_info = "";
544 if($timeto == 0 && $timefrom == 0){
545 $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
546 }
548 $str = "<table summary=\"\" border=0>
549 <tr>
550 <td style='vertical-align:top'>CN</td>
551 <td>".preg_replace("/ /", " ", $certificate->getname())."</td>
552 </tr>
553 </table><br>".
555 sprintf(_("Certificate is valid from %s to %s and is currently %s."),
556 "<b>".date('d M Y',$timefrom)."</b>",
557 "<b>".date('d M Y',$timeto)."</b>",
558 $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
559 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
561 $smarty->assign($cert."info",$str);
562 $smarty->assign($cert."_state","true");
563 } else {
564 $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
565 $smarty->assign($cert."_state","");
566 }
567 }
568 $this->config->current['GOVERNMENTMODE'] = "true";
569 if (isset($this->config->current['GOVERNMENTMODE']) &&
570 preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
571 $smarty->assign("governmentmode", "true");
572 }else{
573 $smarty->assign("governmentmode", "false");
574 }
575 return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
576 }
578 /* Prepare password hashes */
579 if ($this->pw_storage == ""){
580 $this->pw_storage= $this->config->current['HASH'];
581 }
583 $temp= passwordMethod::get_available_methods();
584 $is_configurable= FALSE;
585 $hashes = $temp['name'];
586 if(isset($temp[$this->pw_storage])){
587 $test= new $temp[$this->pw_storage]($this->config);
588 $is_configurable= $test->is_configurable();
589 }else{
590 new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
591 }
593 /* Load attributes and acl's */
594 $ui =get_userinfo();
595 foreach($this->attributes as $val){
596 $smarty->assign("$val", $this->$val);
597 if(in_array($val,$this->multi_boxes)){
598 $smarty->assign("use_".$val,TRUE);
599 }else{
600 $smarty->assign("use_".$val,FALSE);
601 }
602 }
603 foreach(array("base","pw_storage","edit_picture") as $val){
604 if(in_array($val,$this->multi_boxes)){
605 $smarty->assign("use_".$val,TRUE);
606 }else{
607 $smarty->assign("use_".$val,FALSE);
608 }
609 }
611 /* Set acls */
612 $tmp = $this->plinfo();
613 foreach($tmp['plProvidedAcls'] as $val => $translation){
614 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
615 }
617 $smarty->assign("pwmode", $hashes);
618 $smarty->assign("pwmode_select", $this->pw_storage);
619 $smarty->assign("pw_configurable", $is_configurable);
620 $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !session::is_set('edit'))));
621 $smarty->assign("base_select", $this->base);
622 $smarty->assign("CertificatesACL", $this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
623 $smarty->assign("userPictureACL", $this->getacl("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
624 $smarty->assign("userPicture_is_readable", $this->acl_is_readable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
626 /* Create base acls */
627 $tmp = @$this->allowedBasesToMoveTo();
628 $smarty->assign("bases", $tmp);
630 /* Save government mode attributes */
631 if (isset($this->config->current['GOVERNMENTMODE']) &&
632 preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
633 $smarty->assign("governmentmode", "true");
634 $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
635 "internet,ivbv", "internet,testa", "internet,ivbv,testa");
636 $smarty->assign("ivbbmodes", $ivbbmodes);
637 foreach ($this->govattrs as $val){
638 $smarty->assign("$val", $this->$val);
639 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
640 }
641 } else {
642 $smarty->assign("governmentmode", "false");
643 }
645 /* Special mode for uid */
646 $uidACL= $this->getacl("uid",(!is_object($this->parent) && !session::is_set('edit')));
647 if (isset ($this->dn)){
648 if ($this->dn != "new"){
649 $uidACL= preg_replace("/w/","",$uidACL);
650 }
651 } else {
652 $uidACL= preg_replace("/w/","",$uidACL);
653 }
655 $smarty->assign("uidACL", $uidACL);
656 $smarty->assign("is_template", $this->is_template);
657 $smarty->assign("use_dob", $this->use_dob);
659 if (isset($this->parent)){
660 if (isset($this->parent->by_object['phoneAccount']) &&
661 $this->parent->by_object['phoneAccount']->is_account){
662 $smarty->assign("has_phoneaccount", "true");
663 } else {
664 $smarty->assign("has_phoneaccount", "false");
665 }
666 } else {
667 $smarty->assign("has_phoneaccount", "false");
668 }
669 $smarty->assign("multiple_support" , $this->multiple_support_active);
670 return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
671 }
674 /* remove object from parent */
675 function remove_from_parent()
676 {
677 /* Remove password extension */
678 $temp= passwordMethod::get_available_methods();
680 /* Remove password method from user account */
681 if(isset($temp[$this->pw_storage]) && class_available($temp[$this->pw_storage])){
682 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
683 $this->pwObject->remove_from_parent();
684 }
686 /* Remove user */
687 $ldap= $this->config->get_ldap_link();
688 $ldap->rmdir ($this->dn);
689 if (!$ldap->success()){
690 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
691 }
693 new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
695 /* Delete references to groups */
696 $ldap->cd ($this->config->current['BASE']);
697 $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
698 while ($ldap->fetch()){
699 $g= new group($this->config, $ldap->getDN());
700 $g->removeUser($this->uid);
701 $g->save ();
702 }
704 /* Delete references to object groups */
705 $ldap->cd ($this->config->current['BASE']);
706 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
707 while ($ldap->fetch()){
708 $og= new ogroup($this->config, $ldap->getDN());
709 unset($og->member[$this->dn]);
710 $og->save ();
711 }
713 /* If needed, let the password method do some cleanup */
714 $tmp = new passwordMethod($this->config);
715 $available = $tmp->get_available_methods();
716 if (in_array_ics($this->pw_storage, $available['name'])){
717 $test= new $available[$this->pw_storage]($this->config);
718 $test->attrs= $this->attrs;
719 $test->dn= $this->dn;
720 $test->remove_from_parent();
721 }
723 /* Remove ACL dependencies too */
724 $tmp = new acl($this->config,$this->parent,$this->dn);
725 $tmp->remove_acl();
727 /* Optionally execute a command after we're done */
728 $this->handle_post_events("remove",array("uid" => $this->uid));
729 }
732 /* Save data to object */
733 function save_object()
734 {
735 if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
737 /* Make a backup of the current selected base */
738 $base_tmp = $this->base;
740 /* Parents save function */
741 plugin::save_object ();
743 /* Save government mode attributes */
744 if ($this->config->current['GOVERNMENTMODE']){
745 foreach ($this->govattrs as $val){
746 if ($this->acl_is_writeable($val,(!is_object($this->parent) && !session::is_set('edit'))) && isset($_POST["$val"])){
747 $data= stripcslashes($_POST["$val"]);
748 if ($data != $this->$val){
749 $this->is_modified= TRUE;
750 }
751 $this->$val= $data;
752 }
753 }
754 }
756 /* In template mode, the uid is autogenerated... */
757 if ($this->is_template){
758 $this->uid= strtolower($this->sn);
759 $this->givenName= $this->sn;
760 }
762 /* Save base and pw_storage, since these are no LDAP attributes */
763 if (isset($_POST['base'])){
765 $tmp = $this->get_allowed_bases();
766 if(isset($tmp[$_POST['base']])){
767 $base= validate($_POST['base']);
768 if ($base != $this->base){
769 $this->is_modified= TRUE;
770 }
771 $this->base= $base;
772 }else{
773 $this->base = $base_tmp;
774 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
775 $this->set_acl_base('dummy,'.$this->base);
776 }
777 }
779 /* Get pw_storage mode */
780 if (isset($_POST['pw_storage'])){
781 foreach(array("pw_storage") as $val){
782 if(isset($_POST[$val])){
783 $data= validate($_POST[$val]);
784 if ($data != $this->$val){
785 $this->is_modified= TRUE;
786 }
787 $this->$val= $data;
788 }
789 }
790 }
792 $this->set_acl_base('dummy,'.$this->base);
793 }
794 }
796 function rebind($ldap, $referral)
797 {
798 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
799 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
800 $this->error = "Success";
801 $this->hascon=true;
802 $this->reconnect= true;
803 return (0);
804 } else {
805 $this->error = "Could not bind to " . $credentials['ADMIN'];
806 return NULL;
807 }
808 }
811 /* Save data to LDAP, depending on is_account we save or delete */
812 function save()
813 {
814 /* Only force save of changes ....
815 If this attributes aren't changed, avoid saving.
816 */
817 if($this->gender=="0") $this->gender ="";
818 if($this->preferredLanguage=="0") $this->preferredLanguage ="";
820 /* First use parents methods to do some basic fillup in $this->attrs */
821 plugin::save ();
823 if ($this->use_dob == "1"){
824 /* 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. */
825 if(!is_array($this->attrs['dateOfBirth'])) {
826 $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
827 }
828 }
830 /* Remove additional objectClasses */
831 $tmp= array();
832 foreach ($this->attrs['objectClass'] as $key => $set){
833 $found= false;
834 foreach (array("ivbbentry", "gosaUserTemplate") as $val){
835 if (preg_match ("/^$set$/i", $val)){
836 $found= true;
837 break;
838 }
839 }
840 if (!$found){
841 $tmp[]= $set;
842 }
843 }
845 /* Replace the objectClass array. This is done because of the
846 separation into government and normal mode. */
847 $this->attrs['objectClass']= $tmp;
849 /* Add objectClasss for template mode? */
850 if ($this->is_template){
851 $this->attrs['objectClass'][]= "gosaUserTemplate";
852 }
854 /* Hard coded government mode? */
855 if ($this->config->current['GOVERNMENTMODE'] != 'false'){
856 $this->attrs['objectClass'][]= "ivbbentry";
858 /* Copy standard attributes */
859 foreach ($this->govattrs as $val){
860 if ($this->$val != ""){
861 $this->attrs["$val"]= $this->$val;
862 } elseif (!$this->is_new) {
863 $this->attrs["$val"]= array();
864 }
865 }
867 /* Remove attribute if set to "nein" */
868 if ($this->publicVisible == "nein"){
869 $this->attrs['publicVisible']= array();
870 if($this->is_new){
871 unset($this->attrs['publicVisible']);
872 }else{
873 $this->attrs['publicVisible']=array();
874 }
876 }
878 }
880 /* Special handling for attribute userCertificate needed */
881 if ($this->userCertificate != ""){
882 $this->attrs["userCertificate;binary"]= $this->userCertificate;
883 $remove_userCertificate= false;
884 } else {
885 $remove_userCertificate= true;
886 }
888 /* Special handling for dateOfBirth value */
889 if ($this->use_dob != "1"){
890 if ($this->is_new) {
891 unset($this->attrs["dateOfBirth"]);
892 } else {
893 $this->attrs["dateOfBirth"]= array();
894 }
895 }
896 if (!$this->gender){
897 if ($this->is_new) {
898 unset($this->attrs["gender"]);
899 } else {
900 $this->attrs["gender"]= array();
901 }
902 }
903 if (!$this->preferredLanguage){
904 if ($this->is_new) {
905 unset($this->attrs["preferredLanguage"]);
906 } else {
907 $this->attrs["preferredLanguage"]= array();
908 }
909 }
911 /* Special handling for attribute jpegPhote needed, scale image via
912 image magick to 147x200 pixels and inject resulting data. */
913 if ($this->jpegPhoto == "*removed*"){
915 /* Reset attribute to avoid writing *removed* as value */
916 $this->attrs["jpegPhoto"] = array();
918 } else {
920 /* Fallback if there's no image magick inside PHP */
921 if (!function_exists("imagick_blob2image")){
922 /* Get temporary file name for conversation */
923 $fname = tempnam ("/tmp", "GOsa");
925 /* Open file and write out photoData */
926 $fp = fopen ($fname, "w");
927 fwrite ($fp, $this->photoData);
928 fclose ($fp);
930 /* Build conversation query. Filename is generated automatically, so
931 we do not need any special security checks. Exec command and save
932 output. For PHP safe mode, you'll need a configuration which respects
933 image magick as executable... */
934 $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
935 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
936 $query, "Execute");
938 /* Read data written by convert */
939 $output= "";
940 $sh= popen($query, 'r');
941 while (!feof($sh)){
942 $output.= fread($sh, 4096);
943 }
944 pclose($sh);
946 unlink($fname);
948 /* Save attribute */
949 $this->attrs["jpegPhoto"] = $output;
951 } else {
953 /* Load the new uploaded Photo */
954 if(!$handle = imagick_blob2image($this->photoData)) {
955 new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
956 }
958 /* Resizing image to 147x200 and blur */
959 if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
960 new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
961 }
963 /* Converting image to JPEG */
964 if(!imagick_convert($handle,"JPEG")) {
965 new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
966 }
968 /* Creating binary Code for the Image */
969 if(!$dump = imagick_image2blob($handle)){
970 new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
971 }
973 /* Sending Image */
974 $output= $dump;
976 /* Save attribute */
977 $this->attrs["jpegPhoto"] = $output;
978 }
980 }
982 /* This only gets called when user is renaming himself */
983 $ldap= $this->config->get_ldap_link();
984 if ($this->dn != $this->new_dn){
986 /* Write entry on new 'dn' */
987 $this->update_acls($this->dn,$this->new_dn);
988 $this->move($this->dn, $this->new_dn);
990 /* Happen to use the new one */
991 change_ui_dn($this->dn, $this->new_dn);
992 $this->dn= $this->new_dn;
993 }
996 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
997 new entries. So do a check first... */
998 $ldap->cat ($this->dn, array('dn'));
999 if ($ldap->fetch()){
1000 $mode= "modify";
1001 } else {
1002 $mode= "add";
1003 $ldap->cd($this->config->current['BASE']);
1004 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1005 }
1007 /* Set password to some junk stuff in case of templates */
1008 if ($this->is_template){
1009 $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
1010 }
1012 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1013 $this->attributes, "Save via $mode");
1015 /* Finally write data with selected 'mode' */
1016 $this->cleanup();
1018 if(isset($this->attrs['preferredLanguage'])){
1019 $ui = session::get('ui');
1020 $ui->language = $this->preferredLanguage;
1021 session::set('ui',$ui);
1022 session::set('Last_init_lang',"update");
1023 }
1025 $ldap->cd ($this->dn);
1026 $ldap->$mode ($this->attrs);
1027 if (!$ldap->success()){
1028 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1029 return (1);
1030 }
1032 /* Remove ACL dependencies too */
1033 if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1034 $tmp = new acl($this->config,$this->parent,$this->dn);
1035 $tmp->update_acl_membership($this->orig_dn,$this->dn);
1036 }
1038 if($mode == "modify"){
1039 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1040 }else{
1041 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1042 }
1044 /* Remove cert?
1045 For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1046 to work around myself. */
1047 if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1049 /* Reset array, assemble new, this should be reworked */
1050 $this->attrs= array();
1051 $this->attrs['userCertificate;binary']= array();
1053 /* Prepare connection */
1054 if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1055 die ("Could not connect to LDAP server");
1056 }
1057 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1058 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1059 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1060 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1061 }
1062 if(isset($config->current['TLS']) && $config->current['TLS'] == "true"){
1063 ldap_start_tls($ds);
1064 }
1065 if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1066 $this->config->current['PASSWORD']))) {
1067 die ("Could not bind to LDAP");
1068 }
1070 /* Modify using attrs */
1071 ldap_mod_del($ds,$this->dn,$this->attrs);
1072 ldap_close($ds);
1073 }
1075 /* If needed, let the password method do some cleanup */
1076 if ($this->pw_storage != $this->last_pw_storage){
1077 $tmp = new passwordMethod($this->config);
1078 $available = $tmp->get_available_methods();
1079 if (in_array_ics($this->last_pw_storage, $available['name'])){
1080 $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1081 $test->attrs= $this->attrs;
1082 $test->remove_from_parent();
1083 }
1084 }
1086 /* Maybe the current password method want's to do some changes... */
1087 if (is_object($this->pwObject)){
1088 $this->pwObject->save($this->dn);
1089 }
1091 /* Optionally execute a command after we're done */
1092 if ($mode == "add"){
1093 $this->handle_post_events("add", array("uid" => $this->uid));
1094 } elseif ($this->is_modified){
1095 $this->handle_post_events("modify", array("uid" => $this->uid));
1096 }
1098 return (0);
1099 }
1102 function update_new_dn()
1103 {
1104 $pt= "";
1105 if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1106 if(!empty($this->personalTitle)){
1107 $pt = $this->personalTitle." ";
1108 }
1109 }
1110 $this->cn= $pt.$this->givenName." ".$this->sn;
1112 /* Permissions for that base? */
1113 if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1114 $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1115 } else {
1116 /* Don't touch dn, if cn hasn't changed */
1117 if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1118 $this->orig_base == $this->base ){
1119 $this->new_dn= $this->dn;
1120 } else {
1121 $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1122 }
1123 }
1124 }
1127 /* Check formular input */
1128 function check()
1129 {
1130 /* Call common method to give check the hook */
1131 $message= plugin::check();
1133 $this->update_new_dn();
1135 /* Set the new acl base */
1136 if($this->dn == "new") {
1137 $this->set_acl_base($this->base);
1138 }
1140 /* UID already used? */
1141 $ldap= $this->config->get_ldap_link();
1142 $ldap->cd($this->config->current['BASE']);
1143 $ldap->search("(uid=$this->uid)", array("uid"));
1144 $ldap->fetch();
1145 if ($ldap->count() != 0 && $this->dn == 'new'){
1146 $message[]= msgPool::duplicated(_("Login"));
1147 }
1149 /* In template mode, the uid and givenName are autogenerated... */
1150 if (!$this->is_template){
1151 if ($this->sn == ""){
1152 $message[]= msgPool::required(_("Name"));
1153 }
1154 if ($this->givenName == ""){
1155 $message[]= msgPool::required(_("Given name"));
1156 }
1157 if ($this->uid == ""){
1158 $message[]= msgPool::required(_("Login"));
1159 }
1160 if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1161 $ldap->cat($this->new_dn);
1162 if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1163 $message[]= msgPool::duplicated(_("Name"));
1164 }
1165 }
1166 }
1168 /* Check for valid input */
1169 if ($this->is_modified && !tests::is_uid($this->uid)){
1171 if (strict_uid_mode()){
1172 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1173 } else {
1174 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1175 }
1176 }
1177 if (!tests::is_url($this->labeledURI)){
1178 $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1179 }
1181 /* Check phone numbers */
1182 if (!tests::is_phone_nr($this->telephoneNumber)){
1183 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1184 }
1185 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1186 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1187 }
1188 if (!tests::is_phone_nr($this->mobile)){
1189 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1190 }
1191 if (!tests::is_phone_nr($this->pager)){
1192 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1193 }
1195 /* Check for reserved characers */
1196 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1197 $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1198 }
1199 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1200 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1201 }
1203 return $message;
1204 }
1207 /* Indicate whether a password change is needed or not */
1208 function password_change_needed()
1209 {
1210 if(in_array("pw_storage",$this->multi_boxes)){
1211 return(TRUE);
1212 }
1213 return($this->pw_storage != $this->last_pw_storage);
1214 }
1217 /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1218 function load_picture()
1219 {
1220 $ldap = $this->config->get_ldap_link();
1221 $ldap->cd ($this->dn);
1222 $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1224 if((!$data) || ($data == "*removed*")){
1226 /* In case we don't get an entry, load a default picture */
1227 $this->set_picture ();//"./images/default.jpg");
1228 $this->jpegPhoto= "*removed*";
1229 }else{
1231 /* Set picture */
1232 $this->photoData= $data;
1233 session::set('binary',$this->photoData);
1234 session::set('binarytype',"image/jpeg");
1235 $this->jpegPhoto= "";
1236 }
1237 }
1240 /* Load a certificate from LDAP, this is going to be simplified later on */
1241 function load_cert()
1242 {
1243 $ds= ldap_connect($this->config->current['SERVER']);
1244 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1245 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1246 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1247 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1248 }
1249 if(isset($this->config->current['TLS']) &&
1250 $this->config->current['TLS'] == "true"){
1252 ldap_start_tls($ds);
1253 }
1255 $r= ldap_bind($ds);
1256 $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1258 if ($sr) {
1259 $ei= @ldap_first_entry($ds, $sr);
1261 if ($ei) {
1262 if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1263 $this->userCertificate= "";
1264 } else {
1265 $this->userCertificate= $info[0];
1266 }
1267 }
1268 } else {
1269 $this->userCertificate= "";
1270 }
1272 ldap_unbind($ds);
1273 }
1276 /* Load picture from file to object */
1277 function set_picture($filename ="")
1278 {
1279 if (!is_file($filename) || $filename =="" ){
1280 $filename= "./images/default.jpg";
1281 $this->jpegPhoto= "*removed*";
1282 }
1284 $fd = fopen ($filename, "rb");
1285 $this->photoData= fread ($fd, filesize ($filename));
1286 session::set('binary',$this->photoData);
1287 session::set('binarytype',"image/jpeg");
1288 $this->jpegPhoto= "";
1290 fclose ($fd);
1291 }
1294 /* Load certificate from file to object */
1295 function set_cert($cert, $filename)
1296 {
1297 if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1298 $fd = fopen ($filename, "rb");
1299 if (filesize($filename)>0) {
1300 $this->$cert= fread ($fd, filesize ($filename));
1301 fclose ($fd);
1302 $this->is_modified= TRUE;
1303 } else {
1304 msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1305 }
1306 }
1308 /* Adapt from given 'dn' */
1309 function adapt_from_template($dn, $skip= array())
1310 {
1311 plugin::adapt_from_template($dn, $skip);
1313 /* Get base */
1314 $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1316 if ($this->config->current['GOVERNMENTMODE']){
1318 /* Walk through govattrs */
1319 foreach ($this->govattrs as $val){
1321 if (in_array($val, $skip)){
1322 continue;
1323 }
1325 if (isset($this->attrs["$val"][0])){
1327 /* If attribute is set, replace dynamic parts:
1328 %sn, %givenName and %uid. Fill these in our local variables. */
1329 $value= $this->attrs["$val"][0];
1331 foreach (array("sn", "givenName", "uid") as $repl){
1332 if (preg_match("/%$repl/i", $value)){
1333 $value= preg_replace ("/%$repl/i",
1334 $this->parent->$repl, $value);
1335 }
1336 }
1337 $this->$val= $value;
1338 }
1339 }
1340 }
1342 /* Get back uid/sn/givenName - only write if nothing's skipped */
1343 if ($this->parent !== NULL && count($skip) == 0){
1344 $this->uid= $this->parent->uid;
1345 $this->sn= $this->parent->sn;
1346 $this->givenName= $this->parent->givenName;
1347 }
1348 }
1351 /* This avoids that users move themselves out of their rights.
1352 */
1353 function allowedBasesToMoveTo()
1354 {
1355 /* Get bases */
1356 $bases = $this->get_allowed_bases();
1357 return($bases);
1358 }
1361 function getCopyDialog()
1362 {
1363 $str = "";
1365 session::set('binary',$this->photoData);
1366 session::set('binarytype',"image/jpeg");
1368 /* Get random number for pictures */
1369 srand((double)microtime()*1000000);
1370 $rand = rand(0, 10000);
1372 $smarty = get_smarty();
1374 $smarty->assign("passwordTodo","clear");
1376 if(isset($_POST['passwordTodo'])){
1377 $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1378 }
1380 $smarty->assign("sn", $this->sn);
1381 $smarty->assign("givenName",$this->givenName);
1382 $smarty->assign("uid", $this->uid);
1383 $smarty->assign("rand", $rand);
1384 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1387 $ret = array();
1388 $ret['string'] = $str;
1389 $ret['status'] = "";
1390 return($ret);
1391 }
1393 function saveCopyDialog()
1394 {
1395 /* Set_acl_base */
1396 $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1398 if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1399 $this->set_picture($_FILES['picture_file']['tmp_name']);
1400 }
1402 /* Remove picture? */
1403 if (isset($_POST['picture_remove'])){
1404 $this->jpegPhoto= "*removed*";
1405 $this->set_picture ("./images/default.jpg");
1406 $this->is_modified= TRUE;
1407 }
1409 $attrs = array("uid","givenName","sn");
1410 foreach($attrs as $attr){
1411 if(isset($_POST[$attr])){
1412 $this->$attr = $_POST[$attr];
1413 }
1414 }
1415 }
1418 function PrepareForCopyPaste($source)
1419 {
1420 plugin::PrepareForCopyPaste($source);
1422 /* Reset certificate information addepted from source user
1423 to avoid setting the same user certificate for the destination user. */
1424 $this->userPKCS12= "";
1425 $this->userSMIMECertificate= "";
1426 $this->userCertificate= "";
1427 $this->certificateSerialNumber= "";
1428 $this->old_certificateSerialNumber= "";
1429 $this->old_userPKCS12= "";
1430 $this->old_userSMIMECertificate= "";
1431 $this->old_userCertificate= "";
1432 }
1435 static function plInfo()
1436 {
1438 $govattrs= array(
1439 "gouvernmentOrganizationalUnit" => _("Unit"),
1440 "houseIdentifier" => _("House identifier"),
1441 "vocation" => _("Vocation"),
1442 "ivbbLastDeliveryCollective" => _("Last delivery"),
1443 "gouvernmentOrganizationalPersonLocality" => _("Person locality"),
1444 "gouvernmentOrganizationalUnitDescription" => _("Unit description"),
1445 "gouvernmentOrganizationalUnitSubjectArea" => _("Subject area"),
1446 "functionalTitle" => _("Functional title"),
1447 "certificateSerialNumber" => _("Certificate serial number"),
1448 "publicVisible" => _("Public visible"),
1449 "street" => _("Street"),
1450 "role" => _("Role"),
1451 "postalCode" => _("Postal code"));
1453 $ret = array(
1454 "plShortName" => _("Generic"),
1455 "plDescription" => _("Generic user settings"),
1456 "plSelfModify" => TRUE,
1457 "plDepends" => array(),
1458 "plPriority" => 1,
1459 "plSection" => array("personal" => _("My account")),
1460 "plCategory" => array("users" => array("description" => _("Users"),
1461 "objectClass" => "gosaAccount")),
1463 "plProvidedAcls" => array(
1464 "base" => _("Base"),
1465 "userPassword" => _("User password"),
1466 "sn" => _("Surename"),
1467 "givenName" => _("Given name"),
1468 "uid" => _("User identification"),
1469 "personalTitle" => _("Personal title"),
1470 "academicTitle" => _("Academic title"),
1471 "homePostalAddress" => _("Home postal address"),
1472 "homePhone" => _("Home phone number"),
1473 "labeledURI" => _("Homepage"),
1474 "o" => _("Organization"),
1475 "ou" => _("Department"),
1476 "dateOfBirth" => _("Date of birth"),
1477 "gender" => _("Gender"),
1478 "preferredLanguage" => _("Preferred language"),
1479 "departmentNumber" => _("Department number"),
1480 "employeeNumber" => _("Employee number"),
1481 "employeeType" => _("Employee type"),
1482 "l" => _("Location"),
1483 "st" => _("State"),
1484 "userPicture" => _("User picture"),
1485 "roomNumber" => _("Room number"),
1486 "telephoneNumber" => _("Telefon number"),
1487 "mobile" => _("Mobile number"),
1488 "pager" => _("Pager number"),
1489 "Certificate" => _("User certificates"),
1491 "postalAddress" => _("Postal address"),
1492 "facsimileTelephoneNumber" => _("Fax number"))
1493 );
1495 /* Append government attributes if required */
1496 global $config;
1497 if (isset($config->current['GOVERNMENTMODE']) && preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1498 foreach($govattrs as $attr => $desc){
1499 $ret["plProvidedAcls"][$attr] = $desc;
1500 }
1501 }
1502 return($ret);
1503 }
1505 function get_multi_edit_values()
1506 {
1507 $ret = plugin::get_multi_edit_values();
1508 if(in_array("pw_storage",$this->multi_boxes)){
1509 $ret['pw_storage'] = $this->pw_storage;
1510 }
1511 if(in_array("edit_picture",$this->multi_boxes)){
1512 $ret['jpegPhoto'] = $this->jpegPhoto;
1513 $ret['photoData'] = $this->photoData;
1514 $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1515 $ret['old_photoData'] = $this->old_photoData;
1516 }
1517 if(isset($ret['dateOfBirth'])){
1518 unset($ret['dateOfBirth']);
1519 }
1520 if(isset($ret['cn'])){
1521 unset($ret['cn']);
1522 }
1523 $ret['is_modified'] = $this->is_modified;
1524 if(in_array("base",$this->multi_boxes)){
1525 $ret['orig_base']="Changed_by_Multi_Plug";
1526 $ret['base']=$this->base;
1527 }
1528 return($ret);
1529 }
1532 function multiple_save_object()
1533 {
1534 plugin::multiple_save_object();
1536 /* Get pw_storage mode */
1537 if (isset($_POST['pw_storage'])){
1538 foreach(array("pw_storage") as $val){
1539 if(isset($_POST[$val])){
1540 $data= validate(get_post($val));
1541 if ($data != $this->$val){
1542 $this->is_modified= TRUE;
1543 }
1544 $this->$val= $data;
1545 }
1546 }
1547 }
1548 if(isset($_POST['base'])){
1549 $this->base = get_post('base');
1550 }
1552 if(isset($_POST['user_mulitple_edit'])){
1553 foreach(array("base","pw_storage","edit_picture") as $val){
1554 if(isset($_POST["use_".$val])){
1555 $this->multi_boxes[] = $val;
1556 }
1557 }
1558 }
1559 }
1562 function multiple_check()
1563 {
1564 /* Call check() to set new_dn correctly ... */
1565 $message = plugin::multiple_check();
1567 /* Set the new acl base */
1568 if($this->dn == "new") {
1569 $this->set_acl_base($this->base);
1570 }
1571 if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1572 $message[]= msgPool::invalid(_("Homepage"));
1573 }
1574 if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1575 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1576 }
1577 if (!tests::is_phone_nr($this->facsimileTelephoneNumber) && in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1578 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1579 }
1580 if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1581 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1582 }
1583 if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1584 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1585 }
1586 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1587 $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1588 }
1589 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1590 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1591 }
1592 return($message);
1593 }
1597 function multiple_execute()
1598 {
1599 return($this->execute());
1600 }
1603 }
1605 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1606 ?>