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 %s: %s at line %d"),
72 CONFIG_FILE,
73 xml_error_string(xml_get_error_code($this->parser)),
74 xml_get_current_line_number($this->parser)));
75 echo $_SESSION['errors'];
76 exit;
77 }
78 }
80 function tag_open($parser, $tag, $attrs)
81 {
82 /* Save last and current tag for reference */
83 $this->tags[$this->level]= $tag;
84 $this->level++;
86 /* Trigger on CONF section */
87 if ($tag == 'CONF'){
88 $this->config_found= TRUE;
89 }
91 /* Return if we're not in config section */
92 if (!$this->config_found){
93 return;
94 }
96 /* yes/no to true/false and upper case TRUE to true and so on*/
97 foreach($attrs as $name => $value){
98 if(preg_match("/^(true|yes)$/i",$value)){
99 $attrs[$name] = "true";
100 }elseif(preg_match("/^(false|no)$/i",$value)){
101 $attrs[$name] = "false";
102 }
103 }
105 /* Look through attributes */
106 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 }
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 /* Possibly load kerberos style */
305 if (isset($this->current['KRBSASL'])){
306 if (preg_match('/^(yes|true)$/i', $this->current['KRBSASL'])){
307 $this->current['KRBSASL']= "sasl";
308 } else {
309 $this->current['KRBSASL']= "kerberos";
310 }
311 } else {
312 $this->current['KRBSASL']= "kerberos";
313 }
315 /* Load server informations */
316 $this->load_servers();
317 }
319 function load_servers ()
320 {
321 /* Only perform actions if current is set */
322 if ($this->current == NULL){
323 return;
324 }
326 /* Fill imap servers */
327 $ldap= $this->get_ldap_link();
328 $ldap->cd ($this->current['BASE']);
329 if (!isset($this->current['MAILMETHOD'])){
330 $this->current['MAILMETHOD']= "";
331 }
332 $this->data['SERVERS']['IMAP']= array();
333 $old_err = error_reporting(0);
334 while ($attrs= $ldap->fetch()){
335 $name= $attrs['goImapName'][0];
336 $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
337 "admin" => $attrs['goImapAdmin'][0],
338 "password" => $attrs['goImapPassword'][0],
339 "sieve_server" => $attrs['goImapSieveServer'][0],
340 "sieve_port" => $attrs['goImapSievePort'][0]);
341 }
342 error_reporting($old_err);
344 /* Get kerberos server. FIXME: only one is supported currently */
345 $ldap->cd ($this->current['BASE']);
346 $ldap->search ("(objectClass=goKrbServer)");
347 if ($ldap->count()){
348 $attrs= $ldap->fetch();
349 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
350 'REALM' => $attrs['goKrbRealm'][0],
351 'ADMIN' => $attrs['goKrbAdmin'][0],
352 'PASSWORD' => $attrs['goKrbPassword'][0]);
353 }
355 /* Get cups server. FIXME: only one is supported currently */
356 $ldap->cd ($this->current['BASE']);
357 $ldap->search ("(objectClass=goCupsServer)");
358 if ($ldap->count()){
359 $attrs= $ldap->fetch();
360 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
361 }
363 /* Get fax server. FIXME: only one is supported currently */
364 $ldap->cd ($this->current['BASE']);
365 $ldap->search ("(objectClass=goFaxServer)");
366 if ($ldap->count()){
367 $attrs= $ldap->fetch();
368 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
369 'LOGIN' => $attrs['goFaxAdmin'][0],
370 'PASSWORD' => $attrs['goFaxPassword'][0]);
371 }
373 /* Get asterisk servers */
374 $ldap->cd ($this->current['BASE']);
375 $ldap->search ("(objectClass=goFonServer)");
376 $this->data['SERVERS']['FON']= array();
377 if ($ldap->count()){
378 while ($attrs= $ldap->fetch()){
380 /* Add 0 entry for development */
381 if(count($this->data['SERVERS']['FON']) == 0){
382 $this->data['SERVERS']['FON'][0]= array(
383 'DN' => $attrs['dn'],
384 'SERVER' => $attrs['cn'][0],
385 'LOGIN' => $attrs['goFonAdmin'][0],
386 'PASSWORD' => $attrs['goFonPassword'][0],
387 'DB' => "gophone",
388 'SIP_TABLE' => "sip_users",
389 'EXT_TABLE' => "extensions",
390 'VOICE_TABLE' => "voicemail_users",
391 'QUEUE_TABLE' => "queues",
392 'QUEUE_MEMBER_TABLE' => "queue_members");
393 }
395 /* Add entry with 'dn' as index */
396 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
397 'DN' => $attrs['dn'],
398 'SERVER' => $attrs['cn'][0],
399 'LOGIN' => $attrs['goFonAdmin'][0],
400 'PASSWORD' => $attrs['goFonPassword'][0],
401 'DB' => "gophone",
402 'SIP_TABLE' => "sip_users",
403 'EXT_TABLE' => "extensions",
404 'VOICE_TABLE' => "voicemail_users",
405 'QUEUE_TABLE' => "queues",
406 'QUEUE_MEMBER_TABLE' => "queue_members");
407 }
408 }
410 /* Get glpi servers */
411 $ldap->cd ($this->current['BASE']);
412 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
413 if ($ldap->count()){
414 $attrs= $ldap->fetch();
415 if(!isset($attrs['goGlpiPassword'])){
416 $attrs['goGlpiPassword'][0] ="";
417 }
418 $this->data['SERVERS']['GLPI']= array(
419 'SERVER' => $attrs['cn'][0],
420 'LOGIN' => $attrs['goGlpiAdmin'][0],
421 'PASSWORD' => $attrs['goGlpiPassword'][0],
422 'DB' => $attrs['goGlpiDatabase'][0]);
423 }
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 /* Get NFS server lists */
435 $tmp= array("default");
436 $ldap->cd ($this->current['BASE']);
437 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
438 while ($attrs= $ldap->fetch()){
439 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
440 $path= preg_replace ("/\s.*$/", "", $attrs["goExportEntry"][$i]);
441 $tmp[]= $attrs["cn"][0].":$path";
442 }
443 }
444 $this->data['SERVERS']['NFS']= $tmp;
447 /* Load Terminalservers */
448 $ldap->cd ($this->current['BASE']);
449 $ldap->search ("(objectClass=goTerminalServer)");
450 $this->data['SERVERS']['TERMINAL']= array();
451 $this->data['SERVERS']['TERMINAL'][]= "default";
453 $this->data['SERVERS']['FONT']= array();
454 $this->data['SERVERS']['FONT'][]= "default";
455 while ($attrs= $ldap->fetch()){
456 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
457 for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
458 $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
459 }
460 }
462 /* Ldap Server */
463 $this->data['SERVERS']['LDAP']= array();
464 $ldap->cd ($this->current['BASE']);
465 $ldap->search ("(objectClass=goLdapServer)");
466 while ($attrs= $ldap->fetch()){
467 if (isset($attrs["goLdapBase"])){
468 for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
469 $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
470 }
471 }
472 }
474 /* Get misc server lists */
475 $this->data['SERVERS']['SYSLOG']= array("default");
476 $this->data['SERVERS']['NTP']= array("default");
477 $ldap->cd ($this->current['BASE']);
478 $ldap->search ("(objectClass=goNtpServer)");
479 while ($attrs= $ldap->fetch()){
480 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
481 }
482 $ldap->cd ($this->current['BASE']);
483 $ldap->search ("(objectClass=goSyslogServer)");
484 while ($attrs= $ldap->fetch()){
485 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
486 }
488 /* Get samba servers from LDAP, in case of samba3 */
489 if ($this->current['SAMBAVERSION'] == 3){
490 $this->data['SERVERS']['SAMBA']= array();
491 $ldap->cd ($this->current['BASE']);
492 $ldap->search ("(objectClass=sambaDomain)");
493 while ($attrs= $ldap->fetch()){
494 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array(
495 "SID" => $attrs["sambaSID"][0],
496 "RIDBASE" => $attrs["sambaAlgorithmicRidBase"][0]);
497 }
499 /* If no samba servers are found, look for configured sid/ridbase */
500 if (count($this->data['SERVERS']['SAMBA']) == 0){
501 if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
502 print_red(_("SID and/or RIDBASE missing in your configuration!"));
503 echo $_SESSION['errors'];
504 exit;
505 } else {
506 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
507 "SID" => $this->current["SID"],
508 "RIDBASE" => $this->current["RIDBASE"]);
509 }
510 }
511 }
512 }
515 function get_departments($ignore_dn= "")
516 {
517 global $config;
519 /* Initialize result hash */
520 $result= array();
521 $administrative= array();
522 $result['/']= $this->current['BASE'];
523 $this->tdepartments= array();
525 /* Get list of department objects */
526 $ldap= $this->get_ldap_link();
527 $ldap->cd ($this->current['BASE']);
528 $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
529 while ($attrs= $ldap->fetch()){
530 $dn= $ldap->getDN();
531 $this->tdepartments[$dn]= "";
533 /* Save administrative departments */
534 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
535 isset($attrs['gosaUnitTag'][0])){
536 $administrative[$dn]= $attrs['gosaUnitTag'][0];
537 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
538 }
540 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
541 isset($attrs['gosaUnitTag'][0])){
542 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
543 }
545 if ($dn == $ignore_dn){
546 continue;
547 }
549 /* Only assign non-root departments */
550 if ($dn != $result['/']){
551 $result[convert_department_dn($dn)]= $dn;
552 }
553 }
555 $this->adepartments= $administrative;
556 $this->departments= $result;
557 }
560 function make_idepartments($max_size= 28)
561 {
562 global $config;
563 $base = $config->current['BASE'];
565 $arr= array();
566 $ui= get_userinfo();
567 $this->idepartments= array();
569 /* Create multidimensional array, with all departments. */
570 foreach ($this->departments as $key => $val){
572 /* When using strict_units, filter non relevant parts */
573 if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
574 if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
575 $this->tdepartments[$val] != $ui->gosaUnitTag){
576 continue;
577 }
578 }
580 /* remove base from dn */
581 $val2 = str_replace($base,"",$val);
583 /* Get every single ou */
584 $str = preg_replace("/ou=/","|ou=",$val2);
585 $elements = array_reverse(split("\|",$str));
587 /* Save last array position */
588 $last = &$arr;
590 /* Get array depth */
591 $cnt = count($elements);
593 /* Add last ou element of current dn to our array */
594 foreach($elements as $key => $ele){
596 /* skip enpty */
597 if(empty($ele)) continue;
599 /* Extract department name */
600 $elestr = preg_replace("/^ou=/","", $ele);
601 $elestr = preg_replace("/,$/","",$elestr);
603 /* Add to array */
604 if($key == ($cnt-2)){
605 $last[$elestr]['ENTRY'] = $val;
606 }
608 /* Set next array appending position */
609 $last = &$last[$elestr]['SUB'];
610 }
611 }
613 /* Add base entry */
614 $ret["/"]["ENTRY"] = $base;
615 $ret["/"]["SUB"] = $arr;
617 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
618 }
621 /* Creates display friendly output from make_idepartments */
622 function generateDepartmentArray($arr,$depth = -1,$max_size){
623 $ret = array();
624 $depth ++;
626 /* Walk through array */
627 ksort($arr);
628 foreach($arr as $name => $entries){
630 /* If this department is the last in the current tree position
631 * remove it, to avoid generating output for it */
632 if(count($entries['SUB'])==0){
633 unset($entries['SUB']);
634 }
636 /* Fix name, if it contains a replace tag */
637 $name= @LDAP::fix($name);
639 /* Check if current name is too long, then cut it */
640 if(mb_strlen($name, 'UTF-8')> $max_size){
641 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
642 }
644 /* Append the name to the list */
645 if(isset($entries['ENTRY'])){
646 $a = "";
647 for($i = 0 ; $i < $depth ; $i ++){
648 $a.=".";
649 }
650 $ret[$entries['ENTRY']]=$a." ".$name;
651 }
653 /* recursive add of subdepartments */
654 if(isset($entries['SUB'])){
655 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
656 }
657 }
659 return($ret);
660 }
662 /* This function returns all available Shares defined in this ldap
663 * There are two ways to call this function, if listboxEntry is true
664 * only name and path are attached to the array, in it is false, the whole
665 * entry will be parsed an atached to the result.
666 */
667 function getShareList($listboxEntry = false)
668 {
669 $ldap= $this->get_ldap_link();
671 /* Set tag attribute if we've tagging activated */
672 $tag= "";
673 $ui= get_userinfo();
674 if ($ui->gosaUnitTag != "" && isset($this->current['STRICT_UNITS']) &&
675 preg_match('/TRUE/i', $this->current['STRICT_UNITS'])){
676 $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
677 }
679 $a_res = $ldap->search("(&(objectClass=goShareServer)$tag(objectClass=goServer))",array("goExportEntry","cn"));
680 $return= array();
681 while($entry = $ldap->fetch($a_res)){
682 if(isset($entry['goExportEntry']['count'])){
683 unset($entry['goExportEntry']['count']);
684 }
685 if(isset($entry['goExportEntry'])){
686 foreach($entry['goExportEntry'] as $export){
687 $shareAttrs = split("\|",$export);
688 if($listboxEntry) {
689 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
690 }else{
691 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
692 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
693 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
694 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
695 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
696 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
697 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
698 }
699 }
700 }
701 }
702 return($return);
703 }
705 /* This function returns all available ShareServer */
706 function getShareServerList()
707 {
708 global $config;
709 $return = array();
710 $ui = get_userinfo();
711 $base = $config->current['BASE'];
712 $res = get_list("(&(objectClass=goShareServer)(goExportEntry=*))",$ui->subtreeACL,$base,array("goExportEntry","cn"),GL_SUBSEARCH);
713 foreach($res as $entry){
714 if(isset($entry['goExportEntry']['count'])){
715 unset($entry['goExportEntry']['count']);
716 }
717 foreach($entry['goExportEntry'] as $share){
718 $a_share = split("\|",$share);
719 $sharename = $a_share[0];
720 $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
721 }
723 }
724 return($return);
725 }
727 /* Check if there's the specified bool value set in the configuration */
728 function boolValueIsTrue($section, $value)
729 {
730 $section= strtoupper($section);
731 $value= strtoupper($value);
732 if (isset($this->data[$section][$value])){
734 $data= $this->data[$section][$value];
735 if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
736 return TRUE;
737 }
739 }
741 return FALSE;
742 }
744 }
746 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
747 ?>