Code

Added fall back to old style move method.
[gosa.git] / gosa-core / include / class_config.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class config  {
25   /* XML parser */
26   var $parser;
27   var $config_found= FALSE;
28   var $tags= array();
29   var $level= 0;
30   var $gpc= 0;
31   var $section= "";
32   var $currentLocation= "";
34   /* Selected connection */
35   var $current= array();
37   /* Link to LDAP-server */
38   var $ldap= NULL;
39   var $referrals= array();
41   /* Configuration data */
42   var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(),
43       'MAIN' => array(),
44       'MENU' => array(), 'SERVICE' => array());
45   var $basedir= "";
46   var $config_version ="";
48   /* Keep a copy of the current deparment list */
49   var $departments= array();
50   var $idepartments= array();
51   var $adepartments= array();
52   var $tdepartments= array();
53   var $filename = "";
54   var $last_modified = 0;
56   function config($filename, $basedir= "")
57   {
58     $this->parser = xml_parser_create();
59     $this->basedir= $basedir;
61     xml_set_object($this->parser, $this);
62     xml_set_element_handler($this->parser, "tag_open", "tag_close");
64     /* Parse config file directly? */
65     if ($filename != ""){
66       $this->parse($filename);
67     }
68   }
70   
71   function check_and_reload()
72   {
73     if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
75       $this->config_found= FALSE;
76       $this->tags= array();
77       $this->level= 0;
78       $this->gpc= 0;
79       $this->section= "";
80       $this->currentLocation= "";
82       $this->parser = xml_parser_create();
83       xml_set_object($this->parser, $this);
84       xml_set_element_handler($this->parser, "tag_open", "tag_close");
85       $this->parse($this->filename);
86       if(session::is_set('plist')){
87         session::un_set('plist');
88       }
89       if(session::is_set('plug')){
90         session::un_set('plug');
91       }
92       if(isset($_GET['plug'])){
93         unset($_GET['plug']);
94       }
95     }
96   }  
99   function parse($filename)
100   { 
101     $this->last_modified = filemtime($filename);
102     $this->filename = $filename;
103     $fh= fopen($filename, "r"); 
104     $xmldata= fread($fh, 100000);
105     fclose($fh); 
106     if(!xml_parse($this->parser, chop($xmldata))){
107       $msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
108             xml_error_string(xml_get_error_code($this->parser)),
109             xml_get_current_line_number($this->parser));
110       msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG);
111       exit;
112     }
113   }
115   function tag_open($parser, $tag, $attrs)
116   {
117     /* Save last and current tag for reference */
118     $this->tags[$this->level]= $tag;
119     $this->level++;
121     /* Trigger on CONF section */
122     if ($tag == 'CONF'){
123       $this->config_found= TRUE;
124       if(isset($attrs['CONFIG_VERSION'])){
125         $this->config_version = $attrs['CONFIG_VERSION'];
126       }
127     }
129     /* Return if we're not in config section */
130     if (!$this->config_found){
131       return;
132     }
134     /* yes/no to true/false and upper case TRUE to true and so on*/
135     foreach($attrs as $name => $value){
136       if(preg_match("/^(true|yes)$/i",$value)){
137         $attrs[$name] = "true";
138       }elseif(preg_match("/^(false|no)$/i",$value)){
139         $attrs[$name] = "false";
140       } 
141     }
143     /* Look through attributes */
144     switch ($this->tags[$this->level-1]){
147       /* Handle tab section */
148       case 'TAB':       $name= $this->tags[$this->level-2];
150                   /* Create new array? */
151                   if (!isset($this->data['TABS'][$name])){
152                     $this->data['TABS'][$name]= array();
153                   }
155                   /* Add elements */
156                   $this->data['TABS'][$name][]= $attrs;
157                   break;
159                   /* Handle location */
160       case 'LOCATION':
161                   if ($this->tags[$this->level-2] == 'MAIN'){
162                     $name= $attrs['NAME'];
163                     $this->currentLocation= $name;
165                     /* Add location elements */
166                       $this->data['LOCATIONS'][$name]= $attrs;
167                     }
168                   break;
170                   /* Handle referral tags */
171       case 'REFERRAL':
172                   if ($this->tags[$this->level-2] == 'LOCATION'){
173                     $url= $attrs['URL'];
174                     $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
176                     /* Add location elements */
177                     if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
178                       $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
179                     }
181                     $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
182                   }
183                   break;
185                   /* Load main parameters */
186       case 'MAIN':
187                   $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
188                   break;
190                   /* Load menu */
191       case 'SECTION':
192                   if ($this->tags[$this->level-2] == 'MENU'){
193                     $this->section= $attrs['NAME'];
194                     $this->data['MENU'][$this->section]= array(); ;
195                   }
196                   break;
198                   /* Inser plugins */
199       case 'PLUGIN':
200                   if ($this->tags[$this->level-3] == 'MENU' &&
201                       $this->tags[$this->level-2] == 'SECTION'){
203                     $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
204                   }
205                   if ($this->tags[$this->level-2] == 'SERVICEMENU'){
206                     $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
207                   }
208                   break;
209     }
210   }
212   function tag_close($parser, $tag)
213   {
214     /* Close config section */
215     if ($tag == 'CONF'){
216       $this->config_found= FALSE;
217     }
218     $this->level--;
219   }
222   function get_credentials($creds)
223   {
224     if (isset($_SERVER['HTTP_GOSA_KEY'])){
225       return (cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY']));
226     }
227     return ($creds);
228   }
231   function get_ldap_link($sizelimit= FALSE)
232   {
233     if($this->ldap === NULL || !is_resource($this->ldap->cid)){
235       /* Build new connection */
236       $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
237           $this->current['ADMIN'], $this->get_credentials($this->current['PASSWORD']));
239       /* Check for connection */
240       if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
241         $smarty= get_smarty();
242         msg_dialog::display(_("LDAP error"), _("Cannot bind to LDAP. Please contact the system administrator."), FATAL_ERROR_DIALOG);
243         exit();
244       }
246       if (!session::is_set('size_limit')){
247         session::set('size_limit',$this->current['SIZELIMIT']);
248         session::set('size_ignore',$this->current['SIZEIGNORE']);
249       }
251       if ($sizelimit){
252         $this->ldap->set_size_limit(session::get('size_limit'));
253       } else {
254         $this->ldap->set_size_limit(0);
255       }
257       /* Move referrals */
258       if (!isset($this->current['REFERRAL'])){
259         $this->ldap->referrals= array();
260       } else {
261         $this->ldap->referrals= $this->current['REFERRAL'];
262       }
263     }
265     return new ldapMultiplexer($this->ldap);
266   }
268   function set_current($name)
269   {
270     $this->current= $this->data['LOCATIONS'][$name];
271     if (!isset($this->current['PEOPLE'])){
272       $this->current['PEOPLE']= "ou=people";
273     }
274     if (!isset($this->current['GROUPS'])){
275       $this->current['GROUPS']= "ou=groups";
276     }
278     if (isset($this->current['INITIAL_BASE'])){
279       session::set('CurrentMainBase',$this->current['INITIAL_BASE']);
280     }
281   
282     /* Remove possibly added ',' from end of group and people ou */
283     $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
284     $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
286     if (!isset($this->current['WINSTATIONS'])){
287       $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
288     }
289     if (!isset($this->current['HASH'])){
290       $this->current['HASH']= "crypt";
291     }
292     if (!isset($this->current['DNMODE'])){
293       $this->current['DNMODE']= "cn";
294     }
295     if (!isset($this->current['MINID'])){
296       $this->current['MINID']= 100;
297     }
298     if (!isset($this->current['SIZELIMIT'])){
299       $this->current['SIZELIMIT']= 200;
300     }
301     if (!isset($this->current['SIZEINGORE'])){
302       $this->current['SIZEIGNORE']= TRUE;
303     } else {
304       if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
305         $this->current['SIZEIGNORE']= TRUE;
306       } else {
307         $this->current['SIZEIGNORE']= FALSE;
308       }
309     }
311     /* Sort referrals, if present */
312     if (isset ($this->current['REFERRAL'])){
313       $bases= array();
314       $servers= array();
315       foreach ($this->current['REFERRAL'] as $ref){
316         $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
317         $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
318         $bases[$base]= strlen($base);
319         $servers[$base]= $server;
320       }
321       asort($bases);
322       reset($bases);
323     }
325     /* SERVER not defined? Load the one with the shortest base */
326     if (!isset($this->current['SERVER'])){
327       $this->current['SERVER']= $servers[key($bases)];
328     }
330     /* BASE not defined? Load the one with the shortest base */
331     if (!isset($this->current['BASE'])){
332       $this->current['BASE']= key($bases);
333     }
335     /* Convert BASE to have escaped special characters */
336     $this->current['BASE']= @LDAP::convert($this->current['BASE']);
338     /* Parse LDAP referral informations */
339     if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
340       $url= $this->current['SERVER'];
341       $referral= $this->current['REFERRAL'][$url];
342       $this->current['ADMIN']= $referral['ADMIN'];
343       $this->current['PASSWORD']= $referral['PASSWORD'];
344     }
346     /* Load server informations */
347     $this->load_servers();
348   }
350   function load_servers ()
351   {
352     /* Only perform actions if current is set */
353     if ($this->current === NULL){
354       return;
355     }
357     /* Fill imap servers */
358     $ldap= $this->get_ldap_link();
359     $ldap->cd ($this->current['BASE']);
360     if (!isset($this->current['MAILMETHOD'])){
361       $this->current['MAILMETHOD']= "";
362     }
363     if ($this->current['MAILMETHOD'] == ""){
364       $ldap->search ("(objectClass=goMailServer)", array('cn'));
365       $this->data['SERVERS']['IMAP']= array();
366       error_reporting(0);
367       while ($attrs= $ldap->fetch()){
368         $name= $attrs['cn'][0];
369         $this->data['SERVERS']['IMAP'][$name]= $name;
370       }
371       error_reporting(E_ALL);
372     } else {
373       $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
374             'goImapSieveServer', 'goImapSievePort'));
376       $this->data['SERVERS']['IMAP']= array();
377       error_reporting(0);
378       while ($attrs= $ldap->fetch()){
379         $name= $attrs['goImapName'][0];
380         $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
381             "admin" => $attrs['goImapAdmin'][0],
382             "password" => $attrs['goImapPassword'][0],
383             "sieve_server" => $attrs['goImapSieveServer'][0],
384             "sieve_port" => $attrs['goImapSievePort'][0]);
385       }
386       error_reporting(E_ALL);
387     }
389     /* Get kerberos server. FIXME: only one is supported currently */
390     $ldap->cd ($this->current['BASE']);
391     $ldap->search ("(&(goKrbRealm=*)(goKrbAdmin=*)(objectClass=goKrbServer))");
392     if ($ldap->count()){
393       $attrs= $ldap->fetch();
394       $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
395           'REALM' => $attrs['goKrbRealm'][0],
396           'ADMIN' => $attrs['goKrbAdmin'][0]);
397     }
399     /* Get cups server. FIXME: only one is supported currently */
400     $ldap->cd ($this->current['BASE']);
401     $ldap->search ("(objectClass=goCupsServer)");
402     if ($ldap->count()){
403       $attrs= $ldap->fetch();
404       $this->data['SERVERS']['CUPS']= $attrs['cn'][0];  
405     }
407     /* Get fax server. FIXME: only one is supported currently */
408     $ldap->cd ($this->current['BASE']);
409     $ldap->search ("(objectClass=goFaxServer)");
410     if ($ldap->count()){
411       $attrs= $ldap->fetch();
412       $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
413           'LOGIN' => $attrs['goFaxAdmin'][0],
414           'PASSWORD' => $attrs['goFaxPassword'][0]);
415     }
418     /* Get asterisk servers */
419     $ldap->cd ($this->current['BASE']);
420     $ldap->search ("(objectClass=goFonServer)");
421     $this->data['SERVERS']['FON']= array();
422     if ($ldap->count()){
423       while ($attrs= $ldap->fetch()){
425         /* Add 0 entry for development */
426         if(count($this->data['SERVERS']['FON']) == 0){
427           $this->data['SERVERS']['FON'][0]= array(
428               'DN'      => $attrs['dn'],
429               'SERVER'  => $attrs['cn'][0],
430               'LOGIN'   => $attrs['goFonAdmin'][0],
431               'PASSWORD'  => $attrs['goFonPassword'][0],
432               'DB'    => "gophone",
433               'SIP_TABLE'   => "sip_users",
434               'EXT_TABLE'   => "extensions",
435               'VOICE_TABLE' => "voicemail_users",
436               'QUEUE_TABLE' => "queues",
437               'QUEUE_MEMBER_TABLE'  => "queue_members");
438         }
440         /* Add entry with 'dn' as index */
441         $this->data['SERVERS']['FON'][$attrs['dn']]= array(
442             'DN'      => $attrs['dn'],
443             'SERVER'  => $attrs['cn'][0],
444             'LOGIN'   => $attrs['goFonAdmin'][0],
445             'PASSWORD'  => $attrs['goFonPassword'][0],
446             'DB'    => "gophone",
447             'SIP_TABLE'   => "sip_users",
448             'EXT_TABLE'   => "extensions",
449             'VOICE_TABLE' => "voicemail_users",
450             'QUEUE_TABLE' => "queues",
451             'QUEUE_MEMBER_TABLE'  => "queue_members");
452       }
453     }
456     /* Get glpi server */
457     $ldap->cd ($this->current['BASE']);
458     $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
459     if ($ldap->count()){
460       $attrs= $ldap->fetch();
461       if(!isset($attrs['goGlpiPassword'])){
462         $attrs['goGlpiPassword'][0] ="";
463       }
464       $this->data['SERVERS']['GLPI']= array( 
465           'SERVER'      => $attrs['cn'][0],
466           'LOGIN'       => $attrs['goGlpiAdmin'][0],
467           'PASSWORD'    => $attrs['goGlpiPassword'][0],
468           'DB'          => $attrs['goGlpiDatabase'][0]);
469     }
472     /* Get logdb server */
473     $ldap->cd ($this->current['BASE']);
474     $ldap->search ("(objectClass=goLogDBServer)");
475     if ($ldap->count()){
476       $attrs= $ldap->fetch();
477       $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
478           'LOGIN' => $attrs['goLogAdmin'][0],
479           'PASSWORD' => $attrs['goLogPassword'][0]);
480     }
483     /* GOsa logging databases */
484     $ldap->cd ($this->current['BASE']);
485     $ldap->search ("(objectClass=gosaLogServer)");
486     if ($ldap->count()){
487       while($attrs= $ldap->fetch()){
488       $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]= 
489           array(
490           'DN'    => $attrs['dn'],
491           'USER'  => $attrs['goLogDBUser'][0],
492           'DB'    => $attrs['goLogDB'][0],
493           'PWD'   => $attrs['goLogDBPassword'][0]);
494       }
495     }
498     /* Get NFS server lists */
499     $tmp= array("default");
500     $ldap->cd ($this->current['BASE']);
501     $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
502     while ($attrs= $ldap->fetch()){
503       for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
504         if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
505           continue;
506         }
507         $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
508         $tmp[]= $attrs["cn"][0].":$path";
509       }
510     }
511     $this->data['SERVERS']['NFS']= $tmp;
513     /* Load Terminalservers */
514     $ldap->cd ($this->current['BASE']);
515     $ldap->search ("(objectClass=goTerminalServer)",array("cn","gotoSessionType"));
516     $this->data['SERVERS']['TERMINAL']= array();
517     $this->data['SERVERS']['TERMINAL'][]= "default";
518     $this->data['SERVERS']['TERMINAL_SESSION_TYPES'] = array();
521     while ($attrs= $ldap->fetch()){
522       $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
523       if(isset( $attrs["gotoSessionType"]['count'])){
524         for($i =0 ; $i < $attrs["gotoSessionType"]['count'] ; $i++){
525           $this->data['SERVERS']['TERMINAL_SESSION_TYPES'][$attrs["cn"][0]][] = $attrs["gotoSessionType"][$i]; 
526         }
527       }
528     }
530     /* Ldap Server */
531     $this->data['SERVERS']['LDAP']= array();
532     $ldap->cd ($this->current['BASE']);
533     $ldap->search ("(objectClass=goLdapServer)");
534     while ($attrs= $ldap->fetch()){
535       if (isset($attrs["goLdapBase"])){
536         for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
537           $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
538         }
539       }
540     }
542     /* Get misc server lists */
543     $this->data['SERVERS']['SYSLOG']= array("default");
544     $this->data['SERVERS']['NTP']= array("default");
545     $ldap->cd ($this->current['BASE']);
546     $ldap->search ("(objectClass=goNtpServer)");
547     while ($attrs= $ldap->fetch()){
548       $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
549     }
550     $ldap->cd ($this->current['BASE']);
551     $ldap->search ("(objectClass=goSyslogServer)");
552     while ($attrs= $ldap->fetch()){
553       $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
554     }
556     /* Get samba servers from LDAP, in case of samba3 */
557     if ($this->current['SAMBAVERSION'] == 3){
558       $this->data['SERVERS']['SAMBA']= array();
559       $ldap->cd ($this->current['BASE']);
560       $ldap->search ("(objectClass=sambaDomain)");
561       while ($attrs= $ldap->fetch()){
562         $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
563         if(isset($attrs["sambaSID"][0])){
564           $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"]  = $attrs["sambaSID"][0];
565         }
566         if(isset($attrs["sambaAlgorithmicRidBase"][0])){
567           $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
568         }
569       }
571       /* If no samba servers are found, look for configured sid/ridbase */
572       if (count($this->data['SERVERS']['SAMBA']) == 0){
573         if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
574           msg_dialog::display(_("Configuration error"), _("SID and/or RIDBASE missing in the configuration!"), FATAL_ERROR_DIALOG);
575           exit();
576         } else {
577           $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
578               "SID" => $this->current["SID"],
579               "RIDBASE" => $this->current["RIDBASE"]);
580         }
581       }
582     }
583   }
586   function get_departments($ignore_dn= "")
587   {
588     global $config;
590     /* Initialize result hash */
591     $result= array();
592     $administrative= array();
593     $result['/']= $this->current['BASE'];
594     $this->tdepartments= array();
596     /* Get list of department objects */
597     $ldap= $this->get_ldap_link();
598     $ldap->cd ($this->current['BASE']);
599     $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
600     while ($attrs= $ldap->fetch()){
601       $dn= $ldap->getDN();
602       $this->tdepartments[$dn]= "";
604       /* Save administrative departments */
605       if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
606           isset($attrs['gosaUnitTag'][0])){
607         $administrative[$dn]= $attrs['gosaUnitTag'][0];
608         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
609       }
610     
611       if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
612           isset($attrs['gosaUnitTag'][0])){
613         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
614       }
615     
616       if ($dn == $ignore_dn){
617         continue;
618       }
620       /* Only assign non-root departments */
621       if ($dn != $result['/']){
622         $result[convert_department_dn($dn)]= $dn;
623       }
624     }
626     $this->adepartments= $administrative;
627     $this->departments= $result;
628   }
631   function make_idepartments($max_size= 28)
632   {
633     global $config;
634     $base = $config->current['BASE'];
636     $arr = array();
637     $ui= get_userinfo();
639     $this->idepartments= array();
641     /* Create multidimensional array, with all departments. */
642     foreach ($this->departments as $key => $val){
644       /* When using strict_units, filter non relevant parts */
645       if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
646         if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
647             $this->tdepartments[$val] != $ui->gosaUnitTag){
648 #          continue;
649         }
650       }
652       /* remove base from dn */
653       $val2 = str_replace($base,"",$val);
655       /* Get every single ou */
656       $str = preg_replace("/ou=/","|ou=",$val2);        
657       $elements = array_reverse(split("\|",$str));              
659       /* Save last array position */
660       $last = &$arr;
662       /* Get array depth  */
663       $cnt = count($elements);
665       /* Add last ou element of current dn to our array */
666       foreach($elements as $key => $ele){
668         /* skip enpty */
669         if(empty($ele)) continue;
671         /* Extract department name */           
672         $elestr = preg_replace("/^ou=/","", $ele);
673         $elestr = preg_replace("/,$/","",$elestr);      
675         /* Add to array */      
676         if($key == ($cnt-2)){
677           $last[$elestr]['ENTRY'] = $val;
678         }
680         /* Set next array appending position */
681         $last = &$last[$elestr]['SUB'];
682       }
683     }
685     /* Add base entry */
686     $ret["/"]["ENTRY"]  = $base;
687     $ret["/"]["SUB"]    = $arr;
689     $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
690   }
693   /* Creates display friendly output from make_idepartments */
694   function generateDepartmentArray($arr,$depth = -1,$max_size){
695     $ret = array();
696     $depth ++;
698     /* Walk through array */    
699     ksort($arr);
700     foreach($arr as $name => $entries){
702       /* If this department is the last in the current tree position 
703        * remove it, to avoid generating output for it */
704       if(count($entries['SUB'])==0){
705         unset($entries['SUB']);
706       }
708       /* Fix name, if it contains a replace tag */
709       $name= @LDAP::fix($name);
711       /* Check if current name is too long, then cut it */
712       if(mb_strlen($name, 'UTF-8')> $max_size){
713         $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
714       }
716       /* Append the name to the list */ 
717       if(isset($entries['ENTRY'])){
718         $a = "";
719         for($i = 0 ; $i < $depth ; $i ++){
720           $a.=".";
721         }
722         $ret[$entries['ENTRY']]=$a."&nbsp;".$name;
723       } 
725       /* recursive add of subdepartments */
726       if(isset($entries['SUB'])){
727         $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
728       }
729     }
731     return($ret);
732   }
734   /* This function returns all available Shares defined in this ldap
735    * There are two ways to call this function, if listboxEntry is true
736    *  only name and path are attached to the array, in it is false, the whole
737    *  entry will be parsed an atached to the result.
738    */
739   function getShareList($listboxEntry = false)
740   {
741     $tmp = get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",get_ou("serverou"),
742         $this->current['BASE'],array("goExportEntry","cn"), GL_NONE);
743     $return =array();
744     foreach($tmp as $entry){
746       if(isset($entry['goExportEntry']['count'])){
747         unset($entry['goExportEntry']['count']);
748       }
749       if(isset($entry['goExportEntry'])){
750         foreach($entry['goExportEntry'] as $export){
751           $shareAttrs = split("\|",$export);
752           if($listboxEntry) {
753             $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
754           }else{
755             $return[$shareAttrs[0]."|".$entry['cn'][0]]['server']       = $entry['cn'][0];
756             $return[$shareAttrs[0]."|".$entry['cn'][0]]['name']         = $shareAttrs[0];
757             $return[$shareAttrs[0]."|".$entry['cn'][0]]['description']  = $shareAttrs[1];
758             $return[$shareAttrs[0]."|".$entry['cn'][0]]['type']         = $shareAttrs[2];
759             $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset']      = $shareAttrs[3];
760             $return[$shareAttrs[0]."|".$entry['cn'][0]]['path']         = $shareAttrs[4];
761             $return[$shareAttrs[0]."|".$entry['cn'][0]]['option']       = $shareAttrs[5];
762           }
763         }
764       }
765     }
766     return($return);
767   }
770   /* This function returns all available ShareServer */
771   function getShareServerList()
772   {
773     global $config;
774     $return = array();
775     $base = $config->current['BASE'];
776     $res= get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server",
777           get_ou("serverou"), $base,array("goExportEntry","cn"),GL_NONE);
779     foreach($res as $entry){
780         if(isset($entry['goExportEntry']['count'])){
781           unset($entry['goExportEntry']['count']);
782         }
783         foreach($entry['goExportEntry'] as $share){
784           $a_share = split("\|",$share);
785           $sharename = $a_share[0];
786           $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
787         }
788     }
789     return($return);
790   }
793   /* Check if there's the specified bool value set in the configuration */
794   function boolValueIsTrue($section, $value)
795   {
796     $section= strtoupper($section);
797     $value= strtoupper($value);
798     if (isset($this->data[$section][$value])){
799     
800       $data= $this->data[$section][$value];
801       if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
802         return TRUE;
803       }
805     }
807     return FALSE;
808   }
811   function __search(&$arr, $name, $return)
812   {
813     $return= strtoupper($return);
814     if (is_array($arr)){
815       foreach ($arr as &$a){
816         if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
817           return(isset($a[$return])?$a[$return]:"");
818         } else {
819           $res= $this->__search ($a, $name, $return);
820           if ($res != ""){
821             return $res;
822           }
823         }
824       }
825     }
826     return ("");
827   }
830   function search($class, $value, $categories= "")
831   {
832     if (is_array($categories)){
833       foreach ($categories as $category){
834         $res= $this->__search($this->data[strtoupper($category)], $class, $value);
835         if ($res != ""){
836           return $res;
837         }
838       }
839     } else {
840       if ($categories == "") {
841         return $this->__search($this->data, $class, $value);
842       } else {
843         return $this->__search($this->data[strtoupper($categories)], $class, $value);
844       }
845     } 
847     return ("");
848   }
851   function check_config_version()
852   {
854     $current = get_gosa_version();
856     /* Skip check, if we've already mentioned the mismatch 
857      */
858     if(session::is_set("LastChecked") && session::get("LastChecked") == $this->config_version) return;
859   
860     /* Remember last checked version 
861      */
862     session::set("LastChecked",$this->config_version);
864     if(preg_match("/\(Rev[^\)]*\)/",$current)){
866       /* Development Version 
867        */
868       $c_v = preg_replace("/^.*\(Rev ([0-9]*)\).*$/","\\1",$current);
869       $g_v = preg_replace("/^.*\(Rev ([0-9]*)\).*$/","\\1",$this->config_version);
870       if($c_v != $g_v){
871 #        msg_dialog::display(_("Configuration"),_("The configuration file you are using seems to be outdated. Please move the GOsa configuration file away to run the GOsa setup again."));
872       }
873     }else{
875       /* Tagged version 
876        */
877       if($this->config_version != $current){
878         msg_dialog::display(_("Configuration"),_("The configuration file you are using seems to be outdated. Please move the GOsa configuration file away to run the GOsa setup again."));
879       }
880     }
881   }
884   /* On debian systems the session files are deleted with
885    *  a cronjob, which detects all files older than specified 
886    *  in php.ini:'session.gc_maxlifetime' and removes them.
887    * This function checks if the gosa.conf value matches the range
888    *  defined by session.gc_maxlifetime.
889    */
890   function check_session_lifetime()
891   {
892     $cfg_lifetime = $this->data['MAIN']['SESSION_LIFETIME'];
893     $ini_lifetime = ini_get('session.gc_maxlifetime');
894     $deb_system   = file_exists('/etc/debian_version');
895     return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));  
896   }
899 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
900 ?>