1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 /*! \brief The plugin base class
22 \author Cajus Pollmeier <pollmeier@gonicus.de>
23 \version 2.00
24 \date 24.07.2003
26 This is the base class for all plugins. It can be used standalone or
27 can be included by the tabs class. All management should be done
28 within this class. Extend your plugins from this class.
29 */
31 class plugin
32 {
33 /*!
34 \brief Reference to parent object
36 This variable is used when the plugin is included in tabs
37 and keeps reference to the tab class. Communication to other
38 tabs is possible by 'name'. So the 'fax' plugin can ask the
39 'userinfo' plugin for the fax number.
41 \sa tab
42 */
43 var $parent= NULL;
45 /*!
46 \brief Configuration container
48 Access to global configuration
49 */
50 var $config= NULL;
52 /*!
53 \brief Mark plugin as account
55 Defines whether this plugin is defined as an account or not.
56 This has consequences for the plugin to be saved from tab
57 mode. If it is set to 'FALSE' the tab will call the delete
58 function, else the save function. Should be set to 'TRUE' if
59 the construtor detects a valid LDAP object.
61 \sa plugin::plugin()
62 */
63 var $is_account= FALSE;
64 var $initially_was_account= FALSE;
66 /*!
67 \brief Mark plugin as template
69 Defines whether we are creating a template or a normal object.
70 Has conseqences on the way execute() shows the formular and how
71 save() puts the data to LDAP.
73 \sa plugin::save() plugin::execute()
74 */
75 var $is_template= FALSE;
76 var $ignore_account= FALSE;
77 var $is_modified= FALSE;
79 /*!
80 \brief Represent temporary LDAP data
82 This is only used internally.
83 */
84 var $attrs= array();
86 /* Keep set of conflicting plugins */
87 var $conflicts= array();
89 /* Save unit tags */
90 var $gosaUnitTag= "";
92 /*!
93 \brief Used standard values
95 dn
96 */
97 var $dn= "";
98 var $uid= "";
99 var $sn= "";
100 var $givenName= "";
101 var $acl= "*none*";
102 var $dialog= FALSE;
103 var $snapDialog = NULL;
105 /* attribute list for save action */
106 var $attributes= array();
107 var $objectclasses= array();
108 var $is_new= TRUE;
109 var $saved_attributes= array();
111 var $acl_base= "";
112 var $acl_category= "";
114 /* Plugin identifier */
115 var $plHeadline= "";
116 var $plDescription= "";
118 /* This can be set to render the tabulators in another stylesheet */
119 var $pl_notify= FALSE;
121 /* Object entry CSN */
122 var $entryCSN = "";
123 var $CSN_check_active = FALSE;
125 /* This variable indicates that this class can handle multiple dns at once. */
126 var $multiple_support = FALSE;
128 /* This aviable indicates, that we are currently in multiple edit handle */
129 var $multiple_support_active = FALSE;
130 var $selected_edit_values = array();
132 /*! \brief plugin constructor
134 If 'dn' is set, the node loads the given 'dn' from LDAP
136 \param dn Distinguished name to initialize plugin from
137 \sa plugin()
138 */
139 function plugin (&$config, $dn= NULL, $parent= NULL)
140 {
141 /* Configuration is fine, allways */
142 $this->config= &$config;
143 $this->dn= $dn;
145 /* Handle new accounts, don't read information from LDAP */
146 if ($dn == "new"){
147 return;
148 }
150 /* Save current dn as acl_base */
151 $this->acl_base= $dn;
153 /* Get LDAP descriptor */
154 $ldap= $this->config->get_ldap_link();
155 if ($dn !== NULL){
157 /* Load data to 'attrs' and save 'dn' */
158 if ($parent !== NULL){
159 $this->attrs= $parent->attrs;
160 } else {
161 $ldap->cat ($dn);
162 $this->attrs= $ldap->fetch();
163 }
165 /* Copy needed attributes */
166 foreach ($this->attributes as $val){
167 $found= array_key_ics($val, $this->attrs);
168 if ($found != ""){
169 $this->$val= $this->attrs["$found"][0];
170 }
171 }
173 /* gosaUnitTag loading... */
174 if (isset($this->attrs['gosaUnitTag'][0])){
175 $this->gosaUnitTag= $this->attrs['gosaUnitTag'][0];
176 }
178 /* Set the template flag according to the existence of objectClass
179 gosaUserTemplate */
180 if (isset($this->attrs['objectClass'])){
181 if (in_array ("gosaUserTemplate", $this->attrs['objectClass'])){
182 $this->is_template= TRUE;
183 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
184 "found", "Template check");
185 }
186 }
188 /* Is Account? */
189 $found= TRUE;
190 foreach ($this->objectclasses as $obj){
191 if (preg_match('/top/i', $obj)){
192 continue;
193 }
194 if (!isset($this->attrs['objectClass']) || !in_array_ics ($obj, $this->attrs['objectClass'])){
195 $found= FALSE;
196 break;
197 }
198 }
199 if ($found){
200 $this->is_account= TRUE;
201 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
202 "found", "Object check");
203 }
205 /* Prepare saved attributes */
206 $this->saved_attributes= $this->attrs;
207 foreach ($this->saved_attributes as $index => $value){
208 if (preg_match('/^[0-9]+$/', $index)){
209 unset($this->saved_attributes[$index]);
210 continue;
211 }
212 if (!in_array($index, $this->attributes) && $index != "objectClass"){
213 unset($this->saved_attributes[$index]);
214 continue;
215 }
216 if ($this->saved_attributes[$index]["count"] == 1){
217 $tmp= $this->saved_attributes[$index][0];
218 unset($this->saved_attributes[$index]);
219 $this->saved_attributes[$index]= $tmp;
220 continue;
221 }
223 unset($this->saved_attributes["$index"]["count"]);
224 }
225 }
227 /* Save initial account state */
228 $this->initially_was_account= $this->is_account;
229 }
231 /*! \brief execute plugin
233 Generates the html output for this node
234 */
235 function execute()
236 {
237 /* This one is empty currently. Fabian - please fill in the docu code */
238 $_SESSION['current_class_for_help'] = get_class($this);
240 /* Reset Lock message POST/GET check array, to prevent perg_match errors*/
241 $_SESSION['LOCK_VARS_TO_USE'] = $_SESSION['LOCK_VARS_USED'] =array();
242 }
244 /*! \brief execute plugin
245 Removes object from parent
246 */
247 function remove_from_parent()
248 {
249 /* include global link_info */
250 $ldap= $this->config->get_ldap_link();
252 /* Get current objectClasses in order to add the required ones */
253 $ldap->cat($this->dn);
254 $tmp= $ldap->fetch ();
255 $oc= array();
256 if (isset($tmp['objectClass'])){
257 $oc= $tmp['objectClass'];
258 unset($oc['count']);
259 }
261 /* Remove objectClasses from entry */
262 $ldap->cd($this->dn);
263 $this->attrs= array();
264 $this->attrs['objectClass']= array_remove_entries($this->objectclasses,$oc);
266 /* Unset attributes from entry */
267 foreach ($this->attributes as $val){
268 $this->attrs["$val"]= array();
269 }
271 /* Unset account info */
272 $this->is_account= FALSE;
274 /* Do not write in plugin base class, this must be done by
275 children, since there are normally additional attribs,
276 lists, etc. */
277 /*
278 $ldap->modify($this->attrs);
279 */
280 }
283 /* Save data to object */
284 function save_object()
285 {
286 /* Update entry CSN if it is empty. */
287 if(empty($this->entryCSN) && $this->CSN_check_active){
288 $this->entryCSN = getEntryCSN($this->dn);
289 }
291 if($this->multiple_support_active){
292 foreach($this->attributes as $attr){
293 if(isset($_POST["use_".$attr])){
294 $this->selected_edit_values[$attr] = TRUE;
295 }else{
296 $this->selected_edit_values[$attr] = FALSE;
297 }
298 }
299 }
301 /* Save values to object */
302 foreach ($this->attributes as $val){
303 if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){
304 /* Check for modifications */
305 if (get_magic_quotes_gpc()) {
306 $data= stripcslashes($_POST["$val"]);
307 } else {
308 $data= $this->$val = $_POST["$val"];
309 }
310 if ($this->$val != $data){
311 $this->is_modified= TRUE;
312 }
314 /* Okay, how can I explain this fix ...
315 * In firefox, disabled option fields aren't selectable ... but in IE you can select these fileds.
316 * So IE posts these 'unselectable' option, with value = chr(194)
317 * chr(194) seems to be the in between the ...option> </option.. because there is no value=".." specified in these option fields
318 * This was added for W3c compliance, but now causes these ... ldap errors ...
319 * So we set these Fields to ""; a normal empty string, and we can check these values in plugin::check() again ...
320 */
321 if(isset($data[0]) && $data[0] == chr(194)) {
322 $data = "";
323 }
324 $this->$val= $data;
325 //echo "<font color='blue'>".$val."</font><br>";
326 }else{
327 //echo "<font color='red'>".$val."</font><br>";
328 }
329 }
330 }
333 /* Save data to LDAP, depending on is_account we save or delete */
334 function save()
335 {
336 /* include global link_info */
337 $ldap= $this->config->get_ldap_link();
339 /* Save all plugins */
340 $this->entryCSN = "";
342 /* Start with empty array */
343 $this->attrs= array();
345 /* Get current objectClasses in order to add the required ones */
346 $ldap->cat($this->dn);
348 $tmp= $ldap->fetch ();
350 $oc= array();
351 if (isset($tmp['objectClass'])){
352 $oc= $tmp["objectClass"];
353 $this->is_new= FALSE;
354 unset($oc['count']);
355 } else {
356 $this->is_new= TRUE;
357 }
359 /* Load (minimum) attributes, add missing ones */
360 $this->attrs['objectClass']= gosa_array_merge($oc,$this->objectclasses);
362 /* Copy standard attributes */
363 foreach ($this->attributes as $val){
364 if ($this->$val != ""){
365 $this->attrs["$val"]= $this->$val;
366 } elseif (!$this->is_new) {
367 $this->attrs["$val"]= array();
368 }
369 }
371 }
374 function cleanup()
375 {
376 foreach ($this->attrs as $index => $value){
378 /* Convert arrays with one element to non arrays, if the saved
379 attributes are no array, too */
380 if (is_array($this->attrs[$index]) &&
381 count ($this->attrs[$index]) == 1 &&
382 isset($this->saved_attributes[$index]) &&
383 !is_array($this->saved_attributes[$index])){
385 $tmp= $this->attrs[$index][0];
386 $this->attrs[$index]= $tmp;
387 }
389 /* Remove emtpy arrays if they do not differ */
390 if (is_array($this->attrs[$index]) &&
391 count($this->attrs[$index]) == 0 &&
392 !isset($this->saved_attributes[$index])){
394 unset ($this->attrs[$index]);
395 continue;
396 }
398 /* Remove single attributes that do not differ */
399 if (!is_array($this->attrs[$index]) &&
400 isset($this->saved_attributes[$index]) &&
401 !is_array($this->saved_attributes[$index]) &&
402 $this->attrs[$index] == $this->saved_attributes[$index]){
404 unset ($this->attrs[$index]);
405 continue;
406 }
408 /* Remove arrays that do not differ */
409 if (is_array($this->attrs[$index]) &&
410 isset($this->saved_attributes[$index]) &&
411 is_array($this->saved_attributes[$index])){
413 if (!array_differs($this->attrs[$index],$this->saved_attributes[$index])){
414 unset ($this->attrs[$index]);
415 continue;
416 }
417 }
418 }
420 /* Update saved attributes and ensure that next cleanups will be successful too */
421 foreach($this->attrs as $name => $value){
422 $this->saved_attributes[$name] = $value;
423 }
424 }
426 /* Check formular input */
427 function check()
428 {
429 $message= array();
431 /* Skip if we've no config object */
432 if (!isset($this->config) || !is_object($this->config)){
433 return $message;
434 }
436 /* Find hooks entries for this class */
437 $command= $this->config->search(get_class($this), "CHECK", array('menu', 'tabs'));
439 if ($command != ""){
441 if (!check_command($command)){
442 $message[]= sprintf(_("Command '%s', specified as CHECK hook for plugin '%s' doesn't seem to exist."), $command,
443 get_class($this));
444 } else {
446 /* Generate "ldif" for check hook */
447 $ldif= "dn: $this->dn\n";
449 /* ... objectClasses */
450 foreach ($this->objectclasses as $oc){
451 $ldif.= "objectClass: $oc\n";
452 }
454 /* ... attributes */
455 foreach ($this->attributes as $attr){
456 if ($this->$attr == ""){
457 continue;
458 }
459 if (is_array($this->$attr)){
460 foreach ($this->$attr as $val){
461 $ldif.= "$attr: $val\n";
462 }
463 } else {
464 $ldif.= "$attr: ".$this->$attr."\n";
465 }
466 }
468 /* Append empty line */
469 $ldif.= "\n";
471 /* Feed "ldif" into hook and retrieve result*/
472 $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
473 $fh= proc_open($command, $descriptorspec, $pipes);
474 if (is_resource($fh)) {
475 fwrite ($pipes[0], $ldif);
476 fclose($pipes[0]);
478 $result= stream_get_contents($pipes[1]);
479 if ($result != ""){
480 $message[]= $result;
481 }
483 fclose($pipes[1]);
484 fclose($pipes[2]);
485 proc_close($fh);
486 }
487 }
489 }
491 /* Check entryCSN */
492 if($this->CSN_check_active){
493 $current_csn = getEntryCSN($this->dn);
494 if($current_csn != $this->entryCSN && !empty($this->entryCSN) && !empty($current_csn)){
495 $this->entryCSN = $current_csn;
496 $message[] = _("The object has changed since opened in GOsa. Please ensure that nobody has done serious changes that may get lost if you save this entry.");
497 }
498 }
499 return ($message);
500 }
502 /* Adapt from template, using 'dn' */
503 function adapt_from_template($dn)
504 {
505 /* Include global link_info */
506 $ldap= $this->config->get_ldap_link();
508 /* Load requested 'dn' to 'attrs' */
509 $ldap->cat ($dn);
510 $this->attrs= $ldap->fetch();
512 /* Walk through attributes */
513 foreach ($this->attributes as $val){
515 if (isset($this->attrs["$val"][0])){
517 /* If attribute is set, replace dynamic parts:
518 %sn, %givenName and %uid. Fill these in our local variables. */
519 $value= $this->attrs["$val"][0];
521 foreach (array("sn", "givenName", "uid") as $repl){
522 if (preg_match("/%$repl/i", $value)){
523 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
524 }
525 }
526 $this->$val= $value;
527 }
528 }
530 /* Is Account? */
531 $found= TRUE;
532 foreach ($this->objectclasses as $obj){
533 if (preg_match('/top/i', $obj)){
534 continue;
535 }
536 if (!in_array_ics ($obj, $this->attrs['objectClass'])){
537 $found= FALSE;
538 break;
539 }
540 }
541 if ($found){
542 $this->is_account= TRUE;
543 }
544 }
546 /* Indicate whether a password change is needed or not */
547 function password_change_needed()
548 {
549 return FALSE;
550 }
553 /* Show header message for tab dialogs */
554 function show_enable_header($button_text, $text, $disabled= FALSE)
555 {
556 if (($disabled == TRUE) || (!$this->acl_is_createable())){
557 $state= "disabled";
558 } else {
559 $state= "";
560 }
561 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
562 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".$state.
563 "><p class=\"seperator\"> </p></td></tr></table>";
565 return($display);
566 }
569 /* Show header message for tab dialogs */
570 function show_disable_header($button_text, $text, $disabled= FALSE)
571 {
572 if (($disabled == TRUE) || !$this->acl_is_removeable()){
573 $state= "disabled";
574 } else {
575 $state= "";
576 }
577 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
578 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".$state.
579 "><p class=\"seperator\"> </p></td></tr></table>";
581 return($display);
582 }
585 /* Show header message for tab dialogs */
586 function show_header($button_text, $text, $disabled= FALSE)
587 {
588 echo "FIXME: show_header should be replaced by show_disable_header and show_enable_header<br>";
589 if ($disabled == TRUE){
590 $state= "disabled";
591 } else {
592 $state= "";
593 }
594 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
595 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".
596 ($this->acl_is_createable()?'':'disabled')." ".$state.
597 "><p class=\"seperator\"> </p></td></tr></table>";
599 return($display);
600 }
603 function postcreate($add_attrs= array())
604 {
605 /* Find postcreate entries for this class */
606 $command= $this->config->search(get_class($this), "POSTCREATE",array('menu', 'tabs'));
608 if ($command != ""){
610 /* Additional attributes */
611 foreach ($add_attrs as $name => $value){
612 $command= preg_replace("/%$name/", $value, $command);
613 }
615 /* Walk through attribute list */
616 foreach ($this->attributes as $attr){
617 if (!is_array($this->$attr)){
618 $command= preg_replace("/%$attr/", $this->$attr, $command);
619 }
620 }
621 $command= preg_replace("/%dn/", $this->dn, $command);
623 if (check_command($command)){
624 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
625 $command, "Execute");
627 exec($command);
628 } else {
629 $message= sprintf(_("Command '%s', specified as POSTCREATE for plugin '%s' doesn't seem to exist."), $command, get_class($this));
630 print_red ($message);
631 }
632 }
633 }
635 function postmodify($add_attrs= array())
636 {
637 /* Find postcreate entries for this class */
638 $command= $this->config->search(get_class($this), "POSTMODIFY",array('menu','tabs'));
640 if ($command != ""){
642 /* Additional attributes */
643 foreach ($add_attrs as $name => $value){
644 $command= preg_replace("/%$name/", $value, $command);
645 }
647 /* Walk through attribute list */
648 foreach ($this->attributes as $attr){
649 if (!is_array($this->$attr)){
650 $command= preg_replace("/%$attr/", $this->$attr, $command);
651 }
652 }
653 $command= preg_replace("/%dn/", $this->dn, $command);
655 if (check_command($command)){
656 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
657 $command, "Execute");
659 exec($command);
660 } else {
661 $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, get_class($this));
662 print_red ($message);
663 }
664 }
665 }
667 function postremove($add_attrs= array())
668 {
669 /* Find postremove entries for this class */
670 $command= $this->config->search(get_class($this), "POSTREMOVE",array('menu','tabs'));
671 if ($command != ""){
673 /* Additional attributes */
674 foreach ($add_attrs as $name => $value){
675 $command= preg_replace("/%$name/", $value, $command);
676 }
678 /* Walk through attribute list */
679 foreach ($this->attributes as $attr){
680 if (!is_array($this->$attr)){
681 $command= preg_replace("/%$attr/", $this->$attr, $command);
682 }
683 }
684 $command= preg_replace("/%dn/", $this->dn, $command);
686 /* Additional attributes */
687 foreach ($add_attrs as $name => $value){
688 $command= preg_replace("/%$name/", $value, $command);
689 }
691 if (check_command($command)){
692 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
693 $command, "Execute");
695 exec($command);
696 } else {
697 $message= sprintf(_("Command '%s', specified as POSTREMOVE for plugin '%s' doesn't seem to exist."), $command, get_class($this));
698 print_red ($message);
699 }
700 }
701 }
703 /* Create unique DN */
704 function create_unique_dn($attribute, $base)
705 {
706 $ldap= $this->config->get_ldap_link();
707 $base= preg_replace("/^,*/", "", $base);
709 /* Try to use plain entry first */
710 $dn= "$attribute=".$this->$attribute.",$base";
711 $ldap->cat ($dn, array('dn'));
712 if (!$ldap->fetch()){
713 return ($dn);
714 }
716 /* Look for additional attributes */
717 foreach ($this->attributes as $attr){
718 if ($attr == $attribute || $this->$attr == ""){
719 continue;
720 }
722 $dn= "$attribute=".$this->$attribute."+$attr=".$this->$attr.",$base";
723 $ldap->cat ($dn, array('dn'));
724 if (!$ldap->fetch()){
725 return ($dn);
726 }
727 }
729 /* None found */
730 return ("none");
731 }
733 function rebind($ldap, $referral)
734 {
735 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
736 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
737 $this->error = "Success";
738 $this->hascon=true;
739 $this->reconnect= true;
740 return (0);
741 } else {
742 $this->error = "Could not bind to " . $credentials['ADMIN'];
743 return NULL;
744 }
745 }
747 /* This is a workaround function. */
748 function copy($src_dn, $dst_dn)
749 {
750 /* Rename dn in possible object groups */
751 $ldap= $this->config->get_ldap_link();
752 $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($src_dn).'))',
753 array('cn'));
754 while ($attrs= $ldap->fetch()){
755 $og= new ogroup($this->config, $ldap->getDN());
756 unset($og->member[$src_dn]);
757 $og->member[$dst_dn]= $dst_dn;
758 $og->save ();
759 }
761 $ldap->cat($dst_dn);
762 $attrs= $ldap->fetch();
763 if (count($attrs)){
764 trigger_error("Trying to overwrite ".@LDAP::fix($dst_dn).", which already exists.",
765 E_USER_WARNING);
766 return (FALSE);
767 }
769 $ldap->cat($src_dn);
770 $attrs= $ldap->fetch();
771 if (!count($attrs)){
772 trigger_error("Trying to move ".@LDAP::fix($src_dn).", which does not seem to exist.",
773 E_USER_WARNING);
774 return (FALSE);
775 }
777 /* Grummble. This really sucks. PHP ldap doesn't support rdn stuff. */
778 $ds= ldap_connect($this->config->current['SERVER']);
779 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
780 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['REFERRAL'])) {
781 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
782 }
784 $r=ldap_bind($ds,$this->config->current['ADMIN'], $this->config->current['PASSWORD']);
785 $sr=ldap_read($ds, @LDAP::fix($src_dn), "objectClass=*");
787 /* Fill data from LDAP */
788 $new= array();
789 if ($sr) {
790 $ei=ldap_first_entry($ds, $sr);
791 if ($ei) {
792 foreach($attrs as $attr => $val){
793 if ($info = @ldap_get_values_len($ds, $ei, $attr)){
794 for ($i= 0; $i<$info['count']; $i++){
795 if ($info['count'] == 1){
796 $new[$attr]= $info[$i];
797 } else {
798 $new[$attr][]= $info[$i];
799 }
800 }
801 }
802 }
803 }
804 }
806 /* close conncetion */
807 ldap_unbind($ds);
809 /* Adapt naming attribute */
810 $dst_name= preg_replace("/^([^=]+)=.*$/", "\\1", $dst_dn);
811 $dst_val = preg_replace("/^[^=]+=([^,+]+).*,.*$/", "\\1", $dst_dn);
812 $new[$dst_name]= @LDAP::fix($dst_val);
814 /* Check if this is a department.
815 * If it is a dep. && there is a , override in his ou
816 * change \2C to , again, else this entry can't be saved ...
817 */
818 if((isset($new['ou'])) &&( preg_match("/\\,/",$new['ou']))){
819 $new['ou'] = preg_replace("/\\\\,/",",",$new['ou']);
820 }
822 /* Save copy */
823 $ldap->connect();
824 $ldap->cd($this->config->current['BASE']);
826 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dst_dn));
828 /* FAIvariable=.../..., cn=..
829 could not be saved, because the attribute FAIvariable was different to
830 the dn FAIvariable=..., cn=... */
831 if(in_array_ics("FAIdebconfInfo",$new['objectClass'])){
832 $new['FAIvariable'] = $ldap->fix($new['FAIvariable']);
833 }
834 $ldap->cd($dst_dn);
835 $ldap->add($new);
837 if ($ldap->error != "Success"){
838 trigger_error("Trying to save $dst_dn failed.",
839 E_USER_WARNING);
840 return(FALSE);
841 }
843 return (TRUE);
844 }
847 function move($src_dn, $dst_dn)
848 {
849 /* Copy source to destination */
850 if (!$this->copy($src_dn, $dst_dn)){
851 return (FALSE);
852 }
854 /* Delete source */
855 $ldap= $this->config->get_ldap_link();
856 $ldap->rmdir($src_dn);
857 if ($ldap->error != "Success"){
858 trigger_error("Trying to delete $src_dn failed.",
859 E_USER_WARNING);
860 return (FALSE);
861 }
863 return (TRUE);
864 }
867 /* Move/Rename complete trees */
868 function recursive_move($src_dn, $dst_dn)
869 {
870 /* Check if the destination entry exists */
871 $ldap= $this->config->get_ldap_link();
873 /* Check if destination exists - abort */
874 $ldap->cat($dst_dn, array('dn'));
875 if ($ldap->fetch()){
876 trigger_error("recursive_move $dst_dn already exists.",
877 E_USER_WARNING);
878 return (FALSE);
879 }
881 /* Perform a search for all objects to be moved */
882 $objects= array();
883 $ldap->cd($src_dn);
884 $ldap->search("(objectClass=*)", array("dn"));
885 while($attrs= $ldap->fetch()){
886 $dn= $attrs['dn'];
887 $objects[$dn]= strlen($dn);
888 }
890 /* Sort objects by indent level */
891 asort($objects);
892 reset($objects);
894 /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
895 foreach ($objects as $object => $len){
896 $src= $object;
897 $dst= preg_replace("/$src_dn$/", "$dst_dn", $object);
898 if (!$this->copy($src, $dst)){
899 return (FALSE);
900 }
901 }
903 /* Remove src_dn */
904 $ldap->cd($src_dn);
905 $ldap->recursive_remove();
906 return (TRUE);
907 }
910 function handle_post_events($mode, $add_attrs= array())
911 {
912 switch ($mode){
913 case "add":
914 $this->postcreate($add_attrs);
915 break;
917 case "modify":
918 $this->postmodify($add_attrs);
919 break;
921 case "remove":
922 $this->postremove($add_attrs);
923 break;
924 }
925 }
928 function saveCopyDialog(){
929 }
932 function getCopyDialog(){
933 return(array("string"=>"","status"=>""));
934 }
937 function PrepareForCopyPaste($source)
938 {
939 $todo = $this->attributes;
940 if(isset($this->CopyPasteVars)){
941 $todo = array_merge($todo,$this->CopyPasteVars);
942 }
944 if(count($this->objectclasses)){
945 $this->is_account = TRUE;
946 foreach($this->objectclasses as $class){
947 if(!in_array($class,$source['objectClass'])){
948 $this->is_account = FALSE;
949 }
950 }
951 }
953 foreach($todo as $var){
954 if (isset($source[$var])){
955 if(isset($source[$var]['count'])){
956 if($source[$var]['count'] > 1){
957 $this->$var = array();
958 $tmp = array();
959 for($i = 0 ; $i < $source[$var]['count']; $i++){
960 $tmp = $source[$var][$i];
961 }
962 $this->$var = $tmp;
963 # echo $var."=".$tmp."<br>";
964 }else{
965 $this->$var = $source[$var][0];
966 # echo $var."=".$source[$var][0]."<br>";
967 }
968 }else{
969 $this->$var= $source[$var];
970 # echo $var."=".$source[$var]."<br>";
971 }
972 }
973 }
974 }
977 function handle_object_tagging($dn= "", $tag= "", $show= false)
978 {
979 //FIXME: How to optimize this? We have at least two
980 // LDAP accesses per object. It would be a good
981 // idea to have it integrated.
983 /* No dn? Self-operation... */
984 if ($dn == ""){
985 $dn= $this->dn;
987 /* No tag? Find it yourself... */
988 if ($tag == ""){
989 $len= strlen($dn);
991 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging");
992 $relevant= array();
993 foreach ($this->config->adepartments as $key => $ntag){
995 /* This one is bigger than our dn, its not relevant... */
996 if ($len <= strlen($key)){
997 continue;
998 }
1000 /* This one matches with the latter part. Break and don't fix this entry */
1001 if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){
1002 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
1003 $relevant[strlen($key)]= $ntag;
1004 continue;
1005 }
1007 }
1009 /* If we've some relevant tags to set, just get the longest one */
1010 if (count($relevant)){
1011 ksort($relevant);
1012 $tmp= array_keys($relevant);
1013 $idx= end($tmp);
1014 $tag= $relevant[$idx];
1015 $this->gosaUnitTag= $tag;
1016 }
1017 }
1018 }
1021 /* Set tag? */
1022 if ($tag != ""){
1023 /* Set objectclass and attribute */
1024 $ldap= $this->config->get_ldap_link();
1025 $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
1026 $attrs= $ldap->fetch();
1027 if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){
1028 if ($show) {
1029 echo sprintf(_("Object '%s' is already tagged"), @LDAP::fix($dn))."<br>";
1030 flush();
1031 }
1032 return;
1033 }
1034 if (count($attrs)){
1035 if ($show){
1036 echo sprintf(_("Adding tag (%s) to object '%s'"), $tag, @LDAP::fix($dn))."<br>";
1037 flush();
1038 }
1039 $nattrs= array("gosaUnitTag" => $tag);
1040 $nattrs['objectClass']= array();
1041 for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
1042 $oc= $attrs['objectClass'][$i];
1043 if ($oc != "gosaAdministrativeUnitTag"){
1044 $nattrs['objectClass'][]= $oc;
1045 }
1046 }
1047 $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
1048 $ldap->cd($dn);
1049 $ldap->modify($nattrs);
1050 show_ldap_error($ldap->get_error(), sprintf(_("Handle object tagging with dn '%s' failed."),$dn));
1051 } else {
1052 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not tagging ($tag) $dn - seems to have moved away", "Tagging");
1053 }
1055 } else {
1056 /* Remove objectclass and attribute */
1057 $ldap= $this->config->get_ldap_link();
1058 $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
1059 $attrs= $ldap->fetch();
1060 if (isset($attrs['objectClass']) && !in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass'])){
1061 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "$dn is not tagged", "Tagging");
1062 return;
1063 }
1064 if (count($attrs)){
1065 if ($show){
1066 echo sprintf(_("Removing tag from object '%s'"), @LDAP::fix($dn))."<br>";
1067 flush();
1068 }
1069 $nattrs= array("gosaUnitTag" => array());
1070 $nattrs['objectClass']= array();
1071 for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
1072 $oc= $attrs['objectClass'][$i];
1073 if ($oc != "gosaAdministrativeUnitTag"){
1074 $nattrs['objectClass'][]= $oc;
1075 }
1076 }
1077 $ldap->cd($dn);
1078 $ldap->modify($nattrs);
1079 show_ldap_error($ldap->get_error(), sprintf(_("Handle object tagging with dn '%s' failed."),$dn));
1080 } else {
1081 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
1082 }
1083 }
1085 }
1088 /* Add possibility to stop remove process */
1089 function allow_remove()
1090 {
1091 $reason= "";
1092 return $reason;
1093 }
1096 /* Create a snapshot of the current object */
1097 function create_snapshot($type= "snapshot", $description= array())
1098 {
1100 /* Check if snapshot functionality is enabled */
1101 if(!$this->snapshotEnabled()){
1102 return;
1103 }
1105 /* Get configuration from gosa.conf */
1106 $tmp = $this->config->current;
1108 /* Create lokal ldap connection */
1109 $ldap= $this->config->get_ldap_link();
1110 $ldap->cd($this->config->current['BASE']);
1112 /* check if there are special server configurations for snapshots */
1113 if(!isset($tmp['SNAPSHOT_SERVER'])){
1115 /* Source and destination server are both the same, just copy source to dest obj */
1116 $ldap_to = $ldap;
1117 $snapldapbase = $this->config->current['BASE'];
1119 }else{
1120 $server = $tmp['SNAPSHOT_SERVER'];
1121 $user = $tmp['SNAPSHOT_USER'];
1122 $password = $tmp['SNAPSHOT_PASSWORD'];
1123 $snapldapbase = $tmp['SNAPSHOT_BASE'];
1125 $ldap_to = new LDAP($user,$password, $server);
1126 $ldap_to -> cd($snapldapbase);
1127 show_ldap_error($ldap->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$snapldapbase));
1128 }
1130 /* check if the dn exists */
1131 if ($ldap->dn_exists($this->dn)){
1133 /* Extract seconds & mysecs, they are used as entry index */
1134 list($usec, $sec)= explode(" ", microtime());
1136 /* Collect some infos */
1137 $base = $this->config->current['BASE'];
1138 $snap_base = $tmp['SNAPSHOT_BASE'];
1139 $base_of_object = preg_replace ('/^[^,]+,/i', '', $this->dn);
1140 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1142 /* Create object */
1143 #$data = preg_replace('/^dn:.*\n/', '', $ldap->gen_ldif($this->dn,"(!(objectClass=gosaDepartment))"));
1144 $data = $ldap->gen_ldif($this->dn,"(&(!(objectClass=gosaDepartment))(!(objectClass=FAIclass)))");
1145 $newName = preg_replace("/\./", "", $sec."-".$usec);
1146 $target= array();
1147 $target['objectClass'] = array("top", "gosaSnapshotObject");
1148 $target['gosaSnapshotData'] = gzcompress($data, 6);
1149 $target['gosaSnapshotType'] = $type;
1150 $target['gosaSnapshotDN'] = $this->dn;
1151 $target['description'] = $description;
1152 $target['gosaSnapshotTimestamp'] = $newName;
1154 /* Insert the new snapshot
1155 But we have to check first, if the given gosaSnapshotTimestamp
1156 is already used, in this case we should increment this value till there is
1157 an unused value. */
1158 $new_dn = "gosaSnapshotTimestamp=".$newName.",".$new_base;
1159 $ldap_to->cat($new_dn);
1160 while($ldap_to->count()){
1161 $ldap_to->cat($new_dn);
1162 $newName = preg_replace("/\./", "", $sec."-".($usec++));
1163 $new_dn = "gosaSnapshotTimestamp=".$newName.",".$new_base;
1164 $target['gosaSnapshotTimestamp'] = $newName;
1165 }
1167 /* Inset this new snapshot */
1168 $ldap_to->cd($snapldapbase);
1169 $ldap_to->create_missing_trees($new_base);
1170 $ldap_to->cd($new_dn);
1171 $ldap_to->add($target);
1173 show_ldap_error($ldap->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$new_base));
1174 show_ldap_error($ldap_to->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$new_base));
1175 }
1176 }
1178 function remove_snapshot($dn)
1179 {
1180 $ui = get_userinfo();
1181 $old_dn = $this->dn;
1182 $this->dn = $dn;
1183 $ldap = $this->config->get_ldap_link();
1184 $ldap->cd($this->config->current['BASE']);
1185 $ldap->rmdir_recursive($dn);
1186 $this->dn = $old_dn;
1187 }
1190 /* returns true if snapshots are enabled, and false if it is disalbed
1191 There will also be some errors psoted, if the configuration failed */
1192 function snapshotEnabled()
1193 {
1194 $tmp = $this->config->current;
1195 if(isset($tmp['ENABLE_SNAPSHOT'])){
1196 if (preg_match("/^true$/i", $tmp['ENABLE_SNAPSHOT']) || preg_match("/yes/i", $tmp['ENABLE_SNAPSHOT'])){
1198 /* Check if the snapshot_base is defined */
1199 if(!isset($tmp['SNAPSHOT_BASE'])){
1200 print_red(sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not configured in your gosa.conf."),"SNAPSHOT_BASE"));
1201 return(FALSE);
1202 }
1204 /* check if there are special server configurations for snapshots */
1205 if(isset($tmp['SNAPSHOT_SERVER'])){
1207 /* check if all required vars are available to create a new ldap connection */
1208 $missing = "";
1209 foreach(array("SNAPSHOT_SERVER","SNAPSHOT_USER","SNAPSHOT_PASSWORD","SNAPSHOT_BASE") as $var){
1210 if(!isset($tmp[$var])){
1211 $missing .= $var." ";
1212 print_red(sprintf(_("The snapshot functionality is enabled, but the required variable(s) '%s' is not configured in your gosa.conf."),$missing));
1213 return(FALSE);
1214 }
1215 }
1216 }
1217 return(TRUE);
1218 }
1219 }
1220 return(FALSE);
1221 }
1224 /* Return available snapshots for the given base
1225 */
1226 function Available_SnapsShots($dn,$raw = false)
1227 {
1228 if(!$this->snapshotEnabled()) return(array());
1230 /* Create an additional ldap object which
1231 points to our ldap snapshot server */
1232 $ldap= $this->config->get_ldap_link();
1233 $ldap->cd($this->config->current['BASE']);
1234 $cfg= &$this->config->current;
1236 /* check if there are special server configurations for snapshots */
1238 if(isset($cfg['SERVER']) && isset($cfg['SNAPSHOT_SERVER']) && $cfg['SERVER'] == $cfg['SNAPSHOT_SERVER']){
1239 $ldap_to = $ldap;
1240 }elseif(isset($cfg['SNAPSHOT_SERVER'])){
1241 $server = $cfg['SNAPSHOT_SERVER'];
1242 $user = $cfg['SNAPSHOT_USER'];
1243 $password = $cfg['SNAPSHOT_PASSWORD'];
1244 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1246 $ldap_to = new LDAP($user,$password, $server);
1247 $ldap_to -> cd ($snapldapbase);
1248 show_ldap_error($ldap->get_error(), sprintf(_("Method get available snapshots with dn '%s' failed."),$this->dn));
1249 }else{
1250 $ldap_to = $ldap;
1251 }
1253 /* Prepare bases and some other infos */
1254 $base = $this->config->current['BASE'];
1255 $snap_base = $cfg['SNAPSHOT_BASE'];
1256 $base_of_object = preg_replace ('/^[^,]+,/i', '', $dn);
1257 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1258 $tmp = array();
1260 /* Fetch all objects with gosaSnapshotDN=$dn */
1261 $ldap_to->cd($new_base);
1262 $ldap_to->ls("(&(objectClass=gosaSnapshotObject)(gosaSnapshotDN=".$dn."))",$new_base,
1263 array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
1265 /* Put results into a list and add description if missing */
1266 while($entry = $ldap_to->fetch()){
1267 if(!isset($entry['description'][0])){
1268 $entry['description'][0] = "";
1269 }
1270 $tmp[] = $entry;
1271 }
1273 /* Return the raw array, or format the result */
1274 if($raw){
1275 return($tmp);
1276 }else{
1277 $tmp2 = array();
1278 foreach($tmp as $entry){
1279 $tmp2[base64_encode($entry['dn'])] = $entry['description'][0];
1280 }
1281 }
1282 return($tmp2);
1283 }
1286 function getAllDeletedSnapshots($base_of_object,$raw = false)
1287 {
1288 if(!$this->snapshotEnabled()) return(array());
1290 /* Create an additional ldap object which
1291 points to our ldap snapshot server */
1292 $ldap= $this->config->get_ldap_link();
1293 $ldap->cd($this->config->current['BASE']);
1294 $cfg= &$this->config->current;
1296 /* check if there are special server configurations for snapshots */
1297 if(isset($cfg['SNAPSHOT_SERVER'])){
1298 $server = $cfg['SNAPSHOT_SERVER'];
1299 $user = $cfg['SNAPSHOT_USER'];
1300 $password = $cfg['SNAPSHOT_PASSWORD'];
1301 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1302 $ldap_to = new LDAP($user,$password, $server);
1303 $ldap_to->cd ($snapldapbase);
1304 show_ldap_error($ldap_to->get_error(), sprintf(_("Method get deleted snapshots with dn '%s' failed."),$this->dn));
1305 }else{
1306 $ldap_to = $ldap;
1307 }
1309 /* Prepare bases */
1310 $base = $this->config->current['BASE'];
1311 $snap_base = $cfg['SNAPSHOT_BASE'];
1312 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1314 /* Fetch all objects and check if they do not exist anymore */
1315 $ui = get_userinfo();
1316 $tmp = array();
1317 $ldap_to->cd($new_base);
1318 $ldap_to->ls("(objectClass=gosaSnapshotObject)",$new_base,array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
1319 while($entry = $ldap_to->fetch()){
1321 $chk = str_replace($new_base,"",$entry['dn']);
1322 if(preg_match("/,ou=/",$chk)) continue;
1324 if(!isset($entry['description'][0])){
1325 $entry['description'][0] = "";
1326 }
1327 $tmp[] = $entry;
1328 }
1330 /* Check if entry still exists */
1331 foreach($tmp as $key => $entry){
1332 $ldap->cat($entry['gosaSnapshotDN'][0]);
1333 if($ldap->count()){
1334 unset($tmp[$key]);
1335 }
1336 }
1338 /* Format result as requested */
1339 if($raw) {
1340 return($tmp);
1341 }else{
1342 $tmp2 = array();
1343 foreach($tmp as $key => $entry){
1344 $tmp2[base64_encode($entry['dn'])] = $entry['description'][0];
1345 }
1346 }
1347 return($tmp2);
1348 }
1351 /* Restore selected snapshot */
1352 function restore_snapshot($dn)
1353 {
1354 if(!$this->snapshotEnabled()) return(array());
1356 $ldap= $this->config->get_ldap_link();
1357 $ldap->cd($this->config->current['BASE']);
1358 $cfg= &$this->config->current;
1360 /* check if there are special server configurations for snapshots */
1361 if(isset($cfg['SNAPSHOT_SERVER'])){
1362 $server = $cfg['SNAPSHOT_SERVER'];
1363 $user = $cfg['SNAPSHOT_USER'];
1364 $password = $cfg['SNAPSHOT_PASSWORD'];
1365 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1366 $ldap_to = new LDAP($user,$password, $server);
1367 $ldap_to->cd ($snapldapbase);
1368 show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$snapldapbase));
1369 }else{
1370 $ldap_to = $ldap;
1371 }
1373 /* Get the snapshot */
1374 $ldap_to->cat($dn);
1375 $restoreObject = $ldap_to->fetch();
1377 /* Prepare import string */
1378 $data = gzuncompress($ldap_to->get_attribute($dn,'gosaSnapshotData'));
1380 /* Import the given data */
1381 $ldap->import_complete_ldif($data,$err,false,false);
1382 show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$dn));
1383 }
1386 function showSnapshotDialog($base,$baseSuffixe)
1387 {
1388 $once = true;
1389 foreach($_POST as $name => $value){
1391 /* Create a new snapshot, display a dialog */
1392 if(preg_match("/^CreateSnapShotDialog_/",$name) && $once){
1393 $once = false;
1394 $entry = preg_replace("/^CreateSnapShotDialog_/","",$name);
1395 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
1396 $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
1397 }
1399 /* Restore a snapshot, display a dialog with all snapshots of the current object */
1400 if(preg_match("/^RestoreSnapShotDialog_/",$name) && $once){
1401 $once = false;
1402 $entry = preg_replace("/^RestoreSnapShotDialog_/","",$name);
1403 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
1404 $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
1405 $this->snapDialog->display_restore_dialog = true;
1406 }
1408 /* Restore one of the already deleted objects */
1409 if(((isset($_POST['menu_action']) && $_POST['menu_action'] == "RestoreDeletedSnapShot")
1410 || preg_match("/^RestoreDeletedSnapShot_/",$name)) && $once){
1411 $once = false;
1412 $this->snapDialog = new SnapShotDialog($this->config,"",$this);
1413 $this->snapDialog->set_snapshot_bases($baseSuffixe);
1414 $this->snapDialog->display_restore_dialog = true;
1415 $this->snapDialog->display_all_removed_objects = true;
1416 }
1418 /* Restore selected snapshot */
1419 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
1420 $once = false;
1421 $entry = preg_replace("/^RestoreSnapShot_/","",$name);
1422 $entry = base64_decode(trim(preg_replace("/_[xy]$/","",$entry)));
1423 if(!empty($entry)){
1424 $this->restore_snapshot($entry);
1425 $this->snapDialog = NULL;
1426 }
1427 }
1428 }
1430 /* Create a new snapshot requested, check
1431 the given attributes and create the snapshot*/
1432 if(isset($_POST['CreateSnapshot']) && is_object($this->snapDialog)){
1433 $this->snapDialog->save_object();
1434 $msgs = $this->snapDialog->check();
1435 if(count($msgs)){
1436 foreach($msgs as $msg){
1437 print_red($msg);
1438 }
1439 }else{
1440 $this->dn = $this->snapDialog->dn;
1441 $this->create_snapshot("snapshot",$this->snapDialog->CurrentDescription);
1442 $this->snapDialog = NULL;
1443 }
1444 }
1446 /* Restore is requested, restore the object with the posted dn .*/
1447 if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){
1448 }
1450 if(isset($_POST['CancelSnapshot'])){
1451 $this->snapDialog = NULL;
1452 }
1454 if(is_object($this->snapDialog )){
1455 $this->snapDialog->save_object();
1456 return($this->snapDialog->execute());
1457 }
1458 }
1461 static function plInfo()
1462 {
1463 return array();
1464 }
1467 function set_acl_base($base)
1468 {
1469 $this->acl_base= $base;
1470 }
1473 function set_acl_category($category)
1474 {
1475 $this->acl_category= "$category/";
1476 }
1479 function acl_is_writeable($attribute,$skip_write = FALSE)
1480 {
1481 $ui= get_userinfo();
1482 return preg_match('/w/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute, $skip_write));
1483 }
1486 function acl_is_readable($attribute)
1487 {
1488 $ui= get_userinfo();
1489 return preg_match('/r/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute));
1490 }
1493 function acl_is_createable()
1494 {
1495 $ui= get_userinfo();
1496 return preg_match('/c/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1497 }
1500 function acl_is_removeable()
1501 {
1502 $ui= get_userinfo();
1503 return preg_match('/d/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1504 }
1507 function acl_is_moveable()
1508 {
1509 $ui= get_userinfo();
1510 return preg_match('/m/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1511 }
1514 function acl_have_any_permissions()
1515 {
1516 }
1519 function getacl($attribute,$skip_write= FALSE)
1520 {
1521 $ui= get_userinfo();
1522 return $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute,$skip_write);
1523 }
1525 /* Get all allowed bases to move an object to or to create a new object.
1526 Idepartments also contains all base departments which lead to the allowed bases */
1527 function get_allowed_bases($category = "")
1528 {
1529 $ui = get_userinfo();
1530 $deps = array();
1532 /* Set category */
1533 if(empty($category)){
1534 $category = $this->acl_category.get_class($this);
1535 }
1537 /* Is this a new object ? Or just an edited existing object */
1538 if(!$this->initially_was_account && $this->is_account){
1539 $new = true;
1540 }else{
1541 $new = false;
1542 }
1544 $cat_bases = $ui->get_module_departments(preg_replace("/\/.*$/","",$category));
1545 foreach($this->config->idepartments as $dn => $name){
1547 if(!in_array_ics($dn,$cat_bases)){
1548 continue;
1549 }
1551 $acl = $ui->get_permissions($dn,$category);
1552 if($new && preg_match("/c/",$acl)){
1553 $deps[$dn] = $name;
1554 }elseif(!$new && preg_match("/m/",$acl)){
1555 $deps[$dn] = $name;
1556 }
1557 }
1559 /* Add current base */
1560 if(isset($this->base) && isset($this->config->idepartments[$this->base])){
1561 $deps[$this->base] = $this->config->idepartments[$this->base];
1562 }else{
1563 echo "No default base found. ".$this->base."<br> ";
1564 }
1566 return($deps);
1567 }
1569 /* This function modifies object acls too, if an object is moved.
1570 * $old_dn specifies the actually used dn
1571 * $new_dn specifies the destiantion dn
1572 */
1573 function update_acls($old_dn,$new_dn,$output_changes = FALSE)
1574 {
1575 /* Check if old_dn is empty. This should never happen */
1576 if(empty($old_dn) || empty($new_dn)){
1577 trigger_error("Failed to check acl dependencies, wrong dn given.");
1578 return;
1579 }
1581 /* Update userinfo if necessary */
1582 if($_SESSION['ui']->dn == $old_dn){
1583 $_SESSION['ui']->dn = $new_dn;
1584 new log("view","acl/".get_class($this),$this->dn,array(),"Updated current user dn from '".$old_dn."' to '".$new_dn."'");
1585 }
1587 /* Object was moved, ensure that all acls will be moved too */
1588 if($new_dn != $old_dn && $old_dn != "new"){
1590 /* get_ldap configuration */
1591 $update = array();
1592 $ldap = $this->config->get_ldap_link();
1593 $ldap->cd ($this->config->current['BASE']);
1594 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*))",array("cn","gosaAclEntry"));
1595 while($attrs = $ldap->fetch()){
1597 $acls = array();
1599 /* Walk through acls */
1600 for($i = 0 ; $i < $attrs['gosaAclEntry']['count'] ; $i ++ ){
1602 /* Reset vars */
1603 $found = false;
1605 /* Get Acl parts */
1606 $acl_parts = split(":",$attrs['gosaAclEntry'][$i]);
1608 /* Get every single member for this acl */
1609 $members = array();
1610 if(preg_match("/,/",$acl_parts[2])){
1611 $members = split(",",$acl_parts[2]);
1612 }else{
1613 $members = array($acl_parts[2]);
1614 }
1616 /* Check if member match current dn */
1617 foreach($members as $key => $member){
1618 $member = base64_decode($member);
1619 if($member == $old_dn){
1620 $found = true;
1621 $members[$key] = base64_encode($new_dn);
1622 }
1623 }
1625 /* Create new member string */
1626 $new_members = "";
1627 foreach($members as $member){
1628 $new_members .= $member.",";
1629 }
1630 $new_members = preg_replace("/,$/","",$new_members);
1631 $acl_parts[2] = $new_members;
1633 /* Reconstruckt acl entry */
1634 $acl_str ="";
1635 foreach($acl_parts as $t){
1636 $acl_str .= $t.":";
1637 }
1638 $acl_str = preg_replace("/:$/","",$acl_str);
1639 }
1641 /* Acls for this object must be adjusted */
1642 if($found){
1644 if($output_changes){
1645 echo "<font color='green'>".
1646 _("Changing ACL dn")." : <br> -"._("from")." <b> ".
1647 $old_dn.
1648 "</b><br> -"._("to")." <b>".
1649 $new_dn.
1650 "</b></font><br>";
1651 }
1652 $update[$attrs['dn']] =array();
1653 foreach($acls as $acl){
1654 $update[$attrs['dn']]['gosaAclEntry'][] = $acl;
1655 }
1656 }
1657 }
1659 /* Write updated acls */
1660 foreach($update as $dn => $attrs){
1661 $ldap->cd($dn);
1662 $ldap->modify($attrs);
1663 }
1664 }
1665 }
1668 function get_multi_edit_values()
1669 {
1670 $ret = array();
1671 foreach($this->selected_edit_values as $attr => $active){
1672 if($active){
1673 $ret[$attr] = $this->$attr;
1674 }
1675 }
1676 return($ret);
1677 }
1680 /* This function enables the entry Serial ID check.
1681 * If an entry was edited while we have edited the entry too,
1682 * an error message will be shown.
1683 * To configure this check correctly read the FAQ.
1684 */
1685 function enable_CSN_check()
1686 {
1687 $this->CSN_check_active =TRUE;
1688 $this->entryCSN = getEntryCSN($this->dn);
1689 }
1692 function set_multi_edit_value()
1693 {
1695 }
1697 }
1699 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1700 ?>