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