6bf6e73db4e49045c1238a3bc59a5fc83284e539
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= "";
91 var $skipTagging= FALSE;
93 /*!
94 \brief Used standard values
96 dn
97 */
98 var $dn= "";
99 var $uid= "";
100 var $sn= "";
101 var $givenName= "";
102 var $acl= "*none*";
103 var $dialog= FALSE;
104 var $snapDialog = NULL;
106 /* attribute list for save action */
107 var $attributes= array();
108 var $objectclasses= array();
109 var $is_new= TRUE;
110 var $saved_attributes= array();
112 var $acl_base= "";
113 var $acl_category= "";
115 /* This can be set to render the tabulators in another stylesheet */
116 var $pl_notify= FALSE;
118 /* Object entry CSN */
119 var $entryCSN = "";
120 var $CSN_check_active = FALSE;
122 /* This variable indicates that this class can handle multiple dns at once. */
123 var $multiple_support = FALSE;
124 var $multi_attrs = array();
125 var $multi_attrs_all = array();
127 /* This aviable indicates, that we are currently in multiple edit handle */
128 var $multiple_support_active = FALSE;
129 var $selected_edit_values = array();
130 var $multi_boxes = 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 (isset($this->saved_attributes[$index][0]) || $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 }
232 /*! \brief execute plugin
234 Generates the html output for this node
235 */
236 function execute()
237 {
238 /* This one is empty currently. Fabian - please fill in the docu code */
239 session::set('current_class_for_help',get_class($this));
241 /* Reset Lock message POST/GET check array, to prevent perg_match errors*/
242 session::set('LOCK_VARS_TO_USE',array());
243 session::set('LOCK_VARS_USED',array());
244 }
246 /*! \brief execute plugin
247 Removes object from parent
248 */
249 function remove_from_parent()
250 {
251 /* include global link_info */
252 $ldap= $this->config->get_ldap_link();
254 /* Get current objectClasses in order to add the required ones */
255 $ldap->cat($this->dn);
256 $tmp= $ldap->fetch ();
257 $oc= array();
258 if (isset($tmp['objectClass'])){
259 $oc= $tmp['objectClass'];
260 unset($oc['count']);
261 }
263 /* Remove objectClasses from entry */
264 $ldap->cd($this->dn);
265 $this->attrs= array();
266 $this->attrs['objectClass']= array_remove_entries($this->objectclasses,$oc);
268 /* Unset attributes from entry */
269 foreach ($this->attributes as $val){
270 $this->attrs["$val"]= array();
271 }
273 /* Unset account info */
274 $this->is_account= FALSE;
276 /* Do not write in plugin base class, this must be done by
277 children, since there are normally additional attribs,
278 lists, etc. */
279 /*
280 $ldap->modify($this->attrs);
281 */
282 }
285 /*! \brief Save HTML posted data to object
286 */
287 function save_object()
288 {
289 /* Update entry CSN if it is empty. */
290 if(empty($this->entryCSN) && $this->CSN_check_active){
291 $this->entryCSN = getEntryCSN($this->dn);
292 }
294 /* Save values to object */
295 foreach ($this->attributes as $val){
296 if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){
297 /* Check for modifications */
298 if (get_magic_quotes_gpc()) {
299 $data= stripcslashes($_POST["$val"]);
300 } else {
301 $data= $this->$val = $_POST["$val"];
302 }
303 if ($this->$val != $data){
304 $this->is_modified= TRUE;
305 }
307 /* Okay, how can I explain this fix ...
308 * In firefox, disabled option fields aren't selectable ... but in IE you can select these fileds.
309 * So IE posts these 'unselectable' option, with value = chr(194)
310 * chr(194) seems to be the in between the ...option> </option.. because there is no value=".." specified in these option fields
311 * This was added for W3c compliance, but now causes these ... ldap errors ...
312 * So we set these Fields to ""; a normal empty string, and we can check these values in plugin::check() again ...
313 */
314 if(isset($data[0]) && $data[0] == chr(194)) {
315 $data = "";
316 }
317 $this->$val= $data;
318 }
319 }
320 }
323 /* Save data to LDAP, depending on is_account we save or delete */
324 function save()
325 {
326 /* include global link_info */
327 $ldap= $this->config->get_ldap_link();
329 /* Save all plugins */
330 $this->entryCSN = "";
332 /* Start with empty array */
333 $this->attrs= array();
335 /* Get current objectClasses in order to add the required ones */
336 $ldap->cat($this->dn);
338 $tmp= $ldap->fetch ();
340 $oc= array();
341 if (isset($tmp['objectClass'])){
342 $oc= $tmp["objectClass"];
343 $this->is_new= FALSE;
344 unset($oc['count']);
345 } else {
346 $this->is_new= TRUE;
347 }
349 /* Load (minimum) attributes, add missing ones */
350 $this->attrs['objectClass']= gosa_array_merge($oc,$this->objectclasses);
352 /* Copy standard attributes */
353 foreach ($this->attributes as $val){
354 if ($this->$val != ""){
355 $this->attrs["$val"]= $this->$val;
356 } elseif (!$this->is_new) {
357 $this->attrs["$val"]= array();
358 }
359 }
361 /* Handle tagging */
362 $this->tag_attrs($this->attrs);
363 }
366 function cleanup()
367 {
368 foreach ($this->attrs as $index => $value){
370 /* Convert arrays with one element to non arrays, if the saved
371 attributes are no array, too */
372 if (is_array($this->attrs[$index]) &&
373 count ($this->attrs[$index]) == 1 &&
374 isset($this->saved_attributes[$index]) &&
375 !is_array($this->saved_attributes[$index])){
377 $tmp= $this->attrs[$index][0];
378 $this->attrs[$index]= $tmp;
379 }
381 /* Remove emtpy arrays if they do not differ */
382 if (is_array($this->attrs[$index]) &&
383 count($this->attrs[$index]) == 0 &&
384 !isset($this->saved_attributes[$index])){
386 unset ($this->attrs[$index]);
387 continue;
388 }
390 /* Remove single attributes that do not differ */
391 if (!is_array($this->attrs[$index]) &&
392 isset($this->saved_attributes[$index]) &&
393 !is_array($this->saved_attributes[$index]) &&
394 $this->attrs[$index] == $this->saved_attributes[$index]){
396 unset ($this->attrs[$index]);
397 continue;
398 }
400 /* Remove arrays that do not differ */
401 if (is_array($this->attrs[$index]) &&
402 isset($this->saved_attributes[$index]) &&
403 is_array($this->saved_attributes[$index])){
405 if (!array_differs($this->attrs[$index],$this->saved_attributes[$index])){
406 unset ($this->attrs[$index]);
407 continue;
408 }
409 }
410 }
412 /* Update saved attributes and ensure that next cleanups will be successful too */
413 foreach($this->attrs as $name => $value){
414 $this->saved_attributes[$name] = $value;
415 }
416 }
418 /* Check formular input */
419 function check()
420 {
421 $message= array();
423 /* Skip if we've no config object */
424 if (!isset($this->config) || !is_object($this->config)){
425 return $message;
426 }
428 /* Find hooks entries for this class */
429 $command= $this->config->search(get_class($this), "CHECK", array('menu', 'tabs'));
431 if ($command != ""){
433 if (!check_command($command)){
434 $message[]= sprintf(_("Command '%s', specified as CHECK hook for plugin '%s' doesn't seem to exist."), $command,
435 get_class($this));
436 } else {
438 /* Generate "ldif" for check hook */
439 $ldif= "dn: $this->dn\n";
441 /* ... objectClasses */
442 foreach ($this->objectclasses as $oc){
443 $ldif.= "objectClass: $oc\n";
444 }
446 /* ... attributes */
447 foreach ($this->attributes as $attr){
448 if ($this->$attr == ""){
449 continue;
450 }
451 if (is_array($this->$attr)){
452 foreach ($this->$attr as $val){
453 $ldif.= "$attr: $val\n";
454 }
455 } else {
456 $ldif.= "$attr: ".$this->$attr."\n";
457 }
458 }
460 /* Append empty line */
461 $ldif.= "\n";
463 /* Feed "ldif" into hook and retrieve result*/
464 $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
465 $fh= proc_open($command, $descriptorspec, $pipes);
466 if (is_resource($fh)) {
467 fwrite ($pipes[0], $ldif);
468 fclose($pipes[0]);
470 $result= stream_get_contents($pipes[1]);
471 if ($result != ""){
472 $message[]= $result;
473 }
475 fclose($pipes[1]);
476 fclose($pipes[2]);
477 proc_close($fh);
478 }
479 }
481 }
483 /* Check entryCSN */
484 if($this->CSN_check_active){
485 $current_csn = getEntryCSN($this->dn);
486 if($current_csn != $this->entryCSN && !empty($this->entryCSN) && !empty($current_csn)){
487 $this->entryCSN = $current_csn;
488 $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.");
489 }
490 }
491 return ($message);
492 }
494 /* Adapt from template, using 'dn' */
495 function adapt_from_template($dn)
496 {
497 /* Include global link_info */
498 $ldap= $this->config->get_ldap_link();
500 /* Load requested 'dn' to 'attrs' */
501 $ldap->cat ($dn);
502 $this->attrs= $ldap->fetch();
504 /* Walk through attributes */
505 foreach ($this->attributes as $val){
507 if (isset($this->attrs["$val"][0])){
509 /* If attribute is set, replace dynamic parts:
510 %sn, %givenName and %uid. Fill these in our local variables. */
511 $value= $this->attrs["$val"][0];
513 foreach (array("sn", "givenName", "uid") as $repl){
514 if (preg_match("/%$repl/i", $value)){
515 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
516 }
517 }
518 $this->$val= $value;
519 }
520 }
522 /* Is Account? */
523 $found= TRUE;
524 foreach ($this->objectclasses as $obj){
525 if (preg_match('/top/i', $obj)){
526 continue;
527 }
528 if (!in_array_ics ($obj, $this->attrs['objectClass'])){
529 $found= FALSE;
530 break;
531 }
532 }
533 if ($found){
534 $this->is_account= TRUE;
535 }
536 }
538 /* Indicate whether a password change is needed or not */
539 function password_change_needed()
540 {
541 return FALSE;
542 }
545 /* Show header message for tab dialogs */
546 function show_enable_header($button_text, $text, $disabled= FALSE)
547 {
548 if (($disabled == TRUE) || (!$this->acl_is_createable())){
549 $state= "disabled";
550 } else {
551 $state= "";
552 }
553 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
554 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".$state.
555 "><p class=\"seperator\"> </p></td></tr></table>";
557 return($display);
558 }
561 /* Show header message for tab dialogs */
562 function show_disable_header($button_text, $text, $disabled= FALSE)
563 {
564 if (($disabled == TRUE) || !$this->acl_is_removeable()){
565 $state= "disabled";
566 } else {
567 $state= "";
568 }
569 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
570 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".$state.
571 "><p class=\"seperator\"> </p></td></tr></table>";
573 return($display);
574 }
577 /* Show header message for tab dialogs */
578 function show_header($button_text, $text, $disabled= FALSE)
579 {
580 echo "FIXME: show_header should be replaced by show_disable_header and show_enable_header<br>";
581 if ($disabled == TRUE){
582 $state= "disabled";
583 } else {
584 $state= "";
585 }
586 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
587 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".
588 ($this->acl_is_createable()?'':'disabled')." ".$state.
589 "><p class=\"seperator\"> </p></td></tr></table>";
591 return($display);
592 }
595 function postcreate($add_attrs= array())
596 {
597 /* Find postcreate entries for this class */
598 $command= $this->config->search(get_class($this), "POSTCREATE",array('menu', 'tabs'));
600 if ($command != ""){
602 /* Additional attributes */
603 foreach ($add_attrs as $name => $value){
604 $command= preg_replace("/%$name( |$)/", "$value ", $command);
605 }
607 /* Walk through attribute list */
608 foreach ($this->attributes as $attr){
609 if (!is_array($this->$attr)){
610 $command= preg_replace("/%$attr( |$)/", $this->$attr." ", $command);
611 }
612 }
613 $command= preg_replace("/%dn( |$)/", $this->dn." ", $command);
615 if (check_command($command)){
616 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
617 $command, "Execute");
619 exec($command);
620 } else {
621 $message= sprintf(_("Command '%s', specified as POSTCREATE for plugin '%s' doesn't seem to exist."), $command, get_class($this));
622 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
623 }
624 }
625 }
627 function postmodify($add_attrs= array())
628 {
629 /* Find postcreate entries for this class */
630 $command= $this->config->search(get_class($this), "POSTMODIFY",array('menu','tabs'));
632 if ($command != ""){
634 /* Additional attributes */
635 foreach ($add_attrs as $name => $value){
636 $command= preg_replace("/%$name( |$)/", "$value ", $command);
637 }
639 /* Walk through attribute list */
640 foreach ($this->attributes as $attr){
641 if (!is_array($this->$attr)){
642 $command= preg_replace("/%$attr( |$)/", $this->$attr." ", $command);
643 }
644 }
645 $command= preg_replace("/%dn( |$)/", $this->dn." ", $command);
647 if (check_command($command)){
648 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
649 $command, "Execute");
651 exec($command);
652 } else {
653 $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, get_class($this));
654 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
655 }
656 }
657 }
659 function postremove($add_attrs= array())
660 {
661 /* Find postremove entries for this class */
662 $command= $this->config->search(get_class($this), "POSTREMOVE",array('menu','tabs'));
663 if ($command != ""){
665 /* Additional attributes */
666 foreach ($add_attrs as $name => $value){
667 $command= preg_replace("/%$name( |$)/", "$value ", $command);
668 }
670 /* Walk through attribute list */
671 foreach ($this->attributes as $attr){
672 if (!is_array($this->$attr)){
673 $command= preg_replace("/%$attr( |$)/", $this->$attr." ", $command);
674 }
675 }
676 $command= preg_replace("/%dn( |$)/", $this->dn." ", $command);
678 if (check_command($command)){
679 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
680 $command, "Execute");
682 exec($command);
683 } else {
684 $message= sprintf(_("Command '%s', specified as POSTREMOVE for plugin '%s' doesn't seem to exist."), $command, get_class($this));
685 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
686 }
687 }
688 }
690 /* Create unique DN */
691 function create_unique_dn($attribute, $base)
692 {
693 $ldap= $this->config->get_ldap_link();
694 $base= preg_replace("/^,*/", "", $base);
696 /* Try to use plain entry first */
697 $dn= "$attribute=".$this->$attribute.",$base";
698 $ldap->cat ($dn, array('dn'));
699 if (!$ldap->fetch()){
700 return ($dn);
701 }
703 /* Look for additional attributes */
704 foreach ($this->attributes as $attr){
705 if ($attr == $attribute || $this->$attr == ""){
706 continue;
707 }
709 $dn= "$attribute=".$this->$attribute."+$attr=".$this->$attr.",$base";
710 $ldap->cat ($dn, array('dn'));
711 if (!$ldap->fetch()){
712 return ($dn);
713 }
714 }
716 /* None found */
717 return ("none");
718 }
720 function rebind($ldap, $referral)
721 {
722 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
723 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
724 $this->error = "Success";
725 $this->hascon=true;
726 $this->reconnect= true;
727 return (0);
728 } else {
729 $this->error = "Could not bind to " . $credentials['ADMIN'];
730 return NULL;
731 }
732 }
735 /* Recursively copy ldap object */
736 function _copy($src_dn,$dst_dn)
737 {
738 $ldap=$this->config->get_ldap_link();
739 $ldap->cat($src_dn);
740 $attrs= $ldap->fetch();
742 /* Grummble. This really sucks. PHP ldap doesn't support rdn stuff. */
743 $ds= ldap_connect($this->config->current['SERVER']);
744 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
745 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['REFERRAL'])) {
746 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
747 }
749 $r=ldap_bind($ds,$this->config->current['ADMIN'], $this->config->current['PASSWORD']);
750 $sr=ldap_read($ds, @LDAP::fix($src_dn), "objectClass=*");
752 /* Fill data from LDAP */
753 $new= array();
754 if ($sr) {
755 $ei=ldap_first_entry($ds, $sr);
756 if ($ei) {
757 foreach($attrs as $attr => $val){
758 if ($info = @ldap_get_values_len($ds, $ei, $attr)){
759 for ($i= 0; $i<$info['count']; $i++){
760 if ($info['count'] == 1){
761 $new[$attr]= $info[$i];
762 } else {
763 $new[$attr][]= $info[$i];
764 }
765 }
766 }
767 }
768 }
769 }
771 /* close conncetion */
772 ldap_unbind($ds);
774 /* Adapt naming attribute */
775 $dst_name= preg_replace("/^([^=]+)=.*$/", "\\1", $dst_dn);
776 $dst_val = preg_replace("/^[^=]+=([^,+]+).*,.*$/", "\\1", $dst_dn);
777 $new[$dst_name]= @LDAP::fix($dst_val);
779 /* Check if this is a department.
780 * If it is a dep. && there is a , override in his ou
781 * change \2C to , again, else this entry can't be saved ...
782 */
783 if((isset($new['ou'])) &&( preg_match("/\\,/",$new['ou']))){
784 $new['ou'] = preg_replace("/\\\\,/",",",$new['ou']);
785 }
787 /* Save copy */
788 $ldap->connect();
789 $ldap->cd($this->config->current['BASE']);
791 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dst_dn));
793 /* FAIvariable=.../..., cn=..
794 could not be saved, because the attribute FAIvariable was different to
795 the dn FAIvariable=..., cn=... */
796 if(in_array_ics("FAIdebconfInfo",$new['objectClass'])){
797 $new['FAIvariable'] = $ldap->fix($new['FAIvariable']);
798 }
799 $ldap->cd($dst_dn);
800 $ldap->add($new);
802 if ($ldap->error != "Success"){
803 trigger_error("Trying to save $dst_dn failed.",
804 E_USER_WARNING);
805 return(FALSE);
806 }
807 return(TRUE);
808 }
811 /* This is a workaround function. */
812 function copy($src_dn, $dst_dn)
813 {
814 /* Rename dn in possible object groups */
815 $ldap= $this->config->get_ldap_link();
816 $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::prepare4filter($src_dn).'))',
817 array('cn'));
818 while ($attrs= $ldap->fetch()){
819 $og= new ogroup($this->config, $ldap->getDN());
820 unset($og->member[$src_dn]);
821 $og->member[$dst_dn]= $dst_dn;
822 $og->save ();
823 }
825 $ldap->cat($dst_dn);
826 $attrs= $ldap->fetch();
827 if (count($attrs)){
828 trigger_error("Trying to overwrite ".@LDAP::fix($dst_dn).", which already exists.",
829 E_USER_WARNING);
830 return (FALSE);
831 }
833 $ldap->cat($src_dn);
834 $attrs= $ldap->fetch();
835 if (!count($attrs)){
836 trigger_error("Trying to move ".@LDAP::fix($src_dn).", which does not seem to exist.",
837 E_USER_WARNING);
838 return (FALSE);
839 }
841 $ldap->cd($src_dn);
842 $ldap->search("objectClass=*",array("dn"));
843 while($attrs = $ldap->fetch()){
844 $src = $attrs['dn'];
845 $dst = preg_replace("/".normalizePreg($src_dn)."$/",$dst_dn,$attrs['dn']);
846 $this->_copy($src,$dst);
847 }
848 return (TRUE);
849 }
852 function move($src_dn, $dst_dn)
853 {
854 /* Do not copy if only upper- lowercase has changed */
855 if(strtolower($src_dn) == strtolower($dst_dn)){
856 return(TRUE);
857 }
859 /* Copy source to destination */
860 if (!$this->copy($src_dn, $dst_dn)){
861 return (FALSE);
862 }
864 /* Delete source */
865 $ldap= $this->config->get_ldap_link();
866 $ldap->rmdir_recursive($src_dn);
867 if ($ldap->error != "Success"){
868 trigger_error("Trying to delete $src_dn failed.",
869 E_USER_WARNING);
870 return (FALSE);
871 }
873 return (TRUE);
874 }
877 /* Move/Rename complete trees */
878 function recursive_move($src_dn, $dst_dn)
879 {
880 /* Check if the destination entry exists */
881 $ldap= $this->config->get_ldap_link();
883 /* Check if destination exists - abort */
884 $ldap->cat($dst_dn, array('dn'));
885 if ($ldap->fetch()){
886 trigger_error("recursive_move $dst_dn already exists.",
887 E_USER_WARNING);
888 return (FALSE);
889 }
891 $this->copy($src_dn, $dst_dn);
893 /* Remove src_dn */
894 $ldap->cd($src_dn);
895 $ldap->recursive_remove($src_dn);
896 return (TRUE);
897 }
900 function handle_post_events($mode, $add_attrs= array())
901 {
902 switch ($mode){
903 case "add":
904 $this->postcreate($add_attrs);
905 break;
907 case "modify":
908 $this->postmodify($add_attrs);
909 break;
911 case "remove":
912 $this->postremove($add_attrs);
913 break;
914 }
915 }
918 function saveCopyDialog(){
919 }
922 function getCopyDialog(){
923 return(array("string"=>"","status"=>""));
924 }
927 function PrepareForCopyPaste($source)
928 {
929 $todo = $this->attributes;
930 if(isset($this->CopyPasteVars)){
931 $todo = array_merge($todo,$this->CopyPasteVars);
932 }
934 if(count($this->objectclasses)){
935 $this->is_account = TRUE;
936 foreach($this->objectclasses as $class){
937 if(!in_array($class,$source['objectClass'])){
938 $this->is_account = FALSE;
939 }
940 }
941 }
943 foreach($todo as $var){
944 if (isset($source[$var])){
945 if(isset($source[$var]['count'])){
946 if($source[$var]['count'] > 1){
947 $this->$var = array();
948 $tmp = array();
949 for($i = 0 ; $i < $source[$var]['count']; $i++){
950 $tmp = $source[$var][$i];
951 }
952 $this->$var = $tmp;
953 }else{
954 $this->$var = $source[$var][0];
955 }
956 }else{
957 $this->$var= $source[$var];
958 }
959 }
960 }
961 }
963 function tag_attrs(&$at, $dn= "", $tag= "", $show= false)
964 {
965 /* Skip tagging?
966 If this is called from departmentGeneric, we have to skip this
967 tagging procedure.
968 */
969 if($this->skipTagging){
970 return;
971 }
973 /* No dn? Self-operation... */
974 if ($dn == ""){
975 $dn= $this->dn;
977 /* No tag? Find it yourself... */
978 if ($tag == ""){
979 $len= strlen($dn);
981 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging");
982 $relevant= array();
983 foreach ($this->config->adepartments as $key => $ntag){
985 /* This one is bigger than our dn, its not relevant... */
986 if ($len <= strlen($key)){
987 continue;
988 }
990 /* This one matches with the latter part. Break and don't fix this entry */
991 if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){
992 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
993 $relevant[strlen($key)]= $ntag;
994 continue;
995 }
997 }
999 /* If we've some relevant tags to set, just get the longest one */
1000 if (count($relevant)){
1001 ksort($relevant);
1002 $tmp= array_keys($relevant);
1003 $idx= end($tmp);
1004 $tag= $relevant[$idx];
1005 $this->gosaUnitTag= $tag;
1006 }
1007 }
1008 }
1010 /* Remove tags that may already be here... */
1011 remove_objectClass("gosaAdministrativeUnitTag", $at);
1012 if (isset($at['gosaUnitTag'])){
1013 unset($at['gosaUnitTag']);
1014 }
1016 /* Set tag? */
1017 if ($tag != ""){
1018 add_objectClass("gosaAdministrativeUnitTag", $at);
1019 $at['gosaUnitTag']= $tag;
1020 }
1021 }
1024 /* Add possibility to stop remove process */
1025 function allow_remove()
1026 {
1027 $reason= "";
1028 return $reason;
1029 }
1032 /* Create a snapshot of the current object */
1033 function create_snapshot($type= "snapshot", $description= array())
1034 {
1036 /* Check if snapshot functionality is enabled */
1037 if(!$this->snapshotEnabled()){
1038 return;
1039 }
1041 /* Get configuration from gosa.conf */
1042 $tmp = $this->config->current;
1044 /* Create lokal ldap connection */
1045 $ldap= $this->config->get_ldap_link();
1046 $ldap->cd($this->config->current['BASE']);
1048 /* check if there are special server configurations for snapshots */
1049 if(!isset($tmp['SNAPSHOT_SERVER'])){
1051 /* Source and destination server are both the same, just copy source to dest obj */
1052 $ldap_to = $ldap;
1053 $snapldapbase = $this->config->current['BASE'];
1055 }else{
1056 $server = $tmp['SNAPSHOT_SERVER'];
1057 $user = $tmp['SNAPSHOT_USER'];
1058 $password = $tmp['SNAPSHOT_PASSWORD'];
1059 $snapldapbase = $tmp['SNAPSHOT_BASE'];
1061 $ldap_to = new LDAP($user,$password, $server);
1062 $ldap_to -> cd($snapldapbase);
1063 show_ldap_error($ldap->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$snapldapbase));
1064 }
1066 /* check if the dn exists */
1067 if ($ldap->dn_exists($this->dn)){
1069 /* Extract seconds & mysecs, they are used as entry index */
1070 list($usec, $sec)= explode(" ", microtime());
1072 /* Collect some infos */
1073 $base = $this->config->current['BASE'];
1074 $snap_base = $tmp['SNAPSHOT_BASE'];
1075 $base_of_object = preg_replace ('/^[^,]+,/i', '', $this->dn);
1076 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1078 /* Create object */
1079 #$data = preg_replace('/^dn:.*\n/', '', $ldap->gen_ldif($this->dn,"(!(objectClass=gosaDepartment))"));
1080 $data = $ldap->gen_ldif($this->dn,"(&(!(objectClass=gosaDepartment))(!(objectClass=FAIclass)))");
1081 $newName = preg_replace("/\./", "", $sec."-".$usec);
1082 $target= array();
1083 $target['objectClass'] = array("top", "gosaSnapshotObject");
1084 $target['gosaSnapshotData'] = gzcompress($data, 6);
1085 $target['gosaSnapshotType'] = $type;
1086 $target['gosaSnapshotDN'] = $this->dn;
1087 $target['description'] = $description;
1088 $target['gosaSnapshotTimestamp'] = $newName;
1090 /* Insert the new snapshot
1091 But we have to check first, if the given gosaSnapshotTimestamp
1092 is already used, in this case we should increment this value till there is
1093 an unused value. */
1094 $new_dn = "gosaSnapshotTimestamp=".$newName.",".$new_base;
1095 $ldap_to->cat($new_dn);
1096 while($ldap_to->count()){
1097 $ldap_to->cat($new_dn);
1098 $newName = preg_replace("/\./", "", $sec."-".($usec++));
1099 $new_dn = "gosaSnapshotTimestamp=".$newName.",".$new_base;
1100 $target['gosaSnapshotTimestamp'] = $newName;
1101 }
1103 /* Inset this new snapshot */
1104 $ldap_to->cd($snapldapbase);
1105 $ldap_to->create_missing_trees($snapldapbase);
1106 $ldap_to->create_missing_trees($new_base);
1107 $ldap_to->cd($new_dn);
1108 $ldap_to->add($target);
1110 show_ldap_error($ldap->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$new_base));
1111 show_ldap_error($ldap_to->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$new_base));
1112 }
1113 }
1115 function remove_snapshot($dn)
1116 {
1117 $ui = get_userinfo();
1118 $old_dn = $this->dn;
1119 $this->dn = $dn;
1120 $ldap = $this->config->get_ldap_link();
1121 $ldap->cd($this->config->current['BASE']);
1122 $ldap->rmdir_recursive($dn);
1123 $this->dn = $old_dn;
1124 }
1127 /* returns true if snapshots are enabled, and false if it is disalbed
1128 There will also be some errors psoted, if the configuration failed */
1129 function snapshotEnabled()
1130 {
1131 $tmp = $this->config->current;
1132 if(isset($tmp['ENABLE_SNAPSHOT'])){
1133 if (preg_match("/^true$/i", $tmp['ENABLE_SNAPSHOT']) || preg_match("/yes/i", $tmp['ENABLE_SNAPSHOT'])){
1135 /* Check if the snapshot_base is defined */
1136 if(!isset($tmp['SNAPSHOT_BASE'])){
1137 msg_dialog::display(_("Configuration error"), sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."),"SNAPSHOT_BASE"), ERROR_DIALOG);
1138 return(FALSE);
1139 }
1141 /* check if there are special server configurations for snapshots */
1142 if(isset($tmp['SNAPSHOT_SERVER'])){
1144 /* check if all required vars are available to create a new ldap connection */
1145 $missing = "";
1146 foreach(array("SNAPSHOT_SERVER","SNAPSHOT_USER","SNAPSHOT_PASSWORD","SNAPSHOT_BASE") as $var){
1147 if(!isset($tmp[$var])){
1148 $missing .= $var." ";
1149 msg_dialog::display(_("Configuration error"), sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."), $missing), ERROR_DIALOG);
1150 return(FALSE);
1151 }
1152 }
1153 }
1154 return(TRUE);
1155 }
1156 }
1157 return(FALSE);
1158 }
1161 /* Return available snapshots for the given base
1162 */
1163 function Available_SnapsShots($dn,$raw = false)
1164 {
1165 if(!$this->snapshotEnabled()) return(array());
1167 /* Create an additional ldap object which
1168 points to our ldap snapshot server */
1169 $ldap= $this->config->get_ldap_link();
1170 $ldap->cd($this->config->current['BASE']);
1171 $cfg= &$this->config->current;
1173 /* check if there are special server configurations for snapshots */
1175 if(isset($cfg['SERVER']) && isset($cfg['SNAPSHOT_SERVER']) && $cfg['SERVER'] == $cfg['SNAPSHOT_SERVER']){
1176 $ldap_to = $ldap;
1177 }elseif(isset($cfg['SNAPSHOT_SERVER'])){
1178 $server = $cfg['SNAPSHOT_SERVER'];
1179 $user = $cfg['SNAPSHOT_USER'];
1180 $password = $cfg['SNAPSHOT_PASSWORD'];
1181 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1183 $ldap_to = new LDAP($user,$password, $server);
1184 $ldap_to -> cd ($snapldapbase);
1185 show_ldap_error($ldap->get_error(), sprintf(_("Method get available snapshots with dn '%s' failed."),$this->dn));
1186 }else{
1187 $ldap_to = $ldap;
1188 }
1190 /* Prepare bases and some other infos */
1191 $base = $this->config->current['BASE'];
1192 $snap_base = $cfg['SNAPSHOT_BASE'];
1193 $base_of_object = preg_replace ('/^[^,]+,/i', '', $dn);
1194 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1195 $tmp = array();
1197 /* Fetch all objects with gosaSnapshotDN=$dn */
1198 $ldap_to->cd($new_base);
1199 $ldap_to->ls("(&(objectClass=gosaSnapshotObject)(gosaSnapshotDN=".$dn."))",$new_base,
1200 array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
1202 /* Put results into a list and add description if missing */
1203 while($entry = $ldap_to->fetch()){
1204 if(!isset($entry['description'][0])){
1205 $entry['description'][0] = "";
1206 }
1207 $tmp[] = $entry;
1208 }
1210 /* Return the raw array, or format the result */
1211 if($raw){
1212 return($tmp);
1213 }else{
1214 $tmp2 = array();
1215 foreach($tmp as $entry){
1216 $tmp2[base64_encode($entry['dn'])] = $entry['description'][0];
1217 }
1218 }
1219 return($tmp2);
1220 }
1223 function getAllDeletedSnapshots($base_of_object,$raw = false)
1224 {
1225 if(!$this->snapshotEnabled()) return(array());
1227 /* Create an additional ldap object which
1228 points to our ldap snapshot server */
1229 $ldap= $this->config->get_ldap_link();
1230 $ldap->cd($this->config->current['BASE']);
1231 $cfg= &$this->config->current;
1233 /* check if there are special server configurations for snapshots */
1234 if(isset($cfg['SNAPSHOT_SERVER'])){
1235 $server = $cfg['SNAPSHOT_SERVER'];
1236 $user = $cfg['SNAPSHOT_USER'];
1237 $password = $cfg['SNAPSHOT_PASSWORD'];
1238 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1239 $ldap_to = new LDAP($user,$password, $server);
1240 $ldap_to->cd ($snapldapbase);
1241 show_ldap_error($ldap_to->get_error(), sprintf(_("Method get deleted snapshots with dn '%s' failed."),$this->dn));
1242 }else{
1243 $ldap_to = $ldap;
1244 }
1246 /* Prepare bases */
1247 $base = $this->config->current['BASE'];
1248 $snap_base = $cfg['SNAPSHOT_BASE'];
1249 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1251 /* Fetch all objects and check if they do not exist anymore */
1252 $ui = get_userinfo();
1253 $tmp = array();
1254 $ldap_to->cd($new_base);
1255 $ldap_to->ls("(objectClass=gosaSnapshotObject)",$new_base,array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
1256 while($entry = $ldap_to->fetch()){
1258 $chk = str_replace($new_base,"",$entry['dn']);
1259 if(preg_match("/,ou=/",$chk)) continue;
1261 if(!isset($entry['description'][0])){
1262 $entry['description'][0] = "";
1263 }
1264 $tmp[] = $entry;
1265 }
1267 /* Check if entry still exists */
1268 foreach($tmp as $key => $entry){
1269 $ldap->cat($entry['gosaSnapshotDN'][0]);
1270 if($ldap->count()){
1271 unset($tmp[$key]);
1272 }
1273 }
1275 /* Format result as requested */
1276 if($raw) {
1277 return($tmp);
1278 }else{
1279 $tmp2 = array();
1280 foreach($tmp as $key => $entry){
1281 $tmp2[base64_encode($entry['dn'])] = $entry['description'][0];
1282 }
1283 }
1284 return($tmp2);
1285 }
1288 /* Restore selected snapshot */
1289 function restore_snapshot($dn)
1290 {
1291 if(!$this->snapshotEnabled()) return(array());
1293 $ldap= $this->config->get_ldap_link();
1294 $ldap->cd($this->config->current['BASE']);
1295 $cfg= &$this->config->current;
1297 /* check if there are special server configurations for snapshots */
1298 if(isset($cfg['SNAPSHOT_SERVER'])){
1299 $server = $cfg['SNAPSHOT_SERVER'];
1300 $user = $cfg['SNAPSHOT_USER'];
1301 $password = $cfg['SNAPSHOT_PASSWORD'];
1302 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1303 $ldap_to = new LDAP($user,$password, $server);
1304 $ldap_to->cd ($snapldapbase);
1305 show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$snapldapbase));
1306 }else{
1307 $ldap_to = $ldap;
1308 }
1310 /* Get the snapshot */
1311 $ldap_to->cat($dn);
1312 $restoreObject = $ldap_to->fetch();
1314 /* Prepare import string */
1315 $data = gzuncompress($ldap_to->get_attribute($dn,'gosaSnapshotData'));
1317 /* Import the given data */
1318 $ldap->import_complete_ldif($data,$err,false,false);
1319 show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$dn));
1320 }
1323 function showSnapshotDialog($base,$baseSuffixe)
1324 {
1325 $once = true;
1326 foreach($_POST as $name => $value){
1328 /* Create a new snapshot, display a dialog */
1329 if(preg_match("/^CreateSnapShotDialog_/",$name) && $once){
1330 $once = false;
1331 $entry = preg_replace("/^CreateSnapShotDialog_/","",$name);
1332 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
1333 $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
1334 }
1336 /* Restore a snapshot, display a dialog with all snapshots of the current object */
1337 if(preg_match("/^RestoreSnapShotDialog_/",$name) && $once){
1338 $once = false;
1339 $entry = preg_replace("/^RestoreSnapShotDialog_/","",$name);
1340 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
1341 $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
1342 $this->snapDialog->display_restore_dialog = true;
1343 }
1345 /* Restore one of the already deleted objects */
1346 if(((isset($_POST['menu_action']) && $_POST['menu_action'] == "RestoreDeletedSnapShot")
1347 || preg_match("/^RestoreDeletedSnapShot_/",$name)) && $once){
1348 $once = false;
1349 $this->snapDialog = new SnapShotDialog($this->config,"",$this);
1350 $this->snapDialog->set_snapshot_bases($baseSuffixe);
1351 $this->snapDialog->display_restore_dialog = true;
1352 $this->snapDialog->display_all_removed_objects = true;
1353 }
1355 /* Restore selected snapshot */
1356 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
1357 $once = false;
1358 $entry = preg_replace("/^RestoreSnapShot_/","",$name);
1359 $entry = base64_decode(trim(preg_replace("/_[xy]$/","",$entry)));
1360 if(!empty($entry)){
1361 $this->restore_snapshot($entry);
1362 $this->snapDialog = NULL;
1363 }
1364 }
1365 }
1367 /* Create a new snapshot requested, check
1368 the given attributes and create the snapshot*/
1369 if(isset($_POST['CreateSnapshot']) && is_object($this->snapDialog)){
1370 $this->snapDialog->save_object();
1371 $msgs = $this->snapDialog->check();
1372 if(count($msgs)){
1373 foreach($msgs as $msg){
1374 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
1375 }
1376 }else{
1377 $this->dn = $this->snapDialog->dn;
1378 $this->create_snapshot("snapshot",$this->snapDialog->CurrentDescription);
1379 $this->snapDialog = NULL;
1380 }
1381 }
1383 /* Restore is requested, restore the object with the posted dn .*/
1384 if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){
1385 }
1387 if(isset($_POST['CancelSnapshot'])){
1388 $this->snapDialog = NULL;
1389 }
1391 if(is_object($this->snapDialog )){
1392 $this->snapDialog->save_object();
1393 return($this->snapDialog->execute());
1394 }
1395 }
1398 static function plInfo()
1399 {
1400 return array();
1401 }
1404 function set_acl_base($base)
1405 {
1406 $this->acl_base= $base;
1407 }
1410 function set_acl_category($category)
1411 {
1412 $this->acl_category= "$category/";
1413 }
1416 function acl_is_writeable($attribute,$skip_write = FALSE)
1417 {
1418 $ui= get_userinfo();
1419 return preg_match('/w/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute, $skip_write));
1420 }
1423 function acl_is_readable($attribute)
1424 {
1425 $ui= get_userinfo();
1426 return preg_match('/r/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute));
1427 }
1430 function acl_is_createable()
1431 {
1432 $ui= get_userinfo();
1433 return preg_match('/c/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1434 }
1437 function acl_is_removeable()
1438 {
1439 $ui= get_userinfo();
1440 return preg_match('/d/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1441 }
1444 function acl_is_moveable()
1445 {
1446 $ui= get_userinfo();
1447 return preg_match('/m/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1448 }
1451 function acl_have_any_permissions()
1452 {
1453 }
1456 function getacl($attribute,$skip_write= FALSE)
1457 {
1458 $ui= get_userinfo();
1459 return $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute,$skip_write);
1460 }
1462 /* Get all allowed bases to move an object to or to create a new object.
1463 Idepartments also contains all base departments which lead to the allowed bases */
1464 function get_allowed_bases($category = "")
1465 {
1466 $ui = get_userinfo();
1467 $deps = array();
1469 /* Set category */
1470 if(empty($category)){
1471 $category = $this->acl_category.get_class($this);
1472 }
1474 /* Is this a new object ? Or just an edited existing object */
1475 if(!$this->initially_was_account && $this->is_account){
1476 $new = true;
1477 }else{
1478 $new = false;
1479 }
1481 $cat_bases = $ui->get_module_departments(preg_replace("/\/.*$/","",$category));
1482 foreach($this->config->idepartments as $dn => $name){
1484 if(!in_array_ics($dn,$cat_bases)){
1485 continue;
1486 }
1488 $acl = $ui->get_permissions($dn,$category);
1489 if($new && preg_match("/c/",$acl)){
1490 $deps[$dn] = $name;
1491 }elseif(!$new && preg_match("/m/",$acl)){
1492 $deps[$dn] = $name;
1493 }
1494 }
1496 /* Add current base */
1497 if(isset($this->base) && isset($this->config->idepartments[$this->base])){
1498 $deps[$this->base] = $this->config->idepartments[$this->base];
1499 }else{
1500 trigger_error("No default base found in class ".get_class($this).". ".$this->base);
1501 }
1502 return($deps);
1503 }
1506 /* This function modifies object acls too, if an object is moved.
1507 * $old_dn specifies the actually used dn
1508 * $new_dn specifies the destiantion dn
1509 */
1510 function update_acls($old_dn,$new_dn,$output_changes = FALSE)
1511 {
1512 /* Check if old_dn is empty. This should never happen */
1513 if(empty($old_dn) || empty($new_dn)){
1514 trigger_error("Failed to check acl dependencies, wrong dn given.");
1515 return;
1516 }
1518 /* Update userinfo if necessary */
1519 $ui = session::get('ui');
1520 if($ui->dn == $old_dn){
1521 $ui->dn = $new_dn;
1522 session::set('ui',$ui);
1523 new log("view","acl/".get_class($this),$this->dn,array(),"Updated current user dn from '".$old_dn."' to '".$new_dn."'");
1524 }
1526 /* Object was moved, ensure that all acls will be moved too */
1527 if($new_dn != $old_dn && $old_dn != "new"){
1529 /* get_ldap configuration */
1530 $update = array();
1531 $ldap = $this->config->get_ldap_link();
1532 $ldap->cd ($this->config->current['BASE']);
1533 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*))",array("cn","gosaAclEntry"));
1534 while($attrs = $ldap->fetch()){
1536 $acls = array();
1538 /* Walk through acls */
1539 for($i = 0 ; $i < $attrs['gosaAclEntry']['count'] ; $i ++ ){
1541 /* Reset vars */
1542 $found = false;
1544 /* Get Acl parts */
1545 $acl_parts = split(":",$attrs['gosaAclEntry'][$i]);
1547 /* Get every single member for this acl */
1548 $members = array();
1549 if(preg_match("/,/",$acl_parts[2])){
1550 $members = split(",",$acl_parts[2]);
1551 }else{
1552 $members = array($acl_parts[2]);
1553 }
1555 /* Check if member match current dn */
1556 foreach($members as $key => $member){
1557 $member = base64_decode($member);
1558 if($member == $old_dn){
1559 $found = true;
1560 $members[$key] = base64_encode($new_dn);
1561 }
1562 }
1564 /* Create new member string */
1565 $new_members = "";
1566 foreach($members as $member){
1567 $new_members .= $member.",";
1568 }
1569 $new_members = preg_replace("/,$/","",$new_members);
1570 $acl_parts[2] = $new_members;
1572 /* Reconstruckt acl entry */
1573 $acl_str ="";
1574 foreach($acl_parts as $t){
1575 $acl_str .= $t.":";
1576 }
1577 $acl_str = preg_replace("/:$/","",$acl_str);
1578 }
1580 /* Acls for this object must be adjusted */
1581 if($found){
1583 $debug_info= _("Changing ACL dn")." : <br> -"._("from")." <b> ".
1584 $old_dn."</b><br> -"._("to")." <b>".$new_dn."</b><br>";
1585 @DEBUG (DEBUG_ACL, __LINE__, __FUNCTION__, __FILE__,$debug_info,"ACL");
1587 $update[$attrs['dn']] =array();
1588 foreach($acls as $acl){
1589 $update[$attrs['dn']]['gosaAclEntry'][] = $acl;
1590 }
1591 }
1592 }
1594 /* Write updated acls */
1595 foreach($update as $dn => $attrs){
1596 $ldap->cd($dn);
1597 $ldap->modify($attrs);
1598 }
1599 }
1600 }
1604 /* This function enables the entry Serial ID check.
1605 * If an entry was edited while we have edited the entry too,
1606 * an error message will be shown.
1607 * To configure this check correctly read the FAQ.
1608 */
1609 function enable_CSN_check()
1610 {
1611 $this->CSN_check_active =TRUE;
1612 $this->entryCSN = getEntryCSN($this->dn);
1613 }
1616 /*! \brief Prepares the plugin to be used for multiple edit
1617 * Update plugin attributes with given array of attribtues.
1618 * @param array Array with attributes that must be updated.
1619 */
1620 function init_multiple_support($attrs,$all)
1621 {
1622 $ldap= $this->config->get_ldap_link();
1623 $this->multi_attrs = $attrs;
1624 $this->multi_attrs_all= $all;
1626 /* Copy needed attributes */
1627 foreach ($this->attributes as $val){
1628 $found= array_key_ics($val, $this->multi_attrs);
1629 if ($found != ""){
1630 if(isset($this->multi_attrs["$found"][0])){
1631 $this->$val= $this->multi_attrs["$found"][0];
1632 }
1633 }
1634 }
1635 }
1638 /*! \brief Enables multiple support for this plugin
1639 */
1640 function enable_multiple_support()
1641 {
1642 $this->ignore_account = TRUE;
1643 $this->multiple_support_active = TRUE;
1644 }
1647 /*! \brief Returns all values that have been modfied in multiple edit mode.
1648 @return array Cotaining all mdofied values.
1649 */
1650 function get_multi_edit_values()
1651 {
1652 $ret = array();
1653 foreach($this->attributes as $attr){
1654 if(in_array($attr,$this->multi_boxes)){
1655 $ret[$attr] = $this->$attr;
1656 }
1657 }
1658 return($ret);
1659 }
1662 /*! \brief Update class variables with values collected by multiple edit.
1663 */
1664 function set_multi_edit_values($attrs)
1665 {
1666 foreach($attrs as $name => $value){
1667 $this->$name = $value;
1668 }
1669 }
1672 /*! \brief execute plugin
1674 Generates the html output for this node
1675 */
1676 function multiple_execute()
1677 {
1678 /* This one is empty currently. Fabian - please fill in the docu code */
1679 session::set('current_class_for_help',get_class($this));
1681 /* Reset Lock message POST/GET check array, to prevent perg_match errors*/
1682 session::set('LOCK_VARS_TO_USE',array());
1683 session::set('LOCK_VARS_USED',array());
1685 return("Multiple edit is currently not implemented for this plugin.");
1686 }
1689 /*! \brief Save HTML posted data to object for multiple edit
1690 */
1691 function multiple_save_object()
1692 {
1693 if(empty($this->entryCSN) && $this->CSN_check_active){
1694 $this->entryCSN = getEntryCSN($this->dn);
1695 }
1697 /* Save values to object */
1698 $this->multi_boxes = array();
1699 foreach ($this->attributes as $val){
1701 /* Get selected checkboxes from multiple edit */
1702 if(isset($_POST["use_".$val])){
1703 $this->multi_boxes[] = $val;
1704 }
1706 if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){
1708 /* Check for modifications */
1709 if (get_magic_quotes_gpc()) {
1710 $data= stripcslashes($_POST["$val"]);
1711 } else {
1712 $data= $this->$val = $_POST["$val"];
1713 }
1714 if ($this->$val != $data){
1715 $this->is_modified= TRUE;
1716 }
1718 /* IE post fix */
1719 if(isset($data[0]) && $data[0] == chr(194)) {
1720 $data = "";
1721 }
1722 $this->$val= $data;
1723 }
1724 }
1725 }
1728 /*! \brief Returns all attributes of this plugin,
1729 to be able to detect multiple used attributes
1730 in multi_plugg::detect_multiple_used_attributes().
1731 @return array Attributes required for intialization of multi_plug
1732 */
1733 public function get_multi_init_values()
1734 {
1735 $attrs = $this->attrs;
1736 return($attrs);
1737 }
1740 /*! \brief Check given values in multiple edit
1741 @return array Error messages
1742 */
1743 function multiple_check()
1744 {
1745 $message = plugin::check();
1746 return($message);
1747 }
1748 }
1750 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1751 ?>