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= "";
46 var $config_version ="NOT SET";
48 /* Keep a copy of the current deparment list */
49 var $departments= array();
50 var $idepartments= array();
51 var $adepartments= array();
52 var $tdepartments= array();
53 var $filename = "";
54 var $last_modified = 0;
56 function config($filename, $basedir= "")
57 {
58 $this->parser = xml_parser_create();
59 $this->basedir= $basedir;
61 xml_set_object($this->parser, $this);
62 xml_set_element_handler($this->parser, "tag_open", "tag_close");
64 /* Parse config file directly? */
65 if ($filename != ""){
66 $this->parse($filename);
67 }
68 }
71 function check_and_reload()
72 {
73 global $ui;
75 /* Check if class_location.inc has changed, this is the case
76 if we have installed or removed plugins.
77 */
78 if(session::global_is_set("class_location.inc:timestamp")){
79 $tmp = stat("../include/class_location.inc");
80 if($tmp['mtime'] != session::global_get("class_location.inc:timestamp")){
81 session::global_un_set("plist");
82 }
83 }
84 $tmp = stat("../include/class_location.inc");
85 session::global_set("class_location.inc:timestamp",$tmp['mtime']);
89 if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
91 $this->config_found= FALSE;
92 $this->tags= array();
93 $this->level= 0;
94 $this->gpc= 0;
95 $this->section= "";
96 $this->currentLocation= "";
98 $this->parser = xml_parser_create();
99 xml_set_object($this->parser, $this);
100 xml_set_element_handler($this->parser, "tag_open", "tag_close");
101 $this->parse($this->filename);
102 }
103 }
106 function parse($filename)
107 {
109 $this->data = array(
110 "TABS" => array(),
111 "LOCATIONS" => array(),
112 "MAIN" => array(),
113 "MENU" => array(),
114 "SERVICE" => array());
116 $this->last_modified = filemtime($filename);
117 $this->filename = $filename;
118 $fh= fopen($filename, "r");
119 $xmldata= fread($fh, 100000);
120 fclose($fh);
121 if(!xml_parse($this->parser, chop($xmldata))){
122 $msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
123 xml_error_string(xml_get_error_code($this->parser)),
124 xml_get_current_line_number($this->parser));
125 msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG);
126 exit;
127 }
128 }
130 function tag_open($parser, $tag, $attrs)
131 {
132 /* Save last and current tag for reference */
133 $this->tags[$this->level]= $tag;
134 $this->level++;
136 /* Trigger on CONF section */
137 if ($tag == 'CONF'){
138 $this->config_found= TRUE;
139 if(isset($attrs['CONFIGVERSION'])){
140 $this->config_version = $attrs['CONFIGVERSION'];
141 }
142 }
144 /* Return if we're not in config section */
145 if (!$this->config_found){
146 return;
147 }
149 /* yes/no to true/false and upper case TRUE to true and so on*/
150 foreach($attrs as $name => $value){
151 if(preg_match("/^(true|yes)$/i",$value)){
152 $attrs[$name] = "true";
153 }elseif(preg_match("/^(false|no)$/i",$value)){
154 $attrs[$name] = "false";
155 }
156 }
158 /* Look through attributes */
159 switch ($this->tags[$this->level-1]){
162 /* Handle tab section */
163 case 'TAB': $name= $this->tags[$this->level-2];
165 /* Create new array? */
166 if (!isset($this->data['TABS'][$name])){
167 $this->data['TABS'][$name]= array();
168 }
170 /* Add elements */
171 $this->data['TABS'][$name][]= $attrs;
172 break;
174 /* Handle location */
175 case 'LOCATION':
176 if ($this->tags[$this->level-2] == 'MAIN'){
177 $name= $attrs['NAME'];
178 $name = preg_replace("/[<>\"']/","",$name);
179 $attrs['NAME'] = $name;
180 $this->currentLocation= $name;
182 /* Add location elements */
183 $this->data['LOCATIONS'][$name]= $attrs;
184 }
185 break;
187 /* Handle referral tags */
188 case 'REFERRAL':
189 if ($this->tags[$this->level-2] == 'LOCATION'){
190 $url= $attrs['URI'];
191 $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
193 /* Add location elements */
194 if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
195 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
196 }
198 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
199 }
200 break;
202 /* Load main parameters */
203 case 'MAIN':
204 $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
205 break;
207 /* Load menu */
208 case 'SECTION':
209 if ($this->tags[$this->level-2] == 'MENU'){
210 $this->section= $attrs['NAME'];
211 $this->data['MENU'][$this->section]= array(); ;
212 }
213 break;
215 /* Inser plugins */
216 case 'PLUGIN':
217 if ($this->tags[$this->level-3] == 'MENU' &&
218 $this->tags[$this->level-2] == 'SECTION'){
220 $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
221 }
222 if ($this->tags[$this->level-2] == 'SERVICEMENU'){
223 $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
224 }
225 break;
226 }
227 }
229 function tag_close($parser, $tag)
230 {
231 /* Close config section */
232 if ($tag == 'CONF'){
233 $this->config_found= FALSE;
234 }
235 $this->level--;
236 }
239 function get_credentials($creds)
240 {
241 if (isset($_SERVER['HTTP_GOSA_KEY'])){
242 return (cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY']));
243 }
244 return ($creds);
245 }
248 function get_ldap_link($sizelimit= FALSE)
249 {
250 if($this->ldap === NULL || !is_resource($this->ldap->cid)){
252 /* Build new connection */
253 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
254 $this->current['ADMINDN'], $this->get_credentials($this->current['ADMINPASSWORD']));
256 /* Check for connection */
257 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
258 $smarty= get_smarty();
259 msg_dialog::display(_("LDAP error"), _("Cannot bind to LDAP. Please contact the system administrator."), FATAL_ERROR_DIALOG);
260 exit();
261 }
263 /* Move referrals */
264 if (!isset($this->current['REFERRAL'])){
265 $this->ldap->referrals= array();
266 } else {
267 $this->ldap->referrals= $this->current['REFERRAL'];
268 }
270 if (!session::global_is_set('size_limit')){
271 session::global_set('size_limit',$this->current['LDAPSIZELIMIT']);
272 session::global_set('size_ignore',$this->current['LDAPSIZEIGNORE']);
273 }
274 }
276 $obj = new ldapMultiplexer($this->ldap);
277 if ($sizelimit){
278 $obj->set_size_limit(session::global_get('size_limit'));
279 } else {
280 $obj->set_size_limit(0);
281 }
282 return($obj);
283 }
285 function set_current($name)
286 {
287 $this->current= $this->data['LOCATIONS'][$name];
289 if (!isset($this->current['SAMBAVERSION'])){
290 $this->current['SAMBAVERSION']= 3;
291 }
292 if (!isset($this->current['USERRDN'])){
293 $this->current['USERRDN']= "ou=people";
294 }
295 if (!isset($this->current['GROUPRDN'])){
296 $this->current['GROUPS']= "ou=groups";
297 }
299 if (isset($this->current['INITIAL_BASE'])){
300 session::global_set('CurrentMainBase',$this->current['INITIAL_BASE']);
301 }
303 /* Remove possibly added ',' from end of group and people ou */
304 $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPRDN']);
305 $this->current['USERRDN'] = preg_replace("/,*$/","",$this->current['USERRDN']);
307 if (!isset($this->current['SAMBAMACHINEACCOUNTRDN'])){
308 $this->current['SAMBAMACHINEACCOUNTRDN']= "ou=winstations,ou=systems";
309 }
310 if (!isset($this->current['ACCOUNTPRIMARYATTRIBUTE'])){
311 $this->current['ACCOUNTPRIMARYATTRIBUTE']= "cn";
312 }
313 if (!isset($this->current['MINID'])){
314 $this->current['MINID']= 100;
315 }
316 if (!isset($this->current['LDAPSIZELIMIT'])){
317 $this->current['LDAPSIZELIMIT']= 200;
318 }
319 if (!isset($this->current['SIZEINGORE'])){
320 $this->current['LDAPSIZEIGNORE']= TRUE;
321 } else {
322 if (preg_match("/true/i", $this->current['LDAPSIZEIGNORE'])){
323 $this->current['LDAPSIZEIGNORE']= TRUE;
324 } else {
325 $this->current['LDAPSIZEIGNORE']= FALSE;
326 }
327 }
329 /* Sort referrals, if present */
330 if (isset ($this->current['REFERRAL'])){
331 $bases= array();
332 $servers= array();
333 foreach ($this->current['REFERRAL'] as $ref){
334 $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URI']);
335 $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URI']);
336 $bases[$base]= strlen($base);
337 $servers[$base]= $server;
338 }
339 asort($bases);
340 reset($bases);
341 }
343 /* SERVER not defined? Load the one with the shortest base */
344 if (!isset($this->current['SERVER'])){
345 $this->current['SERVER']= $servers[key($bases)];
346 }
348 /* BASE not defined? Load the one with the shortest base */
349 if (!isset($this->current['BASE'])){
350 $this->current['BASE']= key($bases);
351 }
353 /* Convert BASE to have escaped special characters */
354 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
356 /* Parse LDAP referral informations */
357 if (!isset($this->current['ADMINDN']) || !isset($this->current['ADMINPASSWORD'])){
358 $url= $this->current['SERVER'];
359 $referral= $this->current['REFERRAL'][$url];
360 $this->current['ADMINDN']= $referral['ADMINDN'];
361 $this->current['ADMINPASSWORD']= $referral['ADMINPASSWORD'];
362 }
364 /* Load server informations */
365 $this->load_servers();
366 }
368 function load_servers ()
369 {
370 /* Only perform actions if current is set */
371 if ($this->current === NULL){
372 return;
373 }
375 /* Fill imap servers */
376 $ldap= $this->get_ldap_link();
377 $ldap->cd ($this->current['BASE']);
379 /* Search mailMethod konfiguration in main section too
380 */
381 $this->current['MAILMETHOD'] = $this->get_cfg_value("mailMethod","");
382 if (!isset($this->current['MAILMETHOD'])){
383 $this->current['MAILMETHOD']= "";
384 }
385 if ($this->current['MAILMETHOD'] == ""){
386 $ldap->search ("(objectClass=goMailServer)", array('cn'));
387 $this->data['SERVERS']['IMAP']= array();
388 while ($attrs= $ldap->fetch()){
389 $name= $attrs['cn'][0];
390 $this->data['SERVERS']['IMAP'][$name]=
391 array(
392 "server_dn" => $attrs['dn'],
393 "connect" => "",
394 "admin" => "",
395 "password" => "",
396 "sieve_server"=> "",
397 "sieve_option"=> "",
398 "sieve_port" => "");
399 }
400 } else {
401 $ldap->search ("(&(objectClass=goImapServer)(goImapSieveServer=*))",
402 array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
403 'goImapSieveServer', 'goImapSievePort'));
405 $this->data['SERVERS']['IMAP']= array();
407 while ($attrs= $ldap->fetch()){
409 /* Check if the given goImapSieveServer is in the new style "{cn:port/option}"
410 or the old style just "cn".
411 */
412 if(preg_match("/\{/",$attrs['goImapSieveServer'][0])){
413 $sieve_server = preg_replace("/^\{([^:]*).*$/","\\1",$attrs['goImapSieveServer'][0]);
414 $sieve_option = preg_replace("/^[^:]*[^\/]*+\/(.*)\}$/","\\1",$attrs['goImapSieveServer'][0]);
415 }else{
416 $sieve_server = $attrs['goImapSieveServer'][0];
417 $sieve_option = "";
418 }
420 $pwd = $attrs['goImapPassword'][0];
421 $imap_admin = $attrs['goImapAdmin'][0];
422 $imap_connect = $attrs['goImapConnect'][0];
423 $imap_server = $attrs['goImapName'][0];
424 $sieve_port = $attrs['goImapSievePort'][0];
426 $this->data['SERVERS']['IMAP'][$imap_server]=
427 array(
428 "server_dn" => $attrs['dn'],
429 "connect" => $imap_connect,
430 "admin" => $imap_admin,
431 "password" => $pwd,
432 "sieve_server"=> $sieve_server,
433 "sieve_option"=> $sieve_option,
434 "sieve_port" => $sieve_port);
435 }
436 }
438 /* Get kerberos server. FIXME: only one is supported currently */
439 $ldap->cd ($this->current['BASE']);
440 $ldap->search ("(&(goKrbRealm=*)(goKrbAdmin=*)(objectClass=goKrbServer))");
441 if ($ldap->count()){
442 $attrs= $ldap->fetch();
443 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
444 'REALM' => $attrs['goKrbRealm'][0],
445 'ADMIN' => $attrs['goKrbAdmin'][0]);
446 }
448 /* Get cups server. FIXME: only one is supported currently */
449 $ldap->cd ($this->current['BASE']);
450 $ldap->search ("(objectClass=goCupsServer)");
451 if ($ldap->count()){
452 $attrs= $ldap->fetch();
453 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
454 }
456 /* Get fax server. FIXME: only one is supported currently */
457 $ldap->cd ($this->current['BASE']);
458 $ldap->search ("(objectClass=goFaxServer)");
459 if ($ldap->count()){
460 $attrs= $ldap->fetch();
461 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
462 'LOGIN' => $attrs['goFaxAdmin'][0],
463 'PASSWORD' => $attrs['goFaxPassword'][0]);
464 }
467 /* Get asterisk servers */
468 $ldap->cd ($this->current['BASE']);
469 $ldap->search ("(objectClass=goFonServer)");
470 $this->data['SERVERS']['FON']= array();
471 if ($ldap->count()){
472 while ($attrs= $ldap->fetch()){
474 /* Add 0 entry for development */
475 if(count($this->data['SERVERS']['FON']) == 0){
476 $this->data['SERVERS']['FON'][0]= array(
477 'DN' => $attrs['dn'],
478 'SERVER' => $attrs['cn'][0],
479 'LOGIN' => $attrs['goFonAdmin'][0],
480 'PASSWORD' => $attrs['goFonPassword'][0],
481 'DB' => "gophone",
482 'SIP_TABLE' => "sip_users",
483 'EXT_TABLE' => "extensions",
484 'VOICE_TABLE' => "voicemail_users",
485 'QUEUE_TABLE' => "queues",
486 'QUEUE_MEMBER_TABLE' => "queue_members");
487 }
489 /* Add entry with 'dn' as index */
490 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
491 'DN' => $attrs['dn'],
492 'SERVER' => $attrs['cn'][0],
493 'LOGIN' => $attrs['goFonAdmin'][0],
494 'PASSWORD' => $attrs['goFonPassword'][0],
495 'DB' => "gophone",
496 'SIP_TABLE' => "sip_users",
497 'EXT_TABLE' => "extensions",
498 'VOICE_TABLE' => "voicemail_users",
499 'QUEUE_TABLE' => "queues",
500 'QUEUE_MEMBER_TABLE' => "queue_members");
501 }
502 }
505 /* Get glpi server */
506 $ldap->cd ($this->current['BASE']);
507 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
508 if ($ldap->count()){
509 $attrs= $ldap->fetch();
510 if(!isset($attrs['goGlpiPassword'])){
511 $attrs['goGlpiPassword'][0] ="";
512 }
513 $this->data['SERVERS']['GLPI']= array(
514 'SERVER' => $attrs['cn'][0],
515 'LOGIN' => $attrs['goGlpiAdmin'][0],
516 'PASSWORD' => $attrs['goGlpiPassword'][0],
517 'DB' => $attrs['goGlpiDatabase'][0]);
518 }
521 /* Get logdb server */
522 $ldap->cd ($this->current['BASE']);
523 $ldap->search ("(objectClass=goLogDBServer)");
524 if ($ldap->count()){
525 $attrs= $ldap->fetch();
526 if(!isset($attrs['goLogDB'][0])){
527 $attrs['goLogDB'][0] = "gomon";
528 }
529 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
530 'LOGIN' => $attrs['goLogAdmin'][0],
531 'DB' => $attrs['goLogDB'][0],
532 'PASSWORD' => $attrs['goLogPassword'][0]);
533 }
536 /* GOsa logging databases */
537 $ldap->cd ($this->current['BASE']);
538 $ldap->search ("(objectClass=gosaLogServer)");
539 if ($ldap->count()){
540 while($attrs= $ldap->fetch()){
541 $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]=
542 array(
543 'DN' => $attrs['dn'],
544 'USER' => $attrs['goLogDBUser'][0],
545 'DB' => $attrs['goLogDB'][0],
546 'PWD' => $attrs['goLogDBPassword'][0]);
547 }
548 }
551 /* Get NFS server lists */
552 $tmp= array("default");
553 $tmp2= array("default");
554 $ldap->cd ($this->current['BASE']);
555 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
556 while ($attrs= $ldap->fetch()){
557 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
558 if(preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
559 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
560 $tmp[]= $attrs["cn"][0].":$path";
561 }
562 if(preg_match('/^[^|]+\|[^|]+\|NBD\|.*$/', $attrs["goExportEntry"][$i])){
563 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
564 $tmp2[]= $attrs["cn"][0].":$path";
565 }
566 }
567 }
568 $this->data['SERVERS']['NFS']= $tmp;
569 $this->data['SERVERS']['NBD']= $tmp2;
571 /* Load Terminalservers */
572 $ldap->cd ($this->current['BASE']);
573 $ldap->search ("(objectClass=goTerminalServer)",array("cn","gotoSessionType"));
574 $this->data['SERVERS']['TERMINAL']= array();
575 $this->data['SERVERS']['TERMINAL'][]= "default";
576 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'] = array();
579 while ($attrs= $ldap->fetch()){
580 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
581 if(isset( $attrs["gotoSessionType"]['count'])){
582 for($i =0 ; $i < $attrs["gotoSessionType"]['count'] ; $i++){
583 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'][$attrs["cn"][0]][] = $attrs["gotoSessionType"][$i];
584 }
585 }
586 }
588 /* Ldap Server
589 */
590 $this->data['SERVERS']['LDAP']= array();
591 $ldap->cd ($this->current['BASE']);
592 $ldap->search ("(&(objectClass=goLdapServer)(goLdapBase=*))");
593 while ($attrs= $ldap->fetch()){
594 $this->data['SERVERS']['LDAP'][$attrs['dn']] = $attrs;
595 }
597 /* Get misc server lists */
598 $this->data['SERVERS']['SYSLOG']= array("default");
599 $this->data['SERVERS']['NTP']= array("default");
600 $ldap->cd ($this->current['BASE']);
601 $ldap->search ("(objectClass=goNtpServer)");
602 while ($attrs= $ldap->fetch()){
603 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
604 }
605 $ldap->cd ($this->current['BASE']);
606 $ldap->search ("(objectClass=goSyslogServer)");
607 while ($attrs= $ldap->fetch()){
608 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
609 }
611 /* Get samba servers from LDAP, in case of samba3 */
612 if ($this->current['SAMBAVERSION'] == 3){
613 $this->data['SERVERS']['SAMBA']= array();
614 $ldap->cd ($this->current['BASE']);
615 $ldap->search ("(objectClass=sambaDomain)");
616 while ($attrs= $ldap->fetch()){
617 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
618 if(isset($attrs["sambaSID"][0])){
619 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0];
620 }
621 if(isset($attrs["sambaAlgorithmicRidBase"][0])){
622 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
623 }
624 }
626 /* If no samba servers are found, look for configured sid/ridbase */
627 if (count($this->data['SERVERS']['SAMBA']) == 0){
628 if (!isset($this->current["SAMBASID"]) || !isset($this->current["SAMBARIDBASE"])){
629 msg_dialog::display(_("Configuration error"), _("sambaSID and/or sambaRidBase missing in the configuration!"), ERROR_DIALOG);
630 } else {
631 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
632 "SID" => $this->current["SAMBASID"],
633 "RIDBASE" => $this->current["SAMBARIDBASE"]);
634 }
635 }
636 }
637 }
640 function get_departments($ignore_dn= "")
641 {
642 global $config;
644 /* Initialize result hash */
645 $result= array();
646 $administrative= array();
647 $result['/']= $this->current['BASE'];
648 $this->tdepartments= array();
650 /* Get all department types from department Management, to be able detect the department type.
651 -It is possible that differnty department types have the same name,
652 in this case we have to mark the department name to be able to differentiate.
653 (e.g l=Name or o=Name)
654 */
655 $types = departmentManagement::get_support_departments();
657 /* Create a list of attributes to fetch */
658 $ldap_values = array("objectClass","gosaUnitTag");
659 $filter = "";
660 foreach($types as $type){
661 $ldap_values[] = $type['ATTR'];
662 $filter .= "(objectClass=".$type['OC'].")";
663 }
664 $filter = "(&(objectClass=gosaDepartment)(|".$filter."))";
666 /* Get list of department objects */
667 $ldap= $this->get_ldap_link();
668 $ldap->cd ($this->current['BASE']);
669 $ldap->search ($filter, $ldap_values);
670 while ($attrs= $ldap->fetch()){
672 /* Detect department type */
673 $type_data = array();
674 foreach($types as $t => $data){
675 if(in_array($data['OC'],$attrs['objectClass'])){
676 $type_data = $data;
677 break;
678 }
679 }
681 /* Unknown department type -> skip
682 */
683 if(!count($type_data)) continue;
685 $dn= $ldap->getDN();
686 $this->tdepartments[$dn]= "";
688 /* Save administrative departments */
689 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
690 isset($attrs['gosaUnitTag'][0])){
691 $administrative[$dn]= $attrs['gosaUnitTag'][0];
692 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
693 }
695 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
696 isset($attrs['gosaUnitTag'][0])){
697 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
698 }
700 if ($dn == $ignore_dn){
701 continue;
702 }
704 $c_dn = convert_department_dn($dn)." (".$type_data['ATTR'].")";
706 /* Only assign non-root departments */
707 if ($dn != $result['/']){
708 $result[$c_dn]= $dn;
709 }
710 }
712 $this->adepartments= $administrative;
713 $this->departments= $result;
714 }
717 function make_idepartments($max_size= 28)
718 {
719 global $config;
720 $base = $config->current['BASE'];
721 $qbase = preg_quote($base, '/');
722 $utags= isset($config->current['HONOURUNITTAGS']) && preg_match('/true/i', $config->current['HONOURUNITTAGS']);
724 $arr = array();
725 $ui= get_userinfo();
727 $this->idepartments= array();
729 /* Create multidimensional array, with all departments. */
730 foreach ($this->departments as $key => $val){
732 /* When using strict_units, filter non relevant parts */
733 if ($utags){
734 if ($ui->gosaUnitTag != '' && isset($this->tdepartments[$val]) &&
735 $this->tdepartments[$val] != $ui->gosaUnitTag){
737 #TODO: link with strict*
738 #continue;
739 }
740 }
742 /* Split dn into single department pieces */
743 $elements = array_reverse(split(',',preg_replace("/$qbase$/",'',$val)));
745 /* Add last ou element of current dn to our array */
746 $last = &$arr;
747 foreach($elements as $key => $ele){
749 /* skip empty */
750 if(empty($ele)) continue;
752 /* Extract department name */
753 $elestr = trim(preg_replace('/^[^=]*+=/','', $ele),',');
754 $nameA = trim(preg_replace('/=.*$/','', $ele),',');
755 if($nameA != 'ou'){
756 $nameA = " ($nameA)";
757 }else{
758 $nameA = '';
759 }
761 /* Add to array */
762 if($key == (count($elements)-1)){
763 $last[$elestr.$nameA]['ENTRY'] = $val;
764 }
766 /* Set next array appending position */
767 $last = &$last[$elestr.$nameA]['SUB'];
768 }
769 }
772 /* Add base entry */
773 $ret['/']['ENTRY'] = $base;
774 $ret['/']['SUB'] = $arr;
775 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
776 }
779 /* Creates display friendly output from make_idepartments */
780 function generateDepartmentArray($arr,$depth = -1,$max_size = 256)
781 {
782 $ret = array();
783 $depth ++;
785 /* Walk through array */
786 ksort($arr);
787 foreach($arr as $name => $entries){
789 /* If this department is the last in the current tree position
790 * remove it, to avoid generating output for it */
791 if(count($entries['SUB'])==0){
792 unset($entries['SUB']);
793 }
795 /* Fix name, if it contains a replace tag */
796 $name= preg_replace('/\\\\,/', ',', LDAP::fix($name));
798 /* Check if current name is too long, then cut it */
799 if(mb_strlen($name, 'UTF-8')> $max_size){
800 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
801 }
803 /* Append the name to the list */
804 if(isset($entries['ENTRY'])){
805 $a = "";
806 for($i = 0 ; $i < $depth ; $i ++){
807 $a.=".";
808 }
809 $ret[$entries['ENTRY']]=$a." ".$name;
810 }
812 /* recursive add of subdepartments */
813 if(isset($entries['SUB'])){
814 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
815 }
816 }
818 return($ret);
819 }
821 /* This function returns all available Shares defined in this ldap
822 * There are two ways to call this function, if listboxEntry is true
823 * only name and path are attached to the array, in it is false, the whole
824 * entry will be parsed an atached to the result.
825 */
826 function getShareList($listboxEntry = false)
827 {
828 $tmp = get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",get_ou("serverRDN"),
829 $this->current['BASE'],array("goExportEntry","cn"), GL_NONE);
830 $return =array();
831 foreach($tmp as $entry){
833 if(isset($entry['goExportEntry']['count'])){
834 unset($entry['goExportEntry']['count']);
835 }
836 if(isset($entry['goExportEntry'])){
837 foreach($entry['goExportEntry'] as $export){
838 $shareAttrs = split("\|",$export);
839 if($listboxEntry) {
840 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
841 }else{
842 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
843 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
844 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
845 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
846 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
847 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
848 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
849 }
850 }
851 }
852 }
853 return($return);
854 }
857 /* This function returns all available ShareServer */
858 function getShareServerList()
859 {
860 global $config;
861 $return = array();
862 $ui = get_userinfo();
863 $base = $config->current['BASE'];
864 $res= get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server",
865 get_ou("serverRDN"), $base,array("goExportEntry","cn"),GL_NONE | GL_NO_ACL_CHECK);
867 foreach($res as $entry){
869 $acl = $ui->get_permissions($entry['dn'],"server","");
870 if(isset($entry['goExportEntry']['count'])){
871 unset($entry['goExportEntry']['count']);
872 }
873 foreach($entry['goExportEntry'] as $share){
874 $a_share = split("\|",$share);
875 $sharename = $a_share[0];
876 $data= array();
877 $data['NAME'] = $sharename;
878 $data['ACL'] = $acl;
879 $data['SERVER'] = $entry['cn']['0'];
880 $data['SHARE'] = $sharename;
881 $data['DISPLAY']= $entry['cn'][0]." [".$sharename."]";
882 $return[$entry['cn'][0]."|".$sharename] = $data;
883 }
884 }
885 return($return);
886 }
889 /* Check if there's the specified bool value set in the configuration */
890 function boolValueIsTrue($section, $value)
891 {
892 $section= strtoupper($section);
893 $value= strtoupper($value);
894 if (isset($this->data[$section][$value])){
896 $data= $this->data[$section][$value];
897 if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
898 return TRUE;
899 }
901 }
903 return FALSE;
904 }
907 function __search(&$arr, $name, $return)
908 {
909 $return= strtoupper($return);
910 if (is_array($arr)){
911 foreach ($arr as &$a){
912 if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
913 return(isset($a[$return])?$a[$return]:"");
914 } else {
915 $res= $this->__search ($a, $name, $return);
916 if ($res != ""){
917 return $res;
918 }
919 }
920 }
921 }
922 return ("");
923 }
926 function search($class, $value, $categories= "")
927 {
928 if (is_array($categories)){
929 foreach ($categories as $category){
930 $res= $this->__search($this->data[strtoupper($category)], $class, $value);
931 if ($res != ""){
932 return $res;
933 }
934 }
935 } else {
936 if ($categories == "") {
937 return $this->__search($this->data, $class, $value);
938 } else {
939 return $this->__search($this->data[strtoupper($categories)], $class, $value);
940 }
941 }
943 return ("");
944 }
947 function get_cfg_value($name, $default= "") {
948 $name= strtoupper($name);
950 /* Check if we have a current value for $name */
951 if (isset($this->current[$name])){
952 return ($this->current[$name]);
953 }
955 /* Check if we have a global value for $name */
956 if (isset($this->data["MAIN"][$name])){
957 return ($this->data["MAIN"][$name]);
958 }
960 return ($default);
961 }
964 function check_config_version()
965 {
966 /* Skip check, if we've already mentioned the mismatch
967 */
968 if(session::global_is_set("LastChecked") && session::global_get("LastChecked") == $this->config_version) return;
970 /* Remember last checked version
971 */
972 session::global_set("LastChecked",$this->config_version);
974 $current = md5(file_get_contents(CONFIG_TEMPLATE_DIR."/gosa.conf"));
976 /* Check contributed config version and current config version.
977 */
978 if(($this->config_version == "NOT SET") || ($this->config_version != $current && !empty($this->config_version))){
979 msg_dialog::display(_("Configuration"),_("The configuration file you are using seems to be outdated. Please move the GOsa configuration file away to run the GOsa setup again."));
980 }
981 }
984 /* On debian systems the session files are deleted with
985 * a cronjob, which detects all files older than specified
986 * in php.ini:'session.gc_maxlifetime' and removes them.
987 * This function checks if the gosa.conf value matches the range
988 * defined by session.gc_maxlifetime.
989 */
990 function check_session_lifetime()
991 {
992 if(isset($this->data['MAIN']['SESSIONLIFETIME'])){
993 $cfg_lifetime = $this->data['MAIN']['SESSIONLIFETIME'];
994 $ini_lifetime = ini_get('session.gc_maxlifetime');
995 $deb_system = file_exists('/etc/debian_version');
996 return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));
997 }else{
998 return(TRUE);
999 }
1000 }
1001 }
1003 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1004 ?>