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 /*! \brief Configuration class
24 * \ingroup coreclasses
25 *
26 * The configuration class, responsible for parsing and querying the
27 * gosa configuration file.
28 */
30 class config {
32 /* XML parser */
33 var $parser;
34 var $config_found= FALSE;
35 var $tags= array();
36 var $level= 0;
37 var $gpc= 0;
38 var $section= "";
39 var $currentLocation= "";
41 /*! \brief Store configuration for current location */
42 var $current= array();
44 /* Link to LDAP-server */
45 var $ldap= NULL;
46 var $referrals= array();
48 /* \brief Configuration data
49 *
50 * - $data['SERVERS'] contains server informations.
51 * */
52 var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(),
53 'MAIN' => array(),
54 'MENU' => array(), 'SERVICE' => array());
55 var $basedir= "";
56 var $config_version ="NOT SET";
58 /* Keep a copy of the current deparment list */
59 var $departments= array();
60 var $idepartments= array();
61 var $adepartments= array();
62 var $tdepartments= array();
63 var $department_info= array();
64 var $filename = "";
65 var $last_modified = 0;
67 var $instanceUUID = "";
69 private $jsonRPChandle = NULL;
71 public $configRegistry = NULL;
73 /*! \brief Class constructor of the config class
74 *
75 * \param string 'filename' path to the configuration file
76 * \param string 'basedir' base directory
77 *
78 * */
79 function config($filename, $basedir= "")
80 {
81 $this->parser = xml_parser_create();
82 $this->basedir= $basedir;
84 xml_set_object($this->parser, $this);
85 xml_set_element_handler($this->parser, "tag_open", "tag_close");
87 /* Parse config file directly? */
88 if ($filename != ""){
89 $this->parse($filename);
90 }
92 // Load configuration registry
93 $this->configRegistry = new configRegistry($this);
94 $this->registration = new GOsaRegistration($this);
95 }
98 function getInstanceUUID()
99 {
100 return($this->instanceUUID);
101 }
104 /*! \brief Check and reload the configuration
105 *
106 * This function checks if the configuration has changed, since it was
107 * read the last time and reloads it. It uses the file mtime to check
108 * weither the file changed or not.
109 *
110 * */
111 function check_and_reload()
112 {
113 global $ui;
115 /* Check if class_location.inc has changed, this is the case
116 if we have installed or removed plugins.
117 */
118 if(session::global_is_set("class_location.inc:timestamp")){
119 $tmp = stat("../include/class_location.inc");
120 if($tmp['mtime'] != session::global_get("class_location.inc:timestamp")){
121 session::global_un_set("plist");
122 }
123 }
124 $tmp = stat("../include/class_location.inc");
125 session::global_set("class_location.inc:timestamp",$tmp['mtime']);
127 if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
129 $this->config_found= FALSE;
130 $this->tags= array();
131 $this->level= 0;
132 $this->gpc= 0;
133 $this->section= "";
134 $this->currentLocation= "";
136 $this->parser = xml_parser_create();
137 xml_set_object($this->parser, $this);
138 xml_set_element_handler($this->parser, "tag_open", "tag_close");
139 $this->parse($this->filename);
140 $this->set_current($this->current['NAME']);
141 }
142 }
145 /*! \brief Parse the given configuration file
146 *
147 * Parses the configuration file and displays errors if there
148 * is something wrong with it.
149 *
150 * \param string 'filename' The filename of the configuration file.
151 * */
153 function parse($filename)
154 {
155 $this->data = array(
156 "TABS" => array(),
157 "LOCATIONS" => array(),
158 "MAIN" => array(),
159 "MENU" => array(),
160 "SERVICE" => array());
162 $this->last_modified = filemtime($filename);
163 $this->filename = $filename;
164 $fh= fopen($filename, "r");
165 $xmldata= fread($fh, 100000);
166 fclose($fh);
167 if(!xml_parse($this->parser, chop($xmldata))){
168 $msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
169 bold(xml_error_string(xml_get_error_code($this->parser))),
170 bold(xml_get_current_line_number($this->parser)));
171 msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG);
172 exit;
173 }
174 }
176 function tag_open($parser, $tag, $attrs)
177 {
178 /* Save last and current tag for reference */
179 $this->tags[$this->level]= $tag;
180 $this->level++;
182 /* Trigger on CONF section */
183 if ($tag == 'CONF'){
184 $this->config_found= TRUE;
185 if(isset($attrs['CONFIGVERSION'])){
186 $this->config_version = $attrs['CONFIGVERSION'];
187 }
188 if(isset($attrs['INSTANCEUUID'])){
189 $this->instanceUUID = $attrs['INSTANCEUUID'];
190 }
191 }
193 /* Return if we're not in config section */
194 if (!$this->config_found){
195 return;
196 }
198 /* yes/no to true/false and upper case TRUE to true and so on*/
199 foreach($attrs as $name => $value){
200 if(preg_match("/^(true|yes)$/i",$value)){
201 $attrs[$name] = "true";
202 }elseif(preg_match("/^(false|no)$/i",$value)){
203 $attrs[$name] = "false";
204 }
205 }
207 /* Look through attributes */
208 switch ($this->tags[$this->level-1]){
211 /* Handle tab section */
212 case 'TAB': $name= $this->tags[$this->level-2];
214 /* Create new array? */
215 if (!isset($this->data['TABS'][$name])){
216 $this->data['TABS'][$name]= array();
217 }
219 /* Add elements */
220 $this->data['TABS'][$name][]= $attrs;
221 break;
223 /* Handle location */
224 case 'LOCATION':
225 if ($this->tags[$this->level-2] == 'MAIN'){
226 $name= $attrs['NAME'];
227 $name = preg_replace("/[<>\"']/","",$name);
228 $attrs['NAME'] = $name;
229 $this->currentLocation= $name;
231 /* Add location elements */
232 $this->data['LOCATIONS'][$name]= $attrs;
233 }
234 break;
236 /* Handle referral tags */
237 case 'REFERRAL':
238 if ($this->tags[$this->level-2] == 'LOCATION'){
239 $url= $attrs['URI'];
240 $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
242 /* Add location elements */
243 if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
244 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
245 }
247 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
248 }
249 break;
251 /* Load main parameters */
252 case 'MAIN':
253 $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
254 break;
256 /* Load menu */
257 case 'SECTION':
258 if ($this->tags[$this->level-2] == 'MENU'){
259 $this->section= $attrs['NAME'];
260 $this->data['MENU'][$this->section]= array(); ;
261 }
262 break;
264 case 'PATHMENU':
265 $this->data['PATHMENU']= array(); ;
266 break;
268 case 'SHORTCUTMENU':
269 $this->data['SHORTCUTMENU']= array(); ;
270 break;
272 /* Inser plugins */
273 case 'PLUGIN':
274 if ($this->tags[$this->level-3] == 'MENU' &&
275 $this->tags[$this->level-2] == 'SECTION'){
277 $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
278 }
279 if ($this->tags[$this->level-2] == 'PATHMENU'){
280 $this->data['PATHMENU'][$this->gpc++]= $attrs;
281 }
282 if ($this->tags[$this->level-2] == 'SHORTCUTMENU'){
283 $this->data['SHORTCUTMENU'][$this->gpc++]= $attrs;
284 }
285 if ($this->tags[$this->level-2] == 'SERVICEMENU'){
286 $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
287 }
288 break;
289 }
290 }
292 function tag_close($parser, $tag)
293 {
294 /* Close config section */
295 if ($tag == 'CONF'){
296 $this->config_found= FALSE;
297 }
298 $this->level--;
299 }
302 function get_credentials($creds)
303 {
304 if (isset($_SERVER['HTTP_GOSA_KEY'])){
305 if (!session::global_is_set('HTTP_GOSA_KEY_CACHE')){
306 session::global_set('HTTP_GOSA_KEY_CACHE',array());
307 }
308 $cache = session::global_get('HTTP_GOSA_KEY_CACHE');
309 if(!isset($cache[$creds])){
310 $cache[$creds] = cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY']);
311 session::global_set('HTTP_GOSA_KEY_CACHE',$cache);
312 }
313 return ($cache[$creds]);
314 }
315 return ($creds);
316 }
319 function getRpcHandle($connectUrl=NULL, $username=NULL, $userPassword=NULL, $authModeDigest=FALSE, $cache = TRUE)
320 {
321 // Get conenct information, if no info was given use the default values from gosa.conf
322 $connectUrl = ($connectUrl !== NULL) ? $connectUrl : $this->get_cfg_value('core','gosaRpcServer');
323 $username = ($username !== NULL) ? $username : $this->get_cfg_value('core','gosaRpcUser');
324 $userPassword = ($userPassword !== NULL) ? $userPassword : $this->get_cfg_value('core','gosaRpcPassword');
325 $authModeDigest = $authModeDigest;
327 // Create jsonRPC handle on demand.
328 if(!$cache){
329 return(new jsonRPC($this, $connectUrl, $username, $userPassword, $authModeDigest));
330 }else{
332 if(!isset($this->jsonRPChandle[$connectUrl][$username]) || !$this->jsonRPChandle[$connectUrl][$username]){
333 $this->jsonRPChandle[$connectUrl][$username] = new jsonRPC($this, $connectUrl, $username, $userPassword, $authModeDigest);
334 }
335 return($this->jsonRPChandle[$connectUrl][$username]);
336 }
337 }
340 /*! \brief Get a LDAP link object
341 *
342 * This function can be used to get an ldap object, which in turn can
343 * be used to query the LDAP. See the LDAP class for more information
344 * on how to use it.
345 *
346 * Example usage:
347 * \code
348 * $ldap = $this->config->get_ldap_link();
349 * \endcode
350 *
351 * \param boolean sizelimit Weither to impose a sizelimit on the LDAP object or not.
352 * Defaults to false. If set to true, the size limit in the configuration
353 * file will be used to set the option LDAP_OPT_SIZELIMIT.
354 * \return ldapMultiplexer object
355 */
356 function get_ldap_link($sizelimit= FALSE)
357 {
358 if($this->ldap === NULL || !is_resource($this->ldap->cid)){
360 /* Build new connection */
361 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
362 $this->current['ADMINDN'], $this->get_credentials($this->current['ADMINPASSWORD']));
364 /* Check for connection */
365 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
366 $smarty= get_smarty();
367 msg_dialog::display(_("LDAP error"), _("Cannot bind to LDAP!"), FATAL_ERROR_DIALOG);
368 exit();
369 }
371 /* Move referrals */
372 if (!isset($this->current['REFERRAL'])){
373 $this->ldap->referrals= array();
374 } else {
375 $this->ldap->referrals= $this->current['REFERRAL'];
376 }
378 if (!session::global_is_set('size_limit')){
379 session::global_set('size_limit', $this->get_cfg_value('core', 'ldapSizelimit'));
380 session::global_set('size_ignore', $this->boolValueIsTrue('core', 'ldapSizeIgnore'));
381 }
382 }
384 $obj = new ldapMultiplexer($this->ldap);
385 if ($sizelimit){
386 $obj->set_size_limit(session::global_get('size_limit'));
387 } else {
388 $obj->set_size_limit(0);
389 }
390 return($obj);
391 }
393 /*! \brief Set the current location
394 *
395 * \param string name the name of the location
396 */
397 function set_current($name)
398 {
399 $this->current= $this->data['LOCATIONS'][$name];
401 if (isset($this->current['INITIAL_BASE'])){
402 session::global_set('CurrentMainBase',$this->current['INITIAL_BASE']);
403 }
405 /* Sort referrals, if present */
406 if (isset ($this->current['REFERRAL'])){
407 $bases= array();
408 $servers= array();
409 foreach ($this->current['REFERRAL'] as $ref){
410 $server= preg_replace('%^(.*://[^/]+)/.*$%', '\\1', $ref['URI']);
411 $base= preg_replace('%^.*://[^/]+/(.*)$%', '\\1', $ref['URI']);
412 $bases[$base]= strlen($base);
413 $servers[$base]= $server;
414 }
415 asort($bases);
416 reset($bases);
417 }
419 /* SERVER not defined? Load the one with the shortest base */
420 if (!isset($this->current['SERVER'])){
421 $this->current['SERVER']= $servers[key($bases)];
422 }
424 /* BASE not defined? Load the one with the shortest base */
425 if (!isset($this->current['BASE'])){
426 $this->current['BASE']= key($bases);
427 }
429 /* Convert BASE to have escaped special characters */
430 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
432 /* Parse LDAP referral informations */
433 if (!isset($this->current['ADMINDN']) || !isset($this->current['ADMINPASSWORD'])){
434 $url= $this->current['SERVER'];
435 $referral= $this->current['REFERRAL'][$url];
436 $this->current['ADMINDN']= $referral['ADMINDN'];
437 $this->current['ADMINPASSWORD']= $referral['ADMINPASSWORD'];
438 }
440 /* Load server informations */
441 $this->load_servers();
442 }
445 /*! \brief Load server information from config/LDAP
446 *
447 * This function searches the LDAP for servers (e.g. goImapServer, goMailServer etc.)
448 * and stores information about them $this->data['SERVERS']. In the case of mailservers
449 * the main section of the configuration file is searched, too.
450 */
451 function load_servers ()
452 {
453 /* Only perform actions if current is set */
454 if ($this->current === NULL){
455 return;
456 }
458 /* Fill imap servers */
459 $ldap= $this->get_ldap_link();
460 $ldap->cd ($this->current['BASE']);
462 /* Search mailMethod konfiguration in main section too
463 */
464 $tmp = $this->get_cfg_value("core","mailMethod");
465 if ($tmp){
466 $ldap->search ("(objectClass=goMailServer)", array('cn'));
467 $this->data['SERVERS']['IMAP']= array();
468 while ($attrs= $ldap->fetch()){
469 $name= $attrs['cn'][0];
470 $this->data['SERVERS']['IMAP'][$name]=
471 array(
472 "server_dn" => $attrs['dn'],
473 "connect" => "",
474 "admin" => "",
475 "password" => "",
476 "sieve_server"=> "",
477 "sieve_option"=> "",
478 "sieve_port" => "");
479 }
480 } else {
481 $ldap->search ("(&(objectClass=goImapServer)(goImapSieveServer=*))",
482 array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
483 'goImapSieveServer', 'goImapSievePort'));
485 $this->data['SERVERS']['IMAP']= array();
487 while ($attrs= $ldap->fetch()){
489 /* Check if the given goImapSieveServer is in the new style "{cn:port/option}"
490 or the old style just "cn".
491 */
492 if(preg_match("/\{/",$attrs['goImapSieveServer'][0])){
493 $sieve_server = preg_replace("/^\{([^:]*).*$/","\\1",$attrs['goImapSieveServer'][0]);
494 $sieve_option = preg_replace("/^[^:]*[^\/]*+\/(.*)\}$/","\\1",$attrs['goImapSieveServer'][0]);
495 }else{
496 $sieve_server = $attrs['goImapSieveServer'][0];
497 $sieve_option = "";
498 }
500 $pwd = $attrs['goImapPassword'][0];
501 $imap_admin = $attrs['goImapAdmin'][0];
502 $imap_connect = $attrs['goImapConnect'][0];
503 $imap_server = $attrs['goImapName'][0];
504 $sieve_port = $attrs['goImapSievePort'][0];
506 $this->data['SERVERS']['IMAP'][$imap_server]=
507 array(
508 "server_dn" => $attrs['dn'],
509 "connect" => $imap_connect,
510 "admin" => $imap_admin,
511 "password" => $pwd,
512 "sieve_server"=> $sieve_server,
513 "sieve_option"=> $sieve_option,
514 "sieve_port" => $sieve_port);
515 }
516 }
518 /* Get kerberos server. FIXME: only one is supported currently */
519 $ldap->cd ($this->current['BASE']);
520 $ldap->search ("(&(goKrbRealm=*)(goKrbAdmin=*)(objectClass=goKrbServer))");
521 if ($ldap->count()){
522 $attrs= $ldap->fetch();
523 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
524 'REALM' => $attrs['goKrbRealm'][0],
525 'ADMIN' => $attrs['goKrbAdmin'][0]);
526 }
528 /* Get cups server. FIXME: only one is supported currently */
529 $ldap->cd ($this->current['BASE']);
530 $ldap->search ("(objectClass=goCupsServer)");
531 if ($ldap->count()){
532 $attrs= $ldap->fetch();
533 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
534 }
536 /* Get fax server. FIXME: only one is supported currently */
537 $ldap->cd ($this->current['BASE']);
538 $ldap->search ("(objectClass=goFaxServer)");
539 if ($ldap->count()){
540 $attrs= $ldap->fetch();
541 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
542 'LOGIN' => $attrs['goFaxAdmin'][0],
543 'PASSWORD' => $attrs['goFaxPassword'][0]);
544 }
547 /* Get asterisk servers */
548 $ldap->cd ($this->current['BASE']);
549 $ldap->search ("(objectClass=goFonServer)");
550 $this->data['SERVERS']['FON']= array();
551 if ($ldap->count()){
552 while ($attrs= $ldap->fetch()){
554 /* Add 0 entry for development */
555 if(count($this->data['SERVERS']['FON']) == 0){
556 $this->data['SERVERS']['FON'][0]= array(
557 'DN' => $attrs['dn'],
558 'SERVER' => $attrs['cn'][0],
559 'LOGIN' => $attrs['goFonAdmin'][0],
560 'PASSWORD' => $attrs['goFonPassword'][0],
561 'DB' => "gophone",
562 'SIP_TABLE' => "sip_users",
563 'EXT_TABLE' => "extensions",
564 'VOICE_TABLE' => "voicemail_users",
565 'QUEUE_TABLE' => "queues",
566 'QUEUE_MEMBER_TABLE' => "queue_members");
567 }
569 /* Add entry with 'dn' as index */
570 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
571 'DN' => $attrs['dn'],
572 'SERVER' => $attrs['cn'][0],
573 'LOGIN' => $attrs['goFonAdmin'][0],
574 'PASSWORD' => $attrs['goFonPassword'][0],
575 'DB' => "gophone",
576 'SIP_TABLE' => "sip_users",
577 'EXT_TABLE' => "extensions",
578 'VOICE_TABLE' => "voicemail_users",
579 'QUEUE_TABLE' => "queues",
580 'QUEUE_MEMBER_TABLE' => "queue_members");
581 }
582 }
585 /* Get glpi server */
586 $ldap->cd ($this->current['BASE']);
587 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
588 if ($ldap->count()){
589 $attrs= $ldap->fetch();
590 if(!isset($attrs['goGlpiPassword'])){
591 $attrs['goGlpiPassword'][0] ="";
592 }
593 $this->data['SERVERS']['GLPI']= array(
594 'SERVER' => $attrs['cn'][0],
595 'LOGIN' => $attrs['goGlpiAdmin'][0],
596 'PASSWORD' => $attrs['goGlpiPassword'][0],
597 'DB' => $attrs['goGlpiDatabase'][0]);
598 }
601 /* Get logdb server */
602 $ldap->cd ($this->current['BASE']);
603 $ldap->search ("(objectClass=goLogDBServer)");
604 if ($ldap->count()){
605 $attrs= $ldap->fetch();
606 if(!isset($attrs['gosaLogDB'][0])){
607 $attrs['gosaLogDB'][0] = "gomon";
608 }
609 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
610 'LOGIN' => $attrs['goLogAdmin'][0],
611 'DB' => $attrs['gosaLogDB'][0],
612 'PASSWORD' => $attrs['goLogPassword'][0]);
613 }
616 /* GOsa logging databases */
617 $ldap->cd ($this->current['BASE']);
618 $ldap->search ("(objectClass=gosaLogServer)");
619 if ($ldap->count()){
620 while($attrs= $ldap->fetch()){
621 $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]=
622 array(
623 'DN' => $attrs['dn'],
624 'USER' => $attrs['goLogDBUser'][0],
625 'DB' => $attrs['goLogDB'][0],
626 'PWD' => $attrs['goLogDBPassword'][0]);
627 }
628 }
631 /* Get NFS server lists */
632 $tmp= array("default");
633 $tmp2= array("default");
634 $ldap->cd ($this->current['BASE']);
635 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
636 while ($attrs= $ldap->fetch()){
637 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
638 if(preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
639 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
640 $tmp[]= $attrs["cn"][0].":$path";
641 }
642 if(preg_match('/^[^|]+\|[^|]+\|NBD\|.*$/', $attrs["goExportEntry"][$i])){
643 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
644 $tmp2[]= $attrs["cn"][0].":$path";
645 }
646 }
647 }
648 $this->data['SERVERS']['NFS']= $tmp;
649 $this->data['SERVERS']['NBD']= $tmp2;
651 /* Load Terminalservers */
652 $ldap->cd ($this->current['BASE']);
653 $ldap->search ("(objectClass=goTerminalServer)",array("cn","gotoSessionType"));
654 $this->data['SERVERS']['TERMINAL']= array();
655 $this->data['SERVERS']['TERMINAL'][]= "default";
656 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'] = array();
659 while ($attrs= $ldap->fetch()){
660 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
661 if(isset( $attrs["gotoSessionType"]['count'])){
662 for($i =0 ; $i < $attrs["gotoSessionType"]['count'] ; $i++){
663 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'][$attrs["cn"][0]][] = $attrs["gotoSessionType"][$i];
664 }
665 }
666 }
668 /* Ldap Server
669 */
670 $this->data['SERVERS']['LDAP']= array();
671 $ldap->cd ($this->current['BASE']);
672 $ldap->search ("(&(objectClass=goLdapServer)(goLdapBase=*))");
673 while ($attrs= $ldap->fetch()){
674 $this->data['SERVERS']['LDAP'][$attrs['dn']] = $attrs;
675 }
677 /* Get misc server lists */
678 $this->data['SERVERS']['SYSLOG']= array("default");
679 $this->data['SERVERS']['NTP']= array("default");
680 $ldap->cd ($this->current['BASE']);
681 $ldap->search ("(objectClass=goNtpServer)");
682 while ($attrs= $ldap->fetch()){
683 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
684 }
685 $ldap->cd ($this->current['BASE']);
686 $ldap->search ("(objectClass=goSyslogServer)");
687 while ($attrs= $ldap->fetch()){
688 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
689 }
691 /* Get samba servers from LDAP, in case of samba3 */
692 $this->data['SERVERS']['SAMBA']= array();
693 $ldap->cd ($this->current['BASE']);
694 $ldap->search ("(objectClass=sambaDomain)");
695 while ($attrs= $ldap->fetch()){
696 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
697 if(isset($attrs["sambaSID"][0])){
698 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0];
699 }
700 if(isset($attrs["sambaAlgorithmicRidBase"][0])){
701 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
702 }
703 }
705 /* If no samba servers are found, look for configured sid/ridbase */
706 if (count($this->data['SERVERS']['SAMBA']) == 0){
707 $sambaSID = $this->get_cfg_value("core","sambaSID");
708 $sambaRIDBase = $this->get_cfg_value("core","sambaRidBase");
709 if (!isset($sambaSID) || !isset($sambaRIDBase)){
710 msg_dialog::display(_("Configuration error"),
711 _("sambaSID and/or sambaRidBase missing in the configuration!"), ERROR_DIALOG);
712 } else {
713 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
714 "SID" => $sambaSID ,
715 "RIDBASE" => $sambaRIDBase);
716 }
717 }
719 }
722 function get_departments($ignore_dn= "")
723 {
724 global $config;
726 /* Initialize result hash */
727 $result= array();
728 $administrative= array();
729 $result['/']= $this->current['BASE'];
730 $this->tdepartments= array();
732 /* Get all department types from department Management, to be able detect the department type.
733 -It is possible that differnty department types have the same name,
734 in this case we have to mark the department name to be able to differentiate.
735 (e.g l=Name or o=Name)
736 */
737 $types = departmentManagement::get_support_departments();
739 /* Create a list of attributes to fetch */
740 $ldap_values = array("objectClass","gosaUnitTag", "description");
741 $filter = "";
742 foreach($types as $type){
743 $ldap_values[] = $type['ATTR'];
744 $filter .= "(objectClass=".$type['OC'].")";
745 }
746 $filter = "(&(objectClass=gosaDepartment)(|".$filter."))";
748 /* Get list of department objects */
749 $ldap= $this->get_ldap_link();
750 $ldap->cd ($this->current['BASE']);
751 $ldap->search ($filter, $ldap_values);
752 while ($attrs= $ldap->fetch()){
754 /* Detect department type */
755 $type_data = array();
756 foreach($types as $t => $data){
757 if(in_array_strict($data['OC'],$attrs['objectClass'])){
758 $type_data = $data;
759 break;
760 }
761 }
763 /* Unknown department type -> skip */
764 if(!count($type_data)) continue;
766 $dn= $ldap->getDN();
767 $this->tdepartments[$dn]= "";
768 $this->department_info[$dn]= array("img" => $type_data['IMG'],
769 "description" => isset($attrs['description'][0])?$attrs['description'][0]:"",
770 "name" => $attrs[$type_data['ATTR']][0]);
772 /* Save administrative departments */
773 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
774 isset($attrs['gosaUnitTag'][0])){
775 $administrative[$dn]= $attrs['gosaUnitTag'][0];
776 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
777 }
779 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
780 isset($attrs['gosaUnitTag'][0])){
781 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
782 }
784 if ($dn == $ignore_dn){
785 continue;
786 }
787 $c_dn = convert_department_dn($dn)." (".$type_data['ATTR'].")";
789 /* Only assign non-root departments */
790 if ($dn != $result['/']){
791 $result[$c_dn]= $dn;
792 }
793 }
795 $this->adepartments= $administrative;
796 $this->departments= $result;
797 }
800 function make_idepartments($max_size= 28)
801 {
802 global $config;
803 $base = $config->current['BASE'];
804 $qbase = preg_quote($base, '/');
805 $utags= isset($config->current['HONOURUNITTAGS']) && preg_match('/true/i', $config->current['HONOURUNITTAGS']);
807 $arr = array();
808 $ui= get_userinfo();
810 $this->idepartments= array();
812 /* Create multidimensional array, with all departments. */
813 foreach ($this->departments as $key => $val){
815 /* When using strict_units, filter non relevant parts */
816 if ($utags){
817 if ($ui->gosaUnitTag != '' && isset($this->tdepartments[$val]) &&
818 $this->tdepartments[$val] != $ui->gosaUnitTag){
820 #TODO: link with strict*
821 #continue;
822 }
823 }
825 /* Split dn into single department pieces */
826 $elements = array_reverse(explode(',',preg_replace("/$qbase$/",'',$val)));
828 /* Add last ou element of current dn to our array */
829 $last = &$arr;
830 foreach($elements as $key => $ele){
832 /* skip empty */
833 if(empty($ele)) continue;
835 /* Extract department name */
836 $elestr = trim(preg_replace('/^[^=]*+=/','', $ele),',');
837 $nameA = trim(preg_replace('/=.*$/','', $ele),',');
838 if($nameA != 'ou'){
839 $nameA = " ($nameA)";
840 }else{
841 $nameA = '';
842 }
844 /* Add to array */
845 if($key == (count($elements)-1)){
846 $last[$elestr.$nameA]['ENTRY'] = $val;
847 }
849 /* Set next array appending position */
850 $last = &$last[$elestr.$nameA]['SUB'];
851 }
852 }
855 /* Add base entry */
856 $ret['/']['ENTRY'] = $base;
857 $ret['/']['SUB'] = $arr;
858 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
859 }
862 /* Creates display friendly output from make_idepartments */
863 function generateDepartmentArray($arr,$depth = -1,$max_size = 256)
864 {
865 $ret = array();
866 $depth ++;
868 /* Walk through array */
869 ksort($arr);
870 foreach($arr as $name => $entries){
872 /* If this department is the last in the current tree position
873 * remove it, to avoid generating output for it */
874 if(count($entries['SUB'])==0){
875 unset($entries['SUB']);
876 }
878 /* Fix name, if it contains a replace tag */
879 $name= preg_replace('/\\\\,/', ',', LDAP::fix($name));
881 /* Check if current name is too long, then cut it */
882 if(mb_strlen($name, 'UTF-8')> $max_size){
883 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
884 }
886 /* Append the name to the list */
887 if(isset($entries['ENTRY'])){
888 $a = "";
889 for($i = 0 ; $i < $depth ; $i ++){
890 $a.=".";
891 }
892 $ret[$entries['ENTRY']]=$a." ".$name;
893 }
895 /* recursive add of subdepartments */
896 if(isset($entries['SUB'])){
897 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
898 }
899 }
901 return($ret);
902 }
904 /*! \brief Get all available shares defined in the current LDAP
905 *
906 * This function returns all available Shares defined in this ldap
907 *
908 * \param boolean listboxEntry If set to TRUE, only name and path are
909 * attached to the array. If FALSE, the whole entry will be parsed an atached to the result.
910 * \return array
911 */
912 function getShareList($listboxEntry = false)
913 {
914 $tmp = get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",get_ou("servgeneric", "serverRDN"),
915 $this->current['BASE'],array("goExportEntry","cn"), GL_NONE);
916 $return =array();
917 foreach($tmp as $entry){
919 if(isset($entry['goExportEntry']['count'])){
920 unset($entry['goExportEntry']['count']);
921 }
922 if(isset($entry['goExportEntry'])){
923 foreach($entry['goExportEntry'] as $export){
924 $shareAttrs = explode("|",$export);
925 if($listboxEntry) {
926 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
927 }else{
928 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
929 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
930 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
931 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
932 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
933 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
934 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
935 }
936 }
937 }
938 }
939 return($return);
940 }
943 /*! \brief Return al available share servers
944 *
945 * This function returns all available ShareServers.
946 *
947 * \return array
948 * */
949 function getShareServerList()
950 {
951 global $config;
952 $return = array();
953 $ui = get_userinfo();
954 $base = $config->current['BASE'];
955 $res= get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server",
956 get_ou("servgeneric", "serverRDN"), $base,array("goExportEntry","cn"),GL_NONE | GL_NO_ACL_CHECK);
958 foreach($res as $entry){
960 $acl = $ui->get_permissions($entry['dn'],"server","");
961 if(isset($entry['goExportEntry']['count'])){
962 unset($entry['goExportEntry']['count']);
963 }
964 foreach($entry['goExportEntry'] as $share){
965 $a_share = explode("|",$share);
966 $sharename = $a_share[0];
967 $data= array();
968 $data['NAME'] = $sharename;
969 $data['ACL'] = $acl;
970 $data['SERVER'] = $entry['cn']['0'];
971 $data['SHARE'] = $sharename;
972 $data['DISPLAY']= $entry['cn'][0]." [".$sharename."]";
973 $return[$entry['cn'][0]."|".$sharename] = $data;
974 }
975 }
976 return($return);
977 }
980 /*! \brief Checks if there's a bool property set in the configuration.
981 *
982 * The function checks, weither the specified bool value is set to a true
983 * value in the configuration file.
984 *
985 * Example usage:
986 * \code
987 * if ($this->config->boolValueIsTrue("core", "copyPaste")) {
988 * echo "Copy Paste Handling is enabled";
989 * }
990 * \endcode
991 *
992 * \param string 'class' The properties class. e.g. 'core','user','sudo',...
993 * \param string 'value' Key in the given section, which is subject to check
994 *
995 *
996 * */
997 function boolValueIsTrue($class, $name)
998 {
999 return(preg_match("/true/i", $this->get_cfg_value($class,$name)));
1000 }
1003 function __search(&$arr, $name, $return)
1004 {
1005 $return= strtoupper($return);
1006 if (is_array($arr)){
1007 foreach ($arr as &$a){
1008 if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
1009 return(isset($a[$return])?$a[$return]:"");
1010 } else {
1011 $res= $this->__search ($a, $name, $return);
1012 if ($res != ""){
1013 return $res;
1014 }
1015 }
1016 }
1017 }
1018 return ("");
1019 }
1022 /*! Outdated - try to use pluginEnabled, boolValueIsTrue or get_cfg_value instead.
1023 *
1024 * (Search for a configuration setting in different categories
1025 *
1026 * Searches for the value of a given key in the configuration data.
1027 * Optionally the list of categories to search (tabs, main, locations) can
1028 * be specified. The first value that matches is returned.
1029 *
1030 * Example usage:
1031 * \code
1032 * $postcmd = $this->config->search(get_class($this), "POSTCOMMAND", array("menu", "tabs"));
1033 * \endcode
1034 * )
1035 *
1036 * */
1037 function search($class, $value, $categories= "")
1038 {
1039 if (is_array($categories)){
1040 foreach ($categories as $category){
1041 $res= $this->__search($this->data[strtoupper($category)], $class, $value);
1042 if ($res != ""){
1043 return $res;
1044 }
1045 }
1046 } else {
1047 if ($categories == "") {
1048 return $this->__search($this->data, $class, $value);
1049 } else {
1050 return $this->__search($this->data[strtoupper($categories)], $class, $value);
1051 }
1052 }
1054 return ("");
1055 }
1058 /*! \brief Check whether a plugin is activated or not
1059 */
1060 function pluginEnabled($class){
1061 $tmp = $this->search($class, "CLASS",array('menu','tabs'));
1062 return(!empty($tmp));
1063 }
1066 /*! \brief Get a configuration value from the config
1067 *
1068 * This returns a configuration value from the config. It either
1069 * uses the data of the current location ($this->current),
1070 * if it contains the value (e.g. current['BASE']) or otherwise
1071 * uses the data from the main configuration section.
1072 *
1073 * If no value is found and an optional default has been specified,
1074 * then the default is returned.
1075 *
1076 * \param string 'name' the configuration key (case-insensitive)
1077 * \param string 'default' a default that is returned, if no value is found
1078 *
1079 *
1080 */
1081 function get_cfg_value($class,$name, $default= NULL)
1082 {
1083 // The default parameter is deprecated
1084 if($default != NULL){
1085 # trigger_error("Third parameter 'default' is deprecated for function 'get_cfg_value'!");
1086 }
1088 // Return the matching property value if it exists.
1089 if($this->configRegistry->propertyExists($class,$name)){
1090 return($this->configRegistry->getPropertyValue($class,$name));
1091 }
1093 // Show a warning in the syslog if there is an undefined property requested.
1094 if($this->configRegistry->propertyInitializationComplete() &&
1095 "{$class}::{$name}" != 'core::config' && // <--- This on is never set, only in gosa.conf.
1096 "{$class}::{$name}" != 'core::logging'){ // <--- This one may cause endless recursions in class_log.inc
1097 new log("debug","","Unconfigured property: '{$class}::{$name}'",array(),'');
1098 }
1100 // Try to find the property in the config file directly.
1101 $name= strtoupper($name);
1102 if (isset($this->current[$name])) return ($this->current[$name]);
1103 if (isset($this->data["MAIN"][$name])) return ($this->data["MAIN"][$name]);
1104 return ("");
1105 }
1108 /*! \brief Check if current configuration version matches the GOsa version
1109 *
1110 * This function checks if the configuration file version matches the
1111 * version of the gosa version, by comparing it with the configuration
1112 * file version of the example gosa.conf that comes with GOsa.
1113 * If a version mismatch occurs an error is triggered.
1114 * */
1115 function check_config_version()
1116 {
1117 /* Skip check, if we've already mentioned the mismatch
1118 */
1119 if(session::global_is_set("LastChecked") && session::global_get("LastChecked") == $this->config_version) return;
1121 /* Remember last checked version
1122 */
1123 session::global_set("LastChecked",$this->config_version);
1125 $current = md5(file_get_contents(CONFIG_TEMPLATE_DIR."/gosa.conf"));
1127 /* Check contributed config version and current config version.
1128 */
1129 if(($this->config_version == "NOT SET") || ($this->config_version != $current && !empty($this->config_version))){
1130 msg_dialog::display(_("Configuration"),_("The configuration file you are using is outdated. Please move the GOsa configuration file away to run the GOsa setup again."));
1131 }
1132 }
1135 /*! \brief Check if session lifetime matches session.gc_maxlifetime
1136 *
1137 * On debian systems the session files are deleted with
1138 * a cronjob, which detects all files older than specified
1139 * in php.ini:'session.gc_maxlifetime' and removes them.
1140 * This function checks if the gosa.conf value matches the range
1141 * defined by session.gc_maxlifetime.
1142 *
1143 * \return boolean TRUE or FALSE depending on weither the settings match
1144 * or not. If SESSIONLIFETIME is not configured in GOsa it always returns
1145 * TRUE.
1146 */
1147 function check_session_lifetime()
1148 {
1149 if(isset($this->data['MAIN']['SESSIONLIFETIME'])){
1150 $cfg_lifetime = $this->data['MAIN']['SESSIONLIFETIME'];
1151 $ini_lifetime = ini_get('session.gc_maxlifetime');
1152 $deb_system = file_exists('/etc/debian_version');
1153 return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));
1154 }else{
1155 return(TRUE);
1156 }
1157 }
1159 /* Returns true if snapshots are enabled, and false if it is disalbed
1160 There will also be some errors psoted, if the configuration failed */
1161 function snapshotEnabled()
1162 {
1163 if($this->get_cfg_value("core","enableSnapshots") == "true"){
1165 /* Check if the snapshot_base is defined */
1166 if ($this->get_cfg_value("core","snapshotBase") == ""){
1168 /* Send message if not done already */
1169 if(!session::is_set("snapshotFailMessageSend")){
1170 session::set("snapshotFailMessageSend",TRUE);
1171 msg_dialog::display(_("Configuration error"),
1172 sprintf(_("The snapshot functionality is enabled, but the required variable %s is not set."),
1173 bold("snapshotBase")), ERROR_DIALOG);
1174 }
1175 return(FALSE);
1176 }
1178 /* Check if the snapshot_base is defined */
1179 if (!is_callable("gzcompress")){
1181 /* Send message if not done already */
1182 if(!session::is_set("snapshotFailMessageSend")){
1183 session::set("snapshotFailMessageSend",TRUE);
1184 msg_dialog::display(_("Configuration error"),
1185 sprintf(_("The snapshot functionality is enabled, but the required compression module is missing. Please install %s."), bold("php5-zip / php5-gzip")), ERROR_DIALOG);
1186 }
1187 return(FALSE);
1188 }
1190 /* check if there are special server configurations for snapshots */
1191 if ($this->get_cfg_value("core","snapshotURI") != ""){
1193 /* check if all required vars are available to create a new ldap connection */
1194 $missing = "";
1195 foreach(array("snapshotURI","snapshotAdminDn","snapshotAdminPassword","snapshotBase") as $var){
1196 if($this->get_cfg_value("core",$var) == ""){
1197 $missing .= $var." ";
1199 /* Send message if not done already */
1200 if(!session::is_set("snapshotFailMessageSend")){
1201 session::set("snapshotFailMessageSend",TRUE);
1202 msg_dialog::display(_("Configuration error"),
1203 sprintf(_("The snapshot functionality is enabled, but the required variable %s is not set."),
1204 bold($missing)), ERROR_DIALOG);
1205 }
1206 return(FALSE);
1207 }
1208 }
1209 }
1210 return(TRUE);
1211 }
1212 return(FALSE);
1213 }
1215 }
1217 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1218 ?>