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