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 }
182 function get_ldap_link($sizelimit= FALSE)
183 {
184 # Reuse same handle ldap handle.
185 # Disabled due to unpredictable results
186 #
187 # if($this->ldap === NULL || !is_resource($this->ldap->cid)){
188 #
189 /* Build new connection */
190 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
191 $this->current['ADMIN'], $this->current['PASSWORD']);
193 /* Check for connection */
194 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
195 $smarty= get_smarty();
196 print_red (_("Can't bind to LDAP. Please contact the system administrator."));
197 $smarty->display (get_template_path('headers.tpl'));
198 echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
199 exit();
200 }
202 if (!isset($_SESSION['size_limit'])){
203 $_SESSION['size_limit']= $this->current['SIZELIMIT'];
204 $_SESSION['size_ignore']= $this->current['SIZEIGNORE'];
205 }
207 if ($sizelimit){
208 $this->ldap->set_size_limit($_SESSION['size_limit']);
209 } else {
210 $this->ldap->set_size_limit(0);
211 }
213 /* Move referrals */
214 if (!isset($this->current['REFERRAL'])){
215 $this->ldap->referrals= array();
216 } else {
217 $this->ldap->referrals= $this->current['REFERRAL'];
218 }
219 # }
220 return ($this->ldap);
221 }
223 function set_current($name)
224 {
225 $this->current= $this->data['LOCATIONS'][$name];
226 if (!isset($this->current['PEOPLE'])){
227 $this->current['PEOPLE']= "ou=people";
228 }
229 if (!isset($this->current['GROUPS'])){
230 $this->current['GROUPS']= "ou=groups";
231 }
233 if (isset($this->current['INITIAL_BASE'])){
234 $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
235 }
237 /* Remove possibly added ',' from end of group and people ou */
238 $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
239 $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
241 if (!isset($this->current['WINSTATIONS'])){
242 $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
243 }
244 if (!isset($this->current['HASH'])){
245 $this->current['HASH']= "crypt";
246 }
247 if (!isset($this->current['DNMODE'])){
248 $this->current['DNMODE']= "cn";
249 }
250 if (!isset($this->current['MINID'])){
251 $this->current['MINID']= 100;
252 }
253 if (!isset($this->current['SIZELIMIT'])){
254 $this->current['SIZELIMIT']= 200;
255 }
256 if (!isset($this->current['SIZEINGORE'])){
257 $this->current['SIZEIGNORE']= TRUE;
258 } else {
259 if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
260 $this->current['SIZEIGNORE']= TRUE;
261 } else {
262 $this->current['SIZEIGNORE']= FALSE;
263 }
264 }
266 /* Sort referrals, if present */
267 if (isset ($this->current['REFERRAL'])){
268 $bases= array();
269 $servers= array();
270 foreach ($this->current['REFERRAL'] as $ref){
271 $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
272 $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
273 $bases[$base]= strlen($base);
274 $servers[$base]= $server;
275 }
276 asort($bases);
277 reset($bases);
278 }
280 /* SERVER not defined? Load the one with the shortest base */
281 if (!isset($this->current['SERVER'])){
282 $this->current['SERVER']= $servers[key($bases)];
283 }
285 /* BASE not defined? Load the one with the shortest base */
286 if (!isset($this->current['BASE'])){
287 $this->current['BASE']= key($bases);
288 }
290 /* Convert BASE to have escaped special characters */
291 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
293 /* Parse LDAP referral informations */
294 if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
295 $url= $this->current['SERVER'];
296 $referral= $this->current['REFERRAL'][$url];
297 $this->current['ADMIN']= $referral['ADMIN'];
298 $this->current['PASSWORD']= $referral['PASSWORD'];
299 }
301 /* Possibly load kerberos style */
302 if (isset($this->current['KRBSASL'])){
303 if (preg_match('/^(yes|true)$/i', $this->current['KRBSASL'])){
304 $this->current['KRBSASL']= "sasl";
305 } else {
306 $this->current['KRBSASL']= "kerberos";
307 }
308 } else {
309 $this->current['KRBSASL']= "kerberos";
310 }
312 /* Load server informations */
313 $this->load_servers();
314 }
316 function load_servers ()
317 {
318 /* Only perform actions if current is set */
319 if ($this->current == NULL){
320 return;
321 }
323 /* Fill imap servers */
324 $ldap= $this->get_ldap_link();
325 $ldap->cd ($this->current['BASE']);
326 if (!isset($this->current['MAILMETHOD'])){
327 $this->current['MAILMETHOD']= "";
328 }
329 if ($this->current['MAILMETHOD'] == ""){
330 $ldap->search ("(objectClass=goMailServer)", array('cn'));
331 $this->data['SERVERS']['IMAP']= array();
332 error_reporting(0);
333 while ($attrs= $ldap->fetch()){
334 $name= $attrs['cn'][0];
335 $this->data['SERVERS']['IMAP'][$name]= $name;
336 }
337 error_reporting(E_ALL);
338 } else {
339 $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
340 'goImapSieveServer', 'goImapSievePort'));
342 $this->data['SERVERS']['IMAP']= array();
343 error_reporting(0);
344 while ($attrs= $ldap->fetch()){
345 $name= $attrs['goImapName'][0];
346 $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
347 "admin" => $attrs['goImapAdmin'][0],
348 "password" => $attrs['goImapPassword'][0],
349 "sieve_server" => $attrs['goImapSieveServer'][0],
350 "sieve_port" => $attrs['goImapSievePort'][0]);
351 }
352 error_reporting(E_ALL);
353 }
355 /* Get kerberos server. FIXME: only one is supported currently */
356 $ldap->cd ($this->current['BASE']);
357 $ldap->search ("(objectClass=goKrbServer)");
358 if ($ldap->count()){
359 $attrs= $ldap->fetch();
360 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
361 'REALM' => $attrs['goKrbRealm'][0],
362 'ADMIN' => $attrs['goKrbAdmin'][0],
363 'PASSWORD' => $attrs['goKrbPassword'][0]);
364 }
366 /* Get cups server. FIXME: only one is supported currently */
367 $ldap->cd ($this->current['BASE']);
368 $ldap->search ("(objectClass=goCupsServer)");
369 if ($ldap->count()){
370 $attrs= $ldap->fetch();
371 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
372 }
374 /* Get fax server. FIXME: only one is supported currently */
375 $ldap->cd ($this->current['BASE']);
376 $ldap->search ("(objectClass=goFaxServer)");
377 if ($ldap->count()){
378 $attrs= $ldap->fetch();
379 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
380 'LOGIN' => $attrs['goFaxAdmin'][0],
381 'PASSWORD' => $attrs['goFaxPassword'][0]);
382 }
384 /* Get asterisk servers */
385 $ldap->cd ($this->current['BASE']);
386 $ldap->search ("(objectClass=goFonServer)");
387 $this->data['SERVERS']['FON']= array();
388 if ($ldap->count()){
389 while ($attrs= $ldap->fetch()){
391 /* Add 0 entry for development */
392 if(count($this->data['SERVERS']['FON']) == 0){
393 $this->data['SERVERS']['FON'][0]= array(
394 'DN' => $attrs['dn'],
395 'SERVER' => $attrs['cn'][0],
396 'LOGIN' => $attrs['goFonAdmin'][0],
397 'PASSWORD' => $attrs['goFonPassword'][0],
398 'DB' => "gophone",
399 'SIP_TABLE' => "sip_users",
400 'EXT_TABLE' => "extensions",
401 'VOICE_TABLE' => "voicemail_users",
402 'QUEUE_TABLE' => "queues",
403 'QUEUE_MEMBER_TABLE' => "queue_members");
404 }
406 /* Add entry with 'dn' as index */
407 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
408 'DN' => $attrs['dn'],
409 'SERVER' => $attrs['cn'][0],
410 'LOGIN' => $attrs['goFonAdmin'][0],
411 'PASSWORD' => $attrs['goFonPassword'][0],
412 'DB' => "gophone",
413 'SIP_TABLE' => "sip_users",
414 'EXT_TABLE' => "extensions",
415 'VOICE_TABLE' => "voicemail_users",
416 'QUEUE_TABLE' => "queues",
417 'QUEUE_MEMBER_TABLE' => "queue_members");
418 }
419 }
421 /* Get glpi servers */
422 $ldap->cd ($this->current['BASE']);
423 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
424 if ($ldap->count()){
425 $attrs= $ldap->fetch();
426 if(!isset($attrs['goGlpiPassword'])){
427 $attrs['goGlpiPassword'][0] ="";
428 }
429 $this->data['SERVERS']['GLPI']= array(
430 'SERVER' => $attrs['cn'][0],
431 'LOGIN' => $attrs['goGlpiAdmin'][0],
432 'PASSWORD' => $attrs['goGlpiPassword'][0],
433 'DB' => $attrs['goGlpiDatabase'][0]);
434 }
435 /* Get logdb server */
436 $ldap->cd ($this->current['BASE']);
437 $ldap->search ("(objectClass=goLogDBServer)");
438 if ($ldap->count()){
439 $attrs= $ldap->fetch();
440 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
441 'LOGIN' => $attrs['goLogAdmin'][0],
442 'PASSWORD' => $attrs['goLogPassword'][0]);
443 }
445 /* Get NFS server lists */
446 $tmp= array("default");
447 $ldap->cd ($this->current['BASE']);
448 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
449 while ($attrs= $ldap->fetch()){
450 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
451 $path= preg_replace ("/\s.*$/", "", $attrs["goExportEntry"][$i]);
452 $tmp[]= $attrs["cn"][0].":$path";
453 }
454 }
455 $this->data['SERVERS']['NFS']= $tmp;
458 /* Load Terminalservers */
459 $ldap->cd ($this->current['BASE']);
460 $ldap->search ("(objectClass=goTerminalServer)");
461 $this->data['SERVERS']['TERMINAL']= array();
462 $this->data['SERVERS']['TERMINAL'][]= "default";
464 $this->data['SERVERS']['FONT']= array();
465 $this->data['SERVERS']['FONT'][]= "default";
466 while ($attrs= $ldap->fetch()){
467 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
468 for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
469 $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
470 }
471 }
473 /* Ldap Server */
474 $this->data['SERVERS']['LDAP']= array();
475 $ldap->cd ($this->current['BASE']);
476 $ldap->search ("(objectClass=goLdapServer)");
477 while ($attrs= $ldap->fetch()){
478 if (isset($attrs["goLdapBase"])){
479 for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
480 $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
481 }
482 }
483 }
485 /* Get misc server lists */
486 $this->data['SERVERS']['SYSLOG']= array("default");
487 $this->data['SERVERS']['NTP']= array("default");
488 $ldap->cd ($this->current['BASE']);
489 $ldap->search ("(objectClass=goNtpServer)");
490 while ($attrs= $ldap->fetch()){
491 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
492 }
493 $ldap->cd ($this->current['BASE']);
494 $ldap->search ("(objectClass=goSyslogServer)");
495 while ($attrs= $ldap->fetch()){
496 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
497 }
499 /* Get samba servers from LDAP, in case of samba3 */
500 if ($this->current['SAMBAVERSION'] == 3){
501 $this->data['SERVERS']['SAMBA']= array();
502 $ldap->cd ($this->current['BASE']);
503 $ldap->search ("(objectClass=sambaDomain)");
504 while ($attrs= $ldap->fetch()){
505 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
506 if(isset($attrs["sambaSID"][0])){
507 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0];
508 }
509 if(isset($attrs["sambaAlgorithmicRidBase"][0])){
510 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
511 }
512 }
514 /* If no samba servers are found, look for configured sid/ridbase */
515 if (count($this->data['SERVERS']['SAMBA']) == 0){
516 if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
517 print_red(_("SID and/or RIDBASE missing in your configuration!"));
518 echo $_SESSION['errors'];
519 exit;
520 } else {
521 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
522 "SID" => $this->current["SID"],
523 "RIDBASE" => $this->current["RIDBASE"]);
524 }
525 }
526 }
527 }
530 function get_departments($ignore_dn= "")
531 {
532 global $config;
534 /* Initialize result hash */
535 $result= array();
536 $administrative= array();
537 $result['/']= $this->current['BASE'];
538 $this->tdepartments= array();
540 /* Get list of department objects */
541 $ldap= $this->get_ldap_link();
542 $ldap->cd ($this->current['BASE']);
543 $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
544 while ($attrs= $ldap->fetch()){
545 $dn= $ldap->getDN();
546 $this->tdepartments[$dn]= "";
548 /* Save administrative departments */
549 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
550 isset($attrs['gosaUnitTag'][0])){
551 $administrative[$dn]= $attrs['gosaUnitTag'][0];
552 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
553 }
555 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
556 isset($attrs['gosaUnitTag'][0])){
557 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
558 }
560 if ($dn == $ignore_dn){
561 continue;
562 }
564 /* Only assign non-root departments */
565 if ($dn != $result['/']){
566 $result[convert_department_dn($dn)]= $dn;
567 }
568 }
570 $this->adepartments= $administrative;
571 $this->departments= $result;
572 }
575 function make_idepartments($max_size= 28)
576 {
577 global $config;
578 $base = $config->current['BASE'];
580 $arr= array();
581 $ui= get_userinfo();
582 $this->idepartments= array();
584 /* Create multidimensional array, with all departments. */
585 foreach ($this->departments as $key => $val){
587 /* When using strict_units, filter non relevant parts */
588 if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
589 if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
590 $this->tdepartments[$val] != $ui->gosaUnitTag){
591 continue;
592 }
593 }
595 /* remove base from dn */
596 $val2 = str_replace($base,"",$val);
598 /* Get every single ou */
599 $str = preg_replace("/ou=/","|ou=",$val2);
600 $elements = array_reverse(split("\|",$str));
602 /* Save last array position */
603 $last = &$arr;
605 /* Get array depth */
606 $cnt = count($elements);
608 /* Add last ou element of current dn to our array */
609 foreach($elements as $key => $ele){
611 /* skip enpty */
612 if(empty($ele)) continue;
614 /* Extract department name */
615 $elestr = preg_replace("/^ou=/","", $ele);
616 $elestr = preg_replace("/,$/","",$elestr);
618 /* Add to array */
619 if($key == ($cnt-2)){
620 $last[$elestr]['ENTRY'] = $val;
621 }
623 /* Set next array appending position */
624 $last = &$last[$elestr]['SUB'];
625 }
626 }
628 /* Add base entry */
629 $ret["/"]["ENTRY"] = $base;
630 $ret["/"]["SUB"] = $arr;
632 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
633 }
636 /* Creates display friendly output from make_idepartments */
637 function generateDepartmentArray($arr,$depth = -1,$max_size){
638 $ret = array();
639 $depth ++;
641 /* Walk through array */
642 ksort($arr);
643 foreach($arr as $name => $entries){
645 /* If this department is the last in the current tree position
646 * remove it, to avoid generating output for it */
647 if(count($entries['SUB'])==0){
648 unset($entries['SUB']);
649 }
651 /* Fix name, if it contains a replace tag */
652 $name= @LDAP::fix($name);
654 /* Check if current name is too long, then cut it */
655 if(mb_strlen($name, 'UTF-8')> $max_size){
656 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
657 }
659 /* Append the name to the list */
660 if(isset($entries['ENTRY'])){
661 $a = "";
662 for($i = 0 ; $i < $depth ; $i ++){
663 $a.=".";
664 }
665 $ret[$entries['ENTRY']]=$a." ".$name;
666 }
668 /* recursive add of subdepartments */
669 if(isset($entries['SUB'])){
670 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
671 }
672 }
674 return($ret);
675 }
677 /* This function returns all available Shares defined in this ldap
678 * There are two ways to call this function, if listboxEntry is true
679 * only name and path are attached to the array, in it is false, the whole
680 * entry will be parsed an atached to the result.
681 */
682 function getShareList($listboxEntry = false)
683 {
684 $ldap= $this->get_ldap_link();
686 /* Set tag attribute if we've tagging activated */
687 $tag= "";
688 $ui= get_userinfo();
689 if ($ui->gosaUnitTag != "" && isset($this->current['STRICT_UNITS']) &&
690 preg_match('/TRUE/i', $this->current['STRICT_UNITS'])){
691 $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
692 }
694 $a_res = $ldap->search("(&(objectClass=goShareServer)$tag(objectClass=goServer))",array("goExportEntry","cn"));
695 $return= array();
696 while($entry = $ldap->fetch($a_res)){
697 if(isset($entry['goExportEntry']['count'])){
698 unset($entry['goExportEntry']['count']);
699 }
700 if(isset($entry['goExportEntry'])){
701 foreach($entry['goExportEntry'] as $export){
702 $shareAttrs = split("\|",$export);
703 if($listboxEntry) {
704 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
705 }else{
706 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
707 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
708 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
709 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
710 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
711 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
712 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
713 }
714 }
715 }
716 }
717 return($return);
718 }
720 /* This function returns all available ShareServer */
721 function getShareServerList()
722 {
723 global $config;
724 $return = array();
725 $ui = get_userinfo();
726 $base = $config->current['BASE'];
727 $res = get_list("(&(objectClass=goShareServer)(goExportEntry=*))",$ui->subtreeACL,$base,array("goExportEntry","cn"),GL_SUBSEARCH);
728 foreach($res as $entry){
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 }
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])){
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 }
759 }
761 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
762 ?>