1 <?php
2 /*
3 * This code is part of GOsa (https://gosa.gonicus.de)
4 * Copyright (C) 2003-2006 - Cajus Pollmeier <pollmeier@gonicus.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 class config {
23 /* XML parser */
24 var $parser;
25 var $config_found= FALSE;
26 var $tags= array();
27 var $level= 0;
28 var $gpc= 0;
29 var $section= "";
30 var $currentLocation= "";
32 /* Selected connection */
33 var $current= array();
35 /* Link to LDAP-server */
36 var $ldap= NULL;
37 var $referrals= array();
39 /* Configuration data */
40 var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(),
41 'MAIN' => array( 'FAXFORMATS' => array() ),
42 'MENU' => array(), 'SERVICE' => array());
43 var $basedir= "";
45 /* Keep a copy of the current deparment list */
46 var $departments= array();
47 var $idepartments= array();
48 var $adepartments= array();
49 var $tdepartments= array();
51 function config($filename, $basedir= "")
52 {
53 $this->parser = xml_parser_create();
54 $this->basedir= $basedir;
56 xml_set_object($this->parser, $this);
57 xml_set_element_handler($this->parser, "tag_open", "tag_close");
59 /* Parse config file directly? */
60 if ($filename != ""){
61 $this->parse($filename);
62 }
63 }
65 function parse($filename)
66 {
67 $fh= fopen($filename, "r");
68 $xmldata= fread($fh, 100000);
69 fclose($fh);
70 if(!xml_parse($this->parser, chop($xmldata))){
71 print_red(sprintf(_("XML error in %s: %s at line %d"),
72 CONFIG_FILE,
73 xml_error_string(xml_get_error_code($this->parser)),
74 xml_get_current_line_number($this->parser)));
75 echo $_SESSION['errors'];
76 exit;
77 }
78 }
80 function tag_open($parser, $tag, $attrs)
81 {
82 /* Save last and current tag for reference */
83 $this->tags[$this->level]= $tag;
84 $this->level++;
86 /* Trigger on CONF section */
87 if ($tag == 'CONF'){
88 $this->config_found= TRUE;
89 }
91 /* Return if we're not in config section */
92 if (!$this->config_found){
93 return;
94 }
96 /* yes/no to true/false and upper case TRUE to true and so on*/
97 foreach($attrs as $name => $value){
98 if(preg_match("/^(true|yes)$/i",$value)){
99 $attrs[$name] = "true";
100 }elseif(preg_match("/^(false|no)$/i",$value)){
101 $attrs[$name] = "false";
102 }
103 }
105 /* Look through attributes */
106 switch ($this->tags[$this->level-1]){
108 /* Handle tab section */
109 case 'TAB': $name= $this->tags[$this->level-2];
111 /* Create new array? */
112 if (!isset($this->data['TABS'][$name])){
113 $this->data['TABS'][$name]= array();
114 }
116 /* Add elements */
117 $this->data['TABS'][$name][]= $attrs;
118 break;
120 /* Handle location */
121 case 'LOCATION':
122 if ($this->tags[$this->level-2] == 'MAIN'){
123 $name= $attrs['NAME'];
124 $this->currentLocation= $name;
126 /* Add location elements */
127 $this->data['LOCATIONS'][$name]= $attrs;
128 }
129 break;
131 /* Handle referral tags */
132 case 'REFERRAL':
133 if ($this->tags[$this->level-2] == 'LOCATION'){
134 $url= $attrs['URL'];
135 $server= preg_replace('!^([^:]+://[^/]+)/.*$!', '\\1', $url);
137 /* Add location elements */
138 if (!isset($this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'])){
139 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL']= array();
140 }
142 $this->data['LOCATIONS'][$this->currentLocation]['REFERRAL'][$server]= $attrs;
143 }
144 break;
146 /* Handle faxformat */
147 case 'FAXFORMAT':
148 if ($this->tags[$this->level-2] == 'MAIN'){
149 /* Add fax formats */
150 $this->data['MAIN']['FAXFORMATS'][]= $attrs['TYPE'];
151 }
152 break;
154 /* Load main parameters */
155 case 'MAIN':
156 $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
157 break;
159 /* Load menu */
160 case 'SECTION':
161 if ($this->tags[$this->level-2] == 'MENU'){
162 $this->section= $attrs['NAME'];
163 $this->data['MENU'][$this->section]= array(); ;
164 }
165 break;
167 /* Inser plugins */
168 case 'PLUGIN':
169 if ($this->tags[$this->level-3] == 'MENU' &&
170 $this->tags[$this->level-2] == 'SECTION'){
172 $this->data['MENU'][$this->section][$this->gpc++]= $attrs;
173 }
174 if ($this->tags[$this->level-2] == 'SERVICEMENU'){
175 $this->data['SERVICE'][$attrs['CLASS']]= $attrs;
176 }
177 break;
178 }
179 }
181 function tag_close($parser, $tag)
182 {
183 /* Close config section */
184 if ($tag == 'CONF'){
185 $this->config_found= FALSE;
186 }
187 $this->level--;
188 }
190 function get_ldap_link($sizelimit= FALSE)
191 {
192 /* Build new connection */
193 $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'],
194 $this->current['ADMIN'], $this->current['PASSWORD']);
196 /* Check for connection */
197 if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
198 $smarty= get_smarty();
199 print_red (_("Can't bind to LDAP. Please contact the system administrator."));
200 $smarty->display (get_template_path('headers.tpl'));
201 echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
202 exit();
203 }
205 if (!isset($_SESSION['size_limit'])){
206 $_SESSION['size_limit']= $this->current['SIZELIMIT'];
207 $_SESSION['size_ignore']= $this->current['SIZEIGNORE'];
208 }
210 if ($sizelimit){
211 $this->ldap->set_size_limit($_SESSION['size_limit']);
212 } else {
213 $this->ldap->set_size_limit(0);
214 }
216 /* Move referrals */
217 if (!isset($this->current['REFERRAL'])){
218 $this->ldap->referrals= array();
219 } else {
220 $this->ldap->referrals= $this->current['REFERRAL'];
221 }
223 return ($this->ldap);
224 }
226 function set_current($name)
227 {
228 $this->current= $this->data['LOCATIONS'][$name];
229 if (!isset($this->current['PEOPLE'])){
230 $this->current['PEOPLE']= "ou=people";
231 }
232 if (!isset($this->current['GROUPS'])){
233 $this->current['GROUPS']= "ou=groups";
234 }
236 if (isset($this->current['INITIAL_BASE'])){
237 $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
238 }
240 /* Remove possibly added ',' from end of group and people ou */
241 $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
242 $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
244 if (!isset($this->current['WINSTATIONS'])){
245 $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
246 }
247 if (!isset($this->current['HASH'])){
248 $this->current['HASH']= "crypt";
249 }
250 if (!isset($this->current['DNMODE'])){
251 $this->current['DNMODE']= "cn";
252 }
253 if (!isset($this->current['MINID'])){
254 $this->current['MINID']= 100;
255 }
256 if (!isset($this->current['SIZELIMIT'])){
257 $this->current['SIZELIMIT']= 200;
258 }
259 if (!isset($this->current['SIZEINGORE'])){
260 $this->current['SIZEIGNORE']= TRUE;
261 } else {
262 if (preg_match("/true/i", $this->current['SIZEIGNORE'])){
263 $this->current['SIZEIGNORE']= TRUE;
264 } else {
265 $this->current['SIZEIGNORE']= FALSE;
266 }
267 }
269 /* Sort referrals, if present */
270 if (isset ($this->current['REFERRAL'])){
271 $bases= array();
272 $servers= array();
273 foreach ($this->current['REFERRAL'] as $ref){
274 $server= preg_replace('%^(.*)/[^/]+$%', '\\1', $ref['URL']);
275 $base= preg_replace('%^.*/([^/]+)$%', '\\1', $ref['URL']);
276 $bases[$base]= strlen($base);
277 $servers[$base]= $server;
278 }
279 asort($bases);
280 reset($bases);
281 }
283 /* SERVER not defined? Load the one with the shortest base */
284 if (!isset($this->current['SERVER'])){
285 $this->current['SERVER']= $servers[key($bases)];
286 }
288 /* BASE not defined? Load the one with the shortest base */
289 if (!isset($this->current['BASE'])){
290 $this->current['BASE']= key($bases);
291 }
293 /* Convert BASE to have escaped special characters */
294 $this->current['BASE']= @LDAP::convert($this->current['BASE']);
296 /* Parse LDAP referral informations */
297 if (!isset($this->current['ADMIN']) || !isset($this->current['PASSWORD'])){
298 $url= $this->current['SERVER'];
299 $referral= $this->current['REFERRAL'][$url];
300 $this->current['ADMIN']= $referral['ADMIN'];
301 $this->current['PASSWORD']= $referral['PASSWORD'];
302 }
304 /* Possibly load kerberos style */
305 if (isset($this->current['KRBSASL'])){
306 if (preg_match('/^(yes|true)$/i', $this->current['KRBSASL'])){
307 $this->current['KRBSASL']= "sasl";
308 } else {
309 $this->current['KRBSASL']= "kerberos";
310 }
311 } else {
312 $this->current['KRBSASL']= "kerberos";
313 }
315 /* Load server informations */
316 $this->load_servers();
317 }
319 function load_servers ()
320 {
321 /* Only perform actions if current is set */
322 if ($this->current == NULL){
323 return;
324 }
326 /* Fill imap servers */
327 $ldap= $this->get_ldap_link();
328 $ldap->cd ($this->current['BASE']);
329 if (!isset($this->current['MAILMETHOD'])){
330 $this->current['MAILMETHOD']= "";
331 }
332 if ($this->current['MAILMETHOD'] == ""){
333 $ldap->search ("(objectClass=goMailServer)", array('cn'));
334 $this->data['SERVERS']['IMAP']= array();
335 error_reporting(0);
336 while ($attrs= $ldap->fetch()){
337 $name= $attrs['cn'][0];
338 $this->data['SERVERS']['IMAP'][$name]= $name;
339 }
340 error_reporting(E_ALL);
341 } else {
342 $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
343 'goImapSieveServer', 'goImapSievePort'));
345 $this->data['SERVERS']['IMAP']= array();
346 error_reporting(0);
347 while ($attrs= $ldap->fetch()){
348 $name= $attrs['goImapName'][0];
349 $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
350 "admin" => $attrs['goImapAdmin'][0],
351 "password" => $attrs['goImapPassword'][0],
352 "sieve_server" => $attrs['goImapSieveServer'][0],
353 "sieve_port" => $attrs['goImapSievePort'][0]);
354 }
355 error_reporting(E_ALL);
356 }
358 /* Get kerberos server. FIXME: only one is supported currently */
359 $ldap->cd ($this->current['BASE']);
360 $ldap->search ("(objectClass=goKrbServer)");
361 if ($ldap->count()){
362 $attrs= $ldap->fetch();
363 $this->data['SERVERS']['KERBEROS']= array( 'SERVER' => $attrs['cn'][0],
364 'REALM' => $attrs['goKrbRealm'][0],
365 'ADMIN' => $attrs['goKrbAdmin'][0],
366 'PASSWORD' => $attrs['goKrbPassword'][0]);
367 }
369 /* Get cups server. FIXME: only one is supported currently */
370 $ldap->cd ($this->current['BASE']);
371 $ldap->search ("(objectClass=goCupsServer)");
372 if ($ldap->count()){
373 $attrs= $ldap->fetch();
374 $this->data['SERVERS']['CUPS']= $attrs['cn'][0];
375 }
377 /* Get fax server. FIXME: only one is supported currently */
378 $ldap->cd ($this->current['BASE']);
379 $ldap->search ("(objectClass=goFaxServer)");
380 if ($ldap->count()){
381 $attrs= $ldap->fetch();
382 $this->data['SERVERS']['FAX']= array( 'SERVER' => $attrs['cn'][0],
383 'LOGIN' => $attrs['goFaxAdmin'][0],
384 'PASSWORD' => $attrs['goFaxPassword'][0]);
385 }
387 /* Get asterisk servers */
388 $ldap->cd ($this->current['BASE']);
389 $ldap->search ("(objectClass=goFonServer)");
390 $this->data['SERVERS']['FON']= array();
391 if ($ldap->count()){
392 while ($attrs= $ldap->fetch()){
394 /* Add 0 entry for development */
395 if(count($this->data['SERVERS']['FON']) == 0){
396 $this->data['SERVERS']['FON'][0]= array(
397 'DN' => $attrs['dn'],
398 'SERVER' => $attrs['cn'][0],
399 'LOGIN' => $attrs['goFonAdmin'][0],
400 'PASSWORD' => $attrs['goFonPassword'][0],
401 'DB' => "gophone",
402 'SIP_TABLE' => "sip_users",
403 'EXT_TABLE' => "extensions",
404 'VOICE_TABLE' => "voicemail_users",
405 'QUEUE_TABLE' => "queues",
406 'QUEUE_MEMBER_TABLE' => "queue_members");
407 }
409 /* Add entry with 'dn' as index */
410 $this->data['SERVERS']['FON'][$attrs['dn']]= array(
411 'DN' => $attrs['dn'],
412 'SERVER' => $attrs['cn'][0],
413 'LOGIN' => $attrs['goFonAdmin'][0],
414 'PASSWORD' => $attrs['goFonPassword'][0],
415 'DB' => "gophone",
416 'SIP_TABLE' => "sip_users",
417 'EXT_TABLE' => "extensions",
418 'VOICE_TABLE' => "voicemail_users",
419 'QUEUE_TABLE' => "queues",
420 'QUEUE_MEMBER_TABLE' => "queue_members");
421 }
422 }
424 /* Get glpi servers */
425 $ldap->cd ($this->current['BASE']);
426 $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
427 if ($ldap->count()){
428 $attrs= $ldap->fetch();
429 if(!isset($attrs['goGlpiPassword'])){
430 $attrs['goGlpiPassword'][0] ="";
431 }
432 $this->data['SERVERS']['GLPI']= array(
433 'SERVER' => $attrs['cn'][0],
434 'LOGIN' => $attrs['goGlpiAdmin'][0],
435 'PASSWORD' => $attrs['goGlpiPassword'][0],
436 'DB' => $attrs['goGlpiDatabase'][0]);
437 }
438 /* Get logdb server */
439 $ldap->cd ($this->current['BASE']);
440 $ldap->search ("(objectClass=goLogDBServer)");
441 if ($ldap->count()){
442 $attrs= $ldap->fetch();
443 $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0],
444 'LOGIN' => $attrs['goLogAdmin'][0],
445 'PASSWORD' => $attrs['goLogPassword'][0]);
446 }
448 /* Get NFS server lists */
449 $tmp= array("default");
450 $ldap->cd ($this->current['BASE']);
451 $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
452 while ($attrs= $ldap->fetch()){
453 for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
454 $path= preg_replace ("/\s.*$/", "", $attrs["goExportEntry"][$i]);
455 $tmp[]= $attrs["cn"][0].":$path";
456 }
457 }
458 $this->data['SERVERS']['NFS']= $tmp;
461 /* Load Terminalservers */
462 $ldap->cd ($this->current['BASE']);
463 $ldap->search ("(objectClass=goTerminalServer)");
464 $this->data['SERVERS']['TERMINAL']= array();
465 $this->data['SERVERS']['TERMINAL'][]= "default";
467 $this->data['SERVERS']['FONT']= array();
468 $this->data['SERVERS']['FONT'][]= "default";
469 while ($attrs= $ldap->fetch()){
470 $this->data['SERVERS']['TERMINAL'][]= $attrs["cn"][0];
471 for ($i= 0; $i<$attrs["goFontPath"]["count"]; $i++){
472 $this->data['SERVERS']['FONT'][]= $attrs["goFontPath"][$i];
473 }
474 }
476 /* Ldap Server */
477 $this->data['SERVERS']['LDAP']= array();
478 $ldap->cd ($this->current['BASE']);
479 $ldap->search ("(objectClass=goLdapServer)");
480 while ($attrs= $ldap->fetch()){
481 if (isset($attrs["goLdapBase"])){
482 for ($i= 0; $i<$attrs["goLdapBase"]["count"]; $i++){
483 $this->data['SERVERS']['LDAP'][]= $attrs["cn"][0].":".$attrs["goLdapBase"][$i];
484 }
485 }
486 }
488 /* Get misc server lists */
489 $this->data['SERVERS']['SYSLOG']= array("default");
490 $this->data['SERVERS']['NTP']= array("default");
491 $ldap->cd ($this->current['BASE']);
492 $ldap->search ("(objectClass=goNtpServer)");
493 while ($attrs= $ldap->fetch()){
494 $this->data['SERVERS']['NTP'][]= $attrs["cn"][0];
495 }
496 $ldap->cd ($this->current['BASE']);
497 $ldap->search ("(objectClass=goSyslogServer)");
498 while ($attrs= $ldap->fetch()){
499 $this->data['SERVERS']['SYSLOG'][]= $attrs["cn"][0];
500 }
502 /* Get samba servers from LDAP, in case of samba3 */
503 if ($this->current['SAMBAVERSION'] == 3){
504 $this->data['SERVERS']['SAMBA']= array();
505 $ldap->cd ($this->current['BASE']);
506 $ldap->search ("(objectClass=sambaDomain)");
507 while ($attrs= $ldap->fetch()){
508 $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array(
509 "SID" => $attrs["sambaSID"][0],
510 "RIDBASE" => $attrs["sambaAlgorithmicRidBase"][0]);
511 }
513 /* If no samba servers are found, look for configured sid/ridbase */
514 if (count($this->data['SERVERS']['SAMBA']) == 0){
515 if (!isset($this->current["SID"]) || !isset($this->current["RIDBASE"])){
516 print_red(_("SID and/or RIDBASE missing in your configuration!"));
517 echo $_SESSION['errors'];
518 exit;
519 } else {
520 $this->data['SERVERS']['SAMBA']['DEFAULT']= array(
521 "SID" => $this->current["SID"],
522 "RIDBASE" => $this->current["RIDBASE"]);
523 }
524 }
525 }
526 }
529 function get_departments($ignore_dn= "")
530 {
531 global $config;
533 /* Initialize result hash */
534 $result= array();
535 $administrative= array();
536 $result['/']= $this->current['BASE'];
537 $this->tdepartments= array();
539 /* Get list of department objects */
540 $ldap= $this->get_ldap_link();
541 $ldap->cd ($this->current['BASE']);
542 $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
543 while ($attrs= $ldap->fetch()){
544 $dn= $ldap->getDN();
545 $this->tdepartments[$dn]= "";
547 /* Save administrative departments */
548 if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
549 isset($attrs['gosaUnitTag'][0])){
550 $administrative[$dn]= $attrs['gosaUnitTag'][0];
551 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
552 }
554 if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
555 isset($attrs['gosaUnitTag'][0])){
556 $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
557 }
559 if ($dn == $ignore_dn){
560 continue;
561 }
563 /* Only assign non-root departments */
564 if ($dn != $result['/']){
565 $result[convert_department_dn($dn)]= $dn;
566 }
567 }
569 $this->adepartments= $administrative;
570 $this->departments= $result;
571 }
574 function make_idepartments($max_size= 28)
575 {
576 global $config;
577 $base = $config->current['BASE'];
579 $arr= array();
580 $ui= get_userinfo();
581 $this->idepartments= array();
583 /* Create multidimensional array, with all departments. */
584 foreach ($this->departments as $key => $val){
586 /* When using strict_units, filter non relevant parts */
587 if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
588 if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
589 $this->tdepartments[$val] != $ui->gosaUnitTag){
590 continue;
591 }
592 }
594 /* remove base from dn */
595 $val2 = str_replace($base,"",$val);
597 /* Get every single ou */
598 $str = preg_replace("/ou=/","|ou=",$val2);
599 $elements = array_reverse(split("\|",$str));
601 /* Save last array position */
602 $last = &$arr;
604 /* Get array depth */
605 $cnt = count($elements);
607 /* Add last ou element of current dn to our array */
608 foreach($elements as $key => $ele){
610 /* skip enpty */
611 if(empty($ele)) continue;
613 /* Extract department name */
614 $elestr = preg_replace("/^ou=/","", $ele);
615 $elestr = preg_replace("/,$/","",$elestr);
617 /* Add to array */
618 if($key == ($cnt-2)){
619 $last[$elestr]['ENTRY'] = $val;
620 }
622 /* Set next array appending position */
623 $last = &$last[$elestr]['SUB'];
624 }
625 }
627 /* Add base entry */
628 $ret["/"]["ENTRY"] = $base;
629 $ret["/"]["SUB"] = $arr;
631 $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
632 }
635 /* Creates display friendly output from make_idepartments */
636 function generateDepartmentArray($arr,$depth = -1,$max_size){
637 $ret = array();
638 $depth ++;
640 /* Walk through array */
641 ksort($arr);
642 foreach($arr as $name => $entries){
644 /* If this department is the last in the current tree position
645 * remove it, to avoid generating output for it */
646 if(count($entries['SUB'])==0){
647 unset($entries['SUB']);
648 }
650 /* Fix name, if it contains a replace tag */
651 $name= @LDAP::fix($name);
653 /* Check if current name is too long, then cut it */
654 if(mb_strlen($name, 'UTF-8')> $max_size){
655 $name = mb_substr($name,0,($max_size-3), 'UTF-8')." ...";
656 }
658 /* Append the name to the list */
659 if(isset($entries['ENTRY'])){
660 $a = "";
661 for($i = 0 ; $i < $depth ; $i ++){
662 $a.=".";
663 }
664 $ret[$entries['ENTRY']]=$a." ".$name;
665 }
667 /* recursive add of subdepartments */
668 if(isset($entries['SUB'])){
669 $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
670 }
671 }
673 return($ret);
674 }
676 /* This function returns all available Shares defined in this ldap
677 * There are two ways to call this function, if listboxEntry is true
678 * only name and path are attached to the array, in it is false, the whole
679 * entry will be parsed an atached to the result.
680 */
681 function getShareList($listboxEntry = false)
682 {
683 $ldap= $this->get_ldap_link();
685 /* Set tag attribute if we've tagging activated */
686 $tag= "";
687 $ui= get_userinfo();
688 if ($ui->gosaUnitTag != "" && isset($this->current['STRICT_UNITS']) &&
689 preg_match('/TRUE/i', $this->current['STRICT_UNITS'])){
690 $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
691 }
693 $a_res = $ldap->search("(&(objectClass=goShareServer)$tag(objectClass=goServer))",array("goExportEntry","cn"));
694 $return= array();
695 while($entry = $ldap->fetch($a_res)){
696 if(isset($entry['goExportEntry']['count'])){
697 unset($entry['goExportEntry']['count']);
698 }
699 if(isset($entry['goExportEntry'])){
700 foreach($entry['goExportEntry'] as $export){
701 $shareAttrs = split("\|",$export);
702 if($listboxEntry) {
703 $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
704 }else{
705 $return[$shareAttrs[0]."|".$entry['cn'][0]]['server'] = $entry['cn'][0];
706 $return[$shareAttrs[0]."|".$entry['cn'][0]]['name'] = $shareAttrs[0];
707 $return[$shareAttrs[0]."|".$entry['cn'][0]]['description'] = $shareAttrs[1];
708 $return[$shareAttrs[0]."|".$entry['cn'][0]]['type'] = $shareAttrs[2];
709 $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset'] = $shareAttrs[3];
710 $return[$shareAttrs[0]."|".$entry['cn'][0]]['path'] = $shareAttrs[4];
711 $return[$shareAttrs[0]."|".$entry['cn'][0]]['option'] = $shareAttrs[5];
712 }
713 }
714 }
715 }
716 return($return);
717 }
719 /* This function returns all available ShareServer */
720 function getShareServerList()
721 {
722 global $config;
723 $return = array();
724 $ui = get_userinfo();
725 $base = $config->current['BASE'];
726 $res = get_list("(&(objectClass=goShareServer)(goExportEntry=*))",$ui->subtreeACL,$base,array("goExportEntry","cn"),GL_SUBSEARCH);
727 foreach($res as $entry){
728 if(isset($entry['goExportEntry']['count'])){
729 unset($entry['goExportEntry']['count']);
730 }
731 foreach($entry['goExportEntry'] as $share){
732 $a_share = split("\|",$share);
733 $sharename = $a_share[0];
734 $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
735 }
737 }
738 return($return);
739 }
741 /* Check if there's the specified bool value set in the configuration */
742 function boolValueIsTrue($section, $value)
743 {
744 $section= strtoupper($section);
745 $value= strtoupper($value);
746 if (isset($this->data[$section][$value])){
748 $data= $this->data[$section][$value];
749 if (preg_match("/^true$/i", $data) || preg_match("/yes/i", $data)){
750 return TRUE;
751 }
753 }
755 return FALSE;
756 }
758 }
760 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
761 ?>