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 /* This can be set to render the tabulators in another stylesheet */
115 var $pl_notify= FALSE;
117 /* Object entry CSN */
118 var $entryCSN = "";
119 var $CSN_check_active = FALSE;
121 /* This variable indicates that this class can handle multiple dns at once. */
122 var $multiple_support = FALSE;
123 var $multi_attrs = array();
124 var $multi_attrs_all = array();
126 /* This aviable indicates, that we are currently in multiple edit handle */
127 var $multiple_support_active = FALSE;
128 var $selected_edit_values = array();
129 var $multi_boxes = array();
131 /*! \brief plugin constructor
133 If 'dn' is set, the node loads the given 'dn' from LDAP
135 \param dn Distinguished name to initialize plugin from
136 \sa plugin()
137 */
138 function plugin (&$config, $dn= NULL, $parent= NULL)
139 {
140 /* Configuration is fine, allways */
141 $this->config= &$config;
142 $this->dn= $dn;
144 /* Handle new accounts, don't read information from LDAP */
145 if ($dn == "new"){
146 return;
147 }
149 /* Save current dn as acl_base */
150 $this->acl_base= $dn;
152 /* Get LDAP descriptor */
153 $ldap= $this->config->get_ldap_link();
154 if ($dn !== NULL){
156 /* Load data to 'attrs' and save 'dn' */
157 if ($parent !== NULL){
158 $this->attrs= $parent->attrs;
159 } else {
160 $ldap->cat ($dn);
161 $this->attrs= $ldap->fetch();
162 }
164 /* Copy needed attributes */
165 foreach ($this->attributes as $val){
166 $found= array_key_ics($val, $this->attrs);
167 if ($found != ""){
168 $this->$val= $this->attrs["$found"][0];
169 }
170 }
172 /* gosaUnitTag loading... */
173 if (isset($this->attrs['gosaUnitTag'][0])){
174 $this->gosaUnitTag= $this->attrs['gosaUnitTag'][0];
175 }
177 /* Set the template flag according to the existence of objectClass
178 gosaUserTemplate */
179 if (isset($this->attrs['objectClass'])){
180 if (in_array ("gosaUserTemplate", $this->attrs['objectClass'])){
181 $this->is_template= TRUE;
182 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
183 "found", "Template check");
184 }
185 }
187 /* Is Account? */
188 $found= TRUE;
189 foreach ($this->objectclasses as $obj){
190 if (preg_match('/top/i', $obj)){
191 continue;
192 }
193 if (!isset($this->attrs['objectClass']) || !in_array_ics ($obj, $this->attrs['objectClass'])){
194 $found= FALSE;
195 break;
196 }
197 }
198 if ($found){
199 $this->is_account= TRUE;
200 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
201 "found", "Object check");
202 }
204 /* Prepare saved attributes */
205 $this->saved_attributes= $this->attrs;
206 foreach ($this->saved_attributes as $index => $value){
207 if (preg_match('/^[0-9]+$/', $index)){
208 unset($this->saved_attributes[$index]);
209 continue;
210 }
211 if (!in_array($index, $this->attributes) && $index != "objectClass"){
212 unset($this->saved_attributes[$index]);
213 continue;
214 }
215 if ($this->saved_attributes[$index]["count"] == 1){
216 $tmp= $this->saved_attributes[$index][0];
217 unset($this->saved_attributes[$index]);
218 $this->saved_attributes[$index]= $tmp;
219 continue;
220 }
222 unset($this->saved_attributes["$index"]["count"]);
223 }
224 }
226 /* Save initial account state */
227 $this->initially_was_account= $this->is_account;
228 }
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::set('current_class_for_help',get_class($this));
240 /* Reset Lock message POST/GET check array, to prevent perg_match errors*/
241 session::set('LOCK_VARS_TO_USE',array());
242 session::set('LOCK_VARS_USED',array());
243 }
245 /*! \brief execute plugin
246 Removes object from parent
247 */
248 function remove_from_parent()
249 {
250 /* include global link_info */
251 $ldap= $this->config->get_ldap_link();
253 /* Get current objectClasses in order to add the required ones */
254 $ldap->cat($this->dn);
255 $tmp= $ldap->fetch ();
256 $oc= array();
257 if (isset($tmp['objectClass'])){
258 $oc= $tmp['objectClass'];
259 unset($oc['count']);
260 }
262 /* Remove objectClasses from entry */
263 $ldap->cd($this->dn);
264 $this->attrs= array();
265 $this->attrs['objectClass']= array_remove_entries($this->objectclasses,$oc);
267 /* Unset attributes from entry */
268 foreach ($this->attributes as $val){
269 $this->attrs["$val"]= array();
270 }
272 /* Unset account info */
273 $this->is_account= FALSE;
275 /* Do not write in plugin base class, this must be done by
276 children, since there are normally additional attribs,
277 lists, etc. */
278 /*
279 $ldap->modify($this->attrs);
280 */
281 }
284 /*! \brief Save HTML posted data to object
285 */
286 function save_object()
287 {
288 /* Update entry CSN if it is empty. */
289 if(empty($this->entryCSN) && $this->CSN_check_active){
290 $this->entryCSN = getEntryCSN($this->dn);
291 }
293 /* Save values to object */
294 foreach ($this->attributes as $val){
295 if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){
296 /* Check for modifications */
297 if (get_magic_quotes_gpc()) {
298 $data= stripcslashes($_POST["$val"]);
299 } else {
300 $data= $this->$val = $_POST["$val"];
301 }
302 if ($this->$val != $data){
303 $this->is_modified= TRUE;
304 }
306 /* Okay, how can I explain this fix ...
307 * In firefox, disabled option fields aren't selectable ... but in IE you can select these fileds.
308 * So IE posts these 'unselectable' option, with value = chr(194)
309 * chr(194) seems to be the in between the ...option> </option.. because there is no value=".." specified in these option fields
310 * This was added for W3c compliance, but now causes these ... ldap errors ...
311 * So we set these Fields to ""; a normal empty string, and we can check these values in plugin::check() again ...
312 */
313 if(isset($data[0]) && $data[0] == chr(194)) {
314 $data = "";
315 }
316 $this->$val= $data;
317 }
318 }
319 }
322 /* Save data to LDAP, depending on is_account we save or delete */
323 function save()
324 {
325 /* include global link_info */
326 $ldap= $this->config->get_ldap_link();
328 /* Save all plugins */
329 $this->entryCSN = "";
331 /* Start with empty array */
332 $this->attrs= array();
334 /* Get current objectClasses in order to add the required ones */
335 $ldap->cat($this->dn);
337 $tmp= $ldap->fetch ();
339 $oc= array();
340 if (isset($tmp['objectClass'])){
341 $oc= $tmp["objectClass"];
342 $this->is_new= FALSE;
343 unset($oc['count']);
344 } else {
345 $this->is_new= TRUE;
346 }
348 /* Load (minimum) attributes, add missing ones */
349 $this->attrs['objectClass']= gosa_array_merge($oc,$this->objectclasses);
351 /* Copy standard attributes */
352 foreach ($this->attributes as $val){
353 if ($this->$val != ""){
354 $this->attrs["$val"]= $this->$val;
355 } elseif (!$this->is_new) {
356 $this->attrs["$val"]= array();
357 }
358 }
360 /* Handle tagging */
361 $this->tag_attrs(&$this->attrs);
362 }
365 function cleanup()
366 {
367 foreach ($this->attrs as $index => $value){
369 /* Convert arrays with one element to non arrays, if the saved
370 attributes are no array, too */
371 if (is_array($this->attrs[$index]) &&
372 count ($this->attrs[$index]) == 1 &&
373 isset($this->saved_attributes[$index]) &&
374 !is_array($this->saved_attributes[$index])){
376 $tmp= $this->attrs[$index][0];
377 $this->attrs[$index]= $tmp;
378 }
380 /* Remove emtpy arrays if they do not differ */
381 if (is_array($this->attrs[$index]) &&
382 count($this->attrs[$index]) == 0 &&
383 !isset($this->saved_attributes[$index])){
385 unset ($this->attrs[$index]);
386 continue;
387 }
389 /* Remove single attributes that do not differ */
390 if (!is_array($this->attrs[$index]) &&
391 isset($this->saved_attributes[$index]) &&
392 !is_array($this->saved_attributes[$index]) &&
393 $this->attrs[$index] == $this->saved_attributes[$index]){
395 unset ($this->attrs[$index]);
396 continue;
397 }
399 /* Remove arrays that do not differ */
400 if (is_array($this->attrs[$index]) &&
401 isset($this->saved_attributes[$index]) &&
402 is_array($this->saved_attributes[$index])){
404 if (!array_differs($this->attrs[$index],$this->saved_attributes[$index])){
405 unset ($this->attrs[$index]);
406 continue;
407 }
408 }
409 }
411 /* Update saved attributes and ensure that next cleanups will be successful too */
412 foreach($this->attrs as $name => $value){
413 $this->saved_attributes[$name] = $value;
414 }
415 }
417 /* Check formular input */
418 function check()
419 {
420 $message= array();
422 /* Skip if we've no config object */
423 if (!isset($this->config) || !is_object($this->config)){
424 return $message;
425 }
427 /* Find hooks entries for this class */
428 $command= $this->config->search(get_class($this), "CHECK", array('menu', 'tabs'));
430 if ($command != ""){
432 if (!check_command($command)){
433 $message[]= sprintf(_("Command '%s', specified as CHECK hook for plugin '%s' doesn't seem to exist."), $command,
434 get_class($this));
435 } else {
437 /* Generate "ldif" for check hook */
438 $ldif= "dn: $this->dn\n";
440 /* ... objectClasses */
441 foreach ($this->objectclasses as $oc){
442 $ldif.= "objectClass: $oc\n";
443 }
445 /* ... attributes */
446 foreach ($this->attributes as $attr){
447 if ($this->$attr == ""){
448 continue;
449 }
450 if (is_array($this->$attr)){
451 foreach ($this->$attr as $val){
452 $ldif.= "$attr: $val\n";
453 }
454 } else {
455 $ldif.= "$attr: ".$this->$attr."\n";
456 }
457 }
459 /* Append empty line */
460 $ldif.= "\n";
462 /* Feed "ldif" into hook and retrieve result*/
463 $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
464 $fh= proc_open($command, $descriptorspec, $pipes);
465 if (is_resource($fh)) {
466 fwrite ($pipes[0], $ldif);
467 fclose($pipes[0]);
469 $result= stream_get_contents($pipes[1]);
470 if ($result != ""){
471 $message[]= $result;
472 }
474 fclose($pipes[1]);
475 fclose($pipes[2]);
476 proc_close($fh);
477 }
478 }
480 }
482 /* Check entryCSN */
483 if($this->CSN_check_active){
484 $current_csn = getEntryCSN($this->dn);
485 if($current_csn != $this->entryCSN && !empty($this->entryCSN) && !empty($current_csn)){
486 $this->entryCSN = $current_csn;
487 $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.");
488 }
489 }
490 return ($message);
491 }
493 /* Adapt from template, using 'dn' */
494 function adapt_from_template($dn)
495 {
496 /* Include global link_info */
497 $ldap= $this->config->get_ldap_link();
499 /* Load requested 'dn' to 'attrs' */
500 $ldap->cat ($dn);
501 $this->attrs= $ldap->fetch();
503 /* Walk through attributes */
504 foreach ($this->attributes as $val){
506 if (isset($this->attrs["$val"][0])){
508 /* If attribute is set, replace dynamic parts:
509 %sn, %givenName and %uid. Fill these in our local variables. */
510 $value= $this->attrs["$val"][0];
512 foreach (array("sn", "givenName", "uid") as $repl){
513 if (preg_match("/%$repl/i", $value)){
514 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
515 }
516 }
517 $this->$val= $value;
518 }
519 }
521 /* Is Account? */
522 $found= TRUE;
523 foreach ($this->objectclasses as $obj){
524 if (preg_match('/top/i', $obj)){
525 continue;
526 }
527 if (!in_array_ics ($obj, $this->attrs['objectClass'])){
528 $found= FALSE;
529 break;
530 }
531 }
532 if ($found){
533 $this->is_account= TRUE;
534 }
535 }
537 /* Indicate whether a password change is needed or not */
538 function password_change_needed()
539 {
540 return FALSE;
541 }
544 /* Show header message for tab dialogs */
545 function show_enable_header($button_text, $text, $disabled= FALSE)
546 {
547 if (($disabled == TRUE) || (!$this->acl_is_createable())){
548 $state= "disabled";
549 } else {
550 $state= "";
551 }
552 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
553 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".$state.
554 "><p class=\"seperator\"> </p></td></tr></table>";
556 return($display);
557 }
560 /* Show header message for tab dialogs */
561 function show_disable_header($button_text, $text, $disabled= FALSE)
562 {
563 if (($disabled == TRUE) || !$this->acl_is_removeable()){
564 $state= "disabled";
565 } else {
566 $state= "";
567 }
568 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
569 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".$state.
570 "><p class=\"seperator\"> </p></td></tr></table>";
572 return($display);
573 }
576 /* Show header message for tab dialogs */
577 function show_header($button_text, $text, $disabled= FALSE)
578 {
579 echo "FIXME: show_header should be replaced by show_disable_header and show_enable_header<br>";
580 if ($disabled == TRUE){
581 $state= "disabled";
582 } else {
583 $state= "";
584 }
585 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
586 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".
587 ($this->acl_is_createable()?'':'disabled')." ".$state.
588 "><p class=\"seperator\"> </p></td></tr></table>";
590 return($display);
591 }
594 function postcreate($add_attrs= array())
595 {
596 /* Find postcreate entries for this class */
597 $command= $this->config->search(get_class($this), "POSTCREATE",array('menu', 'tabs'));
599 if ($command != ""){
601 /* Additional attributes */
602 foreach ($add_attrs as $name => $value){
603 $command= preg_replace("/%$name/", $value, $command);
604 }
606 /* Walk through attribute list */
607 foreach ($this->attributes as $attr){
608 if (!is_array($this->$attr)){
609 $command= preg_replace("/%$attr/", $this->$attr, $command);
610 }
611 }
612 $command= preg_replace("/%dn/", $this->dn, $command);
614 if (check_command($command)){
615 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
616 $command, "Execute");
618 exec($command);
619 } else {
620 $message= sprintf(_("Command '%s', specified as POSTCREATE for plugin '%s' doesn't seem to exist."), $command, get_class($this));
621 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
622 }
623 }
624 }
626 function postmodify($add_attrs= array())
627 {
628 /* Find postcreate entries for this class */
629 $command= $this->config->search(get_class($this), "POSTMODIFY",array('menu','tabs'));
631 if ($command != ""){
633 /* Additional attributes */
634 foreach ($add_attrs as $name => $value){
635 $command= preg_replace("/%$name/", $value, $command);
636 }
638 /* Walk through attribute list */
639 foreach ($this->attributes as $attr){
640 if (!is_array($this->$attr)){
641 $command= preg_replace("/%$attr/", $this->$attr, $command);
642 }
643 }
644 $command= preg_replace("/%dn/", $this->dn, $command);
646 if (check_command($command)){
647 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
648 $command, "Execute");
650 exec($command);
651 } else {
652 $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, get_class($this));
653 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
654 }
655 }
656 }
658 function postremove($add_attrs= array())
659 {
660 /* Find postremove entries for this class */
661 $command= $this->config->search(get_class($this), "POSTREMOVE",array('menu','tabs'));
662 if ($command != ""){
664 /* Additional attributes */
665 foreach ($add_attrs as $name => $value){
666 $command= preg_replace("/%$name/", $value, $command);
667 }
669 /* Walk through attribute list */
670 foreach ($this->attributes as $attr){
671 if (!is_array($this->$attr)){
672 $command= preg_replace("/%$attr/", $this->$attr, $command);
673 }
674 }
675 $command= preg_replace("/%dn/", $this->dn, $command);
677 /* Additional attributes */
678 foreach ($add_attrs as $name => $value){
679 $command= preg_replace("/%$name/", $value, $command);
680 }
682 if (check_command($command)){
683 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
684 $command, "Execute");
686 exec($command);
687 } else {
688 $message= sprintf(_("Command '%s', specified as POSTREMOVE for plugin '%s' doesn't seem to exist."), $command, get_class($this));
689 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
690 }
691 }
692 }
694 /* Create unique DN */
695 function create_unique_dn($attribute, $base)
696 {
697 $ldap= $this->config->get_ldap_link();
698 $base= preg_replace("/^,*/", "", $base);
700 /* Try to use plain entry first */
701 $dn= "$attribute=".$this->$attribute.",$base";
702 $ldap->cat ($dn, array('dn'));
703 if (!$ldap->fetch()){
704 return ($dn);
705 }
707 /* Look for additional attributes */
708 foreach ($this->attributes as $attr){
709 if ($attr == $attribute || $this->$attr == ""){
710 continue;
711 }
713 $dn= "$attribute=".$this->$attribute."+$attr=".$this->$attr.",$base";
714 $ldap->cat ($dn, array('dn'));
715 if (!$ldap->fetch()){
716 return ($dn);
717 }
718 }
720 /* None found */
721 return ("none");
722 }
724 function rebind($ldap, $referral)
725 {
726 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
727 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
728 $this->error = "Success";
729 $this->hascon=true;
730 $this->reconnect= true;
731 return (0);
732 } else {
733 $this->error = "Could not bind to " . $credentials['ADMIN'];
734 return NULL;
735 }
736 }
739 /* Recursively copy ldap object */
740 function _copy($src_dn,$dst_dn)
741 {
742 $ldap=$this->config->get_ldap_link();
743 $ldap->cat($src_dn);
744 $attrs= $ldap->fetch();
746 /* Grummble. This really sucks. PHP ldap doesn't support rdn stuff. */
747 $ds= ldap_connect($this->config->current['SERVER']);
748 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
749 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['REFERRAL'])) {
750 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
751 }
753 $r=ldap_bind($ds,$this->config->current['ADMIN'], $this->config->current['PASSWORD']);
754 $sr=ldap_read($ds, @LDAP::fix($src_dn), "objectClass=*");
756 /* Fill data from LDAP */
757 $new= array();
758 if ($sr) {
759 $ei=ldap_first_entry($ds, $sr);
760 if ($ei) {
761 foreach($attrs as $attr => $val){
762 if ($info = @ldap_get_values_len($ds, $ei, $attr)){
763 for ($i= 0; $i<$info['count']; $i++){
764 if ($info['count'] == 1){
765 $new[$attr]= $info[$i];
766 } else {
767 $new[$attr][]= $info[$i];
768 }
769 }
770 }
771 }
772 }
773 }
775 /* close conncetion */
776 ldap_unbind($ds);
778 /* Adapt naming attribute */
779 $dst_name= preg_replace("/^([^=]+)=.*$/", "\\1", $dst_dn);
780 $dst_val = preg_replace("/^[^=]+=([^,+]+).*,.*$/", "\\1", $dst_dn);
781 $new[$dst_name]= @LDAP::fix($dst_val);
783 /* Check if this is a department.
784 * If it is a dep. && there is a , override in his ou
785 * change \2C to , again, else this entry can't be saved ...
786 */
787 if((isset($new['ou'])) &&( preg_match("/\\,/",$new['ou']))){
788 $new['ou'] = preg_replace("/\\\\,/",",",$new['ou']);
789 }
791 /* Save copy */
792 $ldap->connect();
793 $ldap->cd($this->config->current['BASE']);
795 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dst_dn));
797 /* FAIvariable=.../..., cn=..
798 could not be saved, because the attribute FAIvariable was different to
799 the dn FAIvariable=..., cn=... */
800 if(in_array_ics("FAIdebconfInfo",$new['objectClass'])){
801 $new['FAIvariable'] = $ldap->fix($new['FAIvariable']);
802 }
803 $ldap->cd($dst_dn);
804 $ldap->add($new);
806 if ($ldap->error != "Success"){
807 trigger_error("Trying to save $dst_dn failed.",
808 E_USER_WARNING);
809 return(FALSE);
810 }
811 return(TRUE);
812 }
815 /* This is a workaround function. */
816 function copy($src_dn, $dst_dn)
817 {
818 /* Rename dn in possible object groups */
819 $ldap= $this->config->get_ldap_link();
820 $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.vLDAP::prepare4filter($src_dn).'))',
821 array('cn'));
822 while ($attrs= $ldap->fetch()){
823 $og= new ogroup($this->config, $ldap->getDN());
824 unset($og->member[$src_dn]);
825 $og->member[$dst_dn]= $dst_dn;
826 $og->save ();
827 }
829 $ldap->cat($dst_dn);
830 $attrs= $ldap->fetch();
831 if (count($attrs)){
832 trigger_error("Trying to overwrite ".@LDAP::fix($dst_dn).", which already exists.",
833 E_USER_WARNING);
834 return (FALSE);
835 }
837 $ldap->cat($src_dn);
838 $attrs= $ldap->fetch();
839 if (!count($attrs)){
840 trigger_error("Trying to move ".@LDAP::fix($src_dn).", which does not seem to exist.",
841 E_USER_WARNING);
842 return (FALSE);
843 }
845 $ldap->cd($src_dn);
846 $ldap->search("objectClass=*",array("dn"));
847 while($attrs = $ldap->fetch()){
848 $src = $attrs['dn'];
849 $dst = preg_replace("/".normalizePreg($src_dn)."$/",$dst_dn,$attrs['dn']);
850 $this->_copy($src,$dst);
851 }
852 return (TRUE);
853 }
856 function move($src_dn, $dst_dn)
857 {
858 /* Copy source to destination */
859 if (!$this->copy($src_dn, $dst_dn)){
860 return (FALSE);
861 }
863 /* Delete source */
864 $ldap= $this->config->get_ldap_link();
865 $ldap->rmdir_recursive($src_dn);
866 if ($ldap->error != "Success"){
867 trigger_error("Trying to delete $src_dn failed.",
868 E_USER_WARNING);
869 return (FALSE);
870 }
872 return (TRUE);
873 }
876 /* Move/Rename complete trees */
877 function recursive_move($src_dn, $dst_dn)
878 {
879 /* Check if the destination entry exists */
880 $ldap= $this->config->get_ldap_link();
882 /* Check if destination exists - abort */
883 $ldap->cat($dst_dn, array('dn'));
884 if ($ldap->fetch()){
885 trigger_error("recursive_move $dst_dn already exists.",
886 E_USER_WARNING);
887 return (FALSE);
888 }
890 /* Perform a search for all objects to be moved */
891 $objects= array();
892 $ldap->cd($src_dn);
893 $ldap->search("(objectClass=*)", array("dn"));
894 while($attrs= $ldap->fetch()){
895 $dn= $attrs['dn'];
896 $objects[$dn]= strlen($dn);
897 }
899 /* Sort objects by indent level */
900 asort($objects);
901 reset($objects);
903 /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
904 foreach ($objects as $object => $len){
905 $src= $object;
906 $dst= preg_replace("/$src_dn$/", "$dst_dn", $object);
907 if (!$this->copy($src, $dst)){
908 return (FALSE);
909 }
910 }
912 /* Remove src_dn */
913 $ldap->cd($src_dn);
914 $ldap->recursive_remove();
915 return (TRUE);
916 }
919 function handle_post_events($mode, $add_attrs= array())
920 {
921 switch ($mode){
922 case "add":
923 $this->postcreate($add_attrs);
924 break;
926 case "modify":
927 $this->postmodify($add_attrs);
928 break;
930 case "remove":
931 $this->postremove($add_attrs);
932 break;
933 }
934 }
937 function saveCopyDialog(){
938 }
941 function getCopyDialog(){
942 return(array("string"=>"","status"=>""));
943 }
946 function PrepareForCopyPaste($source)
947 {
948 $todo = $this->attributes;
949 if(isset($this->CopyPasteVars)){
950 $todo = array_merge($todo,$this->CopyPasteVars);
951 }
953 if(count($this->objectclasses)){
954 $this->is_account = TRUE;
955 foreach($this->objectclasses as $class){
956 if(!in_array($class,$source['objectClass'])){
957 $this->is_account = FALSE;
958 }
959 }
960 }
962 foreach($todo as $var){
963 if (isset($source[$var])){
964 if(isset($source[$var]['count'])){
965 if($source[$var]['count'] > 1){
966 $this->$var = array();
967 $tmp = array();
968 for($i = 0 ; $i < $source[$var]['count']; $i++){
969 $tmp = $source[$var][$i];
970 }
971 $this->$var = $tmp;
972 }else{
973 $this->$var = $source[$var][0];
974 }
975 }else{
976 $this->$var= $source[$var];
977 }
978 }
979 }
980 }
982 function tag_attrs($at, $dn= "", $tag= "", $show= false)
983 {
984 /* No dn? Self-operation... */
985 if ($dn == ""){
986 $dn= $this->dn;
988 /* No tag? Find it yourself... */
989 if ($tag == ""){
990 $len= strlen($dn);
992 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging");
993 $relevant= array();
994 foreach ($this->config->adepartments as $key => $ntag){
996 /* This one is bigger than our dn, its not relevant... */
997 if ($len <= strlen($key)){
998 continue;
999 }
1001 /* This one matches with the latter part. Break and don't fix this entry */
1002 if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){
1003 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
1004 $relevant[strlen($key)]= $ntag;
1005 continue;
1006 }
1008 }
1010 /* If we've some relevant tags to set, just get the longest one */
1011 if (count($relevant)){
1012 ksort($relevant);
1013 $tmp= array_keys($relevant);
1014 $idx= end($tmp);
1015 $tag= $relevant[$idx];
1016 $this->gosaUnitTag= $tag;
1017 }
1018 }
1019 }
1021 /* Remove tags that may already be here... */
1022 remove_objectClass("gosaAdministrativeUnitTag", &$at);
1023 if (isset($at['gosaUnitTag'])){
1024 unset($at['gosaUnitTag']);
1025 }
1027 /* Set tag? */
1028 if ($tag != ""){
1029 add_objectClass("gosaAdministrativeUnitTag", &$at);
1030 $at['gosaUnitTag']= $tag;
1031 }
1032 }
1035 /* Add possibility to stop remove process */
1036 function allow_remove()
1037 {
1038 $reason= "";
1039 return $reason;
1040 }
1043 /* Create a snapshot of the current object */
1044 function create_snapshot($type= "snapshot", $description= array())
1045 {
1047 /* Check if snapshot functionality is enabled */
1048 if(!$this->snapshotEnabled()){
1049 return;
1050 }
1052 /* Get configuration from gosa.conf */
1053 $tmp = $this->config->current;
1055 /* Create lokal ldap connection */
1056 $ldap= $this->config->get_ldap_link();
1057 $ldap->cd($this->config->current['BASE']);
1059 /* check if there are special server configurations for snapshots */
1060 if(!isset($tmp['SNAPSHOT_SERVER'])){
1062 /* Source and destination server are both the same, just copy source to dest obj */
1063 $ldap_to = $ldap;
1064 $snapldapbase = $this->config->current['BASE'];
1066 }else{
1067 $server = $tmp['SNAPSHOT_SERVER'];
1068 $user = $tmp['SNAPSHOT_USER'];
1069 $password = $tmp['SNAPSHOT_PASSWORD'];
1070 $snapldapbase = $tmp['SNAPSHOT_BASE'];
1072 $ldap_to = new LDAP($user,$password, $server);
1073 $ldap_to -> cd($snapldapbase);
1074 show_ldap_error($ldap->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$snapldapbase));
1075 }
1077 /* check if the dn exists */
1078 if ($ldap->dn_exists($this->dn)){
1080 /* Extract seconds & mysecs, they are used as entry index */
1081 list($usec, $sec)= explode(" ", microtime());
1083 /* Collect some infos */
1084 $base = $this->config->current['BASE'];
1085 $snap_base = $tmp['SNAPSHOT_BASE'];
1086 $base_of_object = preg_replace ('/^[^,]+,/i', '', $this->dn);
1087 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1089 /* Create object */
1090 #$data = preg_replace('/^dn:.*\n/', '', $ldap->gen_ldif($this->dn,"(!(objectClass=gosaDepartment))"));
1091 $data = $ldap->gen_ldif($this->dn,"(&(!(objectClass=gosaDepartment))(!(objectClass=FAIclass)))");
1092 $newName = preg_replace("/\./", "", $sec."-".$usec);
1093 $target= array();
1094 $target['objectClass'] = array("top", "gosaSnapshotObject");
1095 $target['gosaSnapshotData'] = gzcompress($data, 6);
1096 $target['gosaSnapshotType'] = $type;
1097 $target['gosaSnapshotDN'] = $this->dn;
1098 $target['description'] = $description;
1099 $target['gosaSnapshotTimestamp'] = $newName;
1101 /* Insert the new snapshot
1102 But we have to check first, if the given gosaSnapshotTimestamp
1103 is already used, in this case we should increment this value till there is
1104 an unused value. */
1105 $new_dn = "gosaSnapshotTimestamp=".$newName.",".$new_base;
1106 $ldap_to->cat($new_dn);
1107 while($ldap_to->count()){
1108 $ldap_to->cat($new_dn);
1109 $newName = preg_replace("/\./", "", $sec."-".($usec++));
1110 $new_dn = "gosaSnapshotTimestamp=".$newName.",".$new_base;
1111 $target['gosaSnapshotTimestamp'] = $newName;
1112 }
1114 /* Inset this new snapshot */
1115 $ldap_to->cd($snapldapbase);
1116 $ldap_to->create_missing_trees($snapldapbase);
1117 $ldap_to->create_missing_trees($new_base);
1118 $ldap_to->cd($new_dn);
1119 $ldap_to->add($target);
1121 show_ldap_error($ldap->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$new_base));
1122 show_ldap_error($ldap_to->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$new_base));
1123 }
1124 }
1126 function remove_snapshot($dn)
1127 {
1128 $ui = get_userinfo();
1129 $old_dn = $this->dn;
1130 $this->dn = $dn;
1131 $ldap = $this->config->get_ldap_link();
1132 $ldap->cd($this->config->current['BASE']);
1133 $ldap->rmdir_recursive($dn);
1134 $this->dn = $old_dn;
1135 }
1138 /* returns true if snapshots are enabled, and false if it is disalbed
1139 There will also be some errors psoted, if the configuration failed */
1140 function snapshotEnabled()
1141 {
1142 $tmp = $this->config->current;
1143 if(isset($tmp['ENABLE_SNAPSHOT'])){
1144 if (preg_match("/^true$/i", $tmp['ENABLE_SNAPSHOT']) || preg_match("/yes/i", $tmp['ENABLE_SNAPSHOT'])){
1146 /* Check if the snapshot_base is defined */
1147 if(!isset($tmp['SNAPSHOT_BASE'])){
1148 msg_dialog::display(_("Configuration error"), sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."),"SNAPSHOT_BASE"), ERROR_DIALOG);
1149 return(FALSE);
1150 }
1152 /* check if there are special server configurations for snapshots */
1153 if(isset($tmp['SNAPSHOT_SERVER'])){
1155 /* check if all required vars are available to create a new ldap connection */
1156 $missing = "";
1157 foreach(array("SNAPSHOT_SERVER","SNAPSHOT_USER","SNAPSHOT_PASSWORD","SNAPSHOT_BASE") as $var){
1158 if(!isset($tmp[$var])){
1159 $missing .= $var." ";
1160 msg_dialog::display(_("Configuration error"), sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."), $missing), ERROR_DIALOG);
1161 return(FALSE);
1162 }
1163 }
1164 }
1165 return(TRUE);
1166 }
1167 }
1168 return(FALSE);
1169 }
1172 /* Return available snapshots for the given base
1173 */
1174 function Available_SnapsShots($dn,$raw = false)
1175 {
1176 if(!$this->snapshotEnabled()) return(array());
1178 /* Create an additional ldap object which
1179 points to our ldap snapshot server */
1180 $ldap= $this->config->get_ldap_link();
1181 $ldap->cd($this->config->current['BASE']);
1182 $cfg= &$this->config->current;
1184 /* check if there are special server configurations for snapshots */
1186 if(isset($cfg['SERVER']) && isset($cfg['SNAPSHOT_SERVER']) && $cfg['SERVER'] == $cfg['SNAPSHOT_SERVER']){
1187 $ldap_to = $ldap;
1188 }elseif(isset($cfg['SNAPSHOT_SERVER'])){
1189 $server = $cfg['SNAPSHOT_SERVER'];
1190 $user = $cfg['SNAPSHOT_USER'];
1191 $password = $cfg['SNAPSHOT_PASSWORD'];
1192 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1194 $ldap_to = new LDAP($user,$password, $server);
1195 $ldap_to -> cd ($snapldapbase);
1196 show_ldap_error($ldap->get_error(), sprintf(_("Method get available snapshots with dn '%s' failed."),$this->dn));
1197 }else{
1198 $ldap_to = $ldap;
1199 }
1201 /* Prepare bases and some other infos */
1202 $base = $this->config->current['BASE'];
1203 $snap_base = $cfg['SNAPSHOT_BASE'];
1204 $base_of_object = preg_replace ('/^[^,]+,/i', '', $dn);
1205 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1206 $tmp = array();
1208 /* Fetch all objects with gosaSnapshotDN=$dn */
1209 $ldap_to->cd($new_base);
1210 $ldap_to->ls("(&(objectClass=gosaSnapshotObject)(gosaSnapshotDN=".$dn."))",$new_base,
1211 array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
1213 /* Put results into a list and add description if missing */
1214 while($entry = $ldap_to->fetch()){
1215 if(!isset($entry['description'][0])){
1216 $entry['description'][0] = "";
1217 }
1218 $tmp[] = $entry;
1219 }
1221 /* Return the raw array, or format the result */
1222 if($raw){
1223 return($tmp);
1224 }else{
1225 $tmp2 = array();
1226 foreach($tmp as $entry){
1227 $tmp2[base64_encode($entry['dn'])] = $entry['description'][0];
1228 }
1229 }
1230 return($tmp2);
1231 }
1234 function getAllDeletedSnapshots($base_of_object,$raw = false)
1235 {
1236 if(!$this->snapshotEnabled()) return(array());
1238 /* Create an additional ldap object which
1239 points to our ldap snapshot server */
1240 $ldap= $this->config->get_ldap_link();
1241 $ldap->cd($this->config->current['BASE']);
1242 $cfg= &$this->config->current;
1244 /* check if there are special server configurations for snapshots */
1245 if(isset($cfg['SNAPSHOT_SERVER'])){
1246 $server = $cfg['SNAPSHOT_SERVER'];
1247 $user = $cfg['SNAPSHOT_USER'];
1248 $password = $cfg['SNAPSHOT_PASSWORD'];
1249 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1250 $ldap_to = new LDAP($user,$password, $server);
1251 $ldap_to->cd ($snapldapbase);
1252 show_ldap_error($ldap_to->get_error(), sprintf(_("Method get deleted snapshots with dn '%s' failed."),$this->dn));
1253 }else{
1254 $ldap_to = $ldap;
1255 }
1257 /* Prepare bases */
1258 $base = $this->config->current['BASE'];
1259 $snap_base = $cfg['SNAPSHOT_BASE'];
1260 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1262 /* Fetch all objects and check if they do not exist anymore */
1263 $ui = get_userinfo();
1264 $tmp = array();
1265 $ldap_to->cd($new_base);
1266 $ldap_to->ls("(objectClass=gosaSnapshotObject)",$new_base,array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
1267 while($entry = $ldap_to->fetch()){
1269 $chk = str_replace($new_base,"",$entry['dn']);
1270 if(preg_match("/,ou=/",$chk)) continue;
1272 if(!isset($entry['description'][0])){
1273 $entry['description'][0] = "";
1274 }
1275 $tmp[] = $entry;
1276 }
1278 /* Check if entry still exists */
1279 foreach($tmp as $key => $entry){
1280 $ldap->cat($entry['gosaSnapshotDN'][0]);
1281 if($ldap->count()){
1282 unset($tmp[$key]);
1283 }
1284 }
1286 /* Format result as requested */
1287 if($raw) {
1288 return($tmp);
1289 }else{
1290 $tmp2 = array();
1291 foreach($tmp as $key => $entry){
1292 $tmp2[base64_encode($entry['dn'])] = $entry['description'][0];
1293 }
1294 }
1295 return($tmp2);
1296 }
1299 /* Restore selected snapshot */
1300 function restore_snapshot($dn)
1301 {
1302 if(!$this->snapshotEnabled()) return(array());
1304 $ldap= $this->config->get_ldap_link();
1305 $ldap->cd($this->config->current['BASE']);
1306 $cfg= &$this->config->current;
1308 /* check if there are special server configurations for snapshots */
1309 if(isset($cfg['SNAPSHOT_SERVER'])){
1310 $server = $cfg['SNAPSHOT_SERVER'];
1311 $user = $cfg['SNAPSHOT_USER'];
1312 $password = $cfg['SNAPSHOT_PASSWORD'];
1313 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1314 $ldap_to = new LDAP($user,$password, $server);
1315 $ldap_to->cd ($snapldapbase);
1316 show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$snapldapbase));
1317 }else{
1318 $ldap_to = $ldap;
1319 }
1321 /* Get the snapshot */
1322 $ldap_to->cat($dn);
1323 $restoreObject = $ldap_to->fetch();
1325 /* Prepare import string */
1326 $data = gzuncompress($ldap_to->get_attribute($dn,'gosaSnapshotData'));
1328 /* Import the given data */
1329 $ldap->import_complete_ldif($data,$err,false,false);
1330 show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$dn));
1331 }
1334 function showSnapshotDialog($base,$baseSuffixe)
1335 {
1336 $once = true;
1337 foreach($_POST as $name => $value){
1339 /* Create a new snapshot, display a dialog */
1340 if(preg_match("/^CreateSnapShotDialog_/",$name) && $once){
1341 $once = false;
1342 $entry = preg_replace("/^CreateSnapShotDialog_/","",$name);
1343 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
1344 $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
1345 }
1347 /* Restore a snapshot, display a dialog with all snapshots of the current object */
1348 if(preg_match("/^RestoreSnapShotDialog_/",$name) && $once){
1349 $once = false;
1350 $entry = preg_replace("/^RestoreSnapShotDialog_/","",$name);
1351 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
1352 $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
1353 $this->snapDialog->display_restore_dialog = true;
1354 }
1356 /* Restore one of the already deleted objects */
1357 if(((isset($_POST['menu_action']) && $_POST['menu_action'] == "RestoreDeletedSnapShot")
1358 || preg_match("/^RestoreDeletedSnapShot_/",$name)) && $once){
1359 $once = false;
1360 $this->snapDialog = new SnapShotDialog($this->config,"",$this);
1361 $this->snapDialog->set_snapshot_bases($baseSuffixe);
1362 $this->snapDialog->display_restore_dialog = true;
1363 $this->snapDialog->display_all_removed_objects = true;
1364 }
1366 /* Restore selected snapshot */
1367 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
1368 $once = false;
1369 $entry = preg_replace("/^RestoreSnapShot_/","",$name);
1370 $entry = base64_decode(trim(preg_replace("/_[xy]$/","",$entry)));
1371 if(!empty($entry)){
1372 $this->restore_snapshot($entry);
1373 $this->snapDialog = NULL;
1374 }
1375 }
1376 }
1378 /* Create a new snapshot requested, check
1379 the given attributes and create the snapshot*/
1380 if(isset($_POST['CreateSnapshot']) && is_object($this->snapDialog)){
1381 $this->snapDialog->save_object();
1382 $msgs = $this->snapDialog->check();
1383 if(count($msgs)){
1384 foreach($msgs as $msg){
1385 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
1386 }
1387 }else{
1388 $this->dn = $this->snapDialog->dn;
1389 $this->create_snapshot("snapshot",$this->snapDialog->CurrentDescription);
1390 $this->snapDialog = NULL;
1391 }
1392 }
1394 /* Restore is requested, restore the object with the posted dn .*/
1395 if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){
1396 }
1398 if(isset($_POST['CancelSnapshot'])){
1399 $this->snapDialog = NULL;
1400 }
1402 if(is_object($this->snapDialog )){
1403 $this->snapDialog->save_object();
1404 return($this->snapDialog->execute());
1405 }
1406 }
1409 static function plInfo()
1410 {
1411 return array();
1412 }
1415 function set_acl_base($base)
1416 {
1417 $this->acl_base= $base;
1418 }
1421 function set_acl_category($category)
1422 {
1423 $this->acl_category= "$category/";
1424 }
1427 function acl_is_writeable($attribute,$skip_write = FALSE)
1428 {
1429 $ui= get_userinfo();
1430 return preg_match('/w/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute, $skip_write));
1431 }
1434 function acl_is_readable($attribute)
1435 {
1436 $ui= get_userinfo();
1437 return preg_match('/r/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute));
1438 }
1441 function acl_is_createable()
1442 {
1443 $ui= get_userinfo();
1444 return preg_match('/c/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1445 }
1448 function acl_is_removeable()
1449 {
1450 $ui= get_userinfo();
1451 return preg_match('/d/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1452 }
1455 function acl_is_moveable()
1456 {
1457 $ui= get_userinfo();
1458 return preg_match('/m/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1459 }
1462 function acl_have_any_permissions()
1463 {
1464 }
1467 function getacl($attribute,$skip_write= FALSE)
1468 {
1469 $ui= get_userinfo();
1470 return $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute,$skip_write);
1471 }
1473 /* Get all allowed bases to move an object to or to create a new object.
1474 Idepartments also contains all base departments which lead to the allowed bases */
1475 function get_allowed_bases($category = "")
1476 {
1477 $ui = get_userinfo();
1478 $deps = array();
1480 /* Set category */
1481 if(empty($category)){
1482 $category = $this->acl_category.get_class($this);
1483 }
1485 /* Is this a new object ? Or just an edited existing object */
1486 if(!$this->initially_was_account && $this->is_account){
1487 $new = true;
1488 }else{
1489 $new = false;
1490 }
1492 $cat_bases = $ui->get_module_departments(preg_replace("/\/.*$/","",$category));
1493 foreach($this->config->idepartments as $dn => $name){
1495 if(!in_array_ics($dn,$cat_bases)){
1496 continue;
1497 }
1499 $acl = $ui->get_permissions($dn,$category);
1500 if($new && preg_match("/c/",$acl)){
1501 $deps[$dn] = $name;
1502 }elseif(!$new && preg_match("/m/",$acl)){
1503 $deps[$dn] = $name;
1504 }
1505 }
1507 /* Add current base */
1508 if(isset($this->base) && isset($this->config->idepartments[$this->base])){
1509 $deps[$this->base] = $this->config->idepartments[$this->base];
1510 }else{
1511 trigger_error("No default base found in class ".get_class($this).". ".$this->base);
1512 }
1513 return($deps);
1514 }
1517 /* This function modifies object acls too, if an object is moved.
1518 * $old_dn specifies the actually used dn
1519 * $new_dn specifies the destiantion dn
1520 */
1521 function update_acls($old_dn,$new_dn,$output_changes = FALSE)
1522 {
1523 /* Check if old_dn is empty. This should never happen */
1524 if(empty($old_dn) || empty($new_dn)){
1525 trigger_error("Failed to check acl dependencies, wrong dn given.");
1526 return;
1527 }
1529 /* Update userinfo if necessary */
1530 $ui = session::get('ui');
1531 if($ui->dn == $old_dn){
1532 $ui->dn = $new_dn;
1533 session::set('ui',$ui);
1534 new log("view","acl/".get_class($this),$this->dn,array(),"Updated current user dn from '".$old_dn."' to '".$new_dn."'");
1535 }
1537 /* Object was moved, ensure that all acls will be moved too */
1538 if($new_dn != $old_dn && $old_dn != "new"){
1540 /* get_ldap configuration */
1541 $update = array();
1542 $ldap = $this->config->get_ldap_link();
1543 $ldap->cd ($this->config->current['BASE']);
1544 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*))",array("cn","gosaAclEntry"));
1545 while($attrs = $ldap->fetch()){
1547 $acls = array();
1549 /* Walk through acls */
1550 for($i = 0 ; $i < $attrs['gosaAclEntry']['count'] ; $i ++ ){
1552 /* Reset vars */
1553 $found = false;
1555 /* Get Acl parts */
1556 $acl_parts = split(":",$attrs['gosaAclEntry'][$i]);
1558 /* Get every single member for this acl */
1559 $members = array();
1560 if(preg_match("/,/",$acl_parts[2])){
1561 $members = split(",",$acl_parts[2]);
1562 }else{
1563 $members = array($acl_parts[2]);
1564 }
1566 /* Check if member match current dn */
1567 foreach($members as $key => $member){
1568 $member = base64_decode($member);
1569 if($member == $old_dn){
1570 $found = true;
1571 $members[$key] = base64_encode($new_dn);
1572 }
1573 }
1575 /* Create new member string */
1576 $new_members = "";
1577 foreach($members as $member){
1578 $new_members .= $member.",";
1579 }
1580 $new_members = preg_replace("/,$/","",$new_members);
1581 $acl_parts[2] = $new_members;
1583 /* Reconstruckt acl entry */
1584 $acl_str ="";
1585 foreach($acl_parts as $t){
1586 $acl_str .= $t.":";
1587 }
1588 $acl_str = preg_replace("/:$/","",$acl_str);
1589 }
1591 /* Acls for this object must be adjusted */
1592 if($found){
1594 $debug_info= _("Changing ACL dn")." : <br> -"._("from")." <b> ".
1595 $old_dn."</b><br> -"._("to")." <b>".$new_dn."</b><br>";
1596 @DEBUG (DEBUG_ACL, __LINE__, __FUNCTION__, __FILE__,$debug_info,"ACL");
1598 $update[$attrs['dn']] =array();
1599 foreach($acls as $acl){
1600 $update[$attrs['dn']]['gosaAclEntry'][] = $acl;
1601 }
1602 }
1603 }
1605 /* Write updated acls */
1606 foreach($update as $dn => $attrs){
1607 $ldap->cd($dn);
1608 $ldap->modify($attrs);
1609 }
1610 }
1611 }
1615 /* This function enables the entry Serial ID check.
1616 * If an entry was edited while we have edited the entry too,
1617 * an error message will be shown.
1618 * To configure this check correctly read the FAQ.
1619 */
1620 function enable_CSN_check()
1621 {
1622 $this->CSN_check_active =TRUE;
1623 $this->entryCSN = getEntryCSN($this->dn);
1624 }
1627 /*! \brief Prepares the plugin to be used for multiple edit
1628 * Update plugin attributes with given array of attribtues.
1629 * @param array Array with attributes that must be updated.
1630 */
1631 function init_multiple_support($attrs,$all)
1632 {
1633 $ldap= $this->config->get_ldap_link();
1634 $this->multi_attrs = $attrs;
1635 $this->multi_attrs_all= $all;
1637 /* Copy needed attributes */
1638 foreach ($this->attributes as $val){
1639 $found= array_key_ics($val, $this->multi_attrs);
1640 if ($found != ""){
1641 if(isset($this->multi_attrs["$found"][0])){
1642 $this->$val= $this->multi_attrs["$found"][0];
1643 }
1644 }
1645 }
1646 }
1649 /*! \brief Enables multiple support for this plugin
1650 */
1651 function enable_multiple_support()
1652 {
1653 $this->ignore_account = TRUE;
1654 $this->multiple_support_active = TRUE;
1655 }
1658 /*! \brief Returns all values that have been modfied in multiple edit mode.
1659 @return array Cotaining all mdofied values.
1660 */
1661 function get_multi_edit_values()
1662 {
1663 $ret = array();
1664 foreach($this->attributes as $attr){
1665 if(in_array($attr,$this->multi_boxes)){
1666 $ret[$attr] = $this->$attr;
1667 }
1668 }
1669 return($ret);
1670 }
1673 /*! \brief Update class variables with values collected by multiple edit.
1674 */
1675 function set_multi_edit_values($attrs)
1676 {
1677 foreach($attrs as $name => $value){
1678 $this->$name = $value;
1679 }
1680 }
1683 /*! \brief execute plugin
1685 Generates the html output for this node
1686 */
1687 function multiple_execute()
1688 {
1689 /* This one is empty currently. Fabian - please fill in the docu code */
1690 session::set('current_class_for_help',get_class($this));
1692 /* Reset Lock message POST/GET check array, to prevent perg_match errors*/
1693 session::set('LOCK_VARS_TO_USE',array());
1694 session::set('LOCK_VARS_USED',array());
1696 return("Multiple edit is currently not implemented for this plugin.");
1697 }
1700 /*! \brief Save HTML posted data to object for multiple edit
1701 */
1702 function multiple_save_object()
1703 {
1704 if(empty($this->entryCSN) && $this->CSN_check_active){
1705 $this->entryCSN = getEntryCSN($this->dn);
1706 }
1708 /* Save values to object */
1709 $this->multi_boxes = array();
1710 foreach ($this->attributes as $val){
1712 /* Get selected checkboxes from multiple edit */
1713 if(isset($_POST["use_".$val])){
1714 $this->multi_boxes[] = $val;
1715 }
1717 if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){
1719 /* Check for modifications */
1720 if (get_magic_quotes_gpc()) {
1721 $data= stripcslashes($_POST["$val"]);
1722 } else {
1723 $data= $this->$val = $_POST["$val"];
1724 }
1725 if ($this->$val != $data){
1726 $this->is_modified= TRUE;
1727 }
1729 /* IE post fix */
1730 if(isset($data[0]) && $data[0] == chr(194)) {
1731 $data = "";
1732 }
1733 $this->$val= $data;
1734 }
1735 }
1736 }
1739 /*! \brief Returns all attributes of this plugin,
1740 to be able to detect multiple used attributes
1741 in multi_plugg::detect_multiple_used_attributes().
1742 @return array Attributes required for intialization of multi_plug
1743 */
1744 public function get_multi_init_values()
1745 {
1746 $attrs = $this->attrs;
1747 return($attrs);
1748 }
1751 /*! \brief Check given values in multiple edit
1752 @return array Error messages
1753 */
1754 function multiple_check()
1755 {
1756 $message = plugin::check();
1757 return($message);
1758 }
1759 }
1761 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1762 ?>