3
* This code is part of GOsa (http://www.gosa-project.org)
4
* Copyright (C) 2003-2008 GONICUS GmbH
6
* ID: $$Id: class_config.inc 20622 2011-03-14 12:30:06Z hickert $$
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.
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.
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
23
/*! \brief Configuration class
24
* \ingroup coreclasses
26
* The configuration class, responsible for parsing and querying the
27
* gosa configuration file.
34
var $config_found= FALSE;
39
var $currentLocation= "";
41
/*! \brief Store configuration for current location */
42
var $current= array();
44
/* Link to LDAP-server */
46
var $referrals= array();
48
/* \brief Configuration data
50
* - $data['SERVERS'] contains server informations.
52
var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(),
54
'MENU' => array(), 'SERVICE' => array());
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();
65
var $last_modified = 0;
67
var $instanceUUID = "";
69
private $jsonRPChandle = NULL;
71
public $configRegistry = NULL;
73
/*! \brief Class constructor of the config class
75
* \param string 'filename' path to the configuration file
76
* \param string 'basedir' base directory
79
function config($filename, $basedir= "")
81
$this->parser = xml_parser_create();
82
$this->basedir= $basedir;
84
xml_set_object($this->parser, $this);
85
xml_set_element_handler($this->parser, "tag_open", "tag_close");
87
/* Parse config file directly? */
89
$this->parse($filename);
92
// Load configuration registry
93
$this->configRegistry = new configRegistry($this);
94
$this->registration = new GOsaRegistration($this);
98
function getInstanceUUID()
100
return($this->instanceUUID);
104
/*! \brief Check and reload the configuration
106
* This function checks if the configuration has changed, since it was
107
* read the last time and reloads it. It uses the file mtime to check
108
* weither the file changed or not.
111
function check_and_reload()
115
/* Check if class_location.inc has changed, this is the case
116
if we have installed or removed plugins.
118
if(session::global_is_set("class_location.inc:timestamp")){
119
$tmp = stat("../include/class_location.inc");
120
if($tmp['mtime'] != session::global_get("class_location.inc:timestamp")){
121
session::global_un_set("plist");
124
$tmp = stat("../include/class_location.inc");
125
session::global_set("class_location.inc:timestamp",$tmp['mtime']);
127
if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
129
$this->config_found= FALSE;
130
$this->tags= array();
134
$this->currentLocation= "";
136
$this->parser = xml_parser_create();
137
xml_set_object($this->parser, $this);
138
xml_set_element_handler($this->parser, "tag_open", "tag_close");
139
$this->parse($this->filename);
140
$this->set_current($this->current['NAME']);
145
/*! \brief Parse the given configuration file
147
* Parses the configuration file and displays errors if there
148
* is something wrong with it.
150
* \param string 'filename' The filename of the configuration file.
153
function parse($filename)
157
"LOCATIONS" => array(),
160
"SERVICE" => array());
162
$this->last_modified = filemtime($filename);
163
$this->filename = $filename;
164
$fh= fopen($filename, "r");
165
$xmldata= fread($fh, 100000);
167
if(!xml_parse($this->parser, chop($xmldata))){
168
$msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
169
bold(xml_error_string(xml_get_error_code($this->parser))),
170
bold(xml_get_current_line_number($this->parser)));
171
msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG);
176
function tag_open($parser, $tag, $attrs)
178
/* Save last and current tag for reference */
179
$this->tags[$this->level]= $tag;
182
/* Trigger on CONF section */
184
$this->config_found= TRUE;
185
if(isset($attrs['CONFIGVERSION'])){
186
$this->config_version = $attrs['CONFIGVERSION'];
188
if(isset($attrs['INSTANCEUUID'])){
189
$this->instanceUUID = $attrs['INSTANCEUUID'];
193
/* Return if we're not in config section */
194
if (!$this->config_found){
198
/* yes/no to true/false and upper case TRUE to true and so on*/
199
foreach($attrs as $name => $value){
200
if(preg_match("/^(true|yes)$/i",$value)){
201
$attrs[$name] = "true";
202
}elseif(preg_match("/^(false|no)$/i",$value)){
203
$attrs[$name] = "false";
207
/* Look through attributes */
208
switch ($this->tags[$this->level-1]){
211
/* Handle tab section */
212
case 'TAB': $name= $this->tags[$this->level-2];
214
/* Create new array? */
215
if (!isset($this->data['TABS'][$name])){
216
$this->data['TABS'][$name]= array();
220
$this->data['TABS'][$name][]= $attrs;
223
/* Handle location */
225
if ($this->tags[$this->level-2] == 'MAIN'){
226
$name= $attrs['NAME'];
227
$name = preg_replace("/[<>\"']/","",$name);
228
$attrs['NAME'] = $name;
229
$this->currentLocation= $name;
231
/* Add location elements */
232
$this->data['LOCATIONS'][$name]= $attrs;
236
/* Handle referral tags */
238
if ($this->tags[$this->level-2] == 'LOCATION'){
240
$server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
242
/* Add location elements */
243
if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
244
$this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
247
$this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
251
/* Load main parameters */
253
$this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
258
if ($this->tags[$this->level-2] == 'MENU'){
259
$this->section= $attrs['NAME'];
260
$this->data['MENU'][$this->section]= array(); ;
265
$this->data['PATHMENU']= array(); ;
269
$this->data['SHORTCUTMENU']= array(); ;
274
if ($this->tags[$this->level-3] == 'MENU' &&
275
$this->tags[$this->level-2] == 'SECTION'){
277
$this->data['MENU'][$this->section][$this->gpc++]= $attrs;
279
if ($this->tags[$this->level-2] == 'PATHMENU'){
280
$this->data['PATHMENU'][$this->gpc++]= $attrs;
282
if ($this->tags[$this->level-2] == 'SHORTCUTMENU'){
283
$this->data['SHORTCUTMENU'][$this->gpc++]= $attrs;
285
if ($this->tags[$this->level-2] == 'SERVICEMENU'){
286
$this->data['SERVICE'][$attrs['CLASS']]= $attrs;
292
function tag_close($parser, $tag)
294
/* Close config section */
296
$this->config_found= FALSE;
302
function get_credentials($creds)
304
if (isset($_SERVER['HTTP_GOSA_KEY'])){
305
if (!session::global_is_set('HTTP_GOSA_KEY_CACHE')){
306
session::global_set('HTTP_GOSA_KEY_CACHE',array());
308
$cache = session::global_get('HTTP_GOSA_KEY_CACHE');
309
if(!isset($cache[$creds])){
310
$cache[$creds] = cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY']);
311
session::global_set('HTTP_GOSA_KEY_CACHE',$cache);
313
return ($cache[$creds]);
319
function getRpcHandle($connectUrl=NULL, $username=NULL, $userPassword=NULL, $authModeDigest=FALSE, $cache = TRUE)
321
// Get conenct information, if no info was given use the default values from gosa.conf
322
$connectUrl = ($connectUrl !== NULL) ? $connectUrl : $this->get_cfg_value('core','gosaRpcServer');
323
$username = ($username !== NULL) ? $username : $this->get_cfg_value('core','gosaRpcUser');
324
$userPassword = ($userPassword !== NULL) ? $userPassword : $this->get_cfg_value('core','gosaRpcPassword');
325
$authModeDigest = $authModeDigest;
327
// Create jsonRPC handle on demand.
329
return(new jsonRPC($this, $connectUrl, $username, $userPassword, $authModeDigest));
332
if(!isset($this->jsonRPChandle[$connectUrl][$username]) || !$this->jsonRPChandle[$connectUrl][$username]){
333
$this->jsonRPChandle[$connectUrl][$username] = new jsonRPC($this, $connectUrl, $username, $userPassword, $authModeDigest);
335
return($this->jsonRPChandle[$connectUrl][$username]);
340
/*! \brief Get a LDAP link object
342
* This function can be used to get an ldap object, which in turn can
343
* be used to query the LDAP. See the LDAP class for more information
348
* $ldap = $this->config->get_ldap_link();
351
* \param boolean sizelimit Weither to impose a sizelimit on the LDAP object or not.
352
* Defaults to false. If set to true, the size limit in the configuration
353
* file will be used to set the option LDAP_OPT_SIZELIMIT.
354
* \return ldapMultiplexer object
356
function get_ldap_link($sizelimit= FALSE)
358
if($this->ldap === NULL || !is_resource($this->ldap->cid)){
360
/* Build new connection */
361
$this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
362
$this->current['ADMINDN'], $this->get_credentials($this->current['ADMINPASSWORD']));
364
/* Check for connection */
365
if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
366
$smarty= get_smarty();
367
msg_dialog::display(_("LDAP error"), _("Cannot bind to LDAP!"), FATAL_ERROR_DIALOG);
372
if (!isset($this->current['REFERRAL'])){
373
$this->ldap->referrals= array();
375
$this->ldap->referrals= $this->current['REFERRAL'];
378
if (!session::global_is_set('size_limit')){
379
session::global_set('size_limit', $this->get_cfg_value('core', 'ldapSizelimit'));
380
session::global_set('size_ignore', $this->boolValueIsTrue('core', 'ldapSizeIgnore'));
384
$obj = new ldapMultiplexer($this->ldap);
386
$obj->set_size_limit(session::global_get('size_limit'));
388
$obj->set_size_limit(0);
393
/*! \brief Set the current location
395
* \param string name the name of the location
397
function set_current($name)
399
$this->current= $this->data['LOCATIONS'][$name];
401
if (isset($this->current['INITIAL_BASE'])){
402
session::global_set('CurrentMainBase',$this->current['INITIAL_BASE']);
405
/* Sort referrals, if present */
406
if (isset ($this->current['REFERRAL'])){
409
foreach ($this->current['REFERRAL'] as $ref){
410
$server= preg_replace('%^(.*://[^/]+)/.*$%', '\\1', $ref['URI']);
411
$base= preg_replace('%^.*://[^/]+/(.*)$%', '\\1', $ref['URI']);
412
$bases[$base]= strlen($base);
413
$servers[$base]= $server;
419
/* SERVER not defined? Load the one with the shortest base */
420
if (!isset($this->current['SERVER'])){
421
$this->current['SERVER']= $servers[key($bases)];
424
/* BASE not defined? Load the one with the shortest base */
425
if (!isset($this->current['BASE'])){
426
$this->current['BASE']= key($bases);
429
/* Convert BASE to have escaped special characters */
430
$this->current['BASE']= @LDAP::convert($this->current['BASE']);
432
/* Parse LDAP referral informations */
433
if (!isset($this->current['ADMINDN']) || !isset($this->current['ADMINPASSWORD'])){
434
$url= $this->current['SERVER'];
435
$referral= $this->current['REFERRAL'][$url];
436
$this->current['ADMINDN']= $referral['ADMINDN'];
437
$this->current['ADMINPASSWORD']= $referral['ADMINPASSWORD'];
440
/* Load server informations */
441
$this->load_servers();
445
/*! \brief Load server information from config/LDAP
447
* This function searches the LDAP for servers (e.g. goImapServer, goMailServer etc.)
448
* and stores information about them $this->data['SERVERS']. In the case of mailservers
449
* the main section of the configuration file is searched, too.
451
function load_servers ()
453
/* Only perform actions if current is set */
454
if ($this->current === NULL){
458
/* Fill imap servers */
459
$ldap= $this->get_ldap_link();
460
$ldap->cd ($this->current['BASE']);
462
/* Search mailMethod konfiguration in main section too
464
$tmp = $this->get_cfg_value("core","mailMethod");
466
$ldap->search ("(objectClass=goMailServer)", array('cn'));
467
$this->data['SERVERS']['IMAP']= array();
468
while ($attrs= $ldap->fetch()){
469
$name= $attrs['cn'][0];
470
$this->data['SERVERS']['IMAP'][$name]=
472
"server_dn" => $attrs['dn'],
481
$ldap->search ("(&(objectClass=goImapServer)(goImapSieveServer=*))",
482
array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
483
'goImapSieveServer', 'goImapSievePort'));
485
$this->data['SERVERS']['IMAP']= array();
487
while ($attrs= $ldap->fetch()){
489
/* Check if the given goImapSieveServer is in the new style "{cn:port/option}"
490
or the old style just "cn".
492
if(preg_match("/\{/",$attrs['goImapSieveServer'][0])){
493
$sieve_server = preg_replace("/^\{([^:]*).*$/","\\1",$attrs['goImapSieveServer'][0]);
494
$sieve_option = preg_replace("/^[^:]*[^\/]*+\/(.*)\}$/","\\1",$attrs['goImapSieveServer'][0]);
496
$sieve_server = $attrs['goImapSieveServer'][0];
500
$pwd = $attrs['goImapPassword'][0];
501
$imap_admin = $attrs['goImapAdmin'][0];
502
$imap_connect = $attrs['goImapConnect'][0];
503
$imap_server = $attrs['goImapName'][0];
504
$sieve_port = $attrs['goImapSievePort'][0];
506
$this->data['SERVERS']['IMAP'][$imap_server]=
508
"server_dn" => $attrs['dn'],
509
"connect" => $imap_connect,
510
"admin" => $imap_admin,
512
"sieve_server"=> $sieve_server,
513
"sieve_option"=> $sieve_option,
514
"sieve_port" => $sieve_port);
518
/* Get kerberos server. FIXME: only one is supported currently */
519
$ldap->cd ($this->current['BASE']);
520
$ldap->search ("(&(goKrbRealm=*)(goKrbAdmin=*)(objectClass=goKrbServer))");
522
$attrs= $ldap->fetch();
523
$this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
524
'REALM' => $attrs['goKrbRealm'][0],
525
'ADMIN' => $attrs['goKrbAdmin'][0]);
528
/* Get cups server. FIXME: only one is supported currently */
529
$ldap->cd ($this->current['BASE']);
530
$ldap->search ("(objectClass=goCupsServer)");
532
$attrs= $ldap->fetch();
533
$this->data['SERVERS']['CUPS']= $attrs['cn'][0];
536
/* Get fax server. FIXME: only one is supported currently */
537
$ldap->cd ($this->current['BASE']);
538
$ldap->search ("(objectClass=goFaxServer)");
540
$attrs= $ldap->fetch();
541
$this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
542
'LOGIN' => $attrs['goFaxAdmin'][0],
543
'PASSWORD' => $attrs['goFaxPassword'][0]);
547
/* Get asterisk servers */
548
$ldap->cd ($this->current['BASE']);
549
$ldap->search ("(objectClass=goFonServer)");
550
$this->data['SERVERS']['FON']= array();
552
while ($attrs= $ldap->fetch()){
554
/* Add 0 entry for development */
555
if(count($this->data['SERVERS']['FON']) == 0){
556
$this->data['SERVERS']['FON'][0]= array(
557
'DN' => $attrs['dn'],
558
'SERVER' => $attrs['cn'][0],
559
'LOGIN' => $attrs['goFonAdmin'][0],
560
'PASSWORD' => $attrs['goFonPassword'][0],
562
'SIP_TABLE' => "sip_users",
563
'EXT_TABLE' => "extensions",
564
'VOICE_TABLE' => "voicemail_users",
565
'QUEUE_TABLE' => "queues",
566
'QUEUE_MEMBER_TABLE' => "queue_members");
569
/* Add entry with 'dn' as index */
570
$this->data['SERVERS']['FON'][$attrs['dn']]= array(
571
'DN' => $attrs['dn'],
572
'SERVER' => $attrs['cn'][0],
573
'LOGIN' => $attrs['goFonAdmin'][0],
574
'PASSWORD' => $attrs['goFonPassword'][0],
576
'SIP_TABLE' => "sip_users",
577
'EXT_TABLE' => "extensions",
578
'VOICE_TABLE' => "voicemail_users",
579
'QUEUE_TABLE' => "queues",
580
'QUEUE_MEMBER_TABLE' => "queue_members");
585
/* Get glpi server */
586
$ldap->cd ($this->current['BASE']);
587
$ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
589
$attrs= $ldap->fetch();
590
if(!isset($attrs['goGlpiPassword'])){
591
$attrs['goGlpiPassword'][0] ="";
593
$this->data['SERVERS']['GLPI']= array(
594
'SERVER' => $attrs['cn'][0],
595
'LOGIN' => $attrs['goGlpiAdmin'][0],
596
'PASSWORD' => $attrs['goGlpiPassword'][0],
597
'DB' => $attrs['goGlpiDatabase'][0]);
601
/* Get logdb server */
602
$ldap->cd ($this->current['BASE']);
603
$ldap->search ("(objectClass=goLogDBServer)");
605
$attrs= $ldap->fetch();
606
if(!isset($attrs['gosaLogDB'][0])){
607
$attrs['gosaLogDB'][0] = "gomon";
609
$this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
610
'LOGIN' => $attrs['goLogAdmin'][0],
611
'DB' => $attrs['gosaLogDB'][0],
612
'PASSWORD' => $attrs['goLogPassword'][0]);
616
/* GOsa logging databases */
617
$ldap->cd ($this->current['BASE']);
618
$ldap->search ("(objectClass=gosaLogServer)");
620
while($attrs= $ldap->fetch()){
621
$this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]=
623
'DN' => $attrs['dn'],
624
'USER' => $attrs['goLogDBUser'][0],
625
'DB' => $attrs['goLogDB'][0],
626
'PWD' => $attrs['goLogDBPassword'][0]);
631
/* Get NFS server lists */
632
$tmp= array("default");
633
$tmp2= array("default");
634
$ldap->cd ($this->current['BASE']);
635
$ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
636
while ($attrs= $ldap->fetch()){
637
for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
638
if(preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
639
$path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
640
$tmp[]= $attrs["cn"][0].":$path";
642
if(preg_match('/^[^|]+\|[^|]+\|NBD\|.*$/', $attrs["goExportEntry"][$i])){
643
$path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
644
$tmp2[]= $attrs["cn"][0].":$path";
648
$this->data['SERVERS']['NFS']= $tmp;
649
$this->data['SERVERS']['NBD']= $tmp2;
651
/* Load Terminalservers */
652
$ldap->cd ($this->current['BASE']);
653
$ldap->search ("(objectClass=goTerminalServer)",array("cn","gotoSessionType"));
654
$this->data['SERVERS']['TERMINAL']= array();
655
$this->data['SERVERS']['TERMINAL'][]= "default";
656
$this->data['SERVERS']['TERMINAL_SESSION_TYPES'] = array();
659
while ($attrs= $ldap->fetch()){
660
$this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
661
if(isset( $attrs["gotoSessionType"]['count'])){
662
for($i =0 ; $i < $attrs["gotoSessionType"]['count'] ; $i++){
663
$this->data['SERVERS']['TERMINAL_SESSION_TYPES'][$attrs["cn"][0]][] = $attrs["gotoSessionType"][$i];
670
$this->data['SERVERS']['LDAP']= array();
671
$ldap->cd ($this->current['BASE']);
672
$ldap->search ("(&(objectClass=goLdapServer)(goLdapBase=*))");
673
while ($attrs= $ldap->fetch()){
674
$this->data['SERVERS']['LDAP'][$attrs['dn']] = $attrs;
677
/* Get misc server lists */
678
$this->data['SERVERS']['SYSLOG']= array("default");
679
$this->data['SERVERS']['NTP']= array("default");
680
$ldap->cd ($this->current['BASE']);
681
$ldap->search ("(objectClass=goNtpServer)");
682
while ($attrs= $ldap->fetch()){
683
$this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
685
$ldap->cd ($this->current['BASE']);
686
$ldap->search ("(objectClass=goSyslogServer)");
687
while ($attrs= $ldap->fetch()){
688
$this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
691
/* Get samba servers from LDAP, in case of samba3 */
692
$this->data['SERVERS']['SAMBA']= array();
693
$ldap->cd ($this->current['BASE']);
694
$ldap->search ("(objectClass=sambaDomain)");
695
while ($attrs= $ldap->fetch()){
696
$this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
697
if(isset($attrs["sambaSID"][0])){
698
$this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0];
700
if(isset($attrs["sambaAlgorithmicRidBase"][0])){
701
$this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
705
/* If no samba servers are found, look for configured sid/ridbase */
706
if (count($this->data['SERVERS']['SAMBA']) == 0){
707
$sambaSID = $this->get_cfg_value("core","sambaSID");
708
$sambaRIDBase = $this->get_cfg_value("core","sambaRidBase");
709
if (!isset($sambaSID) || !isset($sambaRIDBase)){
710
msg_dialog::display(_("Configuration error"),
711
_("sambaSID and/or sambaRidBase missing in the configuration!"), ERROR_DIALOG);
713
$this->data['SERVERS']['SAMBA']['DEFAULT']= array(
715
"RIDBASE" => $sambaRIDBase);
722
function get_departments($ignore_dn= "")
726
/* Initialize result hash */
728
$administrative= array();
729
$result['/']= $this->current['BASE'];
730
$this->tdepartments= array();
732
/* Get all department types from department Management, to be able detect the department type.
733
-It is possible that differnty department types have the same name,
734
in this case we have to mark the department name to be able to differentiate.
735
(e.g l=Name or o=Name)
737
$types = departmentManagement::get_support_departments();
739
/* Create a list of attributes to fetch */
740
$ldap_values = array("objectClass","gosaUnitTag", "description");
742
foreach($types as $type){
743
$ldap_values[] = $type['ATTR'];
744
$filter .= "(objectClass=".$type['OC'].")";
746
$filter = "(&(objectClass=gosaDepartment)(|".$filter."))";
748
/* Get list of department objects */
749
$ldap= $this->get_ldap_link();
750
$ldap->cd ($this->current['BASE']);
751
$ldap->search ($filter, $ldap_values);
752
while ($attrs= $ldap->fetch()){
754
/* Detect department type */
755
$type_data = array();
756
foreach($types as $t => $data){
757
if(in_array($data['OC'],$attrs['objectClass'])){
763
/* Unknown department type -> skip */
764
if(!count($type_data)) continue;
767
$this->tdepartments[$dn]= "";
768
$this->department_info[$dn]= array("img" => $type_data['IMG'],
769
"description" => isset($attrs['description'][0])?$attrs['description'][0]:"",
770
"name" => $attrs[$type_data['ATTR']][0]);
772
/* Save administrative departments */
773
if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
774
isset($attrs['gosaUnitTag'][0])){
775
$administrative[$dn]= $attrs['gosaUnitTag'][0];
776
$this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
779
if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
780
isset($attrs['gosaUnitTag'][0])){
781
$this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
784
if ($dn == $ignore_dn){
787
$c_dn = convert_department_dn($dn)." (".$type_data['ATTR'].")";
789
/* Only assign non-root departments */
790
if ($dn != $result['/']){
795
$this->adepartments= $administrative;
796
$this->departments= $result;
800
function make_idepartments($max_size= 28)
803
$base = $config->current['BASE'];
804
$qbase = preg_quote($base, '/');
805
$utags= isset($config->current['HONOURUNITTAGS']) && preg_match('/true/i', $config->current['HONOURUNITTAGS']);
810
$this->idepartments= array();
812
/* Create multidimensional array, with all departments. */
813
foreach ($this->departments as $key => $val){
815
/* When using strict_units, filter non relevant parts */
817
if ($ui->gosaUnitTag != '' && isset($this->tdepartments[$val]) &&
818
$this->tdepartments[$val] != $ui->gosaUnitTag){
820
#TODO: link with strict*
825
/* Split dn into single department pieces */
826
$elements = array_reverse(explode(',',preg_replace("/$qbase$/",'',$val)));
828
/* Add last ou element of current dn to our array */
830
foreach($elements as $key => $ele){
833
if(empty($ele)) continue;
835
/* Extract department name */
836
$elestr = trim(preg_replace('/^[^=]*+=/','', $ele),',');
837
$nameA = trim(preg_replace('/=.*$/','', $ele),',');
839
$nameA = " ($nameA)";
845
if($key == (count($elements)-1)){
846
$last[$elestr.$nameA]['ENTRY'] = $val;
849
/* Set next array appending position */
850
$last = &$last[$elestr.$nameA]['SUB'];
856
$ret['/']['ENTRY'] = $base;
857
$ret['/']['SUB'] = $arr;
858
$this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
862
/* Creates display friendly output from make_idepartments */
863
function generateDepartmentArray($arr,$depth = -1,$max_size = 256)
868
/* Walk through array */
870
foreach($arr as $name => $entries){
872
/* If this department is the last in the current tree position
873
* remove it, to avoid generating output for it */
874
if(count($entries['SUB'])==0){
875
unset($entries['SUB']);
878
/* Fix name, if it contains a replace tag */
879
$name= preg_replace('/\\\\,/', ',', LDAP::fix($name));
881
/* Check if current name is too long, then cut it */
882
if(mb_strlen($name, 'UTF-8')> $max_size){
883
$name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
886
/* Append the name to the list */
887
if(isset($entries['ENTRY'])){
889
for($i = 0 ; $i < $depth ; $i ++){
892
$ret[$entries['ENTRY']]=$a." ".$name;
895
/* recursive add of subdepartments */
896
if(isset($entries['SUB'])){
897
$ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
904
/*! \brief Get all available shares defined in the current LDAP
906
* This function returns all available Shares defined in this ldap
908
* \param boolean listboxEntry If set to TRUE, only name and path are
909
* attached to the array. If FALSE, the whole entry will be parsed an atached to the result.
912
function getShareList($listboxEntry = false)
914
$tmp = get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",get_ou("servgeneric", "serverRDN"),
915
$this->current['BASE'],array("goExportEntry","cn"), GL_NONE);
917
foreach($tmp as $entry){
919
if(isset($entry['goExportEntry']['count'])){
920
unset($entry['goExportEntry']['count']);
922
if(isset($entry['goExportEntry'])){
923
foreach($entry['goExportEntry'] as $export){
924
$shareAttrs = explode("|",$export);
926
$return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
928
$return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
929
$return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
930
$return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
931
$return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
932
$return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
933
$return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
934
$return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
943
/*! \brief Return al available share servers
945
* This function returns all available ShareServers.
949
function getShareServerList()
953
$ui = get_userinfo();
954
$base = $config->current['BASE'];
955
$res= get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server",
956
get_ou("servgeneric", "serverRDN"), $base,array("goExportEntry","cn"),GL_NONE | GL_NO_ACL_CHECK);
958
foreach($res as $entry){
960
$acl = $ui->get_permissions($entry['dn'],"server","");
961
if(isset($entry['goExportEntry']['count'])){
962
unset($entry['goExportEntry']['count']);
964
foreach($entry['goExportEntry'] as $share){
965
$a_share = explode("|",$share);
966
$sharename = $a_share[0];
968
$data['NAME'] = $sharename;
970
$data['SERVER'] = $entry['cn']['0'];
971
$data['SHARE'] = $sharename;
972
$data['DISPLAY']= $entry['cn'][0]." [".$sharename."]";
973
$return[$entry['cn'][0]."|".$sharename] = $data;
980
/*! \brief Checks if there's a bool property set in the configuration.
982
* The function checks, weither the specified bool value is set to a true
983
* value in the configuration file.
987
* if ($this->config->boolValueIsTrue("core", "copyPaste")) {
988
* echo "Copy Paste Handling is enabled";
992
* \param string 'class' The properties class. e.g. 'core','user','sudo',...
993
* \param string 'value' Key in the given section, which is subject to check
997
function boolValueIsTrue($class, $name)
999
return(preg_match("/true/i", $this->get_cfg_value($class,$name)));
1003
function __search(&$arr, $name, $return)
1005
$return= strtoupper($return);
1006
if (is_array($arr)){
1007
foreach ($arr as &$a){
1008
if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
1009
return(isset($a[$return])?$a[$return]:"");
1011
$res= $this->__search ($a, $name, $return);
1022
/*! Outdated - try to use pluginEnabled, boolValueIsTrue or get_cfg_value instead.
1024
* (Search for a configuration setting in different categories
1026
* Searches for the value of a given key in the configuration data.
1027
* Optionally the list of categories to search (tabs, main, locations) can
1028
* be specified. The first value that matches is returned.
1032
* $postcmd = $this->config->search(get_class($this), "POSTCOMMAND", array("menu", "tabs"));
1037
function search($class, $value, $categories= "")
1039
if (is_array($categories)){
1040
foreach ($categories as $category){
1041
$res= $this->__search($this->data[strtoupper($category)], $class, $value);
1047
if ($categories == "") {
1048
return $this->__search($this->data, $class, $value);
1050
return $this->__search($this->data[strtoupper($categories)], $class, $value);
1058
/*! \brief Check whether a plugin is activated or not
1060
function pluginEnabled($class){
1061
$tmp = $this->search($class, "CLASS",array('menu','tabs'));
1062
return(!empty($tmp));
1066
/*! \brief Get a configuration value from the config
1068
* This returns a configuration value from the config. It either
1069
* uses the data of the current location ($this->current),
1070
* if it contains the value (e.g. current['BASE']) or otherwise
1071
* uses the data from the main configuration section.
1073
* If no value is found and an optional default has been specified,
1074
* then the default is returned.
1076
* \param string 'name' the configuration key (case-insensitive)
1077
* \param string 'default' a default that is returned, if no value is found
1081
function get_cfg_value($class,$name, $default= NULL)
1083
// The default parameter is deprecated
1084
if($default != NULL){
1085
# trigger_error("Third parameter 'default' is deprecated for function 'get_cfg_value'!");
1088
// Return the matching property value if it exists.
1089
if($this->configRegistry->propertyExists($class,$name)){
1090
return($this->configRegistry->getPropertyValue($class,$name));
1093
// Show a warning in the syslog if there is an undefined property requested.
1094
if($this->configRegistry->propertyInitializationComplete() &&
1095
"{$class}::{$name}" != 'core::config' && // <--- This on is never set, only in gosa.conf.
1096
"{$class}::{$name}" != 'core::logging'){ // <--- This one may cause endless recursions in class_log.inc
1097
new log("debug","","Unconfigured property: '{$class}::{$name}'",array(),'');
1100
// Try to find the property in the config file directly.
1101
$name= strtoupper($name);
1102
if (isset($this->current[$name])) return ($this->current[$name]);
1103
if (isset($this->data["MAIN"][$name])) return ($this->data["MAIN"][$name]);
1108
/*! \brief Check if current configuration version matches the GOsa version
1110
* This function checks if the configuration file version matches the
1111
* version of the gosa version, by comparing it with the configuration
1112
* file version of the example gosa.conf that comes with GOsa.
1113
* If a version mismatch occurs an error is triggered.
1115
function check_config_version()
1117
/* Skip check, if we've already mentioned the mismatch
1119
if(session::global_is_set("LastChecked") && session::global_get("LastChecked") == $this->config_version) return;
1121
/* Remember last checked version
1123
session::global_set("LastChecked",$this->config_version);
1125
$current = md5(file_get_contents(CONFIG_TEMPLATE_DIR."/gosa.conf"));
1127
/* Check contributed config version and current config version.
1129
if(($this->config_version == "NOT SET") || ($this->config_version != $current && !empty($this->config_version))){
1130
msg_dialog::display(_("Configuration"),_("The configuration file you are using is outdated. Please move the GOsa configuration file away to run the GOsa setup again."));
1135
/*! \brief Check if session lifetime matches session.gc_maxlifetime
1137
* On debian systems the session files are deleted with
1138
* a cronjob, which detects all files older than specified
1139
* in php.ini:'session.gc_maxlifetime' and removes them.
1140
* This function checks if the gosa.conf value matches the range
1141
* defined by session.gc_maxlifetime.
1143
* \return boolean TRUE or FALSE depending on weither the settings match
1144
* or not. If SESSIONLIFETIME is not configured in GOsa it always returns
1147
function check_session_lifetime()
1149
if(isset($this->data['MAIN']['SESSIONLIFETIME'])){
1150
$cfg_lifetime = $this->data['MAIN']['SESSIONLIFETIME'];
1151
$ini_lifetime = ini_get('session.gc_maxlifetime');
1152
$deb_system = file_exists('/etc/debian_version');
1153
return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));
1159
/* Returns true if snapshots are enabled, and false if it is disalbed
1160
There will also be some errors psoted, if the configuration failed */
1161
function snapshotEnabled()
1163
if($this->get_cfg_value("core","enableSnapshots") == "true"){
1165
/* Check if the snapshot_base is defined */
1166
if ($this->get_cfg_value("core","snapshotBase") == ""){
1168
/* Send message if not done already */
1169
if(!session::is_set("snapshotFailMessageSend")){
1170
session::set("snapshotFailMessageSend",TRUE);
1171
msg_dialog::display(_("Configuration error"),
1172
sprintf(_("The snapshot functionality is enabled, but the required variable %s is not set."),
1173
bold("snapshotBase")), ERROR_DIALOG);
1178
/* Check if the snapshot_base is defined */
1179
if (!is_callable("gzcompress")){
1181
/* Send message if not done already */
1182
if(!session::is_set("snapshotFailMessageSend")){
1183
session::set("snapshotFailMessageSend",TRUE);
1184
msg_dialog::display(_("Configuration error"),
1185
sprintf(_("The snapshot functionality is enabled, but the required compression module is missing. Please install %s."), bold("php5-zip / php5-gzip")), ERROR_DIALOG);
1190
/* check if there are special server configurations for snapshots */
1191
if ($this->get_cfg_value("core","snapshotURI") != ""){
1193
/* check if all required vars are available to create a new ldap connection */
1195
foreach(array("snapshotURI","snapshotAdminDn","snapshotAdminPassword","snapshotBase") as $var){
1196
if($this->get_cfg_value("core",$var) == ""){
1197
$missing .= $var." ";
1199
/* Send message if not done already */
1200
if(!session::is_set("snapshotFailMessageSend")){
1201
session::set("snapshotFailMessageSend",TRUE);
1202
msg_dialog::display(_("Configuration error"),
1203
sprintf(_("The snapshot functionality is enabled, but the required variable %s is not set."),
1204
bold($missing)), ERROR_DIALOG);
1217
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: