0200dae80cd2de5b089b482766064583762b92a5
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 }
788 }
790 /* Get pw_storage mode */
791 if (isset($_POST['pw_storage'])){
792 foreach(array("pw_storage") as $val){
793 if(isset($_POST[$val])){
794 $data= validate($_POST[$val]);
795 if ($data != $this->$val){
796 $this->is_modified= TRUE;
797 }
798 $this->$val= $data;
799 }
800 }
801 }
802 }
803 }
805 function rebind($ldap, $referral)
806 {
807 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
808 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
809 $this->error = "Success";
810 $this->hascon=true;
811 $this->reconnect= true;
812 return (0);
813 } else {
814 $this->error = "Could not bind to " . $credentials['ADMIN'];
815 return NULL;
816 }
817 }
820 /* Save data to LDAP, depending on is_account we save or delete */
821 function save()
822 {
823 /* Only force save of changes ....
824 If this attributes aren't changed, avoid saving.
825 */
826 if($this->gender=="0") $this->gender ="";
827 if($this->preferredLanguage=="0") $this->preferredLanguage ="";
829 /* First use parents methods to do some basic fillup in $this->attrs */
830 plugin::save ();
832 if ($this->use_dob == "1"){
833 /* 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. */
834 if(!is_array($this->attrs['dateOfBirth'])) {
835 $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
836 }
837 }
839 /* Remove additional objectClasses */
840 $tmp= array();
841 foreach ($this->attrs['objectClass'] as $key => $set){
842 $found= false;
843 foreach (array("ivbbentry", "gosaUserTemplate") as $val){
844 if (preg_match ("/^$set$/i", $val)){
845 $found= true;
846 break;
847 }
848 }
849 if (!$found){
850 $tmp[]= $set;
851 }
852 }
854 /* Replace the objectClass array. This is done because of the
855 separation into government and normal mode. */
856 $this->attrs['objectClass']= $tmp;
858 /* Add objectClasss for template mode? */
859 if ($this->is_template){
860 $this->attrs['objectClass'][]= "gosaUserTemplate";
861 }
863 /* Hard coded government mode? */
864 if ($this->governmentmode){
865 $this->attrs['objectClass'][]= "ivbbentry";
867 /* Copy standard attributes */
868 foreach ($this->govattrs as $val){
869 if ($this->$val != ""){
870 $this->attrs["$val"]= $this->$val;
871 } elseif (!$this->is_new) {
872 $this->attrs["$val"]= array();
873 }
874 }
876 /* Remove attribute if set to "nein" */
877 if ($this->publicVisible == "nein"){
878 $this->attrs['publicVisible']= array();
879 if($this->is_new){
880 unset($this->attrs['publicVisible']);
881 }else{
882 $this->attrs['publicVisible']=array();
883 }
885 }
887 }
889 /* Special handling for attribute userCertificate needed */
890 if ($this->userCertificate != ""){
891 $this->attrs["userCertificate;binary"]= $this->userCertificate;
892 $remove_userCertificate= false;
893 } else {
894 $remove_userCertificate= true;
895 }
897 /* Special handling for dateOfBirth value */
898 if ($this->use_dob != "1"){
899 if ($this->is_new) {
900 unset($this->attrs["dateOfBirth"]);
901 } else {
902 $this->attrs["dateOfBirth"]= array();
903 }
904 }
905 if (!$this->gender){
906 if ($this->is_new) {
907 unset($this->attrs["gender"]);
908 } else {
909 $this->attrs["gender"]= array();
910 }
911 }
912 if (!$this->preferredLanguage){
913 if ($this->is_new) {
914 unset($this->attrs["preferredLanguage"]);
915 } else {
916 $this->attrs["preferredLanguage"]= array();
917 }
918 }
920 /* Special handling for attribute jpegPhote needed, scale image via
921 image magick to 147x200 pixels and inject resulting data. */
922 if ($this->jpegPhoto == "*removed*"){
924 /* Reset attribute to avoid writing *removed* as value */
925 $this->attrs["jpegPhoto"] = array();
927 } else {
929 /* Fallback if there's no image magick inside PHP */
930 if (!function_exists("imagick_blob2image")){
931 /* Get temporary file name for conversation */
932 $fname = tempnam (TEMP_DIR, "GOsa");
934 /* Open file and write out photoData */
935 $fp = fopen ($fname, "w");
936 fwrite ($fp, $this->photoData);
937 fclose ($fp);
939 /* Build conversation query. Filename is generated automatically, so
940 we do not need any special security checks. Exec command and save
941 output. For PHP safe mode, you'll need a configuration which respects
942 image magick as executable... */
943 $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
944 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
945 $query, "Execute");
947 /* Read data written by convert */
948 $output= "";
949 $sh= popen($query, 'r');
950 while (!feof($sh)){
951 $output.= fread($sh, 4096);
952 }
953 pclose($sh);
955 unlink($fname);
957 /* Save attribute */
958 $this->attrs["jpegPhoto"] = $output;
960 } else {
962 /* Load the new uploaded Photo */
963 if(!$handle = imagick_blob2image($this->photoData)) {
964 new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
965 }
967 /* Resizing image to 147x200 and blur */
968 if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
969 new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
970 }
972 /* Converting image to JPEG */
973 if(!imagick_convert($handle,"JPEG")) {
974 new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
975 }
977 /* Creating binary Code for the Image */
978 if(!$dump = imagick_image2blob($handle)){
979 new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
980 }
982 /* Sending Image */
983 $output= $dump;
985 /* Save attribute */
986 $this->attrs["jpegPhoto"] = $output;
987 }
989 }
991 /* This only gets called when user is renaming himself */
992 $ldap= $this->config->get_ldap_link();
993 if ($this->dn != $this->new_dn){
995 /* Write entry on new 'dn' */
996 $this->update_acls($this->dn,$this->new_dn);
997 $this->move($this->dn, $this->new_dn);
999 /* Happen to use the new one */
1000 change_ui_dn($this->dn, $this->new_dn);
1001 $this->dn= $this->new_dn;
1002 }
1005 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1006 new entries. So do a check first... */
1007 $ldap->cat ($this->dn, array('dn'));
1008 if ($ldap->fetch()){
1009 $mode= "modify";
1010 } else {
1011 $mode= "add";
1012 $ldap->cd($this->config->current['BASE']);
1013 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1014 }
1016 /* Set password to some junk stuff in case of templates */
1017 if ($this->is_template){
1018 $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
1019 }
1021 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1022 $this->attributes, "Save via $mode");
1024 /* Finally write data with selected 'mode' */
1025 $this->cleanup();
1027 if(isset($this->attrs['preferredLanguage'])){
1028 $ui = session::get('ui');
1029 $ui->language = $this->preferredLanguage;
1030 session::set('ui',$ui);
1031 session::set('Last_init_lang',"update");
1032 }
1034 $ldap->cd ($this->dn);
1035 $ldap->$mode ($this->attrs);
1036 if (!$ldap->success()){
1037 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1038 return (1);
1039 }
1041 /* Remove ACL dependencies too */
1042 if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1043 $tmp = new acl($this->config,$this->parent,$this->dn);
1044 $tmp->update_acl_membership($this->orig_dn,$this->dn);
1045 }
1047 if($mode == "modify"){
1048 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1049 }else{
1050 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1051 }
1053 /* Remove cert?
1054 For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1055 to work around myself. */
1056 if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1058 /* Reset array, assemble new, this should be reworked */
1059 $this->attrs= array();
1060 $this->attrs['userCertificate;binary']= array();
1062 /* Prepare connection */
1063 if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1064 die ("Could not connect to LDAP server");
1065 }
1066 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1067 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1068 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1069 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1070 }
1071 if(isset($config->current['TLS']) && $config->current['TLS'] == "true"){
1072 ldap_start_tls($ds);
1073 }
1074 if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1075 $this->config->current['PASSWORD']))) {
1076 die ("Could not bind to LDAP");
1077 }
1079 /* Modify using attrs */
1080 ldap_mod_del($ds,$this->dn,$this->attrs);
1081 ldap_close($ds);
1082 }
1084 /* If needed, let the password method do some cleanup */
1085 if ($this->pw_storage != $this->last_pw_storage){
1086 $tmp = new passwordMethod($this->config);
1087 $available = $tmp->get_available_methods();
1088 if (in_array_ics($this->last_pw_storage, $available['name'])){
1089 $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1090 $test->attrs= $this->attrs;
1091 $test->remove_from_parent();
1092 }
1093 }
1095 /* Maybe the current password method want's to do some changes... */
1096 if (is_object($this->pwObject)){
1097 $this->pwObject->save($this->dn);
1098 }
1100 /* Optionally execute a command after we're done */
1101 if ($mode == "add"){
1102 $this->handle_post_events("add", array("uid" => $this->uid));
1103 } elseif ($this->is_modified){
1104 $this->handle_post_events("modify", array("uid" => $this->uid));
1105 }
1107 return (0);
1108 }
1111 function update_new_dn()
1112 {
1113 $pt= "";
1114 if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1115 if(!empty($this->personalTitle)){
1116 $pt = $this->personalTitle." ";
1117 }
1118 }
1119 $this->cn= $pt.$this->givenName." ".$this->sn;
1121 /* Permissions for that base? */
1122 if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1123 $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1124 } else {
1125 /* Don't touch dn, if cn hasn't changed */
1126 if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1127 $this->orig_base == $this->base ){
1128 $this->new_dn= $this->dn;
1129 } else {
1130 $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1131 }
1132 }
1133 }
1136 /* Check formular input */
1137 function check()
1138 {
1139 /* Call common method to give check the hook */
1140 $message= plugin::check();
1142 /* Configurable password methods should be configured initially.
1143 */
1144 if($this->last_pw_storage != $this->pw_storage){
1145 $temp= passwordMethod::get_available_methods();
1146 foreach($temp['name'] as $id => $name){
1147 if($name == $this->pw_storage){
1148 if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1149 $message[] = _("The selected password method a requires initial configuration.");
1150 }
1151 break;
1152 }
1153 }
1154 }
1156 $this->update_new_dn();
1158 /* Set the new acl base */
1159 if($this->dn == "new") {
1160 $this->set_acl_base($this->base);
1161 }
1163 /* UID already used? */
1164 $ldap= $this->config->get_ldap_link();
1165 $ldap->cd($this->config->current['BASE']);
1166 $ldap->search("(uid=$this->uid)", array("uid"));
1167 $ldap->fetch();
1168 if ($ldap->count() != 0 && $this->dn == 'new'){
1169 $message[]= msgPool::duplicated(_("Login"));
1170 }
1172 /* In template mode, the uid and givenName are autogenerated... */
1173 if (!$this->is_template){
1174 if ($this->sn == ""){
1175 $message[]= msgPool::required(_("Name"));
1176 }
1177 if ($this->givenName == ""){
1178 $message[]= msgPool::required(_("Given name"));
1179 }
1180 if ($this->uid == ""){
1181 $message[]= msgPool::required(_("Login"));
1182 }
1183 if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1184 $ldap->cat($this->new_dn);
1185 if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1186 $message[]= msgPool::duplicated(_("Name"));
1187 }
1188 }
1189 }
1191 /* Check for valid input */
1192 if ($this->is_modified && !tests::is_uid($this->uid)){
1194 if (strict_uid_mode()){
1195 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1196 } else {
1197 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1198 }
1199 }
1200 if (!tests::is_url($this->labeledURI)){
1201 $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1202 }
1204 /* Check phone numbers */
1205 if (!tests::is_phone_nr($this->telephoneNumber)){
1206 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1207 }
1208 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1209 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1210 }
1211 if (!tests::is_phone_nr($this->mobile)){
1212 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1213 }
1214 if (!tests::is_phone_nr($this->pager)){
1215 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1216 }
1218 /* Check for reserved characers */
1219 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1220 $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1221 }
1222 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1223 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1224 }
1226 return $message;
1227 }
1230 /* Indicate whether a password change is needed or not */
1231 function password_change_needed()
1232 {
1233 if(in_array("pw_storage",$this->multi_boxes)){
1234 return(TRUE);
1235 }
1236 return($this->pw_storage != $this->last_pw_storage);
1237 }
1240 /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1241 function load_picture()
1242 {
1243 $ldap = $this->config->get_ldap_link();
1244 $ldap->cd ($this->dn);
1245 $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1247 if((!$data) || ($data == "*removed*")){
1249 /* In case we don't get an entry, load a default picture */
1250 $this->set_picture ();//"./images/default.jpg");
1251 $this->jpegPhoto= "*removed*";
1252 }else{
1254 /* Set picture */
1255 $this->photoData= $data;
1256 session::set('binary',$this->photoData);
1257 session::set('binarytype',"image/jpeg");
1258 $this->jpegPhoto= "";
1259 }
1260 }
1263 /* Load a certificate from LDAP, this is going to be simplified later on */
1264 function load_cert()
1265 {
1266 $ds= ldap_connect($this->config->current['SERVER']);
1267 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1268 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1269 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1270 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1271 }
1272 if(isset($this->config->current['TLS']) &&
1273 $this->config->current['TLS'] == "true"){
1275 ldap_start_tls($ds);
1276 }
1278 $r= ldap_bind($ds);
1279 $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1281 if ($sr) {
1282 $ei= @ldap_first_entry($ds, $sr);
1284 if ($ei) {
1285 if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1286 $this->userCertificate= "";
1287 } else {
1288 $this->userCertificate= $info[0];
1289 }
1290 }
1291 } else {
1292 $this->userCertificate= "";
1293 }
1295 ldap_unbind($ds);
1296 }
1299 /* Load picture from file to object */
1300 function set_picture($filename ="")
1301 {
1302 if (!is_file($filename) || $filename =="" ){
1303 $filename= "./images/default.jpg";
1304 $this->jpegPhoto= "*removed*";
1305 }
1307 $fd = fopen ($filename, "rb");
1308 $this->photoData= fread ($fd, filesize ($filename));
1309 session::set('binary',$this->photoData);
1310 session::set('binarytype',"image/jpeg");
1311 $this->jpegPhoto= "";
1313 fclose ($fd);
1314 }
1317 /* Load certificate from file to object */
1318 function set_cert($cert, $filename)
1319 {
1320 if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1321 $fd = fopen ($filename, "rb");
1322 if (filesize($filename)>0) {
1323 $this->$cert= fread ($fd, filesize ($filename));
1324 fclose ($fd);
1325 $this->is_modified= TRUE;
1326 } else {
1327 msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1328 }
1329 }
1331 /* Adapt from given 'dn' */
1332 function adapt_from_template($dn, $skip= array())
1333 {
1334 plugin::adapt_from_template($dn, $skip);
1336 /* Get base */
1337 $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1339 if($this->governmentmode){
1341 /* Walk through govattrs */
1342 foreach ($this->govattrs as $val){
1344 if (in_array($val, $skip)){
1345 continue;
1346 }
1348 if (isset($this->attrs["$val"][0])){
1350 /* If attribute is set, replace dynamic parts:
1351 %sn, %givenName and %uid. Fill these in our local variables. */
1352 $value= $this->attrs["$val"][0];
1354 foreach (array("sn", "givenName", "uid") as $repl){
1355 if (preg_match("/%$repl/i", $value)){
1356 $value= preg_replace ("/%$repl/i",
1357 $this->parent->$repl, $value);
1358 }
1359 }
1360 $this->$val= $value;
1361 }
1362 }
1363 }
1365 /* Get back uid/sn/givenName - only write if nothing's skipped */
1366 if ($this->parent !== NULL && count($skip) == 0){
1367 $this->uid= $this->parent->uid;
1368 $this->sn= $this->parent->sn;
1369 $this->givenName= $this->parent->givenName;
1370 }
1371 }
1374 /* This avoids that users move themselves out of their rights.
1375 */
1376 function allowedBasesToMoveTo()
1377 {
1378 /* Get bases */
1379 $bases = $this->get_allowed_bases();
1380 return($bases);
1381 }
1384 function getCopyDialog()
1385 {
1386 $str = "";
1388 session::set('binary',$this->photoData);
1389 session::set('binarytype',"image/jpeg");
1391 /* Get random number for pictures */
1392 srand((double)microtime()*1000000);
1393 $rand = rand(0, 10000);
1395 $smarty = get_smarty();
1397 $smarty->assign("passwordTodo","clear");
1399 if(isset($_POST['passwordTodo'])){
1400 $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1401 }
1403 $smarty->assign("sn", $this->sn);
1404 $smarty->assign("givenName",$this->givenName);
1405 $smarty->assign("uid", $this->uid);
1406 $smarty->assign("rand", $rand);
1407 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1410 $ret = array();
1411 $ret['string'] = $str;
1412 $ret['status'] = "";
1413 return($ret);
1414 }
1416 function saveCopyDialog()
1417 {
1418 /* Set_acl_base */
1419 $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1421 if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1422 $this->set_picture($_FILES['picture_file']['tmp_name']);
1423 }
1425 /* Remove picture? */
1426 if (isset($_POST['picture_remove'])){
1427 $this->jpegPhoto= "*removed*";
1428 $this->set_picture ("./images/default.jpg");
1429 $this->is_modified= TRUE;
1430 }
1432 $attrs = array("uid","givenName","sn");
1433 foreach($attrs as $attr){
1434 if(isset($_POST[$attr])){
1435 $this->$attr = $_POST[$attr];
1436 }
1437 }
1438 }
1441 function PrepareForCopyPaste($source)
1442 {
1443 plugin::PrepareForCopyPaste($source);
1445 /* Reset certificate information addepted from source user
1446 to avoid setting the same user certificate for the destination user. */
1447 $this->userPKCS12= "";
1448 $this->userSMIMECertificate= "";
1449 $this->userCertificate= "";
1450 $this->certificateSerialNumber= "";
1451 $this->old_certificateSerialNumber= "";
1452 $this->old_userPKCS12= "";
1453 $this->old_userSMIMECertificate= "";
1454 $this->old_userCertificate= "";
1455 }
1458 static function plInfo()
1459 {
1461 $govattrs= array(
1462 "gouvernmentOrganizationalUnit" => _("Unit"),
1463 "houseIdentifier" => _("House identifier"),
1464 "vocation" => _("Vocation"),
1465 "ivbbLastDeliveryCollective" => _("Last delivery"),
1466 "gouvernmentOrganizationalPersonLocality" => _("Person locality"),
1467 "gouvernmentOrganizationalUnitDescription" => _("Unit description"),
1468 "gouvernmentOrganizationalUnitSubjectArea" => _("Subject area"),
1469 "functionalTitle" => _("Functional title"),
1470 "certificateSerialNumber" => _("Certificate serial number"),
1471 "publicVisible" => _("Public visible"),
1472 "street" => _("Street"),
1473 "role" => _("Role"),
1474 "postalCode" => _("Postal code"));
1476 $ret = array(
1477 "plShortName" => _("Generic"),
1478 "plDescription" => _("Generic user settings"),
1479 "plSelfModify" => TRUE,
1480 "plDepends" => array(),
1481 "plPriority" => 1,
1482 "plSection" => array("personal" => _("My account")),
1483 "plCategory" => array("users" => array("description" => _("Users"),
1484 "objectClass" => "gosaAccount")),
1486 "plProvidedAcls" => array(
1487 "base" => _("Base"),
1488 "userPassword" => _("User password"),
1489 "sn" => _("Surename"),
1490 "givenName" => _("Given name"),
1491 "uid" => _("User identification"),
1492 "personalTitle" => _("Personal title"),
1493 "academicTitle" => _("Academic title"),
1494 "homePostalAddress" => _("Home postal address"),
1495 "homePhone" => _("Home phone number"),
1496 "labeledURI" => _("Homepage"),
1497 "o" => _("Organization"),
1498 "ou" => _("Department"),
1499 "dateOfBirth" => _("Date of birth"),
1500 "gender" => _("Gender"),
1501 "preferredLanguage" => _("Preferred language"),
1502 "departmentNumber" => _("Department number"),
1503 "employeeNumber" => _("Employee number"),
1504 "employeeType" => _("Employee type"),
1505 "l" => _("Location"),
1506 "st" => _("State"),
1507 "userPicture" => _("User picture"),
1508 "roomNumber" => _("Room number"),
1509 "telephoneNumber" => _("Telefon number"),
1510 "mobile" => _("Mobile number"),
1511 "pager" => _("Pager number"),
1512 "Certificate" => _("User certificates"),
1514 "postalAddress" => _("Postal address"),
1515 "facsimileTelephoneNumber" => _("Fax number"))
1516 );
1518 /* Append government attributes if required */
1519 global $config;
1520 if (isset($config->current['GOVERNMENTMODE']) && preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1521 foreach($govattrs as $attr => $desc){
1522 $ret["plProvidedAcls"][$attr] = $desc;
1523 }
1524 }
1525 return($ret);
1526 }
1528 function get_multi_edit_values()
1529 {
1530 $ret = plugin::get_multi_edit_values();
1531 if(in_array("pw_storage",$this->multi_boxes)){
1532 $ret['pw_storage'] = $this->pw_storage;
1533 }
1534 if(in_array("edit_picture",$this->multi_boxes)){
1535 $ret['jpegPhoto'] = $this->jpegPhoto;
1536 $ret['photoData'] = $this->photoData;
1537 $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1538 $ret['old_photoData'] = $this->old_photoData;
1539 }
1540 if(isset($ret['dateOfBirth'])){
1541 unset($ret['dateOfBirth']);
1542 }
1543 if(isset($ret['cn'])){
1544 unset($ret['cn']);
1545 }
1546 $ret['is_modified'] = $this->is_modified;
1547 if(in_array("base",$this->multi_boxes)){
1548 $ret['orig_base']="Changed_by_Multi_Plug";
1549 $ret['base']=$this->base;
1550 }
1551 return($ret);
1552 }
1555 function multiple_save_object()
1556 {
1557 plugin::multiple_save_object();
1559 /* Get pw_storage mode */
1560 if (isset($_POST['pw_storage'])){
1561 foreach(array("pw_storage") as $val){
1562 if(isset($_POST[$val])){
1563 $data= validate(get_post($val));
1564 if ($data != $this->$val){
1565 $this->is_modified= TRUE;
1566 }
1567 $this->$val= $data;
1568 }
1569 }
1570 }
1571 if(isset($_POST['base'])){
1572 $this->base = get_post('base');
1573 }
1575 if(isset($_POST['user_mulitple_edit'])){
1576 foreach(array("base","pw_storage","edit_picture") as $val){
1577 if(isset($_POST["use_".$val])){
1578 $this->multi_boxes[] = $val;
1579 }
1580 }
1581 }
1582 }
1585 function multiple_check()
1586 {
1587 /* Call check() to set new_dn correctly ... */
1588 $message = plugin::multiple_check();
1590 /* Set the new acl base */
1591 if($this->dn == "new") {
1592 $this->set_acl_base($this->base);
1593 }
1594 if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1595 $message[]= msgPool::invalid(_("Homepage"));
1596 }
1597 if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1598 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1599 }
1600 if (!tests::is_phone_nr($this->facsimileTelephoneNumber) && in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1601 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1602 }
1603 if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1604 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1605 }
1606 if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1607 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1608 }
1609 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1610 $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1611 }
1612 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1613 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1614 }
1615 return($message);
1616 }
1620 function multiple_execute()
1621 {
1622 return($this->execute());
1623 }
1626 }
1628 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1629 ?>