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(),
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 /* Load main parameters */
147 case 'MAIN':
148 $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
149 break;
151 /* Load menu */
152 case 'SECTION':
153 if ($this->tags[$this->level-2] == 'MENU'){
154 $this->section= $attrs['NAME'];
155 $this->data['MENU'][$this->section]= array(); ;
156 }
157 break;
159 /* Inser plugins */
160 case 'PLUGIN':
161 if ($this->tags[$this->level-3] == 'MENU' &&
162 $this->tags[$this->level-2] == 'SECTION'){
164 $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
165 }
166 if ($this->tags[$this->level-2] == 'SERVICEMENU'){
167 $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
168 }
169 break;
170 }
171 }
173 function tag_close($parser, $tag)
174 {
175 /* Close config section */
176 if ($tag == 'CONF'){
177 $this->config_found= FALSE;
178 }
179 $this->level--;
180 }
183 function get_credentials($creds)
184 {
185 if (isset($_SERVER['HTTP_GOSA_KEY'])){
186 return (cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY']));
187 }
188 return ($creds);
189 }
192 function get_ldap_link($sizelimit= FALSE)
193 {
194 /* Build new connection */
195 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
196 $this->current['ADMIN'], $this->get_credentials($this->current['PASSWORD']));
198 /* Check for connection */
199 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
200 $smarty= get_smarty();
201 print_red (_("Can't bind to LDAP. Please contact the system administrator."));
202 $smarty->display (get_template_path('headers.tpl'));
203 echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
204 exit();
205 }
207 if (!isset($_SESSION['size_limit'])){
208 $_SESSION['size_limit']= $this->current['SIZELIMIT'];
209 $_SESSION['size_ignore']= $this->current['SIZEIGNORE'];
210 }
212 if ($sizelimit){
213 $this->ldap->set_size_limit($_SESSION['size_limit']);
214 } else {
215 $this->ldap->set_size_limit(0);
216 }
218 /* Move referrals */
219 if (!isset($this->current['REFERRAL'])){
220 $this->ldap->referrals= array();
221 } else {
222 $this->ldap->referrals= $this->current['REFERRAL'];
223 }
224 # }
225 return ($this->ldap);
226 }
228 function set_current($name)
229 {
230 $this->current= $this->data['LOCATIONS'][$name];
231 if (!isset($this->current['PEOPLE'])){
232 $this->current['PEOPLE']= "ou=people";
233 }
234 if (!isset($this->current['GROUPS'])){
235 $this->current['GROUPS']= "ou=groups";
236 }
238 if (isset($this->current['INITIAL_BASE'])){
239 $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
240 }
242 /* Remove possibly added ',' from end of group and people ou */
243 $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
244 $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
246 if (!isset($this->current['WINSTATIONS'])){
247 $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
248 }
249 if (!isset($this->current['HASH'])){
250 $this->current['HASH']= "crypt";
251 }
252 if (!isset($this->current['DNMODE'])){
253 $this->current['DNMODE']= "cn";
254 }
255 if (!isset($this->current['MINID'])){
256 $this->current['MINID']= 100;
257 }
258 if (!isset($this->current['SIZELIMIT'])){
259 $this->current['SIZELIMIT']= 200;
260 }
261 if (!isset($this->current['SIZEINGORE'])){
262 $this->current['SIZEIGNORE']= TRUE;
263 } else {
264 if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
265 $this->current['SIZEIGNORE']= TRUE;
266 } else {
267 $this->current['SIZEIGNORE']= FALSE;
268 }
269 }
271 /* Sort referrals, if present */
272 if (isset ($this->current['REFERRAL'])){
273 $bases= array();
274 $servers= array();
275 foreach ($this->current['REFERRAL'] as $ref){
276 $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
277 $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
278 $bases[$base]= strlen($base);
279 $servers[$base]= $server;
280 }
281 asort($bases);
282 reset($bases);
283 }
285 /* SERVER not defined? Load the one with the shortest base */
286 if (!isset($this->current['SERVER'])){
287 $this->current['SERVER']= $servers[key($bases)];
288 }
290 /* BASE not defined? Load the one with the shortest base */
291 if (!isset($this->current['BASE'])){
292 $this->current['BASE']= key($bases);
293 }
295 /* Convert BASE to have escaped special characters */
296 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
298 /* Parse LDAP referral informations */
299 if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
300 $url= $this->current['SERVER'];
301 $referral= $this->current['REFERRAL'][$url];
302 $this->current['ADMIN']= $referral['ADMIN'];
303 $this->current['PASSWORD']= $referral['PASSWORD'];
304 }
306 /* Possibly load kerberos style */
307 if (isset($this->current['KRBSASL'])){
308 if (preg_match('/^(yes|true)$/i', $this->current['KRBSASL'])){
309 $this->current['KRBSASL']= "sasl";
310 } else {
311 $this->current['KRBSASL']= "kerberos";
312 }
313 } else {
314 $this->current['KRBSASL']= "kerberos";
315 }
317 /* Load server informations */
318 $this->load_servers();
319 }
321 function load_servers ()
322 {
323 /* Only perform actions if current is set */
324 if ($this->current == NULL){
325 return;
326 }
328 /* Fill imap servers */
329 $ldap= $this->get_ldap_link();
330 $ldap->cd ($this->current['BASE']);
331 if (!isset($this->current['MAILMETHOD'])){
332 $this->current['MAILMETHOD']= "";
333 }
334 if ($this->current['MAILMETHOD'] == ""){
335 $ldap->search ("(objectClass=goMailServer)", array('cn'));
336 $this->data['SERVERS']['IMAP']= array();
337 error_reporting(0);
338 while ($attrs= $ldap->fetch()){
339 $name= $attrs['cn'][0];
340 $this->data['SERVERS']['IMAP'][$name]= $name;
341 }
342 error_reporting(E_ALL);
343 } else {
344 $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
345 'goImapSieveServer', 'goImapSievePort'));
347 $this->data['SERVERS']['IMAP']= array();
348 error_reporting(0);
349 while ($attrs= $ldap->fetch()){
350 $name= $attrs['goImapName'][0];
351 $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
352 "admin" => $attrs['goImapAdmin'][0],
353 "password" => $attrs['goImapPassword'][0],
354 "sieve_server" => $attrs['goImapSieveServer'][0],
355 "sieve_port" => $attrs['goImapSievePort'][0]);
356 }
357 error_reporting(E_ALL);
358 }
360 /* Get kerberos server. FIXME: only one is supported currently */
361 $ldap->cd ($this->current['BASE']);
362 $ldap->search ("(objectClass=goKrbServer)");
363 if ($ldap->count()){
364 $attrs= $ldap->fetch();
365 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
366 'REALM' => $attrs['goKrbRealm'][0],
367 'ADMIN' => $attrs['goKrbAdmin'][0],
368 'PASSWORD' => $attrs['goKrbPassword'][0]);
369 }
371 /* Get cups server. FIXME: only one is supported currently */
372 $ldap->cd ($this->current['BASE']);
373 $ldap->search ("(objectClass=goCupsServer)");
374 if ($ldap->count()){
375 $attrs= $ldap->fetch();
376 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
377 }
379 /* Get fax server. FIXME: only one is supported currently */
380 $ldap->cd ($this->current['BASE']);
381 $ldap->search ("(objectClass=goFaxServer)");
382 if ($ldap->count()){
383 $attrs= $ldap->fetch();
384 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
385 'LOGIN' => $attrs['goFaxAdmin'][0],
386 'PASSWORD' => $attrs['goFaxPassword'][0]);
387 }
389 /* Get asterisk servers */
390 $ldap->cd ($this->current['BASE']);
391 $ldap->search ("(objectClass=goFonServer)");
392 $this->data['SERVERS']['FON']= array();
393 if ($ldap->count()){
394 while ($attrs= $ldap->fetch()){
396 /* Add 0 entry for development */
397 if(count($this->data['SERVERS']['FON']) == 0){
398 $this->data['SERVERS']['FON'][0]= array(
399 'DN' => $attrs['dn'],
400 'SERVER' => $attrs['cn'][0],
401 'LOGIN' => $attrs['goFonAdmin'][0],
402 'PASSWORD' => $attrs['goFonPassword'][0],
403 'DB' => "gophone",
404 'SIP_TABLE' => "sip_users",
405 'EXT_TABLE' => "extensions",
406 'VOICE_TABLE' => "voicemail_users",
407 'QUEUE_TABLE' => "queues",
408 'QUEUE_MEMBER_TABLE' => "queue_members");
409 }
411 /* Add entry with 'dn' as index */
412 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
413 'DN' => $attrs['dn'],
414 'SERVER' => $attrs['cn'][0],
415 'LOGIN' => $attrs['goFonAdmin'][0],
416 'PASSWORD' => $attrs['goFonPassword'][0],
417 'DB' => "gophone",
418 'SIP_TABLE' => "sip_users",
419 'EXT_TABLE' => "extensions",
420 'VOICE_TABLE' => "voicemail_users",
421 'QUEUE_TABLE' => "queues",
422 'QUEUE_MEMBER_TABLE' => "queue_members");
423 }
424 }
426 /* Get glpi servers */
427 $ldap->cd ($this->current['BASE']);
428 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
429 if ($ldap->count()){
430 $attrs= $ldap->fetch();
431 if(!isset($attrs['goGlpiPassword'])){
432 $attrs['goGlpiPassword'][0] ="";
433 }
434 $this->data['SERVERS']['GLPI']= array(
435 'SERVER' => $attrs['cn'][0],
436 'LOGIN' => $attrs['goGlpiAdmin'][0],
437 'PASSWORD' => $attrs['goGlpiPassword'][0],
438 'DB' => $attrs['goGlpiDatabase'][0]);
439 }
440 /* Get logdb server */
441 $ldap->cd ($this->current['BASE']);
442 $ldap->search ("(objectClass=goLogDBServer)");
443 if ($ldap->count()){
444 $attrs= $ldap->fetch();
445 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
446 'LOGIN' => $attrs['goLogAdmin'][0],
447 'PASSWORD' => $attrs['goLogPassword'][0]);
448 }
450 /* Get NFS server lists */
451 $tmp= array("default");
452 $ldap->cd ($this->current['BASE']);
453 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
454 while ($attrs= $ldap->fetch()){
455 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
456 $path= preg_replace ("/\s.*$/", "", $attrs["goExportEntry"][$i]);
457 $tmp[]= $attrs["cn"][0].":$path";
458 }
459 }
460 $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( "SID" =>"","RIDBASE" =>"");
511 if(isset($attrs["sambaSID"][0])){
512 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0];
513 }
514 if(isset($attrs["sambaAlgorithmicRidBase"][0])){
515 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
516 }
517 }
519 /* If no samba servers are found, look for configured sid/ridbase */
520 if (count($this->data['SERVERS']['SAMBA']) == 0){
521 if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
522 print_red(_("SID and/or RIDBASE missing in your configuration!"));
523 echo $_SESSION['errors'];
524 exit;
525 } else {
526 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
527 "SID" => $this->current["SID"],
528 "RIDBASE" => $this->current["RIDBASE"]);
529 }
530 }
531 }
532 }
535 function get_departments($ignore_dn= "")
536 {
537 global $config;
539 /* Initialize result hash */
540 $result= array();
541 $administrative= array();
542 $result['/']= $this->current['BASE'];
543 $this->tdepartments= array();
545 /* Get list of department objects */
546 $ldap= $this->get_ldap_link();
547 $ldap->cd ($this->current['BASE']);
548 $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
549 while ($attrs= $ldap->fetch()){
550 $dn= $ldap->getDN();
551 $this->tdepartments[$dn]= "";
553 /* Save administrative departments */
554 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
555 isset($attrs['gosaUnitTag'][0])){
556 $administrative[$dn]= $attrs['gosaUnitTag'][0];
557 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
558 }
560 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
561 isset($attrs['gosaUnitTag'][0])){
562 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
563 }
565 if ($dn == $ignore_dn){
566 continue;
567 }
569 /* Only assign non-root departments */
570 if ($dn != $result['/']){
571 $result[convert_department_dn($dn)]= $dn;
572 }
573 }
575 $this->adepartments= $administrative;
576 $this->departments= $result;
577 }
580 function make_idepartments($max_size= 28)
581 {
582 global $config;
583 $base = $config->current['BASE'];
585 $arr= array();
586 $ui= get_userinfo();
587 $this->idepartments= array();
589 /* Create multidimensional array, with all departments. */
590 foreach ($this->departments as $key => $val){
592 /* When using strict_units, filter non relevant parts */
593 if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
594 if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
595 $this->tdepartments[$val] != $ui->gosaUnitTag){
596 continue;
597 }
598 }
600 /* remove base from dn */
601 $val2 = str_replace($base,"",$val);
603 /* Get every single ou */
604 $str = preg_replace("/ou=/","|ou=",$val2);
605 $elements = array_reverse(split("\|",$str));
607 /* Save last array position */
608 $last = &$arr;
610 /* Get array depth */
611 $cnt = count($elements);
613 /* Add last ou element of current dn to our array */
614 foreach($elements as $key => $ele){
616 /* skip enpty */
617 if(empty($ele)) continue;
619 /* Extract department name */
620 $elestr = preg_replace("/^ou=/","", $ele);
621 $elestr = preg_replace("/,$/","",$elestr);
623 /* Add to array */
624 if($key == ($cnt-2)){
625 $last[$elestr]['ENTRY'] = $val;
626 }
628 /* Set next array appending position */
629 $last = &$last[$elestr]['SUB'];
630 }
631 }
633 /* Add base entry */
634 $ret["/"]["ENTRY"] = $base;
635 $ret["/"]["SUB"] = $arr;
637 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
638 }
641 /* Creates display friendly output from make_idepartments */
642 function generateDepartmentArray($arr,$depth = -1,$max_size){
643 $ret = array();
644 $depth ++;
646 /* Walk through array */
647 ksort($arr);
648 foreach($arr as $name => $entries){
650 /* If this department is the last in the current tree position
651 * remove it, to avoid generating output for it */
652 if(count($entries['SUB'])==0){
653 unset($entries['SUB']);
654 }
656 /* Fix name, if it contains a replace tag */
657 $name= @LDAP::fix($name);
659 /* Check if current name is too long, then cut it */
660 if(mb_strlen($name, 'UTF-8')> $max_size){
661 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
662 }
664 /* Append the name to the list */
665 if(isset($entries['ENTRY'])){
666 $a = "";
667 for($i = 0 ; $i < $depth ; $i ++){
668 $a.=".";
669 }
670 $ret[$entries['ENTRY']]=$a." ".$name;
671 }
673 /* recursive add of subdepartments */
674 if(isset($entries['SUB'])){
675 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
676 }
677 }
679 return($ret);
680 }
682 /* This function returns all available Shares defined in this ldap
683 * There are two ways to call this function, if listboxEntry is true
684 * only name and path are attached to the array, in it is false, the whole
685 * entry will be parsed an atached to the result.
686 */
687 function getShareList($listboxEntry = false)
688 {
689 $ldap= $this->get_ldap_link();
691 /* Set tag attribute if we've tagging activated */
692 $tag= "";
693 $ui= get_userinfo();
694 if ($ui->gosaUnitTag != "" && isset($this->current['STRICT_UNITS']) &&
695 preg_match('/TRUE/i', $this->current['STRICT_UNITS'])){
696 $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
697 }
699 $a_res = $ldap->search("(&(objectClass=goShareServer)$tag(objectClass=goServer))",array("goExportEntry","cn"));
700 $return= array();
701 while($entry = $ldap->fetch($a_res)){
702 if(isset($entry['goExportEntry']['count'])){
703 unset($entry['goExportEntry']['count']);
704 }
705 if(isset($entry['goExportEntry'])){
706 foreach($entry['goExportEntry'] as $export){
707 $shareAttrs = split("\|",$export);
708 if($listboxEntry) {
709 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
710 }else{
711 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
712 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
713 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
714 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
715 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
716 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
717 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
718 }
719 }
720 }
721 }
722 return($return);
723 }
725 /* This function returns all available ShareServer */
726 function getShareServerList()
727 {
728 global $config;
729 $return = array();
730 $ui = get_userinfo();
731 $base = $config->current['BASE'];
732 $res = get_list("(&(objectClass=goShareServer)(goExportEntry=*))",$ui->subtreeACL,$base,array("goExportEntry","cn"),GL_SUBSEARCH);
733 foreach($res as $entry){
734 if(isset($entry['goExportEntry']['count'])){
735 unset($entry['goExportEntry']['count']);
736 }
737 foreach($entry['goExportEntry'] as $share){
738 $a_share = split("\|",$share);
739 $sharename = $a_share[0];
740 $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
741 }
743 }
744 return($return);
745 }
747 /* Check if there's the specified bool value set in the configuration */
748 function boolValueIsTrue($section, $value)
749 {
750 $section= strtoupper($section);
751 $value= strtoupper($value);
752 if (isset($this->data[$section][$value])){
754 $data= $this->data[$section][$value];
755 if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
756 return TRUE;
757 }
759 }
761 return FALSE;
762 }
764 }
766 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
767 ?>