Code

Updated class_config
[gosa.git] / include / class_config.inc
1 <?php
2 /*
3  * This code is part of GOsa (https://gosa.gonicus.de)
4  * Copyright (C) 2003-2006 - Cajus Pollmeier <pollmeier@gonicus.de>
5  *
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.
10  *
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.
15  *
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 class config  {
23   /* XML parser */
24   var $parser;
25   var $config_found= FALSE;
26   var $tags= array();
27   var $level= 0;
28   var $gpc= 0;
29   var $section= "";
30   var $currentLocation= "";
32   /* Selected connection */
33   var $current= array();
35   /* Link to LDAP-server */
36   var $ldap= NULL;
37   var $referrals= array();
39   /* Configuration data */
40   var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(),
41       'MAIN' => array(),
42       'MENU' => array(), 'SERVICE' => array());
43   var $basedir= "";
45   /* Keep a copy of the current deparment list */
46   var $departments= array();
47   var $idepartments= array();
48   var $adepartments= array();
49   var $tdepartments= array();
51   function config($filename, $basedir= "")
52   {
53     $this->parser = xml_parser_create();
54     $this->basedir= $basedir;
56     xml_set_object($this->parser, $this);
57     xml_set_element_handler($this->parser, "tag_open", "tag_close");
59     /* Parse config file directly? */
60     if ($filename != ""){
61       $this->parse($filename);
62     }
63   }
65   function parse($filename)
66   { 
67     $fh= fopen($filename, "r"); 
68     $xmldata= fread($fh, 100000);
69     fclose($fh); 
70     if(!xml_parse($this->parser, chop($xmldata))){
71       print_red(sprintf(_("XML error in %s: %s at line %d"),
72             CONFIG_FILE,
73             xml_error_string(xml_get_error_code($this->parser)),
74             xml_get_current_line_number($this->parser)));
75       echo $_SESSION['errors'];
76       exit;
77     }
78   }
80   function tag_open($parser, $tag, $attrs)
81   { 
82     /* Save last and current tag for reference */
83     $this->tags[$this->level]= $tag;
84     $this->level++;
86     /* Trigger on CONF section */
87     if ($tag == 'CONF'){
88       $this->config_found= TRUE;
89     }
91     /* Return if we're not in config section */
92     if (!$this->config_found){
93       return;
94     }
96     /* yes/no to true/false and upper case TRUE to true and so on*/
97     foreach($attrs as $name => $value){
98       if(preg_match("/^(true|yes)$/i",$value)){
99         $attrs[$name] = "true";
100       }elseif(preg_match("/^(false|no)$/i",$value)){
101         $attrs[$name] = "false";
102       } 
103     }
105     /* Look through attributes */
106     switch ($this->tags[$this->level-1]){
108       /* Handle tab section */
109       case 'TAB':       $name= $this->tags[$this->level-2];
111                   /* Create new array? */
112                   if (!isset($this->data['TABS'][$name])){
113                     $this->data['TABS'][$name]= array();
114                   }
116                   /* Add elements */
117                   $this->data['TABS'][$name][]= $attrs;
118                   break;
120                   /* Handle location */
121       case 'LOCATION':
122                   if ($this->tags[$this->level-2] == 'MAIN'){
123                     $name= $attrs['NAME'];
124                     $this->currentLocation= $name;
126                     /* Add location elements */
127                     $this->data['LOCATIONS'][$name]= $attrs;
128                   }
129                   break;
131                   /* Handle referral tags */
132       case 'REFERRAL':
133                   if ($this->tags[$this->level-2] == 'LOCATION'){
134                     $url= $attrs['URL'];
135                     $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
137                     /* Add location elements */
138                     if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
139                       $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
140                     }
142                     $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
143                   }
144                   break;
146                   /* Load main parameters */
147       case 'MAIN':
148                   $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
149                   break;
151                   /* Load menu */
152       case 'SECTION':
153                   if ($this->tags[$this->level-2] == 'MENU'){
154                     $this->section= $attrs['NAME'];
155                     $this->data['MENU'][$this->section]= array(); ;
156                   }
157                   break;
159                   /* Inser plugins */
160       case 'PLUGIN':
161                   if ($this->tags[$this->level-3] == 'MENU' &&
162                       $this->tags[$this->level-2] == 'SECTION'){
164                     $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
165                   }
166                   if ($this->tags[$this->level-2] == 'SERVICEMENU'){
167                     $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
168                   }
169                   break;
170     }
171   }
173   function tag_close($parser, $tag)
174   {
175     /* Close config section */
176     if ($tag == 'CONF'){
177       $this->config_found= FALSE;
178     }
179     $this->level--;
180   }
182   function get_ldap_link($sizelimit= FALSE)
183   {
185     if(!is_resource($this->ldap->cid)){
187       /* Build new connection */
188       $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
189           $this->current['ADMIN'], $this->current['PASSWORD']);
191       /* Check for connection */
192       if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
193         $smarty= get_smarty();
194         print_red (_("Can't bind to LDAP. Please contact the system administrator."));
195         $smarty->display (get_template_path('headers.tpl'));
196         echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
197         exit();
198       }
200       if (!isset($_SESSION['size_limit'])){
201         $_SESSION['size_limit']= $this->current['SIZELIMIT'];
202         $_SESSION['size_ignore']= $this->current['SIZEIGNORE'];
203       }
205       if ($sizelimit){
206         $this->ldap->set_size_limit($_SESSION['size_limit']);
207       } else {
208         $this->ldap->set_size_limit(0);
209       }
211       /* Move referrals */
212       if (!isset($this->current['REFERRAL'])){
213         $this->ldap->referrals= array();
214       } else {
215         $this->ldap->referrals= $this->current['REFERRAL'];
216       }
217     }
218     return ($this->ldap);
219   }
221   function set_current($name)
222   {
223     $this->current= $this->data['LOCATIONS'][$name];
224     if (!isset($this->current['PEOPLE'])){
225       $this->current['PEOPLE']= "ou=people";
226     }
227     if (!isset($this->current['GROUPS'])){
228       $this->current['GROUPS']= "ou=groups";
229     }
231     if (isset($this->current['INITIAL_BASE'])){
232       $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
233     }
235     /* Remove possibly added ',' from end of group and people ou */
236     $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
237     $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
239     if (!isset($this->current['WINSTATIONS'])){
240       $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
241     }
242     if (!isset($this->current['HASH'])){
243       $this->current['HASH']= "crypt";
244     }
245     if (!isset($this->current['DNMODE'])){
246       $this->current['DNMODE']= "cn";
247     }
248     if (!isset($this->current['MINID'])){
249       $this->current['MINID']= 100;
250     }
251     if (!isset($this->current['SIZELIMIT'])){
252       $this->current['SIZELIMIT']= 200;
253     }
254     if (!isset($this->current['SIZEINGORE'])){
255       $this->current['SIZEIGNORE']= TRUE;
256     } else {
257       if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
258         $this->current['SIZEIGNORE']= TRUE;
259       } else {
260         $this->current['SIZEIGNORE']= FALSE;
261       }
262     }
264     /* Sort referrals, if present */
265     if (isset ($this->current['REFERRAL'])){
266       $bases= array();
267       $servers= array();
268       foreach ($this->current['REFERRAL'] as $ref){
269         $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
270         $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
271         $bases[$base]= strlen($base);
272         $servers[$base]= $server;
273       }
274       asort($bases);
275       reset($bases);
276     }
278     /* SERVER not defined? Load the one with the shortest base */
279     if (!isset($this->current['SERVER'])){
280       $this->current['SERVER']= $servers[key($bases)];
281     }
283     /* BASE not defined? Load the one with the shortest base */
284     if (!isset($this->current['BASE'])){
285       $this->current['BASE']= key($bases);
286     }
288     /* Convert BASE to have escaped special characters */
289     $this->current['BASE']= @LDAP::convert($this->current['BASE']);
291     /* Parse LDAP referral informations */
292     if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
293       $url= $this->current['SERVER'];
294       $referral= $this->current['REFERRAL'][$url];
295       $this->current['ADMIN']= $referral['ADMIN'];
296       $this->current['PASSWORD']= $referral['PASSWORD'];
297     }
299     /* Possibly load kerberos style */
300     if (isset($this->current['KRBSASL'])){
301       if (preg_match('/^(yes|true)$/i', $this->current['KRBSASL'])){
302         $this->current['KRBSASL']= "sasl";
303       } else {
304         $this->current['KRBSASL']= "kerberos";
305       }
306     } else {
307       $this->current['KRBSASL']= "kerberos";
308     }
310     /* Load server informations */
311     $this->load_servers();
312   }
314   function load_servers ()
315   {
316     /* Only perform actions if current is set */
317     if ($this->current == NULL){
318       return;
319     }
321     /* Fill imap servers */
322     $ldap= $this->get_ldap_link();
323     $ldap->cd ($this->current['BASE']);
324     if (!isset($this->current['MAILMETHOD'])){
325         $this->current['MAILMETHOD']= "";
326     }
327     if ($this->current['MAILMETHOD'] == ""){
328             $ldap->search ("(objectClass=goMailServer)", array('cn'));
329             $this->data['SERVERS']['IMAP']= array();
330             error_reporting(0);
331             while ($attrs= $ldap->fetch()){
332               $name= $attrs['cn'][0];
333               $this->data['SERVERS']['IMAP'][$name]= $name;
334             }
335             error_reporting(E_ALL);
336     } else {
337             $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
338                                                                'goImapSieveServer', 'goImapSievePort'));
340             $this->data['SERVERS']['IMAP']= array();
341             error_reporting(0);
342             while ($attrs= $ldap->fetch()){
343               $name= $attrs['goImapName'][0];
344               $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
345                   "admin" => $attrs['goImapAdmin'][0],
346                   "password" => $attrs['goImapPassword'][0],
347                   "sieve_server" => $attrs['goImapSieveServer'][0],
348                   "sieve_port" => $attrs['goImapSievePort'][0]);
349             }
350             error_reporting(E_ALL);
351     }
353     /* Get kerberos server. FIXME: only one is supported currently */
354     $ldap->cd ($this->current['BASE']);
355     $ldap->search ("(objectClass=goKrbServer)");
356     if ($ldap->count()){
357       $attrs= $ldap->fetch();
358       $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
359           'REALM' => $attrs['goKrbRealm'][0],
360           'ADMIN' => $attrs['goKrbAdmin'][0],
361           'PASSWORD' => $attrs['goKrbPassword'][0]);
362     }
364     /* Get cups server. FIXME: only one is supported currently */
365     $ldap->cd ($this->current['BASE']);
366     $ldap->search ("(objectClass=goCupsServer)");
367     if ($ldap->count()){
368       $attrs= $ldap->fetch();
369       $this->data['SERVERS']['CUPS']= $attrs['cn'][0];  
370     }
372     /* Get fax server. FIXME: only one is supported currently */
373     $ldap->cd ($this->current['BASE']);
374     $ldap->search ("(objectClass=goFaxServer)");
375     if ($ldap->count()){
376       $attrs= $ldap->fetch();
377       $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
378           'LOGIN' => $attrs['goFaxAdmin'][0],
379           'PASSWORD' => $attrs['goFaxPassword'][0]);
380     }
382     /* Get asterisk servers */
383     $ldap->cd ($this->current['BASE']);
384     $ldap->search ("(objectClass=goFonServer)");
385     $this->data['SERVERS']['FON']= array(); 
386     if ($ldap->count()){
387       while ($attrs= $ldap->fetch()){
389         /* Add 0 entry for development */
390         if(count($this->data['SERVERS']['FON']) == 0){
391           $this->data['SERVERS']['FON'][0]= array(
392               'DN'      => $attrs['dn'],
393               'SERVER'  => $attrs['cn'][0],
394               'LOGIN'   => $attrs['goFonAdmin'][0],
395               'PASSWORD'        => $attrs['goFonPassword'][0],
396               'DB'              => "gophone",
397               'SIP_TABLE'               => "sip_users",
398               'EXT_TABLE'       => "extensions",
399               'VOICE_TABLE'     => "voicemail_users",
400               'QUEUE_TABLE'     => "queues",
401               'QUEUE_MEMBER_TABLE'      => "queue_members");
402         }
404         /* Add entry with 'dn' as index */
405         $this->data['SERVERS']['FON'][$attrs['dn']]= array(
406             'DN'      => $attrs['dn'],
407             'SERVER'  => $attrs['cn'][0],
408             'LOGIN'   => $attrs['goFonAdmin'][0],
409             'PASSWORD'  => $attrs['goFonPassword'][0],
410             'DB'    => "gophone",
411             'SIP_TABLE'   => "sip_users",
412             'EXT_TABLE'   => "extensions",
413             'VOICE_TABLE' => "voicemail_users",
414             'QUEUE_TABLE' => "queues",
415             'QUEUE_MEMBER_TABLE'  => "queue_members");
416       }
417     }
419     /* Get glpi servers */
420     $ldap->cd ($this->current['BASE']);
421     $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
422     if ($ldap->count()){
423       $attrs= $ldap->fetch();
424       if(!isset($attrs['goGlpiPassword'])){
425         $attrs['goGlpiPassword'][0] ="";
426       }
427       $this->data['SERVERS']['GLPI']= array(
428           'SERVER'  => $attrs['cn'][0],
429           'LOGIN'   => $attrs['goGlpiAdmin'][0],
430           'PASSWORD'  => $attrs['goGlpiPassword'][0],
431           'DB'    => $attrs['goGlpiDatabase'][0]);
432     }
433     /* Get logdb server */
434     $ldap->cd ($this->current['BASE']);
435     $ldap->search ("(objectClass=goLogDBServer)");
436     if ($ldap->count()){
437       $attrs= $ldap->fetch();
438       $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
439           'LOGIN' => $attrs['goLogAdmin'][0],
440           'PASSWORD' => $attrs['goLogPassword'][0]);
441     }
443     /* Get NFS server lists */
444     $tmp= array("default");
445     $ldap->cd ($this->current['BASE']);
446     $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
447     while ($attrs= $ldap->fetch()){
448       for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
449         $path= preg_replace ("/\s.*$/", "", $attrs["goExportEntry"][$i]);
450         $tmp[]= $attrs["cn"][0].":$path";
451       }
452     }
453     $this->data['SERVERS']['NFS']= $tmp;
456     /* Load Terminalservers */
457     $ldap->cd ($this->current['BASE']);
458     $ldap->search ("(objectClass=goTerminalServer)");
459     $this->data['SERVERS']['TERMINAL']= array();
460     $this->data['SERVERS']['TERMINAL'][]= "default";
462     $this->data['SERVERS']['FONT']= array();
463     $this->data['SERVERS']['FONT'][]= "default";
464     while ($attrs= $ldap->fetch()){
465       $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
466       for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
467         $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
468       }
469     }
471     /* Ldap Server */
472     $this->data['SERVERS']['LDAP']= array();
473     $ldap->cd ($this->current['BASE']);
474     $ldap->search ("(objectClass=goLdapServer)");
475     while ($attrs= $ldap->fetch()){
476       if (isset($attrs["goLdapBase"])){
477         for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
478           $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
479         }
480       }
481     }
483     /* Get misc server lists */
484     $this->data['SERVERS']['SYSLOG']= array("default");
485     $this->data['SERVERS']['NTP']= array("default");
486     $ldap->cd ($this->current['BASE']);
487     $ldap->search ("(objectClass=goNtpServer)");
488     while ($attrs= $ldap->fetch()){
489       $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
490     }
491     $ldap->cd ($this->current['BASE']);
492     $ldap->search ("(objectClass=goSyslogServer)");
493     while ($attrs= $ldap->fetch()){
494       $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
495     }
497     /* Get samba servers from LDAP, in case of samba3 */
498     if ($this->current['SAMBAVERSION'] == 3){
499       $this->data['SERVERS']['SAMBA']= array();
500       $ldap->cd ($this->current['BASE']);
501       $ldap->search ("(objectClass=sambaDomain)");
502       while ($attrs= $ldap->fetch()){
503         $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
504         if(isset($attrs["sambaSID"][0])){
505           $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"]  = $attrs["sambaSID"][0];
506         }
507         if(isset($attrs["sambaAlgorithmicRidBase"][0])){
508           $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
509         }
510       }
512       /* If no samba servers are found, look for configured sid/ridbase */
513       if (count($this->data['SERVERS']['SAMBA']) == 0){
514         if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
515           print_red(_("SID and/or RIDBASE missing in your configuration!"));
516           echo $_SESSION['errors'];
517           exit;
518         } else {
519           $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
520               "SID" => $this->current["SID"],
521               "RIDBASE" => $this->current["RIDBASE"]);
522         }
523       }
524     }
525   }
528   function get_departments($ignore_dn= "")
529   {
530     global $config;
532     /* Initialize result hash */
533     $result= array();
534     $administrative= array();
535     $result['/']= $this->current['BASE'];
536     $this->tdepartments= array();
538     /* Get list of department objects */
539     $ldap= $this->get_ldap_link();
540     $ldap->cd ($this->current['BASE']);
541     $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
542     while ($attrs= $ldap->fetch()){
543       $dn= $ldap->getDN();
544       $this->tdepartments[$dn]= "";
546       /* Save administrative departments */
547       if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
548           isset($attrs['gosaUnitTag'][0])){
549         $administrative[$dn]= $attrs['gosaUnitTag'][0];
550         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
551       }
553       if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
554           isset($attrs['gosaUnitTag'][0])){
555         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
556       }
557     
558       if ($dn == $ignore_dn){
559         continue;
560       }
562       /* Only assign non-root departments */
563       if ($dn != $result['/']){
564         $result[convert_department_dn($dn)]= $dn;
565       }
566     }
568     $this->adepartments= $administrative;
569     $this->departments= $result;
570   }
573   function make_idepartments($max_size= 28)
574   {
575     global $config;
576     $base = $config->current['BASE'];
578     $arr= array();
579     $ui= get_userinfo();
580     $this->idepartments= array();
582     /* Create multidimensional array, with all departments. */
583     foreach ($this->departments as $key => $val){
585       /* When using strict_units, filter non relevant parts */
586       if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
587         if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
588             $this->tdepartments[$val] != $ui->gosaUnitTag){
589           continue;
590         }
591       }
593       /* remove base from dn */
594       $val2 = str_replace($base,"",$val);
596       /* Get every single ou */
597       $str = preg_replace("/ou=/","|ou=",$val2);        
598       $elements = array_reverse(split("\|",$str));              
600       /* Save last array position */
601       $last = &$arr;
603       /* Get array depth  */
604       $cnt = count($elements);
606       /* Add last ou element of current dn to our array */
607       foreach($elements as $key => $ele){
609         /* skip enpty */
610         if(empty($ele)) continue;
612         /* Extract department name */           
613         $elestr = preg_replace("/^ou=/","", $ele);
614         $elestr = preg_replace("/,$/","",$elestr);      
616         /* Add to array */      
617         if($key == ($cnt-2)){
618           $last[$elestr]['ENTRY'] = $val;
619         }
621         /* Set next array appending position */
622         $last = &$last[$elestr]['SUB'];
623       }
624     }
626     /* Add base entry */
627     $ret["/"]["ENTRY"]  = $base;
628     $ret["/"]["SUB"]    = $arr;
630     $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
631   }
634   /* Creates display friendly output from make_idepartments */
635   function generateDepartmentArray($arr,$depth = -1,$max_size){
636     $ret = array();
637     $depth ++;
639     /* Walk through array */
640     ksort($arr);
641     foreach($arr as $name => $entries){
643       /* If this department is the last in the current tree position 
644        * remove it, to avoid generating output for it */
645       if(count($entries['SUB'])==0){
646         unset($entries['SUB']);
647       }
649       /* Fix name, if it contains a replace tag */
650       $name= @LDAP::fix($name);
652       /* Check if current name is too long, then cut it */
653       if(mb_strlen($name, 'UTF-8')> $max_size){
654         $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
655       }
657       /* Append the name to the list */ 
658       if(isset($entries['ENTRY'])){
659         $a = "";
660         for($i = 0 ; $i < $depth ; $i ++){
661           $a.=".";
662         }
663         $ret[$entries['ENTRY']]=$a."&nbsp;".$name;
664       } 
666       /* recursive add of subdepartments */
667       if(isset($entries['SUB'])){
668         $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
669       }
670     }
672     return($ret);
673   }
675   /* This function returns all available Shares defined in this ldap
676    * There are two ways to call this function, if listboxEntry is true
677    *  only name and path are attached to the array, in it is false, the whole
678    *  entry will be parsed an atached to the result.
679    */
680   function getShareList($listboxEntry = false)
681   {
682     $ldap= $this->get_ldap_link();
684     /* Set tag attribute if we've tagging activated */
685     $tag= "";
686     $ui= get_userinfo();
687     if ($ui->gosaUnitTag != "" && isset($this->current['STRICT_UNITS']) &&
688         preg_match('/TRUE/i', $this->current['STRICT_UNITS'])){
689       $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
690     }
692     $a_res = $ldap->search("(&(objectClass=goShareServer)$tag(objectClass=goServer))",array("goExportEntry","cn"));
693     $return= array();
694     while($entry = $ldap->fetch($a_res)){
695       if(isset($entry['goExportEntry']['count'])){
696         unset($entry['goExportEntry']['count']);
697       }
698       if(isset($entry['goExportEntry'])){
699         foreach($entry['goExportEntry'] as $export){
700           $shareAttrs = split("\|",$export);
701           if($listboxEntry) {
702             $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
703           }else{
704             $return[$shareAttrs[0]."|".$entry['cn'][0]]['server']       = $entry['cn'][0];
705             $return[$shareAttrs[0]."|".$entry['cn'][0]]['name']         = $shareAttrs[0];
706             $return[$shareAttrs[0]."|".$entry['cn'][0]]['description']  = $shareAttrs[1];
707             $return[$shareAttrs[0]."|".$entry['cn'][0]]['type']         = $shareAttrs[2];
708             $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset']      = $shareAttrs[3];
709             $return[$shareAttrs[0]."|".$entry['cn'][0]]['path']         = $shareAttrs[4];
710             $return[$shareAttrs[0]."|".$entry['cn'][0]]['option']       = $shareAttrs[5];
711           }
712         }
713       }
714     }
715     return($return);
716   }
718   /* This function returns all available ShareServer */
719   function getShareServerList()
720   {
721     global $config;
722     $return = array();
723     $ui = get_userinfo();
724     $base = $config->current['BASE'];
725     $res = get_list("(&(objectClass=goShareServer)(goExportEntry=*))",$ui->subtreeACL,$base,array("goExportEntry","cn"),GL_SUBSEARCH);
726     foreach($res as $entry){
727       if(isset($entry['goExportEntry']['count'])){
728         unset($entry['goExportEntry']['count']);
729       }
730       foreach($entry['goExportEntry'] as $share){
731         $a_share = split("\|",$share);
732         $sharename = $a_share[0];
733         $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
734       }
736     }
737     return($return);
738   }
740   /* Check if there's the specified bool value set in the configuration */
741   function boolValueIsTrue($section, $value)
742   {
743     $section= strtoupper($section);
744     $value= strtoupper($value);
745     if (isset($this->data[$section][$value])){
746     
747       $data= $this->data[$section][$value];
748       if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
749         return TRUE;
750       }
752     }
754     return FALSE;
755   }
759 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
760 ?>