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 {
73 if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
75 $this->config_found= FALSE;
76 $this->tags= array();
77 $this->level= 0;
78 $this->gpc= 0;
79 $this->section= "";
80 $this->currentLocation= "";
82 $this->parser = xml_parser_create();
83 xml_set_object($this->parser, $this);
84 xml_set_element_handler($this->parser, "tag_open", "tag_close");
85 $this->parse($this->filename);
86 # if(session::is_set('plist')){
87 # session::un_set('plist');
88 # }
89 # if(session::is_set('plug')){
90 # session::un_set('plug');
91 # }
92 # if(isset($_GET['plug'])){
93 # unset($_GET['plug']);
94 # }
95 }
96 }
99 function parse($filename)
100 {
101 $this->last_modified = filemtime($filename);
102 $this->filename = $filename;
103 $fh= fopen($filename, "r");
104 $xmldata= fread($fh, 100000);
105 fclose($fh);
106 if(!xml_parse($this->parser, chop($xmldata))){
107 $msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
108 xml_error_string(xml_get_error_code($this->parser)),
109 xml_get_current_line_number($this->parser));
110 msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG);
111 exit;
112 }
113 }
115 function tag_open($parser, $tag, $attrs)
116 {
117 /* Save last and current tag for reference */
118 $this->tags[$this->level]= $tag;
119 $this->level++;
121 /* Trigger on CONF section */
122 if ($tag == 'CONF'){
123 $this->config_found= TRUE;
124 if(isset($attrs['CONFIG_VERSION'])){
125 $this->config_version = $attrs['CONFIG_VERSION'];
126 }
127 }
129 /* Return if we're not in config section */
130 if (!$this->config_found){
131 return;
132 }
134 /* yes/no to true/false and upper case TRUE to true and so on*/
135 foreach($attrs as $name => $value){
136 if(preg_match("/^(true|yes)$/i",$value)){
137 $attrs[$name] = "true";
138 }elseif(preg_match("/^(false|no)$/i",$value)){
139 $attrs[$name] = "false";
140 }
141 }
143 /* Look through attributes */
144 switch ($this->tags[$this->level-1]){
147 /* Handle tab section */
148 case 'TAB': $name= $this->tags[$this->level-2];
150 /* Create new array? */
151 if (!isset($this->data['TABS'][$name])){
152 $this->data['TABS'][$name]= array();
153 }
155 /* Add elements */
156 $this->data['TABS'][$name][]= $attrs;
157 break;
159 /* Handle location */
160 case 'LOCATION':
161 if ($this->tags[$this->level-2] == 'MAIN'){
162 $name= $attrs['NAME'];
163 $name = preg_replace("/[<>\"']/","",$name);
164 $attrs['NAME'] = $name;
165 $this->currentLocation= $name;
167 /* Add location elements */
168 $this->data['LOCATIONS'][$name]= $attrs;
169 }
170 break;
172 /* Handle referral tags */
173 case 'REFERRAL':
174 if ($this->tags[$this->level-2] == 'LOCATION'){
175 $url= $attrs['URL'];
176 $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
178 /* Add location elements */
179 if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
180 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
181 }
183 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
184 }
185 break;
187 /* Load main parameters */
188 case 'MAIN':
189 $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
190 break;
192 /* Load menu */
193 case 'SECTION':
194 if ($this->tags[$this->level-2] == 'MENU'){
195 $this->section= $attrs['NAME'];
196 $this->data['MENU'][$this->section]= array(); ;
197 }
198 break;
200 /* Inser plugins */
201 case 'PLUGIN':
202 if ($this->tags[$this->level-3] == 'MENU' &&
203 $this->tags[$this->level-2] == 'SECTION'){
205 $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
206 }
207 if ($this->tags[$this->level-2] == 'SERVICEMENU'){
208 $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
209 }
210 break;
211 }
212 }
214 function tag_close($parser, $tag)
215 {
216 /* Close config section */
217 if ($tag == 'CONF'){
218 $this->config_found= FALSE;
219 }
220 $this->level--;
221 }
224 function get_credentials($creds)
225 {
226 if (isset($_SERVER['HTTP_GOSA_KEY'])){
227 return (cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY']));
228 }
229 return ($creds);
230 }
233 function get_ldap_link($sizelimit= FALSE)
234 {
235 if($this->ldap === NULL || !is_resource($this->ldap->cid)){
237 /* Build new connection */
238 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
239 $this->current['ADMIN'], $this->get_credentials($this->current['PASSWORD']));
241 /* Check for connection */
242 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
243 $smarty= get_smarty();
244 msg_dialog::display(_("LDAP error"), _("Cannot bind to LDAP. Please contact the system administrator."), FATAL_ERROR_DIALOG);
245 exit();
246 }
248 if (!session::is_set('size_limit')){
249 session::set('size_limit',$this->current['SIZELIMIT']);
250 session::set('size_ignore',$this->current['SIZEIGNORE']);
251 }
253 if ($sizelimit){
254 $this->ldap->set_size_limit(session::get('size_limit'));
255 } else {
256 $this->ldap->set_size_limit(0);
257 }
259 /* Move referrals */
260 if (!isset($this->current['REFERRAL'])){
261 $this->ldap->referrals= array();
262 } else {
263 $this->ldap->referrals= $this->current['REFERRAL'];
264 }
265 }
267 return new ldapMultiplexer($this->ldap);
268 }
270 function set_current($name)
271 {
272 $this->current= $this->data['LOCATIONS'][$name];
274 if (!isset($this->current['PEOPLE'])){
275 $this->current['PEOPLE']= "ou=people";
276 }
277 if (!isset($this->current['GROUPS'])){
278 $this->current['GROUPS']= "ou=groups";
279 }
281 if (isset($this->current['INITIAL_BASE'])){
282 session::set('CurrentMainBase',$this->current['INITIAL_BASE']);
283 }
285 /* Remove possibly added ',' from end of group and people ou */
286 $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
287 $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
289 if (!isset($this->current['WINSTATIONS'])){
290 $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
291 }
292 if (!isset($this->current['HASH'])){
293 $this->current['HASH']= "crypt";
294 }
295 if (!isset($this->current['DNMODE'])){
296 $this->current['DNMODE']= "cn";
297 }
298 if (!isset($this->current['MINID'])){
299 $this->current['MINID']= 100;
300 }
301 if (!isset($this->current['SIZELIMIT'])){
302 $this->current['SIZELIMIT']= 200;
303 }
304 if (!isset($this->current['SIZEINGORE'])){
305 $this->current['SIZEIGNORE']= TRUE;
306 } else {
307 if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
308 $this->current['SIZEIGNORE']= TRUE;
309 } else {
310 $this->current['SIZEIGNORE']= FALSE;
311 }
312 }
314 /* Sort referrals, if present */
315 if (isset ($this->current['REFERRAL'])){
316 $bases= array();
317 $servers= array();
318 foreach ($this->current['REFERRAL'] as $ref){
319 $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
320 $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
321 $bases[$base]= strlen($base);
322 $servers[$base]= $server;
323 }
324 asort($bases);
325 reset($bases);
326 }
328 /* SERVER not defined? Load the one with the shortest base */
329 if (!isset($this->current['SERVER'])){
330 $this->current['SERVER']= $servers[key($bases)];
331 }
333 /* BASE not defined? Load the one with the shortest base */
334 if (!isset($this->current['BASE'])){
335 $this->current['BASE']= key($bases);
336 }
338 /* Convert BASE to have escaped special characters */
339 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
341 /* Parse LDAP referral informations */
342 if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
343 $url= $this->current['SERVER'];
344 $referral= $this->current['REFERRAL'][$url];
345 $this->current['ADMIN']= $referral['ADMIN'];
346 $this->current['PASSWORD']= $referral['PASSWORD'];
347 }
349 /* Load server informations */
350 $this->load_servers();
351 }
353 function load_servers ()
354 {
355 /* Only perform actions if current is set */
356 if ($this->current === NULL){
357 return;
358 }
360 /* Fill imap servers */
361 $ldap= $this->get_ldap_link();
362 $ldap->cd ($this->current['BASE']);
363 if (!isset($this->current['MAILMETHOD'])){
364 $this->current['MAILMETHOD']= "";
365 }
366 if ($this->current['MAILMETHOD'] == ""){
367 $ldap->search ("(objectClass=goMailServer)", array('cn'));
368 $this->data['SERVERS']['IMAP']= array();
369 error_reporting(0);
370 while ($attrs= $ldap->fetch()){
371 $name= $attrs['cn'][0];
372 $this->data['SERVERS']['IMAP'][$name]= $name;
373 }
374 error_reporting(E_ALL);
375 } else {
376 $ldap->search ("(&(objectClass=goImapServer)(goImapSieveServer=*))",
377 array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
378 'goImapSieveServer', 'goImapSievePort'));
380 $this->data['SERVERS']['IMAP']= array();
382 while ($attrs= $ldap->fetch()){
384 /* Check if the given goImapSieveServer is in the new style "{cn:port/option}"
385 or the old style just "cn".
386 */
387 if(preg_match("/\{/",$attrs['goImapSieveServer'][0])){
388 $sieve_server = preg_replace("/^\{([^:]*).*$/","\\1",$attrs['goImapSieveServer'][0]);
389 $sieve_option = preg_replace("/^[^:]*[^\/]*+\/(.*)\}$/","\\1",$attrs['goImapSieveServer'][0]);
390 }else{
391 $sieve_server = $attrs['goImapSieveServer'][0];
392 $sieve_option = "";
393 }
395 $pwd = $attrs['goImapPassword'][0];
396 $imap_admin = $attrs['goImapAdmin'][0];
397 $imap_connect = $attrs['goImapConnect'][0];
398 $imap_server = $attrs['goImapName'][0];
399 $sieve_port = $attrs['goImapSievePort'][0];
401 $this->data['SERVERS']['IMAP'][$imap_server]=
402 array(
403 "connect" => $imap_connect,
404 "admin" => $imap_admin,
405 "password" => $pwd,
406 "sieve_server"=> $sieve_server,
407 "sieve_option"=> $sieve_option,
408 "sieve_port" => $sieve_port);
409 }
410 }
412 /* Get kerberos server. FIXME: only one is supported currently */
413 $ldap->cd ($this->current['BASE']);
414 $ldap->search ("(&(goKrbRealm=*)(goKrbAdmin=*)(objectClass=goKrbServer))");
415 if ($ldap->count()){
416 $attrs= $ldap->fetch();
417 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
418 'REALM' => $attrs['goKrbRealm'][0],
419 'ADMIN' => $attrs['goKrbAdmin'][0]);
420 }
422 /* Get cups server. FIXME: only one is supported currently */
423 $ldap->cd ($this->current['BASE']);
424 $ldap->search ("(objectClass=goCupsServer)");
425 if ($ldap->count()){
426 $attrs= $ldap->fetch();
427 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
428 }
430 /* Get fax server. FIXME: only one is supported currently */
431 $ldap->cd ($this->current['BASE']);
432 $ldap->search ("(objectClass=goFaxServer)");
433 if ($ldap->count()){
434 $attrs= $ldap->fetch();
435 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
436 'LOGIN' => $attrs['goFaxAdmin'][0],
437 'PASSWORD' => $attrs['goFaxPassword'][0]);
438 }
441 /* Get asterisk servers */
442 $ldap->cd ($this->current['BASE']);
443 $ldap->search ("(objectClass=goFonServer)");
444 $this->data['SERVERS']['FON']= array();
445 if ($ldap->count()){
446 while ($attrs= $ldap->fetch()){
448 /* Add 0 entry for development */
449 if(count($this->data['SERVERS']['FON']) == 0){
450 $this->data['SERVERS']['FON'][0]= array(
451 'DN' => $attrs['dn'],
452 'SERVER' => $attrs['cn'][0],
453 'LOGIN' => $attrs['goFonAdmin'][0],
454 'PASSWORD' => $attrs['goFonPassword'][0],
455 'DB' => "gophone",
456 'SIP_TABLE' => "sip_users",
457 'EXT_TABLE' => "extensions",
458 'VOICE_TABLE' => "voicemail_users",
459 'QUEUE_TABLE' => "queues",
460 'QUEUE_MEMBER_TABLE' => "queue_members");
461 }
463 /* Add entry with 'dn' as index */
464 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
465 'DN' => $attrs['dn'],
466 'SERVER' => $attrs['cn'][0],
467 'LOGIN' => $attrs['goFonAdmin'][0],
468 'PASSWORD' => $attrs['goFonPassword'][0],
469 'DB' => "gophone",
470 'SIP_TABLE' => "sip_users",
471 'EXT_TABLE' => "extensions",
472 'VOICE_TABLE' => "voicemail_users",
473 'QUEUE_TABLE' => "queues",
474 'QUEUE_MEMBER_TABLE' => "queue_members");
475 }
476 }
479 /* Get glpi server */
480 $ldap->cd ($this->current['BASE']);
481 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
482 if ($ldap->count()){
483 $attrs= $ldap->fetch();
484 if(!isset($attrs['goGlpiPassword'])){
485 $attrs['goGlpiPassword'][0] ="";
486 }
487 $this->data['SERVERS']['GLPI']= array(
488 'SERVER' => $attrs['cn'][0],
489 'LOGIN' => $attrs['goGlpiAdmin'][0],
490 'PASSWORD' => $attrs['goGlpiPassword'][0],
491 'DB' => $attrs['goGlpiDatabase'][0]);
492 }
495 /* Get logdb server */
496 $ldap->cd ($this->current['BASE']);
497 $ldap->search ("(objectClass=goLogDBServer)");
498 if ($ldap->count()){
499 $attrs= $ldap->fetch();
500 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
501 'LOGIN' => $attrs['goLogAdmin'][0],
502 'PASSWORD' => $attrs['goLogPassword'][0]);
503 }
506 /* GOsa logging databases */
507 $ldap->cd ($this->current['BASE']);
508 $ldap->search ("(objectClass=gosaLogServer)");
509 if ($ldap->count()){
510 while($attrs= $ldap->fetch()){
511 $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]=
512 array(
513 'DN' => $attrs['dn'],
514 'USER' => $attrs['goLogDBUser'][0],
515 'DB' => $attrs['goLogDB'][0],
516 'PWD' => $attrs['goLogDBPassword'][0]);
517 }
518 }
521 /* Get NFS server lists */
522 $tmp= array("default");
523 $ldap->cd ($this->current['BASE']);
524 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
525 while ($attrs= $ldap->fetch()){
526 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
527 if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
528 continue;
529 }
530 $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
531 $tmp[]= $attrs["cn"][0].":$path";
532 }
533 }
534 $this->data['SERVERS']['NFS']= $tmp;
536 /* Load Terminalservers */
537 $ldap->cd ($this->current['BASE']);
538 $ldap->search ("(objectClass=goTerminalServer)",array("cn","gotoSessionType"));
539 $this->data['SERVERS']['TERMINAL']= array();
540 $this->data['SERVERS']['TERMINAL'][]= "default";
541 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'] = array();
544 while ($attrs= $ldap->fetch()){
545 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
546 if(isset( $attrs["gotoSessionType"]['count'])){
547 for($i =0 ; $i < $attrs["gotoSessionType"]['count'] ; $i++){
548 $this->data['SERVERS']['TERMINAL_SESSION_TYPES'][$attrs["cn"][0]][] = $attrs["gotoSessionType"][$i];
549 }
550 }
551 }
553 /* Ldap Server */
554 $this->data['SERVERS']['LDAP']= array();
555 $ldap->cd ($this->current['BASE']);
556 $ldap->search ("(objectClass=goLdapServer)");
557 while ($attrs= $ldap->fetch()){
558 if (isset($attrs["goLdapBase"])){
559 for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
560 $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
561 }
562 }
563 }
565 /* Get misc server lists */
566 $this->data['SERVERS']['SYSLOG']= array("default");
567 $this->data['SERVERS']['NTP']= array("default");
568 $ldap->cd ($this->current['BASE']);
569 $ldap->search ("(objectClass=goNtpServer)");
570 while ($attrs= $ldap->fetch()){
571 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
572 }
573 $ldap->cd ($this->current['BASE']);
574 $ldap->search ("(objectClass=goSyslogServer)");
575 while ($attrs= $ldap->fetch()){
576 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
577 }
579 /* Get samba servers from LDAP, in case of samba3 */
580 if ($this->current['SAMBAVERSION'] == 3){
581 $this->data['SERVERS']['SAMBA']= array();
582 $ldap->cd ($this->current['BASE']);
583 $ldap->search ("(objectClass=sambaDomain)");
584 while ($attrs= $ldap->fetch()){
585 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>"");
586 if(isset($attrs["sambaSID"][0])){
587 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0];
588 }
589 if(isset($attrs["sambaAlgorithmicRidBase"][0])){
590 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0];
591 }
592 }
594 /* If no samba servers are found, look for configured sid/ridbase */
595 if (count($this->data['SERVERS']['SAMBA']) == 0){
596 if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
597 msg_dialog::display(_("Configuration error"), _("SID and/or RIDBASE missing in the configuration!"), FATAL_ERROR_DIALOG);
598 exit();
599 } else {
600 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
601 "SID" => $this->current["SID"],
602 "RIDBASE" => $this->current["RIDBASE"]);
603 }
604 }
605 }
606 }
609 function get_departments($ignore_dn= "")
610 {
611 global $config;
613 /* Initialize result hash */
614 $result= array();
615 $administrative= array();
616 $result['/']= $this->current['BASE'];
617 $this->tdepartments= array();
619 /* Get all department types from department Management, to be able detect the department type.
620 -It is possible that differnty department types have the same name,
621 in this case we have to mark the department name to be able to differentiate.
622 (e.g l=Name or o=Name)
623 */
624 $types = departmentManagement::get_support_departments();
626 /* Create a list of attributes to fetch */
627 $ldap_values = array("objectClass","gosaUnitTag");
628 $filter = "";
629 foreach($types as $type){
630 $ldap_values[] = $type['ATTR'];
631 $filter .= "(objectClass=".$type['OC'].")";
632 }
633 $filter = "(&(objectClass=gosaDepartment)(|".$filter."))";
635 /* Get list of department objects */
636 $ldap= $this->get_ldap_link();
637 $ldap->cd ($this->current['BASE']);
638 $ldap->search ($filter, $ldap_values);
639 while ($attrs= $ldap->fetch()){
641 /* Detect department type */
642 $type_data = array();
643 foreach($types as $t => $data){
644 if(in_array($data['OC'],$attrs['objectClass'])){
645 $type_data = $data;
646 break;
647 }
648 }
650 /* Unknown department type -> skip
651 */
652 if(!count($type_data)) continue;
654 $dn= $ldap->getDN();
655 $this->tdepartments[$dn]= "";
657 /* Save administrative departments */
658 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
659 isset($attrs['gosaUnitTag'][0])){
660 $administrative[$dn]= $attrs['gosaUnitTag'][0];
661 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
662 }
664 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
665 isset($attrs['gosaUnitTag'][0])){
666 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
667 }
669 if ($dn == $ignore_dn){
670 continue;
671 }
673 $c_dn = convert_department_dn($dn)." (".$type_data['ATTR'].")";
675 /* Only assign non-root departments */
676 if ($dn != $result['/']){
677 $result[$c_dn]= $dn;
678 }
679 }
681 $this->adepartments= $administrative;
682 $this->departments= $result;
683 }
686 function make_idepartments($max_size= 28)
687 {
688 global $config;
689 $base = $config->current['BASE'];
691 $arr = array();
692 $ui= get_userinfo();
694 $this->idepartments= array();
696 /* Create multidimensional array, with all departments. */
697 foreach ($this->departments as $key => $val){
699 /* When using strict_units, filter non relevant parts */
700 if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
701 if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
702 $this->tdepartments[$val] != $ui->gosaUnitTag){
703 # continue;
704 }
705 }
707 /* Split dn into single department pieces.
708 */
709 $elements = array_reverse(split(",",preg_replace("/".normalizePreg($base)."$/","",$val)));
711 /* Add last ou element of current dn to our array */
712 $last = &$arr;
713 foreach($elements as $key => $ele){
715 /* skip empty */
716 if(empty($ele)) continue;
718 /* Extract department name */
719 $elestr = trim(preg_replace("/^[^=]*+=/","", $ele),",");
720 $nameA = trim(preg_replace("/=.*$/","", $ele),",");
721 if($nameA != "ou"){
722 $nameA = " (".$nameA.")";
723 }else{
724 $nameA = "";
725 }
728 /* Add to array */
729 if($key == (count($elements)-1)){
730 $last[$elestr.$nameA]['ENTRY'] = $val;
731 }
733 /* Set next array appending position */
734 $last = &$last[$elestr.$nameA]['SUB'];
735 }
736 }
739 /* Add base entry */
740 $ret["/"]["ENTRY"] = $base;
741 $ret["/"]["SUB"] = $arr;
742 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
743 }
746 /* Creates display friendly output from make_idepartments */
747 function generateDepartmentArray($arr,$depth = -1,$max_size)
748 {
749 $ret = array();
750 $depth ++;
752 /* Walk through array */
753 ksort($arr);
754 foreach($arr as $name => $entries){
756 /* If this department is the last in the current tree position
757 * remove it, to avoid generating output for it */
758 if(count($entries['SUB'])==0){
759 unset($entries['SUB']);
760 }
762 /* Fix name, if it contains a replace tag */
763 $name= @LDAP::fix($name);
765 /* Check if current name is too long, then cut it */
766 if(mb_strlen($name, 'UTF-8')> $max_size){
767 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
768 }
770 /* Append the name to the list */
771 if(isset($entries['ENTRY'])){
772 $a = "";
773 for($i = 0 ; $i < $depth ; $i ++){
774 $a.=".";
775 }
776 $ret[$entries['ENTRY']]=$a." ".$name;
777 }
779 /* recursive add of subdepartments */
780 if(isset($entries['SUB'])){
781 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
782 }
783 }
785 return($ret);
786 }
788 /* This function returns all available Shares defined in this ldap
789 * There are two ways to call this function, if listboxEntry is true
790 * only name and path are attached to the array, in it is false, the whole
791 * entry will be parsed an atached to the result.
792 */
793 function getShareList($listboxEntry = false)
794 {
795 $tmp = get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",get_ou("serverou"),
796 $this->current['BASE'],array("goExportEntry","cn"), GL_NONE);
797 $return =array();
798 foreach($tmp as $entry){
800 if(isset($entry['goExportEntry']['count'])){
801 unset($entry['goExportEntry']['count']);
802 }
803 if(isset($entry['goExportEntry'])){
804 foreach($entry['goExportEntry'] as $export){
805 $shareAttrs = split("\|",$export);
806 if($listboxEntry) {
807 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
808 }else{
809 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
810 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
811 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
812 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
813 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
814 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
815 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
816 }
817 }
818 }
819 }
820 return($return);
821 }
824 /* This function returns all available ShareServer */
825 function getShareServerList()
826 {
827 global $config;
828 $return = array();
829 $ui = get_userinfo();
830 $base = $config->current['BASE'];
831 $res= get_sub_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server",
832 get_ou("serverou"), $base,array("goExportEntry","cn"),GL_NONE | GL_NO_ACL_CHECK);
834 foreach($res as $entry){
836 $acl = $ui->get_permissions($entry['dn'],"server/goShareServer","");
837 if(isset($entry['goExportEntry']['count'])){
838 unset($entry['goExportEntry']['count']);
839 }
840 foreach($entry['goExportEntry'] as $share){
841 $a_share = split("\|",$share);
842 $sharename = $a_share[0];
843 $data= array();
844 $data['NAME'] = $sharename;
845 $data['ACL'] = $acl;
846 $data['SERVER'] = $entry['cn']['0'];
847 $data['SHARE'] = $sharename;
848 $data['DISPLAY']= $entry['cn'][0]." [".$sharename."]";
849 $return[$entry['cn'][0]."|".$sharename] = $data;
850 }
851 }
852 return($return);
853 }
856 /* Check if there's the specified bool value set in the configuration */
857 function boolValueIsTrue($section, $value)
858 {
859 $section= strtoupper($section);
860 $value= strtoupper($value);
861 if (isset($this->data[$section][$value])){
863 $data= $this->data[$section][$value];
864 if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
865 return TRUE;
866 }
868 }
870 return FALSE;
871 }
874 function __search(&$arr, $name, $return)
875 {
876 $return= strtoupper($return);
877 if (is_array($arr)){
878 foreach ($arr as &$a){
879 if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
880 return(isset($a[$return])?$a[$return]:"");
881 } else {
882 $res= $this->__search ($a, $name, $return);
883 if ($res != ""){
884 return $res;
885 }
886 }
887 }
888 }
889 return ("");
890 }
893 function search($class, $value, $categories= "")
894 {
895 if (is_array($categories)){
896 foreach ($categories as $category){
897 $res= $this->__search($this->data[strtoupper($category)], $class, $value);
898 if ($res != ""){
899 return $res;
900 }
901 }
902 } else {
903 if ($categories == "") {
904 return $this->__search($this->data, $class, $value);
905 } else {
906 return $this->__search($this->data[strtoupper($categories)], $class, $value);
907 }
908 }
910 return ("");
911 }
914 function check_config_version()
915 {
916 /* Skip check, if we've already mentioned the mismatch
917 */
918 if(session::is_set("LastChecked") && session::get("LastChecked") == $this->config_version) return;
920 /* Remember last checked version
921 */
922 session::set("LastChecked",$this->config_version);
924 $current = md5(file_get_contents(CONFIG_TEMPLATE_DIR."/gosa.conf"));
926 /* Check contributed config version and current config version.
927 */
928 if($this->config_version != $current && !empty($this->config_version)){
929 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."));
930 }
931 }
934 /* On debian systems the session files are deleted with
935 * a cronjob, which detects all files older than specified
936 * in php.ini:'session.gc_maxlifetime' and removes them.
937 * This function checks if the gosa.conf value matches the range
938 * defined by session.gc_maxlifetime.
939 */
940 function check_session_lifetime()
941 {
942 $cfg_lifetime = $this->data['MAIN']['SESSION_LIFETIME'];
943 $ini_lifetime = ini_get('session.gc_maxlifetime');
944 $deb_system = file_exists('/etc/debian_version');
945 return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));
946 }
947 }
949 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
950 ?>