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 $this->config= $config;
135 /* Configuration is fine, allways */
136 if($this->config->get_cfg_value("honourIvbbAttributes") == "true"){
137 $this->governmentmode = TRUE;
138 $this->attributes=array_merge($this->attributes,$this->govattrs);
139 }
141 /* Load base attributes */
142 plugin::plugin ($config, $dn);
144 $this->orig_dn = $this->dn;
145 $this->new_dn = $dn;
147 if ($this->governmentmode){
148 /* Fix public visible attribute if unset */
149 if (!isset($this->attrs['publicVisible'])){
150 $this->publicVisible == "nein";
151 }
152 }
154 /* Load government mode attributes */
155 if ($this->governmentmode){
156 /* Copy all attributs */
157 foreach ($this->govattrs as $val){
158 if (isset($this->attrs["$val"][0])){
159 $this->$val= $this->attrs["$val"][0];
160 }
161 }
162 }
164 /* Create me for new accounts */
165 if ($dn == "new"){
166 $this->is_account= TRUE;
167 }
169 /* Make hash default to md5 if not set in config */
170 $hash= $this->config->get_cfg_value("passwordDefaultHash", "crypt/md5");
172 /* Load data from LDAP? */
173 if ($dn !== NULL){
175 /* Do base conversation */
176 if ($this->dn == "new"){
177 $ui= get_userinfo();
178 $this->base= dn2base($ui->dn);
179 } else {
180 $this->base= dn2base($dn);
181 }
183 /* get password storage type */
184 if (isset ($this->attrs['userPassword'][0])){
185 /* Initialize local array */
186 $matches= array();
187 if (preg_match ("/^{[^}]+}/", $this->attrs['userPassword'][0])){
188 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
189 if(is_object($tmp)){
190 $this->pw_storage= $tmp->get_hash();
191 }
193 } else {
194 if ($this->attrs['userPassword'][0] != ""){
195 $this->pw_storage= "clear";
196 } else {
197 $this->pw_storage= $hash;
198 }
199 }
200 } else {
201 /* Preset with vaule from configuration */
202 $this->pw_storage= $hash;
203 }
205 /* Load extra attributes: certificate and picture */
206 $this->load_cert();
207 $this->load_picture();
208 if ($this->userCertificate != ""){
209 $this->had_userCertificate= TRUE;
210 }
211 }
213 /* Reset password storage indicator, used by password_change_needed() */
214 if ($dn == "new"){
215 $this->last_pw_storage= "unset";
216 } else {
217 $this->last_pw_storage= $this->pw_storage;
218 }
220 /* Generate dateOfBirth entry */
221 if (isset ($this->attrs['dateOfBirth'])){
222 /* This entry is ISO 8601 conform */
223 list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
225 $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
226 $this->use_dob= "1";
227 } else {
228 $this->use_dob= "0";
229 }
231 /* Put gender attribute to upper case */
232 if (isset ($this->attrs['gender'])){
233 $this->gender= strtoupper($this->attrs['gender'][0]);
234 }
236 $this->orig_base = $this->base;
237 }
242 /* execute generates the html output for this node */
243 function execute()
244 {
245 /* Call parent execute */
246 plugin::execute();
248 /* Handle add/delete for restriction mode */
249 if (isset($_POST['add_res']) && isset($_POST['res'])) {
250 $val= validate($_POST['res']);
251 if (preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/', $val) ||
252 preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+)$/', $val) ||
253 preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $val)) {
254 $this->gosaLoginRestriction[]= $val;
255 } else {
256 msg_dialog::display(_("Error"), _("Please add a single IP address or a network/netmask combination!"), ERROR_DIALOG);
257 }
258 }
259 if (isset($_POST['del_res']) && isset($_POST['restrictions'])) {
260 $res= $_POST['restrictions'];
261 if (!is_array($res)){
262 $res= array($res);
263 }
264 foreach ($res as $restriction) {
265 if (in_array($restriction, $this->gosaLoginRestriction)) {
266 $this->gosaLoginRestriction= array_remove_entries(array($restriction), $this->gosaLoginRestriction);
267 }
268 }
269 }
271 /* Log view */
272 if($this->is_account && !$this->view_logged){
273 $this->view_logged = TRUE;
274 new log("view","users/".get_class($this),$this->dn);
275 }
277 $smarty= get_smarty();
279 /* Fill calendar */
280 if ($this->dateOfBirth == "0"){
281 $date= getdate();
282 } else {
283 if(is_array($this->dateOfBirth)){
284 $date = $this->dateOfBirth;
286 // Trigger on dates like 1985-04-01, getdate only understands timestamps
287 } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
288 $date= getdate(strtotime($this->dateOfBirth));
290 } else {
291 $date = getdate($this->dateOfBirth);
292 }
293 }
295 $days= array();
296 for($d= 1; $d<32; $d++){
297 $days[$d]= $d;
298 }
299 $years= array();
301 if(($date['year']-100)<1901){
302 $start = 1901;
303 }else{
304 $start = $date['year']-100;
305 }
307 $end = $start +100;
309 for($y= $start; $y<=$end; $y++){
310 $years[]= $y;
311 }
312 $years['-']= "- ";
313 $months= msgPool::months();
314 $months['-'] = '- ';
316 $smarty->assign("day", $date["mday"]);
317 $smarty->assign("days", $days);
318 $smarty->assign("months", $months);
319 $smarty->assign("month", $date["mon"]-1);
320 $smarty->assign("years", $years);
321 $smarty->assign("year", $date["year"]);
323 /* Assign sex */
324 $sex= array(0 => " ", "F" => _("female"), "M" => _("male"));
325 $smarty->assign("gender_list", $sex);
326 $language= array_merge(array(0 => " ") ,get_languages(TRUE));
327 $smarty->assign("preferredLanguage_list", $language);
329 /* Get random number for pictures */
330 srand((double)microtime()*1000000);
331 $smarty->assign("rand", rand(0, 10000));
334 /* Do we represent a valid gosaAccount? */
335 if (!$this->is_account){
336 $str = "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
337 msgPool::noValidExtension("GOsa")."</b>";
338 return($str);
339 }
341 /* Base select dialog */
342 $once = true;
343 foreach($_POST as $name => $value){
344 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
345 $once = false;
346 $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
347 $this->dialog->setCurrentBase($this->base);
348 }
349 }
351 /* Password configure dialog handling */
352 if(is_object($this->pwObject) && $this->pwObject->display){
353 $output= $this->pwObject->configure();
354 if ($output != ""){
355 $this->dialog= TRUE;
356 return $output;
357 }
358 $this->dialog= false;
359 }
361 /* Dialog handling */
362 if(is_object($this->dialog)){
363 /* Must be called before save_object */
364 $this->dialog->save_object();
366 if($this->dialog->isClosed()){
367 $this->dialog = false;
368 }elseif($this->dialog->isSelected()){
370 /* check if selected base is allowed to move to / create a new object */
371 $tmp = $this->get_allowed_bases();
372 if(isset($tmp[$this->dialog->isSelected()])){
373 $this->base = $this->dialog->isSelected();
374 }
375 $this->dialog= false;
376 }else{
377 return($this->dialog->execute());
378 }
379 }
381 /* Want password method editing? */
382 if ($this->acl_is_writeable("userPassword")){
383 if (isset($_POST['edit_pw_method'])){
384 if (!is_object($this->pwObject) || $this->pw_storage != $this->pwObject->get_hash_name()){
385 $temp= passwordMethod::get_available_methods();
386 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
387 }
388 $this->pwObject->display = TRUE;
389 $this->dialog= TRUE;
390 return ($this->pwObject->configure());
391 }
392 }
394 /* Want picture edit dialog? */
395 if($this->acl_is_writeable("userPicture")) {
396 if (isset($_POST['edit_picture'])){
397 /* Save values for later recovery, in case some presses
398 the cancel button. */
399 $this->old_jpegPhoto= $this->jpegPhoto;
400 $this->old_photoData= $this->photoData;
401 $this->picture_dialog= TRUE;
402 $this->dialog= TRUE;
403 }
404 }
406 /* Remove picture? */
407 if($this->acl_is_writeable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))) ){
408 if (isset($_POST['picture_remove'])){
409 $this->set_picture ();
410 $this->jpegPhoto= "*removed*";
411 $this->is_modified= TRUE;
412 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
413 }
414 }
416 /* Save picture */
417 if (isset($_POST['picture_edit_finish'])){
419 /* Check for clean upload */
420 if ($_FILES['picture_file']['name'] != ""){
421 if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
422 msg_dialog::display(_("Error"), _("Cannot upload file!"), ERROR_DIALOG);
423 }else{
424 /* Activate new picture */
425 $this->set_picture($_FILES['picture_file']['tmp_name']);
426 }
427 }
428 $this->picture_dialog= FALSE;
429 $this->dialog= FALSE;
430 $this->is_modified= TRUE;
431 }
434 /* Cancel picture */
435 if (isset($_POST['picture_edit_cancel'])){
437 /* Restore values */
438 $this->jpegPhoto= $this->old_jpegPhoto;
439 $this->photoData= $this->old_photoData;
441 /* Update picture */
442 session::set('binary',$this->photoData);
443 session::set('binarytype',"image/jpeg");
444 $this->picture_dialog= FALSE;
445 $this->dialog= FALSE;
446 }
448 /* Toggle dateOfBirth information */
449 if (isset($_POST['set_dob'])){
450 $this->use_dob= ($this->use_dob == "0")?"1":"0";
451 }
454 /* Want certificate= */
455 if ((isset($_POST['edit_cert'])) && $this->acl_is_readable("Certificate")){
457 /* Save original values for later reconstruction */
458 foreach (array("certificateSerialNumber", "userCertificate",
459 "userSMIMECertificate", "userPKCS12") as $val){
461 $oval= "old_$val";
462 $this->$oval= $this->$val;
463 }
465 $this->cert_dialog= TRUE;
466 $this->dialog= TRUE;
467 }
470 /* Cancel certificate dialog */
471 if (isset($_POST['cert_edit_cancel'])){
473 /* Restore original values in case of 'cancel' */
474 foreach (array("certificateSerialNumber", "userCertificate",
475 "userSMIMECertificate", "userPKCS12") as $val){
477 $oval= "old_$val";
478 $this->$val= $this->$oval;
479 }
480 $this->cert_dialog= FALSE;
481 $this->dialog= FALSE;
482 }
485 /* Remove certificate? */
486 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
487 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12") as $val){
488 if (isset($_POST["remove_$val"])){
490 /* Reset specified cert*/
491 $this->$val= "";
492 $this->is_modified= TRUE;
493 }
494 }
495 }
497 /* Upload new cert and close dialog? */
498 if($this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))){
500 $fail =false;
502 if (isset($_POST['cert_edit_finish'])){
504 /* for all certificates do */
505 foreach (array ("userCertificate", "userSMIMECertificate", "userPKCS12")
506 as $val){
508 /* Check for clean upload */
509 if (array_key_exists($val."_file", $_FILES) &&
510 array_key_exists('name', $_FILES[$val."_file"]) &&
511 $_FILES[$val."_file"]['name'] != "" &&
512 is_uploaded_file($_FILES[$val."_file"]['tmp_name'])) {
513 $this->set_cert("$val", $_FILES[$val."_file"]['tmp_name']);
514 }
515 }
517 /* Save serial number */
518 if (isset($_POST["certificateSerialNumber"]) &&
519 $_POST["certificateSerialNumber"] != ""){
521 if (!tests::is_id($_POST["certificateSerialNumber"])){
522 $fail = true;
523 msg_dialog::display(_("Error"), msgPool::invalid(_("Serial number"),$_POST["certificateSerialNumber"],"/[0-9]/"),ERROR_DIALOG);
525 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
526 if ($this->$cert != ""){
527 $smarty->assign("$cert"."_state", "true");
528 } else {
529 $smarty->assign("$cert"."_state", "");
530 }
531 }
532 }
534 $this->certificateSerialNumber= $_POST["certificateSerialNumber"];
535 $this->is_modified= TRUE;
536 }
537 if(!$fail){
538 $this->cert_dialog= FALSE;
539 $this->dialog= FALSE;
540 }
541 }
542 }
543 /* Display picture dialog */
544 if ($this->picture_dialog){
545 return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
546 }
548 /* Display cert dialog */
549 if ($this->cert_dialog){
550 $smarty->assign("CertificateACL",$this->getacl("Certificate",(!is_object($this->parent) && !session::is_set('edit'))));
551 $smarty->assign("Certificate_readable",$this->acl_is_readable("Certificate"));
552 $smarty->assign("certificateSerialNumber",$this->certificateSerialNumber);
554 foreach(array("userCertificate", "userSMIMECertificate", "userPKCS12") as $cert){
555 if ($this->$cert != ""){
556 /* import certificate */
557 $certificate = new certificate;
558 $certificate->import($this->$cert);
560 /* Read out data*/
561 $timeto = $certificate->getvalidto_date();
562 $timefrom = $certificate->getvalidfrom_date();
565 /* Additional info if start end time is '0' */
566 $add_str_info = "";
567 if($timeto == 0 && $timefrom == 0){
568 $add_str_info = "<br><i>"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."</i>";
569 }
571 $str = "<table summary=\"\" border=0>
572 <tr>
573 <td style='vertical-align:top'>CN</td>
574 <td>".preg_replace("/ /", " ", $certificate->getname())."</td>
575 </tr>
576 </table><br>".
578 sprintf(_("Certificate is valid from %s to %s and is currently %s."),
579 "<b>".date('d M Y',$timefrom)."</b>",
580 "<b>".date('d M Y',$timeto)."</b>",
581 $certificate->isvalid()?"<b><font style='color:green'>"._("valid")."</font></b>":
582 "<b><font style='color:red'>"._("invalid")."</font></b>").$add_str_info;
584 $smarty->assign($cert."info",$str);
585 $smarty->assign($cert."_state","true");
586 } else {
587 $smarty->assign($cert."info", "<i>"._("No certificate installed")."</i>");
588 $smarty->assign($cert."_state","");
589 }
590 }
592 if($this->governmentmode){
593 $smarty->assign("honourIvbbAttributes", "true");
594 }else{
595 $smarty->assign("honourIvbbAttributes", "false");
596 }
597 $smarty->assign("governmentmode", $this->governmentmode);
598 return($smarty->fetch (get_template_path('generic_certs.tpl', TRUE, dirname(__FILE__))));
599 }
601 /* Prepare password hashes */
602 if ($this->pw_storage == ""){
603 $this->pw_storage= $this->config->get_cfg_value("hash");
604 }
606 $temp= passwordMethod::get_available_methods();
607 $is_configurable= FALSE;
608 $hashes = $temp['name'];
609 if(isset($temp[$this->pw_storage])){
610 $test= new $temp[$this->pw_storage]($this->config);
611 $is_configurable= $test->is_configurable();
612 }else{
613 new msg_dialog(_("Password method"),_("The selected password method is no longer available."),WARNING_DIALOG);
614 }
617 /* Create password methods array */
618 $pwd_methods = array();
619 foreach($hashes as $id => $name){
620 if(!empty($temp['desc'][$id])){
621 $pwd_methods[$name] = $name." (".$temp['desc'][$id].")";
622 }else{
623 $pwd_methods[$name] = $name;
624 }
625 }
627 /* Load attributes and acl's */
628 $ui =get_userinfo();
629 foreach($this->attributes as $val){
630 $smarty->assign("$val", $this->$val);
631 if(in_array($val,$this->multi_boxes)){
632 $smarty->assign("use_".$val,TRUE);
633 }else{
634 $smarty->assign("use_".$val,FALSE);
635 }
636 }
637 foreach(array("base","pw_storage","edit_picture") as $val){
638 if(in_array($val,$this->multi_boxes)){
639 $smarty->assign("use_".$val,TRUE);
640 }else{
641 $smarty->assign("use_".$val,FALSE);
642 }
643 }
645 /* Set acls */
646 $tmp = $this->plinfo();
647 foreach($tmp['plProvidedAcls'] as $val => $translation){
648 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
649 }
651 $smarty->assign("gosaLoginRestriction", $this->gosaLoginRestriction);
652 $smarty->assign("gosaLoginRestrictionACL", $this->getacl('gosaLoginRestriction', (!is_object($this->parent) && !session::is_set('edit'))));
653 $smarty->assign("pwmode", $pwd_methods);
654 $smarty->assign("pwmode_select", $this->pw_storage);
655 $smarty->assign("pw_configurable", $is_configurable);
656 $smarty->assign("passwordStorageACL", $this->getacl("userPassword",(!is_object($this->parent) && !session::is_set('edit'))));
657 $smarty->assign("base_select", $this->base);
659 if(!session::is_set('edit')){
660 $smarty->assign("CertificatesACL","");
661 }else{
662 $smarty->assign("CertificatesACL", $this->getacl("Certificate"));
663 }
665 $smarty->assign("userPictureACL", $this->getacl("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
666 $smarty->assign("userPicture_is_readable", $this->acl_is_readable("userPicture",(!is_object($this->parent) && !session::is_set('edit'))));
668 /* Create base acls */
669 $tmp = @$this->allowedBasesToMoveTo();
670 $smarty->assign("bases", $tmp);
672 /* Save government mode attributes */
673 if($this->governmentmode){
674 $smarty->assign("governmentmode", "true");
675 $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
676 "internet,ivbv", "internet,testa", "internet,ivbv,testa");
677 $smarty->assign("ivbbmodes", $ivbbmodes);
678 foreach ($this->govattrs as $val){
679 $smarty->assign("$val", $this->$val);
680 $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !session::is_set('edit'))));
681 }
682 } else {
683 $smarty->assign("governmentmode", "false");
684 }
686 /* Special mode for uid */
687 $uidACL= $this->getacl("uid",(!is_object($this->parent) && !session::is_set('edit')));
688 if (isset ($this->dn)){
689 if ($this->dn != "new"){
690 $uidACL= preg_replace("/w/","",$uidACL);
691 }
692 } else {
693 $uidACL= preg_replace("/w/","",$uidACL);
694 }
696 $smarty->assign("uidACL", $uidACL);
697 $smarty->assign("is_template", $this->is_template);
698 $smarty->assign("use_dob", $this->use_dob);
700 if (isset($this->parent)){
701 if (isset($this->parent->by_object['phoneAccount']) &&
702 $this->parent->by_object['phoneAccount']->is_account){
703 $smarty->assign("has_phoneaccount", "true");
704 } else {
705 $smarty->assign("has_phoneaccount", "false");
706 }
707 } else {
708 $smarty->assign("has_phoneaccount", "false");
709 }
710 $smarty->assign("multiple_support" , $this->multiple_support_active);
711 return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
712 }
715 /* remove object from parent */
716 function remove_from_parent()
717 {
718 /* Only remove valid accounts */
719 if(!$this->initially_was_account) return;
721 /* Remove password extension */
722 $temp= passwordMethod::get_available_methods();
724 /* Remove password method from user account */
725 if(isset($temp[$this->pw_storage]) && class_available($temp[$this->pw_storage])){
726 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
727 $this->pwObject->remove_from_parent();
728 }
730 /* Remove user */
731 $ldap= $this->config->get_ldap_link();
732 $ldap->rmdir ($this->dn);
733 if (!$ldap->success()){
734 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
735 }
737 new log("remove","users/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
739 /* Delete references to groups */
740 $ldap->cd ($this->config->current['BASE']);
741 $ldap->search ("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("uid"));
742 while ($ldap->fetch()){
743 $g= new group($this->config, $ldap->getDN());
744 $g->removeUser($this->uid);
745 $g->save ();
746 }
748 /* Delete references to object groups */
749 $ldap->cd ($this->config->current['BASE']);
750 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
751 while ($ldap->fetch()){
752 $og= new ogroup($this->config, $ldap->getDN());
753 unset($og->member[$this->dn]);
754 $og->save ();
755 }
757 /* Delete references to roles */
758 $ldap->cd ($this->config->current['BASE']);
759 $ldap->search ("(&(objectClass=organizationalRole)(roleOccupant=".LDAP::prepare4filter($this->dn)."))", array("cn"));
760 while ($ldap->fetch()){
761 $role= new roleGeneric($this->config, $ldap->getDN());
762 $key = array_search($this->dn,$role->roleOccupant);
763 if($key !== FALSE){
764 unset($role->roleOccupant[$key]);
765 $role->reload();
766 $role->save ();
767 }
768 }
770 /* If needed, let the password method do some cleanup */
771 $tmp = new passwordMethod($this->config);
772 $available = $tmp->get_available_methods();
773 if (in_array_ics($this->pw_storage, $available['name'])){
774 $test= new $available[$this->pw_storage]($this->config);
775 $test->attrs= $this->attrs;
776 $test->dn= $this->dn;
777 $test->remove_from_parent();
778 }
780 /* Remove ACL dependencies too */
781 $tmp = new acl($this->config,$this->parent,$this->dn);
782 $tmp->remove_acl();
784 /* Optionally execute a command after we're done */
785 $this->handle_post_events("remove",array("uid" => $this->uid));
786 }
789 /* Save data to object */
790 function save_object()
791 {
792 if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){
794 /* Make a backup of the current selected base */
795 $base_tmp = $this->base;
797 /* Parents save function */
798 plugin::save_object ();
800 /* Save government mode attributes */
801 if ($this->governmentmode){
802 foreach ($this->govattrs as $val){
803 if ($this->acl_is_writeable($val,(!is_object($this->parent) && !session::is_set('edit'))) && isset($_POST["$val"])){
804 $data= stripcslashes($_POST["$val"]);
805 if ($data != $this->$val){
806 $this->is_modified= TRUE;
807 }
808 $this->$val= $data;
809 }
810 }
811 }
813 /* In template mode, the uid is autogenerated... */
814 if ($this->is_template){
815 $this->uid= strtolower($this->sn);
816 $this->givenName= $this->sn;
817 }
819 /* Save base and pw_storage, since these are no LDAP attributes */
820 if (isset($_POST['base'])){
822 $tmp = $this->get_allowed_bases();
823 if(isset($tmp[$_POST['base']])){
824 $base= validate($_POST['base']);
825 if ($base != $this->base){
826 $this->is_modified= TRUE;
827 }
828 $this->base= $base;
829 }else{
830 $this->base = $base_tmp;
831 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
832 }
833 }
835 /* Get pw_storage mode */
836 if (isset($_POST['pw_storage'])){
837 foreach(array("pw_storage") as $val){
838 if(isset($_POST[$val])){
839 $data= validate($_POST[$val]);
840 if ($data != $this->$val){
841 $this->is_modified= TRUE;
842 }
843 $this->$val= $data;
844 }
845 }
846 }
848 if($this->pw_storage != $this->last_pw_storage && isset($_POST['pw_storage'])){
849 if ($this->acl_is_writeable("userPassword")){
850 $temp= passwordMethod::get_available_methods();
851 if (!is_object($this->pwObject) || !($this->pwObject instanceOf $temp[$this->pw_storage])){
852 foreach($temp as $id => $data){
853 if(isset($data['name']) && $data['name'] == $this->pw_storage && $data['is_configurable']){
854 $this->pwObject= new $temp[$this->pw_storage]($this->config,$this->dn);
855 break;
856 }
857 }
858 }
859 }
860 }
862 /* Save current cn
863 */
864 $this->cn = $this->givenName." ".$this->sn;
865 }
866 }
868 function rebind($ldap, $referral)
869 {
870 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
871 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
872 $this->error = "Success";
873 $this->hascon=true;
874 $this->reconnect= true;
875 return (0);
876 } else {
877 $this->error = "Could not bind to " . $credentials['ADMIN'];
878 return NULL;
879 }
880 }
883 /* Save data to LDAP, depending on is_account we save or delete */
884 function save()
885 {
886 /* Only force save of changes ....
887 If this attributes aren't changed, avoid saving.
888 */
890 if($this->gender=="0") $this->gender ="";
891 if($this->preferredLanguage=="0") $this->preferredLanguage ="";
893 /* First use parents methods to do some basic fillup in $this->attrs */
894 plugin::save ();
896 if ($this->use_dob == "1"){
897 /* If it is an array, the generic page has never been loaded - so there's no difference. Using an array would cause an error btw. */
898 if(!is_array($this->attrs['dateOfBirth'])) {
899 $this->attrs['dateOfBirth'] = date("Y-m-d", $this->dateOfBirth);
900 }
901 }
903 /* Remove additional objectClasses */
904 $tmp= array();
905 foreach ($this->attrs['objectClass'] as $key => $set){
906 $found= false;
907 foreach (array("ivbbentry", "gosaUserTemplate") as $val){
908 if (preg_match ("/^$set$/i", $val)){
909 $found= true;
910 break;
911 }
912 }
913 if (!$found){
914 $tmp[]= $set;
915 }
916 }
918 /* Replace the objectClass array. This is done because of the
919 separation into government and normal mode. */
920 $this->attrs['objectClass']= $tmp;
922 /* Add objectClasss for template mode? */
923 if ($this->is_template){
924 $this->attrs['objectClass'][]= "gosaUserTemplate";
925 }
927 /* Hard coded government mode? */
928 if ($this->governmentmode){
929 $this->attrs['objectClass'][]= "ivbbentry";
931 /* Copy standard attributes */
932 foreach ($this->govattrs as $val){
933 if ($this->$val != ""){
934 $this->attrs["$val"]= $this->$val;
935 } elseif (!$this->is_new) {
936 $this->attrs["$val"]= array();
937 }
938 }
940 /* Remove attribute if set to "nein" */
941 if ($this->publicVisible == "nein"){
942 $this->attrs['publicVisible']= array();
943 if($this->is_new){
944 unset($this->attrs['publicVisible']);
945 }else{
946 $this->attrs['publicVisible']=array();
947 }
949 }
951 }
953 /* Special handling for attribute userCertificate needed */
954 if ($this->userCertificate != ""){
955 $this->attrs["userCertificate;binary"]= $this->userCertificate;
956 $remove_userCertificate= false;
957 } else {
958 $remove_userCertificate= true;
959 }
961 /* Special handling for dateOfBirth value */
962 if ($this->use_dob != "1"){
963 if ($this->is_new) {
964 unset($this->attrs["dateOfBirth"]);
965 } else {
966 $this->attrs["dateOfBirth"]= array();
967 }
968 }
969 if (!$this->gender){
970 if ($this->is_new) {
971 unset($this->attrs["gender"]);
972 } else {
973 $this->attrs["gender"]= array();
974 }
975 }
976 if (!$this->preferredLanguage){
977 if ($this->is_new) {
978 unset($this->attrs["preferredLanguage"]);
979 } else {
980 $this->attrs["preferredLanguage"]= array();
981 }
982 }
984 /* Special handling for attribute jpegPhote needed, scale image via
985 image magick to 147x200 pixels and inject resulting data. */
986 if ($this->jpegPhoto == "*removed*"){
988 /* Reset attribute to avoid writing *removed* as value */
989 $this->attrs["jpegPhoto"] = array();
991 } else {
993 /* Fallback if there's no image magick inside PHP */
994 if (!function_exists("imagick_blob2image")){
995 /* Get temporary file name for conversation */
996 $fname = tempnam (TEMP_DIR, "GOsa");
998 /* Open file and write out photoData */
999 $fp = fopen ($fname, "w");
1000 fwrite ($fp, $this->photoData);
1001 fclose ($fp);
1003 /* Build conversation query. Filename is generated automatically, so
1004 we do not need any special security checks. Exec command and save
1005 output. For PHP safe mode, you'll need a configuration which respects
1006 image magick as executable... */
1007 $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
1008 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
1009 $query, "Execute");
1011 /* Read data written by convert */
1012 $output= "";
1013 $sh= popen($query, 'r');
1014 while (!feof($sh)){
1015 $output.= fread($sh, 4096);
1016 }
1017 pclose($sh);
1019 unlink($fname);
1021 /* Save attribute */
1022 $this->attrs["jpegPhoto"] = $output;
1024 } else {
1026 /* Load the new uploaded Photo */
1027 if(!$handle = imagick_blob2image($this->photoData)) {
1028 new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
1029 }
1031 /* Resizing image to 147x200 and blur */
1032 if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
1033 new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
1034 }
1036 /* Converting image to JPEG */
1037 if(!imagick_convert($handle,"JPEG")) {
1038 new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
1039 }
1041 /* Creating binary Code for the Image */
1042 if(!$dump = imagick_image2blob($handle)){
1043 new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
1044 }
1046 /* Sending Image */
1047 $output= $dump;
1049 /* Save attribute */
1050 $this->attrs["jpegPhoto"] = $output;
1051 }
1053 }
1055 /* This only gets called when user is renaming himself */
1056 $ldap= $this->config->get_ldap_link();
1057 if ($this->dn != $this->new_dn){
1059 /* Write entry on new 'dn' */
1060 $this->update_acls($this->dn,$this->new_dn);
1061 $this->move($this->dn, $this->new_dn);
1063 /* Happen to use the new one */
1064 change_ui_dn($this->dn, $this->new_dn);
1065 $this->dn= $this->new_dn;
1066 }
1069 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1070 new entries. So do a check first... */
1071 $ldap->cat ($this->dn, array('dn'));
1072 if ($ldap->fetch()){
1073 $mode= "modify";
1074 } else {
1075 $mode= "add";
1076 $ldap->cd($this->config->current['BASE']);
1077 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1078 }
1080 /* Set password to some junk stuff in case of templates */
1081 if ($this->is_template){
1082 $temp= passwordMethod::get_available_methods();
1083 foreach($temp as $id => $data){
1084 if(isset($data['name']) && $data['name'] == $this->pw_storage){
1085 $tmp = new $temp[$this->pw_storage]($this->config,$this->dn);
1086 $tmp->set_hash($this->pw_storage);
1087 $this->attrs['userPassword'] = $tmp->create_template_hash($this->attrs);
1088 break;
1089 }
1090 }
1091 }
1093 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1094 $this->attributes, "Save via $mode");
1096 /* Finally write data with selected 'mode' */
1097 $this->cleanup();
1099 /* Update current locale settings, if we have edited ourselves */
1100 $ui = session::get('ui');
1101 if(isset($this->attrs['preferredLanguage']) && $this->dn == $ui->dn){
1102 $ui->language = $this->preferredLanguage;
1103 session::set('ui',$ui);
1104 session::set('Last_init_lang',"update");
1105 }
1107 $ldap->cd ($this->dn);
1108 $ldap->$mode ($this->attrs);
1109 if (!$ldap->success()){
1110 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
1111 return (1);
1112 }
1114 /* Remove ACL dependencies too */
1115 if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1116 $tmp = new acl($this->config,$this->parent,$this->dn);
1117 $tmp->update_acl_membership($this->orig_dn,$this->dn);
1118 }
1120 if($mode == "modify"){
1121 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1122 }else{
1123 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1124 }
1126 /* Remove cert?
1127 For some reason, the 'ldap' class doesn't want to remove binary entries, so I need
1128 to work around myself. */
1129 if ($remove_userCertificate == true && !$this->is_new && $this->had_userCertificate){
1131 /* Reset array, assemble new, this should be reworked */
1132 $this->attrs= array();
1133 $this->attrs['userCertificate;binary']= array();
1135 /* Prepare connection */
1136 if (!($ds = ldap_connect($this->config->current['SERVER']))) {
1137 die ("Could not connect to LDAP server");
1138 }
1139 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1140 if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("ldapFollowReferrals") == "true") {
1141 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1142 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1143 }
1144 if($this->config->get_cfg_value("ldapTLS") == "true"){
1145 ldap_start_tls($ds);
1146 }
1147 if (!($res = @ldap_bind($ds, $this->config->current['ADMIN'],
1148 $this->config->current['PASSWORD']))) {
1149 die ("Could not bind to LDAP");
1150 }
1152 /* Modify using attrs */
1153 ldap_mod_del($ds,$this->dn,$this->attrs);
1154 ldap_close($ds);
1155 }
1157 /* If needed, let the password method do some cleanup */
1158 if ($this->pw_storage != $this->last_pw_storage){
1159 $tmp = new passwordMethod($this->config);
1160 $available = $tmp->get_available_methods();
1161 if (in_array_ics($this->last_pw_storage, $available['name'])){
1162 $test= new $available[$this->last_pw_storage]($this->config,$this->dn);
1163 $test->attrs= $this->attrs;
1164 $test->remove_from_parent();
1165 }
1166 }
1168 /* Maybe the current password method want's to do some changes... */
1169 if (is_object($this->pwObject)){
1170 $this->pwObject->save($this->dn);
1171 }
1173 /* Optionally execute a command after we're done */
1174 if ($mode == "add"){
1175 $this->handle_post_events("add", array("uid" => $this->uid));
1176 } elseif ($this->is_modified){
1177 $this->handle_post_events("modify", array("uid" => $this->uid));
1178 }
1180 return (0);
1181 }
1184 function create_initial_rdn($pattern)
1185 {
1186 // Only generate single RDNs
1187 if (preg_match('/\+/', $pattern)){
1188 msg_dialog::display(_("Error"), _("Cannot build RDN: no + allowed to build sub RDN!"), ERROR_DIALOG);
1189 return "";
1190 }
1192 // Extract attribute
1193 $attribute= preg_replace('/=.*$/', '', $pattern);
1194 if (!in_array_ics($attribute, $this->attributes)) {
1195 msg_dialog::display(_("Error"), _("Cannot build RDN: attribute is not defined!"), ERROR_DIALOG);
1196 return "";
1197 }
1199 // Sort attributes for length
1200 $attrl= array();
1201 foreach ($this->attributes as $attr) {
1202 $attrl[$attr]= strlen($attr);
1203 }
1204 arsort($attrl);
1206 // Walk thru sorted attributes and replace them in pattern
1207 foreach ($attrl as $attr => $dummy) {
1208 if (!is_array($this->$attr)){
1209 $pattern= preg_replace("/%$attr/", $this->$attr, $pattern);
1210 } else {
1211 msg_dialog::display(_("Error"), _("Cannot build RDN: invalid attribute parameters!"), ERROR_DIALOG);
1212 break;
1213 }
1214 }
1216 // Internally assign value
1217 $this->$attribute= preg_replace('/^[^=]+=/', '', $pattern);
1219 return $pattern;
1220 }
1223 function update_new_dn()
1224 {
1225 // Alternative way to handle DN
1226 $pattern= $this->config->get_cfg_value("accountRDN");
1227 if ($pattern != "") {
1228 $rdn= $this->create_initial_rdn($pattern);
1229 $attribute= preg_replace('/=.*$/', '', $rdn);
1230 $value= preg_replace('/^[^=]+=$/', '', $rdn);
1232 /* Don't touch dn, if $attribute hasn't changed */
1233 if (isset($this->saved_attributes[$attribute]) && $this->saved_attributes[$attribute] == $this->$attribute &&
1234 $this->orig_base == $this->base ){
1235 $this->new_dn= $this->dn;
1236 } else {
1237 $this->new_dn= $this->create_unique_dn2($rdn, get_people_ou().$this->base);
1238 }
1240 // Original way to handle DN
1241 } else {
1243 $pt= "";
1244 if($this->config->get_cfg_value("personalTitleInDN") == "true"){
1245 if(!empty($this->personalTitle)){
1246 $pt = $this->personalTitle." ";
1247 }
1248 }
1250 $this->cn= $pt.$this->givenName." ".$this->sn;
1252 /* Permissions for that base? */
1253 if ($this->config->get_cfg_value("accountPrimaryAttribute") == "uid"){
1254 $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
1255 } else {
1256 /* Don't touch dn, if cn hasn't changed */
1257 if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
1258 $this->orig_base == $this->base ){
1259 $this->new_dn= $this->dn;
1260 } else {
1261 $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
1262 }
1263 }
1264 }
1265 }
1268 /* Check formular input */
1269 function check()
1270 {
1271 /* Call common method to give check the hook */
1272 $message= plugin::check();
1274 /* Configurable password methods should be configured initially.
1275 */
1276 if($this->last_pw_storage != $this->pw_storage){
1277 $temp= passwordMethod::get_available_methods();
1278 foreach($temp['name'] as $id => $name){
1279 if($name == $this->pw_storage){
1280 if($temp['is_configurable'][$id] && !$this->pwObject instanceof $temp[$name] ){
1281 $message[] = _("The selected password method requires initial configuration!");
1282 }
1283 break;
1284 }
1285 }
1286 }
1288 $this->update_new_dn();
1290 /* Set the new acl base */
1291 if($this->dn == "new") {
1292 $this->set_acl_base($this->base);
1293 }
1295 /* Check if we are allowed to create/move this user
1296 */
1298 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1299 $message[]= msgPool::permCreate();
1300 }elseif($this->orig_dn != "new" && $this->new_dn != $this->orig_dn && !$this->acl_is_moveable($this->base)){
1301 $message[]= msgPool::permMove();
1302 }
1304 /* UID already used? */
1305 $ldap= $this->config->get_ldap_link();
1306 $ldap->cd($this->config->current['BASE']);
1307 $ldap->search("(uid=$this->uid)", array("uid"));
1308 $ldap->fetch();
1309 if ($ldap->count() != 0 && $this->dn == 'new'){
1310 $message[]= msgPool::duplicated(_("Login"));
1311 }
1313 /* In template mode, the uid and givenName are autogenerated... */
1314 if ($this->sn == ""){
1315 $message[]= msgPool::required(_("Name"));
1316 }
1318 if (!$this->is_template){
1319 if ($this->givenName == ""){
1320 $message[]= msgPool::required(_("Given name"));
1321 }
1322 if ($this->uid == ""){
1323 $message[]= msgPool::required(_("Login"));
1324 }
1325 if ($this->config->get_cfg_value("accountPrimaryAttribute") != "uid"){
1326 $ldap->cat($this->new_dn);
1327 if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
1328 $message[]= msgPool::duplicated(_("Name"));
1329 }
1330 }
1331 }
1333 /* Check for valid input */
1334 if ($this->is_modified && !tests::is_uid($this->uid)){
1336 if (strict_uid_mode()){
1337 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/");
1338 } else {
1339 $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i");
1340 }
1341 }
1342 if (!tests::is_url($this->labeledURI)){
1343 $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.your-domain.com/yourname");
1344 }
1346 /* Check phone numbers */
1347 if (!tests::is_phone_nr($this->telephoneNumber)){
1348 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1349 }
1350 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
1351 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1352 }
1353 if (!tests::is_phone_nr($this->mobile)){
1354 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1355 }
1356 if (!tests::is_phone_nr($this->pager)){
1357 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1358 }
1360 /* Check for reserved characers */
1361 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){
1362 $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/');
1363 }
1364 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){
1365 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1366 }
1368 return $message;
1369 }
1372 /* Indicate whether a password change is needed or not */
1373 function password_change_needed()
1374 {
1375 if(in_array("pw_storage",$this->multi_boxes)){
1376 return(TRUE);
1377 }
1378 return($this->pw_storage != $this->last_pw_storage && !$this->is_template);
1379 }
1382 /* Load a jpegPhoto from LDAP, this is going to be simplified later on */
1383 function load_picture()
1384 {
1385 $ldap = $this->config->get_ldap_link();
1386 $ldap->cd ($this->dn);
1387 $data = $ldap->get_attribute($this->dn,"jpegPhoto");
1389 if((!$data) || ($data == "*removed*")){
1391 /* In case we don't get an entry, load a default picture */
1392 $this->set_picture ();
1393 $this->jpegPhoto= "*removed*";
1394 }else{
1396 /* Set picture */
1397 $this->photoData= $data;
1398 session::set('binary',$this->photoData);
1399 session::set('binarytype',"image/jpeg");
1400 $this->jpegPhoto= "";
1401 }
1402 }
1405 /* Load a certificate from LDAP, this is going to be simplified later on */
1406 function load_cert()
1407 {
1408 $ds= ldap_connect($this->config->current['SERVER']);
1409 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
1410 if (function_exists("ldap_set_rebind_proc") && $this->config->get_cfg_value("ldapFollowReferrals") == "true"){
1411 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
1412 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
1413 }
1414 if ($this->config->get_cfg_value("ldapTLS") == "true"){
1415 ldap_start_tls($ds);
1416 }
1418 $r= ldap_bind($ds);
1419 $sr= @ldap_read($ds, $this->dn, "userCertificate=*", array("userCertificate"));
1421 if ($sr) {
1422 $ei= @ldap_first_entry($ds, $sr);
1424 if ($ei) {
1425 if (!$info = @ldap_get_values_len($ds, $ei, "userCertificate;binary")){
1426 $this->userCertificate= "";
1427 } else {
1428 $this->userCertificate= $info[0];
1429 }
1430 }
1431 } else {
1432 $this->userCertificate= "";
1433 }
1435 ldap_unbind($ds);
1436 }
1439 /* Load picture from file to object */
1440 function set_picture($filename ="")
1441 {
1442 if (!is_file($filename) || $filename =="" ){
1443 $filename= "./plugins/users/images/default.jpg";
1444 $this->jpegPhoto= "*removed*";
1445 }
1447 $fd = fopen ($filename, "rb");
1448 $this->photoData= fread ($fd, filesize ($filename));
1449 session::set('binary',$this->photoData);
1450 session::set('binarytype',"image/jpeg");
1451 $this->jpegPhoto= "";
1453 fclose ($fd);
1454 }
1457 /* Load certificate from file to object */
1458 function set_cert($cert, $filename)
1459 {
1460 if(!$this->acl_is_writeable("Certificate",(!is_object($this->parent) && !session::is_set('edit')))) return;
1461 $fd = fopen ($filename, "rb");
1462 if (filesize($filename)>0) {
1463 $this->$cert= fread ($fd, filesize ($filename));
1464 fclose ($fd);
1465 $this->is_modified= TRUE;
1466 } else {
1467 msg_dialog::display(_("Error"), _("Cannot open certificate!"), ERROR_DIALOG);
1468 }
1469 }
1471 /* Adapt from given 'dn' */
1472 function adapt_from_template($dn, $skip= array())
1473 {
1474 plugin::adapt_from_template($dn, $skip);
1476 /* Get password method from template
1477 */
1478 $tmp= passwordMethod::get_method($this->attrs['userPassword'][0]);
1479 if(is_object($tmp)){
1480 if($tmp->is_configurable()){
1481 $tmp->adapt_from_template($dn);
1482 $this->pwObject = &$tmp;
1483 }
1484 $this->pw_storage= $tmp->get_hash();
1485 }
1487 /* Get base */
1488 $this->base= preg_replace('/^[^,]+,'.get_people_ou().'/i', '', $dn);
1490 if($this->governmentmode){
1492 /* Walk through govattrs */
1493 foreach ($this->govattrs as $val){
1495 if (in_array($val, $skip)){
1496 continue;
1497 }
1499 if (isset($this->attrs["$val"][0])){
1501 /* If attribute is set, replace dynamic parts:
1502 %sn, %givenName and %uid. Fill these in our local variables. */
1503 $value= $this->attrs["$val"][0];
1505 foreach (array("sn", "givenName", "uid") as $repl){
1506 if (preg_match("/%$repl/i", $value)){
1507 $value= preg_replace ("/%$repl/i",
1508 $this->parent->$repl, $value);
1509 }
1510 }
1511 $this->$val= $value;
1512 }
1513 }
1514 }
1516 /* Get back uid/sn/givenName - only write if nothing's skipped */
1517 if ($this->parent !== NULL && count($skip) == 0){
1518 $this->uid= $this->parent->uid;
1519 $this->sn= $this->parent->sn;
1520 $this->givenName= $this->parent->givenName;
1521 }
1522 }
1525 /* This avoids that users move themselves out of their rights.
1526 */
1527 function allowedBasesToMoveTo()
1528 {
1529 /* Get bases */
1530 $bases = $this->get_allowed_bases();
1531 return($bases);
1532 }
1535 function getCopyDialog()
1536 {
1537 $str = "";
1539 session::set('binary',$this->photoData);
1540 session::set('binarytype',"image/jpeg");
1542 /* Get random number for pictures */
1543 srand((double)microtime()*1000000);
1544 $rand = rand(0, 10000);
1546 $smarty = get_smarty();
1548 $smarty->assign("passwordTodo","clear");
1550 if(isset($_POST['passwordTodo'])){
1551 $smarty->assign("passwordTodo",$_POST['passwordTodo']);
1552 }
1554 $smarty->assign("sn", $this->sn);
1555 $smarty->assign("givenName",$this->givenName);
1556 $smarty->assign("uid", $this->uid);
1557 $smarty->assign("rand", $rand);
1558 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1561 $ret = array();
1562 $ret['string'] = $str;
1563 $ret['status'] = "";
1564 return($ret);
1565 }
1567 function saveCopyDialog()
1568 {
1569 /* Set_acl_base */
1570 $this->set_acl_base($this->base);
1572 if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
1573 $this->set_picture($_FILES['picture_file']['tmp_name']);
1574 }
1576 /* Remove picture? */
1577 if (isset($_POST['picture_remove'])){
1578 $this->jpegPhoto= "*removed*";
1579 $this->set_picture ("./plugins/users/images/default.jpg");
1580 $this->is_modified= TRUE;
1581 }
1583 $attrs = array("uid","givenName","sn");
1584 foreach($attrs as $attr){
1585 if(isset($_POST[$attr])){
1586 $this->$attr = $_POST[$attr];
1587 }
1588 }
1589 }
1592 function PrepareForCopyPaste($source)
1593 {
1594 plugin::PrepareForCopyPaste($source);
1596 /* Reset certificate information addepted from source user
1597 to avoid setting the same user certificate for the destination user. */
1598 $this->userPKCS12= "";
1599 $this->userSMIMECertificate= "";
1600 $this->userCertificate= "";
1601 $this->certificateSerialNumber= "";
1602 $this->old_certificateSerialNumber= "";
1603 $this->old_userPKCS12= "";
1604 $this->old_userSMIMECertificate= "";
1605 $this->old_userCertificate= "";
1606 }
1609 static function plInfo()
1610 {
1612 $govattrs= array(
1613 "gouvernmentOrganizationalUnit" => _("Unit"),
1614 "houseIdentifier" => _("House identifier"),
1615 "vocation" => _("Vocation"),
1616 "ivbbLastDeliveryCollective" => _("Last delivery"),
1617 "gouvernmentOrganizationalPersonLocality" => _("Person locality"),
1618 "gouvernmentOrganizationalUnitDescription" => _("Unit description"),
1619 "gouvernmentOrganizationalUnitSubjectArea" => _("Subject area"),
1620 "functionalTitle" => _("Functional title"),
1621 "certificateSerialNumber" => _("Certificate serial number"),
1622 "publicVisible" => _("Public visible"),
1623 "street" => _("Street"),
1624 "role" => _("Role"),
1625 "postalCode" => _("Postal code"));
1627 $ret = array(
1628 "plShortName" => _("Generic"),
1629 "plDescription" => _("Generic user settings"),
1630 "plSelfModify" => TRUE,
1631 "plDepends" => array(),
1632 "plPriority" => 1,
1633 "plSection" => array("personal" => _("My account")),
1634 "plCategory" => array("users" => array("description" => _("Users"),
1635 "objectClass" => "gosaAccount")),
1637 "plProvidedAcls" => array(
1639 "sn" => _("Surname"),
1640 "givenName" => _("Given name"),
1641 "uid" => _("User identification"),
1642 "personalTitle" => _("Personal title"),
1643 "academicTitle" => _("Academic title"),
1645 "dateOfBirth" => _("Date of birth"),
1646 "gender" => _("Gender"),
1647 "preferredLanguage" => _("Preferred language"),
1648 "base" => _("Base"),
1650 "userPicture" => _("User picture"),
1652 "o" => _("Organization"),
1653 "ou" => _("Department"),
1654 "departmentNumber" => _("Department number"),
1655 "employeeNumber" => _("Employee number"),
1656 "employeeType" => _("Employee type"),
1658 "roomNumber" => _("Room number"),
1659 "telephoneNumber" => _("Telefon number"),
1660 "pager" => _("Pager number"),
1661 "mobile" => _("Mobile number"),
1662 "facsimileTelephoneNumber" => _("Fax number"),
1664 "st" => _("State"),
1665 "l" => _("Location"),
1666 "postalAddress" => _("Postal address"),
1668 "homePostalAddress" => _("Home postal address"),
1669 "homePhone" => _("Home phone number"),
1670 "labeledURI" => _("Homepage"),
1671 "userPassword" => _("User password method"),
1672 "Certificate" => _("User certificates"))
1674 );
1676 /* Append government attributes if required */
1677 global $config;
1678 if($config->get_cfg_value("honourIvbbAttributes") == "true"){
1679 foreach($govattrs as $attr => $desc){
1680 $ret["plProvidedAcls"][$attr] = $desc;
1681 }
1682 }
1683 return($ret);
1684 }
1686 function get_multi_edit_values()
1687 {
1688 $ret = plugin::get_multi_edit_values();
1689 if(in_array("pw_storage",$this->multi_boxes)){
1690 $ret['pw_storage'] = $this->pw_storage;
1691 }
1692 if(in_array("edit_picture",$this->multi_boxes)){
1693 $ret['jpegPhoto'] = $this->jpegPhoto;
1694 $ret['photoData'] = $this->photoData;
1695 $ret['old_jpegPhoto'] = $this->old_jpegPhoto;
1696 $ret['old_photoData'] = $this->old_photoData;
1697 }
1698 if(isset($ret['dateOfBirth'])){
1699 unset($ret['dateOfBirth']);
1700 }
1701 if(isset($ret['cn'])){
1702 unset($ret['cn']);
1703 }
1704 $ret['is_modified'] = $this->is_modified;
1705 if(in_array("base",$this->multi_boxes)){
1706 $ret['orig_base']="Changed_by_Multi_Plug";
1707 $ret['base']=$this->base;
1708 }
1709 return($ret);
1710 }
1713 function multiple_save_object()
1714 {
1715 plugin::multiple_save_object();
1717 /* Get pw_storage mode */
1718 if (isset($_POST['pw_storage'])){
1719 foreach(array("pw_storage") as $val){
1720 if(isset($_POST[$val])){
1721 $data= validate(get_post($val));
1722 if ($data != $this->$val){
1723 $this->is_modified= TRUE;
1724 }
1725 $this->$val= $data;
1726 }
1727 }
1728 }
1729 if(isset($_POST['base'])){
1730 $this->base = get_post('base');
1731 }
1733 if(isset($_POST['user_mulitple_edit'])){
1734 foreach(array("base","pw_storage","edit_picture") as $val){
1735 if(isset($_POST["use_".$val])){
1736 $this->multi_boxes[] = $val;
1737 }
1738 }
1739 }
1740 }
1743 function multiple_check()
1744 {
1745 /* Call check() to set new_dn correctly ... */
1746 $message = plugin::multiple_check();
1748 /* Set the new acl base */
1749 if($this->dn == "new") {
1750 $this->set_acl_base($this->base);
1751 }
1752 if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){
1753 $message[]= msgPool::invalid(_("Homepage"));
1754 }
1755 if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){
1756 $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
1757 }
1758 if (!tests::is_phone_nr($this->facsimileTelephoneNumber) && in_array("facsimileTelephoneNumber",$this->multi_boxes)){
1759 $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
1760 }
1761 if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){
1762 $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/");
1763 }
1764 if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){
1765 $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/");
1766 }
1767 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){
1768 $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/');
1769 }
1770 if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){
1771 $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/');
1772 }
1773 return($message);
1774 }
1778 function multiple_execute()
1779 {
1780 return($this->execute());
1781 }
1784 }
1786 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1787 ?>