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