Code

77d4c6474607dd0fdc0832d54c7476dc460322e6
[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, "", "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.4", "class" => "terminals","file" => "goto.schema"),
82       "gotoTerminal"          => array("version" => "2.0", "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, "", "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   }
220   if (!isset($objectclasses['goFonAccount'])){
221     $messages['phoneaccount']['msg']= _("Support for gofon disabled, no schema seems to be installed");
222     $affich['phoneaccount']['msg']= $messages['phoneaccount']['msg']."<td class=\"check\">gofon.schema</td>";
223     $messages['phoneaccount']['status']= FALSE;
224     $affich['phoneaccount']['status']= FALSE;
225   }else{
226     $affich['phoneaccount']['msg']= _("Support for gofon enabled")."<td class=\"check\">gofon.schema</td>";
227     $affich['phoneaccount']['status']= true;
228   }
229   
230   /* Fix for PHP Fehler "Undefined index: ldapconf"
231    * Ablaufverfolgung[1]: Funktion schema_check Datei: /home/hickert/gosa/include/functions_setup.inc (Zeile 230)
232    */
233   if((isset($_SESSION['ldapconf']['mail_methods']))&&(isset($_SESSION['ldapconf']))){
234         if(($_SESSION['ldapconf']['mail_methods'][$_SESSION['ldapconf']['mail']] == "kolab")&&(!$CalledByIndexPhP)){
235           if(!isset($objectclasses['kolabInetOrgPerson']))  {
236             $messages['kolab']['msg']= _("Support for Kolab disabled, no schema seems to be installed, setting mail-method to cyrus");
237             $affich['kolab']['msg']=$messages['kolab']['msg']."<td class=\"check\">kolab2.schema</td>";
238             $tmp= array_flip($_SESSION['ldapconf']['mail_methods']);
239             $_SESSION['ldapconf']['mail']=$tmp['cyrus'];
240             $messages['kolab']['status']= FALSE;
241             $affich['kolab']['status']= FALSE;
242           }else{
243             $affich['kolab']['msg']=_("Support for Kolab enabled")."<td class=\"check\">gofon.schema</td>";
244             $affich['kolab']['status']= TRUE;
245           }
246         }
247   }
248   if($aff==0){
249     return ($messages);
250   } else {
251     return(array_merge($affich,$affich2));
252   }
256 function check(&$faults, $message, $description, $test, $required= TRUE)
258   $msg= "<table summary=\"\" class='check'><tr><td class='check' style='font-size:14px;'>$message</td>
259     <td rowspan=2 style='vertical-align:middle; text-align:center;width:45px;'>";
260   if ($test){
261     $msg.= _("OK")."<br>";
262   } else {
263     if (!$required){
264       $msg.="<font color=red>"._("Ignored")."</font><br>";
265     } else {
266       $msg.="<font color=red>"._("Failed")."</font><br>";
267       $faults++;
268     }
269   }
270   $msg.= "</td></tr><tr><td class='check' style='padding-left:20px;".
271     "background-color:#F0F0F0;'>$description</td></tr></table><br>";
273   return $msg;
276 function perform_php_checks(&$faults)
278   global $check_globals;
280   $faults= 0;
281   $msg= "";
283   $msg.= "<h1>"._("PHP setup inspection")."</h1>";
284   $msg.= check (        $faults, _("Checking for PHP version (>=4.1.0)"),
285       _("PHP must be of version 4.1.0 or above for some functions and known bugs in PHP language."),
286       version_compare(phpversion(), "4.1.0")>=0);
288   $msg.= check (        $faults, _("Checking if register_globals is set to 'off'"),
289       _("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."),
290       $check_globals == 0, FALSE);
292   $msg.= check (        $faults, _("Checking for ldap module"),
293       _("This is the main module used by GOsa and therefore really required."),
294       is_callable('ldap_bind'));
296   $msg.= check (  $faults, _("Checking for XML functions"),
297       _("XML functions are required to parse the configuration file."),
298       is_callable('xml_parser_create'));
300   $msg.= check (        $faults, _("Checking for gettext support"),
301       _("Gettext support is required for internationalized GOsa."),
302       is_callable('bindtextdomain'));
304   $msg.= check (        $faults, _("Checking for iconv support"),
305       _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
306       is_callable('iconv'));
308   $msg.= check (        $faults, _("Checking for mhash module"),
309       _("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."),
310       is_callable('mhash'), FALSE);
312   $msg.= check (        $faults, _("Checking for imap module"),
313       _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
314       is_callable('imap_open'));
316   $msg.= check (        $faults, _("Checking for getacl in imap"),
317       _("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."),
318       is_callable('imap_getacl'), FALSE);
320   $msg.= check (        $faults, _("Checking for mysql module"),
321       _("MySQL support is needed for reading GOfax reports from databases."),
322       is_callable('mysql_query'), FALSE);
324   $msg.= check (        $faults, _("Checking for cups module"),
325       _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
326       is_callable('cups_get_dest_list'), FALSE);
328   $msg.= check (        $faults, _("Checking for kadm5 module"),
329       _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
330       is_callable('kadm5_init_with_password'), FALSE);
332   $msg.= check (  $faults, _("Checking for snmp Module"),
333       _("Simple Network Management Protocol (SNMP) is required for client monitoring."),
334       is_callable('snmpget'), FALSE);
336   return ($msg);
339 function perform_additional_function_checks(&$faults) {
340   global $check_globals;
342   $faults= 0;
343   $msg= "";
344   $functions= array();
345   
346   $functions_list= '../include/functions_list.inc';
348   /* Make sure that we can read the file */
349   if(is_readable($functions_list)) {
350     /* Open filehandle */
351     $fh= fopen($functions_list,'rb');
352     if($fh!=null) {
353       $functions= eval(fread($fh,filesize($functions_list)));
354     }
355   }
357   /* Only print message, if function is not callable */
358   foreach($functions as $key => $fn_name) {
359     if(!is_callable($fn_name)) {
360       $msg.= check (  $faults, _(sprintf("Checking for optional function %s", $fn_name)),
361         _(sprintf("The function $fn_name is used by GOsa. There is no information if it's optional or required yet.",$fn_name)),
362         is_callable($fn_name), TRUE);
363     }
364   }
365   return $msg;
368 function perform_additional_checks(&$faults)
370   $ret = NULL;
371   /* Programm check */
372   $msg= "<h1>"._("Checking for some additional programms")."</h1>";
374   /* Image Magick */
375   $query= "LC_ALL=C LANG=C convert -help";
376   $output= shell_exec ($query);
377   if ($output != ""){
378     $lines= split ("\n", $output);
379     $version= preg_replace ("/^Version:.+Magick ([^\s]+).*/", "\\1", $lines[0]);
380     list($major, $minor)= split("\.", $version);
381     $msg.= check (      $faults, _("Checking for ImageMagick (>=5.4.0)"),
382         _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
383         ($major > 5 || ($major == 5 && $minor >= 4)));
384   } else {
385     $msg.= check (      $faults, _("Checking imagick module for PHP"),
386         _("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);
387   }
389   /* Check for fping */
390   $query= "LC_ALL=C LANG=C fping -v 2>&1";
391   $output= shell_exec ($query);
392   $have_fping= preg_match("/^fping:/", $output);
393   $msg.= check (        $faults, _("Checking for fping utility"),
394       _("The fping utility is only used if you've got a thin client based terminal environment running."),
395       $have_fping, FALSE);
397   /* Check for smb hash generation tool */
398   $query= "mkntpwd 2>&1";
399   $output= shell_exec ($query);
400   $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
401   $alt = 0;
403   if (!$have_mkntpwd){
404     $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
405     system ($query, $ret);
406     $alt= ($ret == 0);
407   }
409   $msg.= check (        $faults, _("Checking for a way to generate LM/NT password hashes"),
410       _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
411       ($have_mkntpwd || $alt));
413   /* seesio.auto_start should be off, in order to without trouble*/
414   $session_auto_start = ini_get('session.auto_start');
415   $implicit_flush     = ini_get('implicit_flush');
416   $max_execution_time = ini_get('max_execution_time');
417   $memory_limit       = ini_get('memory_limit');
418   $expose_php         = ini_get('expose_php');
419   $magic_quotes_gpc   = ini_get('magic_quotes_gpc');
420   $register_globals   = ini_get('register_globals');
422   /* auto_register */
423   $msg.= check (  $faults, _("php.ini check -> session.auto_register"),
424       _("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']));
426   /* implicit_flush */
427   $msg.= check (  $faults, _("php.ini check -> implicit_flush"),
428       _("This option influences the Output handling. Turn this Option off, to increase performance."),
429       !$implicit_flush['local_value'],0,false);
431   /* max_execution_time */
432   if($max_execution_time['local_value'] < 30 ){
433     $max_execution_time['local_value']=false;
434   }
435   $msg.= check (  $faults, _("php.ini check -> max_execution_time"),
436       _("The Execution time should be at least 30 seconds, because some actions may consume more time."),
437       $max_execution_time['local_value'],0,false);
439   /* memory_limit */
440   if($memory_limit['local_value'] < 16 ){
441     $memory_limit['local_value']=false;
442   }
443   $msg.= check (  $faults, _("php.ini check -> memory_limit"),
444       _("GOsa needs at least 16MB of memory, less will cause unpredictable errors! Increase it for larger setups."),
445       !$implicit_flush['local_value'],0,false);
447   /* expose_php */
448   $msg.= check (  $faults, _("php.ini check -> expose_php"),
449       _("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."),
450       !$implicit_flush['local_value'],0,false);
452   /* magic_quotes_gpc */
453   $msg.= check (  $faults, _("php.ini check -> magic_quotes_gpc"),
454       _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."),
455       $magic_quotes_gpc['local_value'],0,false);
457   return $msg;
461 function parse_contrib_conf()
464   $str                = "";
465   $used_samba_version = 0;
466   $query              = ""; 
467   $fp                 = false;
468   $output             = "";
469   $needridbase_sid    = false;
470   $pwdhash            = "";
471   $replacements       = array();
472   $ldapconf           = $_SESSION['ldapconf']; // The Installation information
473   $classes            = $_SESSION['classes'];  // Class information needed to define which features are enabled
474   $possible_plugins   = array();
476   /* Which samba version do we use? */
477   if(isset($classes['samba3'])){
478     $used_samba_version = 2;
479   } else {
480     $used_samba_version = 3;
481   }
483   /* Look for samba password generation method */
484   if(file_exists("/usr/lib/gosa/mkntpasswd")){
485     $pwdhash  = "/usr/lib/gosa/mkntpasswd";
486   } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
487     $pwdhash= "mkntpwd";
488   } else {
489     $pwdhash=('perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
490   }
492   /* Define which variables will be replaced */
493   $replacements['{LOCATIONNAME}']  = $ldapconf['location'];
494   $replacements['{SAMBAVERSION}']  = $used_samba_version;
495   $replacements['{LDAPBASE}']      = $ldapconf['base'];
496   $replacements['{LDAPADMIN}']     = $ldapconf['admin'];
497   $replacements['{DNMODE}']        = $ldapconf['peopledn'];
498   $replacements['{LDAPHOST}']      = $ldapconf['uri'];
499   $replacements['{PASSWORD}']      = $ldapconf['password'];
500   $replacements['{CRYPT}']         = $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
501   $replacements['{SID}']         = "";
502   $replacements['{RIDBASE}']     = "";
503   if($ldapconf['mail'] != "disabled"){
504     $replacements['{MAILMETHOD}']    = $ldapconf['mail_methods'][$ldapconf['mail']];
505   }   
506   $replacements['{SMBHASH}']       = $pwdhash;
507   $replacements['{GOVERNMENTMODE}']= "false"; 
508   $replacements['{kolabAccount}']  = "";
509   $replacements['{servKolab}']     = "";
510   $replacements['{errorlvl}']     = $ldapconf['errorlvl'];
512   /* This array contains all preg_replace syntax to delete all unused plugins
513      THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes'] */
515   $possible_plugins['fonreport'][]   = "'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
516   $possible_plugins['phoneaccount'][]= "'\n.*<tab.*phoneAccount.*>.*\n'i";
517   $possible_plugins['logview'][]     = "'\n.*<plugin.*logview+.*\n.*>.*\n'i";
518   $possible_plugins['pureftp'][]     = "'\n.*<tab.*pureftp.*>.*\n'i";
519   $possible_plugins['webdav'][]      = "'\n.*<tab.*webdav.*>.*\n'i";
520   $possible_plugins['phpgroupware'][]= "'\n.*<tab.*phpgroupware.*>.*\n'i";
522   /*Header information
523      Needed to send the generated gosa.conf to the browser */
524   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
525   header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
526   header("Cache-Control: no-cache");
527   header("Pragma: no-cache");
528   header("Cache-Control: post-check=0, pre-check=0");
529   header("Content-type: text/plain");
531   if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
532       preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
533     header('Content-Disposition: filename="gosa.conf"');
534   } else {
535     header('Content-Disposition: attachment; filename="gosa.conf"');
536   }
538   if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r")) {
539     echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
540   } else {
541     while(!feof($fp)) {
542       $str.= fread($fp,512);
543     }
545     if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab") {
546       $replacements['{kolabAccount}']  ="<tab class=\"kolabAccount\" />\n     ";
547       $replacements['{servKolab}']     ="<tab class=\"servkolab\" name=\"Kolab\" />";
548     }
550     if($used_samba_version == 2) {
551       /* Do nothing for samba 2... */
552     } else {
553       /* Create LDAP connection, to check if there's a domain
554          object defined in the LDAP schema */
555       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
557       /* Try to find a Samba Domain Objekt */
558       $ldap->search("(objectClass=sambaDomain)");
559     
560       /* Something found ??? so we need to define ridbase an SID by ourselfs */
561       if($ldap->count()< 1) {
562         $replacements['{SID}']= "sid=\"123412-11\"";
563         $replacements['{RIDBASE}']= "ridbase=\"1000\"";  
564       } 
565     }
567     /* Data readed, types replaced, samba version detected and checked if
568        we need to add SID and RIDBASE. Check if there is an ivbbEntry in
569        the LDAP tree, in this case we will set the governmentmode to true.
570        Create LDAP connection, to check if theres a domain Objekt definen
571        in the LDAP schema. */
572     if(!isset($ldap)){
573       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
574     }
576     /* Try to find a Samba Domain Objekt */
577     $ldap->search("(objectClass=ivbbEntry)");
579     /* Something found ??? so we need to define ridbase an SID by ourselfs */
580     if($ldap->count()> 0) {
581       $replacements['{GOVERNMENTMODE}']= "true";
582     }
584     /* Replace all colleted information with placeholder */
585     foreach($replacements as $key => $val) {
586       $str = preg_replace("/".$key."/",$val,$str);
587     }    
589     if($ldapconf['mail'] == "disabled"){
590       $str = str_replace("mailMethod=\"{MAILMETHOD}\"","",$str);
591     }
594     /* Remove all unused plugins */
595     foreach($possible_plugins as $key=> $plugin) {
596       foreach($plugin as $key=>$val) {
597         if(in_array($plugin,$classes)) {
598           $str = preg_replace($val,"\n",$str);
599         }
600       }
601     }
602   }
604   return ((($str)));
608 /* Show setup_page 1 */
609 function show_setup_page1($withoutput = true)
611   $faults = array();
612   $smarty = get_smarty();  
613   $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
614   $smarty->assign ("tests", perform_php_checks($faults));
616   /* This var is true if anything went wrong */
617   if ($faults){
618     $smarty->assign("mode", "disabled");
619   }
621   /* This line displays the template only if (withoutput is set) */
622   if($withoutput){
623     $smarty->display (get_template_path('headers.tpl'));
624   }
626   if (isset($_SESSION['errors'])){
627     $smarty->assign("errors", $_SESSION['errors']);
628   }
630   if($withoutput){
631     $smarty->display (get_template_path('setup.tpl'));
632   }
634   return (!$faults);
638 /* Show setup_page 2 */
639 function show_setup_page2($withoutput = true)
641   $faults = array();
642   $smarty = get_smarty();
643   $smarty->assign ("content", get_template_path('setup_step2.tpl'));
644   $smarty->assign ("tests", perform_additional_checks($faults));
646   if ($faults) {
647     $smarty->assign("mode", "disabled");
648   }
649   if($withoutput){
650     $smarty->display (get_template_path('headers.tpl'));
651   }
652   if (isset($_SESSION['errors']))  {
653     $smarty->assign("errors", $_SESSION['errors']);
654   }
655   if($withoutput){
656     $smarty->display (get_template_path('setup.tpl'));
657   }
659   return (!$faults);                               
663 function show_setup_page3($withoutput = true)
665   $ds = NULL;
666   $smarty = get_smarty();
668   /* Take the Post oder the Sessioin saved data */
669   if(isset($_POST['uri'])){
670     $uri = $_POST['uri'];
671   } elseif(isset($_SESSION['ldapconf']['uri'])){
672     $uri = $_SESSION['ldapconf']['uri'];
673   }
675   /* If Page called first time, field is empty */
676   if((!isset($uri))||(empty($uri))){
677     $uri = "ldap://localhost:389";
678   }
680   /* if isset $uri save it to session */
681   if(isset($uri)) {
682     $_SESSION['ldapconf']['uri'] = $uri;
683     $smarty->assign ("uri", validate($uri));
684   }
686   /* No error till now */
687   $fault = false;
689   /* If we pushed the Button continue */
690   if(isset($_POST['continue3'])){
691     if(!isset($uri)) {
692       $fault = true;
694       /* Output the Error */
695       if($withoutput) {
696         print_red (_("You've to specify an ldap server before continuing!"));
697         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
698       }
699     }
700   } elseif (!$ds = @ldap_connect (validate($uri))) {
701     $fault =true;
703     /* Output the Error */
704     if($withoutput) {
705       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
706       $smarty->assign ("uri", validate($uri));
707       $smarty->assign ("content", get_template_path('setup_step3.tpl'));
708     }
709   } else {
710     /* Try to bind the connection */    
711     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
713     /* if we can't bind , print error */
714     if (!$r  =  @ldap_bind ($ds)) {
715       $fault = true;
717       /* Output the Error */
718       if($withoutput) {
719         print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
720         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
721         $smarty->assign ("uri", validate($uri));
722       }
723     } else {
724       $fault = false;
725     }
726   }
728   $smarty->assign ("content", get_template_path('setup_step3.tpl'));
730   /* Load Header */
731   if($withoutput){
732     $smarty->display (get_template_path('headers.tpl'));
733   }
735   /* Set Errors to Smarty */
736   if (isset($_SESSION['errors'])) {
737     $smarty->assign("errors", $_SESSION['errors']);
738   }
740   /* Print out Template */ 
741   if($withoutput){
742     $smarty->display (get_template_path('setup.tpl'));
743   }
745   return (!$fault);                             
749 function show_setup_page4($withoutput = true)
751   $smarty= get_smarty();      
753         // ?
754   if(!isset($_SESSION['ldapconf']['base'])){
755     $_SESSION['ldapconf']['base']= $base;
756   }
758   if(!isset($_SESSION['ldapconf']['base'])){
759     $_SESSION['ldapconf']['base']= $base;
760   }
761   require_once("class_password-methods.inc");
763   $fault     = false;              
764   $uri       = $_SESSION['ldapconf']['uri'];
765   $ldapconf  = $_SESSION['ldapconf'];
766   $arr_crypts= array();
767   $temp      = "";
768   $checkvars = array("location", "admin", "password", "peopleou", "base",
769       "peopledn", "arr_crypts", "mail", "uidbase","errorlvl");
771   if(!isset($_SESSION['ldapconf']['arr_cryptkeys'])) {
772     require_once("class_password-methods.inc");
773     $tmp= passwordMethod::get_available_methods_if_not_loaded();
774     $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
775   }
777   if(!isset($_SESSION['ldapconf']['mail_methods'])) {
778     $_SESSION['ldapconf']['mail_methods']=array();
779     $temp = get_available_mail_classes();
780     $_SESSION['ldapconf']['mail_methods']= $temp['name'];
781   }
783   /* If there are some empty vars in ldapconnect -
784      these values also represent out default values */
785   if(!$ds = @ldap_connect (validate($uri))){
786     $fault = true;
787     if($withoutput){
788       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
789     }
790   } elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
791     $fault = true;
792     if($withoutput){
793       print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
794     }
795   } elseif(!$r= @ldap_bind ($ds)){
796     $fault = true;
797     if($withoutput){
798       print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
799     }
800   } else {
801     $sr=   @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
802     $attr= @ldap_get_entries($ds,$sr);
804     if((empty($attr))) {
805       $base= "dc=example,dc=net";
807       if($withoutput){
808         print_red(_("Bind to server successful, but the server seems to be completly empty, please check all informations twice"));
809       }
811     } else {
812       $base= $attr[0]['dn'];
813     }
814   }
816   if(!isset($_SESSION['ldapconf']['base'])){
817     $_SESSION['ldapconf']['base']= $base;
818   }
819   if(!isset($_SESSION['ldapconf']['admin'])){
820     $_SESSION['ldapconf']['admin']= "cn=ldapadmin,".$base;
821   }
822   if(!isset($_SESSION['ldapconf']['peopleou'])){
823     $_SESSION['ldapconf']['peopleou']= "ou=people";
824   }
825   if(!isset($_SESSION['ldapconf']['groupou'])){
826     $_SESSION['ldapconf']['groupou']= "ou=groups";
827   }
828   if(!isset($_SESSION['ldapconf']['peopledn'])){
829     $_SESSION['ldapconf']['peopledn']= "cn";
830   }
831   if(!isset($_SESSION['ldapconf']['password'])){
832     $_SESSION['ldapconf']['password']= "";
833   }
834   if(!isset($_SESSION['ldapconf']['location'])){
835     $_SESSION['ldapconf']['location']= "Example";
836   }
837   if(!isset($_SESSION['ldapconf']['uidbase'])){
838     $_SESSION['ldapconf']['uidbase']= "1000";
839   }
840   if(!isset($_SESSION['ldapconf']['mail'])){
841     $_SESSION['ldapconf']['mail']= 0;
842   }
843   $tmp= array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
844   if(!isset($_SESSION['ldapconf']['arr_crypts'])){
845     $_SESSION['ldapconf']['arr_crypts']   = $tmp['md5'];
846   }
848   /* check POST data */
849   if(isset($_POST['check'])) {
851     /* Check if all needed vars are submitted */
852     foreach($checkvars as $key) {
853       if($key == "peopleou"){
854         continue;
855       }
856       if($key == "groupou"){
857         continue;
858       }
860       if((isset($_POST[$key]))&&($_POST[$key]!="")) {
861         $_SESSION['ldapconf'][$key] = $_POST[$key];
862       } else {
863         if($withoutput) {
864           print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
865         }
866         $fault = true;
867       }
868     }
869   }
871   /* Transfer base */
872   if(isset($_POST['base'])){
873     $_SESSION['ldapconf']['base']= $_POST['base'];
874   }
876   $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
877   $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
879   foreach($_SESSION['ldapconf'] as $key => $val) {
880     $smarty->assign($key,$val);
881   }
883   if(isset($_POST['check'])) {
884     $ldap= new LDAP($_SESSION['ldapconf']['admin'],
885         $_SESSION['ldapconf']['password'],
886         $_SESSION['ldapconf']['uri']);
888     $m= schema_check($_SESSION['ldapconf']['uri'],
889         $_SESSION['ldapconf']['admin'],
890         $_SESSION['ldapconf']['password']);
891     $_SESSION['classes']= $m;
893     if(!is_schema_readable($ldapconf['uri'],$ldapconf['admin'],$ldapconf['password'])){
894       if($withoutput){
895         print_red(_("Can't read schema informations, GOsa needs to know your schema setup. Please verify that it is readable for GOsa"));
896       }
897       $fault=true;
898     }
902     if ($ldap->error != "Success") {
903       if($withoutput) {
904         print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
905       }
906       $fault = true;
907     }
908   }
910   /* Set smarty output */
911   $smarty->assign ("content", get_template_path('setup_step4.tpl'));
912   $smarty->assign ("peopledns", array("cn", "uid"));
913   if($withoutput){
914     $smarty->display (get_template_path('headers.tpl'));
915   }
916   if(isset($_SESSION['errors'])) {
917     $smarty->assign("errors", $_SESSION['errors']);
918   }
919   if($withoutput){
920     $smarty->display (get_template_path('setup.tpl'));
921   }
922   return (!$fault);
926 function show_setup_page5($withoutput=true)
928   /* Get ldapconf */
929   $ldapconf= $_SESSION['ldapconf'];
931   /* get smarty */
932   $smarty = get_smarty();
934   if(isset($_SESSION['classes'])){
935     $classes = $_SESSION['classes'];
936   }
938   $info= posix_getgrgid(posix_getgid());
939   $smarty->assign("webgroup", $info['name']);
940   $smarty->assign("path", CONFIG_DIR);
941   $message= "<table summary=\"\" class=\"check\">";
942   $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
944   if($withoutput) {
945     $smarty->assign ("schemas", view_schema_check($m));
946     $smarty->assign ("content", get_template_path('setup_finish.tpl'));
947   }
949   /* Output templates... */
950   if($withoutput){
951     $smarty->display (get_template_path('headers.tpl'));
952   }
953   if (isset($_SESSION['errors'])) {
954     $smarty->assign("errors", $_SESSION['errors']);
955   }
956   if($withoutput){
957     $smarty->display (get_template_path('setup.tpl'));
958   }
960   return(true);
964 function create_user_for_setup($withoutput=true)
966   global $samba;
968   $ldapconf = $_SESSION['ldapconf'];
969   $smarty = get_smarty();
970   
971   $need_to_create_group = false;
972   $need_to_create_user  = false;
974   $str_there="";
976   if(isset($_SESSION['classes'])){
977     $classes= $_SESSION['classes'];
978   }
980   /* Everything runns perfect ...
981      So we do a last test on this page
982      is there a user with ACLs :all which will be able to adminsitrate GOsa
983      We check that, if this user or group is missing we ask for creating them */
984   $ldap= new LDAP($_SESSION['ldapconf']['admin'],    $_SESSION['ldapconf']['password'],   $_SESSION['ldapconf']['uri']);
986   /* 
987   Now we are testing for a group, with the rights :all 
988   */
989   
990   $ldap->cd($ldapconf['base']);
991   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
993   $group_cnt  = $ldap->count();
994   $data       = $ldap->fetch();
996 //  $str_there  = "Searching for Aminitrative users <br><br>";
998   /* 
999   We need to create administrative user and group  because theres no group found 
1000   */
1001   if($group_cnt < 1) {
1002     
1003     /* 
1004     Set var to create user 
1005     */
1006 //    $str_there  =   "no group found<br>";
1008     $need_to_create_group = true;
1009     $need_to_create_user  = true;
1012     /* Output error */
1013     if(($withoutput)&&(!isset($_POST['new_admin']))){
1014       print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1015     }
1016   } else {
1017     
1018 //    $str_there = "Group found <br>".$data['dn'];    
1020     $need_to_create_group = false;
1021  
1022     $ldap->clearResult();
1023    
1024     /* We found an Administrative Group, is there a user, too */
1025     if(isset($data['memberUid'][0])) {
1026       $str = "uid=".$data['memberUid']['0'];
1027       $ldap->search("(&(objectClass=gosaAccount)(objectClass=person)(".$str."))");
1028       $data2   = $ldap->fetch();
1029   
1030       /* We must create a user */
1031       if (($ldap->count() < 1)||(!isset($data2))) {
1032 //        $str_there.="Missing user";
1033         
1034         $need_to_create_user = true;
1035       
1036         if(($withoutput)&&(!isset($_POST['new_admin']))){
1037           print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1038         }
1039       }else {
1040 //        $str_there.="<br>User found <br>".$data2['dn'];
1041         $need_to_create_user = false;
1042       }
1043     } else {
1044       $need_to_create_user=true;
1045       if(($withoutput)&&(!isset($_POST['new_admin']))){
1046           print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1047         }   
1048 //      $str_there.="<br>No User found <br>";
1049     }
1050   }
1052   if(!($need_to_create_user&&$need_to_create_group))
1053     return(true);
1055   /* We need to create a new user with group */
1056   if(isset($_POST['new_admin']))
1057   {
1058   
1059     /* Adjust password attributes according to the samba version */
1060     if (isset($classes['samba3'])) {
1061       $samba= "2";
1062       $lmPassword = "lmPassword";
1063       $ntPassword = "ntPassword";
1064     } else {
1065       $samba= "3";
1066       $lmPassword = "sambaLMPassword";
1067       $ntPassword = "sambaNtPassword";
1068     }
1070     /* Nothing submitted */
1071     if(((empty($_POST['admin_name']))||(empty($_POST['admin_pass'])))) {
1072       return(true);
1073     }
1075     if($need_to_create_user) {
1076       /* We have the order to create an Admin */
1077       /* Define the user we are going to create */
1078       $dn= "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1079       $arr['objectClass'][0] ="person";
1080       $arr['objectClass'][1] ="organizationalPerson";
1081       $arr['objectClass'][2] ="inetOrgPerson";
1082       $arr['objectClass'][3] ="gosaAccount";
1083       $arr['uid']            = $_POST['admin_name'];
1084       $arr['cn']             = $_POST['admin_name'];
1085       $arr['sn']             = $_POST['admin_name'];
1086       $arr['givenName']      = "GOsa main administrator";
1087       $arr[$lmPassword]      = "10974C6EFC0AEE1917306D272A9441BB";
1088       $arr[$ntPassword]      = "38F3951141D0F71A039CFA9D1EC06378";
1089       $arr['userPassword']   = crypt_single($_POST['admin_pass'],"md5");
1090     
1092       if(!$ldap->dn_exists($dn)){ 
1093         $ldap->cd($dn); 
1094         $ldap->create_missing_trees($dn);
1095         $ldap->cd($dn);
1096         $ldap->add($arr);
1097         if($ldap->error!="Success"){
1098           print_red($ldap->error);
1099           print_red("Can't create user, and / or Group, possibly this problem  depends on an empty LDAP server. Check your configuration and try again!");
1100         }
1101       }    
1102     }
1104     /* There's already a group for administrator, so we only need to add the user */
1105     if(!$need_to_create_group) {
1106       if(!isset($data['memberUid'])) {
1107         $arrr['memberUid']= $_POST['admin_name'];
1108       } else {
1109         $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1110         $arrr['memberUid'] = $data['memberUid'];
1111         unset($arrr['memberUid']['count']);
1112   
1113         $tmp = array_reverse($arrr['memberUid']);    
1114         foreach($tmp as $tt){
1115           $tmp2[]=$tt;
1116         }
1117         $arrr['memberUid']= $tmp2;
1118 //        $str_there="Group found<br>".$data['dn'];
1119       }
1121       $ldap->cd($data['dn']);
1122       $ldap->modify($arrr);
1124     } else {
1125       $dn                    = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1126       $arrr['objectClass'][0]= "gosaObject";
1127       $arrr['objectClass'][1]= "posixGroup";
1128       $arrr['gosaSubtreeACL']= ":all";
1129       $arrr['cn']            = "administrators";
1130       $arrr['gidNumber']     = "999";
1131       $arrr['memberUid']     = $_POST['admin_name'];
1133       $ldap->cd($dn);
1134       $ldap->create_missing_trees($dn);
1135       $ldap->cd($dn);
1137       $ldap->add($arrr);
1138     }
1139     return(true);
1140   } else {
1142     if((!isset($create_user))||(!($create_user))) {
1143       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1144       $smarty->assign("exists",true);
1145     } else {
1146       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1147       $smarty->assign("exists",false);
1148     }
1150   }
1152   /* Smarty output */ 
1153   if($withoutput){
1154     $smarty->display (get_template_path('headers.tpl'));
1155   }
1156   if (isset($_SESSION['errors'])) {
1157     $smarty->assign("errors", $_SESSION['errors']);
1158   }
1159   $smarty->assign("str_there",$str_there);
1160   if($withoutput){
1161     $smarty->display (get_template_path('setup.tpl'));
1162   }
1163   return(false);
1167 /* Returns the classnames auf the mail classes */
1168 function get_available_mail_classes()
1170   $dir = opendir( "../include");
1171   $methods = array();
1172   $suffix = "class_mail-methods-";
1173   $lensuf = strlen($suffix);
1174   $prefix = ".inc";
1175   $lenpre = strlen($prefix);
1177   $i = 0;
1178   while (($file = readdir($dir)) !== false){
1180     if(stristr($file,$suffix)) {
1181       $lenfile = strlen($file);
1182       $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1183       $methods['file'][$i] = $file;
1184       $methods[$i]['file'] = $file;
1185       $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1186       $i++;
1187     }
1189   }
1191   return($methods);
1194 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1195 ?>