2338ce7aac8ffd84a71e65bcbabd1b2f44218dc3
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 $filename = "";
64 var $last_modified = 0;
66 /*! \brief Class constructor of the config class
67 *
68 * \param string 'filename' path to the configuration file
69 * \param string 'basedir' base directory
70 *
71 * */
72 function config($filename, $basedir= "")
73 {
74 $this->parser = xml_parser_create();
75 $this->basedir= $basedir;
77 xml_set_object($this->parser, $this);
78 xml_set_element_handler($this->parser, "tag_open", "tag_close");
80 /* Parse config file directly? */
81 if ($filename != ""){
82 $this->parse($filename);
83 }
84 }
87 /*! \brief Check and reload the configuration
88 *
89 * This function checks if the configuration has changed, since it was
90 * read the last time and reloads it. It uses the file mtime to check
91 * weither the file changed or not.
92 *
93 * */
94 function check_and_reload()
95 {
96 global $ui;
98 /* Check if class_location.inc has changed, this is the case
99 if we have installed or removed plugins.
100 */
101 if(session::global_is_set("class_location.inc:timestamp")){
102 $tmp = stat("../include/class_location.inc");
103 if($tmp['mtime'] != session::global_get("class_location.inc:timestamp")){
104 session::global_un_set("plist");
105 }
106 }
107 $tmp = stat("../include/class_location.inc");
108 session::global_set("class_location.inc:timestamp",$tmp['mtime']);
110 if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
112 $this->config_found= FALSE;
113 $this->tags= array();
114 $this->level= 0;
115 $this->gpc= 0;
116 $this->section= "";
117 $this->currentLocation= "";
119 $this->parser = xml_parser_create();
120 xml_set_object($this->parser, $this);
121 xml_set_element_handler($this->parser, "tag_open", "tag_close");
122 $this->parse($this->filename);
123 $this->set_current($this->current['NAME']);
124 }
125 }
128 /*! \brief Parse the given configuration file
129 *
130 * Parses the configuration file and displays errors if there
131 * is something wrong with it.
132 *
133 * \param string 'filename' The filename of the configuration file.
134 * */
136 function parse($filename)
137 {
139 $this->data = array(
140 "TABS" => array(),
141 "LOCATIONS" => array(),
142 "MAIN" => array(),
143 "MENU" => array(),
144 "SERVICE" => array());
146 $this->last_modified = filemtime($filename);
147 $this->filename = $filename;
148 $fh= fopen($filename, "r");
149 $xmldata= fread($fh, 100000);
150 fclose($fh);
151 if(!xml_parse($this->parser, chop($xmldata))){
152 $msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
153 xml_error_string(xml_get_error_code($this->parser)),
154 xml_get_current_line_number($this->parser));
155 msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG);
156 exit;
157 }
158 }
160 function tag_open($parser, $tag, $attrs)
161 {
162 /* Save last and current tag for reference */
163 $this->tags[$this->level]= $tag;
164 $this->level++;
166 /* Trigger on CONF section */
167 if ($tag == 'CONF'){
168 $this->config_found= TRUE;
169 if(isset($attrs['CONFIGVERSION'])){
170 $this->config_version = $attrs['CONFIGVERSION'];
171 }
172 }
174 /* Return if we're not in config section */
175 if (!$this->config_found){
176 return;
177 }
179 /* yes/no to true/false and upper case TRUE to true and so on*/
180 foreach($attrs as $name => $value){
181 if(preg_match("/^(true|yes)$/i",$value)){
182 $attrs[$name] = "true";
183 }elseif(preg_match("/^(false|no)$/i",$value)){
184 $attrs[$name] = "false";
185 }
186 }
188 /* Look through attributes */
189 switch ($this->tags[$this->level-1]){
192 /* Handle tab section */
193 case 'TAB': $name= $this->tags[$this->level-2];
195 /* Create new array? */
196 if (!isset($this->data['TABS'][$name])){
197 $this->data['TABS'][$name]= array();
198 }
200 /* Add elements */
201 $this->data['TABS'][$name][]= $attrs;
202 break;
204 /* Handle location */
205 case 'LOCATION':
206 if ($this->tags[$this->level-2] == 'MAIN'){
207 $name= $attrs['NAME'];
208 $name = preg_replace("/[<>\"']/","",$name);
209 $attrs['NAME'] = $name;
210 $this->currentLocation= $name;
212 /* Add location elements */
213 $this->data['LOCATIONS'][$name]= $attrs;
214 }
215 break;
217 /* Handle referral tags */
218 case 'REFERRAL':
219 if ($this->tags[$this->level-2] == 'LOCATION'){
220 $url= $attrs['URI'];
221 $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
223 /* Add location elements */
224 if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
225 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
226 }
228 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
229 }
230 break;
232 /* Load main parameters */
233 case 'MAIN':
234 $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
235 break;
237 /* Load menu */
238 case 'SECTION':
239 if ($this->tags[$this->level-2] == 'MENU'){
240 $this->section= $attrs['NAME'];
241 $this->data['MENU'][$this->section]= array(); ;
242 }
243 break;
245 /* Inser plugins */
246 case 'PLUGIN':
247 if ($this->tags[$this->level-3] == 'MENU' &&
248 $this->tags[$this->level-2] == 'SECTION'){
250 $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
251 }
252 if ($this->tags[$this->level-2] == 'SERVICEMENU'){
253 $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
254 }
255 break;
256 }
257 }
259 function tag_close($parser, $tag)
260 {
261 /* Close config section */
262 if ($tag == 'CONF'){
263 $this->config_found= FALSE;
264 }
265 $this->level--;
266 }
269 function get_credentials($creds)
270 {
271 if (isset($_SERVER['HTTP_GOSA_KEY'])){
272 return (cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY']));
273 }
274 return ($creds);
275 }
278 /*! \brief Get a LDAP link object
279 *
280 * This function can be used to get an ldap object, which in turn can
281 * be used to query the LDAP. See the LDAP class for more information
282 * on how to use it.
283 *
284 * Example usage:
285 * \code
286 * $ldap = $this->config->get_ldap_link();
287 * \endcode
288 *
289 * \param boolean sizelimit Weither to impose a sizelimit on the LDAP object or not.
290 * Defaults to false. If set to true, the size limit in the configuration
291 * file will be used to set the option LDAP_OPT_SIZELIMIT.
292 * \return ldapMultiplexer object
293 */
294 function get_ldap_link($sizelimit= FALSE)
295 {
296 if($this->ldap === NULL || !is_resource($this->ldap->cid)){
298 /* Build new connection */
299 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
300 $this->current['ADMINDN'], $this->get_credentials($this->current['ADMINPASSWORD']));
302 /* Check for connection */
303 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
304 $smarty= get_smarty();
305 msg_dialog::display(_("LDAP error"), _("Cannot bind to LDAP. Please contact the system administrator."), FATAL_ERROR_DIALOG);
306 exit();
307 }
309 /* Move referrals */
310 if (!isset($this->current['REFERRAL'])){
311 $this->ldap->referrals= array();
312 } else {
313 $this->ldap->referrals= $this->current['REFERRAL'];
314 }
316 if (!session::global_is_set('size_limit')){
317 session::global_set('size_limit',$this->current['LDAPSIZELIMIT']);
318 session::global_set('size_ignore',$this->current['LDAPSIZEIGNORE']);
319 }
320 }
322 $obj = new ldapMultiplexer($this->ldap);
323 if ($sizelimit){
324 $obj->set_size_limit(session::global_get('size_limit'));
325 } else {
326 $obj->set_size_limit(0);
327 }
328 return($obj);
329 }
331 /*! \brief Set the current location
332 *
333 * \param string name the name of the location
334 */
335 function set_current($name)
336 {
337 $this->current= $this->data['LOCATIONS'][$name];
339 if (!isset($this->current['SAMBAVERSION'])){
340 $this->current['SAMBAVERSION']= 3;
341 }
342 if (!isset($this->current['USERRDN'])){
343 $this->current['USERRDN']= "ou=people";
344 }
345 if (!isset($this->current['GROUPRDN'])){
346 $this->current['GROUPS']= "ou=groups";
347 }
349 if (isset($this->current['INITIAL_BASE'])){
350 session::global_set('CurrentMainBase',$this->current['INITIAL_BASE']);
351 }
353 /* Remove possibly added ',' from end of group and people ou */
354 $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPRDN']);
355 $this->current['USERRDN'] = preg_replace("/,*$/","",$this->current['USERRDN']);
357 if (!isset($this->current['SAMBAMACHINEACCOUNTRDN'])){
358 $this->current['SAMBAMACHINEACCOUNTRDN']= "ou=winstations,ou=systems";
359 }
360 if (!isset($this->current['ACCOUNTPRIMARYATTRIBUTE'])){
361 $this->current['ACCOUNTPRIMARYATTRIBUTE']= "cn";
362 }
363 if (!isset($this->current['MINID'])){
364 $this->current['MINID']= 100;
365 }
366 if (!isset($this->current['LDAPSIZELIMIT'])){
367 $this->current['LDAPSIZELIMIT']= 200;
368 }
369 if (!isset($this->current['SIZEINGORE'])){
370 $this->current['LDAPSIZEIGNORE']= TRUE;
371 } else {
372 if (preg_match("/true/i", $this->current['LDAPSIZEIGNORE'])){
373 $this->current['LDAPSIZEIGNORE']= TRUE;
374 } else {
375 $this->current['LDAPSIZEIGNORE']= FALSE;
376 }
377 }
379 /* Sort referrals, if present */
380 if (isset ($this->current['REFERRAL'])){
381 $bases= array();
382 $servers= array();
383 foreach ($this->current['REFERRAL'] as $ref){
384 $server= preg_replace('%^(.*://[^/]+)/.*$%', '\\1', $ref['URI']);
385 $base= preg_replace('%^.*://[^/]+/(.*)$%', '\\1', $ref['URI']);
386 $bases[$base]= strlen($base);
387 $servers[$base]= $server;
388 }
389 asort($bases);
390 reset($bases);
391 }
393 /* SERVER not defined? Load the one with the shortest base */
394 if (!isset($this->current['SERVER'])){
395 $this->current['SERVER']= $servers[key($bases)];
396 }
398 /* BASE not defined? Load the one with the shortest base */
399 if (!isset($this->current['BASE'])){
400 $this->current['BASE']= key($bases);
401 }
403 /* Convert BASE to have escaped special characters */
404 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
406 /* Parse LDAP referral informations */
407 if (!isset($this->current['ADMINDN']) || !isset($this->current['ADMINPASSWORD'])){
408 $url= $this->current['SERVER'];
409 $referral= $this->current['REFERRAL'][$url];
410 $this->current['ADMINDN']= $referral['ADMINDN'];
411 $this->current['ADMINPASSWORD']= $referral['ADMINPASSWORD'];
412 }
414 /* Load server informations */
415 $this->load_servers();
416 }
419 /*! \brief Load server information from config/LDAP
420 *
421 * This function searches the LDAP for servers (e.g. goImapServer, goMailServer etc.)
422 * and stores information about them $this->data['SERVERS']. In the case of mailservers
423 * the main section of the configuration file is searched, too.
424 */
425 function load_servers ()
426 {
427 /* Only perform actions if current is set */
428 if ($this->current === NULL){
429 return;
430 }
432 /* Fill imap servers */
433 $ldap= $this->get_ldap_link();
434 $ldap->cd ($this->current['BASE']);
436 /* Search mailMethod konfiguration in main section too
437 */
438 $this->current['MAILMETHOD'] = $this->get_cfg_value("mailMethod","");
439 if (!isset($this->current['MAILMETHOD'])){
440 $this->current['MAILMETHOD']= "";
441 }
442 if ($this->current['MAILMETHOD'] == ""){
443 $ldap->search ("(objectClass=goMailServer)", array('cn'));
444 $this->data['SERVERS']['IMAP']= array();
445 while ($attrs= $ldap->fetch()){
446 $name= $attrs['cn'][0];
447 $this->data['SERVERS']['IMAP'][$name]=
448 array(
449 "server_dn" => $attrs['dn'],
450 "connect" => "",
451 "admin" => "",
452 "password" => "",
453 "sieve_server"=> "",
454 "sieve_option"=> "",
455 "sieve_port" => "");
456 }
457 } else {
458 $ldap->search ("(&(objectClass=goImapServer)(goImapSieveServer=*))",
459 array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
460 'goImapSieveServer', 'goImapSievePort'));
462 $this->data['SERVERS']['IMAP']= array();
464 while ($attrs= $ldap->fetch()){
466 /* Check if the given goImapSieveServer is in the new style "{cn:port/option}"
467 or the old style just "cn".
468 */
469 if(preg_match("/\{/",$attrs['goImapSieveServer'][0])){
470 $sieve_server = preg_replace("/^\{([^:]*).*$/","\\1",$attrs['goImapSieveServer'][0]);
471 $sieve_option = preg_replace("/^[^:]*[^\/]*+\/(.*)\}$/","\\1",$attrs['goImapSieveServer'][0]);
472 }else{
473 $sieve_server = $attrs['goImapSieveServer'][0];
474 $sieve_option = "";
475 }
477 $pwd = $attrs['goImapPassword'][0];
478 $imap_admin = $attrs['goImapAdmin'][0];
479 $imap_connect = $attrs['goImapConnect'][0];
480 $imap_server = $attrs['goImapName'][0];
481 $sieve_port = $attrs['goImapSievePort'][0];
483 $this->data['SERVERS']['IMAP'][$imap_server]=
484 array(
485 "server_dn" => $attrs['dn'],
486 "connect" => $imap_connect,
487 "admin" => $imap_admin,
488 "password" => $pwd,
489 "sieve_server"=> $sieve_server,
490 "sieve_option"=> $sieve_option,
491 "sieve_port" => $sieve_port);
492 }
493 }
495 /* Get kerberos server. FIXME: only one is supported currently */
496 $ldap->cd ($this->current['BASE']);
497 $ldap->search ("(&(objectClass=goKrbServer)(goKrbRealm=*)(goKrbAdmin=*))");
498 if ($ldap->count()){
499 $attrs= $ldap->fetch();
500 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
501 'REALM' => $attrs['goKrbRealm'][0],
502 'ADMIN' => $attrs['goKrbAdmin'][0]);
503 }
505 /* Get cups server. FIXME: only one is supported currently */
506 $ldap->cd ($this->current['BASE']);
507 $ldap->search ("(objectClass=goCupsServer)");
508 if ($ldap->count()){
509 $attrs= $ldap->fetch();
510 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
511 }
513 /* Get fax server. FIXME: only one is supported currently */
514 $ldap->cd ($this->current['BASE']);
515 $ldap->search ("(objectClass=goFaxServer)");
516 if ($ldap->count()){
517 $attrs= $ldap->fetch();
518 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
519 'LOGIN' => $attrs['goFaxAdmin'][0],
520 'PASSWORD' => $attrs['goFaxPassword'][0]);
521 }
524 /* Get asterisk servers */
525 $ldap->cd ($this->current['BASE']);
526 $ldap->search ("(objectClass=goFonServer)");
527 $this->data['SERVERS']['FON']= array();
528 if ($ldap->count()){
529 while ($attrs= $ldap->fetch()){
531 /* Add 0 entry for development */
532 if(count($this->data['SERVERS']['FON']) == 0){
533 $this->data['SERVERS']['FON'][0]= array(
534 'DN' => $attrs['dn'],
535 'SERVER' => $attrs['cn'][0],
536 'LOGIN' => $attrs['goFonAdmin'][0],
537 'PASSWORD' => $attrs['goFonPassword'][0],
538 'DB' => "gophone",
539 'SIP_TABLE' => "sip_users",
540 'EXT_TABLE' => "extensions",
541 'VOICE_TABLE' => "voicemail_users",
542 'QUEUE_TABLE' => "queues",
543 'QUEUE_MEMBER_TABLE' => "queue_members");
544 }
546 /* Add entry with 'dn' as index */
547 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
548 'DN' => $attrs['dn'],
549 'SERVER' => $attrs['cn'][0],
550 'LOGIN' => $attrs['goFonAdmin'][0],
551 'PASSWORD' => $attrs['goFonPassword'][0],
552 'DB' => "gophone",
553 'SIP_TABLE' => "sip_users",
554 'EXT_TABLE' => "extensions",
555 'VOICE_TABLE' => "voicemail_users",
556 'QUEUE_TABLE' => "queues",
557 'QUEUE_MEMBER_TABLE' => "queue_members");
558 }
559 }
562 /* Get glpi server */
563 $ldap->cd ($this->current['BASE']);
564 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
565 if ($ldap->count()){
566 $attrs= $ldap->fetch();
567 if(!isset($attrs['goGlpiPassword'])){
568 $attrs['goGlpiPassword'][0] ="";
569 }
570 $this->data['SERVERS']['GLPI']= array(
571 'SERVER' => $attrs['cn'][0],
572 'LOGIN' => $attrs['goGlpiAdmin'][0],
573 'PASSWORD' => $attrs['goGlpiPassword'][0],
574 'DB' => $attrs['goGlpiDatabase'][0]);
575 }
578 /* Get logdb server */
579 $ldap->cd ($this->current['BASE']);
580 $ldap->search ("(objectClass=goLogDBServer)");
581 if ($ldap->count()){
582 $attrs= $ldap->fetch();
583 if(!isset($attrs['goLogDB'][0])){
584 $attrs['goLogDB'][0] = "gomon";
585 }
586 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
587 'LOGIN' => $attrs['goLogAdmin'][0],
588 'DB' => $attrs['goLogDB'][0],
589 'PASSWORD' => $attrs['goLogPassword'][0]);
590 }
593 /* GOsa logging databases */
594 $ldap->cd ($this->current['BASE']);
595 $ldap->search ("(objectClass=gosaLogServer)");
596 if ($ldap->count()){
597 while($attrs= $ldap->fetch()){
598 $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]=
599 array(
600 'DN' => $attrs['dn'],
601 'USER' => $attrs['goLogDBUser'][0],
602 'DB' => $attrs['goLogDB'][0],
603 'PWD' => $attrs['goLogDBPassword'][0]);
604 }
605 }
608 /* Get NFS server lists */
609 $tmp= array("default");
610 $tmp2= array("default");
611 $ldap->cd ($this->current['BASE']);
612 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
613 while ($attrs= $ldap->fetch()){
614 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
615 if(preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
616 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
617 $tmp[]= $attrs["cn"][0].":$path";
618 }
619 if(preg_match('/^[^|]+\|[^|]+\|NBD\|.*$/', $attrs["goExportEntry"][$i])){
620 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
621 $tmp2[]= $attrs["cn"][0].":$path";
622 }
623 }
624 }
625 $this->data['SERVERS']['NFS']= $tmp;
626 $this->data['SERVERS']['NBD']= $tmp2;
628 /* Load Terminalservers */
629 $ldap->cd ($this->current['BASE']);
630 $ldap->search ("(objectClass=goTerminalServer)",array("cn","gotoSessionType"));
631 $this->data['SERVERS']['TERMINAL']= array();
632 $this->data['SERVERS']['TERMINAL'][]= "default";
633 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'] = array();
636 while ($attrs= $ldap->fetch()){
637 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
638 if(isset( $attrs["gotoSessionType"]['count'])){
639 for($i =0 ; $i < $attrs["gotoSessionType"]['count'] ; $i++){
640 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'][$attrs["cn"][0]][] = $attrs["gotoSessionType"][$i];
641 }
642 }
643 }
645 /* Ldap Server
646 */
647 $this->data['SERVERS']['LDAP']= array();
648 $ldap->cd ($this->current['BASE']);
649 $ldap->search ("(&(objectClass=goLdapServer)(goLdapBase=*))");
650 while ($attrs= $ldap->fetch()){
651 $this->data['SERVERS']['LDAP'][$attrs['dn']] = $attrs;
652 }
654 /* Get misc server lists */
655 $this->data['SERVERS']['SYSLOG']= array("default");
656 $this->data['SERVERS']['NTP']= array("default");
657 $ldap->cd ($this->current['BASE']);
658 $ldap->search ("(objectClass=goNtpServer)");
659 while ($attrs= $ldap->fetch()){
660 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
661 }
662 $ldap->cd ($this->current['BASE']);
663 $ldap->search ("(objectClass=goSyslogServer)");
664 while ($attrs= $ldap->fetch()){
665 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
666 }
668 /* Get samba servers from LDAP, in case of samba3 */
669 if ($this->current['SAMBAVERSION'] == 3){
670 $this->data['SERVERS']['SAMBA']= array();
671 $ldap->cd ($this->current['BASE']);
672 $ldap->search ("(objectClass=sambaDomain)");
673 while ($attrs= $ldap->fetch()){
674 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
675 if(isset($attrs["sambaSID"][0])){
676 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0];
677 }
678 if(isset($attrs["sambaAlgorithmicRidBase"][0])){
679 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
680 }
681 }
683 /* If no samba servers are found, look for configured sid/ridbase */
684 if (count($this->data['SERVERS']['SAMBA']) == 0){
685 if (!isset($this->current["SAMBASID"]) || !isset($this->current["SAMBARIDBASE"])){
686 msg_dialog::display(_("Configuration error"), _("sambaSID and/or sambaRidBase missing in the configuration!"), ERROR_DIALOG);
687 } else {
688 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
689 "SID" => $this->current["SAMBASID"],
690 "RIDBASE" => $this->current["SAMBARIDBASE"]);
691 }
692 }
693 }
694 }
697 function get_departments($ignore_dn= "")
698 {
699 global $config;
701 /* Initialize result hash */
702 $result= array();
703 $administrative= array();
704 $result['/']= $this->current['BASE'];
705 $this->tdepartments= array();
707 /* Get all department types from department Management, to be able detect the department type.
708 -It is possible that differnty department types have the same name,
709 in this case we have to mark the department name to be able to differentiate.
710 (e.g l=Name or o=Name)
711 */
712 $types = departmentManagement::get_support_departments();
714 /* Create a list of attributes to fetch */
715 $ldap_values = array("objectClass","gosaUnitTag");
716 $filter = "";
717 foreach($types as $type){
718 $ldap_values[] = $type['ATTR'];
719 $filter .= "(objectClass=".$type['OC'].")";
720 }
721 $filter = "(&(objectClass=gosaDepartment)(|".$filter."))";
723 /* Get list of department objects */
724 $ldap= $this->get_ldap_link();
725 $ldap->cd ($this->current['BASE']);
726 $ldap->search ($filter, $ldap_values);
727 while ($attrs= $ldap->fetch()){
729 /* Detect department type */
730 $type_data = array();
731 foreach($types as $t => $data){
732 if(in_array($data['OC'],$attrs['objectClass'])){
733 $type_data = $data;
734 break;
735 }
736 }
738 /* Unknown department type -> skip
739 */
740 if(!count($type_data)) continue;
742 $dn= $ldap->getDN();
743 $this->tdepartments[$dn]= "";
745 /* Save administrative departments */
746 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
747 isset($attrs['gosaUnitTag'][0])){
748 $administrative[$dn]= $attrs['gosaUnitTag'][0];
749 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
750 }
752 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
753 isset($attrs['gosaUnitTag'][0])){
754 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
755 }
757 if ($dn == $ignore_dn){
758 continue;
759 }
761 $c_dn = convert_department_dn($dn)." (".$type_data['ATTR'].")";
763 /* Only assign non-root departments */
764 if ($dn != $result['/']){
765 $result[$c_dn]= $dn;
766 }
767 }
769 $this->adepartments= $administrative;
770 $this->departments= $result;
771 }
774 function make_idepartments($max_size= 28)
775 {
776 global $config;
777 $base = $config->current['BASE'];
778 $qbase = preg_quote($base, '/');
779 $utags= isset($config->current['HONOURUNITTAGS']) && preg_match('/true/i', $config->current['HONOURUNITTAGS']);
781 $arr = array();
782 $ui= get_userinfo();
784 $this->idepartments= array();
786 /* Create multidimensional array, with all departments. */
787 foreach ($this->departments as $key => $val){
789 /* When using strict_units, filter non relevant parts */
790 if ($utags){
791 if ($ui->gosaUnitTag != '' && isset($this->tdepartments[$val]) &&
792 $this->tdepartments[$val] != $ui->gosaUnitTag){
794 #TODO: link with strict*
795 #continue;
796 }
797 }
799 /* Split dn into single department pieces */
800 $elements = array_reverse(split(',',preg_replace("/$qbase$/",'',$val)));
802 /* Add last ou element of current dn to our array */
803 $last = &$arr;
804 foreach($elements as $key => $ele){
806 /* skip empty */
807 if(empty($ele)) continue;
809 /* Extract department name */
810 $elestr = trim(preg_replace('/^[^=]*+=/','', $ele),',');
811 $nameA = trim(preg_replace('/=.*$/','', $ele),',');
812 if($nameA != 'ou'){
813 $nameA = " ($nameA)";
814 }else{
815 $nameA = '';
816 }
818 /* Add to array */
819 if($key == (count($elements)-1)){
820 $last[$elestr.$nameA]['ENTRY'] = $val;
821 }
823 /* Set next array appending position */
824 $last = &$last[$elestr.$nameA]['SUB'];
825 }
826 }
829 /* Add base entry */
830 $ret['/']['ENTRY'] = $base;
831 $ret['/']['SUB'] = $arr;
832 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
833 }
836 /* Creates display friendly output from make_idepartments */
837 function generateDepartmentArray($arr,$depth = -1,$max_size = 256)
838 {
839 $ret = array();
840 $depth ++;
842 /* Walk through array */
843 ksort($arr);
844 foreach($arr as $name => $entries){
846 /* If this department is the last in the current tree position
847 * remove it, to avoid generating output for it */
848 if(count($entries['SUB'])==0){
849 unset($entries['SUB']);
850 }
852 /* Fix name, if it contains a replace tag */
853 $name= preg_replace('/\\\\,/', ',', LDAP::fix($name));
855 /* Check if current name is too long, then cut it */
856 if(mb_strlen($name, 'UTF-8')> $max_size){
857 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
858 }
860 /* Append the name to the list */
861 if(isset($entries['ENTRY'])){
862 $a = "";
863 for($i = 0 ; $i < $depth ; $i ++){
864 $a.=".";
865 }
866 $ret[$entries['ENTRY']]=$a." ".$name;
867 }
869 /* recursive add of subdepartments */
870 if(isset($entries['SUB'])){
871 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
872 }
873 }
875 return($ret);
876 }
878 /*! \brief Get all available shares defined in the current LDAP
879 *
880 * This function returns all available Shares defined in this ldap
881 *
882 * \param boolean listboxEntry If set to TRUE, only name and path are
883 * attached to the array. If FALSE, the whole entry will be parsed an atached to the result.
884 * \return array
885 */
886 function getShareList($listboxEntry = false)
887 {
888 $tmp = get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",get_ou("serverRDN"),
889 $this->current['BASE'],array("goExportEntry","cn"), GL_NONE);
890 $return =array();
891 foreach($tmp as $entry){
893 if(isset($entry['goExportEntry']['count'])){
894 unset($entry['goExportEntry']['count']);
895 }
896 if(isset($entry['goExportEntry'])){
897 foreach($entry['goExportEntry'] as $export){
898 $shareAttrs = split("\|",$export);
899 if($listboxEntry) {
900 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
901 }else{
902 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
903 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
904 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
905 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
906 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
907 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
908 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
909 }
910 }
911 }
912 }
913 return($return);
914 }
917 /*! \brief Return al available share servers
918 *
919 * This function returns all available ShareServers.
920 *
921 * \return array
922 * */
923 function getShareServerList()
924 {
925 global $config;
926 $return = array();
927 $ui = get_userinfo();
928 $base = $config->current['BASE'];
929 $res= get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server",
930 get_ou("serverRDN"), $base,array("goExportEntry","cn"),GL_NONE | GL_NO_ACL_CHECK);
932 foreach($res as $entry){
934 $acl = $ui->get_permissions($entry['dn'],"server","");
935 if(isset($entry['goExportEntry']['count'])){
936 unset($entry['goExportEntry']['count']);
937 }
938 foreach($entry['goExportEntry'] as $share){
939 $a_share = split("\|",$share);
940 $sharename = $a_share[0];
941 $data= array();
942 $data['NAME'] = $sharename;
943 $data['ACL'] = $acl;
944 $data['SERVER'] = $entry['cn']['0'];
945 $data['SHARE'] = $sharename;
946 $data['DISPLAY']= $entry['cn'][0]." [".$sharename."]";
947 $return[$entry['cn'][0]."|".$sharename] = $data;
948 }
949 }
950 return($return);
951 }
954 /*! \brief Check if there's the specified bool value set in the configuration
955 *
956 * The function checks, weither the specified bool value is set to a true
957 * value in the configuration file. Considered true are either true or yes,
958 * case-insensitive.
959 *
960 * Example usage:
961 * \code
962 * if ($this->config->boolValueIsTrue("main", "copyPaste")) {
963 * echo "Copy Paste Handling is enabled";
964 * }
965 * \endcode
966 *
967 * \param string 'section' Section in the configuration file.
968 * \param string 'value' Key in the given section, which is subject to check
969 *
970 *
971 * */
972 function boolValueIsTrue($section, $value)
973 {
974 $section= strtoupper($section);
975 $value= strtoupper($value);
976 if (isset($this->data[$section][$value])){
978 $data= $this->data[$section][$value];
979 if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
980 return TRUE;
981 }
983 }
985 return FALSE;
986 }
989 function __search(&$arr, $name, $return)
990 {
991 $return= strtoupper($return);
992 if (is_array($arr)){
993 foreach ($arr as &$a){
994 if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
995 return(isset($a[$return])?$a[$return]:"");
996 } else {
997 $res= $this->__search ($a, $name, $return);
998 if ($res != ""){
999 return $res;
1000 }
1001 }
1002 }
1003 }
1004 return ("");
1005 }
1008 /*! Search for a configuration setting in different categories
1009 *
1010 * Searches for the value of a given key in the configuration data.
1011 * Optionally the list of categories to search (tabs, main, locations) can
1012 * be specified. The first value that matches is returned.
1013 *
1014 * Example usage:
1015 * \code
1016 * $postcmd = $this->config->search(get_class($this), "POSTCOMMAND", array("menu", "tabs"));
1017 * \endcode
1018 *
1019 * */
1020 function search($class, $value, $categories= "")
1021 {
1022 if (is_array($categories)){
1023 foreach ($categories as $category){
1024 $res= $this->__search($this->data[strtoupper($category)], $class, $value);
1025 if ($res != ""){
1026 return $res;
1027 }
1028 }
1029 } else {
1030 if ($categories == "") {
1031 return $this->__search($this->data, $class, $value);
1032 } else {
1033 return $this->__search($this->data[strtoupper($categories)], $class, $value);
1034 }
1035 }
1037 return ("");
1038 }
1041 /*! \brief Get a configuration value from the config
1042 *
1043 * This returns a configuration value from the config. It either
1044 * uses the data of the current location ($this->current),
1045 * if it contains the value (e.g. current['BASE']) or otherwise
1046 * uses the data from the main configuration section.
1047 *
1048 * If no value is found and an optional default has been specified,
1049 * then the default is returned.
1050 *
1051 * \param string 'name' the configuration key (case-insensitive)
1052 * \param string 'default' a default that is returned, if no value is found
1053 *
1054 *
1055 */
1056 function get_cfg_value($name, $default= "") {
1057 $name= strtoupper($name);
1059 /* Check if we have a current value for $name */
1060 if (isset($this->current[$name])){
1061 return ($this->current[$name]);
1062 }
1064 /* Check if we have a global value for $name */
1065 if (isset($this->data["MAIN"][$name])){
1066 return ($this->data["MAIN"][$name]);
1067 }
1069 return ($default);
1070 }
1073 /*! \brief Check if current configuration version matches the GOsa version
1074 *
1075 * This function checks if the configuration file version matches the
1076 * version of the gosa version, by comparing it with the configuration
1077 * file version of the example gosa.conf that comes with GOsa.
1078 * If a version mismatch occurs an error is triggered.
1079 * */
1080 function check_config_version()
1081 {
1082 /* Skip check, if we've already mentioned the mismatch
1083 */
1084 if(session::global_is_set("LastChecked") && session::global_get("LastChecked") == $this->config_version) return;
1086 /* Remember last checked version
1087 */
1088 session::global_set("LastChecked",$this->config_version);
1090 $current = md5(file_get_contents(CONFIG_TEMPLATE_DIR."/gosa.conf"));
1092 /* Check contributed config version and current config version.
1093 */
1094 if(($this->config_version == "NOT SET") || ($this->config_version != $current && !empty($this->config_version))){
1095 msg_dialog::display(_("Configuration"),_("The configuration file you are using seems to be outdated. Please move the GOsa configuration file away to run the GOsa setup again."));
1096 }
1097 }
1100 /*! \brief Check if session lifetime matches session.gc_maxlifetime
1101 *
1102 * On debian systems the session files are deleted with
1103 * a cronjob, which detects all files older than specified
1104 * in php.ini:'session.gc_maxlifetime' and removes them.
1105 * This function checks if the gosa.conf value matches the range
1106 * defined by session.gc_maxlifetime.
1107 *
1108 * \return boolean TRUE or FALSE depending on weither the settings match
1109 * or not. If SESSIONLIFETIME is not configured in GOsa it always returns
1110 * TRUE.
1111 */
1112 function check_session_lifetime()
1113 {
1114 if(isset($this->data['MAIN']['SESSIONLIFETIME'])){
1115 $cfg_lifetime = $this->data['MAIN']['SESSIONLIFETIME'];
1116 $ini_lifetime = ini_get('session.gc_maxlifetime');
1117 $deb_system = file_exists('/etc/debian_version');
1118 return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));
1119 }else{
1120 return(TRUE);
1121 }
1122 }
1123 }
1125 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1126 ?>