1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /*!
24 \brief user plugin
25 \author Cajus Pollmeier <pollmeier@gonicus.de>
26 \version 2.00
27 \date 24.07.2003
29 This class provides the functionality to read and write all attributes
30 relevant for person, organizationalPerson, inetOrgPerson and gosaAccount
31 from/to the LDAP. It does syntax checking and displays the formulars required.
32 */
34 class user extends plugin
35 {
36 /* Definitions */
37 var $plHeadline= "Generic";
38 var $plDescription= "Edit organizational user settings";
40 /* Plugin specific values */
41 var $base= "";
42 var $orig_base= "";
43 var $cn= "";
44 var $new_dn= "";
45 var $personalTitle= "";
46 var $academicTitle= "";
47 var $homePostalAddress= "";
48 var $homePhone= "";
49 var $labeledURI= "";
50 var $o= "";
51 var $ou= "";
52 var $departmentNumber= "";
53 var $employeeNumber= "";
54 var $employeeType= "";
55 var $roomNumber= "";
56 var $telephoneNumber= "";
57 var $facsimileTelephoneNumber= "";
58 var $mobile= "";
59 var $pager= "";
60 var $l= "";
61 var $st= "";
62 var $postalAddress= "";
63 var $dateOfBirth;
64 var $use_dob= "0";
65 var $gender="0";
66 var $preferredLanguage="0";
68 var $jpegPhoto= "*removed*";
69 var $photoData= "";
70 var $old_jpegPhoto= "";
71 var $old_photoData= "";
72 var $cert_dialog= FALSE;
73 var $picture_dialog= FALSE;
74 var $pwObject= NULL;
76 var $userPKCS12= "";
77 var $userSMIMECertificate= "";
78 var $userCertificate= "";
79 var $certificateSerialNumber= "";
80 var $old_certificateSerialNumber= "";
81 var $old_userPKCS12= "";
82 var $old_userSMIMECertificate= "";
83 var $old_userCertificate= "";
85 var $gouvernmentOrganizationalUnit= "";
86 var $houseIdentifier= "";
87 var $street= "";
88 var $postalCode= "";
89 var $vocation= "";
90 var $ivbbLastDeliveryCollective= "";
91 var $gouvernmentOrganizationalPersonLocality= "";
92 var $gouvernmentOrganizationalUnitDescription= "";
93 var $gouvernmentOrganizationalUnitSubjectArea= "";
94 var $functionalTitle= "";
95 var $role= "";
96 var $publicVisible= "";
98 var $orig_dn;
99 var $dialog;
101 /* variables to trigger password changes */
102 var $pw_storage= "md5";
103 var $last_pw_storage= "unset";
104 var $had_userCertificate= FALSE;
106 var $view_logged = FALSE;
108 /* attribute list for save action */
109 var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
110 "homePostalAddress", "homePhone", "labeledURI", "ou", "o", "dateOfBirth", "gender","preferredLanguage",
111 "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
112 "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
113 "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate");
115 var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson",
116 "gosaAccount");
118 /* attributes that are part of the government mode */
119 var $govattrs= array("gouvernmentOrganizationalUnit", "houseIdentifier", "vocation",
120 "ivbbLastDeliveryCollective", "gouvernmentOrganizationalPersonLocality",
121 "gouvernmentOrganizationalUnitDescription","gouvernmentOrganizationalUnitSubjectArea",
122 "functionalTitle", "certificateSerialNumber", "publicVisible", "street", "role",
123 "postalCode");
125 var $multiple_support = TRUE;
127 var $governmentmode = FALSE;
129 /* constructor, if 'dn' is set, the node loads the given
130 'dn' from LDAP */
131 function user (&$config, $dn= NULL)
132 {
133 $this->config= $config;
134 /* Configuration is fine, allways */
135 if (isset($this->config->current['GOVERNMENTMODE']) && preg_match("/true/i",$this->config->current['GOVERNMENTMODE'])){
136 $this->governmentmode = TRUE;
137 $this->attributes=array_merge($this->attributes,$this->govattrs);
138 }
140 /* Load base attributes */
141 plugin::plugin ($config, $dn);
143 $this->orig_dn = $this->dn;
144 $this->new_dn = $dn;
146 if ($this->governmentmode){
147 /* Fix public visible attribute if unset */
148 if (!isset($this->attrs['publicVisible'])){
149 $this->publicVisible == "nein";
150 }
151 }
153 /* Load government mode attributes */
154 if ($this->governmentmode){
155 /* Copy all attributs */
156 foreach ($this->govattrs as $val){
157 if (isset($this->attrs["$val"][0])){
158 $this->$val= $this->attrs["$val"][0];
159 }
160 }
161 }
163 /* Create me for new accounts */
164 if ($dn == "new"){
165 $this->is_account= TRUE;
166 }
168 /* Make hash default to md5 if not set in config */
169 if (!isset($this->config->current['HASH'])){
170 $hash= "md5";
171 } else {
172 $hash= $this->config->current['HASH'];
173 }
175 /* Load data from LDAP? */
176 if ($dn !== NULL){
178 /* Do base conversation */
179 if ($this->dn == "new"){
180 $ui= get_userinfo();
181 $this->base= dn2base($ui->dn);
182 } else {
183 $this->base= dn2base($dn);
184 }
186 /* get password storage type */
187 if (isset ($this->attrs['userPassword'][0])){
188 /* Initialize local array */
189 $matches= array();
190 if (preg_match ("/^{[^}]+}/", $this->attrs['userPassword'][0])){
191 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
192 if(is_object($tmp)){
193 $this->pw_storage= $tmp->get_hash();
194 }
196 } else {
197 if ($this->attrs['userPassword'][0] != ""){
198 $this->pw_storage= "clear";
199 } else {
200 $this->pw_storage= $hash;
201 }
202 }
203 } else {
204 /* Preset with vaule from configuration */
205 $this->pw_storage= $hash;
206 }
208 /* Load extra attributes: certificate and picture */
209 $this->load_cert();
210 $this->load_picture();
211 if ($this->userCertificate != ""){
212 $this->had_userCertificate= TRUE;
213 }
214 }
216 /* Reset password storage indicator, used by password_change_needed() */
217 if ($dn == "new"){
218 $this->last_pw_storage= "unset";
219 } else {
220 $this->last_pw_storage= $this->pw_storage;
221 }
223 /* Generate dateOfBirth entry */
224 if (isset ($this->attrs['dateOfBirth'])){
225 /* This entry is ISO 8601 conform */
226 list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
228 $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
229 $this->use_dob= "1";
230 } else {
231 $this->use_dob= "0";
232 }
234 /* Put gender attribute to upper case */
235 if (isset ($this->attrs['gender'])){
236 $this->gender= strtoupper($this->attrs['gender'][0]);
237 }
239 $this->orig_base = $this->base;
240 }
245 /* execute generates the html output for this node */
246 function execute()
247 {
248 /* Call parent execute */
249 plugin::execute();
251 /* Log view */
252 if($this->is_account && !$this->view_logged){
253 $this->view_logged = TRUE;
254 new log("view","users/".get_class($this),$this->dn);
255 }
257 $smarty= get_smarty();
259 /* Fill calendar */
260 if ($this->dateOfBirth == "0"){
261 $date= getdate();
262 } else {
263 if(is_array($this->dateOfBirth)){
264 $date = $this->dateOfBirth;
266 // Trigger on dates like 1985-04-01, getdate only understands timestamps
267 } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
268 $date= getdate(strtotime($this->dateOfBirth));
270 } else {
271 $date = getdate($this->dateOfBirth);
272 }
273 }
275 $days= array();
276 for($d= 1; $d<32; $d++){
277 $days[$d]= $d;
278 }
279 $years= array();
281 if(($date['year']-100)<1901){
282 $start = 1901;
283 }else{
284 $start = $date['year']-100;
285 }
287 $end = $start +100;
289 for($y= $start; $y<=$end; $y++){
290 $years[]= $y;
291 }
292 $years['-']= "- ";
293 $months= msgPool::months();
294 $months['-'] = '- ';
296 $smarty->assign("day", $date["mday"]);
297 $smarty->assign("days", $days);
298 $smarty->assign("months", $months);
299 $smarty->assign("month", $date["mon"]-1);
300 $smarty->assign("years", $years);
301 $smarty->assign("year", $date["year"]);
303 /* Assign sex */
304 $sex= array(0 => " ", "F" => _("female"), "M" => _("male"));
305 $smarty->assign("gender_list", $sex);
306 $language= array_merge(array(0 => " ") ,get_languages(TRUE));
307 $smarty->assign("preferredLanguage_list", $language);
309 /* Get random number for pictures */
310 srand((double)microtime()*1000000);
311 $smarty->assign("rand", rand(0, 10000));
314 /* Do we represent a valid gosaAccount? */
315 if (!$this->is_account){
316 $str = "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
317 msgPool::noValidExtension("GOsa")."</b>";
318 return($str);
319 }
321 /* Base select dialog */
322 $once = true;
323 foreach($_POST as $name => $value){
324 if(preg_match("/^chooseBase/",$name) && $once){
325 $once = false;
326 $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
327 $this->dialog->setCurrentBase($this->base);
328 }
329 }
331 /* Password configure dialog handling */
332 if(is_object($this->pwObject) && $this->pwObject->display){
333 $output= $this->pwObject->configure();
334 if ($output != ""){
335 $this->dialog= TRUE;
336 return $output;
337 }
338 $this->dialog= false;
339 }
341 /* Dialog handling */
342 if(is_object($this->dialog)){
343 /* Must be called before save_object */
344 $this->dialog->save_object();
346 if($this->dialog->isClosed()){
347 $this->dialog = false;
348 }elseif($this->dialog->isSelected()){
350 /* check if selected base is allowed to move to / create a new object */
351 $tmp = $this->get_allowed_bases();
352 if(isset($tmp[$this->dialog->isSelected()])){
353 $this->base = $this->dialog->isSelected();
354 }
355 $this->dialog= false;
356 }else{
357 return($this->dialog->execute());
358 }
359 }
361 /* Want password method editing? */
362 if ($this->acl_is_writeable("userPassword")){
363 if (isset($_POST['edit_pw_method'])){
364 if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
365 $temp= passwordMethod::get_available_methods();
366 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
367 }
368 $this->pwObject->display = TRUE;
369 $this->dialog= TRUE;
370 return ($this->pwObject->configure());
371 }
372 }
374 /* Want picture edit dialog? */
375 if($this->acl_is_writeable("userPicture")) {
376 if (isset($_POST['edit_picture'])){
377 /* Save values for later recovery, in case some presses
378 the cancel button. */
379 $this->old_jpegPhoto= $this->jpegPhoto;
380 $this->old_photoData= $this->photoData;
381 $this->picture_dialog= TRUE;
382 $this->dialog= TRUE;
383 }
384 }
386 /* Remove picture? */
387 if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))) ){
388 if (isset($_POST['picture_remove'])){
389 $this->set_picture ();
390 $this->jpegPhoto= "*removed*";
391 $this->is_modified= TRUE;
392 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
393 }
394 }
396 /* Save picture */
397 if (isset($_POST['picture_edit_finish'])){
399 /* Check for clean upload */
400 if ($_FILES['picture_file']['name'] != ""){
401 if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
402 msg_dialog::display(_("Error"), _("Cannot upload file!"), ERROR_DIALOG);
403 }else{
404 /* Activate new picture */
405 $this->set_picture($_FILES['picture_file']['tmp_name']);
406 }
407 }
408 $this->picture_dialog= FALSE;
409 $this->dialog= FALSE;
410 $this->is_modified= TRUE;
411 }
414 /* Cancel picture */
415 if (isset($_POST['picture_edit_cancel'])){
417 /* Restore values */
418 $this->jpegPhoto= $this->old_jpegPhoto;
419 $this->photoData= $this->old_photoData;
421 /* Update picture */
422 session::set('binary',$this->photoData);
423 session::set('binarytype',"image/jpeg");
424 $this->picture_dialog= FALSE;
425 $this->dialog= FALSE;
426 }
428 /* Toggle dateOfBirth information */
429 if (isset($_POST['set_dob'])){
430 $this->use_dob= ($this->use_dob == "0")?"1":"0";
431 }
434 /* Want certificate= */
435 if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
437 /* Save original values for later reconstruction */
438 foreach (array("certificateSerialNumber", "userCertificate",
439 "userSMIMECertificate", "userPKCS12") as $val){
441 $oval= "old_$val";
442 $this->$oval= $this->$val;
443 }
445 $this->cert_dialog= TRUE;
446 $this->dialog= TRUE;
447 }
450 /* Cancel certificate dialog */
451 if (isset($_POST['cert_edit_cancel'])){
453 /* Restore original values in case of 'cancel' */
454 foreach (array("certificateSerialNumber", "userCertificate",
455 "userSMIMECertificate", "userPKCS12") as $val){
457 $oval= "old_$val";
458 $this->$val= $this->$oval;
459 }
460 $this->cert_dialog= FALSE;
461 $this->dialog= FALSE;
462 }
465 /* Remove certificate? */
466 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
467 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
468 if (isset($_POST["remove_$val"])){
470 /* Reset specified cert*/
471 $this->$val= "";
472 $this->is_modified= TRUE;
473 }
474 }
475 }
477 /* Upload new cert and close dialog? */
478 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
480 $fail =false;
482 if (isset($_POST['cert_edit_finish'])){
484 /* for all certificates do */
485 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
486 as $val){
488 /* Check for clean upload */
489 if (array_key_exists($val."_file", $_FILES) &&
490 array_key_exists('name', $_FILES[$val."_file"]) &&
491 $_FILES[$val."_file"]['name'] != "" &&
492 is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
493 $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
494 }
495 }
497 /* Save serial number */
498 if (isset($_POST["certificateSerialNumber"]) &&
499 $_POST["certificateSerialNumber"] != ""){
501 if (!tests::is_id($_POST["certificateSerialNumber"])){
502 $fail = true;
503 msg_dialog::display(_("Error"), msgPool::invalid(_("Serial number"),$_POST["certificateSerialNumber"],"/[0-9]/"),ERROR_DIALOG);
505 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
506 if ($this->$cert != ""){
507 $smarty->assign("$cert"."_state", "true");
508 } else {
509 $smarty->assign("$cert"."_state", "");
510 }
511 }
512 }
514 $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
515 $this->is_modified= TRUE;
516 }
517 if(!$fail){
518 $this->cert_dialog= FALSE;
519 $this->dialog= FALSE;
520 }
521 }
522 }
523 /* Display picture dialog */
524 if ($this->picture_dialog){
525 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
526 }
528 /* Display cert dialog */
529 if ($this->cert_dialog){
530 $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
531 $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
532 $smarty->assign("certificateSerialNumber",$this->certificateSerialNumber);
534 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
535 if ($this->$cert != ""){
536 /* import certificate */
537 $certificate = new certificate;
538 $certificate->import($this->$cert);
540 /* Read out data*/
541 $timeto = $certificate->getvalidto_date();
542 $timefrom = $certificate->getvalidfrom_date();
545 /* Additional info if start end time is '0' */
546 $add_str_info = "";
547 if($timeto == 0 && $timefrom == 0){
548 $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
549 }
551 $str = "<table summary=\"\" border=0>
552 <tr>
553 <td style='vertical-align:top'>CN</td>
554 <td>".preg_replace("/ /", " ", $certificate->getname())."</td>
555 </tr>
556 </table><br>".
558 sprintf(_("Certificate is valid from %s to %s and is currently %s."),
559 "<b>".date('d M Y',$timefrom)."</b>",
560 "<b>".date('d M Y',$timeto)."</b>",
561 $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
562 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
564 $smarty->assign($cert."info",$str);
565 $smarty->assign($cert."_state","true");
566 } else {
567 $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
568 $smarty->assign($cert."_state","");
569 }
570 }
572 if($this->governmentmode){
573 $smarty->assign("governmentmode", "true");
574 }else{
575 $smarty->assign("governmentmode", "false");
576 }
577 return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
578 }
580 /* Prepare password hashes */
581 if ($this->pw_storage == ""){
582 $this->pw_storage= $this->config->current['HASH'];
583 }
585 $temp= passwordMethod::get_available_methods();
586 $is_configurable= FALSE;
587 $hashes = $temp['name'];
588 if(isset($temp[$this->pw_storage])){
589 $test= new $temp[$this->pw_storage]($this->config);
590 $is_configurable= $test->is_configurable();
591 }else{
592 new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
593 }
596 /* Create password methods array */
597 $pwd_methods = array();
598 foreach($hashes as $id => $name){
599 if(!empty($temp['desc'][$id])){
600 $pwd_methods[$name] = $name." (".$temp['desc'][$id].")";
601 }else{
602 $pwd_methods[$name] = $name;
603 }
604 }
606 /* Load attributes and acl's */
607 $ui =get_userinfo();
608 foreach($this->attributes as $val){
609 $smarty->assign("$val", $this->$val);
610 if(in_array($val,$this->multi_boxes)){
611 $smarty->assign("use_".$val,TRUE);
612 }else{
613 $smarty->assign("use_".$val,FALSE);
614 }
615 }
616 foreach(array("base","pw_storage","edit_picture") as $val){
617 if(in_array($val,$this->multi_boxes)){
618 $smarty->assign("use_".$val,TRUE);
619 }else{
620 $smarty->assign("use_".$val,FALSE);
621 }
622 }
624 /* Set acls */
625 $tmp = $this->plinfo();
626 foreach($tmp['plProvidedAcls'] as $val => $translation){
627 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
628 }
630 $smarty->assign("pwmode", $pwd_methods);
631 $smarty->assign("pwmode_select", $this->pw_storage);
632 $smarty->assign("pw_configurable", $is_configurable);
633 $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !session::is_set('edit'))));
634 $smarty->assign("base_select", $this->base);
635 $smarty->assign("CertificatesACL", $this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
636 $smarty->assign("userPictureACL", $this->getacl("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
637 $smarty->assign("userPicture_is_readable", $this->acl_is_readable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
639 /* Create base acls */
640 $tmp = @$this->allowedBasesToMoveTo();
641 $smarty->assign("bases", $tmp);
643 /* Save government mode attributes */
644 if($this->governmentmode){
645 $smarty->assign("governmentmode", "true");
646 $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
647 "internet,ivbv", "internet,testa", "internet,ivbv,testa");
648 $smarty->assign("ivbbmodes", $ivbbmodes);
649 foreach ($this->govattrs as $val){
650 $smarty->assign("$val", $this->$val);
651 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
652 }
653 } else {
654 $smarty->assign("governmentmode", "false");
655 }
657 /* Special mode for uid */
658 $uidACL= $this->getacl("uid",(!is_object($this->parent) && !session::is_set('edit')));
659 if (isset ($this->dn)){
660 if ($this->dn != "new"){
661 $uidACL= preg_replace("/w/","",$uidACL);
662 }
663 } else {
664 $uidACL= preg_replace("/w/","",$uidACL);
665 }
667 $smarty->assign("uidACL", $uidACL);
668 $smarty->assign("is_template", $this->is_template);
669 $smarty->assign("use_dob", $this->use_dob);
671 if (isset($this->parent)){
672 if (isset($this->parent->by_object['phoneAccount']) &&
673 $this->parent->by_object['phoneAccount']->is_account){
674 $smarty->assign("has_phoneaccount", "true");
675 } else {
676 $smarty->assign("has_phoneaccount", "false");
677 }
678 } else {
679 $smarty->assign("has_phoneaccount", "false");
680 }
681 $smarty->assign("multiple_support" , $this->multiple_support_active);
682 return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
683 }
686 /* remove object from parent */
687 function remove_from_parent()
688 {
689 /* Remove password extension */
690 $temp= passwordMethod::get_available_methods();
692 /* Remove password method from user account */
693 if(isset($temp[$this->pw_storage]) && class_available($temp[$this->pw_storage])){
694 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
695 $this->pwObject->remove_from_parent();
696 }
698 /* Remove user */
699 $ldap= $this->config->get_ldap_link();
700 $ldap->rmdir ($this->dn);
701 if (!$ldap->success()){
702 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
703 }
705 new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
707 /* Delete references to groups */
708 $ldap->cd ($this->config->current['BASE']);
709 $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
710 while ($ldap->fetch()){
711 $g= new group($this->config, $ldap->getDN());
712 $g->removeUser($this->uid);
713 $g->save ();
714 }
716 /* Delete references to object groups */
717 $ldap->cd ($this->config->current['BASE']);
718 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
719 while ($ldap->fetch()){
720 $og= new ogroup($this->config, $ldap->getDN());
721 unset($og->member[$this->dn]);
722 $og->save ();
723 }
725 /* If needed, let the password method do some cleanup */
726 $tmp = new passwordMethod($this->config);
727 $available = $tmp->get_available_methods();
728 if (in_array_ics($this->pw_storage, $available['name'])){
729 $test= new $available[$this->pw_storage]($this->config);
730 $test->attrs= $this->attrs;
731 $test->dn= $this->dn;
732 $test->remove_from_parent();
733 }
735 /* Remove ACL dependencies too */
736 $tmp = new acl($this->config,$this->parent,$this->dn);
737 $tmp->remove_acl();
739 /* Optionally execute a command after we're done */
740 $this->handle_post_events("remove",array("uid" => $this->uid));
741 }
744 /* Save data to object */
745 function save_object()
746 {
747 if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
749 /* Make a backup of the current selected base */
750 $base_tmp = $this->base;
752 /* Parents save function */
753 plugin::save_object ();
755 /* Save government mode attributes */
756 if ($this->governmentmode){
757 foreach ($this->govattrs as $val){
758 if ($this->acl_is_writeable($val,(!is_object($this->parent) && !session::is_set('edit'))) && isset($_POST["$val"])){
759 $data= stripcslashes($_POST["$val"]);
760 if ($data != $this->$val){
761 $this->is_modified= TRUE;
762 }
763 $this->$val= $data;
764 }
765 }
766 }
768 /* In template mode, the uid is autogenerated... */
769 if ($this->is_template){
770 $this->uid= strtolower($this->sn);
771 $this->givenName= $this->sn;
772 }
774 /* Save base and pw_storage, since these are no LDAP attributes */
775 if (isset($_POST['base'])){
777 $tmp = $this->get_allowed_bases();
778 if(isset($tmp[$_POST['base']])){
779 $base= validate($_POST['base']);
780 if ($base != $this->base){
781 $this->is_modified= TRUE;
782 }
783 $this->base= $base;
784 }else{
785 $this->base = $base_tmp;
786 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
787 $this->set_acl_base('dummy,'.$this->base);
788 }
789 }
791 /* Get pw_storage mode */
792 if (isset($_POST['pw_storage'])){
793 foreach(array("pw_storage") as $val){
794 if(isset($_POST[$val])){
795 $data= validate($_POST[$val]);
796 if ($data != $this->$val){
797 $this->is_modified= TRUE;
798 }
799 $this->$val= $data;
800 }
801 }
802 }
804 $this->set_acl_base('dummy,'.$this->base);
805 }
806 }
808 function rebind($ldap, $referral)
809 {
810 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
811 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
812 $this->error = "Success";
813 $this->hascon=true;
814 $this->reconnect= true;
815 return (0);
816 } else {
817 $this->error = "Could not bind to " . $credentials['ADMIN'];
818 return NULL;
819 }
820 }
823 /* Save data to LDAP, depending on is_account we save or delete */
824 function save()
825 {
826 /* Only force save of changes ....
827 If this attributes aren't changed, avoid saving.
828 */
829 if($this->gender=="0") $this->gender ="";
830 if($this->preferredLanguage=="0") $this->preferredLanguage ="";
832 /* First use parents methods to do some basic fillup in $this->attrs */
833 plugin::save ();
835 if ($this->use_dob == "1"){
836 /* 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. */
837 if(!is_array($this->attrs['dateOfBirth'])) {
838 $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
839 }
840 }
842 /* Remove additional objectClasses */
843 $tmp= array();
844 foreach ($this->attrs['objectClass'] as $key => $set){
845 $found= false;
846 foreach (array("ivbbentry", "gosaUserTemplate") as $val){
847 if (preg_match ("/^$set$/i", $val)){
848 $found= true;
849 break;
850 }
851 }
852 if (!$found){
853 $tmp[]= $set;
854 }
855 }
857 /* Replace the objectClass array. This is done because of the
858 separation into government and normal mode. */
859 $this->attrs['objectClass']= $tmp;
861 /* Add objectClasss for template mode? */
862 if ($this->is_template){
863 $this->attrs['objectClass'][]= "gosaUserTemplate";
864 }
866 /* Hard coded government mode? */
867 if ($this->governmentmode){
868 $this->attrs['objectClass'][]= "ivbbentry";
870 /* Copy standard attributes */
871 foreach ($this->govattrs as $val){
872 if ($this->$val != ""){
873 $this->attrs["$val"]= $this->$val;
874 } elseif (!$this->is_new) {
875 $this->attrs["$val"]= array();
876 }
877 }
879 /* Remove attribute if set to "nein" */
880 if ($this->publicVisible == "nein"){
881 $this->attrs['publicVisible']= array();
882 if($this->is_new){
883 unset($this->attrs['publicVisible']);
884 }else{
885 $this->attrs['publicVisible']=array();
886 }
888 }
890 }
892 /* Special handling for attribute userCertificate needed */
893 if ($this->userCertificate != ""){
894 $this->attrs["userCertificate;binary"]= $this->userCertificate;
895 $remove_userCertificate= false;
896 } else {
897 $remove_userCertificate= true;
898 }
900 /* Special handling for dateOfBirth value */
901 if ($this->use_dob != "1"){
902 if ($this->is_new) {
903 unset($this->attrs["dateOfBirth"]);
904 } else {
905 $this->attrs["dateOfBirth"]= array();
906 }
907 }
908 if (!$this->gender){
909 if ($this->is_new) {
910 unset($this->attrs["gender"]);
911 } else {
912 $this->attrs["gender"]= array();
913 }
914 }
915 if (!$this->preferredLanguage){
916 if ($this->is_new) {
917 unset($this->attrs["preferredLanguage"]);
918 } else {
919 $this->attrs["preferredLanguage"]= array();
920 }
921 }
923 /* Special handling for attribute jpegPhote needed, scale image via
924 image magick to 147x200 pixels and inject resulting data. */
925 if ($this->jpegPhoto == "*removed*"){
927 /* Reset attribute to avoid writing *removed* as value */
928 $this->attrs["jpegPhoto"] = array();
930 } else {
932 /* Fallback if there's no image magick inside PHP */
933 if (!function_exists("imagick_blob2image")){
934 /* Get temporary file name for conversation */
935 $fname = tempnam ("/tmp", "GOsa");
937 /* Open file and write out photoData */
938 $fp = fopen ($fname, "w");
939 fwrite ($fp, $this->photoData);
940 fclose ($fp);
942 /* Build conversation query. Filename is generated automatically, so
943 we do not need any special security checks. Exec command and save
944 output. For PHP safe mode, you'll need a configuration which respects
945 image magick as executable... */
946 $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
947 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
948 $query, "Execute");
950 /* Read data written by convert */
951 $output= "";
952 $sh= popen($query, 'r');
953 while (!feof($sh)){
954 $output.= fread($sh, 4096);
955 }
956 pclose($sh);
958 unlink($fname);
960 /* Save attribute */
961 $this->attrs["jpegPhoto"] = $output;
963 } else {
965 /* Load the new uploaded Photo */
966 if(!$handle = imagick_blob2image($this->photoData)) {
967 new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
968 }
970 /* Resizing image to 147x200 and blur */
971 if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
972 new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
973 }
975 /* Converting image to JPEG */
976 if(!imagick_convert($handle,"JPEG")) {
977 new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
978 }
980 /* Creating binary Code for the Image */
981 if(!$dump = imagick_image2blob($handle)){
982 new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
983 }
985 /* Sending Image */
986 $output= $dump;
988 /* Save attribute */
989 $this->attrs["jpegPhoto"] = $output;
990 }
992 }
994 /* This only gets called when user is renaming himself */
995 $ldap= $this->config->get_ldap_link();
996 if ($this->dn != $this->new_dn){
998 /* Write entry on new 'dn' */
999 $this->update_acls($this->dn,$this->new_dn);
1000 $this->move($this->dn, $this->new_dn);
1002 /* Happen to use the new one */
1003 change_ui_dn($this->dn, $this->new_dn);
1004 $this->dn= $this->new_dn;
1005 }
1008 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1009 new entries. So do a check first... */
1010 $ldap->cat ($this->dn, array('dn'));
1011 if ($ldap->fetch()){
1012 $mode= "modify";
1013 } else {
1014 $mode= "add";
1015 $ldap->cd($this->config->current['BASE']);
1016 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1017 }
1019 /* Set password to some junk stuff in case of templates */
1020 if ($this->is_template){
1021 $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
1022 }
1024 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1025 $this->attributes, "Save via $mode");
1027 /* Finally write data with selected 'mode' */
1028 $this->cleanup();
1030 if(isset($this->attrs['preferredLanguage'])){
1031 $ui = session::get('ui');
1032 $ui->language = $this->preferredLanguage;
1033 session::set('ui',$ui);
1034 session::set('Last_init_lang',"update");
1035 }
1037 $ldap->cd ($this->dn);
1038 $ldap->$mode ($this->attrs);
1039 if (!$ldap->success()){
1040 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1041 return (1);
1042 }
1044 /* Remove ACL dependencies too */
1045 if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1046 $tmp = new acl($this->config,$this->parent,$this->dn);
1047 $tmp->update_acl_membership($this->orig_dn,$this->dn);
1048 }
1050 if($mode == "modify"){
1051 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1052 }else{
1053 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1054 }
1056 /* Remove cert?
1057 For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1058 to work around myself. */
1059 if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1061 /* Reset array, assemble new, this should be reworked */
1062 $this->attrs= array();
1063 $this->attrs['userCertificate;binary']= array();
1065 /* Prepare connection */
1066 if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1067 die ("Could not connect to LDAP server");
1068 }
1069 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1070 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1071 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1072 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1073 }
1074 if(isset($config->current['TLS']) && $config->current['TLS'] == "true"){
1075 ldap_start_tls($ds);
1076 }
1077 if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1078 $this->config->current['PASSWORD']))) {
1079 die ("Could not bind to LDAP");
1080 }
1082 /* Modify using attrs */
1083 ldap_mod_del($ds,$this->dn,$this->attrs);
1084 ldap_close($ds);
1085 }
1087 /* If needed, let the password method do some cleanup */
1088 if ($this->pw_storage != $this->last_pw_storage){
1089 $tmp = new passwordMethod($this->config);
1090 $available = $tmp->get_available_methods();
1091 if (in_array_ics($this->last_pw_storage, $available['name'])){
1092 $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1093 $test->attrs= $this->attrs;
1094 $test->remove_from_parent();
1095 }
1096 }
1098 /* Maybe the current password method want's to do some changes... */
1099 if (is_object($this->pwObject)){
1100 $this->pwObject->save($this->dn);
1101 }
1103 /* Optionally execute a command after we're done */
1104 if ($mode == "add"){
1105 $this->handle_post_events("add", array("uid" => $this->uid));
1106 } elseif ($this->is_modified){
1107 $this->handle_post_events("modify", array("uid" => $this->uid));
1108 }
1110 return (0);
1111 }
1114 function update_new_dn()
1115 {
1116 $pt= "";
1117 if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1118 if(!empty($this->personalTitle)){
1119 $pt = $this->personalTitle." ";
1120 }
1121 }
1122 $this->cn= $pt.$this->givenName." ".$this->sn;
1124 /* Permissions for that base? */
1125 if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1126 $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1127 } else {
1128 /* Don't touch dn, if cn hasn't changed */
1129 if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1130 $this->orig_base == $this->base ){
1131 $this->new_dn= $this->dn;
1132 } else {
1133 $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1134 }
1135 }
1136 }
1139 /* Check formular input */
1140 function check()
1141 {
1142 /* Call common method to give check the hook */
1143 $message= plugin::check();
1145 /* Configurable password methods should be configured initially.
1146 */
1147 if($this->last_pw_storage != $this->pw_storage){
1148 $temp= passwordMethod::get_available_methods();
1149 foreach($temp['name'] as $id => $name){
1150 if($name == $this->pw_storage){
1151 if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1152 $message[] = _("The selected password method a requires initial configuration.");
1153 }
1154 break;
1155 }
1156 }
1157 }
1159 $this->update_new_dn();
1161 /* Set the new acl base */
1162 if($this->dn == "new") {
1163 $this->set_acl_base($this->base);
1164 }
1166 /* UID already used? */
1167 $ldap= $this->config->get_ldap_link();
1168 $ldap->cd($this->config->current['BASE']);
1169 $ldap->search("(uid=$this->uid)", array("uid"));
1170 $ldap->fetch();
1171 if ($ldap->count() != 0 && $this->dn == 'new'){
1172 $message[]= msgPool::duplicated(_("Login"));
1173 }
1175 /* In template mode, the uid and givenName are autogenerated... */
1176 if (!$this->is_template){
1177 if ($this->sn == ""){
1178 $message[]= msgPool::required(_("Name"));
1179 }
1180 if ($this->givenName == ""){
1181 $message[]= msgPool::required(_("Given name"));
1182 }
1183 if ($this->uid == ""){
1184 $message[]= msgPool::required(_("Login"));
1185 }
1186 if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1187 $ldap->cat($this->new_dn);
1188 if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1189 $message[]= msgPool::duplicated(_("Name"));
1190 }
1191 }
1192 }
1194 /* Check for valid input */
1195 if ($this->is_modified && !tests::is_uid($this->uid)){
1197 if (strict_uid_mode()){
1198 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1199 } else {
1200 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1201 }
1202 }
1203 if (!tests::is_url($this->labeledURI)){
1204 $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1205 }
1207 /* Check phone numbers */
1208 if (!tests::is_phone_nr($this->telephoneNumber)){
1209 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1210 }
1211 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1212 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1213 }
1214 if (!tests::is_phone_nr($this->mobile)){
1215 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1216 }
1217 if (!tests::is_phone_nr($this->pager)){
1218 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1219 }
1221 /* Check for reserved characers */
1222 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1223 $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1224 }
1225 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1226 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1227 }
1229 return $message;
1230 }
1233 /* Indicate whether a password change is needed or not */
1234 function password_change_needed()
1235 {
1236 if(in_array("pw_storage",$this->multi_boxes)){
1237 return(TRUE);
1238 }
1239 return($this->pw_storage != $this->last_pw_storage);
1240 }
1243 /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1244 function load_picture()
1245 {
1246 $ldap = $this->config->get_ldap_link();
1247 $ldap->cd ($this->dn);
1248 $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1250 if((!$data) || ($data == "*removed*")){
1252 /* In case we don't get an entry, load a default picture */
1253 $this->set_picture ();//"./images/default.jpg");
1254 $this->jpegPhoto= "*removed*";
1255 }else{
1257 /* Set picture */
1258 $this->photoData= $data;
1259 session::set('binary',$this->photoData);
1260 session::set('binarytype',"image/jpeg");
1261 $this->jpegPhoto= "";
1262 }
1263 }
1266 /* Load a certificate from LDAP, this is going to be simplified later on */
1267 function load_cert()
1268 {
1269 $ds= ldap_connect($this->config->current['SERVER']);
1270 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1271 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1272 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1273 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1274 }
1275 if(isset($this->config->current['TLS']) &&
1276 $this->config->current['TLS'] == "true"){
1278 ldap_start_tls($ds);
1279 }
1281 $r= ldap_bind($ds);
1282 $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1284 if ($sr) {
1285 $ei= @ldap_first_entry($ds, $sr);
1287 if ($ei) {
1288 if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1289 $this->userCertificate= "";
1290 } else {
1291 $this->userCertificate= $info[0];
1292 }
1293 }
1294 } else {
1295 $this->userCertificate= "";
1296 }
1298 ldap_unbind($ds);
1299 }
1302 /* Load picture from file to object */
1303 function set_picture($filename ="")
1304 {
1305 if (!is_file($filename) || $filename =="" ){
1306 $filename= "./images/default.jpg";
1307 $this->jpegPhoto= "*removed*";
1308 }
1310 $fd = fopen ($filename, "rb");
1311 $this->photoData= fread ($fd, filesize ($filename));
1312 session::set('binary',$this->photoData);
1313 session::set('binarytype',"image/jpeg");
1314 $this->jpegPhoto= "";
1316 fclose ($fd);
1317 }
1320 /* Load certificate from file to object */
1321 function set_cert($cert, $filename)
1322 {
1323 if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1324 $fd = fopen ($filename, "rb");
1325 if (filesize($filename)>0) {
1326 $this->$cert= fread ($fd, filesize ($filename));
1327 fclose ($fd);
1328 $this->is_modified= TRUE;
1329 } else {
1330 msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1331 }
1332 }
1334 /* Adapt from given 'dn' */
1335 function adapt_from_template($dn, $skip= array())
1336 {
1337 plugin::adapt_from_template($dn, $skip);
1339 /* Get base */
1340 $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1342 if($this->governmentmode){
1344 /* Walk through govattrs */
1345 foreach ($this->govattrs as $val){
1347 if (in_array($val, $skip)){
1348 continue;
1349 }
1351 if (isset($this->attrs["$val"][0])){
1353 /* If attribute is set, replace dynamic parts:
1354 %sn, %givenName and %uid. Fill these in our local variables. */
1355 $value= $this->attrs["$val"][0];
1357 foreach (array("sn", "givenName", "uid") as $repl){
1358 if (preg_match("/%$repl/i", $value)){
1359 $value= preg_replace ("/%$repl/i",
1360 $this->parent->$repl, $value);
1361 }
1362 }
1363 $this->$val= $value;
1364 }
1365 }
1366 }
1368 /* Get back uid/sn/givenName - only write if nothing's skipped */
1369 if ($this->parent !== NULL && count($skip) == 0){
1370 $this->uid= $this->parent->uid;
1371 $this->sn= $this->parent->sn;
1372 $this->givenName= $this->parent->givenName;
1373 }
1374 }
1377 /* This avoids that users move themselves out of their rights.
1378 */
1379 function allowedBasesToMoveTo()
1380 {
1381 /* Get bases */
1382 $bases = $this->get_allowed_bases();
1383 return($bases);
1384 }
1387 function getCopyDialog()
1388 {
1389 $str = "";
1391 session::set('binary',$this->photoData);
1392 session::set('binarytype',"image/jpeg");
1394 /* Get random number for pictures */
1395 srand((double)microtime()*1000000);
1396 $rand = rand(0, 10000);
1398 $smarty = get_smarty();
1400 $smarty->assign("passwordTodo","clear");
1402 if(isset($_POST['passwordTodo'])){
1403 $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1404 }
1406 $smarty->assign("sn", $this->sn);
1407 $smarty->assign("givenName",$this->givenName);
1408 $smarty->assign("uid", $this->uid);
1409 $smarty->assign("rand", $rand);
1410 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1413 $ret = array();
1414 $ret['string'] = $str;
1415 $ret['status'] = "";
1416 return($ret);
1417 }
1419 function saveCopyDialog()
1420 {
1421 /* Set_acl_base */
1422 $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1424 if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1425 $this->set_picture($_FILES['picture_file']['tmp_name']);
1426 }
1428 /* Remove picture? */
1429 if (isset($_POST['picture_remove'])){
1430 $this->jpegPhoto= "*removed*";
1431 $this->set_picture ("./images/default.jpg");
1432 $this->is_modified= TRUE;
1433 }
1435 $attrs = array("uid","givenName","sn");
1436 foreach($attrs as $attr){
1437 if(isset($_POST[$attr])){
1438 $this->$attr = $_POST[$attr];
1439 }
1440 }
1441 }
1444 function PrepareForCopyPaste($source)
1445 {
1446 plugin::PrepareForCopyPaste($source);
1448 /* Reset certificate information addepted from source user
1449 to avoid setting the same user certificate for the destination user. */
1450 $this->userPKCS12= "";
1451 $this->userSMIMECertificate= "";
1452 $this->userCertificate= "";
1453 $this->certificateSerialNumber= "";
1454 $this->old_certificateSerialNumber= "";
1455 $this->old_userPKCS12= "";
1456 $this->old_userSMIMECertificate= "";
1457 $this->old_userCertificate= "";
1458 }
1461 static function plInfo()
1462 {
1464 $govattrs= array(
1465 "gouvernmentOrganizationalUnit" => _("Unit"),
1466 "houseIdentifier" => _("House identifier"),
1467 "vocation" => _("Vocation"),
1468 "ivbbLastDeliveryCollective" => _("Last delivery"),
1469 "gouvernmentOrganizationalPersonLocality" => _("Person locality"),
1470 "gouvernmentOrganizationalUnitDescription" => _("Unit description"),
1471 "gouvernmentOrganizationalUnitSubjectArea" => _("Subject area"),
1472 "functionalTitle" => _("Functional title"),
1473 "certificateSerialNumber" => _("Certificate serial number"),
1474 "publicVisible" => _("Public visible"),
1475 "street" => _("Street"),
1476 "role" => _("Role"),
1477 "postalCode" => _("Postal code"));
1479 $ret = array(
1480 "plShortName" => _("Generic"),
1481 "plDescription" => _("Generic user settings"),
1482 "plSelfModify" => TRUE,
1483 "plDepends" => array(),
1484 "plPriority" => 1,
1485 "plSection" => array("personal" => _("My account")),
1486 "plCategory" => array("users" => array("description" => _("Users"),
1487 "objectClass" => "gosaAccount")),
1489 "plProvidedAcls" => array(
1490 "base" => _("Base"),
1491 "userPassword" => _("User password"),
1492 "sn" => _("Surename"),
1493 "givenName" => _("Given name"),
1494 "uid" => _("User identification"),
1495 "personalTitle" => _("Personal title"),
1496 "academicTitle" => _("Academic title"),
1497 "homePostalAddress" => _("Home postal address"),
1498 "homePhone" => _("Home phone number"),
1499 "labeledURI" => _("Homepage"),
1500 "o" => _("Organization"),
1501 "ou" => _("Department"),
1502 "dateOfBirth" => _("Date of birth"),
1503 "gender" => _("Gender"),
1504 "preferredLanguage" => _("Preferred language"),
1505 "departmentNumber" => _("Department number"),
1506 "employeeNumber" => _("Employee number"),
1507 "employeeType" => _("Employee type"),
1508 "l" => _("Location"),
1509 "st" => _("State"),
1510 "userPicture" => _("User picture"),
1511 "roomNumber" => _("Room number"),
1512 "telephoneNumber" => _("Telefon number"),
1513 "mobile" => _("Mobile number"),
1514 "pager" => _("Pager number"),
1515 "Certificate" => _("User certificates"),
1517 "postalAddress" => _("Postal address"),
1518 "facsimileTelephoneNumber" => _("Fax number"))
1519 );
1521 /* Append government attributes if required */
1522 global $config;
1523 if (isset($config->current['GOVERNMENTMODE']) && preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1524 foreach($govattrs as $attr => $desc){
1525 $ret["plProvidedAcls"][$attr] = $desc;
1526 }
1527 }
1528 return($ret);
1529 }
1531 function get_multi_edit_values()
1532 {
1533 $ret = plugin::get_multi_edit_values();
1534 if(in_array("pw_storage",$this->multi_boxes)){
1535 $ret['pw_storage'] = $this->pw_storage;
1536 }
1537 if(in_array("edit_picture",$this->multi_boxes)){
1538 $ret['jpegPhoto'] = $this->jpegPhoto;
1539 $ret['photoData'] = $this->photoData;
1540 $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1541 $ret['old_photoData'] = $this->old_photoData;
1542 }
1543 if(isset($ret['dateOfBirth'])){
1544 unset($ret['dateOfBirth']);
1545 }
1546 if(isset($ret['cn'])){
1547 unset($ret['cn']);
1548 }
1549 $ret['is_modified'] = $this->is_modified;
1550 if(in_array("base",$this->multi_boxes)){
1551 $ret['orig_base']="Changed_by_Multi_Plug";
1552 $ret['base']=$this->base;
1553 }
1554 return($ret);
1555 }
1558 function multiple_save_object()
1559 {
1560 plugin::multiple_save_object();
1562 /* Get pw_storage mode */
1563 if (isset($_POST['pw_storage'])){
1564 foreach(array("pw_storage") as $val){
1565 if(isset($_POST[$val])){
1566 $data= validate(get_post($val));
1567 if ($data != $this->$val){
1568 $this->is_modified= TRUE;
1569 }
1570 $this->$val= $data;
1571 }
1572 }
1573 }
1574 if(isset($_POST['base'])){
1575 $this->base = get_post('base');
1576 }
1578 if(isset($_POST['user_mulitple_edit'])){
1579 foreach(array("base","pw_storage","edit_picture") as $val){
1580 if(isset($_POST["use_".$val])){
1581 $this->multi_boxes[] = $val;
1582 }
1583 }
1584 }
1585 }
1588 function multiple_check()
1589 {
1590 /* Call check() to set new_dn correctly ... */
1591 $message = plugin::multiple_check();
1593 /* Set the new acl base */
1594 if($this->dn == "new") {
1595 $this->set_acl_base($this->base);
1596 }
1597 if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1598 $message[]= msgPool::invalid(_("Homepage"));
1599 }
1600 if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1601 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1602 }
1603 if (!tests::is_phone_nr($this->facsimileTelephoneNumber) && in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1604 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1605 }
1606 if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1607 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1608 }
1609 if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1610 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1611 }
1612 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1613 $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1614 }
1615 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1616 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1617 }
1618 return($message);
1619 }
1623 function multiple_execute()
1624 {
1625 return($this->execute());
1626 }
1629 }
1631 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1632 ?>