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();
50 var $filename = "";
51 var $last_modified = 0;
53 function config($filename, $basedir= "")
54 {
55 $this->parser = xml_parser_create();
56 $this->basedir= $basedir;
58 xml_set_object($this->parser, $this);
59 xml_set_element_handler($this->parser, "tag_open", "tag_close");
61 /* Parse config file directly? */
62 if ($filename != ""){
63 $this->parse($filename);
64 }
65 }
68 function check_and_reload()
69 {
70 if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
72 $this->config_found= FALSE;
73 $this->tags= array();
74 $this->level= 0;
75 $this->gpc= 0;
76 $this->section= "";
77 $this->currentLocation= "";
79 $this->parser = xml_parser_create();
80 xml_set_object($this->parser, $this);
81 xml_set_element_handler($this->parser, "tag_open", "tag_close");
82 $this->parse($this->filename);
83 if(isset($_SESSION['plist'])){
84 unset($_SESSION['plist']);
85 }
86 if(isset($_SESSION['plug'])){
87 unset($_SESSION['plug']);
88 }
89 if(isset($_GET['plug'])){
90 unset($_GET['plug']);
91 }
92 }
93 }
96 function parse($filename)
97 {
98 $this->last_modified = filemtime($filename);
99 $this->filename = $filename;
100 $fh= fopen($filename, "r");
101 $xmldata= fread($fh, 100000);
102 fclose($fh);
103 if(!xml_parse($this->parser, chop($xmldata))){
104 $msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
105 xml_error_string(xml_get_error_code($this->parser)),
106 xml_get_current_line_number($this->parser));
107 msg_dialog::display(_("Config file parsing"), $msg, FATAL_ERROR_DIALOG);
108 exit;
109 }
110 }
112 function tag_open($parser, $tag, $attrs)
113 {
114 /* Save last and current tag for reference */
115 $this->tags[$this->level]= $tag;
116 $this->level++;
118 /* Trigger on CONF section */
119 if ($tag == 'CONF'){
120 $this->config_found= TRUE;
121 }
123 /* Return if we're not in config section */
124 if (!$this->config_found){
125 return;
126 }
128 /* yes/no to true/false and upper case TRUE to true and so on*/
129 foreach($attrs as $name => $value){
130 if(preg_match("/^(true|yes)$/i",$value)){
131 $attrs[$name] = "true";
132 }elseif(preg_match("/^(false|no)$/i",$value)){
133 $attrs[$name] = "false";
134 }
135 }
137 /* Look through attributes */
138 switch ($this->tags[$this->level-1]){
141 /* Handle tab section */
142 case 'TAB': $name= $this->tags[$this->level-2];
144 /* Create new array? */
145 if (!isset($this->data['TABS'][$name])){
146 $this->data['TABS'][$name]= array();
147 }
149 /* Add elements */
150 $this->data['TABS'][$name][]= $attrs;
151 break;
153 /* Handle location */
154 case 'LOCATION':
155 if ($this->tags[$this->level-2] == 'MAIN'){
156 $name= $attrs['NAME'];
157 $this->currentLocation= $name;
159 /* Add location elements */
160 $this->data['LOCATIONS'][$name]= $attrs;
161 }
162 break;
164 /* Handle referral tags */
165 case 'REFERRAL':
166 if ($this->tags[$this->level-2] == 'LOCATION'){
167 $url= $attrs['URL'];
168 $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
170 /* Add location elements */
171 if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
172 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
173 }
175 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
176 }
177 break;
179 /* Load main parameters */
180 case 'MAIN':
181 $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
182 break;
184 /* Load menu */
185 case 'SECTION':
186 if ($this->tags[$this->level-2] == 'MENU'){
187 $this->section= $attrs['NAME'];
188 $this->data['MENU'][$this->section]= array(); ;
189 }
190 break;
192 /* Inser plugins */
193 case 'PLUGIN':
194 if ($this->tags[$this->level-3] == 'MENU' &&
195 $this->tags[$this->level-2] == 'SECTION'){
197 $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
198 }
199 if ($this->tags[$this->level-2] == 'SERVICEMENU'){
200 $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
201 }
202 break;
203 }
204 }
206 function tag_close($parser, $tag)
207 {
208 /* Close config section */
209 if ($tag == 'CONF'){
210 $this->config_found= FALSE;
211 }
212 $this->level--;
213 }
215 function get_ldap_link($sizelimit= FALSE)
216 {
217 /* Build new connection */
218 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
219 $this->current['ADMIN'], $this->current['PASSWORD']);
221 /* Check for connection */
222 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
223 $smarty= get_smarty();
224 print_red (_("Can't bind to LDAP. Please contact the system administrator."));
225 $smarty->display (get_template_path('headers.tpl'));
226 echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
227 exit();
228 }
230 if (!isset($_SESSION['size_limit'])){
231 $_SESSION['size_limit']= $this->current['SIZELIMIT'];
232 $_SESSION['size_ignore']= $this->current['SIZEIGNORE'];
233 }
235 if ($sizelimit){
236 $this->ldap->set_size_limit($_SESSION['size_limit']);
237 } else {
238 $this->ldap->set_size_limit(0);
239 }
241 /* Move referrals */
242 if (!isset($this->current['REFERRAL'])){
243 $this->ldap->referrals= array();
244 } else {
245 $this->ldap->referrals= $this->current['REFERRAL'];
246 }
248 return ($this->ldap);
249 }
251 function set_current($name)
252 {
253 $this->current= $this->data['LOCATIONS'][$name];
254 if (!isset($this->current['PEOPLE'])){
255 $this->current['PEOPLE']= "ou=people";
256 }
257 if (!isset($this->current['GROUPS'])){
258 $this->current['GROUPS']= "ou=groups";
259 }
261 if (isset($this->current['INITIAL_BASE'])){
262 $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
263 }
265 /* Remove possibly added ',' from end of group and people ou */
266 $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
267 $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
269 if (!isset($this->current['WINSTATIONS'])){
270 $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
271 }
272 if (!isset($this->current['HASH'])){
273 $this->current['HASH']= "crypt";
274 }
275 if (!isset($this->current['DNMODE'])){
276 $this->current['DNMODE']= "cn";
277 }
278 if (!isset($this->current['MINID'])){
279 $this->current['MINID']= 100;
280 }
281 if (!isset($this->current['SIZELIMIT'])){
282 $this->current['SIZELIMIT']= 200;
283 }
284 if (!isset($this->current['SIZEINGORE'])){
285 $this->current['SIZEIGNORE']= TRUE;
286 } else {
287 if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
288 $this->current['SIZEIGNORE']= TRUE;
289 } else {
290 $this->current['SIZEIGNORE']= FALSE;
291 }
292 }
294 /* Sort referrals, if present */
295 if (isset ($this->current['REFERRAL'])){
296 $bases= array();
297 $servers= array();
298 foreach ($this->current['REFERRAL'] as $ref){
299 $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
300 $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
301 $bases[$base]= strlen($base);
302 $servers[$base]= $server;
303 }
304 asort($bases);
305 reset($bases);
306 }
308 /* SERVER not defined? Load the one with the shortest base */
309 if (!isset($this->current['SERVER'])){
310 $this->current['SERVER']= $servers[key($bases)];
311 }
313 /* BASE not defined? Load the one with the shortest base */
314 if (!isset($this->current['BASE'])){
315 $this->current['BASE']= key($bases);
316 }
318 /* Convert BASE to have escaped special characters */
319 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
321 /* Parse LDAP referral informations */
322 if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
323 $url= $this->current['SERVER'];
324 $referral= $this->current['REFERRAL'][$url];
325 $this->current['ADMIN']= $referral['ADMIN'];
326 $this->current['PASSWORD']= $referral['PASSWORD'];
327 }
329 /* Load server informations */
330 $this->load_servers();
331 }
333 function load_servers ()
334 {
335 /* Only perform actions if current is set */
336 if ($this->current === NULL){
337 return;
338 }
340 /* Fill imap servers */
341 $ldap= $this->get_ldap_link();
342 $ldap->cd ($this->current['BASE']);
343 if (!isset($this->current['MAILMETHOD'])){
344 $this->current['MAILMETHOD']= "";
345 }
346 if ($this->current['MAILMETHOD'] == ""){
347 $ldap->search ("(objectClass=goMailServer)", array('cn'));
348 $this->data['SERVERS']['IMAP']= array();
349 error_reporting(0);
350 while ($attrs= $ldap->fetch()){
351 $name= $attrs['cn'][0];
352 $this->data['SERVERS']['IMAP'][$name]= $name;
353 }
354 error_reporting(E_ALL);
355 } else {
356 $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
357 'goImapSieveServer', 'goImapSievePort'));
359 $this->data['SERVERS']['IMAP']= array();
360 error_reporting(0);
361 while ($attrs= $ldap->fetch()){
362 $name= $attrs['goImapName'][0];
363 $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
364 "admin" => $attrs['goImapAdmin'][0],
365 "password" => $attrs['goImapPassword'][0],
366 "sieve_server" => $attrs['goImapSieveServer'][0],
367 "sieve_port" => $attrs['goImapSievePort'][0]);
368 }
369 error_reporting(E_ALL);
370 }
372 /* Get kerberos server. FIXME: only one is supported currently */
373 $ldap->cd ($this->current['BASE']);
374 $ldap->search ("(objectClass=goKrbServer)");
375 if ($ldap->count()){
376 $attrs= $ldap->fetch();
377 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
378 'REALM' => $attrs['goKrbRealm'][0],
379 'ADMIN' => $attrs['goKrbAdmin'][0],
380 'PASSWORD' => $attrs['goKrbPassword'][0]);
381 }
383 /* Get cups server. FIXME: only one is supported currently */
384 $ldap->cd ($this->current['BASE']);
385 $ldap->search ("(objectClass=goCupsServer)");
386 if ($ldap->count()){
387 $attrs= $ldap->fetch();
388 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
389 }
391 /* Get fax server. FIXME: only one is supported currently */
392 $ldap->cd ($this->current['BASE']);
393 $ldap->search ("(objectClass=goFaxServer)");
394 if ($ldap->count()){
395 $attrs= $ldap->fetch();
396 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
397 'LOGIN' => $attrs['goFaxAdmin'][0],
398 'PASSWORD' => $attrs['goFaxPassword'][0]);
399 }
402 /* Get asterisk servers */
403 $ldap->cd ($this->current['BASE']);
404 $ldap->search ("(objectClass=goFonServer)");
405 $this->data['SERVERS']['FON']= array();
406 if ($ldap->count()){
407 while ($attrs= $ldap->fetch()){
409 /* Add 0 entry for development */
410 if(count($this->data['SERVERS']['FON']) == 0){
411 $this->data['SERVERS']['FON'][0]= array(
412 'DN' => $attrs['dn'],
413 'SERVER' => $attrs['cn'][0],
414 'LOGIN' => $attrs['goFonAdmin'][0],
415 'PASSWORD' => $attrs['goFonPassword'][0],
416 'DB' => "gophone",
417 'SIP_TABLE' => "sip_users",
418 'EXT_TABLE' => "extensions",
419 'VOICE_TABLE' => "voicemail_users",
420 'QUEUE_TABLE' => "queues",
421 'QUEUE_MEMBER_TABLE' => "queue_members");
422 }
424 /* Add entry with 'dn' as index */
425 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
426 'DN' => $attrs['dn'],
427 'SERVER' => $attrs['cn'][0],
428 'LOGIN' => $attrs['goFonAdmin'][0],
429 'PASSWORD' => $attrs['goFonPassword'][0],
430 'DB' => "gophone",
431 'SIP_TABLE' => "sip_users",
432 'EXT_TABLE' => "extensions",
433 'VOICE_TABLE' => "voicemail_users",
434 'QUEUE_TABLE' => "queues",
435 'QUEUE_MEMBER_TABLE' => "queue_members");
436 }
437 }
440 /* Get glpi server */
441 $ldap->cd ($this->current['BASE']);
442 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
443 if ($ldap->count()){
444 $attrs= $ldap->fetch();
445 if(!isset($attrs['goGlpiPassword'])){
446 $attrs['goGlpiPassword'][0] ="";
447 }
448 $this->data['SERVERS']['GLPI']= array(
449 'SERVER' => $attrs['cn'][0],
450 'LOGIN' => $attrs['goGlpiAdmin'][0],
451 'PASSWORD' => $attrs['goGlpiPassword'][0],
452 'DB' => $attrs['goGlpiDatabase'][0]);
453 }
456 /* Get logdb server */
457 $ldap->cd ($this->current['BASE']);
458 $ldap->search ("(objectClass=goLogDBServer)");
459 if ($ldap->count()){
460 $attrs= $ldap->fetch();
461 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
462 'LOGIN' => $attrs['goLogAdmin'][0],
463 'PASSWORD' => $attrs['goLogPassword'][0]);
464 }
467 /* GOsa logging databases */
468 $ldap->cd ($this->current['BASE']);
469 $ldap->search ("(objectClass=gosaLogServer)");
470 if ($ldap->count()){
471 while($attrs= $ldap->fetch()){
472 $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]=
473 array(
474 'DN' => $attrs['dn'],
475 'USER' => $attrs['goLogDBUser'][0],
476 'DB' => $attrs['goLogDB'][0],
477 'PWD' => $attrs['goLogDBPassword'][0]);
478 }
479 }
482 /* Get NFS server lists */
483 $tmp= array("default");
484 $ldap->cd ($this->current['BASE']);
485 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
486 while ($attrs= $ldap->fetch()){
487 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
488 if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
489 continue;
490 }
491 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
492 $tmp[]= $attrs["cn"][0].":$path";
493 }
494 }
495 $this->data['SERVERS']['NFS']= $tmp;
497 /* Load Terminalservers */
498 $ldap->cd ($this->current['BASE']);
499 $ldap->search ("(objectClass=goTerminalServer)");
500 $this->data['SERVERS']['TERMINAL']= array();
501 $this->data['SERVERS']['TERMINAL'][]= "default";
503 $this->data['SERVERS']['FONT']= array();
504 $this->data['SERVERS']['FONT'][]= "default";
505 while ($attrs= $ldap->fetch()){
506 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
507 for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
508 $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
509 }
510 }
512 /* Ldap Server */
513 $this->data['SERVERS']['LDAP']= array();
514 $ldap->cd ($this->current['BASE']);
515 $ldap->search ("(objectClass=goLdapServer)");
516 while ($attrs= $ldap->fetch()){
517 if (isset($attrs["goLdapBase"])){
518 for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
519 $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
520 }
521 }
522 }
524 /* Get misc server lists */
525 $this->data['SERVERS']['SYSLOG']= array("default");
526 $this->data['SERVERS']['NTP']= array("default");
527 $ldap->cd ($this->current['BASE']);
528 $ldap->search ("(objectClass=goNtpServer)");
529 while ($attrs= $ldap->fetch()){
530 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
531 }
532 $ldap->cd ($this->current['BASE']);
533 $ldap->search ("(objectClass=goSyslogServer)");
534 while ($attrs= $ldap->fetch()){
535 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
536 }
538 /* Get samba servers from LDAP, in case of samba3 */
539 if ($this->current['SAMBAVERSION'] == 3){
540 $this->data['SERVERS']['SAMBA']= array();
541 $ldap->cd ($this->current['BASE']);
542 $ldap->search ("(objectClass=sambaDomain)");
543 while ($attrs= $ldap->fetch()){
544 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array(
545 "SID" => $attrs["sambaSID"][0],
546 "RIDBASE" => $attrs["sambaAlgorithmicRidBase"][0]);
547 }
549 /* If no samba servers are found, look for configured sid/ridbase */
550 if (count($this->data['SERVERS']['SAMBA']) == 0){
551 if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
552 print_red(_("SID and/or RIDBASE missing in your configuration!"));
553 echo $_SESSION['errors'];
554 exit;
555 } else {
556 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
557 "SID" => $this->current["SID"],
558 "RIDBASE" => $this->current["RIDBASE"]);
559 }
560 }
561 }
562 }
565 function get_departments($ignore_dn= "")
566 {
567 global $config;
569 /* Initialize result hash */
570 $result= array();
571 $administrative= array();
572 $result['/']= $this->current['BASE'];
573 $this->tdepartments= array();
575 /* Get list of department objects */
576 $ldap= $this->get_ldap_link();
577 $ldap->cd ($this->current['BASE']);
578 $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
579 while ($attrs= $ldap->fetch()){
580 $dn= $ldap->getDN();
581 $this->tdepartments[$dn]= "";
583 /* Save administrative departments */
584 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
585 isset($attrs['gosaUnitTag'][0])){
586 $administrative[$dn]= $attrs['gosaUnitTag'][0];
587 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
588 }
590 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
591 isset($attrs['gosaUnitTag'][0])){
592 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
593 }
595 if ($dn == $ignore_dn){
596 continue;
597 }
599 /* Only assign non-root departments */
600 if ($dn != $result['/']){
601 $result[convert_department_dn($dn)]= $dn;
602 }
603 }
605 $this->adepartments= $administrative;
606 $this->departments= $result;
607 }
610 function make_idepartments($max_size= 28)
611 {
612 global $config;
613 $base = $config->current['BASE'];
615 $arr = array();
616 $ui= get_userinfo();
618 $this->idepartments= array();
620 /* Create multidimensional array, with all departments. */
621 foreach ($this->departments as $key => $val){
623 /* When using strict_units, filter non relevant parts */
624 if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
625 if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
626 $this->tdepartments[$val] != $ui->gosaUnitTag){
627 continue;
628 }
629 }
631 /* remove base from dn */
632 $val2 = str_replace($base,"",$val);
634 /* Get every single ou */
635 $str = preg_replace("/ou=/","|ou=",$val2);
636 $elements = array_reverse(split("\|",$str));
638 /* Save last array position */
639 $last = &$arr;
641 /* Get array depth */
642 $cnt = count($elements);
644 /* Add last ou element of current dn to our array */
645 foreach($elements as $key => $ele){
647 /* skip enpty */
648 if(empty($ele)) continue;
650 /* Extract department name */
651 $elestr = preg_replace("/^ou=/","", $ele);
652 $elestr = preg_replace("/,$/","",$elestr);
654 /* Add to array */
655 if($key == ($cnt-2)){
656 $last[$elestr]['ENTRY'] = $val;
657 }
659 /* Set next array appending position */
660 $last = &$last[$elestr]['SUB'];
661 }
662 }
664 /* Add base entry */
665 $ret["/"]["ENTRY"] = $base;
666 $ret["/"]["SUB"] = $arr;
668 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
669 }
672 /* Creates display friendly output from make_idepartments */
673 function generateDepartmentArray($arr,$depth = -1,$max_size){
674 $ret = array();
675 $depth ++;
677 /* Walk through array */
678 ksort($arr);
679 foreach($arr as $name => $entries){
681 /* If this department is the last in the current tree position
682 * remove it, to avoid generating output for it */
683 if(count($entries['SUB'])==0){
684 unset($entries['SUB']);
685 }
687 /* Fix name, if it contains a replace tag */
688 $name= @LDAP::fix($name);
690 /* Check if current name is too long, then cut it */
691 if(mb_strlen($name, 'UTF-8')> $max_size){
692 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
693 }
695 /* Append the name to the list */
696 if(isset($entries['ENTRY'])){
697 $a = "";
698 for($i = 0 ; $i < $depth ; $i ++){
699 $a.=".";
700 }
701 $ret[$entries['ENTRY']]=$a." ".$name;
702 }
704 /* recursive add of subdepartments */
705 if(isset($entries['SUB'])){
706 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
707 }
708 }
710 return($ret);
711 }
713 /* This function returns all available Shares defined in this ldap
714 * There are two ways to call this function, if listboxEntry is true
715 * only name and path are attached to the array, in it is false, the whole
716 * entry will be parsed an atached to the result.
717 */
718 function getShareList($listboxEntry = false)
719 {
720 $ldap= $this->get_ldap_link();
721 $base = $this->current['BASE'];
722 $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",$base,array("goExportEntry","cn"),GL_SUBSEARCH);
723 $return = array();
725 foreach($res as $entry){
726 if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
728 if(isset($entry['goExportEntry']['count'])){
729 unset($entry['goExportEntry']['count']);
730 }
731 if(isset($entry['goExportEntry'])){
732 foreach($entry['goExportEntry'] as $export){
733 $shareAttrs = split("\|",$export);
734 if($listboxEntry) {
735 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
736 }else{
737 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
738 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
739 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
740 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
741 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
742 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
743 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
744 }
745 }
746 }
747 }
748 }
750 return($return);
751 }
753 /* This function returns all available ShareServer */
754 function getShareServerList()
755 {
756 global $config;
757 $return = array();
758 $ui = get_userinfo();
759 $base = $config->current['BASE'];
761 $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server", $base,array("goExportEntry","cn"),GL_SUBSEARCH);
762 foreach($res as $entry){
763 if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
764 if(isset($entry['goExportEntry']['count'])){
765 unset($entry['goExportEntry']['count']);
766 }
767 foreach($entry['goExportEntry'] as $share){
768 $a_share = split("\|",$share);
769 $sharename = $a_share[0];
770 $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
771 }
772 }
773 }
774 return($return);
775 }
777 /* Check if there's the specified bool value set in the configuration */
778 function boolValueIsTrue($section, $value)
779 {
780 $section= strtoupper($section);
781 $value= strtoupper($value);
782 if (isset($this->data[$section][$value])){
784 $data= $this->data[$section][$value];
785 if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
786 return TRUE;
787 }
789 }
791 return FALSE;
792 }
795 function __search(&$arr, $name, $return)
796 {
797 $return= strtoupper($return);
798 if (is_array($arr)){
799 foreach ($arr as &$a){
800 if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
801 return(isset($a[$return])?$a[$return]:"");
802 } else {
803 $res= $this->__search ($a, $name, $return);
804 if ($res != ""){
805 return $res;
806 }
807 }
808 }
809 }
810 return ("");
811 }
814 function search($class, $value, $categories= "")
815 {
816 if (is_array($categories)){
817 foreach ($categories as $category){
818 $res= $this->__search($this->data[strtoupper($category)], $class, $value);
819 if ($res != ""){
820 return $res;
821 }
822 }
823 } else {
824 if ($categories == "") {
825 return $this->__search($this->data, $class, $value);
826 } else {
827 return $this->__search($this->data[strtoupper($categories)], $class, $value);
828 }
829 }
831 return ("");
832 }
835 /* On debian systems the session files are deleted with
836 * a cronjob, which detects all files older than specified
837 * in php.ini:'session.gc_maxlifetime' and removes them.
838 * This function checks if the gosa.conf value matches the range
839 * defined by session.gc_maxlifetime.
840 */
841 function check_session_lifetime()
842 {
843 $cfg_lifetime = $this->data['MAIN']['SESSION_LIFETIME'];
844 $ini_lifetime = ini_get('session.gc_maxlifetime');
845 $deb_system = file_exists('/etc/debian_version');
846 return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));
847 }
848 }
850 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
851 ?>