Code

Heimdal stuff not needed. It's too insecure to read m-keys by php.
[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( 'FAXFORMATS' => 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 gosa.conf: %s at line %d"),
72             xml_error_string(xml_get_error_code($this->parser)),
73             xml_get_current_line_number($this->parser)));
74       echo $_SESSION['errors'];
75       exit;
76     }
77   }
79   function tag_open($parser, $tag, $attrs)
80   { 
81     /* Save last and current tag for reference */
82     $this->tags[$this->level]= $tag;
83     $this->level++;
85     /* Trigger on CONF section */
86     if ($tag == 'CONF'){
87       $this->config_found= TRUE;
88     }
90     /* Return if we're not in config section */
91     if (!$this->config_found){
92       return;
93     }
95     /* yes/no to true/false and upper case TRUE to true and so on*/
96     foreach($attrs as $name => $value){
97       if(preg_match("/^(true|yes)$/i",$value)){
98         $attrs[$name] = "true";
99       }elseif(preg_match("/^(false|no)$/i",$value)){
100         $attrs[$name] = "false";
101       } 
102     }
104     /* Look through attributes */
105     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                   /* Handle faxformat */
147       case 'FAXFORMAT': 
148                   if ($this->tags[$this->level-2] == 'MAIN'){
149                     /* Add fax formats */
150                     $this->data['MAIN']['FAXFORMATS'][]= $attrs['TYPE'];
151                   }
152                   break;
154                   /* Load main parameters */
155       case 'MAIN':
156                   $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
157                   break;
159                   /* Load menu */
160       case 'SECTION':
161                   if ($this->tags[$this->level-2] == 'MENU'){
162                     $this->section= $attrs['NAME'];
163                     $this->data['MENU'][$this->section]= array(); ;
164                   }
165                   break;
167                   /* Inser plugins */
168       case 'PLUGIN':
169                   if ($this->tags[$this->level-3] == 'MENU' &&
170                       $this->tags[$this->level-2] == 'SECTION'){
172                     $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
173                   }
174                   if ($this->tags[$this->level-2] == 'SERVICEMENU'){
175                     $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
176                   }
177                   break;
178     }
179   }
181   function tag_close($parser, $tag)
182   {
183     /* Close config section */
184     if ($tag == 'CONF'){
185       $this->config_found= FALSE;
186     }
187     $this->level--;
188   }
190   function get_ldap_link($sizelimit= FALSE)
191   {
192     /* Build new connection */
193     $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
194         $this->current['ADMIN'], $this->current['PASSWORD']);
196     /* Check for connection */
197     if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
198       $smarty= get_smarty();
199       print_red (_("Can't bind to LDAP. Please contact the system administrator."));
200       $smarty->display (get_template_path('headers.tpl'));
201       echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
202       exit();
203     }
205     if (!isset($_SESSION['size_limit'])){
206       $_SESSION['size_limit']= $this->current['SIZELIMIT'];
207       $_SESSION['size_ignore']= $this->current['SIZEIGNORE'];
208     }
210     if ($sizelimit){
211       $this->ldap->set_size_limit($_SESSION['size_limit']);
212     } else {
213       $this->ldap->set_size_limit(0);
214     }
216     /* Move referrals */
217     if (!isset($this->current['REFERRAL'])){
218       $this->ldap->referrals= array();
219     } else {
220       $this->ldap->referrals= $this->current['REFERRAL'];
221     }
223     return ($this->ldap);
224   }
226   function set_current($name)
227   {
228     $this->current= $this->data['LOCATIONS'][$name];
229     if (!isset($this->current['PEOPLE'])){
230       $this->current['PEOPLE']= "ou=people";
231     }
232     if (!isset($this->current['GROUPS'])){
233       $this->current['GROUPS']= "ou=groups";
234     }
236     if (isset($this->current['INITIAL_BASE'])){
237       $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
238     }
239   
240     /* Remove possibly added ',' from end of group and people ou */
241     $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
242     $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
244     if (!isset($this->current['WINSTATIONS'])){
245       $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
246     }
247     if (!isset($this->current['HASH'])){
248       $this->current['HASH']= "crypt";
249     }
250     if (!isset($this->current['DNMODE'])){
251       $this->current['DNMODE']= "cn";
252     }
253     if (!isset($this->current['MINID'])){
254       $this->current['MINID']= 100;
255     }
256     if (!isset($this->current['SIZELIMIT'])){
257       $this->current['SIZELIMIT']= 200;
258     }
259     if (!isset($this->current['SIZEINGORE'])){
260       $this->current['SIZEIGNORE']= TRUE;
261     } else {
262       if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
263         $this->current['SIZEIGNORE']= TRUE;
264       } else {
265         $this->current['SIZEIGNORE']= FALSE;
266       }
267     }
269     /* Sort referrals, if present */
270     if (isset ($this->current['REFERRAL'])){
271       $bases= array();
272       $servers= array();
273       foreach ($this->current['REFERRAL'] as $ref){
274         $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
275         $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
276         $bases[$base]= strlen($base);
277         $servers[$base]= $server;
278       }
279       asort($bases);
280       reset($bases);
281     }
283     /* SERVER not defined? Load the one with the shortest base */
284     if (!isset($this->current['SERVER'])){
285       $this->current['SERVER']= $servers[key($bases)];
286     }
288     /* BASE not defined? Load the one with the shortest base */
289     if (!isset($this->current['BASE'])){
290       $this->current['BASE']= key($bases);
291     }
293     /* Convert BASE to have escaped special characters */
294     $this->current['BASE']= @LDAP::convert($this->current['BASE']);
296     /* Parse LDAP referral informations */
297     if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
298       $url= $this->current['SERVER'];
299       $referral= $this->current['REFERRAL'][$url];
300       $this->current['ADMIN']= $referral['ADMIN'];
301       $this->current['PASSWORD']= $referral['PASSWORD'];
302     }
304     /* Load server informations */
305     $this->load_servers();
306   }
308   function load_servers ()
309   {
310     /* Only perform actions if current is set */
311     if ($this->current === NULL){
312       return;
313     }
315     /* Fill imap servers */
316     $ldap= $this->get_ldap_link();
317     $ldap->cd ($this->current['BASE']);
318     if (!isset($this->current['MAILMETHOD'])){
319       $this->current['MAILMETHOD']= "";
320     }
321     if ($this->current['MAILMETHOD'] == ""){
322       $ldap->search ("(objectClass=goMailServer)", array('cn'));
323       $this->data['SERVERS']['IMAP']= array();
324       error_reporting(0);
325       while ($attrs= $ldap->fetch()){
326         $name= $attrs['cn'][0];
327         $this->data['SERVERS']['IMAP'][$name]= $name;
328       }
329       error_reporting(E_ALL);
330     } else {
331       $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
332             'goImapSieveServer', 'goImapSievePort'));
334       $this->data['SERVERS']['IMAP']= array();
335       error_reporting(0);
336       while ($attrs= $ldap->fetch()){
337         $name= $attrs['goImapName'][0];
338         $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
339             "admin" => $attrs['goImapAdmin'][0],
340             "password" => $attrs['goImapPassword'][0],
341             "sieve_server" => $attrs['goImapSieveServer'][0],
342             "sieve_port" => $attrs['goImapSievePort'][0]);
343       }
344       error_reporting(E_ALL);
345     }
347     /* Get kerberos server. FIXME: only one is supported currently */
348     $ldap->cd ($this->current['BASE']);
349     $ldap->search ("(objectClass=goKrbServer)");
350     if ($ldap->count()){
351       $attrs= $ldap->fetch();
352       $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
353           'REALM' => $attrs['goKrbRealm'][0],
354           'ADMIN' => $attrs['goKrbAdmin'][0],
355           'PASSWORD' => $attrs['goKrbPassword'][0]);
356     }
358     /* Get cups server. FIXME: only one is supported currently */
359     $ldap->cd ($this->current['BASE']);
360     $ldap->search ("(objectClass=goCupsServer)");
361     if ($ldap->count()){
362       $attrs= $ldap->fetch();
363       $this->data['SERVERS']['CUPS']= $attrs['cn'][0];  
364     }
366     /* Get fax server. FIXME: only one is supported currently */
367     $ldap->cd ($this->current['BASE']);
368     $ldap->search ("(objectClass=goFaxServer)");
369     if ($ldap->count()){
370       $attrs= $ldap->fetch();
371       $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
372           'LOGIN' => $attrs['goFaxAdmin'][0],
373           'PASSWORD' => $attrs['goFaxPassword'][0]);
374     }
377     /* Get asterisk servers */
378     $ldap->cd ($this->current['BASE']);
379     $ldap->search ("(objectClass=goFonServer)");
380     $this->data['SERVERS']['FON']= array();
381     if ($ldap->count()){
382       while ($attrs= $ldap->fetch()){
384         /* Add 0 entry for development */
385         if(count($this->data['SERVERS']['FON']) == 0){
386           $this->data['SERVERS']['FON'][0]= array(
387               'DN'      => $attrs['dn'],
388               'SERVER'  => $attrs['cn'][0],
389               'LOGIN'   => $attrs['goFonAdmin'][0],
390               'PASSWORD'  => $attrs['goFonPassword'][0],
391               'DB'    => "gophone",
392               'SIP_TABLE'   => "sip_users",
393               'EXT_TABLE'   => "extensions",
394               'VOICE_TABLE' => "voicemail_users",
395               'QUEUE_TABLE' => "queues",
396               'QUEUE_MEMBER_TABLE'  => "queue_members");
397         }
399         /* Add entry with 'dn' as index */
400         $this->data['SERVERS']['FON'][$attrs['dn']]= array(
401             'DN'      => $attrs['dn'],
402             'SERVER'  => $attrs['cn'][0],
403             'LOGIN'   => $attrs['goFonAdmin'][0],
404             'PASSWORD'  => $attrs['goFonPassword'][0],
405             'DB'    => "gophone",
406             'SIP_TABLE'   => "sip_users",
407             'EXT_TABLE'   => "extensions",
408             'VOICE_TABLE' => "voicemail_users",
409             'QUEUE_TABLE' => "queues",
410             'QUEUE_MEMBER_TABLE'  => "queue_members");
411       }
412     }
415     /* Get glpi server */
416     $ldap->cd ($this->current['BASE']);
417     $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
418     if ($ldap->count()){
419       $attrs= $ldap->fetch();
420       if(!isset($attrs['goGlpiPassword'])){
421         $attrs['goGlpiPassword'][0] ="";
422       }
423       $this->data['SERVERS']['GLPI']= array( 
424           'SERVER'      => $attrs['cn'][0],
425           'LOGIN'       => $attrs['goGlpiAdmin'][0],
426           'PASSWORD'    => $attrs['goGlpiPassword'][0],
427           'DB'          => $attrs['goGlpiDatabase'][0]);
428     }
431     /* Get logdb server */
432     $ldap->cd ($this->current['BASE']);
433     $ldap->search ("(objectClass=goLogDBServer)");
434     if ($ldap->count()){
435       $attrs= $ldap->fetch();
436       $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
437           'LOGIN' => $attrs['goLogAdmin'][0],
438           'PASSWORD' => $attrs['goLogPassword'][0]);
439     }
442     /* GOsa logging databases */
443     $ldap->cd ($this->current['BASE']);
444     $ldap->search ("(objectClass=gosaLogServer)");
445     if ($ldap->count()){
446       while($attrs= $ldap->fetch()){
447       $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]= 
448           array(
449           'DN'    => $attrs['dn'],
450           'USER'  => $attrs['goLogDBUser'][0],
451           'DB'    => $attrs['goLogDB'][0],
452           'PWD'   => $attrs['goLogDBPassword'][0]);
453       }
454     }
457     /* Get NFS server lists */
458     $tmp= array("default");
459     $ldap->cd ($this->current['BASE']);
460     $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
461     while ($attrs= $ldap->fetch()){
462       for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
463         if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
464           continue;
465         }
466         $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
467         $tmp[]= $attrs["cn"][0].":$path";
468       }
469     }
470     $this->data['SERVERS']['NFS']= $tmp;
472     /* Load Terminalservers */
473     $ldap->cd ($this->current['BASE']);
474     $ldap->search ("(objectClass=goTerminalServer)");
475     $this->data['SERVERS']['TERMINAL']= array();
476     $this->data['SERVERS']['TERMINAL'][]= "default";
478     $this->data['SERVERS']['FONT']= array();
479     $this->data['SERVERS']['FONT'][]= "default";
480     while ($attrs= $ldap->fetch()){
481       $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
482       for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
483         $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
484       }
485     }
487     /* Ldap Server */
488     $this->data['SERVERS']['LDAP']= array();
489     $ldap->cd ($this->current['BASE']);
490     $ldap->search ("(objectClass=goLdapServer)");
491     while ($attrs= $ldap->fetch()){
492       if (isset($attrs["goLdapBase"])){
493         for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
494           $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
495         }
496       }
497     }
499     /* Get misc server lists */
500     $this->data['SERVERS']['SYSLOG']= array("default");
501     $this->data['SERVERS']['NTP']= array("default");
502     $ldap->cd ($this->current['BASE']);
503     $ldap->search ("(objectClass=goNtpServer)");
504     while ($attrs= $ldap->fetch()){
505       $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
506     }
507     $ldap->cd ($this->current['BASE']);
508     $ldap->search ("(objectClass=goSyslogServer)");
509     while ($attrs= $ldap->fetch()){
510       $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
511     }
513     /* Get samba servers from LDAP, in case of samba3 */
514     if ($this->current['SAMBAVERSION'] == 3){
515       $this->data['SERVERS']['SAMBA']= array();
516       $ldap->cd ($this->current['BASE']);
517       $ldap->search ("(objectClass=sambaDomain)");
518       while ($attrs= $ldap->fetch()){
519         $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array(
520             "SID" => $attrs["sambaSID"][0],
521             "RIDBASE" => $attrs["sambaAlgorithmicRidBase"][0]);
522       }
524       /* If no samba servers are found, look for configured sid/ridbase */
525       if (count($this->data['SERVERS']['SAMBA']) == 0){
526         if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
527           print_red(_("SID and/or RIDBASE missing in your configuration!"));
528           echo $_SESSION['errors'];
529           exit;
530         } else {
531           $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
532               "SID" => $this->current["SID"],
533               "RIDBASE" => $this->current["RIDBASE"]);
534         }
535       }
536     }
537   }
540   function get_departments($ignore_dn= "")
541   {
542     global $config;
544     /* Initialize result hash */
545     $result= array();
546     $administrative= array();
547     $result['/']= $this->current['BASE'];
548     $this->tdepartments= array();
550     /* Get list of department objects */
551     $ldap= $this->get_ldap_link();
552     $ldap->cd ($this->current['BASE']);
553     $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
554     while ($attrs= $ldap->fetch()){
555       $dn= $ldap->getDN();
556       $this->tdepartments[$dn]= "";
558       /* Save administrative departments */
559       if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
560           isset($attrs['gosaUnitTag'][0])){
561         $administrative[$dn]= $attrs['gosaUnitTag'][0];
562         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
563       }
564     
565       if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
566           isset($attrs['gosaUnitTag'][0])){
567         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
568       }
569     
570       if ($dn == $ignore_dn){
571         continue;
572       }
574       /* Only assign non-root departments */
575       if ($dn != $result['/']){
576         $result[convert_department_dn($dn)]= $dn;
577       }
578     }
580     $this->adepartments= $administrative;
581     $this->departments= $result;
582   }
585   function make_idepartments($max_size= 28)
586   {
587     global $config;
588     $base = $config->current['BASE'];
590     $arr = array();
591     $ui= get_userinfo();
593     $this->idepartments= array();
595     /* Create multidimensional array, with all departments. */
596     foreach ($this->departments as $key => $val){
598       /* When using strict_units, filter non relevant parts */
599       if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
600         if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
601             $this->tdepartments[$val] != $ui->gosaUnitTag){
602           continue;
603         }
604       }
606       /* remove base from dn */
607       $val2 = str_replace($base,"",$val);
609       /* Get every single ou */
610       $str = preg_replace("/ou=/","|ou=",$val2);        
611       $elements = array_reverse(split("\|",$str));              
613       /* Save last array position */
614       $last = &$arr;
616       /* Get array depth  */
617       $cnt = count($elements);
619       /* Add last ou element of current dn to our array */
620       foreach($elements as $key => $ele){
622         /* skip enpty */
623         if(empty($ele)) continue;
625         /* Extract department name */           
626         $elestr = preg_replace("/^ou=/","", $ele);
627         $elestr = preg_replace("/,$/","",$elestr);      
629         /* Add to array */      
630         if($key == ($cnt-2)){
631           $last[$elestr]['ENTRY'] = $val;
632         }
634         /* Set next array appending position */
635         $last = &$last[$elestr]['SUB'];
636       }
637     }
639     /* Add base entry */
640     $ret["/"]["ENTRY"]  = $base;
641     $ret["/"]["SUB"]    = $arr;
643     $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
644   }
647   /* Creates display friendly output from make_idepartments */
648   function generateDepartmentArray($arr,$depth = -1,$max_size){
649     $ret = array();
650     $depth ++;
652     /* Walk through array */    
653     ksort($arr);
654     foreach($arr as $name => $entries){
656       /* If this department is the last in the current tree position 
657        * remove it, to avoid generating output for it */
658       if(count($entries['SUB'])==0){
659         unset($entries['SUB']);
660       }
662       /* Fix name, if it contains a replace tag */
663       $name= @LDAP::fix($name);
665       /* Check if current name is too long, then cut it */
666       if(mb_strlen($name, 'UTF-8')> $max_size){
667         $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
668       }
670       /* Append the name to the list */ 
671       if(isset($entries['ENTRY'])){
672         $a = "";
673         for($i = 0 ; $i < $depth ; $i ++){
674           $a.=".";
675         }
676         $ret[$entries['ENTRY']]=$a."&nbsp;".$name;
677       } 
679       /* recursive add of subdepartments */
680       if(isset($entries['SUB'])){
681         $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
682       }
683     }
685     return($ret);
686   }
688   /* This function returns all available Shares defined in this ldap
689    * There are two ways to call this function, if listboxEntry is true
690    *  only name and path are attached to the array, in it is false, the whole
691    *  entry will be parsed an atached to the result.
692    */
693   function getShareList($listboxEntry = false)
694   {
695     $ldap= $this->get_ldap_link();
696     $base =  $this->current['BASE'];
697     $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",$base,array("goExportEntry","cn"),GL_SUBSEARCH);
698     $return = array();
700     foreach($res as $entry){
701       if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
703         if(isset($entry['goExportEntry']['count'])){
704           unset($entry['goExportEntry']['count']);
705         }
706         if(isset($entry['goExportEntry'])){
707           foreach($entry['goExportEntry'] as $export){
708             $shareAttrs = split("\|",$export);
709             if($listboxEntry) {
710               $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
711             }else{
712               $return[$shareAttrs[0]."|".$entry['cn'][0]]['server']       = $entry['cn'][0];
713               $return[$shareAttrs[0]."|".$entry['cn'][0]]['name']         = $shareAttrs[0];
714               $return[$shareAttrs[0]."|".$entry['cn'][0]]['description']  = $shareAttrs[1];
715               $return[$shareAttrs[0]."|".$entry['cn'][0]]['type']         = $shareAttrs[2];
716               $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset']      = $shareAttrs[3];
717               $return[$shareAttrs[0]."|".$entry['cn'][0]]['path']         = $shareAttrs[4];
718               $return[$shareAttrs[0]."|".$entry['cn'][0]]['option']       = $shareAttrs[5];
719             }
720           }
721         }
722       } 
723     }
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'];
736     $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server", $base,array("goExportEntry","cn"),GL_SUBSEARCH);
737     foreach($res as $entry){
738       if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
739         if(isset($entry['goExportEntry']['count'])){
740           unset($entry['goExportEntry']['count']);
741         }
742         foreach($entry['goExportEntry'] as $share){
743           $a_share = split("\|",$share);
744           $sharename = $a_share[0];
745           $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
746         }
747       }
748     }
749     return($return);
750   }
752   /* Check if there's the specified bool value set in the configuration */
753   function boolValueIsTrue($section, $value)
754   {
755     $section= strtoupper($section);
756     $value= strtoupper($value);
757     if (isset($this->data[$section][$value])){
758     
759       $data= $this->data[$section][$value];
760       if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
761         return TRUE;
762       }
764     }
766     return FALSE;
767   }
770   function __search(&$arr, $name, $return)
771   {
772     $return= strtoupper($return);
773     if (is_array($arr)){
774       foreach ($arr as &$a){
775         if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
776           return(isset($a[$return])?$a[$return]:"");
777         } else {
778           $res= $this->__search ($a, $name, $return);
779           if ($res != ""){
780             return $res;
781           }
782         }
783       }
784     }
785     return ("");
786   }
789   function search($class, $value, $categories= "")
790   {
791     if (is_array($categories)){
792       foreach ($categories as $category){
793         $res= $this->__search($this->data[strtoupper($category)], $class, $value);
794         if ($res != ""){
795           return $res;
796         }
797       }
798     } else {
799       if ($categories == "") {
800         return $this->__search($this->data, $class, $value);
801       } else {
802         return $this->__search($this->data[strtoupper($categories)], $class, $value);
803       }
804     } 
806     return ("");
807   }
810   /* On debian systems the session files are deleted with
811    *  a cronjob, which detects all files older than specified 
812    *  in php.ini:'session.gc_maxlifetime' and removes them.
813    * This function checks if the gosa.conf value matches the range
814    *  defined by session.gc_maxlifetime.
815    */
816   function check_session_lifetime()
817   {
818     $cfg_lifetime = $this->data['MAIN']['SESSION_LIFETIME'];
819     $ini_lifetime = ini_get('session.gc_maxlifetime');
820     $deb_system   = file_exists('/etc/debian_version');
821     return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));  
822   }
825 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
826 ?>