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 class config {
25 /* XML parser */
26 var $parser;
27 var $config_found= FALSE;
28 var $tags= array();
29 var $level= 0;
30 var $gpc= 0;
31 var $section= "";
32 var $currentLocation= "";
34 /* Selected connection */
35 var $current= array();
37 /* Link to LDAP-server */
38 var $ldap= NULL;
39 var $referrals= array();
41 /* Configuration data */
42 var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(),
43 'MAIN' => array(),
44 'MENU' => array(), 'SERVICE' => array());
45 var $basedir= "";
46 var $config_version ="";
48 /* Keep a copy of the current deparment list */
49 var $departments= array();
50 var $idepartments= array();
51 var $adepartments= array();
52 var $tdepartments= array();
53 var $filename = "";
54 var $last_modified = 0;
56 function config($filename, $basedir= "")
57 {
58 $this->parser = xml_parser_create();
59 $this->basedir= $basedir;
61 xml_set_object($this->parser, $this);
62 xml_set_element_handler($this->parser, "tag_open", "tag_close");
64 /* Parse config file directly? */
65 if ($filename != ""){
66 $this->parse($filename);
67 }
68 }
71 function check_and_reload()
72 {
74 /* Check if class_location.inc has changed, this is the case
75 if we have installed or removed plugins.
76 */
77 if(session::is_set("class_location.inc:timestamp")){
78 $tmp = stat("../include/class_location.inc");
79 if($tmp['mtime'] != session::get("class_location.inc:timestamp")){
81 /* Refresh users ACLs */
82 $ui= get_userinfo();
83 $ui->loadACL();
84 session::set('ui',$ui);
86 /* Reset menu and iconmenu */
87 if(session::is_set("plist")){
88 $plist = session::get("plist");
89 $plist->reset_menus();
90 session::set("plist",$plist);
91 }
92 }
93 }
94 $tmp = stat("../include/class_location.inc");
95 session::set("class_location.inc:timestamp",$tmp['mtime']);
99 if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
101 $this->config_found= FALSE;
102 $this->tags= array();
103 $this->level= 0;
104 $this->gpc= 0;
105 $this->section= "";
106 $this->currentLocation= "";
108 $this->parser = xml_parser_create();
109 xml_set_object($this->parser, $this);
110 xml_set_element_handler($this->parser, "tag_open", "tag_close");
111 $this->parse($this->filename);
112 # if(session::is_set('plist')){
113 # session::un_set('plist');
114 # }
115 # if(session::is_set('plug')){
116 # session::un_set('plug');
117 # }
118 # if(isset($_GET['plug'])){
119 # unset($_GET['plug']);
120 # }
121 }
122 }
125 function parse($filename)
126 {
127 $this->last_modified = filemtime($filename);
128 $this->filename = $filename;
129 $fh= fopen($filename, "r");
130 $xmldata= fread($fh, 100000);
131 fclose($fh);
132 if(!xml_parse($this->parser, chop($xmldata))){
133 $msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
134 xml_error_string(xml_get_error_code($this->parser)),
135 xml_get_current_line_number($this->parser));
136 msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG);
137 exit;
138 }
139 }
141 function tag_open($parser, $tag, $attrs)
142 {
143 /* Save last and current tag for reference */
144 $this->tags[$this->level]= $tag;
145 $this->level++;
147 /* Trigger on CONF section */
148 if ($tag == 'CONF'){
149 $this->config_found= TRUE;
150 if(isset($attrs['CONFIG_VERSION'])){
151 $this->config_version = $attrs['CONFIG_VERSION'];
152 }
153 }
155 /* Return if we're not in config section */
156 if (!$this->config_found){
157 return;
158 }
160 /* yes/no to true/false and upper case TRUE to true and so on*/
161 foreach($attrs as $name => $value){
162 if(preg_match("/^(true|yes)$/i",$value)){
163 $attrs[$name] = "true";
164 }elseif(preg_match("/^(false|no)$/i",$value)){
165 $attrs[$name] = "false";
166 }
167 }
169 /* Look through attributes */
170 switch ($this->tags[$this->level-1]){
173 /* Handle tab section */
174 case 'TAB': $name= $this->tags[$this->level-2];
176 /* Create new array? */
177 if (!isset($this->data['TABS'][$name])){
178 $this->data['TABS'][$name]= array();
179 }
181 /* Add elements */
182 $this->data['TABS'][$name][]= $attrs;
183 break;
185 /* Handle location */
186 case 'LOCATION':
187 if ($this->tags[$this->level-2] == 'MAIN'){
188 $name= $attrs['NAME'];
189 $name = preg_replace("/[<>\"']/","",$name);
190 $attrs['NAME'] = $name;
191 $this->currentLocation= $name;
193 /* Add location elements */
194 $this->data['LOCATIONS'][$name]= $attrs;
195 }
196 break;
198 /* Handle referral tags */
199 case 'REFERRAL':
200 if ($this->tags[$this->level-2] == 'LOCATION'){
201 $url= $attrs['URL'];
202 $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
204 /* Add location elements */
205 if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
206 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
207 }
209 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
210 }
211 break;
213 /* Load main parameters */
214 case 'MAIN':
215 $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
216 break;
218 /* Load menu */
219 case 'SECTION':
220 if ($this->tags[$this->level-2] == 'MENU'){
221 $this->section= $attrs['NAME'];
222 $this->data['MENU'][$this->section]= array(); ;
223 }
224 break;
226 /* Inser plugins */
227 case 'PLUGIN':
228 if ($this->tags[$this->level-3] == 'MENU' &&
229 $this->tags[$this->level-2] == 'SECTION'){
231 $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
232 }
233 if ($this->tags[$this->level-2] == 'SERVICEMENU'){
234 $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
235 }
236 break;
237 }
238 }
240 function tag_close($parser, $tag)
241 {
242 /* Close config section */
243 if ($tag == 'CONF'){
244 $this->config_found= FALSE;
245 }
246 $this->level--;
247 }
250 function get_credentials($creds)
251 {
252 if (isset($_SERVER['HTTP_GOSA_KEY'])){
253 return (cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY']));
254 }
255 return ($creds);
256 }
259 function get_ldap_link($sizelimit= FALSE)
260 {
261 if($this->ldap === NULL || !is_resource($this->ldap->cid)){
263 /* Build new connection */
264 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
265 $this->current['ADMIN'], $this->get_credentials($this->current['PASSWORD']));
267 /* Check for connection */
268 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
269 $smarty= get_smarty();
270 msg_dialog::display(_("LDAP error"), _("Cannot bind to LDAP. Please contact the system administrator."), FATAL_ERROR_DIALOG);
271 exit();
272 }
274 if (!session::is_set('size_limit')){
275 session::set('size_limit',$this->current['SIZELIMIT']);
276 session::set('size_ignore',$this->current['SIZEIGNORE']);
277 }
279 if ($sizelimit){
280 $this->ldap->set_size_limit(session::get('size_limit'));
281 } else {
282 $this->ldap->set_size_limit(0);
283 }
285 /* Move referrals */
286 if (!isset($this->current['REFERRAL'])){
287 $this->ldap->referrals= array();
288 } else {
289 $this->ldap->referrals= $this->current['REFERRAL'];
290 }
291 }
293 return new ldapMultiplexer($this->ldap);
294 }
296 function set_current($name)
297 {
298 $this->current= $this->data['LOCATIONS'][$name];
300 if (!isset($this->current['PEOPLE'])){
301 $this->current['PEOPLE']= "ou=people";
302 }
303 if (!isset($this->current['GROUPS'])){
304 $this->current['GROUPS']= "ou=groups";
305 }
307 if (isset($this->current['INITIAL_BASE'])){
308 session::set('CurrentMainBase',$this->current['INITIAL_BASE']);
309 }
311 /* Remove possibly added ',' from end of group and people ou */
312 $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
313 $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
315 if (!isset($this->current['WINSTATIONS'])){
316 $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
317 }
318 if (!isset($this->current['HASH'])){
319 $this->current['HASH']= "crypt";
320 }
321 if (!isset($this->current['DNMODE'])){
322 $this->current['DNMODE']= "cn";
323 }
324 if (!isset($this->current['MINID'])){
325 $this->current['MINID']= 100;
326 }
327 if (!isset($this->current['SIZELIMIT'])){
328 $this->current['SIZELIMIT']= 200;
329 }
330 if (!isset($this->current['SIZEINGORE'])){
331 $this->current['SIZEIGNORE']= TRUE;
332 } else {
333 if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
334 $this->current['SIZEIGNORE']= TRUE;
335 } else {
336 $this->current['SIZEIGNORE']= FALSE;
337 }
338 }
340 /* Sort referrals, if present */
341 if (isset ($this->current['REFERRAL'])){
342 $bases= array();
343 $servers= array();
344 foreach ($this->current['REFERRAL'] as $ref){
345 $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
346 $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
347 $bases[$base]= strlen($base);
348 $servers[$base]= $server;
349 }
350 asort($bases);
351 reset($bases);
352 }
354 /* SERVER not defined? Load the one with the shortest base */
355 if (!isset($this->current['SERVER'])){
356 $this->current['SERVER']= $servers[key($bases)];
357 }
359 /* BASE not defined? Load the one with the shortest base */
360 if (!isset($this->current['BASE'])){
361 $this->current['BASE']= key($bases);
362 }
364 /* Convert BASE to have escaped special characters */
365 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
367 /* Parse LDAP referral informations */
368 if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
369 $url= $this->current['SERVER'];
370 $referral= $this->current['REFERRAL'][$url];
371 $this->current['ADMIN']= $referral['ADMIN'];
372 $this->current['PASSWORD']= $referral['PASSWORD'];
373 }
375 /* Load server informations */
376 $this->load_servers();
377 }
379 function load_servers ()
380 {
381 /* Only perform actions if current is set */
382 if ($this->current === NULL){
383 return;
384 }
386 /* Fill imap servers */
387 $ldap= $this->get_ldap_link();
388 $ldap->cd ($this->current['BASE']);
389 if (!isset($this->current['MAILMETHOD'])){
390 $this->current['MAILMETHOD']= "";
391 }
392 if ($this->current['MAILMETHOD'] == ""){
393 $ldap->search ("(objectClass=goMailServer)", array('cn'));
394 $this->data['SERVERS']['IMAP']= array();
395 error_reporting(0);
396 while ($attrs= $ldap->fetch()){
397 $name= $attrs['cn'][0];
398 $this->data['SERVERS']['IMAP'][$name]= $name;
399 }
400 error_reporting(E_ALL);
401 } else {
402 $ldap->search ("(&(objectClass=goImapServer)(goImapSieveServer=*))",
403 array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
404 'goImapSieveServer', 'goImapSievePort'));
406 $this->data['SERVERS']['IMAP']= array();
408 while ($attrs= $ldap->fetch()){
410 /* Check if the given goImapSieveServer is in the new style "{cn:port/option}"
411 or the old style just "cn".
412 */
413 if(preg_match("/\{/",$attrs['goImapSieveServer'][0])){
414 $sieve_server = preg_replace("/^\{([^:]*).*$/","\\1",$attrs['goImapSieveServer'][0]);
415 $sieve_option = preg_replace("/^[^:]*[^\/]*+\/(.*)\}$/","\\1",$attrs['goImapSieveServer'][0]);
416 }else{
417 $sieve_server = $attrs['goImapSieveServer'][0];
418 $sieve_option = "";
419 }
421 $pwd = $attrs['goImapPassword'][0];
422 $imap_admin = $attrs['goImapAdmin'][0];
423 $imap_connect = $attrs['goImapConnect'][0];
424 $imap_server = $attrs['goImapName'][0];
425 $sieve_port = $attrs['goImapSievePort'][0];
427 $this->data['SERVERS']['IMAP'][$imap_server]=
428 array(
429 "server_dn" => $attrs['dn'],
430 "connect" => $imap_connect,
431 "admin" => $imap_admin,
432 "password" => $pwd,
433 "sieve_server"=> $sieve_server,
434 "sieve_option"=> $sieve_option,
435 "sieve_port" => $sieve_port);
436 }
437 }
439 /* Get kerberos server. FIXME: only one is supported currently */
440 $ldap->cd ($this->current['BASE']);
441 $ldap->search ("(&(goKrbRealm=*)(goKrbAdmin=*)(objectClass=goKrbServer))");
442 if ($ldap->count()){
443 $attrs= $ldap->fetch();
444 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
445 'REALM' => $attrs['goKrbRealm'][0],
446 'ADMIN' => $attrs['goKrbAdmin'][0]);
447 }
449 /* Get cups server. FIXME: only one is supported currently */
450 $ldap->cd ($this->current['BASE']);
451 $ldap->search ("(objectClass=goCupsServer)");
452 if ($ldap->count()){
453 $attrs= $ldap->fetch();
454 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
455 }
457 /* Get fax server. FIXME: only one is supported currently */
458 $ldap->cd ($this->current['BASE']);
459 $ldap->search ("(objectClass=goFaxServer)");
460 if ($ldap->count()){
461 $attrs= $ldap->fetch();
462 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
463 'LOGIN' => $attrs['goFaxAdmin'][0],
464 'PASSWORD' => $attrs['goFaxPassword'][0]);
465 }
468 /* Get asterisk servers */
469 $ldap->cd ($this->current['BASE']);
470 $ldap->search ("(objectClass=goFonServer)");
471 $this->data['SERVERS']['FON']= array();
472 if ($ldap->count()){
473 while ($attrs= $ldap->fetch()){
475 /* Add 0 entry for development */
476 if(count($this->data['SERVERS']['FON']) == 0){
477 $this->data['SERVERS']['FON'][0]= array(
478 'DN' => $attrs['dn'],
479 'SERVER' => $attrs['cn'][0],
480 'LOGIN' => $attrs['goFonAdmin'][0],
481 'PASSWORD' => $attrs['goFonPassword'][0],
482 'DB' => "gophone",
483 'SIP_TABLE' => "sip_users",
484 'EXT_TABLE' => "extensions",
485 'VOICE_TABLE' => "voicemail_users",
486 'QUEUE_TABLE' => "queues",
487 'QUEUE_MEMBER_TABLE' => "queue_members");
488 }
490 /* Add entry with 'dn' as index */
491 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
492 'DN' => $attrs['dn'],
493 'SERVER' => $attrs['cn'][0],
494 'LOGIN' => $attrs['goFonAdmin'][0],
495 'PASSWORD' => $attrs['goFonPassword'][0],
496 'DB' => "gophone",
497 'SIP_TABLE' => "sip_users",
498 'EXT_TABLE' => "extensions",
499 'VOICE_TABLE' => "voicemail_users",
500 'QUEUE_TABLE' => "queues",
501 'QUEUE_MEMBER_TABLE' => "queue_members");
502 }
503 }
506 /* Get glpi server */
507 $ldap->cd ($this->current['BASE']);
508 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
509 if ($ldap->count()){
510 $attrs= $ldap->fetch();
511 if(!isset($attrs['goGlpiPassword'])){
512 $attrs['goGlpiPassword'][0] ="";
513 }
514 $this->data['SERVERS']['GLPI']= array(
515 'SERVER' => $attrs['cn'][0],
516 'LOGIN' => $attrs['goGlpiAdmin'][0],
517 'PASSWORD' => $attrs['goGlpiPassword'][0],
518 'DB' => $attrs['goGlpiDatabase'][0]);
519 }
522 /* Get logdb server */
523 $ldap->cd ($this->current['BASE']);
524 $ldap->search ("(objectClass=goLogDBServer)");
525 if ($ldap->count()){
526 $attrs= $ldap->fetch();
527 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
528 'LOGIN' => $attrs['goLogAdmin'][0],
529 'PASSWORD' => $attrs['goLogPassword'][0]);
530 }
533 /* GOsa logging databases */
534 $ldap->cd ($this->current['BASE']);
535 $ldap->search ("(objectClass=gosaLogServer)");
536 if ($ldap->count()){
537 while($attrs= $ldap->fetch()){
538 $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]=
539 array(
540 'DN' => $attrs['dn'],
541 'USER' => $attrs['goLogDBUser'][0],
542 'DB' => $attrs['goLogDB'][0],
543 'PWD' => $attrs['goLogDBPassword'][0]);
544 }
545 }
548 /* Get NFS server lists */
549 $tmp= array("default");
550 $ldap->cd ($this->current['BASE']);
551 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
552 while ($attrs= $ldap->fetch()){
553 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
554 if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
555 continue;
556 }
557 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
558 $tmp[]= $attrs["cn"][0].":$path";
559 }
560 }
561 $this->data['SERVERS']['NFS']= $tmp;
563 /* Load Terminalservers */
564 $ldap->cd ($this->current['BASE']);
565 $ldap->search ("(objectClass=goTerminalServer)",array("cn","gotoSessionType"));
566 $this->data['SERVERS']['TERMINAL']= array();
567 $this->data['SERVERS']['TERMINAL'][]= "default";
568 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'] = array();
571 while ($attrs= $ldap->fetch()){
572 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
573 if(isset( $attrs["gotoSessionType"]['count'])){
574 for($i =0 ; $i < $attrs["gotoSessionType"]['count'] ; $i++){
575 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'][$attrs["cn"][0]][] = $attrs["gotoSessionType"][$i];
576 }
577 }
578 }
580 /* Ldap Server */
581 $this->data['SERVERS']['LDAP']= array();
582 $ldap->cd ($this->current['BASE']);
583 $ldap->search ("(objectClass=goLdapServer)");
584 while ($attrs= $ldap->fetch()){
585 if (isset($attrs["goLdapBase"])){
586 for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
587 $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
588 }
589 }
590 }
592 /* Get misc server lists */
593 $this->data['SERVERS']['SYSLOG']= array("default");
594 $this->data['SERVERS']['NTP']= array("default");
595 $ldap->cd ($this->current['BASE']);
596 $ldap->search ("(objectClass=goNtpServer)");
597 while ($attrs= $ldap->fetch()){
598 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
599 }
600 $ldap->cd ($this->current['BASE']);
601 $ldap->search ("(objectClass=goSyslogServer)");
602 while ($attrs= $ldap->fetch()){
603 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
604 }
606 /* Get samba servers from LDAP, in case of samba3 */
607 if ($this->current['SAMBAVERSION'] == 3){
608 $this->data['SERVERS']['SAMBA']= array();
609 $ldap->cd ($this->current['BASE']);
610 $ldap->search ("(objectClass=sambaDomain)");
611 while ($attrs= $ldap->fetch()){
612 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
613 if(isset($attrs["sambaSID"][0])){
614 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0];
615 }
616 if(isset($attrs["sambaAlgorithmicRidBase"][0])){
617 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
618 }
619 }
621 /* If no samba servers are found, look for configured sid/ridbase */
622 if (count($this->data['SERVERS']['SAMBA']) == 0){
623 if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
624 msg_dialog::display(_("Configuration error"), _("SID and/or RIDBASE missing in the configuration!"), FATAL_ERROR_DIALOG);
625 exit();
626 } else {
627 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
628 "SID" => $this->current["SID"],
629 "RIDBASE" => $this->current["RIDBASE"]);
630 }
631 }
632 }
633 }
636 function get_departments($ignore_dn= "")
637 {
638 global $config;
640 /* Initialize result hash */
641 $result= array();
642 $administrative= array();
643 $result['/']= $this->current['BASE'];
644 $this->tdepartments= array();
646 /* Get all department types from department Management, to be able detect the department type.
647 -It is possible that differnty department types have the same name,
648 in this case we have to mark the department name to be able to differentiate.
649 (e.g l=Name or o=Name)
650 */
651 $types = departmentManagement::get_support_departments();
653 /* Create a list of attributes to fetch */
654 $ldap_values = array("objectClass","gosaUnitTag");
655 $filter = "";
656 foreach($types as $type){
657 $ldap_values[] = $type['ATTR'];
658 $filter .= "(objectClass=".$type['OC'].")";
659 }
660 $filter = "(&(objectClass=gosaDepartment)(|".$filter."))";
662 /* Get list of department objects */
663 $ldap= $this->get_ldap_link();
664 $ldap->cd ($this->current['BASE']);
665 $ldap->search ($filter, $ldap_values);
666 while ($attrs= $ldap->fetch()){
668 /* Detect department type */
669 $type_data = array();
670 foreach($types as $t => $data){
671 if(in_array($data['OC'],$attrs['objectClass'])){
672 $type_data = $data;
673 break;
674 }
675 }
677 /* Unknown department type -> skip
678 */
679 if(!count($type_data)) continue;
681 $dn= $ldap->getDN();
682 $this->tdepartments[$dn]= "";
684 /* Save administrative departments */
685 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
686 isset($attrs['gosaUnitTag'][0])){
687 $administrative[$dn]= $attrs['gosaUnitTag'][0];
688 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
689 }
691 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
692 isset($attrs['gosaUnitTag'][0])){
693 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
694 }
696 if ($dn == $ignore_dn){
697 continue;
698 }
700 $c_dn = convert_department_dn($dn)." (".$type_data['ATTR'].")";
702 /* Only assign non-root departments */
703 if ($dn != $result['/']){
704 $result[$c_dn]= $dn;
705 }
706 }
708 $this->adepartments= $administrative;
709 $this->departments= $result;
710 }
713 function make_idepartments($max_size= 28)
714 {
715 global $config;
716 $base = $config->current['BASE'];
718 $arr = array();
719 $ui= get_userinfo();
721 $this->idepartments= array();
723 /* Create multidimensional array, with all departments. */
724 foreach ($this->departments as $key => $val){
726 /* When using strict_units, filter non relevant parts */
727 if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
728 if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
729 $this->tdepartments[$val] != $ui->gosaUnitTag){
730 # continue;
731 }
732 }
734 /* Split dn into single department pieces.
735 */
736 $elements = array_reverse(split(",",preg_replace("/".normalizePreg($base)."$/","",$val)));
738 /* Add last ou element of current dn to our array */
739 $last = &$arr;
740 foreach($elements as $key => $ele){
742 /* skip empty */
743 if(empty($ele)) continue;
745 /* Extract department name */
746 $elestr = trim(preg_replace("/^[^=]*+=/","", $ele),",");
747 $nameA = trim(preg_replace("/=.*$/","", $ele),",");
748 if($nameA != "ou"){
749 $nameA = " (".$nameA.")";
750 }else{
751 $nameA = "";
752 }
755 /* Add to array */
756 if($key == (count($elements)-1)){
757 $last[$elestr.$nameA]['ENTRY'] = $val;
758 }
760 /* Set next array appending position */
761 $last = &$last[$elestr.$nameA]['SUB'];
762 }
763 }
766 /* Add base entry */
767 $ret["/"]["ENTRY"] = $base;
768 $ret["/"]["SUB"] = $arr;
769 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
770 }
773 /* Creates display friendly output from make_idepartments */
774 function generateDepartmentArray($arr,$depth = -1,$max_size)
775 {
776 $ret = array();
777 $depth ++;
779 /* Walk through array */
780 ksort($arr);
781 foreach($arr as $name => $entries){
783 /* If this department is the last in the current tree position
784 * remove it, to avoid generating output for it */
785 if(count($entries['SUB'])==0){
786 unset($entries['SUB']);
787 }
789 /* Fix name, if it contains a replace tag */
790 $name= @LDAP::fix($name);
792 /* Check if current name is too long, then cut it */
793 if(mb_strlen($name, 'UTF-8')> $max_size){
794 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
795 }
797 /* Append the name to the list */
798 if(isset($entries['ENTRY'])){
799 $a = "";
800 for($i = 0 ; $i < $depth ; $i ++){
801 $a.=".";
802 }
803 $ret[$entries['ENTRY']]=$a." ".$name;
804 }
806 /* recursive add of subdepartments */
807 if(isset($entries['SUB'])){
808 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
809 }
810 }
812 return($ret);
813 }
815 /* This function returns all available Shares defined in this ldap
816 * There are two ways to call this function, if listboxEntry is true
817 * only name and path are attached to the array, in it is false, the whole
818 * entry will be parsed an atached to the result.
819 */
820 function getShareList($listboxEntry = false)
821 {
822 $tmp = get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",get_ou("serverou"),
823 $this->current['BASE'],array("goExportEntry","cn"), GL_NONE);
824 $return =array();
825 foreach($tmp as $entry){
827 if(isset($entry['goExportEntry']['count'])){
828 unset($entry['goExportEntry']['count']);
829 }
830 if(isset($entry['goExportEntry'])){
831 foreach($entry['goExportEntry'] as $export){
832 $shareAttrs = split("\|",$export);
833 if($listboxEntry) {
834 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
835 }else{
836 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
837 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
838 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
839 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
840 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
841 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
842 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
843 }
844 }
845 }
846 }
847 return($return);
848 }
851 /* This function returns all available ShareServer */
852 function getShareServerList()
853 {
854 global $config;
855 $return = array();
856 $ui = get_userinfo();
857 $base = $config->current['BASE'];
858 $res= get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server",
859 get_ou("serverou"), $base,array("goExportEntry","cn"),GL_NONE | GL_NO_ACL_CHECK);
861 foreach($res as $entry){
863 $acl = $ui->get_permissions($entry['dn'],"server/goShareServer","");
864 if(isset($entry['goExportEntry']['count'])){
865 unset($entry['goExportEntry']['count']);
866 }
867 foreach($entry['goExportEntry'] as $share){
868 $a_share = split("\|",$share);
869 $sharename = $a_share[0];
870 $data= array();
871 $data['NAME'] = $sharename;
872 $data['ACL'] = $acl;
873 $data['SERVER'] = $entry['cn']['0'];
874 $data['SHARE'] = $sharename;
875 $data['DISPLAY']= $entry['cn'][0]." [".$sharename."]";
876 $return[$entry['cn'][0]."|".$sharename] = $data;
877 }
878 }
879 return($return);
880 }
883 /* Check if there's the specified bool value set in the configuration */
884 function boolValueIsTrue($section, $value)
885 {
886 $section= strtoupper($section);
887 $value= strtoupper($value);
888 if (isset($this->data[$section][$value])){
890 $data= $this->data[$section][$value];
891 if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
892 return TRUE;
893 }
895 }
897 return FALSE;
898 }
901 function __search(&$arr, $name, $return)
902 {
903 $return= strtoupper($return);
904 if (is_array($arr)){
905 foreach ($arr as &$a){
906 if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
907 return(isset($a[$return])?$a[$return]:"");
908 } else {
909 $res= $this->__search ($a, $name, $return);
910 if ($res != ""){
911 return $res;
912 }
913 }
914 }
915 }
916 return ("");
917 }
920 function search($class, $value, $categories= "")
921 {
922 if (is_array($categories)){
923 foreach ($categories as $category){
924 $res= $this->__search($this->data[strtoupper($category)], $class, $value);
925 if ($res != ""){
926 return $res;
927 }
928 }
929 } else {
930 if ($categories == "") {
931 return $this->__search($this->data, $class, $value);
932 } else {
933 return $this->__search($this->data[strtoupper($categories)], $class, $value);
934 }
935 }
937 return ("");
938 }
941 function check_config_version()
942 {
943 /* Skip check, if we've already mentioned the mismatch
944 */
945 if(session::is_set("LastChecked") && session::get("LastChecked") == $this->config_version) return;
947 /* Remember last checked version
948 */
949 session::set("LastChecked",$this->config_version);
951 $current = md5(file_get_contents(CONFIG_TEMPLATE_DIR."/gosa.conf"));
953 /* Check contributed config version and current config version.
954 */
955 if($this->config_version != $current && !empty($this->config_version)){
956 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."));
957 }
958 }
961 /* On debian systems the session files are deleted with
962 * a cronjob, which detects all files older than specified
963 * in php.ini:'session.gc_maxlifetime' and removes them.
964 * This function checks if the gosa.conf value matches the range
965 * defined by session.gc_maxlifetime.
966 */
967 function check_session_lifetime()
968 {
969 $cfg_lifetime = $this->data['MAIN']['SESSION_LIFETIME'];
970 $ini_lifetime = ini_get('session.gc_maxlifetime');
971 $deb_system = file_exists('/etc/debian_version');
972 return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));
973 }
974 }
976 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
977 ?>