7c34bc6b989e43c71cbdeceb5cb1ba74cdb6aca2
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 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 /* Check if we are allowed to create/move this user
1164 */
1166 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1167 $message[]= msgPool::permCreate();
1168 }elseif($this->orig_dn != "new" && $this->new_dn != $this->orig_dn && !$this->acl_is_moveable($this->base)){
1169 $message[]= msgPool::permMove();
1170 }
1172 /* UID already used? */
1173 $ldap= $this->config->get_ldap_link();
1174 $ldap->cd($this->config->current['BASE']);
1175 $ldap->search("(uid=$this->uid)", array("uid"));
1176 $ldap->fetch();
1177 if ($ldap->count() != 0 && $this->dn == 'new'){
1178 $message[]= msgPool::duplicated(_("Login"));
1179 }
1181 /* In template mode, the uid and givenName are autogenerated... */
1182 if ($this->sn == ""){
1183 $message[]= msgPool::required(_("Name"));
1184 }
1186 if (!$this->is_template){
1187 if ($this->givenName == ""){
1188 $message[]= msgPool::required(_("Given name"));
1189 }
1190 if ($this->uid == ""){
1191 $message[]= msgPool::required(_("Login"));
1192 }
1193 if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1194 $ldap->cat($this->new_dn);
1195 if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1196 $message[]= msgPool::duplicated(_("Name"));
1197 }
1198 }
1199 }
1201 /* Check for valid input */
1202 if ($this->is_modified && !tests::is_uid($this->uid)){
1204 if (strict_uid_mode()){
1205 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1206 } else {
1207 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1208 }
1209 }
1210 if (!tests::is_url($this->labeledURI)){
1211 $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1212 }
1214 /* Check phone numbers */
1215 if (!tests::is_phone_nr($this->telephoneNumber)){
1216 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1217 }
1218 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1219 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1220 }
1221 if (!tests::is_phone_nr($this->mobile)){
1222 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1223 }
1224 if (!tests::is_phone_nr($this->pager)){
1225 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1226 }
1228 /* Check for reserved characers */
1229 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1230 $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1231 }
1232 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1233 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1234 }
1236 return $message;
1237 }
1240 /* Indicate whether a password change is needed or not */
1241 function password_change_needed()
1242 {
1243 if(in_array("pw_storage",$this->multi_boxes)){
1244 return(TRUE);
1245 }
1246 return($this->pw_storage != $this->last_pw_storage);
1247 }
1250 /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1251 function load_picture()
1252 {
1253 $ldap = $this->config->get_ldap_link();
1254 $ldap->cd ($this->dn);
1255 $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1257 if((!$data) || ($data == "*removed*")){
1259 /* In case we don't get an entry, load a default picture */
1260 $this->set_picture ();//"./images/default.jpg");
1261 $this->jpegPhoto= "*removed*";
1262 }else{
1264 /* Set picture */
1265 $this->photoData= $data;
1266 session::set('binary',$this->photoData);
1267 session::set('binarytype',"image/jpeg");
1268 $this->jpegPhoto= "";
1269 }
1270 }
1273 /* Load a certificate from LDAP, this is going to be simplified later on */
1274 function load_cert()
1275 {
1276 $ds= ldap_connect($this->config->current['SERVER']);
1277 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1278 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1279 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1280 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1281 }
1282 if(isset($this->config->current['TLS']) &&
1283 $this->config->current['TLS'] == "true"){
1285 ldap_start_tls($ds);
1286 }
1288 $r= ldap_bind($ds);
1289 $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1291 if ($sr) {
1292 $ei= @ldap_first_entry($ds, $sr);
1294 if ($ei) {
1295 if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1296 $this->userCertificate= "";
1297 } else {
1298 $this->userCertificate= $info[0];
1299 }
1300 }
1301 } else {
1302 $this->userCertificate= "";
1303 }
1305 ldap_unbind($ds);
1306 }
1309 /* Load picture from file to object */
1310 function set_picture($filename ="")
1311 {
1312 if (!is_file($filename) || $filename =="" ){
1313 $filename= "./images/default.jpg";
1314 $this->jpegPhoto= "*removed*";
1315 }
1317 $fd = fopen ($filename, "rb");
1318 $this->photoData= fread ($fd, filesize ($filename));
1319 session::set('binary',$this->photoData);
1320 session::set('binarytype',"image/jpeg");
1321 $this->jpegPhoto= "";
1323 fclose ($fd);
1324 }
1327 /* Load certificate from file to object */
1328 function set_cert($cert, $filename)
1329 {
1330 if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1331 $fd = fopen ($filename, "rb");
1332 if (filesize($filename)>0) {
1333 $this->$cert= fread ($fd, filesize ($filename));
1334 fclose ($fd);
1335 $this->is_modified= TRUE;
1336 } else {
1337 msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1338 }
1339 }
1341 /* Adapt from given 'dn' */
1342 function adapt_from_template($dn, $skip= array())
1343 {
1344 plugin::adapt_from_template($dn, $skip);
1346 /* Get base */
1347 $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1349 if($this->governmentmode){
1351 /* Walk through govattrs */
1352 foreach ($this->govattrs as $val){
1354 if (in_array($val, $skip)){
1355 continue;
1356 }
1358 if (isset($this->attrs["$val"][0])){
1360 /* If attribute is set, replace dynamic parts:
1361 %sn, %givenName and %uid. Fill these in our local variables. */
1362 $value= $this->attrs["$val"][0];
1364 foreach (array("sn", "givenName", "uid") as $repl){
1365 if (preg_match("/%$repl/i", $value)){
1366 $value= preg_replace ("/%$repl/i",
1367 $this->parent->$repl, $value);
1368 }
1369 }
1370 $this->$val= $value;
1371 }
1372 }
1373 }
1375 /* Get back uid/sn/givenName - only write if nothing's skipped */
1376 if ($this->parent !== NULL && count($skip) == 0){
1377 $this->uid= $this->parent->uid;
1378 $this->sn= $this->parent->sn;
1379 $this->givenName= $this->parent->givenName;
1380 }
1381 }
1384 /* This avoids that users move themselves out of their rights.
1385 */
1386 function allowedBasesToMoveTo()
1387 {
1388 /* Get bases */
1389 $bases = $this->get_allowed_bases();
1390 return($bases);
1391 }
1394 function getCopyDialog()
1395 {
1396 $str = "";
1398 session::set('binary',$this->photoData);
1399 session::set('binarytype',"image/jpeg");
1401 /* Get random number for pictures */
1402 srand((double)microtime()*1000000);
1403 $rand = rand(0, 10000);
1405 $smarty = get_smarty();
1407 $smarty->assign("passwordTodo","clear");
1409 if(isset($_POST['passwordTodo'])){
1410 $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1411 }
1413 $smarty->assign("sn", $this->sn);
1414 $smarty->assign("givenName",$this->givenName);
1415 $smarty->assign("uid", $this->uid);
1416 $smarty->assign("rand", $rand);
1417 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1420 $ret = array();
1421 $ret['string'] = $str;
1422 $ret['status'] = "";
1423 return($ret);
1424 }
1426 function saveCopyDialog()
1427 {
1428 /* Set_acl_base */
1429 $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1431 if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1432 $this->set_picture($_FILES['picture_file']['tmp_name']);
1433 }
1435 /* Remove picture? */
1436 if (isset($_POST['picture_remove'])){
1437 $this->jpegPhoto= "*removed*";
1438 $this->set_picture ("./images/default.jpg");
1439 $this->is_modified= TRUE;
1440 }
1442 $attrs = array("uid","givenName","sn");
1443 foreach($attrs as $attr){
1444 if(isset($_POST[$attr])){
1445 $this->$attr = $_POST[$attr];
1446 }
1447 }
1448 }
1451 function PrepareForCopyPaste($source)
1452 {
1453 plugin::PrepareForCopyPaste($source);
1455 /* Reset certificate information addepted from source user
1456 to avoid setting the same user certificate for the destination user. */
1457 $this->userPKCS12= "";
1458 $this->userSMIMECertificate= "";
1459 $this->userCertificate= "";
1460 $this->certificateSerialNumber= "";
1461 $this->old_certificateSerialNumber= "";
1462 $this->old_userPKCS12= "";
1463 $this->old_userSMIMECertificate= "";
1464 $this->old_userCertificate= "";
1465 }
1468 static function plInfo()
1469 {
1471 $govattrs= array(
1472 "gouvernmentOrganizationalUnit" => _("Unit"),
1473 "houseIdentifier" => _("House identifier"),
1474 "vocation" => _("Vocation"),
1475 "ivbbLastDeliveryCollective" => _("Last delivery"),
1476 "gouvernmentOrganizationalPersonLocality" => _("Person locality"),
1477 "gouvernmentOrganizationalUnitDescription" => _("Unit description"),
1478 "gouvernmentOrganizationalUnitSubjectArea" => _("Subject area"),
1479 "functionalTitle" => _("Functional title"),
1480 "certificateSerialNumber" => _("Certificate serial number"),
1481 "publicVisible" => _("Public visible"),
1482 "street" => _("Street"),
1483 "role" => _("Role"),
1484 "postalCode" => _("Postal code"));
1486 $ret = array(
1487 "plShortName" => _("Generic"),
1488 "plDescription" => _("Generic user settings"),
1489 "plSelfModify" => TRUE,
1490 "plDepends" => array(),
1491 "plPriority" => 1,
1492 "plSection" => array("personal" => _("My account")),
1493 "plCategory" => array("users" => array("description" => _("Users"),
1494 "objectClass" => "gosaAccount")),
1496 "plProvidedAcls" => array(
1497 "base" => _("Base"),
1498 "userPassword" => _("User password"),
1499 "sn" => _("Surname"),
1500 "givenName" => _("Given name"),
1501 "uid" => _("User identification"),
1502 "personalTitle" => _("Personal title"),
1503 "academicTitle" => _("Academic title"),
1504 "homePostalAddress" => _("Home postal address"),
1505 "homePhone" => _("Home phone number"),
1506 "labeledURI" => _("Homepage"),
1507 "o" => _("Organization"),
1508 "ou" => _("Department"),
1509 "dateOfBirth" => _("Date of birth"),
1510 "gender" => _("Gender"),
1511 "preferredLanguage" => _("Preferred language"),
1512 "departmentNumber" => _("Department number"),
1513 "employeeNumber" => _("Employee number"),
1514 "employeeType" => _("Employee type"),
1515 "l" => _("Location"),
1516 "st" => _("State"),
1517 "userPicture" => _("User picture"),
1518 "roomNumber" => _("Room number"),
1519 "telephoneNumber" => _("Telefon number"),
1520 "mobile" => _("Mobile number"),
1521 "pager" => _("Pager number"),
1522 "Certificate" => _("User certificates"),
1524 "postalAddress" => _("Postal address"),
1525 "facsimileTelephoneNumber" => _("Fax number"))
1526 );
1528 /* Append government attributes if required */
1529 global $config;
1530 if (isset($config->current['GOVERNMENTMODE']) && preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1531 foreach($govattrs as $attr => $desc){
1532 $ret["plProvidedAcls"][$attr] = $desc;
1533 }
1534 }
1535 return($ret);
1536 }
1538 function get_multi_edit_values()
1539 {
1540 $ret = plugin::get_multi_edit_values();
1541 if(in_array("pw_storage",$this->multi_boxes)){
1542 $ret['pw_storage'] = $this->pw_storage;
1543 }
1544 if(in_array("edit_picture",$this->multi_boxes)){
1545 $ret['jpegPhoto'] = $this->jpegPhoto;
1546 $ret['photoData'] = $this->photoData;
1547 $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1548 $ret['old_photoData'] = $this->old_photoData;
1549 }
1550 if(isset($ret['dateOfBirth'])){
1551 unset($ret['dateOfBirth']);
1552 }
1553 if(isset($ret['cn'])){
1554 unset($ret['cn']);
1555 }
1556 $ret['is_modified'] = $this->is_modified;
1557 if(in_array("base",$this->multi_boxes)){
1558 $ret['orig_base']="Changed_by_Multi_Plug";
1559 $ret['base']=$this->base;
1560 }
1561 return($ret);
1562 }
1565 function multiple_save_object()
1566 {
1567 plugin::multiple_save_object();
1569 /* Get pw_storage mode */
1570 if (isset($_POST['pw_storage'])){
1571 foreach(array("pw_storage") as $val){
1572 if(isset($_POST[$val])){
1573 $data= validate(get_post($val));
1574 if ($data != $this->$val){
1575 $this->is_modified= TRUE;
1576 }
1577 $this->$val= $data;
1578 }
1579 }
1580 }
1581 if(isset($_POST['base'])){
1582 $this->base = get_post('base');
1583 }
1585 if(isset($_POST['user_mulitple_edit'])){
1586 foreach(array("base","pw_storage","edit_picture") as $val){
1587 if(isset($_POST["use_".$val])){
1588 $this->multi_boxes[] = $val;
1589 }
1590 }
1591 }
1592 }
1595 function multiple_check()
1596 {
1597 /* Call check() to set new_dn correctly ... */
1598 $message = plugin::multiple_check();
1600 /* Set the new acl base */
1601 if($this->dn == "new") {
1602 $this->set_acl_base($this->base);
1603 }
1604 if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1605 $message[]= msgPool::invalid(_("Homepage"));
1606 }
1607 if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1608 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1609 }
1610 if (!tests::is_phone_nr($this->facsimileTelephoneNumber) && in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1611 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1612 }
1613 if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1614 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1615 }
1616 if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1617 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1618 }
1619 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1620 $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1621 }
1622 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1623 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1624 }
1625 return($message);
1626 }
1630 function multiple_execute()
1631 {
1632 return($this->execute());
1633 }
1636 }
1638 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1639 ?>