Code

a6fcdda866291dab0a5177740c98ff6a16f5e067
[gosa.git] / include / setup_checks.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 }
10 function view_schema_check($table)
11 {
12   $message="<table class=\"check\">";
13   foreach ($table as $key => $values){
14     $msg = $values['msg'];
15     $message.= "<tr><td class=\"check\">$msg";
16     if($values['status']) {
17       $message.="</td><td style='text-align:center' ><img src=images/true.png alt='true' /></td></tr>";
18     }
19     else
20     {
21       $message.="</td><td style='text-align:center' ><img src=images/button_cancel.png alt='false' /></td></tr>";}
22   }
23   $message.="</table>";
24   return $message;
25 }
27 function schema_check($server, $admin, $password,$aff=0)
28 {
29   global $config;
30   
32   $messages= array();
33   $required_classes= array(
34       "gosaObject"            => array("version" => "2.4"),
35       "gosaAccount"           => array("version" => "2.4"),
36       "gosaLockEntry"         => array("version" => "2.4"),
37       "gosaCacheEntry"        => array("version" => "2.4"),
38       "gosaDepartment"        => array("version" => "2.4"),
40       "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
41       "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
42       "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
44       "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
45       "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
46       "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
47       "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
48       "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
50       "GOhard"                => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
51       "gotoTerminal"          => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
52       "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
53       "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
54       "goNfsServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
55       "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
56       "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
57       "goLdapServer"          => array("version" => "2.4"),
58       "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
59       "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
60       "goKrbServer"           => array("version" => "2.4"),
61       "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
62        
63         );
65   /* Build LDAP connection */
66   $ds= ldap_connect ($server);
67   if (!$ds) {
68     return (array(array("msg" => _("Can't bind to LDAP. No schema check possible!"), "status" => FALSE)));
69   }
70   ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
71   $r= ldap_bind ($ds, $admin, $password);
73   /* Get base to look for schema */
74   $sr  = @ldap_read ($ds, "", "objectClass=*", array("subschemaSubentry"));
75   $attr= @ldap_get_entries($ds,$sr);
76   if (!isset($attr[0]['subschemasubentry'][0])){
77     return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
78   }
80   /* Get list of objectclasses */
81   $nb= $attr[0]['subschemasubentry'][0];
82   $objectclasses= array();
83   $sr= ldap_read ($ds, $nb, "objectClass=*", array("objectclasses"));
84   $attrs= ldap_get_entries($ds,$sr);
85   if (!isset($attrs[0])){
86     return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
87   }
88   foreach ($attrs[0]['objectclasses'] as $val){
89     $name= preg_replace("/^.* NAME\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $val);
90     if ($name != $val){
91       $objectclasses[$name]= $val;
92     }
93   }
94   /* Walk through objectclasses and check if they are needed or not */
95   foreach ($required_classes as $key => $value){
96     if (isset($value['class'])){
97       if (!is_array($value['class'])){
98         $classes= array($value['class']);
99       } else {
100         $classes= $value['class'];
101       }
103       /* Check if we are using the class that requires */
104       foreach($classes as $class){
105         if (!isset($objectclasses[$key])){
106           $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' is not present in LDAP setup"), $key, $class);
107           $messages[$key]['status'] = FALSE;
108         } else {
109           if (!check_schema_version($objectclasses[$key], $value['version'])){
110             $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' does not have version %s"), $key, $class, $value['version']);
111             $messages[$key]['status'] =FALSE;
112           }else {
113             if(!isset($affich2[$class])){
114               $affich2[$class]['msg']   = sprintf(_("Support for '%s' enabled"), $class)."<td class=\"check\"> ".$value['file']."</td>";
115               $affich2[$class]['status']= TRUE; 
116             }
117           }
118         }
120       }
121     } else {
122       /* Required class */
123       if (!isset($objectclasses[$key])){
124         $messages[$key]['msg']= sprintf(_("Required objectclass '%s' is not present in LDAP setup"), $key);
125         $messages[$key]['status'] = FALSE;  
126     } else {
127         if (!check_schema_version($objectclasses[$key], $value['version'])){
128           $messages[$key]['msg']= sprintf(_("Required objectclass '%s' does not have version %s"), $key, $value['version']);
129           $messages[$key]['status'] = FALSE;  
130         }
131       }
132     }
133   }
135   /* Check for correct samba parameters */
136   if (!isset($objectclasses['sambaSamAccount'])){
137     $messages['samba3']['msg']        = _("SAMBA 3 support disabled, no schema seems to be installed");
138     $affich['samba3']['msg']          = $messages['samba3']['msg']."<td class=\"check\">gosa+samba3.schema</td>";
139     $messages['samba3']['status']     = FALSE;
140     $affich['samba3']['status']       = FALSE;
141   }else{
142     $affich['samba3']['msg']          = _("SAMBA 3 support enabled")."<td class=\"check\">gosa+samba3.schema</td>";
143     $affich['samba3']['status']       = TRUE;
144   }
146   if (!isset($objectclasses['sambaAccount'])){
147     $messages['samba2']['msg']        = _("SAMBA 2 support disabled, no schema seems to be installed");
148     $affich['samba2']['msg']          = $messages['samba2']['msg']."<td class=\"check\">samba.schema</td>";
149     $messages['samba2']['status']     = FALSE;
150     $affich['samba2']['status']       = FALSE;
151   }else{
152     $affich['samba2']['msg']          = _("SAMBA 2 support enabled")."<td class=\"check\">samba.schema</td>";
153     $affich['samba2']['status']       = TRUE;
154   }
156   /* Check pureftp/dns/ */
157   if (!isset($objectclasses['PureFTPdUser'])){
158     $messages['pureftp']['msg']       = _("Support for pureftp disabled, no schema seems to be installed");
159     $affich['pureftp']['msg']         = $messages['pureftp']['msg']."<td class=\"check\">pureftpd.schema</td>";
160     $messages['pureftp']['status']    = FALSE;
161     $affich['pureftp']['status']      = FALSE;
162   }else{
163     $affich['pureftp']['msg']         = _("Support for pureftp enabled")."<td class=\"check\">pureftpd.schema</td>";
164     $affich['pureftp']['status']      = TRUE;
165   }
167   if (!isset($objectclasses['gosaWebdavAccount'])){
168     $messages['webdav']['msg']        = _("Support for WebDAV disabled, no schema seems to be installed");
169     $affich['webdav']['msg']          = $messages['webdav']['msg']."<td class=\"check\"></td>";
170     $messages['webdav']['status']     = FALSE;
171     $affich['webdav']['status']       = FALSE;
172   }else{
173     $affich['webdav']['msg']=_("Support for WebDAV enabled")."<td class=\"check\">gosa+samba3.schema</td>";
174     $affich['webdav']['status']       = TRUE;
175   }
177   if (!isset($objectclasses['phpgwAccount'])){
178     $messages['phpgroupware']['msg']  = _("Support for phpgroupware disabled, no schema seems to be installed");
179     $affich['phpgroupware']['msg']=$messages['phpgroupware']['msg']."<td class=\"check\">phpgwaccount.schema</td>";
180     $messages['phpgroupware']['status']  = FALSE;
181     $affich['phpgroupware']['status']    = FALSE;
182   }else{
183     $affich['phpgroupware']['msg']       = _("Support for phpgroupware enabled")."<td class=\"check\">phpgwaccount.schema</td>";
184     $affich['phpgroupware']['status']    = TRUE;
185   }
187   if (!isset($objectclasses['goFonAccount'])){
188     $messages['phoneaccount']['msg']     = _("Support for gofon disabled, no schema seems to be installed");
189     $affich['phoneaccount']['msg']       = $messages['phoneaccount']['msg']."<td class=\"check\">gofon.schema</td>";
190     $messages['phoneaccount']['status']  = FALSE;
191     $affich['phoneaccount']['status']    = FALSE;
192   }else{
193     $affich['phoneaccount']['msg']       = _("Support for gofon enabled")."<td class=\"check\">gofon.schema</td>";
194     $affich['phoneaccount']['status']    = true;
195   }
197   
198   if(($_SESSION['ldapconf']['mail_methods'][$_SESSION['ldapconf']['mail']] == "kolab")){
199     if(!isset($objectclasses['kolabInetOrgPerson']))
200       {
201       $messages['kolab']['msg']          = _("Support for Kolab disabled, no schema seems to be installed, setting mail-method to cyrus");
202       $affich['kolab']['msg']            =$messages['kolab']['msg']."<td class=\"check\">kolab2.schema</td>";
203       
204       $tmp = array_flip($_SESSION['ldapconf']['mail_methods']);
205       $_SESSION['ldapconf']['mail']      =$tmp['cyrus'];
206     
207       $messages['kolab']['status']       = FALSE;
208       $affich['kolab']['status']         = FALSE;
209     }else{
210       $affich['kolab']['msg']            =_("Support for Kolab enabled")."<td class=\"check\">gofon.schema</td>";
211       $affich['kolab']['status']         = TRUE;
212     }
213   }
214   if($aff==0)return ($messages);
215   else return(array_merge($affich,$affich2));
222 function check(&$faults, $message, $description, $test, $required= TRUE)
224   $msg= "<table class='check'><tr><td class='check' style='font-size:14px;'>$message</td><td rowspan=2 style='vertical-align:middle; text-align:center;width:45px;'>";
225   if ($test){
226     $msg.= _("OK")."<br>";
227   } else {
228     if (!$required){
229       $msg.="<font color=red>"._("Ignored")."</font><br>";
230     } else {
231       $msg.="<font color=red>"._("Failed")."</font><br>";
232       $faults++;
233     }
234   }
235   $msg.= "</td></tr><tr><td class='check' style='padding-left:20px;background-color:#F0F0F0;'>$description</td></tr></table><br>";
237   return $msg;
240 function perform_php_checks(&$faults)
242   global $check_globals;
244   $faults= 0;
245   $msg= "";
247   $msg.= "<h1>"._("PHP setup inspection")."</h1>";
248   $msg.= check (        $faults, _("Checking for PHP version (>=4.1.0)"),
249       _("PHP must be of version 4.1.0 or above for some functions and known bugs in PHP language."),
250        version_compare(phpversion(), "4.1.0")>=0);
252   $msg.= check (        $faults, _("Checking if register_globals is set to 'off'"),
253       _("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."),
254       $check_globals == 0, FALSE);
256   $msg.= check (        $faults, _("Checking for ldap module"),
257       _("This is the main module used by GOsa and therefore really required."),
258       function_exists('ldap_bind'));
260   $msg.= check (        $faults, _("Checking for gettext support"),
261       _("Gettext support is required for internationalized GOsa."), function_exists('bindtextdomain'));
263   $msg.= check (        $faults, _("Checking for iconv support"),
264       _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
265       function_exists('iconv'));
267   $msg.= check (        $faults, _("Checking for mhash module"),
268       _("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."),
269       function_exists('mhash'), FALSE);
271   $msg.= check (        $faults, _("Checking for imap module"),
272       _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
273       function_exists('imap_open'));
274   $msg.= check (        $faults, _("Checking for getacl in imap"),
275       _("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."),
276       function_exists('imap_getacl'), FALSE);
277   $msg.= check (        $faults, _("Checking for mysql module"),
278       _("MySQL support is needed for reading GOfax reports from databases."),
279       function_exists('mysql_query'), FALSE);
280   $msg.= check (        $faults, _("Checking for cups module"),
281       _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
282       function_exists('cups_get_dest_list'), FALSE);
283   $msg.= check (        $faults, _("Checking for kadm5 module"),
284       _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
285       function_exists('kadm5_init_with_password'), FALSE);
286   return ($msg);
290 function perform_additional_checks(&$faults)
292 # Programm check
293   $msg= "<h1>"._("Checking for some additional programms")."</h1>";
295 # Image Magick
296   $query= "LC_ALL=C LANG=C convert -help";
297   $output= shell_exec ($query);
298   if ($output != ""){
299     $lines= split ("\n", $output);
300     $version= preg_replace ("/^Version:[^I]+ImageMagick ([^\s]+).*/", "\\1", $lines[0]);
301     list($major, $minor)= split("\.", $version);
302     $msg.= check (      $faults, _("Checking for ImageMagick (>=5.4.0)"),
303         _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
304         ($major > 5 || ($major == 5 && $minor >= 4)));
305   } else {
306     $msg.= check (      $faults, _("Checking imagick module for PHP"),
307         _("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);
308   }
310 # Check for fping
311   $query= "LC_ALL=C LANG=C fping -v 2>&1";
312   $output= shell_exec ($query);
313   $have_fping= preg_match("/^fping:/", $output);
314   $msg.= check (        $faults, _("Checking for fping utility"),
315       _("The fping utility is only used if you've got a thin client based terminal environment running."),
316       $have_fping, FALSE);
318 # Check for smb hash generation tool
319   $query= "mkntpwd 2>&1";
320   $output= shell_exec ($query);
321   $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
322   $alt = 0;
324   if (!$have_mkntpwd){
325     $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
326     system ($query, $ret);
327     $alt= ($ret == 0);
328   }
330   $msg.= check (        $faults, _("Checking for a way to generate LM/NT password hashes"),
331       _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
332       ($have_mkntpwd || $alt));
333 # checking for some PHP.ini Options
335 /* seesio.auto_start should be off, in order to without trouble*/
337 $arra = ini_get_all();
339 /* This array contains folling info now : 
340   global_value  0
341   local_value   0
342   access        7               
344 -->Access types
345 PHP_INI_USER      1          Entry can be set in user scripts
346 PHP_INI_PERDIR    2          Entry can be set in php.ini, .htaccess or httpd.conf 
347 PHP_INI_SYSTEM    4          Entry can be set in php.ini or httpd.conf 
348 PHP_INI_ALL       7          Entry can be set anywhere 
350 */
352 $session_auto_start =     ($arra['session.auto_start']);
353 $implicit_flush     =     ($arra['implicit_flush']);
354 $max_execution_time =     ($arra['max_execution_time']);
355 $memory_limit =           ($arra['memory_limit']);
356 $expose_php =             ($arra['expose_php']);
357 $magic_quotes_gpc =       ($arra['magic_quotes_gpc']);
358 $register_globals =       ($arra['register_globals']);
361 // auto_register
362 $msg.= check (  $faults, _("php.ini check -> session.auto_register"),
363     _("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']));
367 //implicit_flush
368 $msg.= check (  $faults, _("php.ini check -> implicit_flush"),
369     _("This option influences the Output handling. Turn this Option off, to increase performance."),
370     !$implicit_flush['local_value'],0,false);
372 //max_execution_time
373 if($max_execution_time['local_value'] < 30 ){
374   $max_execution_time['local_value']=false;
376 $msg.= check (  $faults, _("php.ini check -> max_execution_time"),
377     _("The Execution time should be at least 30 seconds, because some actions may consume more time."),
378     $max_execution_time['local_value'],0,false);
380 //memory_limit
381 if($memory_limit['local_value'] < 8 ){
382   $memory_limit['local_value']=false;
384 $msg.= check (  $faults, _("php.ini check -> memory_limit"),
385     _("GOsa needs at least 8MB of memory, less will cause unpredictable errors! An optimal setting would be 16MB, increase it for larger setups."),
386     !$implicit_flush['local_value'],0,false);
388 //expose_php
389 $msg.= check (  $faults, _("php.ini check -> expose_php"),
390     _("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."),
391     !$implicit_flush['local_value'],0,false);
393 //magic_quotes_gpc
394 $msg.= check (  $faults, _("php.ini check -> magic_quotes_gpc"),
395     _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."),
396     $magic_quotes_gpc['local_value'],0,false);
398 return $msg;
403 //! Added by Hickert
404 //
405 // Parse /contrib/gosa.conf to set user defined values
406 //This function may create the ldap.conf
407 // Lets try
408 function parse_contrib_conf()
410   /* First gather all needed informations */
414   /* Variables */
415   $str                = "";
416   $used_samba_version = 0;
417   $query              = ""; 
418   $fp                 = false;
419   $output             = "";
420   $needridbase_sid    = false;
421   $pwdhash            = "";
422   $replacements       = array();
423   $ldapconf           = $_SESSION['ldapconf']; // The Installation information
424   $classes            = $_SESSION['classes'];  // Class information needed to define which features are enabled
425   $possible_plugins   = array();
427   if(isset($classes['samba3']))  // means Samba 3 is disabled
428     $used_samba_version = 2;
429   else
430     $used_samba_version = 3;
433   if(file_exists("/usr/lib/gosa/mkntpasswd"))    {
434     $pwdhash  = "/usr/lib/gosa/mkntpasswd";
435   }
436   elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1")))    {
437     $pwdhash= "mkntpwd";
438   } else {
439     
440     $pwdhash=('perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
441     //    $pwdhash= 'perl -MCrypt::SmbHash -e \"ntlmgen \\"\\$ARGV[0]\\", \\$lm, \\$nt; print \\"\\${lm}:\\${nt}\\\";\"'; 
442   }
445   // Define which variables will be replaced
446   $replacements['{LOCATIONNAME}']           =   $ldapconf['location'];
447   $replacements['{SAMBAVERSION}']           =   $used_samba_version;
448   $replacements['{LDAPBASE}']               =   $ldapconf['base'];
449   $replacements['{LDAPADMIN}']              =   $ldapconf['admin'];
450   $replacements['{DNMODE}']                 =   $ldapconf['peopledn'];
451   $replacements['{LDAPHOST}']               =   $ldapconf['uri'];
452   $replacements['{PASSWORD}']               =   $ldapconf['password'];
453   $replacements['{CRYPT}']                  =   $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
454   $replacements['{SID}\n']                    =   "";
455   $replacements['{RIDBASE}\n']                =   "";
456   $replacements['{MAILMETHOD}']             =   $ldapconf['mail_methods'][$ldapconf['mail']];
457   $replacements['{SMBHASH}']                =   $pwdhash;
458   $replacements['{GOVERNMENTMODE}']         =   "false"; 
459   $replacements['{kolabAccount}']           =   "";
460   $replacements['{servKolab}']              =   "";
463   // This array contains all preg_replace syntax to delete all unused plugins
464   // THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes']
466   $possible_plugins['fonreport'][]      ="'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
467   $possible_plugins['phoneaccount'][]   ="'\n.*<tab.*phoneAccount.*>.*\n'i";
469   $possible_plugins['logview'][]        ="'\n.*<plugin.*logview+.*\n.*>.*\n'i";
471   $possible_plugins['pureftp'][]        ="'\n.*<tab.*pureftp.*>.*\n'i";
473   $possible_plugins['webdav'][]         ="'\n.*<tab.*webdav.*>.*\n'i";
475   $possible_plugins['phpgroupware'][]   ="'\n.*<tab.*phpgroupware.*>.*\n'i";
478   // Header information
479   // Needed to send the generated gosa.conf to the browser
480   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
481   header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
482   header("Cache-Control: no-cache");
483   header("Pragma: no-cache");
484   header("Cache-Control: post-check=0, pre-check=0");
485   header("Content-type: text/plain");
487   if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||  preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT']))
488   {
489     header('Content-Disposition: filename="gosa.conf"');
490   } else {
491     header('Content-Disposition: attachment; filename="gosa.conf"');
492   }
495   if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r"))
496   {
497     echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
498     // Don't write anything else
499   }
500   else
501   {
502     // Read out Data .....  
503     while(!feof($fp))
504     {
505       $str.= fread($fp,512);
506     }
509     
510     if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab")
511       {
512       $replacements['{kolabAccount}']  ="<tab class=\"kolabAccount\" />\n     ";
513       $replacements['{servKolab}']     ="<tab class=\"servkolab\" name=\"Kolab\" />";
514       }
515       
520     // Lets check which samba version we will use
522     // in case of samba 2 we don't need to add additional objets in gosa.conf
523     // in case of samba 3 we musst detect if theres an objectType = SambaObjekt defined
524     //   if theres is one, then do nothing, because the setup will detect the the SID themself
525     //   if theres none defined add SID and RIDBASE to gosa.conf
528     if($used_samba_version == 2)
529     {
530       // Do nothing ...
531     }
532     else
533     {
534       // Create LDAP connection, to check if theres a domain Objekt definen in the Ldap scheme
535       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
538       // Try to find a Samba Domain Objekt
539       $ldap->search("(objectClass=sambaDomain)");
541       // Something found ??? so we need to define ridbase an SID by ourselfs
542       if($ldap->count()< 1)
543       {
544         $replacements['{SID}']                  =   "sid=\"123412-11\"";
545         $replacements['{RIDBASE}']              =   "ridbase=\"1000\"";  
546       } 
547     }// else --> $used_samba_version == 2
549     // Data readed, types replaced, samba version detected and checked if we need to add SID and RIDBASE 
552     // Check if there is an ivbbEntry in the LDAP tree, in this case we will set the governmentmode to true
553     // Create LDAP connection, to check if theres a domain Objekt definen in the Ldap scheme
555     if(!isset($ldap))
556       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
559     // Try to find a Samba Domain Objekt
560     $ldap->search("(objectClass=ivbbEntry)");
562     // Something found ??? so we need to define ridbase an SID by ourselfs
563     if($ldap->count()> 0)
564     {
565       $replacements['{GOVERNMENTMODE}']                  =   "true";
566     }
569     // Replace all colleted information with placeholder
570     foreach($replacements as $key => $val)
571     {
572       $str = preg_replace("/".$key."/",$val,$str);
573       //      $str = ereg_replace($key,$val,$str);
574     }    
576     // Remove all unused plugins
577     foreach($possible_plugins as $plugin)
578     {
579       foreach($plugin as $key=>$val)
580       {
581         if(in_array($plugin,$classes))
582         {
583           $str = preg_replace($val,"\n",$str);
584         }
585       }
586     }
589   }// else -->  !$fp=fopen("../contrib/gosa.conf","r")
591   return ((($str)));
595 // This ist the first page shown in setup
596 // This page test some packages, like php version, ldap_module aso
597 // The funtion don't save anything, it tests only, when withoutput = false
598 // (called from setup.php);
599 function show_setup_page1($withoutput = true)
601   $smarty = get_smarty();  
603   $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
604   $smarty->assign ("tests", perform_php_checks($faults));
608   // This var is true if there is anything went wrong
609   if ($faults)
610   {
611     $smarty->assign("mode", "disabled");
612   }
614   // This line displays the template only if (withoutput is set)
615   if($withoutput) 
616     $smarty->display (get_template_path('headers.tpl'));
618   if (isset($_SESSION['errors']))
619   {
620     $smarty->assign("errors", $_SESSION['errors']);
621   }
623   if($withoutput)
624     $smarty->display (get_template_path('setup.tpl'));
626   return (!$faults);
635 /* Shows Setup_page 2*/
636 function show_setup_page2($withoutput = true)
638   $smarty = get_smarty();
640   $smarty->assign ("content", get_template_path('setup_step2.tpl'));
641   $smarty->assign ("tests", perform_additional_checks($faults));
643   if ($faults) {
644     $smarty->assign("mode", "disabled");
645   }
646   if($withoutput){
647     $smarty->display (get_template_path('headers.tpl'));
648   }
650   if (isset($_SESSION['errors']))  {
651     $smarty->assign("errors", $_SESSION['errors']);
652   }
653   if($withoutput){
654     $smarty->display (get_template_path('setup.tpl'));
655   }
656   return (!$faults);                               
660 /* Setup page 3 asks for the server address
661  "Now we're going to include your LDAP server and create an initial configuration"*/
662 function show_setup_page3($withoutput = true)
665   // Take the Post oder the Sessioin saved data  
666   if(isset($_POST['uri']))
667     $uri = $_POST['uri'];
668   elseif(isset($_SESSION['ldapconf']['uri']))
669     $uri = $_SESSION['ldapconf']['uri'];
671   // If Page called first time, field is empty 
672   if((!isset($uri))||(empty($uri)))
673     $uri = "ldap://localhost:389";
676   $smarty = get_smarty();
678   // if isset $uri save it to session
679   if(isset($uri))
680   {
681     $_SESSION['ldapconf']['uri'] = $uri;
682     $smarty->assign ("uri", validate($uri));
683   }
686   // No error till now
687   $fault = false;
690   // If we pushed the Button continue
691   if(isset($_POST['continue3']))
692     if(!isset($uri))
693     {
694       $fault = true;
695       // Output the Error
696       if($withoutput)
697       {
698         print_red (_("You've to specify an ldap server before continuing!"));
699         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
700       }
701     }
702   elseif (!$ds = @ldap_connect (validate($uri)))
703   {
704     $fault =true;
705     // Output the Error
706     if($withoutput)
707     {
708       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
709       $smarty->assign ("uri", validate($uri));
710       $smarty->assign ("content", get_template_path('setup_step3.tpl'));
711     }
712   }
713     else
714     {
715       // Try to bind the connection     
716       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
718       // if we can't bind , print error
719       if (!$r  =  @ldap_bind ($ds))
720       {
721         $fault = true;
722         // Output the Error
723         if($withoutput)      
724         {
725           print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
726           $smarty->assign ("content", get_template_path('setup_step3.tpl'));
727           $smarty->assign ("uri", validate($uri));
728         }
729       }
730       else
731       {
732         $fault = false;
733       }
734     }
737   $smarty->assign ("content", get_template_path('setup_step3.tpl'));
740   // Load Header
741   if($withoutput)
742     $smarty->display (get_template_path('headers.tpl'));
744   // Set Errors to Smarty
745   if (isset($_SESSION['errors']))
746   {
747     $smarty->assign("errors", $_SESSION['errors']);
748   }
750   // Print out Template 
751   if($withoutput)
752     $smarty->display (get_template_path('setup.tpl'));
756   return (!$fault);                             
761 // Setup page 4
762 // This page asked for detailed info, like base dn or admin user
763 // if evrything is ok , but there's a missing user with ACL :all we show a a user creation page before we show page 5
764 function show_setup_page4($withoutput = true)
769   if(!isset($_SESSION['ldapconf']['base']))           $_SESSION['ldapconf']['base']         = $base;
771   if(!isset($_SESSION['ldapconf']['base']))           $_SESSION['ldapconf']['base']         = $base;
772   require_once("class_password-methods.inc");
774   error_reporting(E_ALL);
779   $fault        = false;                        // If an error occures we set this var to true 
780   $smarty       = get_smarty();                 // Our smarty instance
781   $uri          = $_SESSION['ldapconf']['uri']; // This is the the connect path to the ldapserver like ldap://lo..
782   $ldapconf     = $_SESSION['ldapconf'];        // The ldap Configuration informations, we collected while setup 
783   $arr_crypts   = array();                      // array which includes contains all possible password crypting methods
784   $temp         = "";                           // Temp
785   $checkvars    = array("location","admin","password","peopleou","peopledn","arr_crypts","mail","uidbase","base");
788   if(!isset($_SESSION['ldapconf']['arr_cryptkeys']))
789   {
790     require_once("class_password-methods.inc");
791     $tmp = passwordMethod::get_available_methods_if_not_loaded();
792     $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
793   }
797   if(!isset($_SESSION['ldapconf']['mail_methods']))
798   {
799     $_SESSION['ldapconf']['mail_methods']=array();
800     $temp = get_available_mail_classes();
801     $_SESSION['ldapconf']['mail_methods']= $temp['name'];
802   }
807   // If there are some empty vars in ldapconnect
808   // This values also represent out default values 
810 # first try to get $base 
811   if(!$ds = @ldap_connect (validate($uri)))    
812   {
813     $fault = true;
814     if($withoutput)
815       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
816   }
817   elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3))    
818   {
819     $fault = true;
820     if($withoutput)
821       print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
822   }
823   elseif(! $r =  @ldap_bind ($ds))    
824   {
825     $fault = true;
826     if($withoutput)
827       print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
828   }
829   else
830   {
831     $sr=      @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
834     $attr=    @ldap_get_entries($ds,$sr);
835     if((empty($attr)))
836     {
837       $base= "dc=example,dc=net";
840       if($withoutput)
841         print_red(_("Bind to server successful, but the server seems to be completly empty, please check all informations twice"));
843     }
844     else
845     {
846       $base= $attr[0]['dn'];
847     }
848   }
852   if(!isset($_SESSION['ldapconf']['base']))           $_SESSION['ldapconf']['base']         = $base;
853   if(!isset($_SESSION['ldapconf']['admin']))          $_SESSION['ldapconf']['admin']        = "cn=ldapadmin,".$base;
854   if(!isset($_SESSION['ldapconf']['peopleou']))       $_SESSION['ldapconf']['peopleou']     = "ou=people";
855   if(!isset($_SESSION['ldapconf']['groupou']))        $_SESSION['ldapconf']['groupou']      = "ou=groups";
856   if(!isset($_SESSION['ldapconf']['peopledn']))       $_SESSION['ldapconf']['peopledn']     = "cn";
857   if(!isset($_SESSION['ldapconf']['password']))       $_SESSION['ldapconf']['password']     = "";
858   if(!isset($_SESSION['ldapconf']['location']))       $_SESSION['ldapconf']['location']     = "Example";
859   if(!isset($_SESSION['ldapconf']['uidbase']))        $_SESSION['ldapconf']['uidbase']      = "1000";
860   if(!isset($_SESSION['ldapconf']['mail']))           $_SESSION['ldapconf']['mail']         = 0;
861   $tmp = array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
862   if(!isset($_SESSION['ldapconf']['arr_crypts']))     $_SESSION['ldapconf']['arr_crypts']   = $tmp['md5'];
865   // check Post data
867   if(isset($_POST['check']))
868   {
869     // Check if all needed vars are submitted
870     foreach($checkvars as $key)
871     {
872     if($key == "peopleou")  continue;
873     if($key == "groupou")  continue;
874   
875       if((isset($_POST[$key]))&&($_POST[$key]!=""))
876       {
877         $_SESSION['ldapconf'][$key] = $_POST[$key];
878       }
879       else
880       {
881         if($withoutput)
882         {
883           print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
884         }
885         $fault = true;
886       }
887     }
889     // check if another base is given ... (ldapadmin...dc=base,dc=de)   ..
891     $base     =   $_SESSION['ldapconf']['admin'];
892     $tmp      =   array_reverse ( split(",",$base));
893     $base     =   $tmp[1].",".$tmp[0];
894     $_SESSION['ldapconf']['base']         = $base;
897   }
899   if(isset($_POST['base']))
900     $_SESSION['ldapconf']['base']= $_POST['base'];
902   $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
903   $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
905   foreach($_SESSION['ldapconf'] as $key => $val)
906   {
907     $smarty->assign($key,$val);
908   }
910   if(isset($_POST['check']))
911   {
912     $ldap= new LDAP($_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password'], $_SESSION['ldapconf']['uri']);
913   
914     $m= schema_check($_SESSION['ldapconf']['uri'], $_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password']);
915     $_SESSION['classes']= $m;
917     if ($ldap->error != "Success")
918     {
919       if($withoutput)
920       {
921         print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
922       }
923       $fault = true;
924     }
925   }
929   // Set smarty output
930   $smarty->assign ("content", get_template_path('setup_step4.tpl'));
932   $smarty->assign ("peopledns", array("cn", "uid"));
933   if($withoutput)
934     $smarty->display (get_template_path('headers.tpl'));
936   if(isset($_SESSION['errors']))
937   {
938     $smarty->assign("errors", $_SESSION['errors']);
939   }
940   if($withoutput)
941     $smarty->display (get_template_path('setup.tpl'));
944   return (!$fault);
952 // This page shows your configuration 
953 // and wants you to download the gosa.conf ....
954 function show_setup_page5($withoutput=true)
956   // Get ldapconf
957   $ldapconf= $_SESSION['ldapconf'];
959   // get smarty
960   $smarty = get_smarty();
962   if(isset($_SESSION['classes']))
963     $classes = $_SESSION['classes'];
965   $info= posix_getgrgid(posix_getgid());
966   $smarty->assign ("webgroup", $info['name']);
967   $smarty->assign ("path", CONFIG_DIR);
968   $message = "";
969   $message.="<table class=\"check\">";
970   $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
971   
972   if($withoutput)
973   {
974     $smarty->assign ("schemas", view_schema_check($m));
975     $smarty->assign ("content", get_template_path('setup_finish.tpl'));
976   }
977   // Output templates ....
979   if($withoutput)
980     $smarty->display (get_template_path('headers.tpl'));
982   if (isset($_SESSION['errors']))
983   {
984     $smarty->assign("errors", $_SESSION['errors']);
985   }
986   if($withoutput)
987     $smarty->display (get_template_path('setup.tpl'));
988   return(true);
1002 // this function is called by setup step 5, in order to create a missinf Administrator 
1003 // and or Administrational user
1004 // on success go on with setup_page5
1005 // else show this page aggain
1006 function create_user_for_setup($withoutput=true)
1009   error_reporting(E_ALL);
1011   global $samba;
1013   $ldapconf = $_SESSION['ldapconf'];
1014   $smarty = get_smarty();
1017   
1018   if(isset($_SESSION['classes']))
1019     $classes= $_SESSION['classes'];
1021   // Everything runns perfect ...
1022   // So we do a last test on this page
1023   // is there a user with ACLs :all which will be able to adminsitrate GOsa
1024   // We check that, if this user or group is missing we ask for creating them
1026   $ldap= new LDAP($_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password'], $_SESSION['ldapconf']['uri']);
1028   //  $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
1030   // Now we are testing for a group, with the rights :all
1031   $ldap->cd($ldapconf['base']);
1032   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
1034   $group_cnt       = $ldap->count();
1035   $data           = $ldap->fetch();
1036   $create_user    = false;
1038   // We need to create Administrative user and group
1039   // Because theres no Group found
1040   if($group_cnt < 1)
1041   {
1042     // Set var to create user
1043     $create_user    =   true;
1045     // Output error
1046     if(($withoutput)&&(!isset($_POST['new_admin'])))
1047       print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1048   }
1049   else
1050   {
1052     // We found an Administrative Group, is there a user too
1053     if(isset($data['memberUid'][0]))
1054     {
1055       $ldap->search("(&(objectClass=gosaAccount)(objectClass=person))",array("uid=".$data['memberUid'][0]));
1056       $data2      = $ldap->fetch();
1057       $user_cnt   = $ldap->count();
1058     }
1060     // We must create a user
1061     if (($ldap->count() < 1)||(!isset($data2)))
1062     {
1063       $create_user = true;
1064       if(($withoutput)&&(!isset($_POST['new_admin'])))
1065         print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1066     }
1067     else
1068     {
1069       // We don't need to add a user
1070       return(true);
1071     }
1073   }// if($group_cn)
1075   // We need to create a new user with group
1076   if(isset($_POST['new_admin']))
1077   {
1078     // Is there a running user ?
1079     // Then add additional
1081     if (isset($classes['samba3']))
1082     {
1083       $samba= "2";
1084       $lmPassword = "lmPassword";
1085       $ntPassword = "ntPassword";
1086     } else {
1087       $samba= "3";
1088       $lmPassword = "sambaLMPassword";
1089       $ntPassword = "sambaNtPassword";
1090     }
1093     // Nothing submitted
1094     if(( (empty($_POST['admin_name']))||(empty($_POST['admin_pass'])) )&&(!$create_user))
1095     {
1096       return(true);
1097     }
1099     // We have the order to create on Admin ^^
1100     // Detect Samba version to define the Attribute names shown below
1101     // go to base
1102     $ldap->cd($ldapconf['base']);
1104     // Define the user we are going to create
1105     $dn =  "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1108     $arr['objectClass'][0] ="person";
1109     $arr['objectClass'][1] ="organizationalPerson";
1110     $arr['objectClass'][2] ="inetOrgPerson";
1111     $arr['objectClass'][3] ="gosaAccount";
1112     $arr['uid']            = $_POST['admin_name'];
1113     $arr['cn']             = $_POST['admin_name'];
1114     $arr['sn']             = $_POST['admin_name'];
1116     $arr['givenName']     = "GOsa main administrator";
1117     $arr[$lmPassword]     = "10974C6EFC0AEE1917306D272A9441BB";
1118     $arr[$ntPassword]     = "38F3951141D0F71A039CFA9D1EC06378";
1119     $arr['userPassword']  = crypt_single($_POST['admin_pass'],"md5");
1120     if( ! $ldap->dn_exists ( $dn )) { 
1121       $ldap->cd($dn); 
1122       $ldap->create_missing_trees($dn);
1123       $ldap->add($arr);
1124       if($ldap->error!="Success")      {
1125         print_red("Can't create user, and / or Group, possibly this problem  depends on an empty LDAP server. Check your configuration and try again!");
1126       }
1127     }
1129     // theres already a group for administrator, so we only need to add the user
1130     if($group_cnt)
1131     {
1132       if(!isset($data['memberUid']))
1133       {
1134         $arrr['memberUid']= $_POST['admin_name'];
1135       }
1136       else
1137       {
1138         $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1139         $arrr['memberUid'] = $data['memberUid'];
1140         unset($arrr['memberUid']['count']);
1141       }
1142       $ldap->cd($data['dn']);
1143       $ldap->modify($arrr);
1144     }
1145     else
1146     {
1147       // there was no group defined, so we must create one
1148       $dn                       = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1149       $arrr['objectClass'][0]   = "gosaObject";
1150       $arrr['objectClass'][1]   = "posixGroup";
1151       $arrr['gosaSubtreeACL']   = ":all";
1152       $arrr['cn']               = "administrators";
1153       $arrr['gidNumber']        = "999";
1154       $arrr['memberUid']        = $_POST['admin_name'];
1155       $ldap->cd($dn);
1156       $ldap->add($arrr);
1157     }
1160     // We created the Group and the user, so we can go on with the next setup step
1161     return(true);
1162   }
1163   else
1164   {
1165     if(!($create_user))
1166     {
1167       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1168       $smarty->assign("exists",true);
1169     }
1170     else
1171     {
1172       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1173       $smarty->assign("exists",false);
1174     }
1175   }
1178   // Smarty outout  
1180   if($withoutput)
1181     $smarty->display (get_template_path('headers.tpl'));
1183   if (isset($_SESSION['errors']))
1184   {
1185     $smarty->assign("errors", $_SESSION['errors']);
1186   }
1187   if($withoutput)
1188     $smarty->display (get_template_path('setup.tpl'));
1191   return(false);
1195 // Returns the classnames auf the mail classes
1196 function get_available_mail_classes()
1198   $dir = opendir( "../include");
1199   $methods = array();
1200   $suffix = "class_mail-methods-";
1201   $lensuf = strlen($suffix);
1202   $prefix = ".inc";
1203   $lenpre = strlen($prefix);
1206   $i = 0;
1207   while (($file = readdir($dir)) !== false) 
1208   {
1209     if(stristr($file,$suffix))
1210     {
1211       $lenfile = strlen($file);
1212       $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1213       $methods['file'][$i] = $file;
1214       $methods[$i]['file'] = $file;
1215       $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1216       $i++;
1217     }
1218   }
1219   return($methods);
1228 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1229 ?>