Code

Fixed user certiciate ACLs.
[gosa.git] / gosa-core / plugins / personal / generic / class_user.inc
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);
227     
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     }
238  
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;
265   
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;
288     
289     for($y= $start; $y<=$end; $y++){
290       $years[]= $y;
291     }
292     $years['-']= "-&nbsp;";
293     $months= msgPool::months();
294     $months['-'] = '-&nbsp;';
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 => "&nbsp;", "F" => _("female"), "M" => _("male"));
305     $smarty->assign("gender_list", $sex);
306     $language= array_merge(array(0 => "&nbsp;") ,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\">&nbsp;<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();
345    
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);
539       
540           /* Read out data*/
541           $timeto   = $certificate->getvalidto_date();
542           $timefrom = $certificate->getvalidfrom_date();
543          
544           
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("/ /", "&nbsp;", $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       }
571   
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     }
605  
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);
636     if(!session::is_set('edit')){
637       $smarty->assign("CertificatesACL","");
638     }else{
639       $smarty->assign("CertificatesACL",  $this->getacl("Certificate"));
640     }
641     
642     $smarty->assign("userPictureACL",   $this->getacl("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
643     $smarty->assign("userPicture_is_readable",   $this->acl_is_readable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
645     /* Create base acls */
646     $tmp = @$this->allowedBasesToMoveTo();
647     $smarty->assign("bases", $tmp);
649     /* Save government mode attributes */
650     if($this->governmentmode){
651       $smarty->assign("governmentmode", "true");
652       $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
653           "internet,ivbv", "internet,testa", "internet,ivbv,testa");
654       $smarty->assign("ivbbmodes", $ivbbmodes);
655       foreach ($this->govattrs as $val){
656         $smarty->assign("$val", $this->$val);
657         $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
658       }
659     } else {
660       $smarty->assign("governmentmode", "false");
661     }
663     /* Special mode for uid */
664     $uidACL= $this->getacl("uid",(!is_object($this->parent) && !session::is_set('edit')));
665     if (isset ($this->dn)){
666       if ($this->dn != "new"){
667         $uidACL= preg_replace("/w/","",$uidACL);
668       }
669     }  else {
670       $uidACL= preg_replace("/w/","",$uidACL);
671     }
672     
673     $smarty->assign("uidACL", $uidACL);
674     $smarty->assign("is_template", $this->is_template);
675     $smarty->assign("use_dob", $this->use_dob);
677     if (isset($this->parent)){
678       if (isset($this->parent->by_object['phoneAccount']) &&
679           $this->parent->by_object['phoneAccount']->is_account){
680         $smarty->assign("has_phoneaccount", "true");
681       } else {
682         $smarty->assign("has_phoneaccount", "false");
683       }
684     } else {
685       $smarty->assign("has_phoneaccount", "false");
686     }
687     $smarty->assign("multiple_support" , $this->multiple_support_active);
688     return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
689   }
692   /* remove object from parent */
693   function remove_from_parent()
694   {
695     /* Remove password extension */
696     $temp= passwordMethod::get_available_methods();
698     /* Remove password method from user account */
699     if(isset($temp[$this->pw_storage]) && class_available($temp[$this->pw_storage])){
700       $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
701       $this->pwObject->remove_from_parent();
702     }
704     /* Remove user */
705     $ldap= $this->config->get_ldap_link();
706     $ldap->rmdir ($this->dn);
707     if (!$ldap->success()){
708       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
709     }
710   
711     new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
712   
713     /* Delete references to groups */
714     $ldap->cd ($this->config->current['BASE']);
715     $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
716     while ($ldap->fetch()){
717       $g= new group($this->config, $ldap->getDN());
718       $g->removeUser($this->uid);
719       $g->save ();
720     }
722     /* Delete references to object groups */
723     $ldap->cd ($this->config->current['BASE']);
724     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
725     while ($ldap->fetch()){
726       $og= new ogroup($this->config, $ldap->getDN());
727       unset($og->member[$this->dn]);
728       $og->save ();
729     }
731     /* If needed, let the password method do some cleanup */
732     $tmp = new passwordMethod($this->config);
733     $available = $tmp->get_available_methods();
734     if (in_array_ics($this->pw_storage, $available['name'])){
735       $test= new $available[$this->pw_storage]($this->config);
736       $test->attrs= $this->attrs;
737       $test->dn= $this->dn;
738       $test->remove_from_parent();
739     }
741     /* Remove ACL dependencies too */
742     $tmp = new acl($this->config,$this->parent,$this->dn);
743     $tmp->remove_acl();
745     /* Optionally execute a command after we're done */
746     $this->handle_post_events("remove",array("uid" => $this->uid));
747   }
750   /* Save data to object */
751   function save_object()
752   {
753     if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
755       /* Make a backup of the current selected base */
756       $base_tmp = $this->base;
758       /* Parents save function */
759       plugin::save_object ();
761       /* Save government mode attributes */
762       if ($this->governmentmode){
763         foreach ($this->govattrs as $val){
764           if ($this->acl_is_writeable($val,(!is_object($this->parent) && !session::is_set('edit'))) && isset($_POST["$val"])){
765             $data= stripcslashes($_POST["$val"]);
766             if ($data != $this->$val){
767               $this->is_modified= TRUE;
768             }
769             $this->$val= $data;
770           }
771         }
772       }
774       /* In template mode, the uid is autogenerated... */
775       if ($this->is_template){
776         $this->uid= strtolower($this->sn);
777         $this->givenName= $this->sn;
778       }
780       /* Save base and pw_storage, since these are no LDAP attributes */
781       if (isset($_POST['base'])){
783         $tmp = $this->get_allowed_bases();
784         if(isset($tmp[$_POST['base']])){
785           $base= validate($_POST['base']);
786           if ($base != $this->base){
787             $this->is_modified= TRUE;
788           }
789           $this->base= $base;
790         }else{
791           $this->base = $base_tmp;
792           msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
793         }
794       }
796       /* Get pw_storage mode */
797       if (isset($_POST['pw_storage'])){
798         foreach(array("pw_storage") as $val){
799           if(isset($_POST[$val])){
800             $data= validate($_POST[$val]);
801             if ($data != $this->$val){
802               $this->is_modified= TRUE;
803             }
804             $this->$val= $data;
805           }
806         }
807       }
809       /* Save current cn
810        */
811       $this->cn = $this->givenName." ".$this->sn;
812     }
813   }
815   function rebind($ldap, $referral)
816   {
817     $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
818     if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
819       $this->error = "Success";
820       $this->hascon=true;
821       $this->reconnect= true;
822       return (0);
823     } else {
824       $this->error = "Could not bind to " . $credentials['ADMIN'];
825       return NULL;
826     }
827   }
829   
830   /* Save data to LDAP, depending on is_account we save or delete */
831   function save()
832   {
833     /* Only force save of changes .... 
834        If this attributes aren't changed, avoid saving.
835      */
836     if($this->gender=="0") $this->gender ="";
837     if($this->preferredLanguage=="0") $this->preferredLanguage ="";
839     /* First use parents methods to do some basic fillup in $this->attrs */
840     plugin::save ();
842     if ($this->use_dob == "1"){
843       /* 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. */
844       if(!is_array($this->attrs['dateOfBirth'])) {
845         $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
846       }
847     }
849     /* Remove additional objectClasses */
850     $tmp= array();
851     foreach ($this->attrs['objectClass'] as $key => $set){
852       $found= false;
853       foreach (array("ivbbentry", "gosaUserTemplate") as $val){
854         if (preg_match ("/^$set$/i", $val)){
855           $found= true;
856           break;
857         }
858       }
859       if (!$found){
860         $tmp[]= $set;
861       }
862     }
864     /* Replace the objectClass array. This is done because of the
865        separation into government and normal mode. */
866     $this->attrs['objectClass']= $tmp;
868     /* Add objectClasss for template mode? */
869     if ($this->is_template){
870       $this->attrs['objectClass'][]= "gosaUserTemplate";
871     }
873     /* Hard coded government mode? */
874     if ($this->governmentmode){
875       $this->attrs['objectClass'][]= "ivbbentry";
877       /* Copy standard attributes */
878       foreach ($this->govattrs as $val){
879         if ($this->$val != ""){
880           $this->attrs["$val"]= $this->$val;
881         } elseif (!$this->is_new) {
882           $this->attrs["$val"]= array();
883         }
884       }
886       /* Remove attribute if set to "nein" */
887       if ($this->publicVisible == "nein"){
888         $this->attrs['publicVisible']= array();
889         if($this->is_new){
890           unset($this->attrs['publicVisible']);
891         }else{
892           $this->attrs['publicVisible']=array();
893         }
895       }
897     }
899     /* Special handling for attribute userCertificate needed */
900     if ($this->userCertificate != ""){
901       $this->attrs["userCertificate;binary"]= $this->userCertificate;
902       $remove_userCertificate= false;
903     } else {
904       $remove_userCertificate= true;
905     }
907     /* Special handling for dateOfBirth value */
908     if ($this->use_dob != "1"){
909       if ($this->is_new) {
910         unset($this->attrs["dateOfBirth"]);
911       } else {
912         $this->attrs["dateOfBirth"]= array();
913       }
914     }
915     if (!$this->gender){
916       if ($this->is_new) {
917         unset($this->attrs["gender"]);
918       } else {
919         $this->attrs["gender"]= array();
920       }
921     }
922     if (!$this->preferredLanguage){
923       if ($this->is_new) {
924         unset($this->attrs["preferredLanguage"]);
925       } else {
926         $this->attrs["preferredLanguage"]= array();
927       }
928     }
930     /* Special handling for attribute jpegPhote needed, scale image via
931        image magick to 147x200 pixels and inject resulting data. */
932     if ($this->jpegPhoto == "*removed*"){
933     
934       /* Reset attribute to avoid writing *removed* as value */    
935       $this->attrs["jpegPhoto"] = array();
937     } else {
939       /* Fallback if there's no image magick inside PHP */
940       if (!function_exists("imagick_blob2image")){
941         /* Get temporary file name for conversation */
942         $fname = tempnam (TEMP_DIR, "GOsa");
943   
944         /* Open file and write out photoData */
945         $fp = fopen ($fname, "w");
946         fwrite ($fp, $this->photoData);
947         fclose ($fp);
949         /* Build conversation query. Filename is generated automatically, so
950            we do not need any special security checks. Exec command and save
951            output. For PHP safe mode, you'll need a configuration which respects
952            image magick as executable... */
953         $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
954         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
955             $query, "Execute");
956   
957         /* Read data written by convert */
958         $output= "";
959         $sh= popen($query, 'r');
960         while (!feof($sh)){
961           $output.= fread($sh, 4096);
962         }
963         pclose($sh);
965         unlink($fname);
967         /* Save attribute */
968         $this->attrs["jpegPhoto"] = $output;
970       } else {
972         /* Load the new uploaded Photo */
973         if(!$handle  =  imagick_blob2image($this->photoData))  {
974           new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
975         }
977         /* Resizing image to 147x200 and blur */
978         if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
979           new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
980         }
982         /* Converting image to JPEG */
983         if(!imagick_convert($handle,"JPEG")) {
984           new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
985         }
987         /* Creating binary Code for the Image */
988         if(!$dump = imagick_image2blob($handle)){
989           new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
990         }
992         /* Sending Image */
993         $output=  $dump;
995         /* Save attribute */
996         $this->attrs["jpegPhoto"] = $output;
997       }
999     }
1001     /* This only gets called when user is renaming himself */
1002     $ldap= $this->config->get_ldap_link();
1003     if ($this->dn != $this->new_dn){
1005       /* Write entry on new 'dn' */
1006       $this->update_acls($this->dn,$this->new_dn);
1007       $this->move($this->dn, $this->new_dn);
1009       /* Happen to use the new one */
1010       change_ui_dn($this->dn, $this->new_dn);
1011       $this->dn= $this->new_dn;
1012     }
1015     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1016        new entries. So do a check first... */
1017     $ldap->cat ($this->dn, array('dn'));
1018     if ($ldap->fetch()){
1019       $mode= "modify";
1020     } else {
1021       $mode= "add";
1022       $ldap->cd($this->config->current['BASE']);
1023       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1024     }
1026     /* Set password to some junk stuff in case of templates */
1027     if ($this->is_template){
1028       $this->attrs['userPassword']= '{crypt}N0T$3T4N0W';
1029     }
1031     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1032         $this->attributes, "Save via $mode");
1034     /* Finally write data with selected 'mode' */
1035     $this->cleanup();
1037     if(isset($this->attrs['preferredLanguage'])){
1038       $ui = session::get('ui');
1039       $ui->language = $this->preferredLanguage;
1040       session::set('ui',$ui);
1041       session::set('Last_init_lang',"update");
1042     }
1044     $ldap->cd ($this->dn);
1045     $ldap->$mode ($this->attrs);
1046     if (!$ldap->success()){
1047       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1048       return (1);
1049     }
1051     /* Remove ACL dependencies too */
1052     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1053       $tmp = new acl($this->config,$this->parent,$this->dn);
1054       $tmp->update_acl_membership($this->orig_dn,$this->dn);
1055     }
1057     if($mode == "modify"){
1058       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1059     }else{
1060       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1061     }
1063     /* Remove cert? 
1064        For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1065        to work around myself. */
1066     if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1068       /* Reset array, assemble new, this should be reworked */
1069       $this->attrs= array();
1070       $this->attrs['userCertificate;binary']= array();
1072       /* Prepare connection */
1073       if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1074         die ("Could not connect to LDAP server");
1075       }
1076       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1077       if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1078         ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1079         ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1080       }
1081       if(isset($config->current['TLS']) && $config->current['TLS'] == "true"){
1082         ldap_start_tls($ds);
1083       }
1084       if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1085               $this->config->current['PASSWORD']))) {
1086         die ("Could not bind to LDAP");
1087       }
1089       /* Modify using attrs */
1090       ldap_mod_del($ds,$this->dn,$this->attrs);
1091       ldap_close($ds);
1092     }
1094     /* If needed, let the password method do some cleanup */
1095     if ($this->pw_storage != $this->last_pw_storage){
1096       $tmp = new passwordMethod($this->config);
1097       $available = $tmp->get_available_methods();
1098       if (in_array_ics($this->last_pw_storage, $available['name'])){
1099         $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1100         $test->attrs= $this->attrs;
1101         $test->remove_from_parent();
1102       }
1103     }
1105     /* Maybe the current password method want's to do some changes... */
1106     if (is_object($this->pwObject)){
1107       $this->pwObject->save($this->dn);
1108     }
1110     /* Optionally execute a command after we're done */
1111     if ($mode == "add"){
1112       $this->handle_post_events("add", array("uid" => $this->uid));
1113     } elseif ($this->is_modified){
1114       $this->handle_post_events("modify", array("uid" => $this->uid));
1115     }
1117     return (0);
1118   }
1120   
1121   function update_new_dn()
1122   {
1123     $pt= "";
1124     if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
1125       if(!empty($this->personalTitle)){
1126         $pt = $this->personalTitle." ";
1127       }
1128     }
1129     $this->cn= $pt.$this->givenName." ".$this->sn;
1131     /* Permissions for that base? */
1132     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
1133       $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1134     } else {
1135       /* Don't touch dn, if cn hasn't changed */
1136       if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1137           $this->orig_base == $this->base ){
1138         $this->new_dn= $this->dn;
1139       } else {
1140         $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1141       }
1142     }
1143   }
1144   
1146   /* Check formular input */
1147   function check()
1148   {
1149     /* Call common method to give check the hook */
1150     $message= plugin::check();
1152     /* Configurable password methods should be configured initially. 
1153      */ 
1154     if($this->last_pw_storage != $this->pw_storage){
1155       $temp= passwordMethod::get_available_methods();
1156       foreach($temp['name'] as $id => $name){
1157         if($name == $this->pw_storage){
1158           if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1159             $message[] = _("The selected password method requires initial configuration!");
1160           }
1161           break;
1162         }
1163       }
1164     }
1166     $this->update_new_dn();
1168     /* Set the new acl base */
1169     if($this->dn == "new") {
1170       $this->set_acl_base($this->base);
1171     }
1173     /* Check if we are allowed to create/move this user 
1174      */
1175     
1176     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1177       $message[]= msgPool::permCreate();
1178     }elseif($this->orig_dn != "new" && $this->new_dn != $this->orig_dn && !$this->acl_is_moveable($this->base)){
1179       $message[]= msgPool::permMove();
1180     }
1182     /* UID already used? */
1183     $ldap= $this->config->get_ldap_link();
1184     $ldap->cd($this->config->current['BASE']);
1185     $ldap->search("(uid=$this->uid)", array("uid"));
1186     $ldap->fetch();
1187     if ($ldap->count() != 0 && $this->dn == 'new'){
1188       $message[]= msgPool::duplicated(_("Login"));
1189     }
1191     /* In template mode, the uid and givenName are autogenerated... */
1192     if ($this->sn == ""){
1193       $message[]= msgPool::required(_("Name"));
1194     }
1196     if (!$this->is_template){
1197       if ($this->givenName == ""){
1198         $message[]= msgPool::required(_("Given name"));
1199       }
1200       if ($this->uid == ""){
1201         $message[]= msgPool::required(_("Login"));
1202       }
1203       if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
1204         $ldap->cat($this->new_dn);
1205         if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1206           $message[]= msgPool::duplicated(_("Name"));
1207         }
1208       }
1209     }
1211     /* Check for valid input */
1212     if ($this->is_modified && !tests::is_uid($this->uid)){
1214       if (strict_uid_mode()){
1215         $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1216       } else {
1217         $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1218       }
1219     }
1220     if (!tests::is_url($this->labeledURI)){
1221       $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1222     }
1224     /* Check phone numbers */
1225     if (!tests::is_phone_nr($this->telephoneNumber)){
1226       $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1227     }
1228     if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1229       $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1230     }
1231     if (!tests::is_phone_nr($this->mobile)){
1232       $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1233     }
1234     if (!tests::is_phone_nr($this->pager)){
1235       $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1236     }
1238     /* Check for reserved characers */
1239     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1240       $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1241     }
1242     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1243       $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1244     }
1246     return $message;
1247   }
1250   /* Indicate whether a password change is needed or not */
1251   function password_change_needed()
1252   {
1253     if(in_array("pw_storage",$this->multi_boxes)){
1254       return(TRUE);
1255     }
1256     return($this->pw_storage != $this->last_pw_storage);
1257   }
1260   /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1261   function load_picture()
1262   {
1263     $ldap = $this->config->get_ldap_link();
1264     $ldap->cd ($this->dn);
1265     $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1267     if((!$data) || ($data == "*removed*")){ 
1269       /* In case we don't get an entry, load a default picture */
1270       $this->set_picture ();//"./images/default.jpg");
1271       $this->jpegPhoto= "*removed*";
1272     }else{
1274       /* Set picture */
1275       $this->photoData= $data;
1276       session::set('binary',$this->photoData);
1277       session::set('binarytype',"image/jpeg");
1278       $this->jpegPhoto= "";
1279     }
1280   }
1283   /* Load a certificate from LDAP, this is going to be simplified later on */
1284   function load_cert()
1285   {
1286     $ds= ldap_connect($this->config->current['SERVER']);
1287     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1288     if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
1289       ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1290       ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1291     }
1292     if(isset($this->config->current['TLS']) &&
1293         $this->config->current['TLS'] == "true"){
1295       ldap_start_tls($ds);
1296     }
1298     $r= ldap_bind($ds);
1299     $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1301     if ($sr) {
1302       $ei= @ldap_first_entry($ds, $sr);
1303       
1304       if ($ei) {
1305         if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1306           $this->userCertificate= "";
1307         } else {
1308           $this->userCertificate= $info[0];
1309         }
1310       }
1311     } else {
1312       $this->userCertificate= "";
1313     }
1315     ldap_unbind($ds);
1316   }
1319   /* Load picture from file to object */
1320   function set_picture($filename ="")
1321   {
1322     if (!is_file($filename) || $filename =="" ){
1323       $filename= "./images/default.jpg";
1324       $this->jpegPhoto= "*removed*";
1325     }
1327     $fd = fopen ($filename, "rb");
1328     $this->photoData= fread ($fd, filesize ($filename));
1329     session::set('binary',$this->photoData);
1330     session::set('binarytype',"image/jpeg");
1331     $this->jpegPhoto= "";
1333     fclose ($fd);
1334   }
1337   /* Load certificate from file to object */
1338   function set_cert($cert, $filename)
1339   {
1340     if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1341     $fd = fopen ($filename, "rb");
1342     if (filesize($filename)>0) {
1343       $this->$cert= fread ($fd, filesize ($filename));
1344       fclose ($fd);
1345       $this->is_modified= TRUE;
1346     } else {
1347       msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1348     }
1349   }
1351   /* Adapt from given 'dn' */
1352   function adapt_from_template($dn, $skip= array())
1353   {
1354     plugin::adapt_from_template($dn, $skip);
1356     /* Get base */
1357     $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1359     if($this->governmentmode){
1361       /* Walk through govattrs */
1362       foreach ($this->govattrs as $val){
1364         if (in_array($val, $skip)){
1365           continue;
1366         }
1368         if (isset($this->attrs["$val"][0])){
1370           /* If attribute is set, replace dynamic parts: 
1371              %sn, %givenName and %uid. Fill these in our local variables. */
1372           $value= $this->attrs["$val"][0];
1374           foreach (array("sn", "givenName", "uid") as $repl){
1375             if (preg_match("/%$repl/i", $value)){
1376               $value= preg_replace ("/%$repl/i",
1377                   $this->parent->$repl, $value);
1378             }
1379           }
1380           $this->$val= $value;
1381         }
1382       }
1383     }
1385     /* Get back uid/sn/givenName - only write if nothing's skipped */
1386     if ($this->parent !== NULL && count($skip) == 0){
1387       $this->uid= $this->parent->uid;
1388       $this->sn= $this->parent->sn;
1389       $this->givenName= $this->parent->givenName;
1390     }
1391   }
1393  
1394   /* This avoids that users move themselves out of their rights. 
1395    */
1396   function allowedBasesToMoveTo()
1397   {
1398     /* Get bases */
1399     $bases  = $this->get_allowed_bases();
1400     return($bases);
1401   } 
1404   function getCopyDialog()
1405   {
1406     $str = "";
1408     session::set('binary',$this->photoData); 
1409     session::set('binarytype',"image/jpeg");
1411     /* Get random number for pictures */
1412     srand((double)microtime()*1000000); 
1413     $rand = rand(0, 10000);
1415     $smarty = get_smarty();
1417     $smarty->assign("passwordTodo","clear");
1419     if(isset($_POST['passwordTodo'])){
1420       $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1421     }
1423     $smarty->assign("sn",       $this->sn);
1424     $smarty->assign("givenName",$this->givenName);
1425     $smarty->assign("uid",      $this->uid);
1426     $smarty->assign("rand",     $rand);
1427     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1430     $ret = array();
1431     $ret['string'] = $str;
1432     $ret['status'] = "";  
1433     return($ret);
1434   }
1436   function saveCopyDialog()
1437   {
1438     /* Set_acl_base */
1439     $this->set_acl_base("cn=dummy,".get_people_ou().$this->base);
1441     if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1442       $this->set_picture($_FILES['picture_file']['tmp_name']);
1443     }
1445     /* Remove picture? */
1446     if (isset($_POST['picture_remove'])){
1447       $this->jpegPhoto= "*removed*";
1448       $this->set_picture ("./images/default.jpg");
1449       $this->is_modified= TRUE;
1450     }
1452     $attrs = array("uid","givenName","sn");
1453     foreach($attrs as $attr){
1454       if(isset($_POST[$attr])){
1455         $this->$attr = $_POST[$attr];
1456       }
1457     } 
1458   }
1461   function PrepareForCopyPaste($source)
1462   {
1463     plugin::PrepareForCopyPaste($source);
1465     /* Reset certificate information addepted from source user
1466        to avoid setting the same user certificate for the destination user. */
1467     $this->userPKCS12= "";
1468     $this->userSMIMECertificate= "";
1469     $this->userCertificate= "";
1470     $this->certificateSerialNumber= "";
1471     $this->old_certificateSerialNumber= "";
1472     $this->old_userPKCS12= "";
1473     $this->old_userSMIMECertificate= "";
1474     $this->old_userCertificate= "";
1475   }
1478   static function plInfo()
1479   {
1480   
1481     $govattrs= array(
1482         "gouvernmentOrganizationalUnit"             =>  _("Unit"), 
1483         "houseIdentifier"                           =>  _("House identifier"), 
1484         "vocation"                                  =>  _("Vocation"),
1485         "ivbbLastDeliveryCollective"                =>  _("Last delivery"), 
1486         "gouvernmentOrganizationalPersonLocality"   =>  _("Person locality"),
1487         "gouvernmentOrganizationalUnitDescription"  =>  _("Unit description"),
1488         "gouvernmentOrganizationalUnitSubjectArea"  =>  _("Subject area"),
1489         "functionalTitle"                           =>  _("Functional title"),
1490         "certificateSerialNumber"                   =>  _("Certificate serial number"),
1491         "publicVisible"                             =>  _("Public visible"),
1492         "street"                                    =>  _("Street"),
1493         "role"                                      =>  _("Role"),
1494         "postalCode"                                =>  _("Postal code"));
1496     $ret = array(
1497         "plShortName" => _("Generic"),
1498         "plDescription" => _("Generic user settings"),
1499         "plSelfModify"  => TRUE,
1500         "plDepends"     => array(),
1501         "plPriority"    => 1,
1502         "plSection"     => array("personal" => _("My account")),
1503         "plCategory"    => array("users" => array("description" => _("Users"),
1504                                                   "objectClass" => "gosaAccount")),
1506         "plProvidedAcls" => array(
1507           "base"              => _("Base"), 
1508           "userPassword"      => _("User password"), 
1509           "sn"                => _("Surname"),
1510           "givenName"         => _("Given name"),
1511           "uid"               => _("User identification"),
1512           "personalTitle"     => _("Personal title"),
1513           "academicTitle"     => _("Academic title"),
1514           "homePostalAddress" => _("Home postal address"),
1515           "homePhone"         => _("Home phone number"),
1516           "labeledURI"        => _("Homepage"),
1517           "o"                 => _("Organization"),
1518           "ou"                => _("Department"),
1519           "dateOfBirth"       => _("Date of birth"),
1520           "gender"            => _("Gender"),
1521           "preferredLanguage" => _("Preferred language"),
1522           "departmentNumber"  => _("Department number"),
1523           "employeeNumber"    => _("Employee number"),
1524           "employeeType"      => _("Employee type"),
1525           "l"                 => _("Location"),
1526           "st"                => _("State"),
1527           "userPicture"       => _("User picture"),
1528           "roomNumber"        => _("Room number"),
1529           "telephoneNumber"   => _("Telefon number"),
1530           "mobile"            => _("Mobile number"),
1531           "pager"             => _("Pager number"),
1532           "Certificate"        => _("User certificates"),
1534           "postalAddress"                => _("Postal address"),
1535           "facsimileTelephoneNumber"     => _("Fax number"))
1536         );
1538     /* Append government attributes if required */
1539       global $config;
1540     if (isset($config->current['GOVERNMENTMODE']) &&  preg_match('/true/i', $config->current['GOVERNMENTMODE'])){
1541       foreach($govattrs as $attr => $desc){
1542         $ret["plProvidedAcls"][$attr] = $desc;
1543       }
1544     }
1545     return($ret);
1546   }
1548   function get_multi_edit_values()
1549   {
1550     $ret = plugin::get_multi_edit_values();
1551     if(in_array("pw_storage",$this->multi_boxes)){
1552       $ret['pw_storage'] = $this->pw_storage;
1553     }
1554     if(in_array("edit_picture",$this->multi_boxes)){
1555       $ret['jpegPhoto'] = $this->jpegPhoto;
1556       $ret['photoData'] = $this->photoData;
1557       $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1558       $ret['old_photoData'] = $this->old_photoData;
1559     }
1560     if(isset($ret['dateOfBirth'])){
1561       unset($ret['dateOfBirth']);
1562     }
1563     if(isset($ret['cn'])){
1564       unset($ret['cn']);
1565     }
1566     $ret['is_modified'] = $this->is_modified;
1567     if(in_array("base",$this->multi_boxes)){
1568       $ret['orig_base']="Changed_by_Multi_Plug";
1569       $ret['base']=$this->base;
1570     }
1571     return($ret); 
1572   }
1575   function multiple_save_object()
1576   {
1577     plugin::multiple_save_object();
1579     /* Get pw_storage mode */
1580     if (isset($_POST['pw_storage'])){
1581       foreach(array("pw_storage") as $val){
1582         if(isset($_POST[$val])){
1583           $data= validate(get_post($val));
1584           if ($data != $this->$val){
1585             $this->is_modified= TRUE;
1586           }
1587           $this->$val= $data;
1588         }
1589       }
1590     }
1591     if(isset($_POST['base'])){
1592       $this->base = get_post('base');
1593     }
1595     if(isset($_POST['user_mulitple_edit'])){
1596       foreach(array("base","pw_storage","edit_picture") as $val){
1597         if(isset($_POST["use_".$val])){
1598           $this->multi_boxes[] = $val;
1599         }
1600       }
1601     }
1602   }
1604   
1605   function multiple_check()
1606   {
1607     /* Call check() to set new_dn correctly ... */
1608     $message = plugin::multiple_check();
1610     /* Set the new acl base */
1611     if($this->dn == "new") {
1612       $this->set_acl_base($this->base);
1613     }
1614     if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1615       $message[]= msgPool::invalid(_("Homepage"));
1616     }
1617     if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1618       $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1619     }
1620     if (!tests::is_phone_nr($this->facsimileTelephoneNumber) &&  in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1621       $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1622     }
1623     if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1624       $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1625     }
1626     if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1627       $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1628     }
1629     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1630       $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1631     }
1632     if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1633       $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1634     }
1635     return($message);
1636   }
1640   function multiple_execute()
1641   {
1642     return($this->execute());
1643   }
1648 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1649 ?>