Code

Some updates
[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( 'LANGUAGES' => 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 language */
147       case 'LANGUAGE':
148                   if ($this->tags[$this->level-2] == 'MAIN'){
149                     /* Add languages */
150                     $this->data['MAIN']['LANGUAGES'][$attrs['NAME']]= 
151                       $attrs['TAG'];
152                   }
153                   break;
155                   /* Handle faxformat */
156       case 'FAXFORMAT': 
157                   if ($this->tags[$this->level-2] == 'MAIN'){
158                     /* Add fax formats */
159                     $this->data['MAIN']['FAXFORMATS'][]= $attrs['TYPE'];
160                   }
161                   break;
163                   /* Load main parameters */
164       case 'MAIN':
165                   $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
166                   break;
168                   /* Load menu */
169       case 'SECTION':
170                   if ($this->tags[$this->level-2] == 'MENU'){
171                     $this->section= $attrs['NAME'];
172                     $this->data['MENU'][$this->section]= array(); ;
173                   }
174                   break;
176                   /* Inser plugins */
177       case 'PLUGIN':
178                   if ($this->tags[$this->level-3] == 'MENU' &&
179                       $this->tags[$this->level-2] == 'SECTION'){
181                     $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
182                   }
183                   if ($this->tags[$this->level-2] == 'SERVICEMENU'){
184                     $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
185                   }
186                   break;
187     }
188   }
190   function tag_close($parser, $tag)
191   {
192     /* Close config section */
193     if ($tag == 'CONF'){
194       $this->config_found= FALSE;
195     }
196     $this->level--;
197   }
199   function get_ldap_link($sizelimit= FALSE)
200   {
201     /* Build new connection */
202     $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
203         $this->current['ADMIN'], $this->current['PASSWORD']);
205     /* Check for connection */
206     if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
207       $smarty= get_smarty();
208       print_red (_("Can't bind to LDAP. Please contact the system administrator."));
209       $smarty->display (get_template_path('headers.tpl'));
210       echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
211       exit();
212     }
214     if (!isset($_SESSION['size_limit'])){
215       $_SESSION['size_limit']= $this->current['SIZELIMIT'];
216       $_SESSION['size_ignore']= $this->current['SIZEIGNORE'];
217     }
219     if ($sizelimit){
220       $this->ldap->set_size_limit($_SESSION['size_limit']);
221     } else {
222       $this->ldap->set_size_limit(0);
223     }
225     /* Move referrals */
226     if (!isset($this->current['REFERRAL'])){
227       $this->ldap->referrals= array();
228     } else {
229       $this->ldap->referrals= $this->current['REFERRAL'];
230     }
232     return ($this->ldap);
233   }
235   function set_current($name)
236   {
237     $this->current= $this->data['LOCATIONS'][$name];
238     if (!isset($this->current['PEOPLE'])){
239       $this->current['PEOPLE']= "ou=people";
240     }
241     if (!isset($this->current['GROUPS'])){
242       $this->current['GROUPS']= "ou=groups";
243     }
244   
245     /* Remove possibly added ',' from end of group and people ou */
246     $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
247     $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
249     if (!isset($this->current['WINSTATIONS'])){
250       $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
251     }
252     if (!isset($this->current['HASH'])){
253       $this->current['HASH']= "crypt";
254     }
255     if (!isset($this->current['DNMODE'])){
256       $this->current['DNMODE']= "cn";
257     }
258     if (!isset($this->current['MINID'])){
259       $this->current['MINID']= 100;
260     }
261     if (!isset($this->current['SIZELIMIT'])){
262       $this->current['SIZELIMIT']= 200;
263     }
264     if (!isset($this->current['SIZEINGORE'])){
265       $this->current['SIZEIGNORE']= TRUE;
266     } else {
267       if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
268         $this->current['SIZEIGNORE']= TRUE;
269       } else {
270         $this->current['SIZEIGNORE']= FALSE;
271       }
272     }
274     /* Sort referrals, if present */
275     if (isset ($this->current['REFERRAL'])){
276       $bases= array();
277       $servers= array();
278       foreach ($this->current['REFERRAL'] as $ref){
279         $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
280         $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
281         $bases[$base]= strlen($base);
282         $servers[$base]= $server;
283       }
284       asort($bases);
285       reset($bases);
286     }
288     /* SERVER not defined? Load the one with the shortest base */
289     if (!isset($this->current['SERVER'])){
290       $this->current['SERVER']= $servers[key($bases)];
291     }
293     /* BASE not defined? Load the one with the shortest base */
294     if (!isset($this->current['BASE'])){
295       $this->current['BASE']= key($bases);
296     }
298     /* Convert BASE to have escaped special characters */
299     $this->current['BASE']= @LDAP::convert($this->current['BASE']);
301     /* Parse LDAP referral informations */
302     if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
303       $url= $this->current['SERVER'];
304       $referral= $this->current['REFERRAL'][$url];
305       $this->current['ADMIN']= $referral['ADMIN'];
306       $this->current['PASSWORD']= $referral['PASSWORD'];
307     }
309     /* Load server informations */
310     $this->load_servers();
311   }
313   function load_servers ()
314   {
315     /* Only perform actions if current is set */
316     if ($this->current == NULL){
317       return;
318     }
320     /* Fill imap servers */
321     $ldap= $this->get_ldap_link();
322     $ldap->cd ($this->current['BASE']);
323     $ldap->search ("(objectClass=goImapServer)");
325     $this->data['SERVERS']['IMAP']= array();
326     error_reporting(0);
327     while ($attrs= $ldap->fetch()){
328       $name= $attrs['goImapName'][0];
329       $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
330           "admin" => $attrs['goImapAdmin'][0],
331           "password" => $attrs['goImapPassword'][0],
332           "sieve_server" => $attrs['goImapSieveServer'][0],
333           "sieve_port" => $attrs['goImapSievePort'][0]);
334     }
335     error_reporting(E_ALL);
337     /* Get kerberos server. FIXME: only one is supported currently */
338     $ldap->cd ($this->current['BASE']);
339     $ldap->search ("(objectClass=goKrbServer)");
340     if ($ldap->count()){
341       $attrs= $ldap->fetch();
342       $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
343           'REALM' => $attrs['goKrbRealm'][0],
344           'ADMIN' => $attrs['goKrbAdmin'][0],
345           'PASSWORD' => $attrs['goKrbPassword'][0]);
346     }
348     /* Get cups server. FIXME: only one is supported currently */
349     $ldap->cd ($this->current['BASE']);
350     $ldap->search ("(objectClass=goCupsServer)");
351     if ($ldap->count()){
352       $attrs= $ldap->fetch();
353       $this->data['SERVERS']['CUPS']= $attrs['cn'][0];  
354     }
356     /* Get fax server. FIXME: only one is supported currently */
357     $ldap->cd ($this->current['BASE']);
358     $ldap->search ("(objectClass=goFaxServer)");
359     if ($ldap->count()){
360       $attrs= $ldap->fetch();
361       $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
362           'LOGIN' => $attrs['goFaxAdmin'][0],
363           'PASSWORD' => $attrs['goFaxPassword'][0]);
364     }
367     /* Get asterisk servers */
368     $ldap->cd ($this->current['BASE']);
369     $ldap->search ("(objectClass=goFonServer)");
370     $this->data['SERVERS']['FON']= array();
371     if ($ldap->count()){
372       while ($attrs= $ldap->fetch()){
374         /* Add 0 entry for development */
375         if(count($this->data['SERVERS']['FON']) == 0){
376           $this->data['SERVERS']['FON'][0]= array(
377               'DN'      => $attrs['dn'],
378               'SERVER'  => $attrs['cn'][0],
379               'LOGIN'   => $attrs['goFonAdmin'][0],
380               'PASSWORD'  => $attrs['goFonPassword'][0],
381               'DB'    => "gophone",
382               'SIP_TABLE'   => "sip_users",
383               'EXT_TABLE'   => "extensions",
384               'VOICE_TABLE' => "voicemail_users",
385               'QUEUE_TABLE' => "queues",
386               'QUEUE_MEMBER_TABLE'  => "queue_members");
387         }
389         /* Add entry with 'dn' as index */
390         $this->data['SERVERS']['FON'][$attrs['dn']]= array(
391             'DN'      => $attrs['dn'],
392             'SERVER'  => $attrs['cn'][0],
393             'LOGIN'   => $attrs['goFonAdmin'][0],
394             'PASSWORD'  => $attrs['goFonPassword'][0],
395             'DB'    => "gophone",
396             'SIP_TABLE'   => "sip_users",
397             'EXT_TABLE'   => "extensions",
398             'VOICE_TABLE' => "voicemail_users",
399             'QUEUE_TABLE' => "queues",
400             'QUEUE_MEMBER_TABLE'  => "queue_members");
401       }
402     }
405     /* Get glpi server */
406     $ldap->cd ($this->current['BASE']);
407     $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
408     if ($ldap->count()){
409       $attrs= $ldap->fetch();
410       if(!isset($attrs['goGlpiPassword'])){
411         $attrs['goGlpiPassword'][0] ="";
412       }
413       $this->data['SERVERS']['GLPI']= array( 
414           'SERVER'      => $attrs['cn'][0],
415           'LOGIN'       => $attrs['goGlpiAdmin'][0],
416           'PASSWORD'    => $attrs['goGlpiPassword'][0],
417           'DB'          => $attrs['goGlpiDatabase'][0]);
418     }
419     /* Get logdb server */
420     $ldap->cd ($this->current['BASE']);
421     $ldap->search ("(objectClass=goLogDBServer)");
422     if ($ldap->count()){
423       $attrs= $ldap->fetch();
424       $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
425           'LOGIN' => $attrs['goLogAdmin'][0],
426           'PASSWORD' => $attrs['goLogPassword'][0]);
427     }
429     /* Get NFS server lists */
430     $tmp= array("default");
431     $ldap->cd ($this->current['BASE']);
432     $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
433     while ($attrs= $ldap->fetch()){
434       for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
435         if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
436           continue;
437         }
438         $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
439         $tmp[]= $attrs["cn"][0].":$path";
440       }
441     }
442     $this->data['SERVERS']['NFS']= $tmp;
444     /* Load Terminalservers */
445     $ldap->cd ($this->current['BASE']);
446     $ldap->search ("(objectClass=goTerminalServer)");
447     $this->data['SERVERS']['TERMINAL']= array();
448     $this->data['SERVERS']['TERMINAL'][]= "default";
450     $this->data['SERVERS']['FONT']= array();
451     $this->data['SERVERS']['FONT'][]= "default";
452     while ($attrs= $ldap->fetch()){
453       $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
454       for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
455         $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
456       }
457     }
459     /* Ldap Server */
460     $this->data['SERVERS']['LDAP']= array();
461     $ldap->cd ($this->current['BASE']);
462     $ldap->search ("(objectClass=goLdapServer)");
463     while ($attrs= $ldap->fetch()){
464       if (isset($attrs["goLdapBase"])){
465         for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
466           $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
467         }
468       }
469     }
471     /* Get misc server lists */
472     $this->data['SERVERS']['SYSLOG']= array("default");
473     $this->data['SERVERS']['NTP']= array("default");
474     $ldap->cd ($this->current['BASE']);
475     $ldap->search ("(objectClass=goNtpServer)");
476     while ($attrs= $ldap->fetch()){
477       $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
478     }
479     $ldap->cd ($this->current['BASE']);
480     $ldap->search ("(objectClass=goSyslogServer)");
481     while ($attrs= $ldap->fetch()){
482       $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
483     }
485     /* Get samba servers from LDAP, in case of samba3 */
486     if ($this->current['SAMBAVERSION'] == 3){
487       $this->data['SERVERS']['SAMBA']= array();
488       $ldap->cd ($this->current['BASE']);
489       $ldap->search ("(objectClass=sambaDomain)");
490       while ($attrs= $ldap->fetch()){
491         $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array(
492             "SID" => $attrs["sambaSID"][0],
493             "RIDBASE" => $attrs["sambaAlgorithmicRidBase"][0]);
494       }
496       /* If no samba servers are found, look for configured sid/ridbase */
497       if (count($this->data['SERVERS']['SAMBA']) == 0){
498         if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
499           print_red(_("SID and/or RIDBASE missing in your configuration!"));
500           echo $_SESSION['errors'];
501           exit;
502         } else {
503           $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
504               "SID" => $this->current["SID"],
505               "RIDBASE" => $this->current["RIDBASE"]);
506         }
507       }
508     }
509   }
512   function get_departments($ignore_dn= "")
513   {
514     global $config;
516     /* Initialize result hash */
517     $result= array();
518     $administrative= array();
519     $result['/']= $this->current['BASE'];
520     $this->tdepartments= array();
522     /* Get list of department objects */
523     $ldap= $this->get_ldap_link();
524     $ldap->cd ($this->current['BASE']);
525     $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
526     while ($attrs= $ldap->fetch()){
527       $dn= $ldap->getDN();
528       $this->tdepartments[$dn]= "";
530       /* Save administrative departments */
531       if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
532           isset($attrs['gosaUnitTag'][0])){
533         $administrative[$dn]= $attrs['gosaUnitTag'][0];
534         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
535       }
536     
537       if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
538           isset($attrs['gosaUnitTag'][0])){
539         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
540       }
541     
542       if ($dn == $ignore_dn){
543         continue;
544       }
546       /* Only assign non-root departments */
547       if ($dn != $result['/']){
548         $result[convert_department_dn($dn)]= $dn;
549       }
550     }
552     $this->adepartments= $administrative;
553     $this->departments= $result;
554   }
557   function make_idepartments($max_size= 28)
558   {
559     global $config;
560     $base = $config->current['BASE'];
562     $arr = array();
563     $ui= get_userinfo();
565     $this->idepartments= array();
567     /* Create multidimensional array, with all departments. */
568     foreach ($this->departments as $key => $val){
570       /* When using strict_units, filter non relevant parts */
571       if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
572         if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
573             $this->tdepartments[$val] != $ui->gosaUnitTag){
574           continue;
575         }
576       }
578       /* remove base from dn */
579       $val2 = str_replace($base,"",$val);
581       /* Get every single ou */
582       $str = preg_replace("/ou=/","|ou=",$val2);        
583       $elements = array_reverse(split("\|",$str));              
585       /* Save last array position */
586       $last = &$arr;
588       /* Get array depth  */
589       $cnt = count($elements);
591       /* Add last ou element of current dn to our array */
592       foreach($elements as $key => $ele){
594         /* skip enpty */
595         if(empty($ele)) continue;
597         /* Extract department name */           
598         $elestr = preg_replace("/^ou=/","", $ele);
599         $elestr = preg_replace("/,$/","",$elestr);      
601         /* Add to array */      
602         if($key == ($cnt-2)){
603           $last[$elestr]['ENTRY'] = $val;
604         }
606         /* Set next array appending position */
607         $last = &$last[$elestr]['SUB'];
608       }
609     }
611     /* Add base entry */
612     $ret["/"]["ENTRY"]  = $base;
613     $ret["/"]["SUB"]    = $arr;
615     $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
616   }
619   /* Creates display friendly output from make_idepartments */
620   function generateDepartmentArray($arr,$depth = -1,$max_size){
621     $ret = array();
622     $depth ++;
624     /* Walk through array */    
625     foreach($arr as $name => $entries){
627       /* If this department is the last in the current tree position 
628        * remove it, to avoid generating output for it */
629       if(count($entries['SUB'])==0){
630         unset($entries['SUB']);
631       }
633       /* Fix name, if it contains a replace tag */
634       $name= @LDAP::fix($name);
636       /* Check if current name is too long, then cut it */
637       if(mb_strlen($name, 'UTF-8')> $max_size){
638         $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
639       }
641       /* Append the name to the list */ 
642       if(isset($entries['ENTRY'])){
643         $a = "";
644         for($i = 0 ; $i < $depth ; $i ++){
645           $a.="&nbsp;";
646         }
647         $ret[$entries['ENTRY']]=$a."&nbsp;".$name;
648       } 
650       /* recursive add of subdepartments */
651       if(isset($entries['SUB'])){
652         $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
653       }
654     }
656     return($ret);
657   }
659   /* This function returns all available Shares defined in this ldap
660    * There are two ways to call this function, if listboxEntry is true
661    *  only name and path are attached to the array, in it is false, the whole
662    *  entry will be parsed an atached to the result.
663    */
664   function getShareList($listboxEntry = false)
665   {
666     $ldap= $this->get_ldap_link();
667     $base =  $this->current['BASE'];
668     $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",$base,array("goExportEntry","cn"),GL_SUBSEARCH);
669     $return = array();
671     foreach($res as $entry){
672       if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
674         if(isset($entry['goExportEntry']['count'])){
675           unset($entry['goExportEntry']['count']);
676         }
677         if(isset($entry['goExportEntry'])){
678           foreach($entry['goExportEntry'] as $export){
679             $shareAttrs = split("\|",$export);
680             if($listboxEntry) {
681               $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
682             }else{
683               $return[$shareAttrs[0]."|".$entry['cn'][0]]['server']       = $entry['cn'][0];
684               $return[$shareAttrs[0]."|".$entry['cn'][0]]['name']         = $shareAttrs[0];
685               $return[$shareAttrs[0]."|".$entry['cn'][0]]['description']  = $shareAttrs[1];
686               $return[$shareAttrs[0]."|".$entry['cn'][0]]['type']         = $shareAttrs[2];
687               $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset']      = $shareAttrs[3];
688               $return[$shareAttrs[0]."|".$entry['cn'][0]]['path']         = $shareAttrs[4];
689               $return[$shareAttrs[0]."|".$entry['cn'][0]]['option']       = $shareAttrs[5];
690             }
691           }
692         }
693       } 
694     }
696     return($return);
697   }
699   /* This function returns all available ShareServer */
700   function getShareServerList()
701   {
702     global $config;
703     $return = array();
704     $ui = get_userinfo();
705     $base = $config->current['BASE'];
707     $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server", $base,array("goExportEntry","cn"),GL_SUBSEARCH);
708     foreach($res as $entry){
709       if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
710         if(isset($entry['goExportEntry']['count'])){
711           unset($entry['goExportEntry']['count']);
712         }
713         foreach($entry['goExportEntry'] as $share){
714           $a_share = split("\|",$share);
715           $sharename = $a_share[0];
716           $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
717         }
718       }
719     }
720     return($return);
721   }
723   /* Check if there's the specified bool value set in the configuration */
724   function boolValueIsTrue($section, $value)
725   {
726     $section= strtoupper($section);
727     $value= strtoupper($value);
728     if (isset($this->data[$section][$value])){
729     
730       $data= $this->data[$section][$value];
731       if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
732         return TRUE;
733       }
735     }
737     return FALSE;
738   }
742 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
743 ?>