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 $this->configRegistry->reload();
455 /* Only perform actions if current is set */
456 if ($this->current === NULL){
457 return;
458 }
460 /* Fill imap servers */
461 $ldap= $this->get_ldap_link();
462 $ldap->cd ($this->current['BASE']);
464 /* Search mailMethod konfiguration in main section too
465 */
466 $tmp = $this->get_cfg_value("core","mailMethod");
467 if ($tmp == ""){
468 $ldap->search ("(objectClass=goMailServer)", array('cn'));
469 $this->data['SERVERS']['IMAP']= array();
470 while ($attrs= $ldap->fetch()){
471 $name= $attrs['cn'][0];
472 $this->data['SERVERS']['IMAP'][$name]=
473 array(
474 "server_dn" => $attrs['dn'],
475 "connect" => "",
476 "admin" => "",
477 "password" => "",
478 "sieve_server"=> "",
479 "sieve_option"=> "",
480 "sieve_port" => "");
481 }
482 } else {
483 $ldap->search ("(&(objectClass=goImapServer)(goImapSieveServer=*))",
484 array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
485 'goImapSieveServer', 'goImapSievePort'));
487 $this->data['SERVERS']['IMAP']= array();
489 while ($attrs= $ldap->fetch()){
491 /* Check if the given goImapSieveServer is in the new style "{cn:port/option}"
492 or the old style just "cn".
493 */
494 if(preg_match("/\{/",$attrs['goImapSieveServer'][0])){
495 $sieve_server = preg_replace("/^\{([^:]*).*$/","\\1",$attrs['goImapSieveServer'][0]);
496 $sieve_option = preg_replace("/^[^:]*[^\/]*+\/(.*)\}$/","\\1",$attrs['goImapSieveServer'][0]);
497 }else{
498 $sieve_server = $attrs['goImapSieveServer'][0];
499 $sieve_option = "";
500 }
502 $pwd = $attrs['goImapPassword'][0];
503 $imap_admin = $attrs['goImapAdmin'][0];
504 $imap_connect = $attrs['goImapConnect'][0];
505 $imap_server = $attrs['goImapName'][0];
506 $sieve_port = $attrs['goImapSievePort'][0];
508 $this->data['SERVERS']['IMAP'][$imap_server]=
509 array(
510 "server_dn" => $attrs['dn'],
511 "connect" => $imap_connect,
512 "admin" => $imap_admin,
513 "password" => $pwd,
514 "sieve_server"=> $sieve_server,
515 "sieve_option"=> $sieve_option,
516 "sieve_port" => $sieve_port);
517 }
518 }
520 /* Get kerberos server. FIXME: only one is supported currently */
521 $ldap->cd ($this->current['BASE']);
522 $ldap->search ("(&(goKrbRealm=*)(goKrbAdmin=*)(objectClass=goKrbServer))");
523 if ($ldap->count()){
524 $attrs= $ldap->fetch();
525 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
526 'REALM' => $attrs['goKrbRealm'][0],
527 'ADMIN' => $attrs['goKrbAdmin'][0]);
528 }
530 /* Get cups server. FIXME: only one is supported currently */
531 $ldap->cd ($this->current['BASE']);
532 $ldap->search ("(objectClass=goCupsServer)");
533 if ($ldap->count()){
534 $attrs= $ldap->fetch();
535 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
536 }
538 /* Get fax server. FIXME: only one is supported currently */
539 $ldap->cd ($this->current['BASE']);
540 $ldap->search ("(objectClass=goFaxServer)");
541 if ($ldap->count()){
542 $attrs= $ldap->fetch();
543 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
544 'LOGIN' => $attrs['goFaxAdmin'][0],
545 'PASSWORD' => $attrs['goFaxPassword'][0]);
546 }
549 /* Get asterisk servers */
550 $ldap->cd ($this->current['BASE']);
551 $ldap->search ("(objectClass=goFonServer)");
552 $this->data['SERVERS']['FON']= array();
553 if ($ldap->count()){
554 while ($attrs= $ldap->fetch()){
556 /* Add 0 entry for development */
557 if(count($this->data['SERVERS']['FON']) == 0){
558 $this->data['SERVERS']['FON'][0]= array(
559 'DN' => $attrs['dn'],
560 'SERVER' => $attrs['cn'][0],
561 'LOGIN' => $attrs['goFonAdmin'][0],
562 'PASSWORD' => $attrs['goFonPassword'][0],
563 'DB' => "gophone",
564 'SIP_TABLE' => "sip_users",
565 'EXT_TABLE' => "extensions",
566 'VOICE_TABLE' => "voicemail_users",
567 'QUEUE_TABLE' => "queues",
568 'QUEUE_MEMBER_TABLE' => "queue_members");
569 }
571 /* Add entry with 'dn' as index */
572 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
573 'DN' => $attrs['dn'],
574 'SERVER' => $attrs['cn'][0],
575 'LOGIN' => $attrs['goFonAdmin'][0],
576 'PASSWORD' => $attrs['goFonPassword'][0],
577 'DB' => "gophone",
578 'SIP_TABLE' => "sip_users",
579 'EXT_TABLE' => "extensions",
580 'VOICE_TABLE' => "voicemail_users",
581 'QUEUE_TABLE' => "queues",
582 'QUEUE_MEMBER_TABLE' => "queue_members");
583 }
584 }
587 /* Get glpi server */
588 $ldap->cd ($this->current['BASE']);
589 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
590 if ($ldap->count()){
591 $attrs= $ldap->fetch();
592 if(!isset($attrs['goGlpiPassword'])){
593 $attrs['goGlpiPassword'][0] ="";
594 }
595 $this->data['SERVERS']['GLPI']= array(
596 'SERVER' => $attrs['cn'][0],
597 'LOGIN' => $attrs['goGlpiAdmin'][0],
598 'PASSWORD' => $attrs['goGlpiPassword'][0],
599 'DB' => $attrs['goGlpiDatabase'][0]);
600 }
603 /* Get logdb server */
604 $ldap->cd ($this->current['BASE']);
605 $ldap->search ("(objectClass=goLogDBServer)");
606 if ($ldap->count()){
607 $attrs= $ldap->fetch();
608 if(!isset($attrs['gosaLogDB'][0])){
609 $attrs['gosaLogDB'][0] = "gomon";
610 }
611 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
612 'LOGIN' => $attrs['goLogAdmin'][0],
613 'DB' => $attrs['gosaLogDB'][0],
614 'PASSWORD' => $attrs['goLogPassword'][0]);
615 }
618 /* GOsa logging databases */
619 $ldap->cd ($this->current['BASE']);
620 $ldap->search ("(objectClass=gosaLogServer)");
621 if ($ldap->count()){
622 while($attrs= $ldap->fetch()){
623 $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]=
624 array(
625 'DN' => $attrs['dn'],
626 'USER' => $attrs['goLogDBUser'][0],
627 'DB' => $attrs['goLogDB'][0],
628 'PWD' => $attrs['goLogDBPassword'][0]);
629 }
630 }
633 /* Get NFS server lists */
634 $tmp= array("default");
635 $tmp2= array("default");
636 $ldap->cd ($this->current['BASE']);
637 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
638 while ($attrs= $ldap->fetch()){
639 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
640 if(preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
641 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
642 $tmp[]= $attrs["cn"][0].":$path";
643 }
644 if(preg_match('/^[^|]+\|[^|]+\|NBD\|.*$/', $attrs["goExportEntry"][$i])){
645 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
646 $tmp2[]= $attrs["cn"][0].":$path";
647 }
648 }
649 }
650 $this->data['SERVERS']['NFS']= $tmp;
651 $this->data['SERVERS']['NBD']= $tmp2;
653 /* Load Terminalservers */
654 $ldap->cd ($this->current['BASE']);
655 $ldap->search ("(objectClass=goTerminalServer)",array("cn","gotoSessionType"));
656 $this->data['SERVERS']['TERMINAL']= array();
657 $this->data['SERVERS']['TERMINAL'][]= "default";
658 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'] = array();
661 while ($attrs= $ldap->fetch()){
662 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
663 if(isset( $attrs["gotoSessionType"]['count'])){
664 for($i =0 ; $i < $attrs["gotoSessionType"]['count'] ; $i++){
665 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'][$attrs["cn"][0]][] = $attrs["gotoSessionType"][$i];
666 }
667 }
668 }
670 /* Ldap Server
671 */
672 $this->data['SERVERS']['LDAP']= array();
673 $ldap->cd ($this->current['BASE']);
674 $ldap->search ("(&(objectClass=goLdapServer)(goLdapBase=*))");
675 while ($attrs= $ldap->fetch()){
676 $this->data['SERVERS']['LDAP'][$attrs['dn']] = $attrs;
677 }
679 /* Get misc server lists */
680 $this->data['SERVERS']['SYSLOG']= array("default");
681 $this->data['SERVERS']['NTP']= array("default");
682 $ldap->cd ($this->current['BASE']);
683 $ldap->search ("(objectClass=goNtpServer)");
684 while ($attrs= $ldap->fetch()){
685 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
686 }
687 $ldap->cd ($this->current['BASE']);
688 $ldap->search ("(objectClass=goSyslogServer)");
689 while ($attrs= $ldap->fetch()){
690 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
691 }
693 /* Get samba servers from LDAP, in case of samba3 */
694 $this->data['SERVERS']['SAMBA']= array();
695 $ldap->cd ($this->current['BASE']);
696 $ldap->search ("(objectClass=sambaDomain)");
697 while ($attrs= $ldap->fetch()){
698 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
699 if(isset($attrs["sambaSID"][0])){
700 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0];
701 }
702 if(isset($attrs["sambaAlgorithmicRidBase"][0])){
703 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
704 }
705 }
707 /* If no samba servers are found, look for configured sid/ridbase */
708 if (count($this->data['SERVERS']['SAMBA']) == 0){
709 $sambaSID = $this->get_cfg_value("core","sambaSID");
710 $sambaRIDBase = $this->get_cfg_value("core","sambaRidBase");
711 if (!isset($sambaSID) || !isset($sambaRIDBase)){
712 msg_dialog::display(_("Configuration error"),
713 _("sambaSID and/or sambaRidBase missing in the configuration!"), ERROR_DIALOG);
714 } else {
715 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
716 "SID" => $sambaSID ,
717 "RIDBASE" => $sambaRIDBase);
718 }
719 }
721 }
724 function get_departments($ignore_dn= "")
725 {
726 global $config;
728 /* Initialize result hash */
729 $result= array();
730 $administrative= array();
731 $result['/']= $this->current['BASE'];
732 $this->tdepartments= array();
734 /* Get all department types from department Management, to be able detect the department type.
735 -It is possible that differnty department types have the same name,
736 in this case we have to mark the department name to be able to differentiate.
737 (e.g l=Name or o=Name)
738 */
739 $types = departmentManagement::get_support_departments();
741 /* Create a list of attributes to fetch */
742 $ldap_values = array("objectClass","gosaUnitTag", "description");
743 $filter = "";
744 foreach($types as $type){
745 $ldap_values[] = $type['ATTR'];
746 $filter .= "(objectClass=".$type['OC'].")";
747 }
748 $filter = "(&(objectClass=gosaDepartment)(|".$filter."))";
750 /* Get list of department objects */
751 $ldap= $this->get_ldap_link();
752 $ldap->cd ($this->current['BASE']);
753 $ldap->search ($filter, $ldap_values);
754 while ($attrs= $ldap->fetch()){
756 /* Detect department type */
757 $type_data = array();
758 foreach($types as $t => $data){
759 if(in_array_strict($data['OC'],$attrs['objectClass'])){
760 $type_data = $data;
761 break;
762 }
763 }
765 /* Unknown department type -> skip */
766 if(!count($type_data)) continue;
768 $dn= $ldap->getDN();
769 $this->tdepartments[$dn]= "";
770 $this->department_info[$dn]= array("img" => $type_data['IMG'],
771 "description" => isset($attrs['description'][0])?$attrs['description'][0]:"",
772 "name" => $attrs[$type_data['ATTR']][0]);
774 /* Save administrative departments */
775 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
776 isset($attrs['gosaUnitTag'][0])){
777 $administrative[$dn]= $attrs['gosaUnitTag'][0];
778 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
779 }
781 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
782 isset($attrs['gosaUnitTag'][0])){
783 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
784 }
786 if ($dn == $ignore_dn){
787 continue;
788 }
789 $c_dn = convert_department_dn($dn)." (".$type_data['ATTR'].")";
791 /* Only assign non-root departments */
792 if ($dn != $result['/']){
793 $result[$c_dn]= $dn;
794 }
795 }
797 $this->adepartments= $administrative;
798 $this->departments= $result;
799 }
802 function make_idepartments($max_size= 28)
803 {
804 global $config;
805 $base = $config->current['BASE'];
806 $qbase = preg_quote($base, '/');
807 $utags= isset($config->current['HONOURUNITTAGS']) && preg_match('/true/i', $config->current['HONOURUNITTAGS']);
809 $arr = array();
810 $ui= get_userinfo();
812 $this->idepartments= array();
814 /* Create multidimensional array, with all departments. */
815 foreach ($this->departments as $key => $val){
817 /* When using strict_units, filter non relevant parts */
818 if ($utags){
819 if ($ui->gosaUnitTag != '' && isset($this->tdepartments[$val]) &&
820 $this->tdepartments[$val] != $ui->gosaUnitTag){
822 #TODO: link with strict*
823 #continue;
824 }
825 }
827 /* Split dn into single department pieces */
828 $elements = array_reverse(explode(',',preg_replace("/$qbase$/",'',$val)));
830 /* Add last ou element of current dn to our array */
831 $last = &$arr;
832 foreach($elements as $key => $ele){
834 /* skip empty */
835 if(empty($ele)) continue;
837 /* Extract department name */
838 $elestr = trim(preg_replace('/^[^=]*+=/','', $ele),',');
839 $nameA = trim(preg_replace('/=.*$/','', $ele),',');
840 if($nameA != 'ou'){
841 $nameA = " ($nameA)";
842 }else{
843 $nameA = '';
844 }
846 /* Add to array */
847 if($key == (count($elements)-1)){
848 $last[$elestr.$nameA]['ENTRY'] = $val;
849 }
851 /* Set next array appending position */
852 $last = &$last[$elestr.$nameA]['SUB'];
853 }
854 }
857 /* Add base entry */
858 $ret['/']['ENTRY'] = $base;
859 $ret['/']['SUB'] = $arr;
860 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
861 }
864 /* Creates display friendly output from make_idepartments */
865 function generateDepartmentArray($arr,$depth = -1,$max_size = 256)
866 {
867 $ret = array();
868 $depth ++;
870 /* Walk through array */
871 ksort($arr);
872 foreach($arr as $name => $entries){
874 /* If this department is the last in the current tree position
875 * remove it, to avoid generating output for it */
876 if(count($entries['SUB'])==0){
877 unset($entries['SUB']);
878 }
880 /* Fix name, if it contains a replace tag */
881 $name= preg_replace('/\\\\,/', ',', LDAP::fix($name));
883 /* Check if current name is too long, then cut it */
884 if(mb_strlen($name, 'UTF-8')> $max_size){
885 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
886 }
888 /* Append the name to the list */
889 if(isset($entries['ENTRY'])){
890 $a = "";
891 for($i = 0 ; $i < $depth ; $i ++){
892 $a.=".";
893 }
894 $ret[$entries['ENTRY']]=$a." ".$name;
895 }
897 /* recursive add of subdepartments */
898 if(isset($entries['SUB'])){
899 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
900 }
901 }
903 return($ret);
904 }
906 /*! \brief Get all available shares defined in the current LDAP
907 *
908 * This function returns all available Shares defined in this ldap
909 *
910 * \param boolean listboxEntry If set to TRUE, only name and path are
911 * attached to the array. If FALSE, the whole entry will be parsed an atached to the result.
912 * \return array
913 */
914 function getShareList($listboxEntry = false)
915 {
916 $tmp = get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",get_ou("servgeneric", "serverRDN"),
917 $this->current['BASE'],array("goExportEntry","cn"), GL_NONE);
918 $return =array();
919 foreach($tmp as $entry){
921 if(isset($entry['goExportEntry']['count'])){
922 unset($entry['goExportEntry']['count']);
923 }
924 if(isset($entry['goExportEntry'])){
925 foreach($entry['goExportEntry'] as $export){
926 $shareAttrs = explode("|",$export);
927 if($listboxEntry) {
928 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
929 }else{
930 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
931 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
932 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
933 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
934 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
935 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
936 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
937 }
938 }
939 }
940 }
941 return($return);
942 }
945 /*! \brief Return al available share servers
946 *
947 * This function returns all available ShareServers.
948 *
949 * \return array
950 * */
951 function getShareServerList()
952 {
953 global $config;
954 $return = array();
955 $ui = get_userinfo();
956 $base = $config->current['BASE'];
957 $res= get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server",
958 get_ou("servgeneric", "serverRDN"), $base,array("goExportEntry","cn"),GL_NONE | GL_NO_ACL_CHECK);
960 foreach($res as $entry){
962 $acl = $ui->get_permissions($entry['dn'],"server","");
963 if(isset($entry['goExportEntry']['count'])){
964 unset($entry['goExportEntry']['count']);
965 }
966 foreach($entry['goExportEntry'] as $share){
967 $a_share = explode("|",$share);
968 $sharename = $a_share[0];
969 $data= array();
970 $data['NAME'] = $sharename;
971 $data['ACL'] = $acl;
972 $data['SERVER'] = $entry['cn']['0'];
973 $data['SHARE'] = $sharename;
974 $data['DISPLAY']= $entry['cn'][0]." [".$sharename."]";
975 $return[$entry['cn'][0]."|".$sharename] = $data;
976 }
977 }
978 return($return);
979 }
982 /*! \brief Checks if there's a bool property set in the configuration.
983 *
984 * The function checks, weither the specified bool value is set to a true
985 * value in the configuration file.
986 *
987 * Example usage:
988 * \code
989 * if ($this->config->boolValueIsTrue("core", "copyPaste")) {
990 * echo "Copy Paste Handling is enabled";
991 * }
992 * \endcode
993 *
994 * \param string 'class' The properties class. e.g. 'core','user','sudo',...
995 * \param string 'value' Key in the given section, which is subject to check
996 *
997 *
998 * */
999 function boolValueIsTrue($class, $name)
1000 {
1001 return(preg_match("/true/i", $this->get_cfg_value($class,$name)));
1002 }
1005 function __search(&$arr, $name, $return)
1006 {
1007 $return= strtoupper($return);
1008 if (is_array($arr)){
1009 foreach ($arr as &$a){
1010 if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
1011 return(isset($a[$return])?$a[$return]:"");
1012 } else {
1013 $res= $this->__search ($a, $name, $return);
1014 if ($res != ""){
1015 return $res;
1016 }
1017 }
1018 }
1019 }
1020 return ("");
1021 }
1024 /*! Outdated - try to use pluginEnabled, boolValueIsTrue or get_cfg_value instead.
1025 *
1026 * (Search for a configuration setting in different categories
1027 *
1028 * Searches for the value of a given key in the configuration data.
1029 * Optionally the list of categories to search (tabs, main, locations) can
1030 * be specified. The first value that matches is returned.
1031 *
1032 * Example usage:
1033 * \code
1034 * $postcmd = $this->config->search(get_class($this), "POSTCOMMAND", array("menu", "tabs"));
1035 * \endcode
1036 * )
1037 *
1038 * */
1039 function search($class, $value, $categories= "")
1040 {
1041 if (is_array($categories)){
1042 foreach ($categories as $category){
1043 $res= $this->__search($this->data[strtoupper($category)], $class, $value);
1044 if ($res != ""){
1045 return $res;
1046 }
1047 }
1048 } else {
1049 if ($categories == "") {
1050 return $this->__search($this->data, $class, $value);
1051 } else {
1052 return $this->__search($this->data[strtoupper($categories)], $class, $value);
1053 }
1054 }
1056 return ("");
1057 }
1060 /*! \brief Check whether a plugin is activated or not
1061 */
1062 function pluginEnabled($class){
1063 $tmp = $this->search($class, "CLASS",array('menu','tabs'));
1064 return(!empty($tmp));
1065 }
1068 /*! \brief Get a configuration value from the config
1069 *
1070 * This returns a configuration value from the config. It either
1071 * uses the data of the current location ($this->current),
1072 * if it contains the value (e.g. current['BASE']) or otherwise
1073 * uses the data from the main configuration section.
1074 *
1075 * If no value is found and an optional default has been specified,
1076 * then the default is returned.
1077 *
1078 * \param string 'name' the configuration key (case-insensitive)
1079 * \param string 'default' a default that is returned, if no value is found
1080 *
1081 *
1082 */
1083 function get_cfg_value($class,$name, $default= NULL)
1084 {
1085 // The default parameter is deprecated
1086 if($default != NULL){
1087 # trigger_error("Third parameter 'default' is deprecated for function 'get_cfg_value'!");
1088 }
1090 // Return the matching property value if it exists.
1091 if($this->configRegistry->propertyExists($class,$name)){
1092 return($this->configRegistry->getPropertyValue($class,$name));
1093 }
1095 // Show a warning in the syslog if there is an undefined property requested.
1096 if($this->configRegistry->propertyInitializationComplete() &&
1097 "{$class}::{$name}" != 'core::config' && // <--- This on is never set, only in gosa.conf.
1098 "{$class}::{$name}" != 'core::logging'){ // <--- This one may cause endless recursions in class_log.inc
1099 new log("debug","","Unconfigured property: '{$class}::{$name}'",array(),'');
1100 }
1102 // Try to find the property in the config file directly.
1103 $name= strtoupper($name);
1104 if (isset($this->current[$name])) return ($this->current[$name]);
1105 if (isset($this->data["MAIN"][$name])) return ($this->data["MAIN"][$name]);
1106 return ("");
1107 }
1110 /*! \brief Check if current configuration version matches the GOsa version
1111 *
1112 * This function checks if the configuration file version matches the
1113 * version of the gosa version, by comparing it with the configuration
1114 * file version of the example gosa.conf that comes with GOsa.
1115 * If a version mismatch occurs an error is triggered.
1116 * */
1117 function check_config_version()
1118 {
1119 /* Skip check, if we've already mentioned the mismatch
1120 */
1121 if(session::global_is_set("LastChecked") && session::global_get("LastChecked") == $this->config_version) return;
1123 /* Remember last checked version
1124 */
1125 session::global_set("LastChecked",$this->config_version);
1127 $current = md5(file_get_contents(CONFIG_TEMPLATE_DIR."/gosa.conf"));
1129 /* Check contributed config version and current config version.
1130 */
1131 if(($this->config_version == "NOT SET") || ($this->config_version != $current && !empty($this->config_version))){
1132 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."));
1133 }
1134 }
1137 /*! \brief Check if session lifetime matches session.gc_maxlifetime
1138 *
1139 * On debian systems the session files are deleted with
1140 * a cronjob, which detects all files older than specified
1141 * in php.ini:'session.gc_maxlifetime' and removes them.
1142 * This function checks if the gosa.conf value matches the range
1143 * defined by session.gc_maxlifetime.
1144 *
1145 * \return boolean TRUE or FALSE depending on weither the settings match
1146 * or not. If SESSIONLIFETIME is not configured in GOsa it always returns
1147 * TRUE.
1148 */
1149 function check_session_lifetime()
1150 {
1151 if(isset($this->data['MAIN']['SESSIONLIFETIME'])){
1152 $cfg_lifetime = $this->data['MAIN']['SESSIONLIFETIME'];
1153 $ini_lifetime = ini_get('session.gc_maxlifetime');
1154 $deb_system = file_exists('/etc/debian_version');
1155 return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));
1156 }else{
1157 return(TRUE);
1158 }
1159 }
1161 /* Returns true if snapshots are enabled, and false if it is disalbed
1162 There will also be some errors psoted, if the configuration failed */
1163 function snapshotEnabled()
1164 {
1165 if($this->get_cfg_value("core","enableSnapshots") == "true"){
1167 /* Check if the snapshot_base is defined */
1168 if ($this->get_cfg_value("core","snapshotBase") == ""){
1170 /* Send message if not done already */
1171 if(!session::is_set("snapshotFailMessageSend")){
1172 session::set("snapshotFailMessageSend",TRUE);
1173 msg_dialog::display(_("Configuration error"),
1174 sprintf(_("The snapshot functionality is enabled, but the required variable %s is not set."),
1175 bold("snapshotBase")), ERROR_DIALOG);
1176 }
1177 return(FALSE);
1178 }
1180 /* Check if the snapshot_base is defined */
1181 if (!is_callable("gzcompress")){
1183 /* Send message if not done already */
1184 if(!session::is_set("snapshotFailMessageSend")){
1185 session::set("snapshotFailMessageSend",TRUE);
1186 msg_dialog::display(_("Configuration error"),
1187 sprintf(_("The snapshot functionality is enabled, but the required compression module is missing. Please install %s."), bold("php5-zip / php5-gzip")), ERROR_DIALOG);
1188 }
1189 return(FALSE);
1190 }
1192 /* check if there are special server configurations for snapshots */
1193 if ($this->get_cfg_value("core","snapshotURI") != ""){
1195 /* check if all required vars are available to create a new ldap connection */
1196 $missing = "";
1197 foreach(array("snapshotURI","snapshotAdminDn","snapshotAdminPassword","snapshotBase") as $var){
1198 if($this->get_cfg_value("core",$var) == ""){
1199 $missing .= $var." ";
1201 /* Send message if not done already */
1202 if(!session::is_set("snapshotFailMessageSend")){
1203 session::set("snapshotFailMessageSend",TRUE);
1204 msg_dialog::display(_("Configuration error"),
1205 sprintf(_("The snapshot functionality is enabled, but the required variable %s is not set."),
1206 bold($missing)), ERROR_DIALOG);
1207 }
1208 return(FALSE);
1209 }
1210 }
1211 }
1212 return(TRUE);
1213 }
1214 return(FALSE);
1215 }
1217 }
1219 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1220 ?>