92bd6f7f91cf07d39af98cfae80f34ca2a8643c3
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 $gosaLoginRestriction= array();
54 var $employeeNumber= "";
55 var $employeeType= "";
56 var $roomNumber= "";
57 var $telephoneNumber= "";
58 var $facsimileTelephoneNumber= "";
59 var $mobile= "";
60 var $pager= "";
61 var $l= "";
62 var $st= "";
63 var $postalAddress= "";
64 var $dateOfBirth;
65 var $use_dob= "0";
66 var $gender="0";
67 var $preferredLanguage="0";
69 var $jpegPhoto= "*removed*";
70 var $photoData= "";
71 var $old_jpegPhoto= "";
72 var $old_photoData= "";
73 var $cert_dialog= FALSE;
74 var $picture_dialog= FALSE;
75 var $pwObject= NULL;
77 var $userPKCS12= "";
78 var $userSMIMECertificate= "";
79 var $userCertificate= "";
80 var $certificateSerialNumber= "";
81 var $old_certificateSerialNumber= "";
82 var $old_userPKCS12= "";
83 var $old_userSMIMECertificate= "";
84 var $old_userCertificate= "";
86 var $gouvernmentOrganizationalUnit= "";
87 var $houseIdentifier= "";
88 var $street= "";
89 var $postalCode= "";
90 var $vocation= "";
91 var $ivbbLastDeliveryCollective= "";
92 var $gouvernmentOrganizationalPersonLocality= "";
93 var $gouvernmentOrganizationalUnitDescription= "";
94 var $gouvernmentOrganizationalUnitSubjectArea= "";
95 var $functionalTitle= "";
96 var $role= "";
97 var $publicVisible= "";
99 var $orig_dn;
100 var $dialog;
102 /* variables to trigger password changes */
103 var $pw_storage= "md5";
104 var $last_pw_storage= "unset";
105 var $had_userCertificate= FALSE;
107 var $view_logged = FALSE;
109 /* attribute list for save action */
110 var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
111 "homePostalAddress", "homePhone", "labeledURI", "ou", "o", "dateOfBirth", "gender","preferredLanguage",
112 "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
113 "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
114 "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate", "gosaLoginRestriction");
116 var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson",
117 "gosaAccount");
119 /* attributes that are part of the government mode */
120 var $govattrs= array("gouvernmentOrganizationalUnit", "houseIdentifier", "vocation",
121 "ivbbLastDeliveryCollective", "gouvernmentOrganizationalPersonLocality",
122 "gouvernmentOrganizationalUnitDescription","gouvernmentOrganizationalUnitSubjectArea",
123 "functionalTitle", "certificateSerialNumber", "publicVisible", "street", "role",
124 "postalCode");
126 var $multiple_support = TRUE;
128 var $governmentmode = FALSE;
130 /* constructor, if 'dn' is set, the node loads the given
131 'dn' from LDAP */
132 function user (&$config, $dn= NULL)
133 {
134 global $lang;
136 $this->config= $config;
137 /* Configuration is fine, allways */
138 if($this->config->get_cfg_value("honourIvbbAttributes") == "true"){
139 $this->governmentmode = TRUE;
140 $this->attributes=array_merge($this->attributes,$this->govattrs);
141 }
143 /* Load base attributes */
144 plugin::plugin ($config, $dn);
146 $this->orig_dn = $this->dn;
147 $this->new_dn = $dn;
149 if ($this->governmentmode){
150 /* Fix public visible attribute if unset */
151 if (!isset($this->attrs['publicVisible'])){
152 $this->publicVisible == "nein";
153 }
154 }
156 /* Load government mode attributes */
157 if ($this->governmentmode){
158 /* Copy all attributs */
159 foreach ($this->govattrs as $val){
160 if (isset($this->attrs["$val"][0])){
161 $this->$val= $this->attrs["$val"][0];
162 }
163 }
164 }
166 /* Create me for new accounts */
167 if ($dn == "new"){
168 $this->is_account= TRUE;
169 }
171 /* Make hash default to md5 if not set in config */
172 $hash= $this->config->get_cfg_value("passwordDefaultHash", "crypt/md5");
174 /* Load data from LDAP? */
175 if ($dn !== NULL){
177 /* Do base conversation */
178 if ($this->dn == "new"){
179 $ui= get_userinfo();
180 $this->base= dn2base($ui->dn);
181 } else {
182 $this->base= dn2base($dn);
183 }
185 /* get password storage type */
186 if (isset ($this->attrs['userPassword'][0])){
187 /* Initialize local array */
188 $matches= array();
189 if (preg_match ("/^{[^}]+}/", $this->attrs['userPassword'][0])){
190 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
191 if(is_object($tmp)){
192 $this->pw_storage= $tmp->get_hash();
193 }
195 } else {
196 if ($this->attrs['userPassword'][0] != ""){
197 $this->pw_storage= "clear";
198 } else {
199 $this->pw_storage= $hash;
200 }
201 }
202 } else {
203 /* Preset with vaule from configuration */
204 $this->pw_storage= $hash;
205 }
207 /* Load extra attributes: certificate and picture */
208 $this->load_cert();
209 $this->load_picture();
210 if ($this->userCertificate != ""){
211 $this->had_userCertificate= TRUE;
212 }
213 }
215 /* Reset password storage indicator, used by password_change_needed() */
216 if ($dn == "new"){
217 $this->last_pw_storage= "unset";
218 } else {
219 $this->last_pw_storage= $this->pw_storage;
220 }
222 /* Generate dateOfBirth entry */
223 if (isset ($this->attrs['dateOfBirth'])){
224 /* This entry is ISO 8601 conform */
225 list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
227 #TODO: use $lang to convert date
228 $this->dateOfBirth= "$day.$month.$year";
229 } else {
230 $this->dateOfBirth= "";
231 }
233 /* Put gender attribute to upper case */
234 if (isset ($this->attrs['gender'])){
235 $this->gender= strtoupper($this->attrs['gender'][0]);
236 }
238 $this->orig_base = $this->base;
239 }
244 /* execute generates the html output for this node */
245 function execute()
246 {
247 /* Call parent execute */
248 plugin::execute();
250 /* Handle add/delete for restriction mode */
251 if (isset($_POST['add_res']) && isset($_POST['res'])) {
252 $val= validate($_POST['res']);
253 if (preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/', $val) ||
254 preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+)$/', $val) ||
255 preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $val)) {
256 $this->gosaLoginRestriction[]= $val;
257 } else {
258 msg_dialog::display(_("Error"), _("Please add a single IP address or a network/netmask combination!"), ERROR_DIALOG);
259 }
260 }
261 if (isset($_POST['del_res']) && isset($_POST['restrictions'])) {
262 $res= $_POST['restrictions'];
263 if (!is_array($res)){
264 $res= array($res);
265 }
266 foreach ($res as $restriction) {
267 if (in_array($restriction, $this->gosaLoginRestriction)) {
268 $this->gosaLoginRestriction= array_remove_entries(array($restriction), $this->gosaLoginRestriction);
269 }
270 }
271 }
273 /* Log view */
274 if($this->is_account && !$this->view_logged){
275 $this->view_logged = TRUE;
276 new log("view","users/".get_class($this),$this->dn);
277 }
279 $smarty= get_smarty();
280 $smarty->assign("usePrototype", "true");
282 /* Assign sex */
283 $sex= array(0 => " ", "F" => _("female"), "M" => _("male"));
284 $smarty->assign("gender_list", $sex);
285 $language= array_merge(array(0 => " ") ,get_languages(TRUE));
286 $smarty->assign("preferredLanguage_list", $language);
288 /* Get random number for pictures */
289 srand((double)microtime()*1000000);
290 $smarty->assign("rand", rand(0, 10000));
293 /* Do we represent a valid gosaAccount? */
294 if (!$this->is_account){
295 $str = "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
296 msgPool::noValidExtension("GOsa")."</b>";
297 return($str);
298 }
300 /* Base select dialog */
301 $once = true;
302 foreach($_POST as $name => $value){
303 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
304 $once = false;
305 $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
306 $this->dialog->setCurrentBase($this->base);
307 }
308 }
310 /* Password configure dialog handling */
311 if(is_object($this->pwObject) && $this->pwObject->display){
312 $output= $this->pwObject->configure();
313 if ($output != ""){
314 $this->dialog= TRUE;
315 return $output;
316 }
317 $this->dialog= false;
318 }
320 /* Dialog handling */
321 if(is_object($this->dialog)){
322 /* Must be called before save_object */
323 $this->dialog->save_object();
325 if($this->dialog->isClosed()){
326 $this->dialog = false;
327 }elseif($this->dialog->isSelected()){
329 /* check if selected base is allowed to move to / create a new object */
330 $tmp = $this->get_allowed_bases();
331 if(isset($tmp[$this->dialog->isSelected()])){
332 $this->base = $this->dialog->isSelected();
333 }
334 $this->dialog= false;
335 }else{
336 return($this->dialog->execute());
337 }
338 }
340 /* Want password method editing? */
341 if ($this->acl_is_writeable("userPassword")){
342 if (isset($_POST['edit_pw_method'])){
343 if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
344 $temp= passwordMethod::get_available_methods();
345 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
346 }
347 $this->pwObject->display = TRUE;
348 $this->dialog= TRUE;
349 return ($this->pwObject->configure());
350 }
351 }
353 /* Want picture edit dialog? */
354 if($this->acl_is_writeable("userPicture")) {
355 if (isset($_POST['edit_picture'])){
356 /* Save values for later recovery, in case some presses
357 the cancel button. */
358 $this->old_jpegPhoto= $this->jpegPhoto;
359 $this->old_photoData= $this->photoData;
360 $this->picture_dialog= TRUE;
361 $this->dialog= TRUE;
362 }
363 }
365 /* Remove picture? */
366 if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))) ){
367 if (isset($_POST['picture_remove'])){
368 $this->set_picture ();
369 $this->jpegPhoto= "*removed*";
370 $this->is_modified= TRUE;
371 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
372 }
373 }
375 /* Save picture */
376 if (isset($_POST['picture_edit_finish'])){
378 /* Check for clean upload */
379 if ($_FILES['picture_file']['name'] != ""){
380 if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
381 msg_dialog::display(_("Error"), _("Cannot upload file!"), ERROR_DIALOG);
382 }else{
383 /* Activate new picture */
384 $this->set_picture($_FILES['picture_file']['tmp_name']);
385 }
386 }
387 $this->picture_dialog= FALSE;
388 $this->dialog= FALSE;
389 $this->is_modified= TRUE;
390 }
393 /* Cancel picture */
394 if (isset($_POST['picture_edit_cancel'])){
396 /* Restore values */
397 $this->jpegPhoto= $this->old_jpegPhoto;
398 $this->photoData= $this->old_photoData;
400 /* Update picture */
401 session::set('binary',$this->photoData);
402 session::set('binarytype',"image/jpeg");
403 $this->picture_dialog= FALSE;
404 $this->dialog= FALSE;
405 }
407 /* Want certificate= */
408 if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
410 /* Save original values for later reconstruction */
411 foreach (array("certificateSerialNumber", "userCertificate",
412 "userSMIMECertificate", "userPKCS12") as $val){
414 $oval= "old_$val";
415 $this->$oval= $this->$val;
416 }
418 $this->cert_dialog= TRUE;
419 $this->dialog= TRUE;
420 }
423 /* Cancel certificate dialog */
424 if (isset($_POST['cert_edit_cancel'])){
426 /* Restore original values in case of 'cancel' */
427 foreach (array("certificateSerialNumber", "userCertificate",
428 "userSMIMECertificate", "userPKCS12") as $val){
430 $oval= "old_$val";
431 $this->$val= $this->$oval;
432 }
433 $this->cert_dialog= FALSE;
434 $this->dialog= FALSE;
435 }
438 /* Remove certificate? */
439 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
440 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
441 if (isset($_POST["remove_$val"])){
443 /* Reset specified cert*/
444 $this->$val= "";
445 $this->is_modified= TRUE;
446 }
447 }
448 }
450 /* Upload new cert and close dialog? */
451 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
453 $fail =false;
455 if (isset($_POST['cert_edit_finish'])){
457 /* for all certificates do */
458 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
459 as $val){
461 /* Check for clean upload */
462 if (array_key_exists($val."_file", $_FILES) &&
463 array_key_exists('name', $_FILES[$val."_file"]) &&
464 $_FILES[$val."_file"]['name'] != "" &&
465 is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
466 $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
467 }
468 }
470 /* Save serial number */
471 if (isset($_POST["certificateSerialNumber"]) &&
472 $_POST["certificateSerialNumber"] != ""){
474 if (!tests::is_id($_POST["certificateSerialNumber"])){
475 $fail = true;
476 msg_dialog::display(_("Error"), msgPool::invalid(_("Serial number"),$_POST["certificateSerialNumber"],"/[0-9]/"),ERROR_DIALOG);
478 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
479 if ($this->$cert != ""){
480 $smarty->assign("$cert"."_state", "true");
481 } else {
482 $smarty->assign("$cert"."_state", "");
483 }
484 }
485 }
487 $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
488 $this->is_modified= TRUE;
489 }
490 if(!$fail){
491 $this->cert_dialog= FALSE;
492 $this->dialog= FALSE;
493 }
494 }
495 }
496 /* Display picture dialog */
497 if ($this->picture_dialog){
498 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
499 }
501 /* Display cert dialog */
502 if ($this->cert_dialog){
503 $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
504 $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
505 $smarty->assign("certificateSerialNumber",$this->certificateSerialNumber);
507 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
508 if ($this->$cert != ""){
509 /* import certificate */
510 $certificate = new certificate;
511 $certificate->import($this->$cert);
513 /* Read out data*/
514 $timeto = $certificate->getvalidto_date();
515 $timefrom = $certificate->getvalidfrom_date();
518 /* Additional info if start end time is '0' */
519 $add_str_info = "";
520 if($timeto == 0 && $timefrom == 0){
521 $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
522 }
524 $str = "<table summary=\"\" border=0>
525 <tr>
526 <td style='vertical-align:top'>CN</td>
527 <td>".preg_replace("/ /", " ", $certificate->getname())."</td>
528 </tr>
529 </table><br>".
531 sprintf(_("Certificate is valid from %s to %s and is currently %s."),
532 "<b>".date('d M Y',$timefrom)."</b>",
533 "<b>".date('d M Y',$timeto)."</b>",
534 $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
535 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
537 $smarty->assign($cert."info",$str);
538 $smarty->assign($cert."_state","true");
539 } else {
540 $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
541 $smarty->assign($cert."_state","");
542 }
543 }
545 if($this->governmentmode){
546 $smarty->assign("honourIvbbAttributes", "true");
547 }else{
548 $smarty->assign("honourIvbbAttributes", "false");
549 }
550 $smarty->assign("governmentmode", $this->governmentmode);
551 return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
552 }
554 /* Prepare password hashes */
555 if ($this->pw_storage == ""){
556 $this->pw_storage= $this->config->get_cfg_value("hash");
557 }
559 $temp= passwordMethod::get_available_methods();
560 $is_configurable= FALSE;
561 $hashes = $temp['name'];
562 if(isset($temp[$this->pw_storage])){
563 $test= new $temp[$this->pw_storage]($this->config);
564 $is_configurable= $test->is_configurable();
565 }else{
566 new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
567 }
570 /* Create password methods array */
571 $pwd_methods = array();
572 foreach($hashes as $id => $name){
573 if(!empty($temp['desc'][$id])){
574 $pwd_methods[$name] = $name." (".$temp['desc'][$id].")";
575 }else{
576 $pwd_methods[$name] = $name;
577 }
578 }
580 /* Load attributes and acl's */
581 $ui =get_userinfo();
582 foreach($this->attributes as $val){
583 $smarty->assign("$val", $this->$val);
584 if(in_array($val,$this->multi_boxes)){
585 $smarty->assign("use_".$val,TRUE);
586 }else{
587 $smarty->assign("use_".$val,FALSE);
588 }
589 }
590 foreach(array("base","pw_storage","edit_picture") as $val){
591 if(in_array($val,$this->multi_boxes)){
592 $smarty->assign("use_".$val,TRUE);
593 }else{
594 $smarty->assign("use_".$val,FALSE);
595 }
596 }
598 /* Set acls */
599 $tmp = $this->plinfo();
600 foreach($tmp['plProvidedAcls'] as $val => $translation){
601 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
602 }
604 $smarty->assign("gosaLoginRestriction", $this->gosaLoginRestriction);
605 $smarty->assign("gosaLoginRestrictionACL", $this->getacl('gosaLoginRestriction', (!is_object($this->parent) && !session::is_set('edit'))));
606 $smarty->assign("pwmode", $pwd_methods);
607 $smarty->assign("pwmode_select", $this->pw_storage);
608 $smarty->assign("pw_configurable", $is_configurable);
609 $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !session::is_set('edit'))));
610 $smarty->assign("base_select", $this->base);
612 if(!session::is_set('edit')){
613 $smarty->assign("CertificatesACL","");
614 }else{
615 $smarty->assign("CertificatesACL", $this->getacl("Certificate"));
616 }
618 $smarty->assign("userPictureACL", $this->getacl("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
619 $smarty->assign("userPicture_is_readable", $this->acl_is_readable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
621 /* Create base acls */
622 $tmp = @$this->allowedBasesToMoveTo();
623 $smarty->assign("bases", $tmp);
625 /* Save government mode attributes */
626 if($this->governmentmode){
627 $smarty->assign("governmentmode", "true");
628 $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
629 "internet,ivbv", "internet,testa", "internet,ivbv,testa");
630 $smarty->assign("ivbbmodes", $ivbbmodes);
631 foreach ($this->govattrs as $val){
632 $smarty->assign("$val", $this->$val);
633 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
634 }
635 } else {
636 $smarty->assign("governmentmode", "false");
637 }
639 /* Special mode for uid */
640 $uidACL= $this->getacl("uid",(!is_object($this->parent) && !session::is_set('edit')));
641 if (isset ($this->dn)){
642 if ($this->dn != "new"){
643 $uidACL= preg_replace("/w/","",$uidACL);
644 }
645 } else {
646 $uidACL= preg_replace("/w/","",$uidACL);
647 }
649 $smarty->assign("uidACL", $uidACL);
650 $smarty->assign("is_template", $this->is_template);
651 $smarty->assign("use_dob", $this->use_dob);
653 if (isset($this->parent)){
654 if (isset($this->parent->by_object['phoneAccount']) &&
655 $this->parent->by_object['phoneAccount']->is_account){
656 $smarty->assign("has_phoneaccount", "true");
657 } else {
658 $smarty->assign("has_phoneaccount", "false");
659 }
660 } else {
661 $smarty->assign("has_phoneaccount", "false");
662 }
663 $smarty->assign("multiple_support" , $this->multiple_support_active);
664 return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
665 }
668 /* remove object from parent */
669 function remove_from_parent()
670 {
671 /* Only remove valid accounts */
672 if(!$this->initially_was_account) return;
674 /* Remove password extension */
675 $temp= passwordMethod::get_available_methods();
677 /* Remove password method from user account */
678 if(isset($temp[$this->pw_storage]) && class_available($temp[$this->pw_storage])){
679 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
680 $this->pwObject->remove_from_parent();
681 }
683 /* Remove user */
684 $ldap= $this->config->get_ldap_link();
685 $ldap->rmdir ($this->dn);
686 if (!$ldap->success()){
687 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
688 }
690 new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
692 /* Delete references to groups */
693 $ldap->cd ($this->config->current['BASE']);
694 $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
695 while ($ldap->fetch()){
696 $g= new group($this->config, $ldap->getDN());
697 $g->removeUser($this->uid);
698 $g->save ();
699 }
701 /* Delete references to object groups */
702 $ldap->cd ($this->config->current['BASE']);
703 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
704 while ($ldap->fetch()){
705 $og= new ogroup($this->config, $ldap->getDN());
706 unset($og->member[$this->dn]);
707 $og->save ();
708 }
710 /* Delete references to roles */
711 $ldap->cd ($this->config->current['BASE']);
712 $ldap->search ("(&(objectClass=organizationalRole)(roleOccupant=".LDAP::prepare4filter($this->dn)."))", array("cn"));
713 while ($ldap->fetch()){
714 $role= new roleGeneric($this->config, $ldap->getDN());
715 $key = array_search($this->dn,$role->roleOccupant);
716 if($key !== FALSE){
717 unset($role->roleOccupant[$key]);
718 $role->reload();
719 $role->save ();
720 }
721 }
723 /* If needed, let the password method do some cleanup */
724 $tmp = new passwordMethod($this->config);
725 $available = $tmp->get_available_methods();
726 if (in_array_ics($this->pw_storage, $available['name'])){
727 $test= new $available[$this->pw_storage]($this->config);
728 $test->attrs= $this->attrs;
729 $test->dn= $this->dn;
730 $test->remove_from_parent();
731 }
733 /* Remove ACL dependencies too */
734 $tmp = new acl($this->config,$this->parent,$this->dn);
735 $tmp->remove_acl();
737 /* Optionally execute a command after we're done */
738 $this->handle_post_events("remove",array("uid" => $this->uid));
739 }
742 /* Save data to object */
743 function save_object()
744 {
745 if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
747 /* Make a backup of the current selected base */
748 $base_tmp = $this->base;
750 /* Parents save function */
751 plugin::save_object ();
753 /* Save government mode attributes */
754 if ($this->governmentmode){
755 foreach ($this->govattrs as $val){
756 if ($this->acl_is_writeable($val,(!is_object($this->parent) && !session::is_set('edit'))) && isset($_POST["$val"])){
757 $data= stripcslashes($_POST["$val"]);
758 if ($data != $this->$val){
759 $this->is_modified= TRUE;
760 }
761 $this->$val= $data;
762 }
763 }
764 }
766 /* In template mode, the uid is autogenerated... */
767 if ($this->is_template){
768 $this->uid= strtolower($this->sn);
769 $this->givenName= $this->sn;
770 }
772 /* Save base and pw_storage, since these are no LDAP attributes */
773 if (isset($_POST['base'])){
775 $tmp = $this->get_allowed_bases();
776 if(isset($tmp[$_POST['base']])){
777 $base= validate($_POST['base']);
778 if ($base != $this->base){
779 $this->is_modified= TRUE;
780 }
781 $this->base= $base;
782 }else{
783 $this->base = $base_tmp;
784 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
785 }
786 }
788 /* Get pw_storage mode */
789 if (isset($_POST['pw_storage'])){
790 foreach(array("pw_storage") as $val){
791 if(isset($_POST[$val])){
792 $data= validate($_POST[$val]);
793 if ($data != $this->$val){
794 $this->is_modified= TRUE;
795 }
796 $this->$val= $data;
797 }
798 }
799 }
801 if($this->pw_storage != $this->last_pw_storage && isset($_POST['pw_storage'])){
802 if ($this->acl_is_writeable("userPassword")){
803 $temp= passwordMethod::get_available_methods();
804 if (!is_object($this->pwObject) || !($this->pwObject instanceOf $temp[$this->pw_storage])){
805 foreach($temp as $id => $data){
806 if(isset($data['name']) && $data['name'] == $this->pw_storage && $data['is_configurable']){
807 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
808 break;
809 }
810 }
811 }
812 }
813 }
815 /* Save current cn
816 */
817 $this->cn = $this->givenName." ".$this->sn;
818 }
819 }
821 function rebind($ldap, $referral)
822 {
823 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
824 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
825 $this->error = "Success";
826 $this->hascon=true;
827 $this->reconnect= true;
828 return (0);
829 } else {
830 $this->error = "Could not bind to " . $credentials['ADMIN'];
831 return NULL;
832 }
833 }
836 /* Save data to LDAP, depending on is_account we save or delete */
837 function save()
838 {
839 global $lang;
841 /* Only force save of changes ....
842 If this attributes aren't changed, avoid saving.
843 */
845 if($this->gender=="0") $this->gender ="";
846 if($this->preferredLanguage=="0") $this->preferredLanguage ="";
848 /* First use parents methods to do some basic fillup in $this->attrs */
849 plugin::save ();
851 if ($this->dateOfBirth != ""){
852 if(!is_array($this->attrs['dateOfBirth'])) {
853 #TODO: use $lang to convert date
854 list($day, $month, $year)= split("\.", $this->dateOfBirth);
855 $this->attrs['dateOfBirth'] = sprintf("%04d-%02d-%02d", $year, $month, $day);
856 }
857 }
859 /* Remove additional objectClasses */
860 $tmp= array();
861 foreach ($this->attrs['objectClass'] as $key => $set){
862 $found= false;
863 foreach (array("ivbbentry", "gosaUserTemplate") as $val){
864 if (preg_match ("/^$set$/i", $val)){
865 $found= true;
866 break;
867 }
868 }
869 if (!$found){
870 $tmp[]= $set;
871 }
872 }
874 /* Replace the objectClass array. This is done because of the
875 separation into government and normal mode. */
876 $this->attrs['objectClass']= $tmp;
878 /* Add objectClasss for template mode? */
879 if ($this->is_template){
880 $this->attrs['objectClass'][]= "gosaUserTemplate";
881 }
883 /* Hard coded government mode? */
884 if ($this->governmentmode){
885 $this->attrs['objectClass'][]= "ivbbentry";
887 /* Copy standard attributes */
888 foreach ($this->govattrs as $val){
889 if ($this->$val != ""){
890 $this->attrs["$val"]= $this->$val;
891 } elseif (!$this->is_new) {
892 $this->attrs["$val"]= array();
893 }
894 }
896 /* Remove attribute if set to "nein" */
897 if ($this->publicVisible == "nein"){
898 $this->attrs['publicVisible']= array();
899 if($this->is_new){
900 unset($this->attrs['publicVisible']);
901 }else{
902 $this->attrs['publicVisible']=array();
903 }
905 }
907 }
909 /* Special handling for attribute userCertificate needed */
910 if ($this->userCertificate != ""){
911 $this->attrs["userCertificate;binary"]= $this->userCertificate;
912 $remove_userCertificate= false;
913 } else {
914 $remove_userCertificate= true;
915 }
917 /* Special handling for dateOfBirth value */
918 if ($this->dateOfBirth == ""){
919 if ($this->is_new) {
920 unset($this->attrs["dateOfBirth"]);
921 } else {
922 $this->attrs["dateOfBirth"]= array();
923 }
924 }
925 if (!$this->gender){
926 if ($this->is_new) {
927 unset($this->attrs["gender"]);
928 } else {
929 $this->attrs["gender"]= array();
930 }
931 }
932 if (!$this->preferredLanguage){
933 if ($this->is_new) {
934 unset($this->attrs["preferredLanguage"]);
935 } else {
936 $this->attrs["preferredLanguage"]= array();
937 }
938 }
940 /* Special handling for attribute jpegPhote needed, scale image via
941 image magick to 147x200 pixels and inject resulting data. */
942 if ($this->jpegPhoto == "*removed*"){
944 /* Reset attribute to avoid writing *removed* as value */
945 $this->attrs["jpegPhoto"] = array();
947 } else {
949 /* Fallback if there's no image magick inside PHP */
950 if (!function_exists("imagick_blob2image")){
951 /* Get temporary file name for conversation */
952 $fname = tempnam (TEMP_DIR, "GOsa");
954 /* Open file and write out photoData */
955 $fp = fopen ($fname, "w");
956 fwrite ($fp, $this->photoData);
957 fclose ($fp);
959 /* Build conversation query. Filename is generated automatically, so
960 we do not need any special security checks. Exec command and save
961 output. For PHP safe mode, you'll need a configuration which respects
962 image magick as executable... */
963 $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
964 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
965 $query, "Execute");
967 /* Read data written by convert */
968 $output= "";
969 $sh= popen($query, 'r');
970 while (!feof($sh)){
971 $output.= fread($sh, 4096);
972 }
973 pclose($sh);
975 unlink($fname);
977 /* Save attribute */
978 $this->attrs["jpegPhoto"] = $output;
980 } else {
982 /* Load the new uploaded Photo */
983 if(!$handle = imagick_blob2image($this->photoData)) {
984 new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
985 }
987 /* Resizing image to 147x200 and blur */
988 if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
989 new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
990 }
992 /* Converting image to JPEG */
993 if(!imagick_convert($handle,"JPEG")) {
994 new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
995 }
997 /* Creating binary Code for the Image */
998 if(!$dump = imagick_image2blob($handle)){
999 new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
1000 }
1002 /* Sending Image */
1003 $output= $dump;
1005 /* Save attribute */
1006 $this->attrs["jpegPhoto"] = $output;
1007 }
1009 }
1011 /* This only gets called when user is renaming himself */
1012 $ldap= $this->config->get_ldap_link();
1013 if ($this->dn != $this->new_dn){
1015 /* Write entry on new 'dn' */
1016 $this->update_acls($this->dn,$this->new_dn);
1017 $this->move($this->dn, $this->new_dn);
1019 /* Happen to use the new one */
1020 change_ui_dn($this->dn, $this->new_dn);
1021 $this->dn= $this->new_dn;
1022 }
1025 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1026 new entries. So do a check first... */
1027 $ldap->cat ($this->dn, array('dn'));
1028 if ($ldap->fetch()){
1029 $mode= "modify";
1030 } else {
1031 $mode= "add";
1032 $ldap->cd($this->config->current['BASE']);
1033 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1034 }
1036 /* Set password to some junk stuff in case of templates */
1037 if ($this->is_template){
1038 $temp= passwordMethod::get_available_methods();
1039 foreach($temp as $id => $data){
1040 if(isset($data['name']) && $data['name'] == $this->pw_storage){
1041 $tmp = new $temp[$this->pw_storage]($this->config,$this->dn);
1042 $tmp->set_hash($this->pw_storage);
1043 $this->attrs['userPassword'] = $tmp->create_template_hash($this->attrs);
1044 break;
1045 }
1046 }
1047 }
1049 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1050 $this->attributes, "Save via $mode");
1052 /* Finally write data with selected 'mode' */
1053 $this->cleanup();
1055 /* Update current locale settings, if we have edited ourselves */
1056 $ui = session::get('ui');
1057 if(isset($this->attrs['preferredLanguage']) && $this->dn == $ui->dn){
1058 $ui->language = $this->preferredLanguage;
1059 session::set('ui',$ui);
1060 session::set('Last_init_lang',"update");
1061 }
1063 $ldap->cd ($this->dn);
1064 $ldap->$mode ($this->attrs);
1065 if (!$ldap->success()){
1066 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1067 return (1);
1068 }
1070 /* Remove ACL dependencies too */
1071 if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1072 $tmp = new acl($this->config,$this->parent,$this->dn);
1073 $tmp->update_acl_membership($this->orig_dn,$this->dn);
1074 }
1076 if($mode == "modify"){
1077 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1078 }else{
1079 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1080 }
1082 /* Remove cert?
1083 For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1084 to work around myself. */
1085 if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1087 /* Reset array, assemble new, this should be reworked */
1088 $this->attrs= array();
1089 $this->attrs['userCertificate;binary']= array();
1091 /* Prepare connection */
1092 if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1093 die ("Could not connect to LDAP server");
1094 }
1095 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1096 if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("ldapFollowReferrals") == "true") {
1097 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1098 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1099 }
1100 if($this->config->get_cfg_value("ldapTLS") == "true"){
1101 ldap_start_tls($ds);
1102 }
1103 if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1104 $this->config->current['PASSWORD']))) {
1105 die ("Could not bind to LDAP");
1106 }
1108 /* Modify using attrs */
1109 ldap_mod_del($ds,$this->dn,$this->attrs);
1110 ldap_close($ds);
1111 }
1113 /* If needed, let the password method do some cleanup */
1114 if ($this->pw_storage != $this->last_pw_storage){
1115 $tmp = new passwordMethod($this->config);
1116 $available = $tmp->get_available_methods();
1117 if (in_array_ics($this->last_pw_storage, $available['name'])){
1118 $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1119 $test->attrs= $this->attrs;
1120 $test->remove_from_parent();
1121 }
1122 }
1124 /* Maybe the current password method want's to do some changes... */
1125 if (is_object($this->pwObject)){
1126 $this->pwObject->save($this->dn);
1127 }
1129 /* Optionally execute a command after we're done */
1130 if ($mode == "add"){
1131 $this->handle_post_events("add", array("uid" => $this->uid));
1132 } elseif ($this->is_modified){
1133 $this->handle_post_events("modify", array("uid" => $this->uid));
1134 }
1136 return (0);
1137 }
1140 function create_initial_rdn($pattern)
1141 {
1142 // Only generate single RDNs
1143 if (preg_match('/\+/', $pattern)){
1144 msg_dialog::display(_("Error"), _("Cannot build RDN: no + allowed to build sub RDN!"), ERROR_DIALOG);
1145 return "";
1146 }
1148 // Extract attribute
1149 $attribute= preg_replace('/=.*$/', '', $pattern);
1150 if (!in_array_ics($attribute, $this->attributes)) {
1151 msg_dialog::display(_("Error"), _("Cannot build RDN: attribute is not defined!"), ERROR_DIALOG);
1152 return "";
1153 }
1155 // Sort attributes for length
1156 $attrl= array();
1157 foreach ($this->attributes as $attr) {
1158 $attrl[$attr]= strlen($attr);
1159 }
1160 arsort($attrl);
1162 // Walk thru sorted attributes and replace them in pattern
1163 foreach ($attrl as $attr => $dummy) {
1164 if (!is_array($this->$attr)){
1165 $pattern= preg_replace("/%$attr/", $this->$attr, $pattern);
1166 } else {
1167 // Array elements cannot be used for ID generation
1168 if (preg_match("/%$attr/", $pattern)) {
1169 msg_dialog::display(_("Error"), _("Cannot build RDN: invalid attribute parameters!"), ERROR_DIALOG);
1170 break;
1171 }
1172 }
1173 }
1175 // Internally assign value
1176 $this->$attribute= preg_replace('/^[^=]+=/', '', $pattern);
1178 return $pattern;
1179 }
1182 function update_new_dn()
1183 {
1184 // Alternative way to handle DN
1185 $pattern= $this->config->get_cfg_value("accountRDN");
1186 if ($pattern != "") {
1187 $rdn= $this->create_initial_rdn($pattern);
1188 $attribute= preg_replace('/=.*$/', '', $rdn);
1189 $value= preg_replace('/^[^=]+=$/', '', $rdn);
1191 /* Don't touch dn, if $attribute hasn't changed */
1192 if (isset($this->saved_attributes[$attribute]) && $this->saved_attributes[$attribute] == $this->$attribute &&
1193 $this->orig_base == $this->base ){
1194 $this->new_dn= $this->dn;
1195 } else {
1196 $this->new_dn= $this->create_unique_dn2($rdn, get_people_ou().$this->base);
1197 }
1199 // Original way to handle DN
1200 } else {
1202 $pt= "";
1203 if($this->config->get_cfg_value("personalTitleInDN") == "true"){
1204 if(!empty($this->personalTitle)){
1205 $pt = $this->personalTitle." ";
1206 }
1207 }
1209 $this->cn= $pt.$this->givenName." ".$this->sn;
1211 /* Permissions for that base? */
1212 if ($this->config->get_cfg_value("accountPrimaryAttribute") == "uid"){
1213 $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1214 } else {
1215 /* Don't touch dn, if cn hasn't changed */
1216 if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1217 $this->orig_base == $this->base ){
1218 $this->new_dn= $this->dn;
1219 } else {
1220 $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1221 }
1222 }
1223 }
1224 }
1227 /* Check formular input */
1228 function check()
1229 {
1230 /* Call common method to give check the hook */
1231 $message= plugin::check();
1233 /* Configurable password methods should be configured initially.
1234 */
1235 if($this->last_pw_storage != $this->pw_storage){
1236 $temp= passwordMethod::get_available_methods();
1237 foreach($temp['name'] as $id => $name){
1238 if($name == $this->pw_storage){
1239 if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1240 $message[] = _("The selected password method requires initial configuration!");
1241 }
1242 break;
1243 }
1244 }
1245 }
1247 $this->update_new_dn();
1249 /* Set the new acl base */
1250 if($this->dn == "new") {
1251 $this->set_acl_base($this->base);
1252 }
1254 /* Check if we are allowed to create/move this user */
1255 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1256 $message[]= msgPool::permCreate();
1257 }elseif($this->orig_dn != "new" && $this->new_dn != $this->orig_dn && !$this->acl_is_moveable($this->base)){
1258 $message[]= msgPool::permMove();
1259 }
1261 /* UID already used? */
1262 $ldap= $this->config->get_ldap_link();
1263 $ldap->cd($this->config->current['BASE']);
1264 $ldap->search("(uid=$this->uid)", array("uid"));
1265 $ldap->fetch();
1266 if ($ldap->count() != 0 && $this->dn == 'new'){
1267 $message[]= msgPool::duplicated(_("Login"));
1268 }
1270 /* In template mode, the uid and givenName are autogenerated... */
1271 if ($this->sn == ""){
1272 $message[]= msgPool::required(_("Name"));
1273 }
1275 if (!$this->is_template){
1276 if ($this->givenName == ""){
1277 $message[]= msgPool::required(_("Given name"));
1278 }
1279 if ($this->uid == ""){
1280 $message[]= msgPool::required(_("Login"));
1281 }
1282 if ($this->config->get_cfg_value("accountPrimaryAttribute") != "uid"){
1283 $ldap->cat($this->new_dn);
1284 if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1285 $message[]= msgPool::duplicated(_("Name"));
1286 }
1287 }
1288 }
1290 /* Check for valid input */
1291 if ($this->is_modified && !tests::is_uid($this->uid)){
1293 if (strict_uid_mode()){
1294 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1295 } else {
1296 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1297 }
1298 }
1299 if (!tests::is_url($this->labeledURI)){
1300 $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1301 }
1303 /* Check phone numbers */
1304 if (!tests::is_phone_nr($this->telephoneNumber)){
1305 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1306 }
1307 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1308 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1309 }
1310 if (!tests::is_phone_nr($this->mobile)){
1311 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1312 }
1313 if (!tests::is_phone_nr($this->pager)){
1314 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1315 }
1317 /* Check dates */
1318 if (!tests::is_date($this->dateOfBirth)){
1319 $message[]= msgPool::invalid(_("Date of birth"), $this->dateOfBirth);
1320 }
1322 /* Check for reserved characers */
1323 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1324 $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1325 }
1326 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1327 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1328 }
1330 return $message;
1331 }
1334 /* Indicate whether a password change is needed or not */
1335 function password_change_needed()
1336 {
1337 if(in_array("pw_storage",$this->multi_boxes)){
1338 return(TRUE);
1339 }
1340 return($this->pw_storage != $this->last_pw_storage && !$this->is_template);
1341 }
1344 /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1345 function load_picture()
1346 {
1347 $ldap = $this->config->get_ldap_link();
1348 $ldap->cd ($this->dn);
1349 $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1351 if((!$data) || ($data == "*removed*")){
1353 /* In case we don't get an entry, load a default picture */
1354 $this->set_picture ();
1355 $this->jpegPhoto= "*removed*";
1356 }else{
1358 /* Set picture */
1359 $this->photoData= $data;
1360 session::set('binary',$this->photoData);
1361 session::set('binarytype',"image/jpeg");
1362 $this->jpegPhoto= "";
1363 }
1364 }
1367 /* Load a certificate from LDAP, this is going to be simplified later on */
1368 function load_cert()
1369 {
1370 $ds= ldap_connect($this->config->current['SERVER']);
1371 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1372 if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("ldapFollowReferrals") == "true"){
1373 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1374 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1375 }
1376 if ($this->config->get_cfg_value("ldapTLS") == "true"){
1377 ldap_start_tls($ds);
1378 }
1380 $r= ldap_bind($ds);
1381 $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1383 if ($sr) {
1384 $ei= @ldap_first_entry($ds, $sr);
1386 if ($ei) {
1387 if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1388 $this->userCertificate= "";
1389 } else {
1390 $this->userCertificate= $info[0];
1391 }
1392 }
1393 } else {
1394 $this->userCertificate= "";
1395 }
1397 ldap_unbind($ds);
1398 }
1401 /* Load picture from file to object */
1402 function set_picture($filename ="")
1403 {
1404 if (!is_file($filename) || $filename =="" ){
1405 $filename= "./plugins/users/images/default.jpg";
1406 $this->jpegPhoto= "*removed*";
1407 }
1409 $fd = fopen ($filename, "rb");
1410 $this->photoData= fread ($fd, filesize ($filename));
1411 session::set('binary',$this->photoData);
1412 session::set('binarytype',"image/jpeg");
1413 $this->jpegPhoto= "";
1415 fclose ($fd);
1416 }
1419 /* Load certificate from file to object */
1420 function set_cert($cert, $filename)
1421 {
1422 if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1423 $fd = fopen ($filename, "rb");
1424 if (filesize($filename)>0) {
1425 $this->$cert= fread ($fd, filesize ($filename));
1426 fclose ($fd);
1427 $this->is_modified= TRUE;
1428 } else {
1429 msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1430 }
1431 }
1433 /* Adapt from given 'dn' */
1434 function adapt_from_template($dn, $skip= array())
1435 {
1436 plugin::adapt_from_template($dn, $skip);
1438 /* Get password method from template
1439 */
1440 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
1441 if(is_object($tmp)){
1442 if($tmp->is_configurable()){
1443 $tmp->adapt_from_template($dn);
1444 $this->pwObject = &$tmp;
1445 }
1446 $this->pw_storage= $tmp->get_hash();
1447 }
1449 /* Get base */
1450 $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1452 if($this->governmentmode){
1454 /* Walk through govattrs */
1455 foreach ($this->govattrs as $val){
1457 if (in_array($val, $skip)){
1458 continue;
1459 }
1461 if (isset($this->attrs["$val"][0])){
1463 /* If attribute is set, replace dynamic parts:
1464 %sn, %givenName and %uid. Fill these in our local variables. */
1465 $value= $this->attrs["$val"][0];
1467 foreach (array("sn", "givenName", "uid") as $repl){
1468 if (preg_match("/%$repl/i", $value)){
1469 $value= preg_replace ("/%$repl/i",
1470 $this->parent->$repl, $value);
1471 }
1472 }
1473 $this->$val= $value;
1474 }
1475 }
1476 }
1478 /* Get back uid/sn/givenName - only write if nothing's skipped */
1479 if ($this->parent !== NULL && count($skip) == 0){
1480 $this->uid= $this->parent->uid;
1481 $this->sn= $this->parent->sn;
1482 $this->givenName= $this->parent->givenName;
1483 }
1484 }
1487 /* This avoids that users move themselves out of their rights.
1488 */
1489 function allowedBasesToMoveTo()
1490 {
1491 /* Get bases */
1492 $bases = $this->get_allowed_bases();
1493 return($bases);
1494 }
1497 function getCopyDialog()
1498 {
1499 $str = "";
1501 session::set('binary',$this->photoData);
1502 session::set('binarytype',"image/jpeg");
1504 /* Get random number for pictures */
1505 srand((double)microtime()*1000000);
1506 $rand = rand(0, 10000);
1508 $smarty = get_smarty();
1510 $smarty->assign("passwordTodo","clear");
1512 if(isset($_POST['passwordTodo'])){
1513 $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1514 }
1516 $smarty->assign("sn", $this->sn);
1517 $smarty->assign("givenName",$this->givenName);
1518 $smarty->assign("uid", $this->uid);
1519 $smarty->assign("rand", $rand);
1520 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1523 $ret = array();
1524 $ret['string'] = $str;
1525 $ret['status'] = "";
1526 return($ret);
1527 }
1529 function saveCopyDialog()
1530 {
1531 /* Set_acl_base */
1532 $this->set_acl_base($this->base);
1534 if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1535 $this->set_picture($_FILES['picture_file']['tmp_name']);
1536 }
1538 /* Remove picture? */
1539 if (isset($_POST['picture_remove'])){
1540 $this->jpegPhoto= "*removed*";
1541 $this->set_picture ("./plugins/users/images/default.jpg");
1542 $this->is_modified= TRUE;
1543 }
1545 $attrs = array("uid","givenName","sn");
1546 foreach($attrs as $attr){
1547 if(isset($_POST[$attr])){
1548 $this->$attr = $_POST[$attr];
1549 }
1550 }
1551 }
1554 function PrepareForCopyPaste($source)
1555 {
1556 plugin::PrepareForCopyPaste($source);
1558 /* Reset certificate information addepted from source user
1559 to avoid setting the same user certificate for the destination user. */
1560 $this->userPKCS12= "";
1561 $this->userSMIMECertificate= "";
1562 $this->userCertificate= "";
1563 $this->certificateSerialNumber= "";
1564 $this->old_certificateSerialNumber= "";
1565 $this->old_userPKCS12= "";
1566 $this->old_userSMIMECertificate= "";
1567 $this->old_userCertificate= "";
1568 }
1571 static function plInfo()
1572 {
1574 $govattrs= array(
1575 "gouvernmentOrganizationalUnit" => _("Unit"),
1576 "houseIdentifier" => _("House identifier"),
1577 "vocation" => _("Vocation"),
1578 "ivbbLastDeliveryCollective" => _("Last delivery"),
1579 "gouvernmentOrganizationalPersonLocality" => _("Person locality"),
1580 "gouvernmentOrganizationalUnitDescription" => _("Unit description"),
1581 "gouvernmentOrganizationalUnitSubjectArea" => _("Subject area"),
1582 "functionalTitle" => _("Functional title"),
1583 "certificateSerialNumber" => _("Certificate serial number"),
1584 "publicVisible" => _("Public visible"),
1585 "street" => _("Street"),
1586 "role" => _("Role"),
1587 "postalCode" => _("Postal code"));
1589 $ret = array(
1590 "plShortName" => _("Generic"),
1591 "plDescription" => _("Generic user settings"),
1592 "plSelfModify" => TRUE,
1593 "plDepends" => array(),
1594 "plPriority" => 1,
1595 "plSection" => array("personal" => _("My account")),
1596 "plCategory" => array("users" => array("description" => _("Users"),
1597 "objectClass" => "gosaAccount")),
1599 "plProvidedAcls" => array(
1601 "sn" => _("Surname"),
1602 "givenName" => _("Given name"),
1603 "uid" => _("User identification"),
1604 "personalTitle" => _("Personal title"),
1605 "academicTitle" => _("Academic title"),
1607 "dateOfBirth" => _("Date of birth"),
1608 "gender" => _("Gender"),
1609 "preferredLanguage" => _("Preferred language"),
1610 "base" => _("Base"),
1612 "userPicture" => _("User picture"),
1614 "o" => _("Organization"),
1615 "ou" => _("Department"),
1616 "departmentNumber" => _("Department number"),
1617 "employeeNumber" => _("Employee number"),
1618 "employeeType" => _("Employee type"),
1620 "roomNumber" => _("Room number"),
1621 "telephoneNumber" => _("Telefon number"),
1622 "pager" => _("Pager number"),
1623 "mobile" => _("Mobile number"),
1624 "facsimileTelephoneNumber" => _("Fax number"),
1626 "st" => _("State"),
1627 "l" => _("Location"),
1628 "postalAddress" => _("Postal address"),
1630 "homePostalAddress" => _("Home postal address"),
1631 "homePhone" => _("Home phone number"),
1632 "labeledURI" => _("Homepage"),
1633 "userPassword" => _("User password method"),
1634 "Certificate" => _("User certificates"))
1636 );
1638 /* Append government attributes if required */
1639 global $config;
1640 if($config->get_cfg_value("honourIvbbAttributes") == "true"){
1641 foreach($govattrs as $attr => $desc){
1642 $ret["plProvidedAcls"][$attr] = $desc;
1643 }
1644 }
1645 return($ret);
1646 }
1648 function get_multi_edit_values()
1649 {
1650 $ret = plugin::get_multi_edit_values();
1651 if(in_array("pw_storage",$this->multi_boxes)){
1652 $ret['pw_storage'] = $this->pw_storage;
1653 }
1654 if(in_array("edit_picture",$this->multi_boxes)){
1655 $ret['jpegPhoto'] = $this->jpegPhoto;
1656 $ret['photoData'] = $this->photoData;
1657 $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1658 $ret['old_photoData'] = $this->old_photoData;
1659 }
1660 if(isset($ret['dateOfBirth'])){
1661 unset($ret['dateOfBirth']);
1662 }
1663 if(isset($ret['cn'])){
1664 unset($ret['cn']);
1665 }
1666 $ret['is_modified'] = $this->is_modified;
1667 if(in_array("base",$this->multi_boxes)){
1668 $ret['orig_base']="Changed_by_Multi_Plug";
1669 $ret['base']=$this->base;
1670 }
1671 return($ret);
1672 }
1675 function multiple_save_object()
1676 {
1677 plugin::multiple_save_object();
1679 /* Get pw_storage mode */
1680 if (isset($_POST['pw_storage'])){
1681 foreach(array("pw_storage") as $val){
1682 if(isset($_POST[$val])){
1683 $data= validate(get_post($val));
1684 if ($data != $this->$val){
1685 $this->is_modified= TRUE;
1686 }
1687 $this->$val= $data;
1688 }
1689 }
1690 }
1691 if(isset($_POST['base'])){
1692 $this->base = get_post('base');
1693 }
1695 if(isset($_POST['user_mulitple_edit'])){
1696 foreach(array("base","pw_storage","edit_picture") as $val){
1697 if(isset($_POST["use_".$val])){
1698 $this->multi_boxes[] = $val;
1699 }
1700 }
1701 }
1702 }
1705 function multiple_check()
1706 {
1707 /* Call check() to set new_dn correctly ... */
1708 $message = plugin::multiple_check();
1710 /* Set the new acl base */
1711 if($this->dn == "new") {
1712 $this->set_acl_base($this->base);
1713 }
1714 if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1715 $message[]= msgPool::invalid(_("Homepage"));
1716 }
1717 if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1718 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1719 }
1720 if (!tests::is_phone_nr($this->facsimileTelephoneNumber) && in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1721 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1722 }
1723 if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1724 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1725 }
1726 if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1727 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1728 }
1729 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1730 $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1731 }
1732 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1733 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1734 }
1735 return($message);
1736 }
1740 function multiple_execute()
1741 {
1742 return($this->execute());
1743 }
1746 }
1748 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1749 ?>