Code

Fixed some session problems
[gosa.git] / include / functions_setup.inc
1 <?php
3 function check_schema_version($description, $version)
4 {
5   $desc= preg_replace("/^.* DESC\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $description);
7   return preg_match("/\(v$version\)/", $desc);
8 }
11 function view_schema_check($table)
12 {
13   $message="<table summary=\"\" class=\"check\">";
15   foreach ($table as $key => $values){
16     $msg = $values['msg'];
17     $message.= "<tr><td class=\"check\">$msg";
19     if($values['status']) {
20       $message.="</td><td style='text-align:center' >
21         <img src=images/true.png alt='true' /></td></tr>";
22     } else {
23       $message.="</td><td style='text-align:center' >
24         <img src=images/button_cancel.png alt='false' /></td></tr>";
25     }
26   }
27   $message.="</table>";
29   return $message;
30 }
33 function is_schema_readable($server, $admin, $password)
34 {
35   $ds= ldap_connect ($server);
36   if (!$ds) {
37     return (false);
38   }
39   ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
40   $r= ldap_bind ($ds, $admin, $password);
42   /* Get base to look for schema */
43   $sr  = @ldap_read ($ds, NULL, "objectClass=*", array("subschemaSubentry"));
44   $attr= @ldap_get_entries($ds,$sr);
45   if (!isset($attr[0]['subschemasubentry'][0])){
46     return (false);
47   }
49   $nb= $attr[0]['subschemasubentry'][0];
50   $objectclasses= array();
51   $sr= ldap_read ($ds, $nb, "objectClass=*", array("objectclasses"));
52   $attrs= ldap_get_entries($ds,$sr);
53   if (!isset($attrs[0])){
54     return (false);
55   }
56   return(true);
57
59 function schema_check($server, $admin, $password, $aff=0,$CalledByIndexPhP=false)
60 {
61   global $config;
63   $messages= array();
64   $required_classes= array(
65       "gosaObject"            => array("version" => "2.4"),
66       "gosaAccount"           => array("version" => "2.4"),
67       "gosaLockEntry"         => array("version" => "2.4"),
68       "gosaCacheEntry"        => array("version" => "2.4"),
69       "gosaDepartment"        => array("version" => "2.4"),
71       "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
72       "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
73       "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
75       "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
76       "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
77       "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
78       "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
79       "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
81       "GOhard"                => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
82       "gotoTerminal"          => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
83       "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
84       "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
85       "goShareServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
86       "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
87       "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
88       "goLdapServer"          => array("version" => "2.4"),
89       "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
90       "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
91       "goKrbServer"           => array("version" => "2.4"),
92       "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
93       );
95   /* Build LDAP connection */
96   $ds= ldap_connect ($server);
97   if (!$ds) {
98     return (array(array("msg" => _("Can't bind to LDAP. No schema check possible!"), "status" => FALSE)));
99   }
100   ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
101   $r= ldap_bind ($ds, $admin, $password);
103   /* Get base to look for schema */
104   $sr  = @ldap_read ($ds, NULL, "objectClass=*", array("subschemaSubentry"));
105   $attr= @ldap_get_entries($ds,$sr);
106   if (!isset($attr[0]['subschemasubentry'][0])){
107     return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
108   }
110   /* Get list of objectclasses */
111   $nb= $attr[0]['subschemasubentry'][0];
112   $objectclasses= array();
113   $sr= ldap_read ($ds, $nb, "objectClass=*", array("objectclasses"));
114   $attrs= ldap_get_entries($ds,$sr);
115   if (!isset($attrs[0])){
116     return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
117   }
118   foreach ($attrs[0]['objectclasses'] as $val){
119     $name= preg_replace("/^.* NAME\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $val);
120     if ($name != $val){
121       $objectclasses[$name]= $val;
122     }
123   }
124   /* Walk through objectclasses and check if they are needed or not */
125   foreach ($required_classes as $key => $value){
126     if (isset($value['class'])){
127       if (!is_array($value['class'])){
128         $classes= array($value['class']);
129       } else {
130         $classes= $value['class'];
131       }
133       /* Check if we are using the class that requires */
134       foreach($classes as $class){
135         if (!isset($objectclasses[$key])){
136           $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' is not present in LDAP setup"), $key, $class);
137           $messages[$key]['status'] = FALSE;
138         } else {
139           if (!check_schema_version($objectclasses[$key], $value['version'])){
140             $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' does not have version %s"), $key, $class, $value['version']);
141             $messages[$key]['needonstartup'] = TRUE;
142             $messages[$key]['status'] =FALSE;
143           }else {
144             if(!isset($affich2[$class])){
145               $affich2[$class]['msg']   = sprintf(_("Support for '%s' enabled"), $class)."<td class=\"check\"> ".$value['file']."</td>";
146               $affich2[$class]['status']= TRUE; 
147             }
148           }
149         }
151       }
152     } else {
153       /* Required class */
154       if (!isset($objectclasses[$key])){
155         $messages[$key]['msg']= sprintf(_("Required objectclass '%s' is not present in LDAP setup"), $key);
156         $messages[$key]['status'] = FALSE;  
157       } else {
158         if (!check_schema_version($objectclasses[$key], $value['version'])){
159           $messages[$key]['msg']= sprintf(_("Required objectclass '%s' does not have version %s"), $key, $value['version']);
160           $messages[$key]['status'] = FALSE;  
161           $messages[$key]['needonstartup'] = TRUE;
162         }
163     
164       }
165     }
166   }
168   /* Check for correct samba parameters */
169   if (!isset($objectclasses['sambaSamAccount'])){
170     $messages['samba3']['msg']= _("SAMBA 3 support disabled, no schema seems to be installed");
171     $affich['samba3']['msg']= $messages['samba3']['msg']."<td class=\"check\">gosa+samba3.schema</td>";
172     $messages['samba3']['status']= FALSE;
173     $affich['samba3']['status']= FALSE;
174   }else{
175     $affich['samba3']['msg']= _("SAMBA 3 support enabled")."<td class=\"check\">gosa+samba3.schema</td>";
176     $affich['samba3']['status']= TRUE;
177   }
179   if (!isset($objectclasses['sambaAccount'])){
180     $messages['samba2']['msg']= _("SAMBA 2 support disabled, no schema seems to be installed");
181     $affich['samba2']['msg']= $messages['samba2']['msg']."<td class=\"check\">samba.schema</td>";
182     $messages['samba2']['status']= FALSE;
183     $affich['samba2']['status']= FALSE;
184   }else{
185     $affich['samba2']['msg']= _("SAMBA 2 support enabled")."<td class=\"check\">samba.schema</td>";
186     $affich['samba2']['status']= TRUE;
187   }
189   /* Check pureftp/dns/ */
190   if (!isset($objectclasses['PureFTPdUser'])){
191     $messages['pureftp']['msg']= _("Support for pureftp disabled, no schema seems to be installed");
192     $affich['pureftp']['msg']= $messages['pureftp']['msg']."<td class=\"check\">pureftpd.schema</td>";
193     $messages['pureftp']['status']= FALSE;
194     $affich['pureftp']['status']= FALSE;
195   }else{
196     $affich['pureftp']['msg']= _("Support for pureftp enabled")."<td class=\"check\">pureftpd.schema</td>";
197     $affich['pureftp']['status']= TRUE;
198   }
200   if (!isset($objectclasses['gosaWebdavAccount'])){
201     $messages['webdav']['msg']= _("Support for WebDAV disabled, no schema seems to be installed");
202     $affich['webdav']['msg']= $messages['webdav']['msg']."<td class=\"check\"></td>";
203     $messages['webdav']['status']= FALSE;
204     $affich['webdav']['status']= FALSE;
205   }else{
206     $affich['webdav']['msg']=_("Support for WebDAV enabled")."<td class=\"check\">gosa+samba3.schema</td>";
207     $affich['webdav']['status']= TRUE;
208   }
210   if (!isset($objectclasses['phpgwAccount'])){
211     $messages['phpgroupware']['msg']= _("Support for phpgroupware disabled, no schema seems to be installed");
212     $affich['phpgroupware']['msg']= $messages['phpgroupware']['msg']."<td class=\"check\">phpgwaccount.schema</td>";
213     $messages['phpgroupware']['status']= FALSE;
214     $affich['phpgroupware']['status']= FALSE;
215   }else{
216     $affich['phpgroupware']['msg']= _("Support for phpgroupware enabled")."<td class=\"check\">phpgwaccount.schema</td>";
217     $affich['phpgroupware']['status']= TRUE;
218   }
219   
220   if (!isset($objectclasses['trustAccount'])){
221     $messages['trustAccount']['msg']= _("Support for trustAccount disabled, no schema seems to be installed");
222     $affich['trustAccount']['msg']= $messages['trustAccount']['msg']."<td class=\"check\">trust.schema</td>";
223     $messages['trustAccount']['status']= FALSE;
224     $affich['trustAccount']['status']= FALSE;
225   }else{
226     $affich['trustAccount']['msg']= _("Support for trustAccount enabled")."<td class=\"check\">trust.schema</td>";
227     $affich['trustAccount']['status']= TRUE;
228   }
230   if (!isset($objectclasses['goFonAccount'])){
231     $messages['phoneaccount']['msg']= _("Support for gofon disabled, no schema seems to be installed");
232     $affich['phoneaccount']['msg']= $messages['phoneaccount']['msg']."<td class=\"check\">gofon.schema</td>";
233     $messages['phoneaccount']['status']= FALSE;
234     $affich['phoneaccount']['status']= FALSE;
235   }else{
236     $affich['phoneaccount']['msg']= _("Support for gofon enabled")."<td class=\"check\">gofon.schema</td>";
237     $affich['phoneaccount']['status']= true;
238   }
240   if (!isset($objectclasses['nagiosContact'])){
241     $messages['nagioscontact']['msg']= _("Support for nagios disabled, no schema seems to be installed");
242     $affich['nagioscontact']['msg']= $messages['nagioscontact']['msg']."<td class=\"check\">nagios.schema</td>";
243     $messages['nagioscontact']['status']= FALSE;
244     $affich['nagioscontact']['status']= FALSE;
245   }else{
246     $affich['nagioscontact']['msg']= _("Support for nagios enabled")."<td class=\"check\">nagios.schema</td>";
247     $affich['nagioscontact']['status']= true;
248   }
249   
250   if ((!isset($objectclasses['apple-user'])) || (!isset($objectclasses['mount'])) ){
251     $messages['netatalk']['msg']= _("Support for netatalk disabled, no schema seems to be installed");
252     $affich['netatalk']['msg']= $messages['netatalk']['msg']."<td class=\"check\">apple.schema</td>";
253     $messages['netatalk']['status']= FALSE;
254     $affich['netatalk']['status']= FALSE;
255   }else{
256     $affich['netatalk']['msg']= _("Support for netatalk enabled")."<td class=\"check\">apple.schema</td>";
257     $affich['netatalk']['status']= true;
258   }
259   
260   /* Fix for PHP Fehler "Undefined index: ldapconf"
261    * Ablaufverfolgung[1]: Funktion schema_check Datei: /home/hickert/gosa/include/functions_setup.inc (Zeile 230)
262    */
263   if((isset($_SESSION['ldapconf']['mail_methods']))&&(isset($_SESSION['ldapconf']))){
264         if(($_SESSION['ldapconf']['mail_methods'][$_SESSION['ldapconf']['mail']] == "kolab")&&(!$CalledByIndexPhP)){
265           if(!isset($objectclasses['kolabInetOrgPerson']))  {
266             $messages['kolab']['msg']= _("Support for Kolab disabled, no schema seems to be installed, setting mail-method to cyrus");
267             $affich['kolab']['msg']=$messages['kolab']['msg']."<td class=\"check\">kolab2.schema</td>";
268             $tmp= array_flip($_SESSION['ldapconf']['mail_methods']);
269             $_SESSION['ldapconf']['mail']=$tmp['cyrus'];
270             $messages['kolab']['status']= FALSE;
271             $affich['kolab']['status']= FALSE;
272           }else{
273             $affich['kolab']['msg']=_("Support for Kolab enabled")."<td class=\"check\">gofon.schema</td>";
274             $affich['kolab']['status']= TRUE;
275           }
276         }
277   }
278   if($aff==0){
279     return ($messages);
280   } else {
281     return(array_merge($affich,$affich2));
282   }
286 function check(&$faults, $message, $description, $test, $required= TRUE)
288   $msg= "<table summary=\"\" class='check'><tr><td class='check' style='font-size:14px;'>$message</td>
289     <td rowspan=2 style='vertical-align:middle; text-align:center;width:45px;'>";
290   if ($test){
291     $msg.= _("OK")."<br>";
292   } else {
293     if (!$required){
294       $msg.="<font color=red>"._("Ignored")."</font><br>";
295     } else {
296       $msg.="<font color=red>"._("Failed")."</font><br>";
297       $faults++;
298     }
299   }
300   $msg.= "</td></tr><tr><td class='check' style='padding-left:20px;".
301     "background-color:#F0F0F0;'>$description</td></tr></table><br>";
303   return $msg;
306 function perform_php_checks(&$faults)
308   global $check_globals;
310   $faults= 0;
311   $msg= "";
313   $msg.= "<h1>"._("PHP setup inspection")."</h1>";
315   $msg.= check (        $faults, _("Checking for PHP version (>=4.1.0)"),
316       _("PHP must be of version 4.1.0 or above for some functions and known bugs in PHP language."),
317       version_compare(phpversion(), "4.1.0")>=0);
319   $msg.= check (        $faults, _("Checking if register_globals is set to 'off'"),
320       _("register_globals is a PHP mechanism to register all global varibales to be accessible from scripts without changing the scope. This may be a security risk. GOsa will run in both modes."),
321       $check_globals == 0, FALSE);
322   
323   $msg.= check (  $faults, _("PHP session.gc_maxlifetime (>= 86400 seconds)."),
324       _("PHP uses this value for the garbage collector to delete old sessions, setting this value to one day will prevent loosing session and cookie  before they really timeout."),
325       ini_get("session.gc_maxlifetime") >= 86400,FALSE);
327   $msg.= check (        $faults, _("Checking for ldap module"),
328       _("This is the main module used by GOsa and therefore really required."),
329       is_callable('ldap_bind'));
331   $msg.= check (  $faults, _("Checking for XML functions"),
332       _("XML functions are required to parse the configuration file."),
333       is_callable('xml_parser_create'));
335   $msg.= check (        $faults, _("Checking for gettext support"),
336       _("Gettext support is required for internationalized GOsa."),
337       is_callable('bindtextdomain'));
339   $msg.= check (        $faults, _("Checking for iconv support"),
340       _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
341       is_callable('iconv'));
343   $msg.= check (        $faults, _("Checking for mhash module"),
344       _("To use SSHA encryption, you'll need this module. If you are just using crypt or md5 encryption, ignore this message. GOsa will run without it."),
345       is_callable('mhash'), FALSE);
347   $msg.= check (        $faults, _("Checking for imap module"),
348       _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
349       is_callable('imap_open'));
351   $msg.= check (        $faults, _("Checking for getacl in imap"),
352       _("The getacl support is needed for shared folder permissions. The standard IMAP module is not capable of reading acl's. You need a recend PHP version for this feature."),
353       is_callable('imap_getacl'), FALSE);
355   $msg.= check (        $faults, _("Checking for mysql module"),
356       _("MySQL support is needed for reading GOfax reports from databases."),
357       is_callable('mysql_query'), FALSE);
359   $msg.= check (        $faults, _("Checking for cups module"),
360       _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
361       is_callable('cups_get_dest_list'), FALSE);
363   $msg.= check (        $faults, _("Checking for kadm5 module"),
364       _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
365       is_callable('kadm5_init_with_password'), FALSE);
367   $msg.= check (  $faults, _("Checking for snmp Module"),
368       _("Simple Network Management Protocol (SNMP) is required for client monitoring."),
369       is_callable('snmpget'), FALSE);
371   return ($msg);
374 function get_link($function_name) {
375   $result= "<a href='http://de.php.net/manual/en/function.";
377   /* Replace all underscores with hyphens (phpdoc convention) */
378   $function_name= str_replace("_", "-", $function_name);
380   /* Append to base URL */
381   $result.= $function_name.".php'>$function_name</a>";
383   return $result;
386 function perform_additional_function_checks(&$faults) {
387   global $check_globals;
389   $faults= 0;
390   $msg= "";
391   $functions= array();
392   
393   $functions_list= '../include/functions_list.inc';
395   /* Make sure that we can read the file */
396   if(is_readable($functions_list)) {
397     /* Open filehandle */
398     $fh= fopen($functions_list,'rb');
399     if($fh!=null) {
400       $functions= eval(fread($fh,filesize($functions_list)));
401     }
402   }
404   $msg.= "<h1>"._("PHP detailed function inspection")."</h1>";
405   /* Only print message, if function is not callable */
406   foreach($functions as $key => $fn_name) {
407     if(!is_callable($fn_name)) {
408       $msg.= check ($faults, sprintf(_("Checking for function %s"), "<b>".get_link($fn_name)."</b>"),
409         sprintf(_("The function %s is used by GOsa. There is no information if it's optional or required yet."), "<b>".get_link($fn_name)."</b>"),
410         is_callable($fn_name), false);
411     }
412   }
413   return $msg;
416 function perform_additional_checks(&$faults)
418   $ret = NULL;
419   /* Programm check */
420   $msg= "<h1>"._("Checking for some additional programms")."</h1>";
422   /* Image Magick */
423   $query= "LC_ALL=C LANG=C convert -help";
424   $output= shell_exec ($query);
425   if ($output != ""){
426     $lines= split ("\n", $output);
427     $version= preg_replace ("/^Version:.+Magick ([^\s]+).*/", "\\1", $lines[0]);
428     list($major, $minor)= split("\.", $version);
429     $msg.= check (      $faults, _("Checking for ImageMagick (>=5.4.0)"),
430         _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
431         ($major > 5 || ($major == 5 && $minor >= 4)));
432   } else {
433     $msg.= check (      $faults, _("Checking imagick module for PHP"),
434         _("Imagick is used to convert user supplied images to fit the suggested size and the unified JPEG format from PHP script."), function_exists('imagick_blob2image'), TRUE);
435   }
437   /* Check for fping */
438   $query= "LC_ALL=C LANG=C fping -v 2>&1";
439   $output= shell_exec ($query);
440   $have_fping= preg_match("/^fping:/", $output);
441   $msg.= check (        $faults, _("Checking for fping utility"),
442       _("The fping utility is only used if you've got a thin client based terminal environment running."),
443       $have_fping, FALSE);
445   /* Check for smb hash generation tool */
446   $query= "mkntpwd 2>&1";
447   $output= shell_exec ($query);
448   $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
449   $alt = 0;
451   if (!$have_mkntpwd){
452     $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
453     system ($query, $ret);
454     $alt= ($ret == 0);
455   }
457   $msg.= check (        $faults, _("Checking for a way to generate LM/NT password hashes"),
458       _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
459       ($have_mkntpwd || $alt));
461   /* seesio.auto_start should be off, in order to without trouble*/
462   $session_auto_start = ini_get('session.auto_start');
463   $implicit_flush     = ini_get('implicit_flush');
464   $max_execution_time = ini_get('max_execution_time');
465   $memory_limit       = ini_get('memory_limit');
466   $expose_php         = ini_get('expose_php');
467   $magic_quotes_gpc   = ini_get('magic_quotes_gpc');
468   $register_globals   = ini_get('register_globals');
470   /* auto_register */
471   $msg.= check (  $faults, _("php.ini check -> session.auto_register"),
472       _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini must be set to 'Off'."), (!$session_auto_start['local_value']));
474   /* implicit_flush */
475   $msg.= check (  $faults, _("php.ini check -> implicit_flush"),
476       _("This option influences the Output handling. Turn this Option off, to increase performance."),
477       !$implicit_flush['local_value'],0,false);
479   /* max_execution_time */
480   if($max_execution_time['local_value'] < 30 ){
481     $max_execution_time['local_value']=false;
482   }
483   $msg.= check (  $faults, _("php.ini check -> max_execution_time"),
484       _("The Execution time should be at least 30 seconds, because some actions may consume more time."),
485       $max_execution_time['local_value'],0,false);
487   /* memory_limit */
488   if($memory_limit['local_value'] < 16 ){
489     $memory_limit['local_value']=false;
490   }
491   $msg.= check (  $faults, _("php.ini check -> memory_limit"),
492       _("GOsa needs at least 16MB of memory, less will cause unpredictable errors! Increase it for larger setups."),
493       !$implicit_flush['local_value'],0,false);
495   /* expose_php */
496   $msg.= check (  $faults, _("php.ini check -> expose_php"),
497       _("Increase the server security by setting expose_php to 'off'. PHP won't send any Information about the server you are running in this case."),
498       !$implicit_flush['local_value'],0,false);
500   /* magic_quotes_gpc */
501   $msg.= check (  $faults, _("php.ini check -> magic_quotes_gpc"),
502       _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."),
503       $magic_quotes_gpc['local_value'],0,false);
505   return $msg;
509 function parse_contrib_conf()
512   $str                = "";
513   $used_samba_version = 0;
514   $query              = ""; 
515   $fp                 = false;
516   $output             = "";
517   $needridbase_sid    = false;
518   $pwdhash            = "";
519   $replacements       = array();
520   $ldapconf           = $_SESSION['ldapconf']; // The Installation information
521   $classes            = $_SESSION['classes'];  // Class information needed to define which features are enabled
522   $possible_plugins   = array();
524   /* Which samba version do we use? */
525   if(isset($classes['samba3'])){
526     $used_samba_version = 2;
527   } else {
528     $used_samba_version = 3;
529   }
531   /* Look for samba password generation method */
532   if(file_exists("/usr/bin/mkntpasswd")){
533     $pwdhash  = "/usr/bin/mkntpasswd";
534   } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
535     $pwdhash= "mkntpwd";
536   } else {
537     $pwdhash=('perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
538   }
541   /* Define which variables will be replaced */
542   $replacements['{LOCATIONNAME}']  = $ldapconf['location'];
543   $replacements['{SAMBAVERSION}']  = $used_samba_version;
544   $replacements['{LDAPBASE}']      = $ldapconf['base'];
545   $replacements['{LDAPADMIN}']     = $ldapconf['admin'];
546   $replacements['{UIDBASE}']       = $ldapconf['uidbase'];
547   $replacements['{DNMODE}']        = $ldapconf['peopledn'];
548   $replacements['{LDAPHOST}']      = $ldapconf['uri'];
549   $replacements['{PASSWORD}']      = $ldapconf['password'];
550   $replacements['{CRYPT}']         = $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
551   $replacements['{SID}']         = "";
552   $replacements['{RIDBASE}']     = "";
553   if($ldapconf['mail'] != "disabled"){
554     $replacements['{MAILMETHOD}']    = $ldapconf['mail_methods'][$ldapconf['mail']];
555   }   
556   $replacements['{SMBHASH}']       = $pwdhash;
557   $replacements['{GOVERNMENTMODE}']= "false"; 
558   $replacements['{kolabAccount}']  = "";
559   $replacements['{servKolab}']     = "";
560   $replacements['{errorlvl}']     = $ldapconf['errorlvl'];
562   /* This array contains all preg_replace syntax to delete all unused plugins
563      THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes'] */
565   $possible_plugins['fonreport'][]   = "'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
566   $possible_plugins['phoneaccount'][]= "'\n.*<tab.*phoneAccount.*>.*\n'i";
567   $possible_plugins['logview'][]     = "'\n.*<plugin.*logview+.*\n.*>.*\n'i";
568   $possible_plugins['pureftp'][]     = "'\n.*<tab.*pureftp.*>.*\n'i";
569   $possible_plugins['webdav'][]      = "'\n.*<tab.*webdav.*>.*\n'i";
570   $possible_plugins['phpgroupware'][]= "'\n.*<tab.*phpgroupware.*>.*\n'i";
571   $possible_plugins['netatalk'][0]    = "'\n.*<plugin.*netatalk+.*\n.*>.*\n'i";
572   $possible_plugins['netatalk'][1]    = "'\n.*<tab.*netatalk.*>.*\n'i";
574   /*Header information
575      Needed to send the generated gosa.conf to the browser */
576   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
577   header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
578   header("Cache-Control: no-cache");
579   header("Pragma: no-cache");
580   header("Cache-Control: post-check=0, pre-check=0");
581   header("Content-type: text/plain");
583   if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
584       preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
585     header('Content-Disposition: filename="gosa.conf"');
586   } else {
587     header('Content-Disposition: attachment; filename="gosa.conf"');
588   }
590   if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r")) {
591     echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
592   } else {
593     while(!feof($fp)) {
594       $str.= fread($fp,512);
595     }
597     if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab") {
598       $replacements['{kolabAccount}']  ="<tab class=\"kolabAccount\" />\n     ";
599       $replacements['{servKolab}']     ="<tab class=\"servkolab\" name=\"Kolab\" />";
600     }
602     if($used_samba_version == 2) {
603       /* Do nothing for samba 2... */
604     } else {
605       /* Create LDAP connection, to check if there's a domain
606          object defined in the LDAP schema */
607       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
609       /* Try to find a Samba Domain Objekt */
610       $ldap->search("(objectClass=sambaDomain)");
611     
612       /* Something found ??? so we need to define ridbase an SID by ourselfs */
613       if($ldap->count()< 1) {
614         $replacements['{SID}']= "sid=\"123412-11\"";
615         $replacements['{RIDBASE}']= "ridbase=\"1000\"";  
616       } 
617     }
619     /* Data readed, types replaced, samba version detected and checked if
620        we need to add SID and RIDBASE. Check if there is an ivbbentry in
621        the LDAP tree, in this case we will set the governmentmode to true.
622        Create LDAP connection, to check if theres a domain Objekt definen
623        in the LDAP schema. */
624     if(!isset($ldap)){
625       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
626     }
628     /* Try to find a Samba Domain Objekt */
629     $ldap->search("(objectClass=ivbbentry)");
631     /* Something found ??? so we need to define ridbase an SID by ourselfs */
632     if($ldap->count()> 0) {
633       $replacements['{GOVERNMENTMODE}']= "true";
634     }
636     /* Replace all colleted information with placeholder */
637     foreach($replacements as $key => $val) {
638       $str = preg_replace("/".$key."/",$val,$str);
639     }    
641     if($ldapconf['mail'] == "disabled"){
642       $str = str_replace("mailMethod=\"{MAILMETHOD}\"","",$str);
643     }
645     /* Remove all unused plugins */
646     foreach(array_keys($possible_plugins) as $akey) {
647       if(array_key_exists($akey,$classes)) {
648         foreach($possible_plugins[$akey] as $key=>$val) {
649           $str = preg_replace($val,"\n",$str);
650         }
651       }
652     }
653   }
655   return ((($str)));
659 /* Show setup_page 1 */
660 function show_setup_page1($withoutput = true)
662   $faults = array();
663   $smarty = get_smarty();  
664   $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
665   $smarty->assign ("tests", perform_php_checks($faults));
666   $smarty->assign ("detailed_tests", perform_additional_function_checks($faults));
668   /* This var is true if anything went wrong */
669   if ($faults){
670     $smarty->assign("mode", "disabled");
671   }
673   /* This line displays the template only if (withoutput is set) */
674   if($withoutput){
675     $smarty->display (get_template_path('headers.tpl'));
676   }
678   if (isset($_SESSION['errors'])){
679     $smarty->assign("errors", $_SESSION['errors']);
680   }
682   if($withoutput){
683     $smarty->display (get_template_path('setup.tpl'));
684   }
686   return (!$faults);
690 /* Show setup_page 2 */
691 function show_setup_page2($withoutput = true)
693   $faults = array();
694   $smarty = get_smarty();
695   $smarty->assign ("content", get_template_path('setup_step2.tpl'));
696   $smarty->assign ("tests", perform_additional_checks($faults));
698   if ($faults) {
699     $smarty->assign("mode", "disabled");
700   }
701   if($withoutput){
702     $smarty->display (get_template_path('headers.tpl'));
703   }
704   if (isset($_SESSION['errors']))  {
705     $smarty->assign("errors", $_SESSION['errors']);
706   }
707   if($withoutput){
708     $smarty->display (get_template_path('setup.tpl'));
709   }
711   return (!$faults);                               
715 function show_setup_page3($withoutput = true)
717   $ds = NULL;
718   $smarty = get_smarty();
720   /* Take the Post oder the Sessioin saved data */
721   if(isset($_POST['uri'])){
722     $uri = $_POST['uri'];
723   } elseif(isset($_SESSION['ldapconf']['uri'])){
724     $uri = $_SESSION['ldapconf']['uri'];
725   }
727   /* If Page called first time, field is empty */
728   if((!isset($uri))||(empty($uri))){
729     $uri = "ldap://localhost:389";
730   }
732   /* if isset $uri save it to session */
733   if(isset($uri)) {
734     $_SESSION['ldapconf']['uri'] = $uri;
735     $smarty->assign ("uri", validate($uri));
736   }
738   /* No error till now */
739   $fault = false;
741   /* If we pushed the Button continue */
742   if(isset($_POST['continue3'])){
743     if(!isset($uri)) {
744       $fault = true;
746       /* Output the Error */
747       if($withoutput) {
748         print_red (_("You've to specify an ldap server before continuing!"));
749         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
750       }
751     }
752   } elseif (!$ds = @ldap_connect (validate($uri))) {
753     $fault =true;
755     /* Output the Error */
756     if($withoutput) {
757       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
758       $smarty->assign ("uri", validate($uri));
759       $smarty->assign ("content", get_template_path('setup_step3.tpl'));
760     }
761   } else {
762     /* Try to bind the connection */    
763     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
765     /* if we can't bind , print error */
766     if (!$r  =  @ldap_bind ($ds)) {
767       $fault = true;
769       /* Output the Error */
770       if($withoutput) {
771         print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
772         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
773         $smarty->assign ("uri", validate($uri));
774       }
775     } else {
776       $fault = false;
777     }
778   }
780   $smarty->assign ("content", get_template_path('setup_step3.tpl'));
782   /* Load Header */
783   if($withoutput){
784     $smarty->display (get_template_path('headers.tpl'));
785   }
787   /* Set Errors to Smarty */
788   if (isset($_SESSION['errors'])) {
789     $smarty->assign("errors", $_SESSION['errors']);
790   }
792   /* Print out Template */ 
793   if($withoutput){
794     $smarty->display (get_template_path('setup.tpl'));
795   }
797   return (!$fault);                             
801 function show_setup_page4($withoutput = true)
803   $smarty= get_smarty();      
805         // ?
806   if(!isset($_SESSION['ldapconf']['base'])){
807     $_SESSION['ldapconf']['base']= $base;
808   }
810   if(!isset($_SESSION['ldapconf']['base'])){
811     $_SESSION['ldapconf']['base']= $base;
812   }
813   require_once("class_password-methods.inc");
815   $fault     = false;              
816   $uri       = $_SESSION['ldapconf']['uri'];
817   $ldapconf  = $_SESSION['ldapconf'];
818   $arr_crypts= array();
819   $temp      = "";
820   $checkvars = array("location", "admin", "password", "peopleou", "base",
821       "peopledn", "arr_crypts", "mail", "uidbase","errorlvl");
823   if(!isset($_SESSION['ldapconf']['arr_cryptkeys'])) {
824     require_once("class_password-methods.inc");
825     $tmp= passwordMethod::get_available_methods_if_not_loaded();
826     $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
827   }
829   if(!isset($_SESSION['ldapconf']['mail_methods'])) {
830     $_SESSION['ldapconf']['mail_methods']=array();
831     $temp = get_available_mail_classes();
832     $_SESSION['ldapconf']['mail_methods']= $temp['name'];
833   }
835   /* If there are some empty vars in ldapconnect -
836      these values also represent out default values */
837   if(!$ds = @ldap_connect (validate($uri))){
838     $fault = true;
839     if($withoutput){
840       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
841     }
842   } elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
843     $fault = true;
844     if($withoutput){
845       print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
846     }
847   } elseif(!$r= @ldap_bind ($ds)){
848     $fault = true;
849     if($withoutput){
850       print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
851     }
852   } else {
853     $sr=   @ldap_search ($ds, NULL, "objectClass=*", array("namingContexts"));
854     $attr= @ldap_get_entries($ds,$sr);
856     if((empty($attr))) {
857       $base= "dc=example,dc=net";
859       if($withoutput){
860         print_red(_("Bind to server successful, but the server seems to be completly empty, please check all information twice"));
861       }
863     } else {
864       $base= $attr[0]['dn'];
865     }
866   }
868   if(!isset($_SESSION['ldapconf']['base'])){
869     $_SESSION['ldapconf']['base']= $base;
870   }
871   if(!isset($_SESSION['ldapconf']['admin'])){
872     $_SESSION['ldapconf']['admin']= "cn=ldapadmin,".$base;
873   }
874   if(!isset($_SESSION['ldapconf']['peopleou'])){
875     $_SESSION['ldapconf']['peopleou']= "ou=people";
876   }
877   if(!isset($_SESSION['ldapconf']['groupou'])){
878     $_SESSION['ldapconf']['groupou']= "ou=groups";
879   }
880   if(!isset($_SESSION['ldapconf']['peopledn'])){
881     $_SESSION['ldapconf']['peopledn']= "cn";
882   }
883   if(!isset($_SESSION['ldapconf']['password'])){
884     $_SESSION['ldapconf']['password']= "";
885   }
886   if(!isset($_SESSION['ldapconf']['location'])){
887     $_SESSION['ldapconf']['location']= "Example";
888   }
889   if(!isset($_SESSION['ldapconf']['uidbase'])){
890     $_SESSION['ldapconf']['uidbase']= "1000";
891   }
892   if(!isset($_SESSION['ldapconf']['mail'])){
893     $_SESSION['ldapconf']['mail']= 0;
894   }
895   $tmp= array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
896   if(!isset($_SESSION['ldapconf']['arr_crypts'])){
897     $_SESSION['ldapconf']['arr_crypts']   = $tmp['md5'];
898   }
900   /* check POST data */
901   if(isset($_POST['check'])) {
903     /* Check if all needed vars are submitted */
904     foreach($checkvars as $key) {
905       if($key == "peopleou"){
906         continue;
907       }
908       if($key == "groupou"){
909         continue;
910       }
912       if((isset($_POST[$key]))&&($_POST[$key]!="")) {
913         $_SESSION['ldapconf'][$key] = $_POST[$key];
914       } else {
915         if($withoutput) {
916           print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
917         }
918         $fault = true;
919       }
920     }
921   }
923   /* Transfer base */
924   if(isset($_POST['base'])){
925     $_SESSION['ldapconf']['base']= $_POST['base'];
926   }
928   $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
929   $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
931   foreach($_SESSION['ldapconf'] as $key => $val) {
932     $smarty->assign($key,$val);
933   }
935   if(isset($_POST['check'])) {
936     $ldap= new LDAP($_SESSION['ldapconf']['admin'],
937         $_SESSION['ldapconf']['password'],
938         $_SESSION['ldapconf']['uri']);
940     $m= schema_check($_SESSION['ldapconf']['uri'],
941         $_SESSION['ldapconf']['admin'],
942         $_SESSION['ldapconf']['password']);
943     $_SESSION['classes']= $m;
945     if(!is_schema_readable($ldapconf['uri'],$ldapconf['admin'],$ldapconf['password'])){
946       if($withoutput){
947         print_red(_("Can't read schema informations, GOsa needs to know your schema setup. Please verify that it is readable for GOsa"));
948       }
949       $fault=true;
950     }
954     if ($ldap->error != "Success") {
955       if($withoutput) {
956         print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
957       }
958       $fault = true;
959     }
960   }
962   /* Set smarty output */
963   $smarty->assign ("content", get_template_path('setup_step4.tpl'));
964   $smarty->assign ("peopledns", array("cn", "uid"));
965   if($withoutput){
966     $smarty->display (get_template_path('headers.tpl'));
967   }
968   if(isset($_SESSION['errors'])) {
969     $smarty->assign("errors", $_SESSION['errors']);
970   }
971   if($withoutput){
972     $smarty->display (get_template_path('setup.tpl'));
973   }
974   return (!$fault);
978 function show_setup_page5($withoutput=true)
980   /* Get ldapconf */
981   $ldapconf= $_SESSION['ldapconf'];
983   /* get smarty */
984   $smarty = get_smarty();
986   if(isset($_SESSION['classes'])){
987     $classes = $_SESSION['classes'];
988   }
990   $info= posix_getgrgid(posix_getgid());
991   $smarty->assign("webgroup", $info['name']);
992   $smarty->assign("path", CONFIG_DIR);
993   $message= "<table summary=\"\" class=\"check\">";
994   $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
996   if($withoutput) {
997     $smarty->assign ("schemas", view_schema_check($m));
998     $smarty->assign ("content", get_template_path('setup_finish.tpl'));
999   }
1001   /* Output templates... */
1002   if($withoutput){
1003     $smarty->display (get_template_path('headers.tpl'));
1004   }
1005   if (isset($_SESSION['errors'])) {
1006     $smarty->assign("errors", $_SESSION['errors']);
1007   }
1008   if($withoutput){
1009     $smarty->display (get_template_path('setup.tpl'));
1010   }
1012   return(true);
1016 function create_user_for_setup($withoutput=true)
1018   global $samba;
1020   $ldapconf = $_SESSION['ldapconf'];
1021   $smarty = get_smarty();
1022   
1023   $need_to_create_group = false;
1024   $need_to_create_user  = false;
1026   $str_there="";
1028   if(isset($_SESSION['classes'])){
1029     $classes= $_SESSION['classes'];
1030   }
1032   /* Everything runns perfect ...
1033      So we do a last test on this page
1034      is there a user with ACLs :all which will be able to adminsitrate GOsa
1035      We check that, if this user or group is missing we ask for creating them */
1036   $ldap= new LDAP($_SESSION['ldapconf']['admin'],    $_SESSION['ldapconf']['password'],   $_SESSION['ldapconf']['uri']);
1038   /* 
1039   Now we are testing for a group, with the rights :all 
1040   */
1041   
1042   $ldap->cd($ldapconf['base']);
1043   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
1045   $group_cnt  = $ldap->count();
1046   $data       = $ldap->fetch();
1048 //  $str_there  = "Searching for Aminitrative users <br><br>";
1050   /* 
1051   We need to create administrative user and group  because theres no group found 
1052   */
1053   if($group_cnt < 1) {
1054     
1055     /* 
1056     Set var to create user 
1057     */
1058 //    $str_there  =   "no group found<br>";
1060     $need_to_create_group = true;
1061     $need_to_create_user  = true;
1064     /* Output error */
1065     if(($withoutput)&&(!isset($_POST['new_admin']))){
1066       print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1067     }
1068   } else {
1069     
1070 //    $str_there = "Group found <br>".$data['dn'];    
1072     $need_to_create_group = false;
1073  
1074     $ldap->clearResult();
1075    
1076     /* We found an Administrative Group, is there a user, too */
1077     if(isset($data['memberUid'][0])) {
1078       $str = "uid=".$data['memberUid']['0'];
1079       $ldap->search("(&(objectClass=gosaAccount)(objectClass=person)(".$str."))");
1080       $data2   = $ldap->fetch();
1081   
1082       /* We must create a user */
1083       if (($ldap->count() < 1)||(!isset($data2))) {
1084 //        $str_there.="Missing user";
1085         
1086         $need_to_create_user = true;
1087       
1088         if(($withoutput)&&(!isset($_POST['new_admin']))){
1089           print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1090         }
1091       }else {
1092 //        $str_there.="<br>User found <br>".$data2['dn'];
1093         $need_to_create_user = false;
1094       }
1095     } else {
1096       $need_to_create_user=true;
1097       if(($withoutput)&&(!isset($_POST['new_admin']))){
1098           print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1099         }   
1100 //      $str_there.="<br>No User found <br>";
1101     }
1102   }
1104   if(!($need_to_create_user&&$need_to_create_group))
1105     return(true);
1107   /* We need to create a new user with group */
1108   if(isset($_POST['new_admin']))
1109   {
1110   
1111     /* Adjust password attributes according to the samba version */
1112     if (isset($classes['samba3'])) {
1113       $samba= "2";
1114       $lmPassword = "lmPassword";
1115       $ntPassword = "ntPassword";
1116     } else {
1117       $samba= "3";
1118       $lmPassword = "sambaLMPassword";
1119       $ntPassword = "sambaNtPassword";
1120     }
1122     /* Nothing submitted */
1123     if(((empty($_POST['admin_name']))||(empty($_POST['admin_pass'])))) {
1124       return(true);
1125     }
1127     if($need_to_create_user) {
1128       /* We have the order to create an Admin */
1129       /* Define the user we are going to create */
1130       $dn= "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1131       $arr['objectClass'][0] ="person";
1132       $arr['objectClass'][1] ="organizationalPerson";
1133       $arr['objectClass'][2] ="inetOrgPerson";
1134       $arr['objectClass'][3] ="gosaAccount";
1135       $arr['uid']            = $_POST['admin_name'];
1136       $arr['cn']             = $_POST['admin_name'];
1137       $arr['sn']             = $_POST['admin_name'];
1138       $arr['givenName']      = "GOsa main administrator";
1139       $arr[$lmPassword]      = "10974C6EFC0AEE1917306D272A9441BB";
1140       $arr[$ntPassword]      = "38F3951141D0F71A039CFA9D1EC06378";
1141       $arr['userPassword']   = crypt_single($_POST['admin_pass'],"md5");
1142     
1144       if(!$ldap->dn_exists($dn)){ 
1145         $ldap->cd($dn); 
1146         $ldap->create_missing_trees($dn);
1147         $ldap->cd($dn);
1148         $ldap->add($arr);
1149         if($ldap->error!="Success"){
1150           print_red($ldap->error);
1151           print_red("Can't create user, and / or Group, possibly this problem  depends on an empty LDAP server. Check your configuration and try again!");
1152         }
1153       }    
1154     }
1156     /* There's already a group for administrator, so we only need to add the user */
1157     if(!$need_to_create_group) {
1158       if(!isset($data['memberUid'])) {
1159         $arrr['memberUid']= $_POST['admin_name'];
1160       } else {
1161         $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1162         $arrr['memberUid'] = $data['memberUid'];
1163         unset($arrr['memberUid']['count']);
1164   
1165         $tmp = array_reverse($arrr['memberUid']);    
1166         foreach($tmp as $tt){
1167           $tmp2[]=$tt;
1168         }
1169         $arrr['memberUid']= $tmp2;
1170 //        $str_there="Group found<br>".$data['dn'];
1171       }
1173       $ldap->cd($data['dn']);
1174       $ldap->modify($arrr);
1176     } else {
1177       $dn                    = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1178       $arrr['objectClass'][0]= "gosaObject";
1179       $arrr['objectClass'][1]= "posixGroup";
1180       $arrr['gosaSubtreeACL']= ":all";
1181       $arrr['cn']            = "administrators";
1182       $arrr['gidNumber']     = "999";
1183       $arrr['memberUid']     = $_POST['admin_name'];
1185       $ldap->cd($dn);
1186       $ldap->create_missing_trees($dn);
1187       $ldap->cd($dn);
1189       $ldap->add($arrr);
1190     }
1191     return(true);
1192   } else {
1194     if((!isset($create_user))||(!($create_user))) {
1195       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1196       $smarty->assign("exists",true);
1197     } else {
1198       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1199       $smarty->assign("exists",false);
1200     }
1202   }
1204   /* Smarty output */ 
1205   if($withoutput){
1206     $smarty->display (get_template_path('headers.tpl'));
1207   }
1208   if (isset($_SESSION['errors'])) {
1209     $smarty->assign("errors", $_SESSION['errors']);
1210   }
1211   $smarty->assign("str_there",$str_there);
1212   if($withoutput){
1213     $smarty->display (get_template_path('setup.tpl'));
1214   }
1215   return(false);
1219 /* Returns the classnames auf the mail classes */
1220 function get_available_mail_classes()
1222   $dir = opendir( "../include");
1223   $methods = array();
1224   $suffix = "class_mail-methods-";
1225   $lensuf = strlen($suffix);
1226   $prefix = ".inc";
1227   $lenpre = strlen($prefix);
1229   $i = 0;
1230   while (($file = readdir($dir)) !== false){
1232     if(stristr($file,$suffix)) {
1233       $lenfile = strlen($file);
1234       $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1235       $methods['file'][$i] = $file;
1236       $methods[$i]['file'] = $file;
1237       $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1238       $i++;
1239     }
1241   }
1243   return($methods);
1246 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1247 ?>