Code

e16945b88eb1415d26b23a78da6a8d3d11b8405b
[gosa.git] / include / class_config.inc
1 <?php
2 /*
3  * This code is part of GOsa (https://gosa.gonicus.de)
4  * Copyright (C) 2003-2006 - Cajus Pollmeier <pollmeier@gonicus.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 class config  {
23   /* XML parser */
24   var $parser;
25   var $config_found= FALSE;
26   var $tags= array();
27   var $level= 0;
28   var $gpc= 0;
29   var $section= "";
30   var $currentLocation= "";
32   /* Selected connection */
33   var $current= array();
35   /* Link to LDAP-server */
36   var $ldap= NULL;
37   var $referrals= array();
39   /* Configuration data */
40   var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(),
41       'MAIN' => array( 'FAXFORMATS' => array() ),
42       'MENU' => array(), 'SERVICE' => array());
43   var $basedir= "";
45   /* Keep a copy of the current deparment list */
46   var $departments= array();
47   var $idepartments= array();
48   var $adepartments= array();
49   var $tdepartments= array();
51   function config($filename, $basedir= "")
52   {
53     $this->parser = xml_parser_create();
54     $this->basedir= $basedir;
56     xml_set_object($this->parser, $this);
57     xml_set_element_handler($this->parser, "tag_open", "tag_close");
59     /* Parse config file directly? */
60     if ($filename != ""){
61       $this->parse($filename);
62     }
63   }
65   function parse($filename)
66   { 
67     $fh= fopen($filename, "r"); 
68     $xmldata= fread($fh, 100000);
69     fclose($fh); 
70     if(!xml_parse($this->parser, chop($xmldata))){
71       print_red(sprintf(_("XML error in gosa.conf: %s at line %d"),
72             xml_error_string(xml_get_error_code($this->parser)),
73             xml_get_current_line_number($this->parser)));
74       echo $_SESSION['errors'];
75       exit;
76     }
77   }
79   function tag_open($parser, $tag, $attrs)
80   { 
81     /* Save last and current tag for reference */
82     $this->tags[$this->level]= $tag;
83     $this->level++;
85     /* Trigger on CONF section */
86     if ($tag == 'CONF'){
87       $this->config_found= TRUE;
88     }
90     /* Return if we're not in config section */
91     if (!$this->config_found){
92       return;
93     }
95     /* yes/no to true/false and upper case TRUE to true and so on*/
96     foreach($attrs as $name => $value){
97       if(preg_match("/^(true|yes)$/i",$value)){
98         $attrs[$name] = "true";
99       }elseif(preg_match("/^(false|no)$/i",$value)){
100         $attrs[$name] = "false";
101       } 
102     }
104     /* Look through attributes */
105     switch ($this->tags[$this->level-1]){
108       /* Handle tab section */
109       case 'TAB':       $name= $this->tags[$this->level-2];
111                   /* Create new array? */
112                   if (!isset($this->data['TABS'][$name])){
113                     $this->data['TABS'][$name]= array();
114                   }
116                   /* Add elements */
117                   $this->data['TABS'][$name][]= $attrs;
118                   break;
120                   /* Handle location */
121       case 'LOCATION':
122                   if ($this->tags[$this->level-2] == 'MAIN'){
123                     $name= $attrs['NAME'];
124                     $this->currentLocation= $name;
126                     /* Add location elements */
127                       $this->data['LOCATIONS'][$name]= $attrs;
128                     }
129                   break;
131                   /* Handle referral tags */
132       case 'REFERRAL':
133                   if ($this->tags[$this->level-2] == 'LOCATION'){
134                     $url= $attrs['URL'];
135                     $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
137                     /* Add location elements */
138                     if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
139                       $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
140                     }
142                     $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
143                   }
144                   break;
146                   /* Handle faxformat */
147       case 'FAXFORMAT': 
148                   if ($this->tags[$this->level-2] == 'MAIN'){
149                     /* Add fax formats */
150                     $this->data['MAIN']['FAXFORMATS'][]= $attrs['TYPE'];
151                   }
152                   break;
154                   /* Load main parameters */
155       case 'MAIN':
156                   $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
157                   break;
159                   /* Load menu */
160       case 'SECTION':
161                   if ($this->tags[$this->level-2] == 'MENU'){
162                     $this->section= $attrs['NAME'];
163                     $this->data['MENU'][$this->section]= array(); ;
164                   }
165                   break;
167                   /* Inser plugins */
168       case 'PLUGIN':
169                   if ($this->tags[$this->level-3] == 'MENU' &&
170                       $this->tags[$this->level-2] == 'SECTION'){
172                     $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
173                   }
174                   if ($this->tags[$this->level-2] == 'SERVICEMENU'){
175                     $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
176                   }
177                   break;
178     }
179   }
181   function tag_close($parser, $tag)
182   {
183     /* Close config section */
184     if ($tag == 'CONF'){
185       $this->config_found= FALSE;
186     }
187     $this->level--;
188   }
190   function get_ldap_link($sizelimit= FALSE)
191   {
192     /* Build new connection */
193     $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
194         $this->current['ADMIN'], $this->current['PASSWORD']);
196     /* Check for connection */
197     if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
198       $smarty= get_smarty();
199       print_red (_("Can't bind to LDAP. Please contact the system administrator."));
200       $smarty->display (get_template_path('headers.tpl'));
201       echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
202       exit();
203     }
205     if (!isset($_SESSION['size_limit'])){
206       $_SESSION['size_limit']= $this->current['SIZELIMIT'];
207       $_SESSION['size_ignore']= $this->current['SIZEIGNORE'];
208     }
210     if ($sizelimit){
211       $this->ldap->set_size_limit($_SESSION['size_limit']);
212     } else {
213       $this->ldap->set_size_limit(0);
214     }
216     /* Move referrals */
217     if (!isset($this->current['REFERRAL'])){
218       $this->ldap->referrals= array();
219     } else {
220       $this->ldap->referrals= $this->current['REFERRAL'];
221     }
223     return ($this->ldap);
224   }
226   function set_current($name)
227   {
228     $this->current= $this->data['LOCATIONS'][$name];
229     if (!isset($this->current['PEOPLE'])){
230       $this->current['PEOPLE']= "ou=people";
231     }
232     if (!isset($this->current['GROUPS'])){
233       $this->current['GROUPS']= "ou=groups";
234     }
236     if (isset($this->current['INITIAL_BASE'])){
237       $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
238     }
239   
240     /* Remove possibly added ',' from end of group and people ou */
241     $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
242     $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
244     if (!isset($this->current['WINSTATIONS'])){
245       $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
246     }
247     if (!isset($this->current['HASH'])){
248       $this->current['HASH']= "crypt";
249     }
250     if (!isset($this->current['DNMODE'])){
251       $this->current['DNMODE']= "cn";
252     }
253     if (!isset($this->current['MINID'])){
254       $this->current['MINID']= 100;
255     }
256     if (!isset($this->current['SIZELIMIT'])){
257       $this->current['SIZELIMIT']= 200;
258     }
259     if (!isset($this->current['SIZEINGORE'])){
260       $this->current['SIZEIGNORE']= TRUE;
261     } else {
262       if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
263         $this->current['SIZEIGNORE']= TRUE;
264       } else {
265         $this->current['SIZEIGNORE']= FALSE;
266       }
267     }
269     /* Sort referrals, if present */
270     if (isset ($this->current['REFERRAL'])){
271       $bases= array();
272       $servers= array();
273       foreach ($this->current['REFERRAL'] as $ref){
274         $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
275         $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
276         $bases[$base]= strlen($base);
277         $servers[$base]= $server;
278       }
279       asort($bases);
280       reset($bases);
281     }
283     /* SERVER not defined? Load the one with the shortest base */
284     if (!isset($this->current['SERVER'])){
285       $this->current['SERVER']= $servers[key($bases)];
286     }
288     /* BASE not defined? Load the one with the shortest base */
289     if (!isset($this->current['BASE'])){
290       $this->current['BASE']= key($bases);
291     }
293     /* Convert BASE to have escaped special characters */
294     $this->current['BASE']= @LDAP::convert($this->current['BASE']);
296     /* Parse LDAP referral informations */
297     if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
298       $url= $this->current['SERVER'];
299       $referral= $this->current['REFERRAL'][$url];
300       $this->current['ADMIN']= $referral['ADMIN'];
301       $this->current['PASSWORD']= $referral['PASSWORD'];
302     }
304     /* Load server informations */
305     $this->load_servers();
306   }
308   function load_servers ()
309   {
310     /* Only perform actions if current is set */
311     if ($this->current == NULL){
312       return;
313     }
315     /* Fill imap servers */
316     $ldap= $this->get_ldap_link();
317     $ldap->cd ($this->current['BASE']);
318     $ldap->search ("(objectClass=goImapServer)");
320     $this->data['SERVERS']['IMAP']= array();
321     error_reporting(0);
322     while ($attrs= $ldap->fetch()){
323       $name= $attrs['goImapName'][0];
324       $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
325           "admin" => $attrs['goImapAdmin'][0],
326           "password" => $attrs['goImapPassword'][0],
327           "sieve_server" => $attrs['goImapSieveServer'][0],
328           "sieve_port" => $attrs['goImapSievePort'][0]);
329     }
330     error_reporting(E_ALL | E_STRICT);
332     /* Get kerberos server. FIXME: only one is supported currently */
333     $ldap->cd ($this->current['BASE']);
334     $ldap->search ("(objectClass=goKrbServer)");
335     if ($ldap->count()){
336       $attrs= $ldap->fetch();
337       $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
338           'REALM' => $attrs['goKrbRealm'][0],
339           'ADMIN' => $attrs['goKrbAdmin'][0],
340           'PASSWORD' => $attrs['goKrbPassword'][0]);
341     }
343     /* Get cups server. FIXME: only one is supported currently */
344     $ldap->cd ($this->current['BASE']);
345     $ldap->search ("(objectClass=goCupsServer)");
346     if ($ldap->count()){
347       $attrs= $ldap->fetch();
348       $this->data['SERVERS']['CUPS']= $attrs['cn'][0];  
349     }
351     /* Get fax server. FIXME: only one is supported currently */
352     $ldap->cd ($this->current['BASE']);
353     $ldap->search ("(objectClass=goFaxServer)");
354     if ($ldap->count()){
355       $attrs= $ldap->fetch();
356       $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
357           'LOGIN' => $attrs['goFaxAdmin'][0],
358           'PASSWORD' => $attrs['goFaxPassword'][0]);
359     }
362     /* Get asterisk servers */
363     $ldap->cd ($this->current['BASE']);
364     $ldap->search ("(objectClass=goFonServer)");
365     $this->data['SERVERS']['FON']= array();
366     if ($ldap->count()){
367       while ($attrs= $ldap->fetch()){
369         /* Add 0 entry for development */
370         if(count($this->data['SERVERS']['FON']) == 0){
371           $this->data['SERVERS']['FON'][0]= array(
372               'DN'      => $attrs['dn'],
373               'SERVER'  => $attrs['cn'][0],
374               'LOGIN'   => $attrs['goFonAdmin'][0],
375               'PASSWORD'  => $attrs['goFonPassword'][0],
376               'DB'    => "gophone",
377               'SIP_TABLE'   => "sip_users",
378               'EXT_TABLE'   => "extensions",
379               'VOICE_TABLE' => "voicemail_users",
380               'QUEUE_TABLE' => "queues",
381               'QUEUE_MEMBER_TABLE'  => "queue_members");
382         }
384         /* Add entry with 'dn' as index */
385         $this->data['SERVERS']['FON'][$attrs['dn']]= array(
386             'DN'      => $attrs['dn'],
387             'SERVER'  => $attrs['cn'][0],
388             'LOGIN'   => $attrs['goFonAdmin'][0],
389             'PASSWORD'  => $attrs['goFonPassword'][0],
390             'DB'    => "gophone",
391             'SIP_TABLE'   => "sip_users",
392             'EXT_TABLE'   => "extensions",
393             'VOICE_TABLE' => "voicemail_users",
394             'QUEUE_TABLE' => "queues",
395             'QUEUE_MEMBER_TABLE'  => "queue_members");
396       }
397     }
400     /* Get glpi server */
401     $ldap->cd ($this->current['BASE']);
402     $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
403     if ($ldap->count()){
404       $attrs= $ldap->fetch();
405       if(!isset($attrs['goGlpiPassword'])){
406         $attrs['goGlpiPassword'][0] ="";
407       }
408       $this->data['SERVERS']['GLPI']= array( 
409           'SERVER'      => $attrs['cn'][0],
410           'LOGIN'       => $attrs['goGlpiAdmin'][0],
411           'PASSWORD'    => $attrs['goGlpiPassword'][0],
412           'DB'          => $attrs['goGlpiDatabase'][0]);
413     }
416     /* Get logdb server */
417     $ldap->cd ($this->current['BASE']);
418     $ldap->search ("(objectClass=goLogDBServer)");
419     if ($ldap->count()){
420       $attrs= $ldap->fetch();
421       $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
422           'LOGIN' => $attrs['goLogAdmin'][0],
423           'PASSWORD' => $attrs['goLogPassword'][0]);
424     }
427     /* GOsa logging databases */
428     $ldap->cd ($this->current['BASE']);
429     $ldap->search ("(objectClass=gosaLogServer)");
430     if ($ldap->count()){
431       while($attrs= $ldap->fetch()){
432       $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]= 
433           array(
434           'DN'    => $attrs['dn'],
435           'USER'  => $attrs['goLogDBUser'][0],
436           'DB'    => $attrs['goLogDB'][0],
437           'PWD'   => $attrs['goLogDBPassword'][0]);
438       }
439     }
442     /* Get NFS server lists */
443     $tmp= array("default");
444     $ldap->cd ($this->current['BASE']);
445     $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
446     while ($attrs= $ldap->fetch()){
447       for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
448         if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
449           continue;
450         }
451         $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
452         $tmp[]= $attrs["cn"][0].":$path";
453       }
454     }
455     $this->data['SERVERS']['NFS']= $tmp;
457     /* Load Terminalservers */
458     $ldap->cd ($this->current['BASE']);
459     $ldap->search ("(objectClass=goTerminalServer)");
460     $this->data['SERVERS']['TERMINAL']= array();
461     $this->data['SERVERS']['TERMINAL'][]= "default";
463     $this->data['SERVERS']['FONT']= array();
464     $this->data['SERVERS']['FONT'][]= "default";
465     while ($attrs= $ldap->fetch()){
466       $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
467       for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
468         $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
469       }
470     }
472     /* Ldap Server */
473     $this->data['SERVERS']['LDAP']= array();
474     $ldap->cd ($this->current['BASE']);
475     $ldap->search ("(objectClass=goLdapServer)");
476     while ($attrs= $ldap->fetch()){
477       if (isset($attrs["goLdapBase"])){
478         for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
479           $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
480         }
481       }
482     }
484     /* Get misc server lists */
485     $this->data['SERVERS']['SYSLOG']= array("default");
486     $this->data['SERVERS']['NTP']= array("default");
487     $ldap->cd ($this->current['BASE']);
488     $ldap->search ("(objectClass=goNtpServer)");
489     while ($attrs= $ldap->fetch()){
490       $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
491     }
492     $ldap->cd ($this->current['BASE']);
493     $ldap->search ("(objectClass=goSyslogServer)");
494     while ($attrs= $ldap->fetch()){
495       $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
496     }
498     /* Get samba servers from LDAP, in case of samba3 */
499     if ($this->current['SAMBAVERSION'] == 3){
500       $this->data['SERVERS']['SAMBA']= array();
501       $ldap->cd ($this->current['BASE']);
502       $ldap->search ("(objectClass=sambaDomain)");
503       while ($attrs= $ldap->fetch()){
504         $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array(
505             "SID" => $attrs["sambaSID"][0],
506             "RIDBASE" => $attrs["sambaAlgorithmicRidBase"][0]);
507       }
509       /* If no samba servers are found, look for configured sid/ridbase */
510       if (count($this->data['SERVERS']['SAMBA']) == 0){
511         if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
512           print_red(_("SID and/or RIDBASE missing in your configuration!"));
513           echo $_SESSION['errors'];
514           exit;
515         } else {
516           $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
517               "SID" => $this->current["SID"],
518               "RIDBASE" => $this->current["RIDBASE"]);
519         }
520       }
521     }
522   }
525   function get_departments($ignore_dn= "")
526   {
527     global $config;
529     /* Initialize result hash */
530     $result= array();
531     $administrative= array();
532     $result['/']= $this->current['BASE'];
533     $this->tdepartments= array();
535     /* Get list of department objects */
536     $ldap= $this->get_ldap_link();
537     $ldap->cd ($this->current['BASE']);
538     $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
539     while ($attrs= $ldap->fetch()){
540       $dn= $ldap->getDN();
541       $this->tdepartments[$dn]= "";
543       /* Save administrative departments */
544       if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
545           isset($attrs['gosaUnitTag'][0])){
546         $administrative[$dn]= $attrs['gosaUnitTag'][0];
547         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
548       }
549     
550       if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
551           isset($attrs['gosaUnitTag'][0])){
552         $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
553       }
554     
555       if ($dn == $ignore_dn){
556         continue;
557       }
559       /* Only assign non-root departments */
560       if ($dn != $result['/']){
561         $result[convert_department_dn($dn)]= $dn;
562       }
563     }
565     $this->adepartments= $administrative;
566     $this->departments= $result;
567   }
570   function make_idepartments($max_size= 28)
571   {
572     global $config;
573     $base = $config->current['BASE'];
575     $arr = array();
576     $ui= get_userinfo();
578     $this->idepartments= array();
580     /* Create multidimensional array, with all departments. */
581     foreach ($this->departments as $key => $val){
583       /* When using strict_units, filter non relevant parts */
584       if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
585         if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
586             $this->tdepartments[$val] != $ui->gosaUnitTag){
587           continue;
588         }
589       }
591       /* remove base from dn */
592       $val2 = str_replace($base,"",$val);
594       /* Get every single ou */
595       $str = preg_replace("/ou=/","|ou=",$val2);        
596       $elements = array_reverse(split("\|",$str));              
598       /* Save last array position */
599       $last = &$arr;
601       /* Get array depth  */
602       $cnt = count($elements);
604       /* Add last ou element of current dn to our array */
605       foreach($elements as $key => $ele){
607         /* skip enpty */
608         if(empty($ele)) continue;
610         /* Extract department name */           
611         $elestr = preg_replace("/^ou=/","", $ele);
612         $elestr = preg_replace("/,$/","",$elestr);      
614         /* Add to array */      
615         if($key == ($cnt-2)){
616           $last[$elestr]['ENTRY'] = $val;
617         }
619         /* Set next array appending position */
620         $last = &$last[$elestr]['SUB'];
621       }
622     }
624     /* Add base entry */
625     $ret["/"]["ENTRY"]  = $base;
626     $ret["/"]["SUB"]    = $arr;
628     $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
629   }
632   /* Creates display friendly output from make_idepartments */
633   function generateDepartmentArray($arr,$depth = -1,$max_size){
634     $ret = array();
635     $depth ++;
637     /* Walk through array */    
638     ksort($arr);
639     foreach($arr as $name => $entries){
641       /* If this department is the last in the current tree position 
642        * remove it, to avoid generating output for it */
643       if(count($entries['SUB'])==0){
644         unset($entries['SUB']);
645       }
647       /* Fix name, if it contains a replace tag */
648       $name= @LDAP::fix($name);
650       /* Check if current name is too long, then cut it */
651       if(mb_strlen($name, 'UTF-8')> $max_size){
652         $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
653       }
655       /* Append the name to the list */ 
656       if(isset($entries['ENTRY'])){
657         $a = "";
658         for($i = 0 ; $i < $depth ; $i ++){
659           $a.=".";
660         }
661         $ret[$entries['ENTRY']]=$a."&nbsp;".$name;
662       } 
664       /* recursive add of subdepartments */
665       if(isset($entries['SUB'])){
666         $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
667       }
668     }
670     return($ret);
671   }
673   /* This function returns all available Shares defined in this ldap
674    * There are two ways to call this function, if listboxEntry is true
675    *  only name and path are attached to the array, in it is false, the whole
676    *  entry will be parsed an atached to the result.
677    */
678   function getShareList($listboxEntry = false)
679   {
680     $ldap= $this->get_ldap_link();
681     $base =  $this->current['BASE'];
682     $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",$base,array("goExportEntry","cn"),GL_SUBSEARCH);
683     $return = array();
685     foreach($res as $entry){
686       if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
688         if(isset($entry['goExportEntry']['count'])){
689           unset($entry['goExportEntry']['count']);
690         }
691         if(isset($entry['goExportEntry'])){
692           foreach($entry['goExportEntry'] as $export){
693             $shareAttrs = split("\|",$export);
694             if($listboxEntry) {
695               $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
696             }else{
697               $return[$shareAttrs[0]."|".$entry['cn'][0]]['server']       = $entry['cn'][0];
698               $return[$shareAttrs[0]."|".$entry['cn'][0]]['name']         = $shareAttrs[0];
699               $return[$shareAttrs[0]."|".$entry['cn'][0]]['description']  = $shareAttrs[1];
700               $return[$shareAttrs[0]."|".$entry['cn'][0]]['type']         = $shareAttrs[2];
701               $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset']      = $shareAttrs[3];
702               $return[$shareAttrs[0]."|".$entry['cn'][0]]['path']         = $shareAttrs[4];
703               $return[$shareAttrs[0]."|".$entry['cn'][0]]['option']       = $shareAttrs[5];
704             }
705           }
706         }
707       } 
708     }
710     return($return);
711   }
713   /* This function returns all available ShareServer */
714   function getShareServerList()
715   {
716     global $config;
717     $return = array();
718     $ui = get_userinfo();
719     $base = $config->current['BASE'];
721     $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server", $base,array("goExportEntry","cn"),GL_SUBSEARCH);
722     foreach($res as $entry){
723       if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
724         if(isset($entry['goExportEntry']['count'])){
725           unset($entry['goExportEntry']['count']);
726         }
727         foreach($entry['goExportEntry'] as $share){
728           $a_share = split("\|",$share);
729           $sharename = $a_share[0];
730           $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
731         }
732       }
733     }
734     return($return);
735   }
737   /* Check if there's the specified bool value set in the configuration */
738   function boolValueIsTrue($section, $value)
739   {
740     $section= strtoupper($section);
741     $value= strtoupper($value);
742     if (isset($this->data[$section][$value])){
743     
744       $data= $this->data[$section][$value];
745       if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
746         return TRUE;
747       }
749     }
751     return FALSE;
752   }
756 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
757 ?>