Code

5f3d8ceb56b0c281fe144fbd073d6a04109b6c5d
[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     }
245     if (isset($this->current['INITIAL_BASE'])){
246       $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
247     }
248   
249     /* Remove possibly added ',' from end of group and people ou */
250     $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
251     $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
253     if (!isset($this->current['WINSTATIONS'])){
254       $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
255     }
256     if (!isset($this->current['HASH'])){
257       $this->current['HASH']= "crypt";
258     }
259     if (!isset($this->current['DNMODE'])){
260       $this->current['DNMODE']= "cn";
261     }
262     if (!isset($this->current['MINID'])){
263       $this->current['MINID']= 100;
264     }
265     if (!isset($this->current['SIZELIMIT'])){
266       $this->current['SIZELIMIT']= 200;
267     }
268     if (!isset($this->current['SIZEINGORE'])){
269       $this->current['SIZEIGNORE']= TRUE;
270     } else {
271       if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
272         $this->current['SIZEIGNORE']= TRUE;
273       } else {
274         $this->current['SIZEIGNORE']= FALSE;
275       }
276     }
278     /* Sort referrals, if present */
279     if (isset ($this->current['REFERRAL'])){
280       $bases= array();
281       $servers= array();
282       foreach ($this->current['REFERRAL'] as $ref){
283         $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
284         $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
285         $bases[$base]= strlen($base);
286         $servers[$base]= $server;
287       }
288       asort($bases);
289       reset($bases);
290     }
292     /* SERVER not defined? Load the one with the shortest base */
293     if (!isset($this->current['SERVER'])){
294       $this->current['SERVER']= $servers[key($bases)];
295     }
297     /* BASE not defined? Load the one with the shortest base */
298     if (!isset($this->current['BASE'])){
299       $this->current['BASE']= key($bases);
300     }
302     /* Convert BASE to have escaped special characters */
303     $this->current['BASE']= @LDAP::convert($this->current['BASE']);
305     /* Parse LDAP referral informations */
306     if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
307       $url= $this->current['SERVER'];
308       $referral= $this->current['REFERRAL'][$url];
309       $this->current['ADMIN']= $referral['ADMIN'];
310       $this->current['PASSWORD']= $referral['PASSWORD'];
311     }
313     /* Load server informations */
314     $this->load_servers();
315   }
317   function load_servers ()
318   {
319     /* Only perform actions if current is set */
320     if ($this->current == NULL){
321       return;
322     }
324     /* Fill imap servers */
325     $ldap= $this->get_ldap_link();
326     $ldap->cd ($this->current['BASE']);
327     $ldap->search ("(objectClass=goImapServer)");
329     $this->data['SERVERS']['IMAP']= array();
330     error_reporting(0);
331     while ($attrs= $ldap->fetch()){
332       $name= $attrs['goImapName'][0];
333       $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
334           "admin" => $attrs['goImapAdmin'][0],
335           "password" => $attrs['goImapPassword'][0],
336           "sieve_server" => $attrs['goImapSieveServer'][0],
337           "sieve_port" => $attrs['goImapSievePort'][0]);
338     }
339     error_reporting(E_ALL);
341     /* Get kerberos server. FIXME: only one is supported currently */
342     $ldap->cd ($this->current['BASE']);
343     $ldap->search ("(objectClass=goKrbServer)");
344     if ($ldap->count()){
345       $attrs= $ldap->fetch();
346       $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
347           'REALM' => $attrs['goKrbRealm'][0],
348           'ADMIN' => $attrs['goKrbAdmin'][0],
349           'PASSWORD' => $attrs['goKrbPassword'][0]);
350     }
352     /* Get cups server. FIXME: only one is supported currently */
353     $ldap->cd ($this->current['BASE']);
354     $ldap->search ("(objectClass=goCupsServer)");
355     if ($ldap->count()){
356       $attrs= $ldap->fetch();
357       $this->data['SERVERS']['CUPS']= $attrs['cn'][0];  
358     }
360     /* Get fax server. FIXME: only one is supported currently */
361     $ldap->cd ($this->current['BASE']);
362     $ldap->search ("(objectClass=goFaxServer)");
363     if ($ldap->count()){
364       $attrs= $ldap->fetch();
365       $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
366           'LOGIN' => $attrs['goFaxAdmin'][0],
367           'PASSWORD' => $attrs['goFaxPassword'][0]);
368     }
371     /* Get asterisk servers */
372     $ldap->cd ($this->current['BASE']);
373     $ldap->search ("(objectClass=goFonServer)");
374     $this->data['SERVERS']['FON']= array();
375     if ($ldap->count()){
376       while ($attrs= $ldap->fetch()){
378         /* Add 0 entry for development */
379         if(count($this->data['SERVERS']['FON']) == 0){
380           $this->data['SERVERS']['FON'][0]= array(
381               'DN'      => $attrs['dn'],
382               'SERVER'  => $attrs['cn'][0],
383               'LOGIN'   => $attrs['goFonAdmin'][0],
384               'PASSWORD'  => $attrs['goFonPassword'][0],
385               'DB'    => "gophone",
386               'SIP_TABLE'   => "sip_users",
387               'EXT_TABLE'   => "extensions",
388               'VOICE_TABLE' => "voicemail_users",
389               'QUEUE_TABLE' => "queues",
390               'QUEUE_MEMBER_TABLE'  => "queue_members");
391         }
393         /* Add entry with 'dn' as index */
394         $this->data['SERVERS']['FON'][$attrs['dn']]= array(
395             'DN'      => $attrs['dn'],
396             'SERVER'  => $attrs['cn'][0],
397             'LOGIN'   => $attrs['goFonAdmin'][0],
398             'PASSWORD'  => $attrs['goFonPassword'][0],
399             'DB'    => "gophone",
400             'SIP_TABLE'   => "sip_users",
401             'EXT_TABLE'   => "extensions",
402             'VOICE_TABLE' => "voicemail_users",
403             'QUEUE_TABLE' => "queues",
404             'QUEUE_MEMBER_TABLE'  => "queue_members");
405       }
406     }
409     /* Get glpi server */
410     $ldap->cd ($this->current['BASE']);
411     $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
412     if ($ldap->count()){
413       $attrs= $ldap->fetch();
414       if(!isset($attrs['goGlpiPassword'])){
415         $attrs['goGlpiPassword'][0] ="";
416       }
417       $this->data['SERVERS']['GLPI']= array( 
418           'SERVER'      => $attrs['cn'][0],
419           'LOGIN'       => $attrs['goGlpiAdmin'][0],
420           'PASSWORD'    => $attrs['goGlpiPassword'][0],
421           'DB'          => $attrs['goGlpiDatabase'][0]);
422     }
424     /* Get logdb server */
425     $ldap->cd ($this->current['BASE']);
426     $ldap->search ("(objectClass=goLogDBServer)");
427     if ($ldap->count()){
428       $attrs= $ldap->fetch();
429       $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
430           'LOGIN' => $attrs['goLogAdmin'][0],
431           'PASSWORD' => $attrs['goLogPassword'][0]);
432     }
434     /* Logging databases */
435     $this->data['SERVERS']['LOGGING']= 
436       array("testserver1" => 
437         array(
438               "SERVER"  => "localhost",
439               "USER"    => "gosa_log",
440               "PWD"     => "tester",
441               "DB"      => "gosa_log"
442              )
443            );
448     /* Get NFS server lists */
449     $tmp= array("default");
450     $ldap->cd ($this->current['BASE']);
451     $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
452     while ($attrs= $ldap->fetch()){
453       for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
454         if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
455           continue;
456         }
457         $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
458         $tmp[]= $attrs["cn"][0].":$path";
459       }
460     }
461     $this->data['SERVERS']['NFS']= $tmp;
463     /* Load Terminalservers */
464     $ldap->cd ($this->current['BASE']);
465     $ldap->search ("(objectClass=goTerminalServer)");
466     $this->data['SERVERS']['TERMINAL']= array();
467     $this->data['SERVERS']['TERMINAL'][]= "default";
469     $this->data['SERVERS']['FONT']= array();
470     $this->data['SERVERS']['FONT'][]= "default";
471     while ($attrs= $ldap->fetch()){
472       $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
473       for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
474         $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
475       }
476     }
478     /* Ldap Server */
479     $this->data['SERVERS']['LDAP']= array();
480     $ldap->cd ($this->current['BASE']);
481     $ldap->search ("(objectClass=goLdapServer)");
482     while ($attrs= $ldap->fetch()){
483       if (isset($attrs["goLdapBase"])){
484         for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
485           $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
486         }
487       }
488     }
490     /* Get misc server lists */
491     $this->data['SERVERS']['SYSLOG']= array("default");
492     $this->data['SERVERS']['NTP']= array("default");
493     $ldap->cd ($this->current['BASE']);
494     $ldap->search ("(objectClass=goNtpServer)");
495     while ($attrs= $ldap->fetch()){
496       $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
497     }
498     $ldap->cd ($this->current['BASE']);
499     $ldap->search ("(objectClass=goSyslogServer)");
500     while ($attrs= $ldap->fetch()){
501       $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
502     }
504     /* Get samba servers from LDAP, in case of samba3 */
505     if ($this->current['SAMBAVERSION'] == 3){
506       $this->data['SERVERS']['SAMBA']= array();
507       $ldap->cd ($this->current['BASE']);
508       $ldap->search ("(objectClass=sambaDomain)");
509       while ($attrs= $ldap->fetch()){
510         $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array(
511             "SID" => $attrs["sambaSID"][0],
512             "RIDBASE" => $attrs["sambaAlgorithmicRidBase"][0]);
513       }
515       /* If no samba servers are found, look for configured sid/ridbase */
516       if (count($this->data['SERVERS']['SAMBA']) == 0){
517         if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
518           print_red(_("SID and/or RIDBASE missing in your configuration!"));
519           echo $_SESSION['errors'];
520           exit;
521         } else {
522           $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
523               "SID" => $this->current["SID"],
524               "RIDBASE" => $this->current["RIDBASE"]);
525         }
526       }
527     }
528   }
531   function get_departments($ignore_dn= "")
532   {
533     global $config;
535     /* Initialize result hash */
536     $result= array();
537     $administrative= array();
538     $result['/']= $this->current['BASE'];
539     $this->tdepartments= array();
541     /* Get list of department objects */
542     $ldap= $this->get_ldap_link();
543     $ldap->cd ($this->current['BASE']);
544     $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
545     while ($attrs= $ldap->fetch()){
546       $dn= $ldap->getDN();
547       $this->tdepartments[$dn]= "";
549       /* Save administrative departments */
550       if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
551           isset($attrs['gosaUnitTag'][0])){
552         $administrative[$dn]= $attrs['gosaUnitTag'][0];
553         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
554       }
555     
556       if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
557           isset($attrs['gosaUnitTag'][0])){
558         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
559       }
560     
561       if ($dn == $ignore_dn){
562         continue;
563       }
565       /* Only assign non-root departments */
566       if ($dn != $result['/']){
567         $result[convert_department_dn($dn)]= $dn;
568       }
569     }
571     $this->adepartments= $administrative;
572     $this->departments= $result;
573   }
576   function make_idepartments($max_size= 28)
577   {
578     global $config;
579     $base = $config->current['BASE'];
581     $arr = array();
582     $ui= get_userinfo();
584     $this->idepartments= array();
586     /* Create multidimensional array, with all departments. */
587     foreach ($this->departments as $key => $val){
589       /* When using strict_units, filter non relevant parts */
590       if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
591         if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
592             $this->tdepartments[$val] != $ui->gosaUnitTag){
593           continue;
594         }
595       }
597       /* remove base from dn */
598       $val2 = str_replace($base,"",$val);
600       /* Get every single ou */
601       $str = preg_replace("/ou=/","|ou=",$val2);        
602       $elements = array_reverse(split("\|",$str));              
604       /* Save last array position */
605       $last = &$arr;
607       /* Get array depth  */
608       $cnt = count($elements);
610       /* Add last ou element of current dn to our array */
611       foreach($elements as $key => $ele){
613         /* skip enpty */
614         if(empty($ele)) continue;
616         /* Extract department name */           
617         $elestr = preg_replace("/^ou=/","", $ele);
618         $elestr = preg_replace("/,$/","",$elestr);      
620         /* Add to array */      
621         if($key == ($cnt-2)){
622           $last[$elestr]['ENTRY'] = $val;
623         }
625         /* Set next array appending position */
626         $last = &$last[$elestr]['SUB'];
627       }
628     }
630     /* Add base entry */
631     $ret["/"]["ENTRY"]  = $base;
632     $ret["/"]["SUB"]    = $arr;
634     $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
635   }
638   /* Creates display friendly output from make_idepartments */
639   function generateDepartmentArray($arr,$depth = -1,$max_size){
640     $ret = array();
641     $depth ++;
643     /* Walk through array */    
644     foreach($arr as $name => $entries){
646       /* If this department is the last in the current tree position 
647        * remove it, to avoid generating output for it */
648       if(count($entries['SUB'])==0){
649         unset($entries['SUB']);
650       }
652       /* Fix name, if it contains a replace tag */
653       $name= @LDAP::fix($name);
655       /* Check if current name is too long, then cut it */
656       if(mb_strlen($name, 'UTF-8')> $max_size){
657         $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
658       }
660       /* Append the name to the list */ 
661       if(isset($entries['ENTRY'])){
662         $a = "";
663         for($i = 0 ; $i < $depth ; $i ++){
664           $a.="&nbsp;";
665         }
666         $ret[$entries['ENTRY']]=$a."&nbsp;".$name;
667       } 
669       /* recursive add of subdepartments */
670       if(isset($entries['SUB'])){
671         $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
672       }
673     }
675     return($ret);
676   }
678   /* This function returns all available Shares defined in this ldap
679    * There are two ways to call this function, if listboxEntry is true
680    *  only name and path are attached to the array, in it is false, the whole
681    *  entry will be parsed an atached to the result.
682    */
683   function getShareList($listboxEntry = false)
684   {
685     $ldap= $this->get_ldap_link();
686     $base =  $this->current['BASE'];
687     $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",$base,array("goExportEntry","cn"),GL_SUBSEARCH);
688     $return = array();
690     foreach($res as $entry){
691       if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
693         if(isset($entry['goExportEntry']['count'])){
694           unset($entry['goExportEntry']['count']);
695         }
696         if(isset($entry['goExportEntry'])){
697           foreach($entry['goExportEntry'] as $export){
698             $shareAttrs = split("\|",$export);
699             if($listboxEntry) {
700               $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
701             }else{
702               $return[$shareAttrs[0]."|".$entry['cn'][0]]['server']       = $entry['cn'][0];
703               $return[$shareAttrs[0]."|".$entry['cn'][0]]['name']         = $shareAttrs[0];
704               $return[$shareAttrs[0]."|".$entry['cn'][0]]['description']  = $shareAttrs[1];
705               $return[$shareAttrs[0]."|".$entry['cn'][0]]['type']         = $shareAttrs[2];
706               $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset']      = $shareAttrs[3];
707               $return[$shareAttrs[0]."|".$entry['cn'][0]]['path']         = $shareAttrs[4];
708               $return[$shareAttrs[0]."|".$entry['cn'][0]]['option']       = $shareAttrs[5];
709             }
710           }
711         }
712       } 
713     }
715     return($return);
716   }
718   /* This function returns all available ShareServer */
719   function getShareServerList()
720   {
721     global $config;
722     $return = array();
723     $ui = get_userinfo();
724     $base = $config->current['BASE'];
726     $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server", $base,array("goExportEntry","cn"),GL_SUBSEARCH);
727     foreach($res as $entry){
728       if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
729         if(isset($entry['goExportEntry']['count'])){
730           unset($entry['goExportEntry']['count']);
731         }
732         foreach($entry['goExportEntry'] as $share){
733           $a_share = split("\|",$share);
734           $sharename = $a_share[0];
735           $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
736         }
737       }
738     }
739     return($return);
740   }
742   /* Check if there's the specified bool value set in the configuration */
743   function boolValueIsTrue($section, $value)
744   {
745     $section= strtoupper($section);
746     $value= strtoupper($value);
747     if (isset($this->data[$section][$value])){
748     
749       $data= $this->data[$section][$value];
750       if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
751         return TRUE;
752       }
754     }
756     return FALSE;
757   }
761 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
762 ?>