1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /*! \brief The plugin base class
24 \author Cajus Pollmeier <pollmeier@gonicus.de>
25 \version 2.00
26 \date 24.07.2003
28 This is the base class for all plugins. It can be used standalone or
29 can be included by the tabs class. All management should be done
30 within this class. Extend your plugins from this class.
31 */
33 class plugin
34 {
35 /*!
36 \brief Reference to parent object
38 This variable is used when the plugin is included in tabs
39 and keeps reference to the tab class. Communication to other
40 tabs is possible by 'name'. So the 'fax' plugin can ask the
41 'userinfo' plugin for the fax number.
43 \sa tab
44 */
45 var $parent= NULL;
47 /*!
48 \brief Configuration container
50 Access to global configuration
51 */
52 var $config= NULL;
54 /*!
55 \brief Mark plugin as account
57 Defines whether this plugin is defined as an account or not.
58 This has consequences for the plugin to be saved from tab
59 mode. If it is set to 'FALSE' the tab will call the delete
60 function, else the save function. Should be set to 'TRUE' if
61 the construtor detects a valid LDAP object.
63 \sa plugin::plugin()
64 */
65 var $is_account= FALSE;
66 var $initially_was_account= FALSE;
68 /*!
69 \brief Mark plugin as template
71 Defines whether we are creating a template or a normal object.
72 Has conseqences on the way execute() shows the formular and how
73 save() puts the data to LDAP.
75 \sa plugin::save() plugin::execute()
76 */
77 var $is_template= FALSE;
78 var $ignore_account= FALSE;
79 var $is_modified= FALSE;
81 /*!
82 \brief Represent temporary LDAP data
84 This is only used internally.
85 */
86 var $attrs= array();
88 /* Keep set of conflicting plugins */
89 var $conflicts= array();
91 /* Save unit tags */
92 var $gosaUnitTag= "";
93 var $skipTagging= FALSE;
95 /*!
96 \brief Used standard values
98 dn
99 */
100 var $dn= "";
101 var $uid= "";
102 var $sn= "";
103 var $givenName= "";
104 var $acl= "*none*";
105 var $dialog= FALSE;
106 var $snapDialog = NULL;
108 /* attribute list for save action */
109 var $attributes= array();
110 var $objectclasses= array();
111 var $is_new= TRUE;
112 var $saved_attributes= array();
114 var $acl_base= "";
115 var $acl_category= "";
117 /* This can be set to render the tabulators in another stylesheet */
118 var $pl_notify= FALSE;
120 /* Object entry CSN */
121 var $entryCSN = "";
122 var $CSN_check_active = FALSE;
124 /* This variable indicates that this class can handle multiple dns at once. */
125 var $multiple_support = FALSE;
126 var $multi_attrs = array();
127 var $multi_attrs_all = array();
129 /* This aviable indicates, that we are currently in multiple edit handle */
130 var $multiple_support_active = FALSE;
131 var $selected_edit_values = array();
132 var $multi_boxes = array();
134 /*! \brief plugin constructor
136 If 'dn' is set, the node loads the given 'dn' from LDAP
138 \param dn Distinguished name to initialize plugin from
139 \sa plugin()
140 */
141 function plugin (&$config, $dn= NULL, $parent= NULL)
142 {
143 /* Configuration is fine, allways */
144 $this->config= &$config;
145 $this->dn= $dn;
147 /* Handle new accounts, don't read information from LDAP */
148 if ($dn == "new"){
149 return;
150 }
152 /* Save current dn as acl_base */
153 $this->acl_base= $dn;
155 /* Get LDAP descriptor */
156 if ($dn !== NULL){
158 /* Load data to 'attrs' and save 'dn' */
159 if ($parent !== NULL){
160 $this->attrs= $parent->attrs;
161 } else {
162 $ldap= $this->config->get_ldap_link();
163 $ldap->cat ($dn);
164 $this->attrs= $ldap->fetch();
165 }
167 /* Copy needed attributes */
168 foreach ($this->attributes as $val){
169 $found= array_key_ics($val, $this->attrs);
170 if ($found != ""){
171 $this->$val= $this->attrs["$found"][0];
172 }
173 }
175 /* gosaUnitTag loading... */
176 if (isset($this->attrs['gosaUnitTag'][0])){
177 $this->gosaUnitTag= $this->attrs['gosaUnitTag'][0];
178 }
180 /* Set the template flag according to the existence of objectClass
181 gosaUserTemplate */
182 if (isset($this->attrs['objectClass'])){
183 if (in_array ("gosaUserTemplate", $this->attrs['objectClass'])){
184 $this->is_template= TRUE;
185 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
186 "found", "Template check");
187 }
188 }
190 /* Is Account? */
191 $found= TRUE;
192 foreach ($this->objectclasses as $obj){
193 if (preg_match('/top/i', $obj)){
194 continue;
195 }
196 if (!isset($this->attrs['objectClass']) || !in_array_ics ($obj, $this->attrs['objectClass'])){
197 $found= FALSE;
198 break;
199 }
200 }
201 if ($found){
202 $this->is_account= TRUE;
203 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
204 "found", "Object check");
205 }
207 /* Prepare saved attributes */
208 $this->saved_attributes= $this->attrs;
209 foreach ($this->saved_attributes as $index => $value){
210 if (preg_match('/^[0-9]+$/', $index)){
211 unset($this->saved_attributes[$index]);
212 continue;
213 }
214 if (!in_array($index, $this->attributes) && $index != "objectClass"){
215 unset($this->saved_attributes[$index]);
216 continue;
217 }
218 if (isset($this->saved_attributes[$index][0]) || $this->saved_attributes[$index]["count"] == 1){
219 $tmp= $this->saved_attributes[$index][0];
220 unset($this->saved_attributes[$index]);
221 $this->saved_attributes[$index]= $tmp;
222 continue;
223 }
225 unset($this->saved_attributes["$index"]["count"]);
226 }
227 if(isset($this->attrs['gosaUnitTag'])){
228 $this->saved_attributes['gosaUnitTag'] = $this->attrs['gosaUnitTag'][0];
229 }
230 }
232 /* Save initial account state */
233 $this->initially_was_account= $this->is_account;
234 }
237 /*! \brief execute plugin
239 Generates the html output for this node
240 */
241 function execute()
242 {
243 /* This one is empty currently. Fabian - please fill in the docu code */
244 session::set('current_class_for_help',get_class($this));
246 /* Reset Lock message POST/GET check array, to prevent perg_match errors*/
247 session::set('LOCK_VARS_TO_USE',array());
248 session::set('LOCK_VARS_USED',array());
249 }
251 /*! \brief execute plugin
252 Removes object from parent
253 */
254 function remove_from_parent()
255 {
256 /* include global link_info */
257 $ldap= $this->config->get_ldap_link();
259 /* Get current objectClasses in order to add the required ones */
260 $ldap->cat($this->dn);
261 $tmp= $ldap->fetch ();
262 $oc= array();
263 if (isset($tmp['objectClass'])){
264 $oc= $tmp['objectClass'];
265 unset($oc['count']);
266 }
268 /* Remove objectClasses from entry */
269 $ldap->cd($this->dn);
270 $this->attrs= array();
271 $this->attrs['objectClass']= array_remove_entries($this->objectclasses,$oc);
273 /* Unset attributes from entry */
274 foreach ($this->attributes as $val){
275 $this->attrs["$val"]= array();
276 }
278 /* Unset account info */
279 $this->is_account= FALSE;
281 /* Do not write in plugin base class, this must be done by
282 children, since there are normally additional attribs,
283 lists, etc. */
284 /*
285 $ldap->modify($this->attrs);
286 */
287 }
290 /*! \brief Save HTML posted data to object
291 */
292 function save_object()
293 {
294 /* Update entry CSN if it is empty. */
295 if(empty($this->entryCSN) && $this->CSN_check_active){
296 $this->entryCSN = getEntryCSN($this->dn);
297 }
299 /* Save values to object */
300 foreach ($this->attributes as $val){
301 if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){
302 /* Check for modifications */
303 if (get_magic_quotes_gpc()) {
304 $data= stripcslashes($_POST["$val"]);
305 } else {
306 $data= $this->$val = $_POST["$val"];
307 }
308 if ($this->$val != $data){
309 $this->is_modified= TRUE;
310 }
312 /* Okay, how can I explain this fix ...
313 * In firefox, disabled option fields aren't selectable ... but in IE you can select these fileds.
314 * So IE posts these 'unselectable' option, with value = chr(194)
315 * chr(194) seems to be the in between the ...option> </option.. because there is no value=".." specified in these option fields
316 * This was added for W3c compliance, but now causes these ... ldap errors ...
317 * So we set these Fields to ""; a normal empty string, and we can check these values in plugin::check() again ...
318 */
319 if(isset($data[0]) && $data[0] == chr(194)) {
320 $data = "";
321 }
322 $this->$val= $data;
323 }
324 }
325 }
328 /* Save data to LDAP, depending on is_account we save or delete */
329 function save()
330 {
331 /* include global link_info */
332 $ldap= $this->config->get_ldap_link();
334 /* Save all plugins */
335 $this->entryCSN = "";
337 /* Start with empty array */
338 $this->attrs= array();
340 /* Get current objectClasses in order to add the required ones */
341 $ldap->cat($this->dn);
343 $tmp= $ldap->fetch ();
345 $oc= array();
346 if (isset($tmp['objectClass'])){
347 $oc= $tmp["objectClass"];
348 $this->is_new= FALSE;
349 unset($oc['count']);
350 } else {
351 $this->is_new= TRUE;
352 }
354 /* Load (minimum) attributes, add missing ones */
355 $this->attrs['objectClass']= gosa_array_merge($oc,$this->objectclasses);
357 /* Copy standard attributes */
358 foreach ($this->attributes as $val){
359 if ($this->$val != ""){
360 $this->attrs["$val"]= $this->$val;
361 } elseif (!$this->is_new) {
362 $this->attrs["$val"]= array();
363 }
364 }
366 /* Handle tagging */
367 $this->tag_attrs($this->attrs);
368 }
371 function cleanup()
372 {
373 foreach ($this->attrs as $index => $value){
375 /* Convert arrays with one element to non arrays, if the saved
376 attributes are no array, too */
377 if (is_array($this->attrs[$index]) &&
378 count ($this->attrs[$index]) == 1 &&
379 isset($this->saved_attributes[$index]) &&
380 !is_array($this->saved_attributes[$index])){
382 $tmp= $this->attrs[$index][0];
383 $this->attrs[$index]= $tmp;
384 }
386 /* Remove emtpy arrays if they do not differ */
387 if (is_array($this->attrs[$index]) &&
388 count($this->attrs[$index]) == 0 &&
389 !isset($this->saved_attributes[$index])){
391 unset ($this->attrs[$index]);
392 continue;
393 }
395 /* Remove single attributes that do not differ */
396 if (!is_array($this->attrs[$index]) &&
397 isset($this->saved_attributes[$index]) &&
398 !is_array($this->saved_attributes[$index]) &&
399 $this->attrs[$index] == $this->saved_attributes[$index]){
401 unset ($this->attrs[$index]);
402 continue;
403 }
405 /* Remove arrays that do not differ */
406 if (is_array($this->attrs[$index]) &&
407 isset($this->saved_attributes[$index]) &&
408 is_array($this->saved_attributes[$index])){
410 if (!array_differs($this->attrs[$index],$this->saved_attributes[$index])){
411 unset ($this->attrs[$index]);
412 continue;
413 }
414 }
415 }
417 /* Update saved attributes and ensure that next cleanups will be successful too */
418 foreach($this->attrs as $name => $value){
419 $this->saved_attributes[$name] = $value;
420 }
421 }
423 /* Check formular input */
424 function check()
425 {
426 $message= array();
428 /* Skip if we've no config object */
429 if (!isset($this->config) || !is_object($this->config)){
430 return $message;
431 }
433 /* Find hooks entries for this class */
434 $command= $this->config->search(get_class($this), "CHECK", array('menu', 'tabs'));
436 if ($command != ""){
438 if (!check_command($command)){
439 $message[]= msgPool::cmdnotfound("CHECK", get_class($this));
440 } else {
442 /* Generate "ldif" for check hook */
443 $ldif= "dn: $this->dn\n";
445 /* ... objectClasses */
446 foreach ($this->objectclasses as $oc){
447 $ldif.= "objectClass: $oc\n";
448 }
450 /* ... attributes */
451 foreach ($this->attributes as $attr){
452 if ($this->$attr == ""){
453 continue;
454 }
455 if (is_array($this->$attr)){
456 foreach ($this->$attr as $val){
457 $ldif.= "$attr: $val\n";
458 }
459 } else {
460 $ldif.= "$attr: ".$this->$attr."\n";
461 }
462 }
464 /* Append empty line */
465 $ldif.= "\n";
467 /* Feed "ldif" into hook and retrieve result*/
468 $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
469 $fh= proc_open($command, $descriptorspec, $pipes);
470 if (is_resource($fh)) {
471 fwrite ($pipes[0], $ldif);
472 fclose($pipes[0]);
474 $result= stream_get_contents($pipes[1]);
475 if ($result != ""){
476 $message[]= $result;
477 }
479 fclose($pipes[1]);
480 fclose($pipes[2]);
481 proc_close($fh);
482 }
483 }
485 }
487 /* Check entryCSN */
488 if($this->CSN_check_active){
489 $current_csn = getEntryCSN($this->dn);
490 if($current_csn != $this->entryCSN && !empty($this->entryCSN) && !empty($current_csn)){
491 $this->entryCSN = $current_csn;
492 $message[] = _("The object has changed since opened in GOsa. All changes that may be done by others get lost if you save this entry!");
493 }
494 }
495 return ($message);
496 }
498 /* Adapt from template, using 'dn' */
499 function adapt_from_template($dn)
500 {
501 /* Include global link_info */
502 $ldap= $this->config->get_ldap_link();
504 /* Load requested 'dn' to 'attrs' */
505 $ldap->cat ($dn);
506 $this->attrs= $ldap->fetch();
508 /* Walk through attributes */
509 foreach ($this->attributes as $val){
511 if (isset($this->attrs["$val"][0])){
513 /* If attribute is set, replace dynamic parts:
514 %sn, %givenName and %uid. Fill these in our local variables. */
515 $value= $this->attrs["$val"][0];
517 foreach (array("sn", "givenName", "uid") as $repl){
518 if (preg_match("/%$repl/i", $value)){
519 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
520 }
521 }
522 $this->$val= $value;
523 }
524 }
526 /* Is Account? */
527 $found= TRUE;
528 foreach ($this->objectclasses as $obj){
529 if (preg_match('/top/i', $obj)){
530 continue;
531 }
532 if (!in_array_ics ($obj, $this->attrs['objectClass'])){
533 $found= FALSE;
534 break;
535 }
536 }
537 if ($found){
538 $this->is_account= TRUE;
539 }
540 }
542 /* Indicate whether a password change is needed or not */
543 function password_change_needed()
544 {
545 return FALSE;
546 }
549 /* Show header message for tab dialogs */
550 function show_enable_header($button_text, $text, $disabled= FALSE)
551 {
552 if (($disabled == TRUE) || (!$this->acl_is_createable())){
553 $state= "disabled";
554 } else {
555 $state= "";
556 }
557 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
558 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".$state.
559 "><p class=\"seperator\"> </p></td></tr></table>";
561 return($display);
562 }
565 /* Show header message for tab dialogs */
566 function show_disable_header($button_text, $text, $disabled= FALSE)
567 {
568 if (($disabled == TRUE) || !$this->acl_is_removeable()){
569 $state= "disabled";
570 } else {
571 $state= "";
572 }
573 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
574 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".$state.
575 "><p class=\"seperator\"> </p></td></tr></table>";
577 return($display);
578 }
581 /* Show header message for tab dialogs */
582 function show_header($button_text, $text, $disabled= FALSE)
583 {
584 echo "FIXME: show_header should be replaced by show_disable_header and show_enable_header<br>";
585 if ($disabled == TRUE){
586 $state= "disabled";
587 } else {
588 $state= "";
589 }
590 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
591 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".
592 ($this->acl_is_createable()?'':'disabled')." ".$state.
593 "><p class=\"seperator\"> </p></td></tr></table>";
595 return($display);
596 }
599 function postcreate($add_attrs= array())
600 {
601 /* Find postcreate entries for this class */
602 $command= $this->config->search(get_class($this), "POSTCREATE",array('menu', 'tabs'));
604 if ($command != ""){
606 /* Additional attributes */
607 foreach ($add_attrs as $name => $value){
608 $command= preg_replace("/%$name( |$)/", "$value ", $command);
609 }
611 /* Walk through attribute list */
612 foreach ($this->attributes as $attr){
613 if (!is_array($this->$attr)){
614 $command= preg_replace("/%$attr( |$)/", $this->$attr." ", $command);
615 }
616 }
617 $command= preg_replace("/%dn( |$)/", $this->dn." ", $command);
619 if (check_command($command)){
620 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
621 $command, "Execute");
623 exec($command);
624 } else {
625 $message[]= msgPool::cmdnotfound("POSTCREATE", get_class($this));
626 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
627 }
628 }
629 }
631 function postmodify($add_attrs= array())
632 {
633 /* Find postcreate entries for this class */
634 $command= $this->config->search(get_class($this), "POSTMODIFY",array('menu','tabs'));
636 if ($command != ""){
638 /* Additional attributes */
639 foreach ($add_attrs as $name => $value){
640 $command= preg_replace("/%$name( |$)/", "$value ", $command);
641 }
643 /* Walk through attribute list */
644 foreach ($this->attributes as $attr){
645 if (!is_array($this->$attr)){
646 $command= preg_replace("/%$attr( |$)/", $this->$attr." ", $command);
647 }
648 }
649 $command= preg_replace("/%dn( |$)/", $this->dn." ", $command);
651 if (check_command($command)){
652 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
653 $command, "Execute");
655 exec($command);
656 } else {
657 $message[]= msgPool::cmdnotfound("POSTMODIFY", get_class($this));
658 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
659 }
660 }
661 }
663 function postremove($add_attrs= array())
664 {
665 /* Find postremove entries for this class */
666 $command= $this->config->search(get_class($this), "POSTREMOVE",array('menu','tabs'));
667 if ($command != ""){
669 /* Additional attributes */
670 foreach ($add_attrs as $name => $value){
671 $command= preg_replace("/%$name( |$)/", "$value ", $command);
672 }
674 /* Walk through attribute list */
675 foreach ($this->attributes as $attr){
676 if (!is_array($this->$attr)){
677 $command= preg_replace("/%$attr( |$)/", $this->$attr." ", $command);
678 }
679 }
680 $command= preg_replace("/%dn( |$)/", $this->dn." ", $command);
682 if (check_command($command)){
683 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
684 $command, "Execute");
686 exec($command);
687 } else {
688 $message[]= msgPool::cmdnotfound("POSTREMOVE", 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->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='.@LDAP::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 /* Do not copy if only upper- lowercase has changed */
859 if(strtolower($src_dn) == strtolower($dst_dn)){
860 return(TRUE);
861 }
863 /* Copy source to destination */
864 if (!$this->copy($src_dn, $dst_dn)){
865 return (FALSE);
866 }
868 /* Delete source */
869 $ldap= $this->config->get_ldap_link();
870 $ldap->rmdir_recursive($src_dn);
871 if (!$ldap->success()){
872 trigger_error("Trying to delete $src_dn failed.",
873 E_USER_WARNING);
874 return (FALSE);
875 }
877 return (TRUE);
878 }
881 /* Move/Rename complete trees */
882 function recursive_move($src_dn, $dst_dn)
883 {
884 /* Check if the destination entry exists */
885 $ldap= $this->config->get_ldap_link();
887 /* Check if destination exists - abort */
888 $ldap->cat($dst_dn, array('dn'));
889 if ($ldap->fetch()){
890 trigger_error("recursive_move $dst_dn already exists.",
891 E_USER_WARNING);
892 return (FALSE);
893 }
895 $this->copy($src_dn, $dst_dn);
897 /* Remove src_dn */
898 $ldap->cd($src_dn);
899 $ldap->recursive_remove($src_dn);
900 return (TRUE);
901 }
904 function handle_post_events($mode, $add_attrs= array())
905 {
906 switch ($mode){
907 case "add":
908 $this->postcreate($add_attrs);
909 break;
911 case "modify":
912 $this->postmodify($add_attrs);
913 break;
915 case "remove":
916 $this->postremove($add_attrs);
917 break;
918 }
919 }
922 function saveCopyDialog(){
923 }
926 function getCopyDialog(){
927 return(array("string"=>"","status"=>""));
928 }
931 function PrepareForCopyPaste($source)
932 {
933 $todo = $this->attributes;
934 if(isset($this->CopyPasteVars)){
935 $todo = array_merge($todo,$this->CopyPasteVars);
936 }
938 if(count($this->objectclasses)){
939 $this->is_account = TRUE;
940 foreach($this->objectclasses as $class){
941 if(!in_array($class,$source['objectClass'])){
942 $this->is_account = FALSE;
943 }
944 }
945 }
947 foreach($todo as $var){
948 if (isset($source[$var])){
949 if(isset($source[$var]['count'])){
950 if($source[$var]['count'] > 1){
951 $this->$var = array();
952 $tmp = array();
953 for($i = 0 ; $i < $source[$var]['count']; $i++){
954 $tmp = $source[$var][$i];
955 }
956 $this->$var = $tmp;
957 }else{
958 $this->$var = $source[$var][0];
959 }
960 }else{
961 $this->$var= $source[$var];
962 }
963 }
964 }
965 }
967 function tag_attrs(&$at, $dn= "", $tag= "", $show= false)
968 {
969 /* Skip tagging?
970 If this is called from departmentGeneric, we have to skip this
971 tagging procedure.
972 */
973 if($this->skipTagging){
974 return;
975 }
977 /* No dn? Self-operation... */
978 if ($dn == ""){
979 $dn= $this->dn;
981 /* No tag? Find it yourself... */
982 if ($tag == ""){
983 $len= strlen($dn);
985 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging");
986 $relevant= array();
987 foreach ($this->config->adepartments as $key => $ntag){
989 /* This one is bigger than our dn, its not relevant... */
990 if ($len <= strlen($key)){
991 continue;
992 }
994 /* This one matches with the latter part. Break and don't fix this entry */
995 if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){
996 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
997 $relevant[strlen($key)]= $ntag;
998 continue;
999 }
1001 }
1003 /* If we've some relevant tags to set, just get the longest one */
1004 if (count($relevant)){
1005 ksort($relevant);
1006 $tmp= array_keys($relevant);
1007 $idx= end($tmp);
1008 $tag= $relevant[$idx];
1009 $this->gosaUnitTag= $tag;
1010 }
1011 }
1012 }
1014 /* Remove tags that may already be here... */
1015 remove_objectClass("gosaAdministrativeUnitTag", $at);
1016 if (isset($at['gosaUnitTag'])){
1017 unset($at['gosaUnitTag']);
1018 }
1020 /* Set tag? */
1021 if ($tag != ""){
1022 add_objectClass("gosaAdministrativeUnitTag", $at);
1023 $at['gosaUnitTag']= $tag;
1024 }
1026 /* Initially this object was tagged.
1027 - But now, it is no longer inside a tagged department.
1028 So force the remove of the tag.
1029 (objectClass was already removed obove)
1030 */
1031 if($tag == "" && $this->gosaUnitTag){
1032 $at['gosaUnitTag'] = array();
1033 }
1034 }
1037 /* Add possibility to stop remove process */
1038 function allow_remove()
1039 {
1040 $reason= "";
1041 return $reason;
1042 }
1045 /* Create a snapshot of the current object */
1046 function create_snapshot($type= "snapshot", $description= array())
1047 {
1049 /* Check if snapshot functionality is enabled */
1050 if(!$this->snapshotEnabled()){
1051 return;
1052 }
1054 /* Get configuration from gosa.conf */
1055 $tmp = $this->config->current;
1057 /* Create lokal ldap connection */
1058 $ldap= $this->config->get_ldap_link();
1059 $ldap->cd($this->config->current['BASE']);
1061 /* check if there are special server configurations for snapshots */
1062 if(!isset($tmp['SNAPSHOT_SERVER'])){
1064 /* Source and destination server are both the same, just copy source to dest obj */
1065 $ldap_to = $ldap;
1066 $snapldapbase = $this->config->current['BASE'];
1068 }else{
1069 $server = $tmp['SNAPSHOT_SERVER'];
1070 $user = $tmp['SNAPSHOT_USER'];
1071 $password = $tmp['SNAPSHOT_PASSWORD'];
1072 $snapldapbase = $tmp['SNAPSHOT_BASE'];
1074 $ldap_to = new ldapMultipelxer(new LDAP($user,$password, $server));
1075 $ldap_to -> cd($snapldapbase);
1077 if (!$ldap_to->success()){
1078 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $snapldapbase, "", get_class()));
1079 }
1081 }
1083 /* check if the dn exists */
1084 if ($ldap->dn_exists($this->dn)){
1086 /* Extract seconds & mysecs, they are used as entry index */
1087 list($usec, $sec)= explode(" ", microtime());
1089 /* Collect some infos */
1090 $base = $this->config->current['BASE'];
1091 $snap_base = $tmp['SNAPSHOT_BASE'];
1092 $base_of_object = preg_replace ('/^[^,]+,/i', '', $this->dn);
1093 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1095 /* Create object */
1096 #$data = preg_replace('/^dn:.*\n/', '', $ldap->gen_ldif($this->dn,"(!(objectClass=gosaDepartment))"));
1097 $data = $ldap->gen_ldif($this->dn,"(&(!(objectClass=gosaDepartment))(!(objectClass=FAIclass)))");
1098 $newName = preg_replace("/\./", "", $sec."-".$usec);
1099 $target= array();
1100 $target['objectClass'] = array("top", "gosaSnapshotObject");
1101 $target['gosaSnapshotData'] = gzcompress($data, 6);
1102 $target['gosaSnapshotType'] = $type;
1103 $target['gosaSnapshotDN'] = $this->dn;
1104 $target['description'] = $description;
1105 $target['gosaSnapshotTimestamp'] = $newName;
1107 /* Insert the new snapshot
1108 But we have to check first, if the given gosaSnapshotTimestamp
1109 is already used, in this case we should increment this value till there is
1110 an unused value. */
1111 $new_dn = "gosaSnapshotTimestamp=".$newName.",".$new_base;
1112 $ldap_to->cat($new_dn);
1113 while($ldap_to->count()){
1114 $ldap_to->cat($new_dn);
1115 $newName = preg_replace("/\./", "", $sec."-".($usec++));
1116 $new_dn = "gosaSnapshotTimestamp=".$newName.",".$new_base;
1117 $target['gosaSnapshotTimestamp'] = $newName;
1118 }
1120 /* Inset this new snapshot */
1121 $ldap_to->cd($snapldapbase);
1122 $ldap_to->create_missing_trees($snapldapbase);
1123 $ldap_to->create_missing_trees($new_base);
1124 $ldap_to->cd($new_dn);
1125 $ldap_to->add($target);
1126 if (!$ldap_to->success()){
1127 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $new_dn, LDAP_ADD, get_class()));
1128 }
1130 if (!$ldap->success()){
1131 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $new_base, "", get_class()));
1132 }
1134 }
1135 }
1137 function remove_snapshot($dn)
1138 {
1139 $ui = get_userinfo();
1140 $old_dn = $this->dn;
1141 $this->dn = $dn;
1142 $ldap = $this->config->get_ldap_link();
1143 $ldap->cd($this->config->current['BASE']);
1144 $ldap->rmdir_recursive($dn);
1145 $this->dn = $old_dn;
1146 }
1149 /* returns true if snapshots are enabled, and false if it is disalbed
1150 There will also be some errors psoted, if the configuration failed */
1151 function snapshotEnabled()
1152 {
1153 $tmp = $this->config->current;
1154 if(isset($tmp['ENABLE_SNAPSHOT'])){
1155 if (preg_match("/^true$/i", $tmp['ENABLE_SNAPSHOT']) || preg_match("/yes/i", $tmp['ENABLE_SNAPSHOT'])){
1157 /* Check if the snapshot_base is defined */
1158 if(!isset($tmp['SNAPSHOT_BASE'])){
1159 msg_dialog::display(_("Configuration error"), sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."),"SNAPSHOT_BASE"), ERROR_DIALOG);
1160 return(FALSE);
1161 }
1163 /* check if there are special server configurations for snapshots */
1164 if(isset($tmp['SNAPSHOT_SERVER'])){
1166 /* check if all required vars are available to create a new ldap connection */
1167 $missing = "";
1168 foreach(array("SNAPSHOT_SERVER","SNAPSHOT_USER","SNAPSHOT_PASSWORD","SNAPSHOT_BASE") as $var){
1169 if(!isset($tmp[$var])){
1170 $missing .= $var." ";
1171 msg_dialog::display(_("Configuration error"), sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."), $missing), ERROR_DIALOG);
1172 return(FALSE);
1173 }
1174 }
1175 }
1176 return(TRUE);
1177 }
1178 }
1179 return(FALSE);
1180 }
1183 /* Return available snapshots for the given base
1184 */
1185 function Available_SnapsShots($dn,$raw = false)
1186 {
1187 if(!$this->snapshotEnabled()) return(array());
1189 /* Create an additional ldap object which
1190 points to our ldap snapshot server */
1191 $ldap= $this->config->get_ldap_link();
1192 $ldap->cd($this->config->current['BASE']);
1193 $cfg= &$this->config->current;
1195 /* check if there are special server configurations for snapshots */
1197 if(isset($cfg['SERVER']) && isset($cfg['SNAPSHOT_SERVER']) && $cfg['SERVER'] == $cfg['SNAPSHOT_SERVER']){
1198 $ldap_to = $ldap;
1199 }elseif(isset($cfg['SNAPSHOT_SERVER'])){
1200 $server = $cfg['SNAPSHOT_SERVER'];
1201 $user = $cfg['SNAPSHOT_USER'];
1202 $password = $cfg['SNAPSHOT_PASSWORD'];
1203 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1205 $ldap_to = new ldapMultiplexer(new LDAP($user,$password, $server));
1206 $ldap_to -> cd ($snapldapbase);
1207 if (!$ldap_to->success()){
1208 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $snapldapbase, "", get_class()));
1209 }
1210 }else{
1211 $ldap_to = $ldap;
1212 }
1214 /* Prepare bases and some other infos */
1215 $base = $this->config->current['BASE'];
1216 $snap_base = $cfg['SNAPSHOT_BASE'];
1217 $base_of_object = preg_replace ('/^[^,]+,/i', '', $dn);
1218 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1219 $tmp = array();
1221 /* Fetch all objects with gosaSnapshotDN=$dn */
1222 $ldap_to->cd($new_base);
1223 $ldap_to->ls("(&(objectClass=gosaSnapshotObject)(gosaSnapshotDN=".$dn."))",$new_base,
1224 array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
1226 /* Put results into a list and add description if missing */
1227 while($entry = $ldap_to->fetch()){
1228 if(!isset($entry['description'][0])){
1229 $entry['description'][0] = "";
1230 }
1231 $tmp[] = $entry;
1232 }
1234 /* Return the raw array, or format the result */
1235 if($raw){
1236 return($tmp);
1237 }else{
1238 $tmp2 = array();
1239 foreach($tmp as $entry){
1240 $tmp2[base64_encode($entry['dn'])] = $entry['description'][0];
1241 }
1242 }
1243 return($tmp2);
1244 }
1247 function getAllDeletedSnapshots($base_of_object,$raw = false)
1248 {
1249 if(!$this->snapshotEnabled()) return(array());
1251 /* Create an additional ldap object which
1252 points to our ldap snapshot server */
1253 $ldap= $this->config->get_ldap_link();
1254 $ldap->cd($this->config->current['BASE']);
1255 $cfg= &$this->config->current;
1257 /* check if there are special server configurations for snapshots */
1258 if(isset($cfg['SNAPSHOT_SERVER'])){
1259 $server = $cfg['SNAPSHOT_SERVER'];
1260 $user = $cfg['SNAPSHOT_USER'];
1261 $password = $cfg['SNAPSHOT_PASSWORD'];
1262 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1263 $ldap_to = new ldapMultiplexer(new LDAP($user,$password, $server));
1264 $ldap_to->cd ($snapldapbase);
1265 if (!$ldap_to->success()){
1266 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $snapldapbase, "", get_class()));
1267 }
1268 }else{
1269 $ldap_to = $ldap;
1270 }
1272 /* Prepare bases */
1273 $base = $this->config->current['BASE'];
1274 $snap_base = $cfg['SNAPSHOT_BASE'];
1275 $new_base = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1277 /* Fetch all objects and check if they do not exist anymore */
1278 $ui = get_userinfo();
1279 $tmp = array();
1280 $ldap_to->cd($new_base);
1281 $ldap_to->ls("(objectClass=gosaSnapshotObject)",$new_base,array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
1282 while($entry = $ldap_to->fetch()){
1284 $chk = str_replace($new_base,"",$entry['dn']);
1285 if(preg_match("/,ou=/",$chk)) continue;
1287 if(!isset($entry['description'][0])){
1288 $entry['description'][0] = "";
1289 }
1290 $tmp[] = $entry;
1291 }
1293 /* Check if entry still exists */
1294 foreach($tmp as $key => $entry){
1295 $ldap->cat($entry['gosaSnapshotDN'][0]);
1296 if($ldap->count()){
1297 unset($tmp[$key]);
1298 }
1299 }
1301 /* Format result as requested */
1302 if($raw) {
1303 return($tmp);
1304 }else{
1305 $tmp2 = array();
1306 foreach($tmp as $key => $entry){
1307 $tmp2[base64_encode($entry['dn'])] = $entry['description'][0];
1308 }
1309 }
1310 return($tmp2);
1311 }
1314 /* Restore selected snapshot */
1315 function restore_snapshot($dn)
1316 {
1317 if(!$this->snapshotEnabled()) return(array());
1319 $ldap= $this->config->get_ldap_link();
1320 $ldap->cd($this->config->current['BASE']);
1321 $cfg= &$this->config->current;
1323 /* check if there are special server configurations for snapshots */
1324 if(isset($cfg['SNAPSHOT_SERVER'])){
1325 $server = $cfg['SNAPSHOT_SERVER'];
1326 $user = $cfg['SNAPSHOT_USER'];
1327 $password = $cfg['SNAPSHOT_PASSWORD'];
1328 $snapldapbase = $cfg['SNAPSHOT_BASE'];
1329 $ldap_to = new ldapMultiplexer(new LDAP($user,$password, $server));
1330 $ldap_to->cd ($snapldapbase);
1331 if (!$ldap_to->success()){
1332 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $snapldapbase, "", get_class()));
1333 }
1334 }else{
1335 $ldap_to = $ldap;
1336 }
1338 /* Get the snapshot */
1339 $ldap_to->cat($dn);
1340 $restoreObject = $ldap_to->fetch();
1342 /* Prepare import string */
1343 $data = gzuncompress($ldap_to->get_attribute($dn,'gosaSnapshotData'));
1345 /* Import the given data */
1346 $ldap->import_complete_ldif($data,$err,false,false);
1347 if (!$ldap->success()){
1348 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, "", get_class()));
1349 }
1350 }
1353 function showSnapshotDialog($base,$baseSuffixe)
1354 {
1355 $once = true;
1356 foreach($_POST as $name => $value){
1358 /* Create a new snapshot, display a dialog */
1359 if(preg_match("/^CreateSnapShotDialog_/",$name) && $once){
1360 $once = false;
1361 $entry = preg_replace("/^CreateSnapShotDialog_/","",$name);
1362 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
1363 $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
1364 }
1366 /* Restore a snapshot, display a dialog with all snapshots of the current object */
1367 if(preg_match("/^RestoreSnapShotDialog_/",$name) && $once){
1368 $once = false;
1369 $entry = preg_replace("/^RestoreSnapShotDialog_/","",$name);
1370 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
1371 $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
1372 $this->snapDialog->display_restore_dialog = true;
1373 }
1375 /* Restore one of the already deleted objects */
1376 if(((isset($_POST['menu_action']) && $_POST['menu_action'] == "RestoreDeletedSnapShot")
1377 || preg_match("/^RestoreDeletedSnapShot_/",$name)) && $once){
1378 $once = false;
1379 $this->snapDialog = new SnapShotDialog($this->config,"",$this);
1380 $this->snapDialog->set_snapshot_bases($baseSuffixe);
1381 $this->snapDialog->display_restore_dialog = true;
1382 $this->snapDialog->display_all_removed_objects = true;
1383 }
1385 /* Restore selected snapshot */
1386 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
1387 $once = false;
1388 $entry = preg_replace("/^RestoreSnapShot_/","",$name);
1389 $entry = base64_decode(trim(preg_replace("/_[xy]$/","",$entry)));
1390 if(!empty($entry)){
1391 $this->restore_snapshot($entry);
1392 $this->snapDialog = NULL;
1393 }
1394 }
1395 }
1397 /* Create a new snapshot requested, check
1398 the given attributes and create the snapshot*/
1399 if(isset($_POST['CreateSnapshot']) && is_object($this->snapDialog)){
1400 $this->snapDialog->save_object();
1401 $msgs = $this->snapDialog->check();
1402 if(count($msgs)){
1403 foreach($msgs as $msg){
1404 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
1405 }
1406 }else{
1407 $this->dn = $this->snapDialog->dn;
1408 $this->create_snapshot("snapshot",$this->snapDialog->CurrentDescription);
1409 $this->snapDialog = NULL;
1410 }
1411 }
1413 /* Restore is requested, restore the object with the posted dn .*/
1414 if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){
1415 }
1417 if(isset($_POST['CancelSnapshot'])){
1418 $this->snapDialog = NULL;
1419 }
1421 if(is_object($this->snapDialog )){
1422 $this->snapDialog->save_object();
1423 return($this->snapDialog->execute());
1424 }
1425 }
1428 static function plInfo()
1429 {
1430 return array();
1431 }
1434 function set_acl_base($base)
1435 {
1436 $this->acl_base= $base;
1437 }
1440 function set_acl_category($category)
1441 {
1442 $this->acl_category= "$category/";
1443 }
1446 function acl_is_writeable($attribute,$skip_write = FALSE)
1447 {
1448 $ui= get_userinfo();
1449 return preg_match('/w/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute, $skip_write));
1450 }
1453 function acl_is_readable($attribute)
1454 {
1455 $ui= get_userinfo();
1456 return preg_match('/r/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute));
1457 }
1460 function acl_is_createable()
1461 {
1462 $ui= get_userinfo();
1463 return preg_match('/c/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1464 }
1467 function acl_is_removeable()
1468 {
1469 $ui= get_userinfo();
1470 return preg_match('/d/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1471 }
1474 function acl_is_moveable()
1475 {
1476 $ui= get_userinfo();
1477 return preg_match('/m/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1478 }
1481 function acl_have_any_permissions()
1482 {
1483 }
1486 function getacl($attribute,$skip_write= FALSE)
1487 {
1488 $ui= get_userinfo();
1489 return $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute,$skip_write);
1490 }
1492 /* Get all allowed bases to move an object to or to create a new object.
1493 Idepartments also contains all base departments which lead to the allowed bases */
1494 function get_allowed_bases($category = "")
1495 {
1496 $ui = get_userinfo();
1497 $deps = array();
1499 /* Set category */
1500 if(empty($category)){
1501 $category = $this->acl_category.get_class($this);
1502 }
1504 /* Is this a new object ? Or just an edited existing object */
1505 if(!$this->initially_was_account && $this->is_account){
1506 $new = true;
1507 }else{
1508 $new = false;
1509 }
1511 $cat_bases = $ui->get_module_departments(preg_replace("/\/.*$/","",$category));
1512 foreach($this->config->idepartments as $dn => $name){
1514 if(!in_array_ics($dn,$cat_bases)){
1515 continue;
1516 }
1518 $acl = $ui->get_permissions($dn,$category);
1519 if($new && preg_match("/c/",$acl)){
1520 $deps[$dn] = $name;
1521 }elseif(!$new && preg_match("/m/",$acl)){
1522 $deps[$dn] = $name;
1523 }
1524 }
1526 /* Add current base */
1527 if(isset($this->base) && isset($this->config->idepartments[$this->base])){
1528 $deps[$this->base] = $this->config->idepartments[$this->base];
1529 }else{
1530 trigger_error("No default base found in class ".get_class($this).". ".$this->base);
1531 }
1532 return($deps);
1533 }
1536 /* This function modifies object acls too, if an object is moved.
1537 * $old_dn specifies the actually used dn
1538 * $new_dn specifies the destiantion dn
1539 */
1540 function update_acls($old_dn,$new_dn,$output_changes = FALSE)
1541 {
1542 /* Check if old_dn is empty. This should never happen */
1543 if(empty($old_dn) || empty($new_dn)){
1544 trigger_error("Failed to check acl dependencies, wrong dn given.");
1545 return;
1546 }
1548 /* Update userinfo if necessary */
1549 $ui = session::get('ui');
1550 if($ui->dn == $old_dn){
1551 $ui->dn = $new_dn;
1552 session::set('ui',$ui);
1553 new log("view","acl/".get_class($this),$this->dn,array(),"Updated current user dn from '".$old_dn."' to '".$new_dn."'");
1554 }
1556 /* Object was moved, ensure that all acls will be moved too */
1557 if($new_dn != $old_dn && $old_dn != "new"){
1559 /* get_ldap configuration */
1560 $update = array();
1561 $ldap = $this->config->get_ldap_link();
1562 $ldap->cd ($this->config->current['BASE']);
1563 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*))",array("cn","gosaAclEntry"));
1564 while($attrs = $ldap->fetch()){
1566 $acls = array();
1568 /* Walk through acls */
1569 for($i = 0 ; $i < $attrs['gosaAclEntry']['count'] ; $i ++ ){
1571 /* Reset vars */
1572 $found = false;
1574 /* Get Acl parts */
1575 $acl_parts = split(":",$attrs['gosaAclEntry'][$i]);
1577 /* Get every single member for this acl */
1578 $members = array();
1579 if(preg_match("/,/",$acl_parts[2])){
1580 $members = split(",",$acl_parts[2]);
1581 }else{
1582 $members = array($acl_parts[2]);
1583 }
1585 /* Check if member match current dn */
1586 foreach($members as $key => $member){
1587 $member = base64_decode($member);
1588 if($member == $old_dn){
1589 $found = true;
1590 $members[$key] = base64_encode($new_dn);
1591 }
1592 }
1594 /* Create new member string */
1595 $new_members = "";
1596 foreach($members as $member){
1597 $new_members .= $member.",";
1598 }
1599 $new_members = preg_replace("/,$/","",$new_members);
1600 $acl_parts[2] = $new_members;
1602 /* Reconstruckt acl entry */
1603 $acl_str ="";
1604 foreach($acl_parts as $t){
1605 $acl_str .= $t.":";
1606 }
1607 $acl_str = preg_replace("/:$/","",$acl_str);
1608 }
1610 /* Acls for this object must be adjusted */
1611 if($found){
1613 $debug_info= _("Changing ACL dn")." : <br> -"._("from")." <b> ".
1614 $old_dn."</b><br> -"._("to")." <b>".$new_dn."</b><br>";
1615 @DEBUG (DEBUG_ACL, __LINE__, __FUNCTION__, __FILE__,$debug_info,"ACL");
1617 $update[$attrs['dn']] =array();
1618 foreach($acls as $acl){
1619 $update[$attrs['dn']]['gosaAclEntry'][] = $acl;
1620 }
1621 }
1622 }
1624 /* Write updated acls */
1625 foreach($update as $dn => $attrs){
1626 $ldap->cd($dn);
1627 $ldap->modify($attrs);
1628 }
1629 }
1630 }
1634 /* This function enables the entry Serial ID check.
1635 * If an entry was edited while we have edited the entry too,
1636 * an error message will be shown.
1637 * To configure this check correctly read the FAQ.
1638 */
1639 function enable_CSN_check()
1640 {
1641 $this->CSN_check_active =TRUE;
1642 $this->entryCSN = getEntryCSN($this->dn);
1643 }
1646 /*! \brief Prepares the plugin to be used for multiple edit
1647 * Update plugin attributes with given array of attribtues.
1648 * @param array Array with attributes that must be updated.
1649 */
1650 function init_multiple_support($attrs,$all)
1651 {
1652 $ldap= $this->config->get_ldap_link();
1653 $this->multi_attrs = $attrs;
1654 $this->multi_attrs_all= $all;
1656 /* Copy needed attributes */
1657 foreach ($this->attributes as $val){
1658 $found= array_key_ics($val, $this->multi_attrs);
1659 if ($found != ""){
1660 if(isset($this->multi_attrs["$found"][0])){
1661 $this->$val= $this->multi_attrs["$found"][0];
1662 }
1663 }
1664 }
1665 }
1668 /*! \brief Enables multiple support for this plugin
1669 */
1670 function enable_multiple_support()
1671 {
1672 $this->ignore_account = TRUE;
1673 $this->multiple_support_active = TRUE;
1674 }
1677 /*! \brief Returns all values that have been modfied in multiple edit mode.
1678 @return array Cotaining all mdofied values.
1679 */
1680 function get_multi_edit_values()
1681 {
1682 $ret = array();
1683 foreach($this->attributes as $attr){
1684 if(in_array($attr,$this->multi_boxes)){
1685 $ret[$attr] = $this->$attr;
1686 }
1687 }
1688 return($ret);
1689 }
1692 /*! \brief Update class variables with values collected by multiple edit.
1693 */
1694 function set_multi_edit_values($attrs)
1695 {
1696 foreach($attrs as $name => $value){
1697 $this->$name = $value;
1698 }
1699 }
1702 /*! \brief execute plugin
1704 Generates the html output for this node
1705 */
1706 function multiple_execute()
1707 {
1708 /* This one is empty currently. Fabian - please fill in the docu code */
1709 session::set('current_class_for_help',get_class($this));
1711 /* Reset Lock message POST/GET check array, to prevent perg_match errors*/
1712 session::set('LOCK_VARS_TO_USE',array());
1713 session::set('LOCK_VARS_USED',array());
1715 return("Multiple edit is currently not implemented for this plugin.");
1716 }
1719 /*! \brief Save HTML posted data to object for multiple edit
1720 */
1721 function multiple_save_object()
1722 {
1723 if(empty($this->entryCSN) && $this->CSN_check_active){
1724 $this->entryCSN = getEntryCSN($this->dn);
1725 }
1727 /* Save values to object */
1728 $this->multi_boxes = array();
1729 foreach ($this->attributes as $val){
1731 /* Get selected checkboxes from multiple edit */
1732 if(isset($_POST["use_".$val])){
1733 $this->multi_boxes[] = $val;
1734 }
1736 if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){
1738 /* Check for modifications */
1739 if (get_magic_quotes_gpc()) {
1740 $data= stripcslashes($_POST["$val"]);
1741 } else {
1742 $data= $this->$val = $_POST["$val"];
1743 }
1744 if ($this->$val != $data){
1745 $this->is_modified= TRUE;
1746 }
1748 /* IE post fix */
1749 if(isset($data[0]) && $data[0] == chr(194)) {
1750 $data = "";
1751 }
1752 $this->$val= $data;
1753 }
1754 }
1755 }
1758 /*! \brief Returns all attributes of this plugin,
1759 to be able to detect multiple used attributes
1760 in multi_plugg::detect_multiple_used_attributes().
1761 @return array Attributes required for intialization of multi_plug
1762 */
1763 public function get_multi_init_values()
1764 {
1765 $attrs = $this->attrs;
1766 return($attrs);
1767 }
1770 /*! \brief Check given values in multiple edit
1771 @return array Error messages
1772 */
1773 function multiple_check()
1774 {
1775 $message = plugin::check();
1776 return($message);
1777 }
1778 }
1780 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1781 ?>