1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class config {
25 /* XML parser */
26 var $parser;
27 var $config_found= FALSE;
28 var $tags= array();
29 var $level= 0;
30 var $gpc= 0;
31 var $section= "";
32 var $currentLocation= "";
34 /* Selected connection */
35 var $current= array();
37 /* Link to LDAP-server */
38 var $ldap= NULL;
39 var $referrals= array();
41 /* Configuration data */
42 var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(),
43 'MAIN' => array(),
44 'MENU' => array(), 'SERVICE' => array());
45 var $basedir= "";
47 /* Keep a copy of the current deparment list */
48 var $departments= array();
49 var $idepartments= array();
50 var $adepartments= array();
51 var $tdepartments= array();
52 var $filename = "";
53 var $last_modified = 0;
55 function config($filename, $basedir= "")
56 {
57 $this->parser = xml_parser_create();
58 $this->basedir= $basedir;
60 xml_set_object($this->parser, $this);
61 xml_set_element_handler($this->parser, "tag_open", "tag_close");
63 /* Parse config file directly? */
64 if ($filename != ""){
65 $this->parse($filename);
66 }
67 }
70 function check_and_reload()
71 {
72 if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
74 $this->config_found= FALSE;
75 $this->tags= array();
76 $this->level= 0;
77 $this->gpc= 0;
78 $this->section= "";
79 $this->currentLocation= "";
81 $this->parser = xml_parser_create();
82 xml_set_object($this->parser, $this);
83 xml_set_element_handler($this->parser, "tag_open", "tag_close");
84 $this->parse($this->filename);
85 if(session::is_set('plist')){
86 session::un_set('plist');
87 }
88 if(session::is_set('plug')){
89 session::un_set('plug');
90 }
91 if(isset($_GET['plug'])){
92 unset($_GET['plug']);
93 }
94 }
95 }
98 function parse($filename)
99 {
100 $this->last_modified = filemtime($filename);
101 $this->filename = $filename;
102 $fh= fopen($filename, "r");
103 $xmldata= fread($fh, 100000);
104 fclose($fh);
105 if(!xml_parse($this->parser, chop($xmldata))){
106 $msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
107 xml_error_string(xml_get_error_code($this->parser)),
108 xml_get_current_line_number($this->parser));
109 msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG);
110 exit;
111 }
112 }
114 function tag_open($parser, $tag, $attrs)
115 {
116 /* Save last and current tag for reference */
117 $this->tags[$this->level]= $tag;
118 $this->level++;
120 /* Trigger on CONF section */
121 if ($tag == 'CONF'){
122 $this->config_found= TRUE;
123 }
125 /* Return if we're not in config section */
126 if (!$this->config_found){
127 return;
128 }
130 /* yes/no to true/false and upper case TRUE to true and so on*/
131 foreach($attrs as $name => $value){
132 if(preg_match("/^(true|yes)$/i",$value)){
133 $attrs[$name] = "true";
134 }elseif(preg_match("/^(false|no)$/i",$value)){
135 $attrs[$name] = "false";
136 }
137 }
139 /* Look through attributes */
140 switch ($this->tags[$this->level-1]){
143 /* Handle tab section */
144 case 'TAB': $name= $this->tags[$this->level-2];
146 /* Create new array? */
147 if (!isset($this->data['TABS'][$name])){
148 $this->data['TABS'][$name]= array();
149 }
151 /* Add elements */
152 $this->data['TABS'][$name][]= $attrs;
153 break;
155 /* Handle location */
156 case 'LOCATION':
157 if ($this->tags[$this->level-2] == 'MAIN'){
158 $name= $attrs['NAME'];
159 $this->currentLocation= $name;
161 /* Add location elements */
162 $this->data['LOCATIONS'][$name]= $attrs;
163 }
164 break;
166 /* Handle referral tags */
167 case 'REFERRAL':
168 if ($this->tags[$this->level-2] == 'LOCATION'){
169 $url= $attrs['URL'];
170 $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
172 /* Add location elements */
173 if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
174 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
175 }
177 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
178 }
179 break;
181 /* Load main parameters */
182 case 'MAIN':
183 $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
184 break;
186 /* Load menu */
187 case 'SECTION':
188 if ($this->tags[$this->level-2] == 'MENU'){
189 $this->section= $attrs['NAME'];
190 $this->data['MENU'][$this->section]= array(); ;
191 }
192 break;
194 /* Inser plugins */
195 case 'PLUGIN':
196 if ($this->tags[$this->level-3] == 'MENU' &&
197 $this->tags[$this->level-2] == 'SECTION'){
199 $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
200 }
201 if ($this->tags[$this->level-2] == 'SERVICEMENU'){
202 $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
203 }
204 break;
205 }
206 }
208 function tag_close($parser, $tag)
209 {
210 /* Close config section */
211 if ($tag == 'CONF'){
212 $this->config_found= FALSE;
213 }
214 $this->level--;
215 }
217 function get_ldap_link($sizelimit= FALSE)
218 {
219 if($this->ldap === NULL || !is_resource($this->ldap->cid)){
221 /* Build new connection */
222 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
223 $this->get_admin_dn(), $this->get_admin_password());
225 /* Check for connection */
226 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
227 $smarty= get_smarty();
228 msg_dialog::display(_("LDAP error"), _("Cannot bind to LDAP. Please contact the system administrator."), FATAL_ERROR_DIALOG);
229 exit();
230 }
232 if (!session::is_set('size_limit')){
233 session::set('size_limit',$this->current['SIZELIMIT']);
234 session::set('size_ignore',$this->current['SIZEIGNORE']);
235 }
237 if ($sizelimit){
238 $this->ldap->set_size_limit(session::get('size_limit'));
239 } else {
240 $this->ldap->set_size_limit(0);
241 }
243 /* Move referrals */
244 if (!isset($this->current['REFERRAL'])){
245 $this->ldap->referrals= array();
246 } else {
247 $this->ldap->referrals= $this->current['REFERRAL'];
248 }
249 }
251 return new ldapMultiplexer($this->ldap);
252 }
254 function set_current($name)
255 {
256 $this->current= $this->data['LOCATIONS'][$name];
257 if (!isset($this->current['PEOPLE'])){
258 $this->current['PEOPLE']= "ou=people";
259 }
260 if (!isset($this->current['GROUPS'])){
261 $this->current['GROUPS']= "ou=groups";
262 }
264 if (isset($this->current['INITIAL_BASE'])){
265 session::set('CurrentMainBase',$this->current['INITIAL_BASE']);
266 }
268 /* Remove possibly added ',' from end of group and people ou */
269 $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
270 $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
272 if (!isset($this->current['WINSTATIONS'])){
273 $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
274 }
275 if (!isset($this->current['HASH'])){
276 $this->current['HASH']= "crypt";
277 }
278 if (!isset($this->current['DNMODE'])){
279 $this->current['DNMODE']= "cn";
280 }
281 if (!isset($this->current['MINID'])){
282 $this->current['MINID']= 100;
283 }
284 if (!isset($this->current['SIZELIMIT'])){
285 $this->current['SIZELIMIT']= 200;
286 }
287 if (!isset($this->current['SIZEINGORE'])){
288 $this->current['SIZEIGNORE']= TRUE;
289 } else {
290 if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
291 $this->current['SIZEIGNORE']= TRUE;
292 } else {
293 $this->current['SIZEIGNORE']= FALSE;
294 }
295 }
297 /* Sort referrals, if present */
298 if (isset ($this->current['REFERRAL'])){
299 $bases= array();
300 $servers= array();
301 foreach ($this->current['REFERRAL'] as $ref){
302 $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
303 $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
304 $bases[$base]= strlen($base);
305 $servers[$base]= $server;
306 }
307 asort($bases);
308 reset($bases);
309 }
311 /* SERVER not defined? Load the one with the shortest base */
312 if (!isset($this->current['SERVER'])){
313 $this->current['SERVER']= $servers[key($bases)];
314 }
316 /* BASE not defined? Load the one with the shortest base */
317 if (!isset($this->current['BASE'])){
318 $this->current['BASE']= key($bases);
319 }
321 /* Convert BASE to have escaped special characters */
322 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
324 /* Load server informations */
325 $this->load_servers();
326 }
329 function update_credentials_from_config()
330 {
331 /* Parse LDAP referral informations */
332 if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
333 $url= $this->current['SERVER'];
334 $referral= $this->current['REFERRAL'][$url];
335 $this->current['ADMIN']= $referral['ADMIN'];
336 $this->current['PASSWORD']= $referral['PASSWORD'];
337 }
339 /* Bail out if problematic */
340 if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
341 msg_dialog::display(_("Configuration error"), _("Cannot find any administrative LDAP credentials!"), FATAL_ERROR_DIALOG);
342 exit;
343 }
344 }
347 function encode_server_url($url, $base, $val)
348 {
349 return (preg_replace("/_+/", "_", "HTTP_".strtr(strtoupper($url."_".md5($base)."_$val"), "-:/", "___")));
350 }
353 function get_admin_dn()
354 {
355 $enc= $this->encode_server_url($this->current['SERVER'], $this->current['BASE'], "ADMIN");
357 /* Answer from http request */
358 if (isset($_SERVER[$enc])){
359 return $_SERVER[$enc];
360 }
362 /* Answer in old style for compatibility */
363 $this->update_credentials_from_config();
364 return $this->current['ADMIN'];
365 }
368 function get_admin_password()
369 {
370 $enc= $this->encode_server_url($this->current['SERVER'], $this->current['BASE'], "PASSWORD");
372 /* Answer from http request */
373 if (isset($_SERVER[$enc])){
374 return $_SERVER[$enc];
375 }
377 /* Answer in old style for compatibility */
378 $this->update_credentials_from_config();
379 return $this->current['PASSWORD'];
380 }
383 function load_servers ()
384 {
385 /* Only perform actions if current is set */
386 if ($this->current === NULL){
387 return;
388 }
390 /* Fill imap servers */
391 $ldap= $this->get_ldap_link();
392 $ldap->cd ($this->current['BASE']);
393 if (!isset($this->current['MAILMETHOD'])){
394 $this->current['MAILMETHOD']= "";
395 }
396 if ($this->current['MAILMETHOD'] == ""){
397 $ldap->search ("(objectClass=goMailServer)", array('cn'));
398 $this->data['SERVERS']['IMAP']= array();
399 error_reporting(0);
400 while ($attrs= $ldap->fetch()){
401 $name= $attrs['cn'][0];
402 $this->data['SERVERS']['IMAP'][$name]= $name;
403 }
404 error_reporting(E_ALL);
405 } else {
406 $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
407 'goImapSieveServer', 'goImapSievePort'));
409 $this->data['SERVERS']['IMAP']= array();
410 error_reporting(0);
411 while ($attrs= $ldap->fetch()){
412 $name= $attrs['goImapName'][0];
413 $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
414 "admin" => $attrs['goImapAdmin'][0],
415 "password" => $attrs['goImapPassword'][0],
416 "sieve_server" => $attrs['goImapSieveServer'][0],
417 "sieve_port" => $attrs['goImapSievePort'][0]);
418 }
419 error_reporting(E_ALL);
420 }
422 /* Get kerberos server. FIXME: only one is supported currently */
423 $ldap->cd ($this->current['BASE']);
424 $ldap->search ("(objectClass=goKrbServer)");
425 if ($ldap->count()){
426 $attrs= $ldap->fetch();
427 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
428 'REALM' => $attrs['goKrbRealm'][0]);
429 }
431 /* Get cups server. FIXME: only one is supported currently */
432 $ldap->cd ($this->current['BASE']);
433 $ldap->search ("(objectClass=goCupsServer)");
434 if ($ldap->count()){
435 $attrs= $ldap->fetch();
436 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
437 }
439 /* Get fax server. FIXME: only one is supported currently */
440 $ldap->cd ($this->current['BASE']);
441 $ldap->search ("(objectClass=goFaxServer)");
442 if ($ldap->count()){
443 $attrs= $ldap->fetch();
444 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
445 'LOGIN' => $attrs['goFaxAdmin'][0],
446 'PASSWORD' => $attrs['goFaxPassword'][0]);
447 }
450 /* Get asterisk servers */
451 $ldap->cd ($this->current['BASE']);
452 $ldap->search ("(objectClass=goFonServer)");
453 $this->data['SERVERS']['FON']= array();
454 if ($ldap->count()){
455 while ($attrs= $ldap->fetch()){
457 /* Add 0 entry for development */
458 if(count($this->data['SERVERS']['FON']) == 0){
459 $this->data['SERVERS']['FON'][0]= array(
460 'DN' => $attrs['dn'],
461 'SERVER' => $attrs['cn'][0],
462 'LOGIN' => $attrs['goFonAdmin'][0],
463 'PASSWORD' => $attrs['goFonPassword'][0],
464 'DB' => "gophone",
465 'SIP_TABLE' => "sip_users",
466 'EXT_TABLE' => "extensions",
467 'VOICE_TABLE' => "voicemail_users",
468 'QUEUE_TABLE' => "queues",
469 'QUEUE_MEMBER_TABLE' => "queue_members");
470 }
472 /* Add entry with 'dn' as index */
473 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
474 'DN' => $attrs['dn'],
475 'SERVER' => $attrs['cn'][0],
476 'LOGIN' => $attrs['goFonAdmin'][0],
477 'PASSWORD' => $attrs['goFonPassword'][0],
478 'DB' => "gophone",
479 'SIP_TABLE' => "sip_users",
480 'EXT_TABLE' => "extensions",
481 'VOICE_TABLE' => "voicemail_users",
482 'QUEUE_TABLE' => "queues",
483 'QUEUE_MEMBER_TABLE' => "queue_members");
484 }
485 }
488 /* Get glpi server */
489 $ldap->cd ($this->current['BASE']);
490 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
491 if ($ldap->count()){
492 $attrs= $ldap->fetch();
493 if(!isset($attrs['goGlpiPassword'])){
494 $attrs['goGlpiPassword'][0] ="";
495 }
496 $this->data['SERVERS']['GLPI']= array(
497 'SERVER' => $attrs['cn'][0],
498 'LOGIN' => $attrs['goGlpiAdmin'][0],
499 'PASSWORD' => $attrs['goGlpiPassword'][0],
500 'DB' => $attrs['goGlpiDatabase'][0]);
501 }
504 /* Get logdb server */
505 $ldap->cd ($this->current['BASE']);
506 $ldap->search ("(objectClass=goLogDBServer)");
507 if ($ldap->count()){
508 $attrs= $ldap->fetch();
509 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
510 'LOGIN' => $attrs['goLogAdmin'][0],
511 'PASSWORD' => $attrs['goLogPassword'][0]);
512 }
515 /* GOsa logging databases */
516 $ldap->cd ($this->current['BASE']);
517 $ldap->search ("(objectClass=gosaLogServer)");
518 if ($ldap->count()){
519 while($attrs= $ldap->fetch()){
520 $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]=
521 array(
522 'DN' => $attrs['dn'],
523 'USER' => $attrs['goLogDBUser'][0],
524 'DB' => $attrs['goLogDB'][0],
525 'PWD' => $attrs['goLogDBPassword'][0]);
526 }
527 }
530 /* Get NFS server lists */
531 $tmp= array("default");
532 $ldap->cd ($this->current['BASE']);
533 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
534 while ($attrs= $ldap->fetch()){
535 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
536 if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
537 continue;
538 }
539 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
540 $tmp[]= $attrs["cn"][0].":$path";
541 }
542 }
543 $this->data['SERVERS']['NFS']= $tmp;
545 /* Load Terminalservers */
546 $ldap->cd ($this->current['BASE']);
547 $ldap->search ("(objectClass=goTerminalServer)",array("cn","gotoSessionType"));
548 $this->data['SERVERS']['TERMINAL']= array();
549 $this->data['SERVERS']['TERMINAL'][]= "default";
550 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'] = array();
553 while ($attrs= $ldap->fetch()){
554 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
555 if(isset( $attrs["gotoSessionType"]['count'])){
556 for($i =0 ; $i < $attrs["gotoSessionType"]['count'] ; $i++){
557 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'][$attrs["cn"][0]][] = $attrs["gotoSessionType"][$i];
558 }
559 }
560 }
562 /* Ldap Server */
563 $this->data['SERVERS']['LDAP']= array();
564 $ldap->cd ($this->current['BASE']);
565 $ldap->search ("(objectClass=goLdapServer)");
566 while ($attrs= $ldap->fetch()){
567 if (isset($attrs["goLdapBase"])){
568 for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
569 $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
570 }
571 }
572 }
574 /* Get misc server lists */
575 $this->data['SERVERS']['SYSLOG']= array("default");
576 $this->data['SERVERS']['NTP']= array("default");
577 $ldap->cd ($this->current['BASE']);
578 $ldap->search ("(objectClass=goNtpServer)");
579 while ($attrs= $ldap->fetch()){
580 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
581 }
582 $ldap->cd ($this->current['BASE']);
583 $ldap->search ("(objectClass=goSyslogServer)");
584 while ($attrs= $ldap->fetch()){
585 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
586 }
588 /* Get samba servers from LDAP, in case of samba3 */
589 if ($this->current['SAMBAVERSION'] == 3){
590 $this->data['SERVERS']['SAMBA']= array();
591 $ldap->cd ($this->current['BASE']);
592 $ldap->search ("(objectClass=sambaDomain)");
593 while ($attrs= $ldap->fetch()){
594 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
595 if(isset($attrs["sambaSID"][0])){
596 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0];
597 }
598 if(isset($attrs["sambaAlgorithmicRidBase"][0])){
599 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
600 }
601 }
603 /* If no samba servers are found, look for configured sid/ridbase */
604 if (count($this->data['SERVERS']['SAMBA']) == 0){
605 if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
606 msg_dialog::display(_("Configuration error"), _("SID and/or RIDBASE missing in the configuration!"), FATAL_ERROR_DIALOG);
607 exit();
608 } else {
609 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
610 "SID" => $this->current["SID"],
611 "RIDBASE" => $this->current["RIDBASE"]);
612 }
613 }
614 }
615 }
618 function get_departments($ignore_dn= "")
619 {
620 global $config;
622 /* Initialize result hash */
623 $result= array();
624 $administrative= array();
625 $result['/']= $this->current['BASE'];
626 $this->tdepartments= array();
628 /* Get list of department objects */
629 $ldap= $this->get_ldap_link();
630 $ldap->cd ($this->current['BASE']);
631 $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
632 while ($attrs= $ldap->fetch()){
633 $dn= $ldap->getDN();
634 $this->tdepartments[$dn]= "";
636 /* Save administrative departments */
637 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
638 isset($attrs['gosaUnitTag'][0])){
639 $administrative[$dn]= $attrs['gosaUnitTag'][0];
640 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
641 }
643 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
644 isset($attrs['gosaUnitTag'][0])){
645 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
646 }
648 if ($dn == $ignore_dn){
649 continue;
650 }
652 /* Only assign non-root departments */
653 if ($dn != $result['/']){
654 $result[convert_department_dn($dn)]= $dn;
655 }
656 }
658 $this->adepartments= $administrative;
659 $this->departments= $result;
660 }
663 function make_idepartments($max_size= 28)
664 {
665 global $config;
666 $base = $config->current['BASE'];
668 $arr = array();
669 $ui= get_userinfo();
671 $this->idepartments= array();
673 /* Create multidimensional array, with all departments. */
674 foreach ($this->departments as $key => $val){
676 /* When using strict_units, filter non relevant parts */
677 if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
678 if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
679 $this->tdepartments[$val] != $ui->gosaUnitTag){
680 # continue;
681 }
682 }
684 /* remove base from dn */
685 $val2 = str_replace($base,"",$val);
687 /* Get every single ou */
688 $str = preg_replace("/ou=/","|ou=",$val2);
689 $elements = array_reverse(split("\|",$str));
691 /* Save last array position */
692 $last = &$arr;
694 /* Get array depth */
695 $cnt = count($elements);
697 /* Add last ou element of current dn to our array */
698 foreach($elements as $key => $ele){
700 /* skip enpty */
701 if(empty($ele)) continue;
703 /* Extract department name */
704 $elestr = preg_replace("/^ou=/","", $ele);
705 $elestr = preg_replace("/,$/","",$elestr);
707 /* Add to array */
708 if($key == ($cnt-2)){
709 $last[$elestr]['ENTRY'] = $val;
710 }
712 /* Set next array appending position */
713 $last = &$last[$elestr]['SUB'];
714 }
715 }
717 /* Add base entry */
718 $ret["/"]["ENTRY"] = $base;
719 $ret["/"]["SUB"] = $arr;
721 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
722 }
725 /* Creates display friendly output from make_idepartments */
726 function generateDepartmentArray($arr,$depth = -1,$max_size){
727 $ret = array();
728 $depth ++;
730 /* Walk through array */
731 ksort($arr);
732 foreach($arr as $name => $entries){
734 /* If this department is the last in the current tree position
735 * remove it, to avoid generating output for it */
736 if(count($entries['SUB'])==0){
737 unset($entries['SUB']);
738 }
740 /* Fix name, if it contains a replace tag */
741 $name= @LDAP::fix($name);
743 /* Check if current name is too long, then cut it */
744 if(mb_strlen($name, 'UTF-8')> $max_size){
745 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
746 }
748 /* Append the name to the list */
749 if(isset($entries['ENTRY'])){
750 $a = "";
751 for($i = 0 ; $i < $depth ; $i ++){
752 $a.=".";
753 }
754 $ret[$entries['ENTRY']]=$a." ".$name;
755 }
757 /* recursive add of subdepartments */
758 if(isset($entries['SUB'])){
759 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
760 }
761 }
763 return($ret);
764 }
766 /* This function returns all available Shares defined in this ldap
767 * There are two ways to call this function, if listboxEntry is true
768 * only name and path are attached to the array, in it is false, the whole
769 * entry will be parsed an atached to the result.
770 */
771 function getShareList($listboxEntry = false)
772 {
773 $tmp = get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",get_ou("serverou"),
774 $this->current['BASE'],array("goExportEntry","cn"), GL_NONE);
775 $return =array();
776 foreach($tmp as $entry){
778 if(isset($entry['goExportEntry']['count'])){
779 unset($entry['goExportEntry']['count']);
780 }
781 if(isset($entry['goExportEntry'])){
782 foreach($entry['goExportEntry'] as $export){
783 $shareAttrs = split("\|",$export);
784 if($listboxEntry) {
785 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
786 }else{
787 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
788 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
789 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
790 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
791 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
792 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
793 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
794 }
795 }
796 }
797 }
798 return($return);
799 }
802 /* This function returns all available ShareServer */
803 function getShareServerList()
804 {
805 global $config;
806 $return = array();
807 $base = $config->current['BASE'];
808 $res= get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server",
809 get_ou("serverou"), $base,array("goExportEntry","cn"),GL_NONE);
811 foreach($res as $entry){
812 if(isset($entry['goExportEntry']['count'])){
813 unset($entry['goExportEntry']['count']);
814 }
815 foreach($entry['goExportEntry'] as $share){
816 $a_share = split("\|",$share);
817 $sharename = $a_share[0];
818 $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
819 }
820 }
821 return($return);
822 }
825 /* Check if there's the specified bool value set in the configuration */
826 function boolValueIsTrue($section, $value)
827 {
828 $section= strtoupper($section);
829 $value= strtoupper($value);
830 if (isset($this->data[$section][$value])){
832 $data= $this->data[$section][$value];
833 if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
834 return TRUE;
835 }
837 }
839 return FALSE;
840 }
843 function __search(&$arr, $name, $return)
844 {
845 $return= strtoupper($return);
846 if (is_array($arr)){
847 foreach ($arr as &$a){
848 if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
849 return(isset($a[$return])?$a[$return]:"");
850 } else {
851 $res= $this->__search ($a, $name, $return);
852 if ($res != ""){
853 return $res;
854 }
855 }
856 }
857 }
858 return ("");
859 }
862 function search($class, $value, $categories= "")
863 {
864 if (is_array($categories)){
865 foreach ($categories as $category){
866 $res= $this->__search($this->data[strtoupper($category)], $class, $value);
867 if ($res != ""){
868 return $res;
869 }
870 }
871 } else {
872 if ($categories == "") {
873 return $this->__search($this->data, $class, $value);
874 } else {
875 return $this->__search($this->data[strtoupper($categories)], $class, $value);
876 }
877 }
879 return ("");
880 }
883 /* On debian systems the session files are deleted with
884 * a cronjob, which detects all files older than specified
885 * in php.ini:'session.gc_maxlifetime' and removes them.
886 * This function checks if the gosa.conf value matches the range
887 * defined by session.gc_maxlifetime.
888 */
889 function check_session_lifetime()
890 {
891 $cfg_lifetime = $this->data['MAIN']['SESSION_LIFETIME'];
892 $ini_lifetime = ini_get('session.gc_maxlifetime');
893 $deb_system = file_exists('/etc/debian_version');
894 return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));
895 }
896 }
898 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
899 ?>