Code

Updated locales
[gosa.git] / include / setup_checks.inc
1 <?php
3 function minimum_version($vercheck)
4 {
5   $minver = (int)str_replace('.', '', $vercheck);
6   $curver = (int)str_replace('.', '', phpversion());
8   if($curver >= $minver){
9     return (true);
10   }
12   return (false);
13 }
16 function check_schema_version($description, $version)
17 {
18   $desc= preg_replace("/^.* DESC\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $description);
20   return preg_match("/\(v$version\)/", $desc);
21 }
23 function view_schema_check($table)
24 {
25   $message="<table class=\"check\">";
26   foreach ($table as $key => $msg){
27     $message.= "<tr><td class=\"check\">$msg";
28     if(strstr($msg,"enabled")) {
29       $message.="</td><td style='text-align:center' ><img src=images/true.png alt='true' /></td></tr>";
30     }
31     else
32     {
33       $message.="</td><td style='text-align:center' ><img src=images/button_cancel.png alt='false' /></td></tr>";}
34   }
35   $message.="</table>";
36   return $message;
37 }
39 function schema_check($server, $admin, $password,$aff=0)
40 {
41   global $config;
42   
44   $messages= array();
45   $required_classes= array(
46       "gosaObject"            => array("version" => "2.1"),
47       "gosaAccount"           => array("version" => "2.1.2"),
48       "gosaLockEntry"         => array("version" => "2.1"),
49       "gosaCacheEntry"        => array("version" => "2.1"),
50       "gosaDepartment"        => array("version" => "2.1"),
52       "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
53       "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
54       "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
56       "gosaUserTemplate"      => array("version" => "2.1", "class" => "posixAccount","file" => "nis.schema"),
57       "gosaMailAccount"       => array("version" => "2.1", "class" => "mailAccount","file" => "gosa+samba3.schema"),
58       "gosaProxyAccount"      => array("version" => "2.1.2", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
59       "gosaApplication"       => array("version" => "2.1", "class" => "appgroup","file" => "gosa.schema"),
60       "gosaApplicationGroup"  => array("version" => "2.1", "class" => "appgroup","file" => "gosa.schema"),
62       "GOhard"                => array("version" => "2.1", "class" => "terminals","file" => "goto.schema"),
63       "gotoTerminal"          => array("version" => "2.0", "class" => "terminals","file" => "goto.schema"),
64       "goServer"              => array("version" => "2.1","class" => "server","file" => "goserver.schema"),
65       "goTerminalServer"      => array("version" => "2.1", "class" => "terminals","file" => "goto.schema"),
66       "goNfsServer"           => array("version" => "2.1", "class" => "terminals","file" => "goto.schema"),
67       "goNtpServer"           => array("version" => "2.1", "class" => "terminals","file" => "goto.schema"),
68       "goSyslogServer"        => array("version" => "2.1", "class" => "terminals","file" => "goto.schema"),
69       "goLdapServer"          => array("version" => "2.1"),
70       "goCupsServer"          => array("version" => "2.1", "class" => array("posixAccount", "terminals"),),
71       "goImapServer"          => array("version" => "2.1", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
72       "goKrbServer"           => array("version" => "2.1"),
73       "goFaxServer"           => array("version" => "2.1", "class" => "gofaxAccount","file" => "gofax.schema"),
74        
75         );
77   /* Build LDAP connection */
78   $ds= ldap_connect ($server);
79   if (!$ds) {
80     return (array(_("Can't bind to LDAP. No schema check possible!")));
81   }
82   ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
83   $r= ldap_bind ($ds, $admin, $password);
85   /* Get base to look for schema */
86   $sr  = @ldap_read ($ds, "", "objectClass=*", array("subschemaSubentry"));
87   $attr= @ldap_get_entries($ds,$sr);
88   if (!isset($attr[0]['subschemasubentry'][0])){
89     return (array(_("Can't get schema information from server. No schema check possible!")));
90   }
92   /* Get list of objectclasses */
93   $nb= $attr[0]['subschemasubentry'][0];
94   $objectclasses= array();
95   $sr= ldap_read ($ds, $nb, "objectClass=*", array("objectclasses"));
96   $attrs= ldap_get_entries($ds,$sr);
97   if (!isset($attrs[0])){
98     return (array(_("Can't get schema information from server. No schema check possible!")));
99   }
100   foreach ($attrs[0]['objectclasses'] as $val){
101     $name= preg_replace("/^.* NAME\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $val);
102     if ($name != $val){
103       $objectclasses[$name]= $val;
104     }
105   }
106   /* Walk through objectclasses and check if they are needed or not */
107   foreach ($required_classes as $key => $value){
108     if (isset($value['class'])){
109       if (!is_array($value['class'])){
110         $classes= array($value['class']);
111       } else {
112         $classes= $value['class'];
113       }
115       /* Check if we are using the class that requires */
116       foreach($classes as $class){
117         if (!isset($objectclasses[$key])){
118           $messages[$key]= sprintf(_("Optional objectclass '%s' required by plugin '%s' is not present in LDAP setup"), $key, $class);
119         } else {
120           if (!check_schema_version($objectclasses[$key], $value['version'])){
121             $messages[$key]= sprintf(_("Optional objectclass '%s' required by plugin '%s' does not have version %s"), $key, $class, $value['version']);
122           }else {
123             if(!isset($affich2[$class])){
124               $affich2[$class]="Support for <b>$class</b> enabled <td class=\"check\"> ".$value['file']."</td>";
125             }
126           }
127         }
129       }
130     } else {
131       /* Required class */
132       if (!isset($objectclasses[$key])){
133         $messages[$key]= sprintf(_("Required objectclass '%s' is not present in LDAP setup"), $key);
134       } else {
135         if (!check_schema_version($objectclasses[$key], $value['version'])){
136           $messages[$key]= sprintf(_("Required objectclass '%s' does not have version %s"), $key, $value['version']);
137         }
138       }
139     }
140   }
142   /* Check for correct samba parameters */
143   if (!isset($objectclasses['sambaSamAccount'])){
144     $messages['samba3']= _("<b>SAMBA 3</b> support disabled, no schema seems to be installed");
145     $affich['samba3']= $messages['samba3']."<td class=\"check\">gosa+samba3.schema</td>";
146   }else{$affich['samba3']=_("<b>SAMBA 3</b> support enabled<td class=\"check\">gosa+samba3.schema</td>");}
148   if (!isset($objectclasses['sambaAccount'])){
149     $messages['samba2']= _("<b>SAMBA 2</b> support disabled, no schema seems to be installed");
150     $affich['samba2']=$messages['samba2']."<td class=\"check\">samba.schema</td>";
151   }else{$affich['samba2']=_("<b>SAMBA 2</b> support enabled<td class=\"check\">samba.schema</td>");}
153   /* Check pureftp/dns/ */
154   if (!isset($objectclasses['PureFTPdUser'])){
155     $messages['pureftp']= _("Support for <b>pureftp</b> disabled, no schema seems to be installed");
156     $affich['pureftp']= $messages['pureftp']."<td class=\"check\">pureftpd.schema</td>";
157   }else{$affich['pureftp']=_("Support for <b>pureftp</b> enabled<td class=\"check\">pureftpd.schema</td>");}
159   if (!isset($objectclasses['gosaWebdavAccount'])){
160     $messages['webdav']= _("Support for <b>WebDAV</b> disabled, no schema seems to be installed");
161     $affich['webdav']=$messages['webdav']."<td class=\"check\"></td>";
162   }else{$affich['webdav']=_("Support for <b>WebDAV</b> enabled<td class=\"check\">gosa+samba3.schema</td>");}
164   if (!isset($objectclasses['phpgwAccount'])){
165     $messages['phpgroupware']= _("Support for <b>phpgroupware</b> disabled, no schema seems to be installed");
166     $affich['phpgroupware']=$messages['phpgroupware']."<td class=\"check\">phpgwaccount.schema</td>";
167   }else{$affich['phpgroupware']=_("Support for <b>phpgroupware</b> enabled<td class=\"check\">phpgwaccount.schema</td>");}
169   if (!isset($objectclasses['goFonAccount'])){
170     $messages['phoneaccount']= _("Support for <b>gofon</b> disabled, no schema seems to be installed");
171     $affich['phoneaccount']=$messages['phoneaccount']."<td class=\"check\">gofon.schema</td>";
172   }else{$affich['phoneaccount']=_("Support for <b>gofon</b> enabled<td class=\"check\">gofon.schema</td>");}
174   
175   if(($_SESSION['ldapconf']['mail_methods'][$_SESSION['ldapconf']['mail']] == "kolab"))
176   if(!isset($objectclasses['kolabInetOrgPerson']))
177     {
178     $messages['kolab']= _("Support for <b>Kolab</b> disabled, no schema seems to be installed, setting mail-method to cyrus");
179     $tmp = array_flip($_SESSION['ldapconf']['mail_methods']);
180     $_SESSION['ldapconf']['mail']=$tmp['cyrus'];
181     $affich['kolab']=$messages['kolab']."<td class=\"check\">kolab2.schema</td>";
182   }else{$affich['kolab']=_("Support for <b>Kolab</b> enabled<td class=\"check\">gofon.schema</td>");}
185   if($aff==0)return ($messages);
186   else return(array_merge($affich,$affich2));
193 function check(&$faults, $message, $description, $test, $required= TRUE)
195   $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;'>";
196   if ($test){
197     $msg.= _("OK")."<br>";
198   } else {
199     if (!$required){
200       $msg.="<font color=red>"._("Ignored")."</font><br>";
201     } else {
202       $msg.="<font color=red>"._("Failed")."</font><br>";
203       $faults++;
204     }
205   }
206   $msg.= "</td></tr><tr><td class='check' style='padding-left:20px;background-color:#F0F0F0;'>$description</td></tr></table><br>";
208   return $msg;
211 function perform_php_checks(&$faults)
213   global $check_globals;
215   $faults= 0;
216   $msg= "";
218   $msg.= "<h1>"._("PHP setup inspection")."</h1>";
219   $msg.= check (        $faults, _("Checking for PHP version (>=4.1.0)"),
220       _("PHP must be of version 4.1.0 or above for some functions and known bugs in PHP language."),
221       minimum_version('4.1.0'));
223   $msg.= check (        $faults, _("Checking if register_globals is set to 'off'"),
224       _("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."),
225       $check_globals == 0, FALSE);
227   $msg.= check (        $faults, _("Checking for ldap module"),
228       _("This is the main module used by GOsa and therefore really required."),
229       function_exists('ldap_bind'));
231   $msg.= check (        $faults, _("Checking for gettext support"),
232       _("Gettext support is required for internationalized GOsa."), function_exists('bindtextdomain'));
234   $msg.= check (        $faults, _("Checking for iconv support"),
235       _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
236       function_exists('iconv'));
238   $msg.= check (        $faults, _("Checking for mhash module"),
239       _("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."),
240       function_exists('mhash'), FALSE);
242   $msg.= check (        $faults, _("Checking for imap module"),
243       _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
244       function_exists('imap_open'));
245   $msg.= check (        $faults, _("Checking for getacl in imap"),
246       _("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."),
247       function_exists('imap_getacl'), FALSE);
248   $msg.= check (        $faults, _("Checking for mysql module"),
249       _("MySQL support is needed for reading GOfax reports from databases."),
250       function_exists('mysql_query'), FALSE);
251   $msg.= check (        $faults, _("Checking for cups module"),
252       _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
253       function_exists('cups_get_dest_list'), FALSE);
254   $msg.= check (        $faults, _("Checking for kadm5 module"),
255       _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
256       function_exists('kadm5_init_with_password'), FALSE);
257   return ($msg);
261 function perform_additional_checks(&$faults)
263 # Programm check
264   $msg= "<h1>"._("Checking for some additional programms")."</h1>";
266 # Image Magick
267   $query= "LC_ALL=C LANG=C convert -help";
268   $output= shell_exec ($query);
269   if ($output != ""){
270     $lines= split ("\n", $output);
271     $version= preg_replace ("/^Version:[^I]+ImageMagick ([^\s]+).*/", "\\1", $lines[0]);
272     list($major, $minor)= split("\.", $version);
273     $msg.= check (      $faults, _("Checking for ImageMagick (>=5.4.0)"),
274         _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
275         ($major > 5 || ($major == 5 && $minor >= 4)));
276   } else {
277     $msg.= check (      $faults, _("Checking imagick module for PHP"),
278         _("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);
279   }
281 # Check for fping
282   $query= "LC_ALL=C LANG=C fping -v 2>&1";
283   $output= shell_exec ($query);
284   $have_fping= preg_match("/^fping:/", $output);
285   $msg.= check (        $faults, _("Checking for fping utility"),
286       _("The fping utility is only used if you've got a thin client based terminal environment running."),
287       $have_fping, FALSE);
289 # Check for smb hash generation tool
290   $query= "mkntpwd 2>&1";
291   $output= shell_exec ($query);
292   $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
293   $alt = 0;
295   if (!$have_mkntpwd){
296     $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
297     system ($query, $ret);
298     $alt= ($ret == 0);
299   }
301   $msg.= check (        $faults, _("Checking for a way to generate LM/NT password hashes"),
302       _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
303       ($have_mkntpwd || $alt));
304 # checking for some PHP.ini Options
306 /* seesio.auto_start should be off, in order to without trouble*/
308 $arra = ini_get_all();
310 /* This array contains folling info now : 
311   global_value  0
312   local_value   0
313   access        7               
315 -->Access types
316 PHP_INI_USER      1          Entry can be set in user scripts
317 PHP_INI_PERDIR    2          Entry can be set in php.ini, .htaccess or httpd.conf 
318 PHP_INI_SYSTEM    4          Entry can be set in php.ini or httpd.conf 
319 PHP_INI_ALL       7          Entry can be set anywhere 
321 */
323 $session_auto_start =     ($arra['session.auto_start']);
324 $implicit_flush     =     ($arra['implicit_flush']);
325 $max_execution_time =     ($arra['max_execution_time']);
326 $memory_limit =           ($arra['memory_limit']);
327 $expose_php =             ($arra['expose_php']);
328 $magic_quotes_gpc =       ($arra['magic_quotes_gpc']);
329 $register_globals =       ($arra['register_globals']);
332 // auto_register
333 $msg.= check (  $faults, _("PHP.ini check -> session.auto_register"),
334       _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini musst be 'Off'."),
335       (!$session_auto_start['local_value']));
339 //implicit_flush
340 $msg.= check (  $faults, _("PHP.ini check -> implicit_flush"),
341       _("This Option defines the Ouput handling, turn this Option off, to increase performance."),
342         !$implicit_flush['local_value'],0,false);
344 //max_execution_time
345 if($max_execution_time['local_value'] < 30 )
346   $max_execution_time['local_value']=false;
347 $msg.= check (  $faults, _("PHP.ini check -> max_execution_time"),
348       _("The Execution time, should be 30 seconds minimun, cause some actions will need huge ammount of time ."),
349         $max_execution_time['local_value'],0,false);
351 //memory_limit
352 if($memory_limit['local_value'] < 8 )
353   $memory_limit['local_value']=false;
354 $msg.= check (  $faults, _("PHP.ini check -> memory_limit"),
355       _("GOsa need at least 8M of memory, less will cause unpredictable errors, sometimes without error message!. Best would be 32 M here."),
356         !$implicit_flush['local_value'],0,false);
358 //expose_php
359 $msg.= check (  $faults, _("PHP.ini check -> expose_php"),
360       _("PHP won't send any Information about the Server you are running, should be a security fact."),
361         !$implicit_flush['local_value'],0,false);
363 //magic_quotes_gpc
364 $msg.= check (  $faults, _("PHP.ini check -> magic_quotes_gpc"),
365       _("Security option, php will escape all quotes in strings ."),
366         $magic_quotes_gpc['local_value'],0,false);
368   return $msg;
373 //! Added by Hickert
374 //
375 // Parse /contrib/gosa.conf to set user defined values
376 //This function may create the ldap.conf
377 // Lets try
378 function parse_contrib_conf()
380   /* First gather all needed informations */
384   /* Variables */
385   $str                = "";
386   $used_samba_version = 0;
387   $query              = ""; 
388   $fp                 = false;
389   $output             = "";
390   $needridbase_sid    = false;
391   $pwdhash            = "";
392   $replacements       = array();
393   $ldapconf           = $_SESSION['ldapconf']; // The Installation information
394   $classes            = $_SESSION['classes'];  // Class information needed to define which features are enabled
395   $possible_plugins   = array();
397   if(isset($classes['samba3']))  // means Samba 3 is disabled
398     $used_samba_version = 2;
399   else
400     $used_samba_version = 3;
403   if(file_exists("/usr/lib/gosa/mkntpasswd"))    {
404     $pwdhash  = "/usr/lib/gosa/mkntpasswd";
405   }
406   elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1")))    {
407     $pwdhash= "mkntpwd";
408   } else {
409     $pwdhash=addslashes('  perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
410     //    $pwdhash= 'perl -MCrypt::SmbHash -e \"ntlmgen \\"\\$ARGV[0]\\", \\$lm, \\$nt; print \\"\\${lm}:\\${nt}\\\";\"'; 
411   }
414   // Define which variables will be replaced
415   $replacements['{LOCATIONNAME}']           =   $ldapconf['location'];
416   $replacements['{SAMBAVERSION}']           =   $used_samba_version;
417   $replacements['{LDAPBASE}']               =   $ldapconf['base'];
418   $replacements['{LDAPADMIN}']              =   $ldapconf['admin'];
419   $replacements['{DNMODE}']                 =   $ldapconf['peopledn'];
420   $replacements['{LDAPHOST}']               =   $ldapconf['uri'];
421   $replacements['{PASSWORD}']               =   $ldapconf['password'];
422   $replacements['{CRYPT}']                  =   $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
423   $replacements['{SID}']                    =   "";
424   $replacements['{RIDBASE}']                =   "";
425   $replacements['{MAILMETHOD}']             =   $ldapconf['mail_methods'][$ldapconf['mail']];
426   $replacements['{SMBHASH}']                =   $pwdhash;
427   $replacements['{GOVERNMENTMODE}']         =   "false"; 
428   $replacements['{kolabAccount}']           =   "";
429   $replacements['{servKolab}']              =   "";
432   // This array contains all preg_replace syntax to delete all unused plugins
433   // THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes']
435   $possible_plugins['fonreport'][]      ="'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
436   $possible_plugins['phoneaccount'][]   ="'\n.*<tab.*phoneAccount.*>.*\n'i";
438   $possible_plugins['logview'][]        ="'\n.*<plugin.*logview+.*\n.*>.*\n'i";
440   $possible_plugins['pureftp'][]        ="'\n.*<tab.*pureftp.*>.*\n'i";
442   $possible_plugins['webdav'][]         ="'\n.*<tab.*webdav.*>.*\n'i";
444   $possible_plugins['phpgroupware'][]   ="'\n.*<tab.*phpgroupware.*>'i";
447   // Header information
448   // Needed to send the generated gosa.conf to the browser
449   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
450   header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
451   header("Cache-Control: no-cache");
452   header("Pragma: no-cache");
453   header("Cache-Control: post-check=0, pre-check=0");
454   header("Content-type: text/plain");
456   if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||  preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT']))
457   {
458     header('Content-Disposition: filename="gosa.conf"');
459   } else {
460     header('Content-Disposition: attachment; filename="gosa.conf"');
461   }
464   if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r"))
465   {
466     echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
467     // Don't write anything else
468   }
469   else
470   {
471     // Read out Data .....  
472     while(!feof($fp))
473     {
474       $str.= fread($fp,512);
475     }
478     
479     if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab")
480       {
481       $replacements['{kolabAccount}']  ="<tab class=\"kolabAccount\" />";
482       $replacements['{servKolab}']     ="<tab class=\"servkolab\" name=\"Kolab\" />";
483       }
484       
489     // Lets check which samba version we will use
491     // in case of samba 2 we don't need to add additional objets in gosa.conf
492     // in case of samba 3 we musst detect if theres an objectType = SambaObjekt defined
493     //   if theres is one, then do nothing, because the setup will detect the the SID themself
494     //   if theres none defined add SID and RIDBASE to gosa.conf
497     if($used_samba_version == 2)
498     {
499       // Do nothing ...
500     }
501     else
502     {
503       // Create LDAP connection, to check if theres a domain Objekt definen in the Ldap scheme
504       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
507       // Try to find a Samba Domain Objekt
508       $ldap->search("(objectClass=sambaDomain)");
510       // Something found ??? so we need to define ridbase an SID by ourselfs
511       if($ldap->count()< 1)
512       {
513         $replacements['{SID}']                  =   "sid=\"123412-11\"";
514         $replacements['{RIDBASE}']              =   "ridbase=\"1000\"";  
515       } 
516     }// else --> $used_samba_version == 2
518     // Data readed, types replaced, samba version detected and checked if we need to add SID and RIDBASE 
521     // Check if there is an ivbbEntry in the LDAP tree, in this case we will set the governmentmode to true
522     // Create LDAP connection, to check if theres a domain Objekt definen in the Ldap scheme
524     if(!isset($ldap))
525       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
528     // Try to find a Samba Domain Objekt
529     $ldap->search("(objectClass=ivbbEntry)");
531     // Something found ??? so we need to define ridbase an SID by ourselfs
532     if($ldap->count()> 0)
533     {
534       $replacements['{GOVERNMENTMODE}']                  =   "true";
535     }
538     // Replace all colleted information with placeholder
539     foreach($replacements as $key => $val)
540     {
541       $str = preg_replace("/".$key."/",$val,$str);
542       //      $str = ereg_replace($key,$val,$str);
543     }    
545     // Remove all unused plugins
546     foreach($possible_plugins as $plugin)
547     {
548       foreach($plugin as $key=>$val)
549       {
550         if(in_array($plugin,$classes))
551         {
552           $str = preg_replace($val,"\n",$str);
553         }
554       }
555     }
558   }// else -->  !$fp=fopen("../contrib/gosa.conf","r")
560   return ((($str)));
564 // This ist the first page shown in setup
565 // This page test some packages, like php version, ldap_module aso
566 // The funtion don't save anything, it tests only, when withoutput = false
567 // (called from setup.php);
568 function show_setup_page1($withoutput = true)
570   $smarty = get_smarty();  
572   $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
573   $smarty->assign ("tests", perform_php_checks($faults));
577   // This var is true if there is anything went wrong
578   if ($faults)
579   {
580     $smarty->assign("mode", "disabled");
581   }
583   // This line displays the template only if (withoutput is set)
584   if($withoutput) 
585     $smarty->display (get_template_path('headers.tpl'));
587   if (isset($_SESSION['errors']))
588   {
589     $smarty->assign("errors", $_SESSION['errors']);
590   }
592   if($withoutput)
593     $smarty->display (get_template_path('setup.tpl'));
595   return (!$faults);
604 /* Shows Setup_page 2*/
605 function show_setup_page2($withoutput = true)
607   $smarty = get_smarty();
609   $smarty->assign ("content", get_template_path('setup_step2.tpl'));
610   $smarty->assign ("tests", perform_additional_checks($faults));
612   if ($faults) {
613     $smarty->assign("mode", "disabled");
614   }
615   if($withoutput){
616     $smarty->display (get_template_path('headers.tpl'));
617   }
619   if (isset($_SESSION['errors']))  {
620     $smarty->assign("errors", $_SESSION['errors']);
621   }
622   if($withoutput){
623     $smarty->display (get_template_path('setup.tpl'));
624   }
625   return (!$faults);                               
629 /* Setup page 3 asks for the server address
630  "Now we're going to include your LDAP server and create an initial configuration"*/
631 function show_setup_page3($withoutput = true)
634   // Take the Post oder the Sessioin saved data  
635   if(isset($_POST['uri']))
636     $uri = $_POST['uri'];
637   elseif(isset($_SESSION['ldapconf']['uri']))
638     $uri = $_SESSION['ldapconf']['uri'];
640   // If Page called first time, field is empty 
641   if((!isset($uri))||(empty($uri)))
642     $uri = "ldap://localhost:389";
645   $smarty = get_smarty();
647   // if isset $uri save it to session
648   if(isset($uri))
649   {
650     $_SESSION['ldapconf']['uri'] = $uri;
651     $smarty->assign ("uri", validate($uri));
652   }
655   // No error till now
656   $fault = false;
659   // If we pushed the Button continue
660   if(isset($_POST['continue3']))
661     if(!isset($uri))
662     {
663       $fault = true;
664       // Output the Error
665       if($withoutput)
666       {
667         print_red (_("You've to specify an ldap server before continuing!"));
668         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
669       }
670     }
671   elseif (!$ds = @ldap_connect (validate($uri)))
672   {
673     $fault =true;
674     // Output the Error
675     if($withoutput)
676     {
677       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
678       $smarty->assign ("uri", validate($uri));
679       $smarty->assign ("content", get_template_path('setup_step3.tpl'));
680     }
681   }
682     else
683     {
684       // Try to bind the connection     
685       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
687       // if we can't bind , print error
688       if (!$r  =  @ldap_bind ($ds))
689       {
690         $fault = true;
691         // Output the Error
692         if($withoutput)      
693         {
694           print_red (_("Can't bind to the specified LDAP server! Please make sure that is reachable for GOsa."));
695           $smarty->assign ("content", get_template_path('setup_step3.tpl'));
696           $smarty->assign ("uri", validate($uri));
697         }
698       }
699       else
700       {
701         $fault = false;
702       }
703     }
706   $smarty->assign ("content", get_template_path('setup_step3.tpl'));
709   // Load Header
710   if($withoutput)
711     $smarty->display (get_template_path('headers.tpl'));
713   // Set Errors to Smarty
714   if (isset($_SESSION['errors']))
715   {
716     $smarty->assign("errors", $_SESSION['errors']);
717   }
719   // Print out Template 
720   if($withoutput)
721     $smarty->display (get_template_path('setup.tpl'));
725   return (!$fault);                             
730 // Setup page 4
731 // This page asked for detailed info, like base dn or admin user
732 // 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
733 function show_setup_page4($withoutput = true)
737   require_once("class_password-methods.inc");
739   error_reporting(E_ALL);
744   $fault        = false;                        // If an error occures we set this var to true 
745   $smarty       = get_smarty();                 // Our smarty instance
746   $uri          = $_SESSION['ldapconf']['uri']; // This is the the connect path to the ldapserver like ldap://lo..
747   $ldapconf     = $_SESSION['ldapconf'];        // The ldap Configuration informations, we collected while setup 
748   $arr_crypts   = array();                      // array which includes contains all possible password crypting methods
749   $temp         = "";                           // Temp
750   $checkvars    = array("location","admin","password","peopleou","peopledn","arr_crypts","mail","uidbase");
753   if(!isset($_SESSION['ldapconf']['arr_cryptkeys']))
754   {
755     require_once("class_password-methods.inc");
756     $tmp = passwordMethod::get_available_methods_if_not_loaded();
757     $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
758   }
762   if(!isset($_SESSION['ldapconf']['mail_methods']))
763   {
764     $_SESSION['ldapconf']['mail_methods']=array();
765     $temp = get_available_mail_classes();
766     $_SESSION['ldapconf']['mail_methods']= $temp['name'];
767   }
772   // If there are some empty vars in ldapconnect
773   // This values also represent out default values 
775 # first try to get $base 
776   if(!$ds = @ldap_connect (validate($uri)))    
777   {
778     $fault = true;
779   }
780   elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3))    
781   {
782     $fault = true;
783   }
784   elseif(! $r =  @ldap_bind ($ds))    
785   {
786     $fault = true;
787   }
788   else
789   {
790     $sr=      @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
793     $attr=    @ldap_get_entries($ds,$sr);
794     if((empty($attr)))
795     {
796       $base= "dc=example,dc=net";
799       if($withoutput)
800         print_red(_("Bind to server successfull, but the server seems to be completly empty, please check all informations twice"));
802     }
803     else
804     {
805       $base= $attr[0]['dn'];
806     }
807   }
811   if(!isset($_SESSION['ldapconf']['base']))           $_SESSION['ldapconf']['base']         = $base;
812   if(!isset($_SESSION['ldapconf']['admin']))          $_SESSION['ldapconf']['admin']        = "cn=ldapadmin,".$base;
813   if(!isset($_SESSION['ldapconf']['peopleou']))       $_SESSION['ldapconf']['peopleou']     = "ou=people";
814   if(!isset($_SESSION['ldapconf']['groupou']))        $_SESSION['ldapconf']['groupou']      = "ou=groups";
815   if(!isset($_SESSION['ldapconf']['peopledn']))       $_SESSION['ldapconf']['peopledn']     = "cn";
816   if(!isset($_SESSION['ldapconf']['password']))       $_SESSION['ldapconf']['password']     = "";
817   if(!isset($_SESSION['ldapconf']['location']))       $_SESSION['ldapconf']['location']     = "Example";
818   if(!isset($_SESSION['ldapconf']['uidbase']))        $_SESSION['ldapconf']['uidbase']      = "1000";
819   if(!isset($_SESSION['ldapconf']['mail']))           $_SESSION['ldapconf']['mail']         = 0;
820   $tmp = array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
821   if(!isset($_SESSION['ldapconf']['arr_crypts']))     $_SESSION['ldapconf']['arr_crypts']   = $tmp['md5'];
824   // check Post data
826   if(isset($_POST['check']))
827   {
828     // Check if all needed vars are submitted
829     foreach($checkvars as $key)
830     {
831       if((isset($_POST[$key]))&&($_POST[$key]!=""))
832       {
833         $_SESSION['ldapconf'][$key] = $_POST[$key];
834       }
835       else
836       {
837         if($withoutput)
838         {
839           print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
840         }
841         $fault = true;
842       }
843     }
845     // check if another base is given ... (ldapadmin...dc=base,dc=de)   ..
847     $base     =   $_SESSION['ldapconf']['admin'];
848     $tmp      =   array_reverse ( split(",",$base));
849     $base     =   $tmp[1].",".$tmp[0];
850     $_SESSION['ldapconf']['base']         = $base;
853   }
857   $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
858   $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
860   foreach($_SESSION['ldapconf'] as $key => $val)
861   {
862     $smarty->assign($key,$val);
863   }
865   if(isset($_POST['check']))
866   {
867     $ldap= new LDAP($_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password'], $_SESSION['ldapconf']['uri']);
868   
869     $m= schema_check($_SESSION['ldapconf']['uri'], $_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password']);
870     $_SESSION['classes']= $m;
872     if ($ldap->error != "Success")
873     {
874       if($withoutput)
875       {
876         print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
877       }
878       $fault = true;
879     }
880   }
884   // Set smarty output
885   $smarty->assign ("content", get_template_path('setup_step4.tpl'));
887   $smarty->assign ("peopledns", array("cn", "uid"));
888   if($withoutput)
889     $smarty->display (get_template_path('headers.tpl'));
891   if(isset($_SESSION['errors']))
892   {
893     $smarty->assign("errors", $_SESSION['errors']);
894   }
895   if($withoutput)
896     $smarty->display (get_template_path('setup.tpl'));
899   return (!$fault);
907 // This page shows your configuration 
908 // and wants you to download the gosa.conf ....
909 function show_setup_page5($withoutput=true)
911   // Get ldapconf
912   $ldapconf= $_SESSION['ldapconf'];
914   // get smarty
915   $smarty = get_smarty();
917   if(isset($_SESSION['classes']))
918     $classes = $_SESSION['classes'];
920   $info= posix_getgrgid(posix_getgid());
921   $smarty->assign ("webgroup", $info['name']);
922   $smarty->assign ("path", CONFIG_DIR);
923   $message = "";
924   $message.="<table class=\"check\">";
925   $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
926   
927   if($withoutput)
928   {
929     $smarty->assign ("schemas", view_schema_check($m));
930     $smarty->assign ("content", get_template_path('setup_finish.tpl'));
931   }
932   // Output templates ....
934   if($withoutput)
935     $smarty->display (get_template_path('headers.tpl'));
937   if (isset($_SESSION['errors']))
938   {
939     $smarty->assign("errors", $_SESSION['errors']);
940   }
941   if($withoutput)
942     $smarty->display (get_template_path('setup.tpl'));
943   return(true);
957 // this function is called by setup step 5, in order to create a missinf Administrator 
958 // and or Administrational user
959 // on success go on with setup_page5
960 // else show this page aggain
961 function create_user_for_setup($withoutput=true)
964   error_reporting(E_ALL);
966   global $samba;
968   $ldapconf = $_SESSION['ldapconf'];
969   $smarty = get_smarty();
972   
973   if(isset($_SESSION['classes']))
974     $classes= $_SESSION['classes'];
976   // Everything runns perfect ...
977   // So we do a last test on this page
978   // is there a user with ACLs :all which will be able to adminsitrate GOsa
979   // We check that, if this user or group is missing we ask for creating them
981   $ldap= new LDAP($_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password'], $_SESSION['ldapconf']['uri']);
983   //  $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
985   // Now we are testing for a group, with the rights :all
986   $ldap->cd($ldapconf['base']);
987   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
989   $group_cnt       = $ldap->count();
990   $data           = $ldap->fetch();
991   $create_user    = false;
993   // We need to create Administrative user and group
994   // Because theres no Group found
995   if($group_cnt < 1)
996   {
997     // Set var to create user
998     $create_user    =   true;
1000     // Output error
1001     if(($withoutput)&&(!isset($_POST['new_admin'])))
1002       print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1003   }
1004   else
1005   {
1007     // We found an Administrative Group, is there a user too
1008     if(isset($data['memberUid'][0]))
1009     {
1010       $ldap->search("(&(objectClass=gosaAccount)(objectClass=person))",array("uid=".$data['memberUid'][0]));
1011       $data2      = $ldap->fetch();
1012       $user_cnt   = $ldap->count();
1013     }
1015     // We must create a user
1016     if (($ldap->count() < 1)||(!isset($data2)))
1017     {
1018       $create_user = true;
1019       if(($withoutput)&&(!isset($_POST['new_admin'])))
1020         print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1021     }
1022     else
1023     {
1024       // We don't need to add a user
1025       return(true);
1026     }
1028   }// if($group_cn)
1030   // We need to create a new user with group
1031   if(isset($_POST['new_admin']))
1032   {
1033     // Is there a running user ?
1034     // Then add additional
1036     if (isset($classes['samba3']))
1037     {
1038       $samba= "2";
1039       $lmPassword = "lmPassword";
1040       $ntPassword = "ntPassword";
1041     } else {
1042       $samba= "3";
1043       $lmPassword = "sambaLMPassword";
1044       $ntPassword = "sambaNtPassword";
1045     }
1048     // Nothing submitted
1049     if(( (empty($_POST['admin_name']))||(empty($_POST['admin_pass'])) )&&(!$create_user))
1050     {
1051       return(true);
1052     }
1054     // We have the order to create on Admin ^^
1055     // Detect Samba version to define the Attribute names shown below
1056     // go to base
1057     $ldap->cd($ldapconf['base']);
1059     // Define the user we are going to create
1060     $dn =  "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1063     $arr['objectClass'][0] ="person";
1064     $arr['objectClass'][1] ="organizationalPerson";
1065     $arr['objectClass'][2] ="inetOrgPerson";
1066     $arr['objectClass'][3] ="gosaAccount";
1067     $arr['uid']            = $_POST['admin_name'];
1068     $arr['cn']             = $_POST['admin_name'];
1069     $arr['sn']             = $_POST['admin_name'];
1071     $arr['givenName']     = "GOsa main administrator";
1072     $arr[$lmPassword]     = "10974C6EFC0AEE1917306D272A9441BB";
1073     $arr[$ntPassword]     = "38F3951141D0F71A039CFA9D1EC06378";
1074     $arr['userPassword']  = crypt_single($_POST['admin_pass'],"md5");
1075     if( ! $ldap->dn_exists ( $dn )) { 
1076       $ldap->cd($dn); 
1077       $ldap->create_missing_trees($dn);
1078       $ldap->add($arr);
1079       if($ldap->error!="Success")      {
1080         print_red("Can't create user, and / or Group, possibly this problem  depends on an empty LDAP server. Check your configuration and try again!");
1081       }
1082     }
1084     // theres already a group for administrator, so we only need to add the user
1085     if($group_cnt)
1086     {
1087       if(!isset($data['memberUid']))
1088       {
1089         $arrr['memberUid']= $_POST['admin_name'];
1090       }
1091       else
1092       {
1093         $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1094         $arrr['memberUid'] = $data['memberUid'];
1095         unset($arrr['memberUid']['count']);
1096       }
1097       $ldap->cd($data['dn']);
1098       $ldap->modify($arrr);
1099     }
1100     else
1101     {
1102       // there was no group defined, so we must create one
1103       $dn                       = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1104       $arrr['objectClass'][0]   = "gosaObject";
1105       $arrr['objectClass'][1]   = "posixGroup";
1106       $arrr['gosaSubtreeACL']   = ":all";
1107       $arrr['cn']               = "administrators";
1108       $arrr['gidNumber']        = "999";
1109       $arrr['memberUid']        = $_POST['admin_name'];
1110       $ldap->cd($dn);
1111       $ldap->add($arrr);
1112     }
1115     // We created the Group and the user, so we can go on with the next setup step
1116     return(true);
1117   }
1118   else
1119   {
1120     if(!($create_user))
1121     {
1122       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1123       $smarty->assign("exists",true);
1124     }
1125     else
1126     {
1127       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1128       $smarty->assign("exists",false);
1129     }
1130   }
1133   // Smarty outout  
1135   if($withoutput)
1136     $smarty->display (get_template_path('headers.tpl'));
1138   if (isset($_SESSION['errors']))
1139   {
1140     $smarty->assign("errors", $_SESSION['errors']);
1141   }
1142   if($withoutput)
1143     $smarty->display (get_template_path('setup.tpl'));
1146   return(false);
1150 // Returns the classnames auf the mail classes
1151 function get_available_mail_classes()
1153   $dir = opendir( "../include");
1154   $methods = array();
1155   $suffix = "class_mail-methods-";
1156   $lensuf = strlen($suffix);
1157   $prefix = ".inc";
1158   $lenpre = strlen($prefix);
1161   $i = 0;
1162   while (($file = readdir($dir)) !== false) 
1163   {
1164     if(stristr($file,$suffix))
1165     {
1166       $lenfile = strlen($file);
1167       $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1168       $methods['file'][$i] = $file;
1169       $methods[$i]['file'] = $file;
1170       $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1171       $i++;
1172     }
1173   }
1174   return($methods);
1183 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1184 ?>