Code

- Corrected debian bugnumbers
[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   }
183   function get_credentials($creds)
184   {
185     if (isset($_SERVER['HTTP_GOSA_KEY'])){
186       return (cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY']));
187     }
188     return ($creds);
189   }
192   function get_ldap_link($sizelimit= FALSE)
193   {
194       /* Build new connection */
195       $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
196           $this->current['ADMIN'], $this->get_credentials($this->current['PASSWORD']));
198       /* Check for connection */
199       if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
200         $smarty= get_smarty();
201         print_red (_("Can't bind to LDAP. Please contact the system administrator."));
202         $smarty->display (get_template_path('headers.tpl'));
203         echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
204         exit();
205       }
207       if (!isset($_SESSION['size_limit'])){
208         $_SESSION['size_limit']= $this->current['SIZELIMIT'];
209         $_SESSION['size_ignore']= $this->current['SIZEIGNORE'];
210       }
212       if ($sizelimit){
213         $this->ldap->set_size_limit($_SESSION['size_limit']);
214       } else {
215         $this->ldap->set_size_limit(0);
216       }
218       /* Move referrals */
219       if (!isset($this->current['REFERRAL'])){
220         $this->ldap->referrals= array();
221       } else {
222         $this->ldap->referrals= $this->current['REFERRAL'];
223       }
224 #    } 
225     return ($this->ldap);
226   }
228   function set_current($name)
229   {
230     $this->current= $this->data['LOCATIONS'][$name];
231     if (!isset($this->current['PEOPLE'])){
232       $this->current['PEOPLE']= "ou=people";
233     }
234     if (!isset($this->current['SAMBAVERSION'])){
235       $this->current['SAMBAVERSION']= 3;
236     }
237     if (!isset($this->current['GROUPS'])){
238       $this->current['GROUPS']= "ou=groups";
239     }
241     if (isset($this->current['INITIAL_BASE'])){
242       $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
243     }
245     /* Remove possibly added ',' from end of group and people ou */
246     $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
247     $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
249     if (!isset($this->current['WINSTATIONS'])){
250       $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
251     }
252     if (!isset($this->current['HASH'])){
253       $this->current['HASH']= "crypt";
254     }
255     if (!isset($this->current['DNMODE'])){
256       $this->current['DNMODE']= "cn";
257     }
258     if (!isset($this->current['MINID'])){
259       $this->current['MINID']= 100;
260     }
261     if (!isset($this->current['SIZELIMIT'])){
262       $this->current['SIZELIMIT']= 200;
263     }
264     if (!isset($this->current['SIZEINGORE'])){
265       $this->current['SIZEIGNORE']= TRUE;
266     } else {
267       if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
268         $this->current['SIZEIGNORE']= TRUE;
269       } else {
270         $this->current['SIZEIGNORE']= FALSE;
271       }
272     }
274     /* Sort referrals, if present */
275     if (isset ($this->current['REFERRAL'])){
276       $bases= array();
277       $servers= array();
278       foreach ($this->current['REFERRAL'] as $ref){
279         $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
280         $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
281         $bases[$base]= strlen($base);
282         $servers[$base]= $server;
283       }
284       asort($bases);
285       reset($bases);
286     }
288     /* SERVER not defined? Load the one with the shortest base */
289     if (!isset($this->current['SERVER'])){
290       $this->current['SERVER']= $servers[key($bases)];
291     }
293     /* BASE not defined? Load the one with the shortest base */
294     if (!isset($this->current['BASE'])){
295       $this->current['BASE']= key($bases);
296     }
298     /* Convert BASE to have escaped special characters */
299     $this->current['BASE']= @LDAP::convert($this->current['BASE']);
301     /* Parse LDAP referral informations */
302     if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
303       $url= $this->current['SERVER'];
304       $referral= $this->current['REFERRAL'][$url];
305       $this->current['ADMIN']= $referral['ADMIN'];
306       $this->current['PASSWORD']= $referral['PASSWORD'];
307     }
309     /* Possibly load kerberos style */
310     if (isset($this->current['KRBSASL'])){
311       if (preg_match('/^(yes|true)$/i', $this->current['KRBSASL'])){
312         $this->current['KRBSASL']= "sasl";
313       } else {
314         $this->current['KRBSASL']= "kerberos";
315       }
316     } else {
317       $this->current['KRBSASL']= "kerberos";
318     }
320     /* Load server informations */
321     $this->load_servers();
322   }
324   function load_servers ()
325   {
326     /* Only perform actions if current is set */
327     if ($this->current == NULL){
328       return;
329     }
331     /* Fill imap servers */
332     $ldap= $this->get_ldap_link();
333     $ldap->cd ($this->current['BASE']);
334     if (!isset($this->current['MAILMETHOD'])){
335         $this->current['MAILMETHOD']= "";
336     }
337     if ($this->current['MAILMETHOD'] == ""){
338             $ldap->search ("(objectClass=goMailServer)", array('cn'));
339             $this->data['SERVERS']['IMAP']= array();
340             error_reporting(0);
341             while ($attrs= $ldap->fetch()){
342               $name= $attrs['cn'][0];
343               $this->data['SERVERS']['IMAP'][$name]= $name;
344             }
345             error_reporting(E_ALL);
346     } else {
347             $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
348                                                                'goImapSieveServer', 'goImapSievePort'));
350             $this->data['SERVERS']['IMAP']= array();
351             error_reporting(0);
352             while ($attrs= $ldap->fetch()){
353               $name= $attrs['goImapName'][0];
354               $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
355                   "admin" => $attrs['goImapAdmin'][0],
356                   "password" => $attrs['goImapPassword'][0],
357                   "sieve_server" => $attrs['goImapSieveServer'][0],
358                   "sieve_port" => $attrs['goImapSievePort'][0]);
359             }
360             error_reporting(E_ALL);
361     }
363     /* Get kerberos server. FIXME: only one is supported currently */
364     $ldap->cd ($this->current['BASE']);
365     $ldap->search ("(objectClass=goKrbServer)");
366     if ($ldap->count()){
367       $attrs= $ldap->fetch();
368       $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
369           'REALM' => $attrs['goKrbRealm'][0],
370           'ADMIN' => $attrs['goKrbAdmin'][0],
371           'PASSWORD' => $attrs['goKrbPassword'][0]);
372     }
374     /* Get cups server. FIXME: only one is supported currently */
375     $ldap->cd ($this->current['BASE']);
376     $ldap->search ("(objectClass=goCupsServer)");
377     if ($ldap->count()){
378       $attrs= $ldap->fetch();
379       $this->data['SERVERS']['CUPS']= $attrs['cn'][0];  
380     }
382     /* Get fax server. FIXME: only one is supported currently */
383     $ldap->cd ($this->current['BASE']);
384     $ldap->search ("(objectClass=goFaxServer)");
385     if ($ldap->count()){
386       $attrs= $ldap->fetch();
387       $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
388           'LOGIN' => $attrs['goFaxAdmin'][0],
389           'PASSWORD' => $attrs['goFaxPassword'][0]);
390     }
392     /* Get asterisk servers */
393     $ldap->cd ($this->current['BASE']);
394     $ldap->search ("(objectClass=goFonServer)");
395     $this->data['SERVERS']['FON']= array(); 
396     if ($ldap->count()){
397       while ($attrs= $ldap->fetch()){
399         /* Add 0 entry for development */
400         if(count($this->data['SERVERS']['FON']) == 0){
401           $this->data['SERVERS']['FON'][0]= array(
402               'DN'      => $attrs['dn'],
403               'SERVER'  => $attrs['cn'][0],
404               'LOGIN'   => $attrs['goFonAdmin'][0],
405               'PASSWORD'        => $attrs['goFonPassword'][0],
406               'DB'              => "gophone",
407               'SIP_TABLE'               => "sip_users",
408               'EXT_TABLE'       => "extensions",
409               'VOICE_TABLE'     => "voicemail_users",
410               'QUEUE_TABLE'     => "queues",
411               'QUEUE_MEMBER_TABLE'      => "queue_members");
412         }
414         /* Add entry with 'dn' as index */
415         $this->data['SERVERS']['FON'][$attrs['dn']]= array(
416             'DN'      => $attrs['dn'],
417             'SERVER'  => $attrs['cn'][0],
418             'LOGIN'   => $attrs['goFonAdmin'][0],
419             'PASSWORD'  => $attrs['goFonPassword'][0],
420             'DB'    => "gophone",
421             'SIP_TABLE'   => "sip_users",
422             'EXT_TABLE'   => "extensions",
423             'VOICE_TABLE' => "voicemail_users",
424             'QUEUE_TABLE' => "queues",
425             'QUEUE_MEMBER_TABLE'  => "queue_members");
426       }
427     }
429     /* Get glpi servers */
430     $ldap->cd ($this->current['BASE']);
431     $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
432     if ($ldap->count()){
433       $attrs= $ldap->fetch();
434       if(!isset($attrs['goGlpiPassword'])){
435         $attrs['goGlpiPassword'][0] ="";
436       }
437       $this->data['SERVERS']['GLPI']= array(
438           'SERVER'  => $attrs['cn'][0],
439           'LOGIN'   => $attrs['goGlpiAdmin'][0],
440           'PASSWORD'  => $attrs['goGlpiPassword'][0],
441           'DB'    => $attrs['goGlpiDatabase'][0]);
442     }
443     /* Get logdb server */
444     $ldap->cd ($this->current['BASE']);
445     $ldap->search ("(objectClass=goLogDBServer)");
446     if ($ldap->count()){
447       $attrs= $ldap->fetch();
448       $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
449           'LOGIN' => $attrs['goLogAdmin'][0],
450           'PASSWORD' => $attrs['goLogPassword'][0]);
451     }
453     /* Get NFS server lists */
454     $tmp= array("default");
455     $ldap->cd ($this->current['BASE']);
456     $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
457     while ($attrs= $ldap->fetch()){
458       for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
459         $path= preg_replace ("/\s.*$/", "", $attrs["goExportEntry"][$i]);
460         $tmp[]= $attrs["cn"][0].":$path";
461       }
462     }
463     $this->data['SERVERS']['NFS']= $tmp;
466     /* Load Terminalservers */
467     $ldap->cd ($this->current['BASE']);
468     $ldap->search ("(objectClass=goTerminalServer)");
469     $this->data['SERVERS']['TERMINAL']= array();
470     $this->data['SERVERS']['TERMINAL'][]= "default";
472     $this->data['SERVERS']['FONT']= array();
473     $this->data['SERVERS']['FONT'][]= "default";
474     while ($attrs= $ldap->fetch()){
475       $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
476       for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
477         $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
478       }
479     }
481     /* Ldap Server */
482     $this->data['SERVERS']['LDAP']= array();
483     $ldap->cd ($this->current['BASE']);
484     $ldap->search ("(objectClass=goLdapServer)");
485     while ($attrs= $ldap->fetch()){
486       if (isset($attrs["goLdapBase"])){
487         for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
488           $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
489         }
490       }
491     }
493     /* Get misc server lists */
494     $this->data['SERVERS']['SYSLOG']= array("default");
495     $this->data['SERVERS']['NTP']= array("default");
496     $ldap->cd ($this->current['BASE']);
497     $ldap->search ("(objectClass=goNtpServer)");
498     while ($attrs= $ldap->fetch()){
499       $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
500     }
501     $ldap->cd ($this->current['BASE']);
502     $ldap->search ("(objectClass=goSyslogServer)");
503     while ($attrs= $ldap->fetch()){
504       $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
505     }
507     /* Get samba servers from LDAP, in case of samba3 */
508     if ($this->current['SAMBAVERSION'] == 3){
509       $this->data['SERVERS']['SAMBA']= array();
510       $ldap->cd ($this->current['BASE']);
511       $ldap->search ("(objectClass=sambaDomain)");
512       while ($attrs= $ldap->fetch()){
513         $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
514         if(isset($attrs["sambaSID"][0])){
515           $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"]  = $attrs["sambaSID"][0];
516         }
517         if(isset($attrs["sambaAlgorithmicRidBase"][0])){
518           $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
519         }
520       }
522       /* If no samba servers are found, look for configured sid/ridbase */
523       if (count($this->data['SERVERS']['SAMBA']) == 0){
524         if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
525           print_red(_("SID and/or RIDBASE missing in your configuration!"));
526           echo $_SESSION['errors'];
527           exit;
528         } else {
529           $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
530               "SID" => $this->current["SID"],
531               "RIDBASE" => $this->current["RIDBASE"]);
532         }
533       }
534     }
535   }
538   function get_departments($ignore_dn= "")
539   {
540     global $config;
542     /* Initialize result hash */
543     $result= array();
544     $administrative= array();
545     $result['/']= $this->current['BASE'];
546     $this->tdepartments= array();
548     /* Get list of department objects */
549     $ldap= $this->get_ldap_link();
550     $ldap->cd ($this->current['BASE']);
551     $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
552     while ($attrs= $ldap->fetch()){
553       $dn= $ldap->getDN();
554       $this->tdepartments[$dn]= "";
556       /* Save administrative departments */
557       if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
558           isset($attrs['gosaUnitTag'][0])){
559         $administrative[$dn]= $attrs['gosaUnitTag'][0];
560         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
561       }
563       if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
564           isset($attrs['gosaUnitTag'][0])){
565         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
566       }
567     
568       if ($dn == $ignore_dn){
569         continue;
570       }
572       /* Only assign non-root departments */
573       if ($dn != $result['/']){
574         $result[convert_department_dn($dn)]= $dn;
575       }
576     }
578     $this->adepartments= $administrative;
579     $this->departments= $result;
580   }
583   function make_idepartments($max_size= 28)
584   {
585     global $config;
586     $base = $config->current['BASE'];
588     $arr= array();
589     $ui= get_userinfo();
590     $this->idepartments= array();
592     /* Create multidimensional array, with all departments. */
593     foreach ($this->departments as $key => $val){
595       /* When using strict_units, filter non relevant parts */
596       if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
597         if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
598             $this->tdepartments[$val] != $ui->gosaUnitTag){
599           continue;
600         }
601       }
603       /* remove base from dn */
604       $val2 = str_replace($base,"",$val);
606       /* Get every single ou */
607       $str = preg_replace("/ou=/","|ou=",$val2);        
608       $elements = array_reverse(split("\|",$str));              
610       /* Save last array position */
611       $last = &$arr;
613       /* Get array depth  */
614       $cnt = count($elements);
616       /* Add last ou element of current dn to our array */
617       foreach($elements as $key => $ele){
619         /* skip enpty */
620         if(empty($ele)) continue;
622         /* Extract department name */           
623         $elestr = preg_replace("/^ou=/","", $ele);
624         $elestr = preg_replace("/,$/","",$elestr);      
626         /* Add to array */      
627         if($key == ($cnt-2)){
628           $last[$elestr]['ENTRY'] = $val;
629         }
631         /* Set next array appending position */
632         $last = &$last[$elestr]['SUB'];
633       }
634     }
636     /* Add base entry */
637     $ret["/"]["ENTRY"]  = $base;
638     $ret["/"]["SUB"]    = $arr;
640     $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
641   }
644   /* Creates display friendly output from make_idepartments */
645   function generateDepartmentArray($arr,$depth = -1,$max_size){
646     $ret = array();
647     $depth ++;
649     /* Walk through array */
650     ksort($arr);
651     foreach($arr as $name => $entries){
653       /* If this department is the last in the current tree position 
654        * remove it, to avoid generating output for it */
655       if(count($entries['SUB'])==0){
656         unset($entries['SUB']);
657       }
659       /* Fix name, if it contains a replace tag */
660       $name= @LDAP::fix($name);
662       /* Check if current name is too long, then cut it */
663       if(mb_strlen($name, 'UTF-8')> $max_size){
664         $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
665       }
667       /* Append the name to the list */ 
668       if(isset($entries['ENTRY'])){
669         $a = "";
670         for($i = 0 ; $i < $depth ; $i ++){
671           $a.=".";
672         }
673         $ret[$entries['ENTRY']]=$a."&nbsp;".$name;
674       } 
676       /* recursive add of subdepartments */
677       if(isset($entries['SUB'])){
678         $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
679       }
680     }
682     return($ret);
683   }
685   /* This function returns all available Shares defined in this ldap
686    * There are two ways to call this function, if listboxEntry is true
687    *  only name and path are attached to the array, in it is false, the whole
688    *  entry will be parsed an atached to the result.
689    */
690   function getShareList($listboxEntry = false)
691   {
692     $ldap= $this->get_ldap_link();
694     /* Set tag attribute if we've tagging activated */
695     $tag= "";
696     $ui= get_userinfo();
697     if ($ui->gosaUnitTag != "" && isset($this->current['STRICT_UNITS']) &&
698         preg_match('/TRUE/i', $this->current['STRICT_UNITS'])){
699       $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
700     }
702     $a_res = $ldap->search("(&(objectClass=goShareServer)$tag(objectClass=goServer))",array("goExportEntry","cn"));
703     $return= array();
704     while($entry = $ldap->fetch($a_res)){
705       if(isset($entry['goExportEntry']['count'])){
706         unset($entry['goExportEntry']['count']);
707       }
708       if(isset($entry['goExportEntry'])){
709         foreach($entry['goExportEntry'] as $export){
710           $shareAttrs = split("\|",$export);
711           if($listboxEntry) {
712             $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
713           }else{
714             $return[$shareAttrs[0]."|".$entry['cn'][0]]['server']       = $entry['cn'][0];
715             $return[$shareAttrs[0]."|".$entry['cn'][0]]['name']         = $shareAttrs[0];
716             $return[$shareAttrs[0]."|".$entry['cn'][0]]['description']  = $shareAttrs[1];
717             $return[$shareAttrs[0]."|".$entry['cn'][0]]['type']         = $shareAttrs[2];
718             $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset']      = $shareAttrs[3];
719             $return[$shareAttrs[0]."|".$entry['cn'][0]]['path']         = $shareAttrs[4];
720             $return[$shareAttrs[0]."|".$entry['cn'][0]]['option']       = $shareAttrs[5];
721           }
722         }
723       }
724     }
725     return($return);
726   }
728   /* This function returns all available ShareServer */
729   function getShareServerList()
730   {
731     global $config;
732     $return = array();
733     $ui = get_userinfo();
734     $base = $config->current['BASE'];
735     $res = get_list("(&(objectClass=goShareServer)(goExportEntry=*))",$ui->subtreeACL,$base,array("goExportEntry","cn"),GL_SUBSEARCH);
736     foreach($res as $entry){
737       if(isset($entry['goExportEntry']['count'])){
738         unset($entry['goExportEntry']['count']);
739       }
740       foreach($entry['goExportEntry'] as $share){
741         $a_share = split("\|",$share);
742         $sharename = $a_share[0];
743         $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
744       }
746     }
747     return($return);
748   }
750   /* Check if there's the specified bool value set in the configuration */
751   function boolValueIsTrue($section, $value)
752   {
753     $section= strtoupper($section);
754     $value= strtoupper($value);
755     if (isset($this->data[$section][$value])){
756     
757       $data= $this->data[$section][$value];
758       if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
759         return TRUE;
760       }
762     }
764     return FALSE;
765   }
769 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
770 ?>