Code

Updated gotomasses.
[gosa.git] / gosa-core / 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();
50   var $filename = "";
51   var $last_modified = 0;
53   function config($filename, $basedir= "")
54   {
55     $this->parser = xml_parser_create();
56     $this->basedir= $basedir;
58     xml_set_object($this->parser, $this);
59     xml_set_element_handler($this->parser, "tag_open", "tag_close");
61     /* Parse config file directly? */
62     if ($filename != ""){
63       $this->parse($filename);
64     }
65   }
67   
68   function check_and_reload()
69   {
70     if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
72       $this->config_found= FALSE;
73       $this->tags= array();
74       $this->level= 0;
75       $this->gpc= 0;
76       $this->section= "";
77       $this->currentLocation= "";
79       $this->parser = xml_parser_create();
80       xml_set_object($this->parser, $this);
81       xml_set_element_handler($this->parser, "tag_open", "tag_close");
82       $this->parse($this->filename);
83       if(session::is_set('plist')){
84         session::un_set('plist');
85       }
86       if(session::is_set('plug')){
87         session::un_set('plug');
88       }
89       if(isset($_GET['plug'])){
90         unset($_GET['plug']);
91       }
92     }
93   }  
96   function parse($filename)
97   { 
98     $this->last_modified = filemtime($filename);
99     $this->filename = $filename;
100     $fh= fopen($filename, "r"); 
101     $xmldata= fread($fh, 100000);
102     fclose($fh); 
103     if(!xml_parse($this->parser, chop($xmldata))){
104       $msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
105             xml_error_string(xml_get_error_code($this->parser)),
106             xml_get_current_line_number($this->parser));
107       msg_dialog::display(_("Config file parsing"), $msg, FATAL_ERROR_DIALOG);
108       exit;
109     }
110   }
112   function tag_open($parser, $tag, $attrs)
113   { 
114     /* Save last and current tag for reference */
115     $this->tags[$this->level]= $tag;
116     $this->level++;
118     /* Trigger on CONF section */
119     if ($tag == 'CONF'){
120       $this->config_found= TRUE;
121     }
123     /* Return if we're not in config section */
124     if (!$this->config_found){
125       return;
126     }
128     /* yes/no to true/false and upper case TRUE to true and so on*/
129     foreach($attrs as $name => $value){
130       if(preg_match("/^(true|yes)$/i",$value)){
131         $attrs[$name] = "true";
132       }elseif(preg_match("/^(false|no)$/i",$value)){
133         $attrs[$name] = "false";
134       } 
135     }
137     /* Look through attributes */
138     switch ($this->tags[$this->level-1]){
141       /* Handle tab section */
142       case 'TAB':       $name= $this->tags[$this->level-2];
144                   /* Create new array? */
145                   if (!isset($this->data['TABS'][$name])){
146                     $this->data['TABS'][$name]= array();
147                   }
149                   /* Add elements */
150                   $this->data['TABS'][$name][]= $attrs;
151                   break;
153                   /* Handle location */
154       case 'LOCATION':
155                   if ($this->tags[$this->level-2] == 'MAIN'){
156                     $name= $attrs['NAME'];
157                     $this->currentLocation= $name;
159                     /* Add location elements */
160                       $this->data['LOCATIONS'][$name]= $attrs;
161                     }
162                   break;
164                   /* Handle referral tags */
165       case 'REFERRAL':
166                   if ($this->tags[$this->level-2] == 'LOCATION'){
167                     $url= $attrs['URL'];
168                     $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
170                     /* Add location elements */
171                     if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
172                       $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
173                     }
175                     $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
176                   }
177                   break;
179                   /* Load main parameters */
180       case 'MAIN':
181                   $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
182                   break;
184                   /* Load menu */
185       case 'SECTION':
186                   if ($this->tags[$this->level-2] == 'MENU'){
187                     $this->section= $attrs['NAME'];
188                     $this->data['MENU'][$this->section]= array(); ;
189                   }
190                   break;
192                   /* Inser plugins */
193       case 'PLUGIN':
194                   if ($this->tags[$this->level-3] == 'MENU' &&
195                       $this->tags[$this->level-2] == 'SECTION'){
197                     $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
198                   }
199                   if ($this->tags[$this->level-2] == 'SERVICEMENU'){
200                     $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
201                   }
202                   break;
203     }
204   }
206   function tag_close($parser, $tag)
207   {
208     /* Close config section */
209     if ($tag == 'CONF'){
210       $this->config_found= FALSE;
211     }
212     $this->level--;
213   }
215   function get_ldap_link($sizelimit= FALSE)
216   {
217     /* Build new connection */
218     $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
219         $this->current['ADMIN'], $this->current['PASSWORD']);
221     /* Check for connection */
222     if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
223       $smarty= get_smarty();
224       msg_dialog::display(_("LDAP error"), _("Can't bind to LDAP. Please contact the system administrator."), ERROR_DIALOG);
225       display_error_page();
226     }
228     if (!session::is_set('size_limit')){
229       session::set('size_limit',$this->current['SIZELIMIT']);
230       session::set('size_ignore',$this->current['SIZEIGNORE']);
231     }
233     if ($sizelimit){
234       $this->ldap->set_size_limit(session::get('size_limit'));
235     } else {
236       $this->ldap->set_size_limit(0);
237     }
239     /* Move referrals */
240     if (!isset($this->current['REFERRAL'])){
241       $this->ldap->referrals= array();
242     } else {
243       $this->ldap->referrals= $this->current['REFERRAL'];
244     }
246     return ($this->ldap);
247   }
249   function set_current($name)
250   {
251     $this->current= $this->data['LOCATIONS'][$name];
252     if (!isset($this->current['PEOPLE'])){
253       $this->current['PEOPLE']= "ou=people";
254     }
255     if (!isset($this->current['GROUPS'])){
256       $this->current['GROUPS']= "ou=groups";
257     }
259     if (isset($this->current['INITIAL_BASE'])){
260       session::set('CurrentMainBase',$this->current['INITIAL_BASE']);
261     }
262   
263     /* Remove possibly added ',' from end of group and people ou */
264     $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
265     $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
267     if (!isset($this->current['WINSTATIONS'])){
268       $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
269     }
270     if (!isset($this->current['HASH'])){
271       $this->current['HASH']= "crypt";
272     }
273     if (!isset($this->current['DNMODE'])){
274       $this->current['DNMODE']= "cn";
275     }
276     if (!isset($this->current['MINID'])){
277       $this->current['MINID']= 100;
278     }
279     if (!isset($this->current['SIZELIMIT'])){
280       $this->current['SIZELIMIT']= 200;
281     }
282     if (!isset($this->current['SIZEINGORE'])){
283       $this->current['SIZEIGNORE']= TRUE;
284     } else {
285       if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
286         $this->current['SIZEIGNORE']= TRUE;
287       } else {
288         $this->current['SIZEIGNORE']= FALSE;
289       }
290     }
292     /* Sort referrals, if present */
293     if (isset ($this->current['REFERRAL'])){
294       $bases= array();
295       $servers= array();
296       foreach ($this->current['REFERRAL'] as $ref){
297         $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
298         $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
299         $bases[$base]= strlen($base);
300         $servers[$base]= $server;
301       }
302       asort($bases);
303       reset($bases);
304     }
306     /* SERVER not defined? Load the one with the shortest base */
307     if (!isset($this->current['SERVER'])){
308       $this->current['SERVER']= $servers[key($bases)];
309     }
311     /* BASE not defined? Load the one with the shortest base */
312     if (!isset($this->current['BASE'])){
313       $this->current['BASE']= key($bases);
314     }
316     /* Convert BASE to have escaped special characters */
317     $this->current['BASE']= @LDAP::convert($this->current['BASE']);
319     /* Parse LDAP referral informations */
320     if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
321       $url= $this->current['SERVER'];
322       $referral= $this->current['REFERRAL'][$url];
323       $this->current['ADMIN']= $referral['ADMIN'];
324       $this->current['PASSWORD']= $referral['PASSWORD'];
325     }
327     /* Load server informations */
328     $this->load_servers();
329   }
331   function load_servers ()
332   {
333     /* Only perform actions if current is set */
334     if ($this->current === NULL){
335       return;
336     }
338     /* Fill imap servers */
339     $ldap= $this->get_ldap_link();
340     $ldap->cd ($this->current['BASE']);
341     if (!isset($this->current['MAILMETHOD'])){
342       $this->current['MAILMETHOD']= "";
343     }
344     if ($this->current['MAILMETHOD'] == ""){
345       $ldap->search ("(objectClass=goMailServer)", array('cn'));
346       $this->data['SERVERS']['IMAP']= array();
347       error_reporting(0);
348       while ($attrs= $ldap->fetch()){
349         $name= $attrs['cn'][0];
350         $this->data['SERVERS']['IMAP'][$name]= $name;
351       }
352       error_reporting(E_ALL);
353     } else {
354       $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
355             'goImapSieveServer', 'goImapSievePort'));
357       $this->data['SERVERS']['IMAP']= array();
358       error_reporting(0);
359       while ($attrs= $ldap->fetch()){
360         $name= $attrs['goImapName'][0];
361         $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
362             "admin" => $attrs['goImapAdmin'][0],
363             "password" => $attrs['goImapPassword'][0],
364             "sieve_server" => $attrs['goImapSieveServer'][0],
365             "sieve_port" => $attrs['goImapSievePort'][0]);
366       }
367       error_reporting(E_ALL);
368     }
370     /* Get kerberos server. FIXME: only one is supported currently */
371     $ldap->cd ($this->current['BASE']);
372     $ldap->search ("(objectClass=goKrbServer)");
373     if ($ldap->count()){
374       $attrs= $ldap->fetch();
375       $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
376           'REALM' => $attrs['goKrbRealm'][0],
377           'ADMIN' => $attrs['goKrbAdmin'][0],
378           'PASSWORD' => $attrs['goKrbPassword'][0]);
379     }
381     /* Get cups server. FIXME: only one is supported currently */
382     $ldap->cd ($this->current['BASE']);
383     $ldap->search ("(objectClass=goCupsServer)");
384     if ($ldap->count()){
385       $attrs= $ldap->fetch();
386       $this->data['SERVERS']['CUPS']= $attrs['cn'][0];  
387     }
389     /* Get fax server. FIXME: only one is supported currently */
390     $ldap->cd ($this->current['BASE']);
391     $ldap->search ("(objectClass=goFaxServer)");
392     if ($ldap->count()){
393       $attrs= $ldap->fetch();
394       $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
395           'LOGIN' => $attrs['goFaxAdmin'][0],
396           'PASSWORD' => $attrs['goFaxPassword'][0]);
397     }
400     /* Get asterisk servers */
401     $ldap->cd ($this->current['BASE']);
402     $ldap->search ("(objectClass=goFonServer)");
403     $this->data['SERVERS']['FON']= array();
404     if ($ldap->count()){
405       while ($attrs= $ldap->fetch()){
407         /* Add 0 entry for development */
408         if(count($this->data['SERVERS']['FON']) == 0){
409           $this->data['SERVERS']['FON'][0]= array(
410               'DN'      => $attrs['dn'],
411               'SERVER'  => $attrs['cn'][0],
412               'LOGIN'   => $attrs['goFonAdmin'][0],
413               'PASSWORD'  => $attrs['goFonPassword'][0],
414               'DB'    => "gophone",
415               'SIP_TABLE'   => "sip_users",
416               'EXT_TABLE'   => "extensions",
417               'VOICE_TABLE' => "voicemail_users",
418               'QUEUE_TABLE' => "queues",
419               'QUEUE_MEMBER_TABLE'  => "queue_members");
420         }
422         /* Add entry with 'dn' as index */
423         $this->data['SERVERS']['FON'][$attrs['dn']]= array(
424             'DN'      => $attrs['dn'],
425             'SERVER'  => $attrs['cn'][0],
426             'LOGIN'   => $attrs['goFonAdmin'][0],
427             'PASSWORD'  => $attrs['goFonPassword'][0],
428             'DB'    => "gophone",
429             'SIP_TABLE'   => "sip_users",
430             'EXT_TABLE'   => "extensions",
431             'VOICE_TABLE' => "voicemail_users",
432             'QUEUE_TABLE' => "queues",
433             'QUEUE_MEMBER_TABLE'  => "queue_members");
434       }
435     }
438     /* Get glpi server */
439     $ldap->cd ($this->current['BASE']);
440     $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
441     if ($ldap->count()){
442       $attrs= $ldap->fetch();
443       if(!isset($attrs['goGlpiPassword'])){
444         $attrs['goGlpiPassword'][0] ="";
445       }
446       $this->data['SERVERS']['GLPI']= array( 
447           'SERVER'      => $attrs['cn'][0],
448           'LOGIN'       => $attrs['goGlpiAdmin'][0],
449           'PASSWORD'    => $attrs['goGlpiPassword'][0],
450           'DB'          => $attrs['goGlpiDatabase'][0]);
451     }
454     /* Get logdb server */
455     $ldap->cd ($this->current['BASE']);
456     $ldap->search ("(objectClass=goLogDBServer)");
457     if ($ldap->count()){
458       $attrs= $ldap->fetch();
459       $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
460           'LOGIN' => $attrs['goLogAdmin'][0],
461           'PASSWORD' => $attrs['goLogPassword'][0]);
462     }
465     /* GOsa logging databases */
466     $ldap->cd ($this->current['BASE']);
467     $ldap->search ("(objectClass=gosaLogServer)");
468     if ($ldap->count()){
469       while($attrs= $ldap->fetch()){
470       $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]= 
471           array(
472           'DN'    => $attrs['dn'],
473           'USER'  => $attrs['goLogDBUser'][0],
474           'DB'    => $attrs['goLogDB'][0],
475           'PWD'   => $attrs['goLogDBPassword'][0]);
476       }
477     }
480     /* Get NFS server lists */
481     $tmp= array("default");
482     $ldap->cd ($this->current['BASE']);
483     $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
484     while ($attrs= $ldap->fetch()){
485       for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
486         if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
487           continue;
488         }
489         $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
490         $tmp[]= $attrs["cn"][0].":$path";
491       }
492     }
493     $this->data['SERVERS']['NFS']= $tmp;
495     /* Load Terminalservers */
496     $ldap->cd ($this->current['BASE']);
497     $ldap->search ("(objectClass=goTerminalServer)",array("cn","gotoSessionType"));
498     $this->data['SERVERS']['TERMINAL']= array();
499     $this->data['SERVERS']['TERMINAL'][]= "default";
500     $this->data['SERVERS']['TERMINAL_SESSION_TYPES'] = array();
503     while ($attrs= $ldap->fetch()){
504       $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
505       if(isset( $attrs["gotoSessionType"]['count'])){
506         for($i =0 ; $i < $attrs["gotoSessionType"]['count'] ; $i++){
507           $this->data['SERVERS']['TERMINAL_SESSION_TYPES'][$attrs["cn"][0]][] = $attrs["gotoSessionType"][$i]; 
508         }
509       }
510     }
512     /* Ldap Server */
513     $this->data['SERVERS']['LDAP']= array();
514     $ldap->cd ($this->current['BASE']);
515     $ldap->search ("(objectClass=goLdapServer)");
516     while ($attrs= $ldap->fetch()){
517       if (isset($attrs["goLdapBase"])){
518         for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
519           $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
520         }
521       }
522     }
524     /* Get misc server lists */
525     $this->data['SERVERS']['SYSLOG']= array("default");
526     $this->data['SERVERS']['NTP']= array("default");
527     $ldap->cd ($this->current['BASE']);
528     $ldap->search ("(objectClass=goNtpServer)");
529     while ($attrs= $ldap->fetch()){
530       $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
531     }
532     $ldap->cd ($this->current['BASE']);
533     $ldap->search ("(objectClass=goSyslogServer)");
534     while ($attrs= $ldap->fetch()){
535       $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
536     }
538     /* Get samba servers from LDAP, in case of samba3 */
539     if ($this->current['SAMBAVERSION'] == 3){
540       $this->data['SERVERS']['SAMBA']= array();
541       $ldap->cd ($this->current['BASE']);
542       $ldap->search ("(objectClass=sambaDomain)");
543       while ($attrs= $ldap->fetch()){
544         $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
545         if(isset($attrs["sambaSID"][0])){
546           $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"]  = $attrs["sambaSID"][0];
547         }
548         if(isset($attrs["sambaAlgorithmicRidBase"][0])){
549           $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
550         }
551       }
553       /* If no samba servers are found, look for configured sid/ridbase */
554       if (count($this->data['SERVERS']['SAMBA']) == 0){
555         if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
556           msg_dialog::display(_("Configuration error"), _("SID and/or RIDBASE missing in the configuration!"), ERROR_DIALOG);
557           display_error_page();
558         } else {
559           $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
560               "SID" => $this->current["SID"],
561               "RIDBASE" => $this->current["RIDBASE"]);
562         }
563       }
564     }
565   }
568   function get_departments($ignore_dn= "")
569   {
570     global $config;
572     /* Initialize result hash */
573     $result= array();
574     $administrative= array();
575     $result['/']= $this->current['BASE'];
576     $this->tdepartments= array();
578     /* Get list of department objects */
579     $ldap= $this->get_ldap_link();
580     $ldap->cd ($this->current['BASE']);
581     $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
582     while ($attrs= $ldap->fetch()){
583       $dn= $ldap->getDN();
584       $this->tdepartments[$dn]= "";
586       /* Save administrative departments */
587       if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
588           isset($attrs['gosaUnitTag'][0])){
589         $administrative[$dn]= $attrs['gosaUnitTag'][0];
590         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
591       }
592     
593       if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
594           isset($attrs['gosaUnitTag'][0])){
595         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
596       }
597     
598       if ($dn == $ignore_dn){
599         continue;
600       }
602       /* Only assign non-root departments */
603       if ($dn != $result['/']){
604         $result[convert_department_dn($dn)]= $dn;
605       }
606     }
608     $this->adepartments= $administrative;
609     $this->departments= $result;
610   }
613   function make_idepartments($max_size= 28)
614   {
615     global $config;
616     $base = $config->current['BASE'];
618     $arr = array();
619     $ui= get_userinfo();
621     $this->idepartments= array();
623     /* Create multidimensional array, with all departments. */
624     foreach ($this->departments as $key => $val){
626       /* When using strict_units, filter non relevant parts */
627       if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
628         if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
629             $this->tdepartments[$val] != $ui->gosaUnitTag){
630 #          continue;
631         }
632       }
634       /* remove base from dn */
635       $val2 = str_replace($base,"",$val);
637       /* Get every single ou */
638       $str = preg_replace("/ou=/","|ou=",$val2);        
639       $elements = array_reverse(split("\|",$str));              
641       /* Save last array position */
642       $last = &$arr;
644       /* Get array depth  */
645       $cnt = count($elements);
647       /* Add last ou element of current dn to our array */
648       foreach($elements as $key => $ele){
650         /* skip enpty */
651         if(empty($ele)) continue;
653         /* Extract department name */           
654         $elestr = preg_replace("/^ou=/","", $ele);
655         $elestr = preg_replace("/,$/","",$elestr);      
657         /* Add to array */      
658         if($key == ($cnt-2)){
659           $last[$elestr]['ENTRY'] = $val;
660         }
662         /* Set next array appending position */
663         $last = &$last[$elestr]['SUB'];
664       }
665     }
667     /* Add base entry */
668     $ret["/"]["ENTRY"]  = $base;
669     $ret["/"]["SUB"]    = $arr;
671     $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
672   }
675   /* Creates display friendly output from make_idepartments */
676   function generateDepartmentArray($arr,$depth = -1,$max_size){
677     $ret = array();
678     $depth ++;
680     /* Walk through array */    
681     ksort($arr);
682     foreach($arr as $name => $entries){
684       /* If this department is the last in the current tree position 
685        * remove it, to avoid generating output for it */
686       if(count($entries['SUB'])==0){
687         unset($entries['SUB']);
688       }
690       /* Fix name, if it contains a replace tag */
691       $name= @LDAP::fix($name);
693       /* Check if current name is too long, then cut it */
694       if(mb_strlen($name, 'UTF-8')> $max_size){
695         $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
696       }
698       /* Append the name to the list */ 
699       if(isset($entries['ENTRY'])){
700         $a = "";
701         for($i = 0 ; $i < $depth ; $i ++){
702           $a.=".";
703         }
704         $ret[$entries['ENTRY']]=$a."&nbsp;".$name;
705       } 
707       /* recursive add of subdepartments */
708       if(isset($entries['SUB'])){
709         $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
710       }
711     }
713     return($ret);
714   }
716   /* This function returns all available Shares defined in this ldap
717    * There are two ways to call this function, if listboxEntry is true
718    *  only name and path are attached to the array, in it is false, the whole
719    *  entry will be parsed an atached to the result.
720    */
721   function getShareList($listboxEntry = false)
722   {
723     $ldap= $this->get_ldap_link();
724     $base =  $this->current['BASE'];
725     $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",$base,array("goExportEntry","cn"),GL_SUBSEARCH);
726     $return = array();
728     foreach($res as $entry){
729       if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
731         if(isset($entry['goExportEntry']['count'])){
732           unset($entry['goExportEntry']['count']);
733         }
734         if(isset($entry['goExportEntry'])){
735           foreach($entry['goExportEntry'] as $export){
736             $shareAttrs = split("\|",$export);
737             if($listboxEntry) {
738               $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
739             }else{
740               $return[$shareAttrs[0]."|".$entry['cn'][0]]['server']       = $entry['cn'][0];
741               $return[$shareAttrs[0]."|".$entry['cn'][0]]['name']         = $shareAttrs[0];
742               $return[$shareAttrs[0]."|".$entry['cn'][0]]['description']  = $shareAttrs[1];
743               $return[$shareAttrs[0]."|".$entry['cn'][0]]['type']         = $shareAttrs[2];
744               $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset']      = $shareAttrs[3];
745               $return[$shareAttrs[0]."|".$entry['cn'][0]]['path']         = $shareAttrs[4];
746               $return[$shareAttrs[0]."|".$entry['cn'][0]]['option']       = $shareAttrs[5];
747             }
748           }
749         }
750       } 
751     }
753     return($return);
754   }
756   /* This function returns all available ShareServer */
757   function getShareServerList()
758   {
759     global $config;
760     $return = array();
761     $ui = get_userinfo();
762     $base = $config->current['BASE'];
764     $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server", $base,array("goExportEntry","cn"),GL_SUBSEARCH);
765     foreach($res as $entry){
766       if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
767         if(isset($entry['goExportEntry']['count'])){
768           unset($entry['goExportEntry']['count']);
769         }
770         foreach($entry['goExportEntry'] as $share){
771           $a_share = split("\|",$share);
772           $sharename = $a_share[0];
773           $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
774         }
775       }
776     }
777     return($return);
778   }
780   /* Check if there's the specified bool value set in the configuration */
781   function boolValueIsTrue($section, $value)
782   {
783     $section= strtoupper($section);
784     $value= strtoupper($value);
785     if (isset($this->data[$section][$value])){
786     
787       $data= $this->data[$section][$value];
788       if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
789         return TRUE;
790       }
792     }
794     return FALSE;
795   }
798   function __search(&$arr, $name, $return)
799   {
800     $return= strtoupper($return);
801     if (is_array($arr)){
802       foreach ($arr as &$a){
803         if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
804           return(isset($a[$return])?$a[$return]:"");
805         } else {
806           $res= $this->__search ($a, $name, $return);
807           if ($res != ""){
808             return $res;
809           }
810         }
811       }
812     }
813     return ("");
814   }
817   function search($class, $value, $categories= "")
818   {
819     if (is_array($categories)){
820       foreach ($categories as $category){
821         $res= $this->__search($this->data[strtoupper($category)], $class, $value);
822         if ($res != ""){
823           return $res;
824         }
825       }
826     } else {
827       if ($categories == "") {
828         return $this->__search($this->data, $class, $value);
829       } else {
830         return $this->__search($this->data[strtoupper($categories)], $class, $value);
831       }
832     } 
834     return ("");
835   }
838   /* On debian systems the session files are deleted with
839    *  a cronjob, which detects all files older than specified 
840    *  in php.ini:'session.gc_maxlifetime' and removes them.
841    * This function checks if the gosa.conf value matches the range
842    *  defined by session.gc_maxlifetime.
843    */
844   function check_session_lifetime()
845   {
846     $cfg_lifetime = $this->data['MAIN']['SESSION_LIFETIME'];
847     $ini_lifetime = ini_get('session.gc_maxlifetime');
848     $deb_system   = file_exists('/etc/debian_version');
849     return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));  
850   }
853 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
854 ?>