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();
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 /* Handle faxformat */
180 case 'FAXFORMAT':
181 if ($this->tags[$this->level-2] == 'MAIN'){
182 /* Add fax formats */
183 $this->data['MAIN']['FAXFORMATS'][]= $attrs['TYPE'];
184 }
185 break;
187 /* Load main parameters */
188 case 'MAIN':
189 $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
190 break;
192 /* Load menu */
193 case 'SECTION':
194 if ($this->tags[$this->level-2] == 'MENU'){
195 $this->section= $attrs['NAME'];
196 $this->data['MENU'][$this->section]= array(); ;
197 }
198 break;
200 /* Inser plugins */
201 case 'PLUGIN':
202 if ($this->tags[$this->level-3] == 'MENU' &&
203 $this->tags[$this->level-2] == 'SECTION'){
205 $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
206 }
207 if ($this->tags[$this->level-2] == 'SERVICEMENU'){
208 $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
209 }
210 break;
211 }
212 }
214 function tag_close($parser, $tag)
215 {
216 /* Close config section */
217 if ($tag == 'CONF'){
218 $this->config_found= FALSE;
219 }
220 $this->level--;
221 }
223 function get_ldap_link($sizelimit= FALSE)
224 {
225 /* Build new connection */
226 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
227 $this->current['ADMIN'], $this->current['PASSWORD']);
229 /* Check for connection */
230 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
231 $smarty= get_smarty();
232 print_red (_("Can't bind to LDAP. Please contact the system administrator."));
233 $smarty->display (get_template_path('headers.tpl'));
234 echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
235 exit();
236 }
238 if (!isset($_SESSION['size_limit'])){
239 $_SESSION['size_limit']= $this->current['SIZELIMIT'];
240 $_SESSION['size_ignore']= $this->current['SIZEIGNORE'];
241 }
243 if ($sizelimit){
244 $this->ldap->set_size_limit($_SESSION['size_limit']);
245 } else {
246 $this->ldap->set_size_limit(0);
247 }
249 /* Move referrals */
250 if (!isset($this->current['REFERRAL'])){
251 $this->ldap->referrals= array();
252 } else {
253 $this->ldap->referrals= $this->current['REFERRAL'];
254 }
256 return ($this->ldap);
257 }
259 function set_current($name)
260 {
261 $this->current= $this->data['LOCATIONS'][$name];
262 if (!isset($this->current['PEOPLE'])){
263 $this->current['PEOPLE']= "ou=people";
264 }
265 if (!isset($this->current['GROUPS'])){
266 $this->current['GROUPS']= "ou=groups";
267 }
269 if (isset($this->current['INITIAL_BASE'])){
270 $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
271 }
273 /* Remove possibly added ',' from end of group and people ou */
274 $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
275 $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
277 if (!isset($this->current['WINSTATIONS'])){
278 $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
279 }
280 if (!isset($this->current['HASH'])){
281 $this->current['HASH']= "crypt";
282 }
283 if (!isset($this->current['DNMODE'])){
284 $this->current['DNMODE']= "cn";
285 }
286 if (!isset($this->current['MINID'])){
287 $this->current['MINID']= 100;
288 }
289 if (!isset($this->current['SIZELIMIT'])){
290 $this->current['SIZELIMIT']= 200;
291 }
292 if (!isset($this->current['SIZEINGORE'])){
293 $this->current['SIZEIGNORE']= TRUE;
294 } else {
295 if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
296 $this->current['SIZEIGNORE']= TRUE;
297 } else {
298 $this->current['SIZEIGNORE']= FALSE;
299 }
300 }
302 /* Sort referrals, if present */
303 if (isset ($this->current['REFERRAL'])){
304 $bases= array();
305 $servers= array();
306 foreach ($this->current['REFERRAL'] as $ref){
307 $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
308 $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
309 $bases[$base]= strlen($base);
310 $servers[$base]= $server;
311 }
312 asort($bases);
313 reset($bases);
314 }
316 /* SERVER not defined? Load the one with the shortest base */
317 if (!isset($this->current['SERVER'])){
318 $this->current['SERVER']= $servers[key($bases)];
319 }
321 /* BASE not defined? Load the one with the shortest base */
322 if (!isset($this->current['BASE'])){
323 $this->current['BASE']= key($bases);
324 }
326 /* Convert BASE to have escaped special characters */
327 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
329 /* Parse LDAP referral informations */
330 if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
331 $url= $this->current['SERVER'];
332 $referral= $this->current['REFERRAL'][$url];
333 $this->current['ADMIN']= $referral['ADMIN'];
334 $this->current['PASSWORD']= $referral['PASSWORD'];
335 }
337 /* Load server informations */
338 $this->load_servers();
339 }
341 function load_servers ()
342 {
343 /* Only perform actions if current is set */
344 if ($this->current === NULL){
345 return;
346 }
348 /* Fill imap servers */
349 $ldap= $this->get_ldap_link();
350 $ldap->cd ($this->current['BASE']);
351 if (!isset($this->current['MAILMETHOD'])){
352 $this->current['MAILMETHOD']= "";
353 }
354 if ($this->current['MAILMETHOD'] == ""){
355 $ldap->search ("(objectClass=goMailServer)", array('cn'));
356 $this->data['SERVERS']['IMAP']= array();
357 error_reporting(0);
358 while ($attrs= $ldap->fetch()){
359 $name= $attrs['cn'][0];
360 $this->data['SERVERS']['IMAP'][$name]= $name;
361 }
362 error_reporting(E_ALL);
363 } else {
364 $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
365 'goImapSieveServer', 'goImapSievePort'));
367 $this->data['SERVERS']['IMAP']= array();
368 error_reporting(0);
369 while ($attrs= $ldap->fetch()){
370 $name= $attrs['goImapName'][0];
371 $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
372 "admin" => $attrs['goImapAdmin'][0],
373 "password" => $attrs['goImapPassword'][0],
374 "sieve_server" => $attrs['goImapSieveServer'][0],
375 "sieve_port" => $attrs['goImapSievePort'][0]);
376 }
377 error_reporting(E_ALL);
378 }
380 /* Get kerberos server. FIXME: only one is supported currently */
381 $ldap->cd ($this->current['BASE']);
382 $ldap->search ("(objectClass=goKrbServer)");
383 if ($ldap->count()){
384 $attrs= $ldap->fetch();
385 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
386 'REALM' => $attrs['goKrbRealm'][0],
387 'ADMIN' => $attrs['goKrbAdmin'][0],
388 'PASSWORD' => $attrs['goKrbPassword'][0]);
389 }
391 /* Get cups server. FIXME: only one is supported currently */
392 $ldap->cd ($this->current['BASE']);
393 $ldap->search ("(objectClass=goCupsServer)");
394 if ($ldap->count()){
395 $attrs= $ldap->fetch();
396 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
397 }
399 /* Get fax server. FIXME: only one is supported currently */
400 $ldap->cd ($this->current['BASE']);
401 $ldap->search ("(objectClass=goFaxServer)");
402 if ($ldap->count()){
403 $attrs= $ldap->fetch();
404 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
405 'LOGIN' => $attrs['goFaxAdmin'][0],
406 'PASSWORD' => $attrs['goFaxPassword'][0]);
407 }
410 /* Get asterisk servers */
411 $ldap->cd ($this->current['BASE']);
412 $ldap->search ("(objectClass=goFonServer)");
413 $this->data['SERVERS']['FON']= array();
414 if ($ldap->count()){
415 while ($attrs= $ldap->fetch()){
417 /* Add 0 entry for development */
418 if(count($this->data['SERVERS']['FON']) == 0){
419 $this->data['SERVERS']['FON'][0]= array(
420 'DN' => $attrs['dn'],
421 'SERVER' => $attrs['cn'][0],
422 'LOGIN' => $attrs['goFonAdmin'][0],
423 'PASSWORD' => $attrs['goFonPassword'][0],
424 'DB' => "gophone",
425 'SIP_TABLE' => "sip_users",
426 'EXT_TABLE' => "extensions",
427 'VOICE_TABLE' => "voicemail_users",
428 'QUEUE_TABLE' => "queues",
429 'QUEUE_MEMBER_TABLE' => "queue_members");
430 }
432 /* Add entry with 'dn' as index */
433 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
434 'DN' => $attrs['dn'],
435 'SERVER' => $attrs['cn'][0],
436 'LOGIN' => $attrs['goFonAdmin'][0],
437 'PASSWORD' => $attrs['goFonPassword'][0],
438 'DB' => "gophone",
439 'SIP_TABLE' => "sip_users",
440 'EXT_TABLE' => "extensions",
441 'VOICE_TABLE' => "voicemail_users",
442 'QUEUE_TABLE' => "queues",
443 'QUEUE_MEMBER_TABLE' => "queue_members");
444 }
445 }
448 /* Get glpi server */
449 $ldap->cd ($this->current['BASE']);
450 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
451 if ($ldap->count()){
452 $attrs= $ldap->fetch();
453 if(!isset($attrs['goGlpiPassword'])){
454 $attrs['goGlpiPassword'][0] ="";
455 }
456 $this->data['SERVERS']['GLPI']= array(
457 'SERVER' => $attrs['cn'][0],
458 'LOGIN' => $attrs['goGlpiAdmin'][0],
459 'PASSWORD' => $attrs['goGlpiPassword'][0],
460 'DB' => $attrs['goGlpiDatabase'][0]);
461 }
464 /* Get logdb server */
465 $ldap->cd ($this->current['BASE']);
466 $ldap->search ("(objectClass=goLogDBServer)");
467 if ($ldap->count()){
468 $attrs= $ldap->fetch();
469 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
470 'LOGIN' => $attrs['goLogAdmin'][0],
471 'PASSWORD' => $attrs['goLogPassword'][0]);
472 }
475 /* GOsa logging databases */
476 $ldap->cd ($this->current['BASE']);
477 $ldap->search ("(objectClass=gosaLogServer)");
478 if ($ldap->count()){
479 while($attrs= $ldap->fetch()){
480 $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]=
481 array(
482 'DN' => $attrs['dn'],
483 'USER' => $attrs['goLogDBUser'][0],
484 'DB' => $attrs['goLogDB'][0],
485 'PWD' => $attrs['goLogDBPassword'][0]);
486 }
487 }
490 /* Get NFS server lists */
491 $tmp= array("default");
492 $ldap->cd ($this->current['BASE']);
493 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
494 while ($attrs= $ldap->fetch()){
495 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
496 if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
497 continue;
498 }
499 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
500 $tmp[]= $attrs["cn"][0].":$path";
501 }
502 }
503 $this->data['SERVERS']['NFS']= $tmp;
505 /* Load Terminalservers */
506 $ldap->cd ($this->current['BASE']);
507 $ldap->search ("(objectClass=goTerminalServer)");
508 $this->data['SERVERS']['TERMINAL']= array();
509 $this->data['SERVERS']['TERMINAL'][]= "default";
511 $this->data['SERVERS']['FONT']= array();
512 $this->data['SERVERS']['FONT'][]= "default";
513 while ($attrs= $ldap->fetch()){
514 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
515 for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
516 $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
517 }
518 }
520 /* Ldap Server */
521 $this->data['SERVERS']['LDAP']= array();
522 $ldap->cd ($this->current['BASE']);
523 $ldap->search ("(objectClass=goLdapServer)");
524 while ($attrs= $ldap->fetch()){
525 if (isset($attrs["goLdapBase"])){
526 for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
527 $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
528 }
529 }
530 }
532 /* Get misc server lists */
533 $this->data['SERVERS']['SYSLOG']= array("default");
534 $this->data['SERVERS']['NTP']= array("default");
535 $ldap->cd ($this->current['BASE']);
536 $ldap->search ("(objectClass=goNtpServer)");
537 while ($attrs= $ldap->fetch()){
538 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
539 }
540 $ldap->cd ($this->current['BASE']);
541 $ldap->search ("(objectClass=goSyslogServer)");
542 while ($attrs= $ldap->fetch()){
543 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
544 }
546 /* Get samba servers from LDAP, in case of samba3 */
547 if ($this->current['SAMBAVERSION'] == 3){
548 $this->data['SERVERS']['SAMBA']= array();
549 $ldap->cd ($this->current['BASE']);
550 $ldap->search ("(objectClass=sambaDomain)");
551 while ($attrs= $ldap->fetch()){
552 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array(
553 "SID" => $attrs["sambaSID"][0],
554 "RIDBASE" => $attrs["sambaAlgorithmicRidBase"][0]);
555 }
557 /* If no samba servers are found, look for configured sid/ridbase */
558 if (count($this->data['SERVERS']['SAMBA']) == 0){
559 if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
560 print_red(_("SID and/or RIDBASE missing in your configuration!"));
561 echo $_SESSION['errors'];
562 exit;
563 } else {
564 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
565 "SID" => $this->current["SID"],
566 "RIDBASE" => $this->current["RIDBASE"]);
567 }
568 }
569 }
570 }
573 function get_departments($ignore_dn= "")
574 {
575 global $config;
577 /* Initialize result hash */
578 $result= array();
579 $administrative= array();
580 $result['/']= $this->current['BASE'];
581 $this->tdepartments= array();
583 /* Get list of department objects */
584 $ldap= $this->get_ldap_link();
585 $ldap->cd ($this->current['BASE']);
586 $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
587 while ($attrs= $ldap->fetch()){
588 $dn= $ldap->getDN();
589 $this->tdepartments[$dn]= "";
591 /* Save administrative departments */
592 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
593 isset($attrs['gosaUnitTag'][0])){
594 $administrative[$dn]= $attrs['gosaUnitTag'][0];
595 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
596 }
598 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
599 isset($attrs['gosaUnitTag'][0])){
600 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
601 }
603 if ($dn == $ignore_dn){
604 continue;
605 }
607 /* Only assign non-root departments */
608 if ($dn != $result['/']){
609 $result[convert_department_dn($dn)]= $dn;
610 }
611 }
613 $this->adepartments= $administrative;
614 $this->departments= $result;
615 }
618 function make_idepartments($max_size= 28)
619 {
620 global $config;
621 $base = $config->current['BASE'];
623 $arr = array();
624 $ui= get_userinfo();
626 $this->idepartments= array();
628 /* Create multidimensional array, with all departments. */
629 foreach ($this->departments as $key => $val){
631 /* When using strict_units, filter non relevant parts */
632 if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
633 if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
634 $this->tdepartments[$val] != $ui->gosaUnitTag){
635 continue;
636 }
637 }
639 /* remove base from dn */
640 $val2 = str_replace($base,"",$val);
642 /* Get every single ou */
643 $str = preg_replace("/ou=/","|ou=",$val2);
644 $elements = array_reverse(split("\|",$str));
646 /* Save last array position */
647 $last = &$arr;
649 /* Get array depth */
650 $cnt = count($elements);
652 /* Add last ou element of current dn to our array */
653 foreach($elements as $key => $ele){
655 /* skip enpty */
656 if(empty($ele)) continue;
658 /* Extract department name */
659 $elestr = preg_replace("/^ou=/","", $ele);
660 $elestr = preg_replace("/,$/","",$elestr);
662 /* Add to array */
663 if($key == ($cnt-2)){
664 $last[$elestr]['ENTRY'] = $val;
665 }
667 /* Set next array appending position */
668 $last = &$last[$elestr]['SUB'];
669 }
670 }
672 /* Add base entry */
673 $ret["/"]["ENTRY"] = $base;
674 $ret["/"]["SUB"] = $arr;
676 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
677 }
680 /* Creates display friendly output from make_idepartments */
681 function generateDepartmentArray($arr,$depth = -1,$max_size){
682 $ret = array();
683 $depth ++;
685 /* Walk through array */
686 ksort($arr);
687 foreach($arr as $name => $entries){
689 /* If this department is the last in the current tree position
690 * remove it, to avoid generating output for it */
691 if(count($entries['SUB'])==0){
692 unset($entries['SUB']);
693 }
695 /* Fix name, if it contains a replace tag */
696 $name= @LDAP::fix($name);
698 /* Check if current name is too long, then cut it */
699 if(mb_strlen($name, 'UTF-8')> $max_size){
700 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
701 }
703 /* Append the name to the list */
704 if(isset($entries['ENTRY'])){
705 $a = "";
706 for($i = 0 ; $i < $depth ; $i ++){
707 $a.=".";
708 }
709 $ret[$entries['ENTRY']]=$a." ".$name;
710 }
712 /* recursive add of subdepartments */
713 if(isset($entries['SUB'])){
714 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
715 }
716 }
718 return($ret);
719 }
721 /* This function returns all available Shares defined in this ldap
722 * There are two ways to call this function, if listboxEntry is true
723 * only name and path are attached to the array, in it is false, the whole
724 * entry will be parsed an atached to the result.
725 */
726 function getShareList($listboxEntry = false)
727 {
728 $ldap= $this->get_ldap_link();
729 $base = $this->current['BASE'];
730 $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",$base,array("goExportEntry","cn"),GL_SUBSEARCH);
731 $return = array();
733 foreach($res as $entry){
734 if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
736 if(isset($entry['goExportEntry']['count'])){
737 unset($entry['goExportEntry']['count']);
738 }
739 if(isset($entry['goExportEntry'])){
740 foreach($entry['goExportEntry'] as $export){
741 $shareAttrs = split("\|",$export);
742 if($listboxEntry) {
743 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
744 }else{
745 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
746 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
747 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
748 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
749 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
750 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
751 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
752 }
753 }
754 }
755 }
756 }
758 return($return);
759 }
761 /* This function returns all available ShareServer */
762 function getShareServerList()
763 {
764 global $config;
765 $return = array();
766 $ui = get_userinfo();
767 $base = $config->current['BASE'];
769 $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server", $base,array("goExportEntry","cn"),GL_SUBSEARCH);
770 foreach($res as $entry){
771 if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
772 if(isset($entry['goExportEntry']['count'])){
773 unset($entry['goExportEntry']['count']);
774 }
775 foreach($entry['goExportEntry'] as $share){
776 $a_share = split("\|",$share);
777 $sharename = $a_share[0];
778 $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
779 }
780 }
781 }
782 return($return);
783 }
785 /* Check if there's the specified bool value set in the configuration */
786 function boolValueIsTrue($section, $value)
787 {
788 $section= strtoupper($section);
789 $value= strtoupper($value);
790 if (isset($this->data[$section][$value])){
792 $data= $this->data[$section][$value];
793 if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
794 return TRUE;
795 }
797 }
799 return FALSE;
800 }
803 function __search(&$arr, $name, $return)
804 {
805 $return= strtoupper($return);
806 if (is_array($arr)){
807 foreach ($arr as &$a){
808 if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
809 return(isset($a[$return])?$a[$return]:"");
810 } else {
811 $res= $this->__search ($a, $name, $return);
812 if ($res != ""){
813 return $res;
814 }
815 }
816 }
817 }
818 return ("");
819 }
822 function search($class, $value, $categories= "")
823 {
824 if (is_array($categories)){
825 foreach ($categories as $category){
826 $res= $this->__search($this->data[strtoupper($category)], $class, $value);
827 if ($res != ""){
828 return $res;
829 }
830 }
831 } else {
832 if ($categories == "") {
833 return $this->__search($this->data, $class, $value);
834 } else {
835 return $this->__search($this->data[strtoupper($categories)], $class, $value);
836 }
837 }
839 return ("");
840 }
843 /* On debian systems the session files are deleted with
844 * a cronjob, which detects all files older than specified
845 * in php.ini:'session.gc_maxlifetime' and removes them.
846 * This function checks if the gosa.conf value matches the range
847 * defined by session.gc_maxlifetime.
848 */
849 function check_session_lifetime()
850 {
851 $cfg_lifetime = $this->data['MAIN']['SESSION_LIFETIME'];
852 $ini_lifetime = ini_get('session.gc_maxlifetime');
853 $deb_system = file_exists('/etc/debian_version');
854 return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));
855 }
856 }
858 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
859 ?>