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