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