Code

Adressbook undefined vars
[gosa.git] / include / setup_checks.inc
1 <?php
6 function minimum_version($vercheck)
7 {
8   $needver = split("\.",$vercheck);
9   $curver  = split("\.",phpversion());
10   
11   $c1 = count($needver);
12   $c2 = count($curver);
14   if($c2 >= $c1) $c1 = $c2;
16   for($i=0; $i < $c1 ; $i++)
17   {
18   // no success
19   if($needver[$i] > $curver[$i])
20     {
21     return(false);
22     }
23   // current ist higher
24   if($needver[$i] < $curver[$i])
25     {
26     return(true);
27     }
28   // Number is Equal
29   } 
30   return (true);
31 }
33 function minimum_versioni2($vercheck)
34 {
35   $minver = (int)str_replace('.', '', $vercheck);
36   $curver = (int)str_replace('.', '', phpversion());
38   if($curver >= $minver){
39     return (true);
40   }
42   return (false);
43 }
46 function check_schema_version($description, $version)
47 {
48   $desc= preg_replace("/^.* DESC\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $description);
50   return preg_match("/\(v$version\)/", $desc);
51 }
53 function view_schema_check($table)
54 {
55   $message="<table class=\"check\">";
56   foreach ($table as $key => $msg){
57     $message.= "<tr><td class=\"check\">$msg";
58     if(strstr($msg,"enabled")) {
59       $message.="</td><td style='text-align:center' ><img src=images/true.png alt='true' /></td></tr>";
60     }
61     else
62     {
63       $message.="</td><td style='text-align:center' ><img src=images/button_cancel.png alt='false' /></td></tr>";}
64   }
65   $message.="</table>";
66   return $message;
67 }
69 function schema_check($server, $admin, $password,$aff=0)
70 {
71   global $config;
72   
74   $messages= array();
75   $required_classes= array(
76       "gosaObject"            => array("version" => "2.4"),
77       "gosaAccount"           => array("version" => "2.4"),
78       "gosaLockEntry"         => array("version" => "2.4"),
79       "gosaCacheEntry"        => array("version" => "2.4"),
80       "gosaDepartment"        => array("version" => "2.4"),
82       "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
83       "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
84       "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
86       "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
87       "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
88       "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
89       "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
90       "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
92       "GOhard"                => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
93       "gotoTerminal"          => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
94       "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
95       "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
96       "goNfsServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
97       "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
98       "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
99       "goLdapServer"          => array("version" => "2.4"),
100       "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
101       "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
102       "goKrbServer"           => array("version" => "2.4"),
103       "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
104        
105         );
107   /* Build LDAP connection */
108   $ds= ldap_connect ($server);
109   if (!$ds) {
110     return (array(_("Can't bind to LDAP. No schema check possible!")));
111   }
112   ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
113   $r= ldap_bind ($ds, $admin, $password);
115   /* Get base to look for schema */
116   $sr  = @ldap_read ($ds, "", "objectClass=*", array("subschemaSubentry"));
117   $attr= @ldap_get_entries($ds,$sr);
118   if (!isset($attr[0]['subschemasubentry'][0])){
119     return (array(_("Can't get schema information from server. No schema check possible!")));
120   }
122   /* Get list of objectclasses */
123   $nb= $attr[0]['subschemasubentry'][0];
124   $objectclasses= array();
125   $sr= ldap_read ($ds, $nb, "objectClass=*", array("objectclasses"));
126   $attrs= ldap_get_entries($ds,$sr);
127   if (!isset($attrs[0])){
128     return (array(_("Can't get schema information from server. No schema check possible!")));
129   }
130   foreach ($attrs[0]['objectclasses'] as $val){
131     $name= preg_replace("/^.* NAME\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $val);
132     if ($name != $val){
133       $objectclasses[$name]= $val;
134     }
135   }
136   /* Walk through objectclasses and check if they are needed or not */
137   foreach ($required_classes as $key => $value){
138     if (isset($value['class'])){
139       if (!is_array($value['class'])){
140         $classes= array($value['class']);
141       } else {
142         $classes= $value['class'];
143       }
145       /* Check if we are using the class that requires */
146       foreach($classes as $class){
147         if (!isset($objectclasses[$key])){
148           $messages[$key]= sprintf(_("Optional objectclass '%s' required by plugin '%s' is not present in LDAP setup"), $key, $class);
149         } else {
150           if (!check_schema_version($objectclasses[$key], $value['version'])){
151             $messages[$key]= sprintf(_("Optional objectclass '%s' required by plugin '%s' does not have version %s"), $key, $class, $value['version']);
152           }else {
153             if(!isset($affich2[$class])){
154               $affich2[$class]="Support for <b>$class</b> enabled <td class=\"check\"> ".$value['file']."</td>";
155             }
156           }
157         }
159       }
160     } else {
161       /* Required class */
162       if (!isset($objectclasses[$key])){
163         $messages[$key]= sprintf(_("Required objectclass '%s' is not present in LDAP setup"), $key);
164       } else {
165         if (!check_schema_version($objectclasses[$key], $value['version'])){
166           $messages[$key]= sprintf(_("Required objectclass '%s' does not have version %s"), $key, $value['version']);
167         }
168       }
169     }
170   }
172   /* Check for correct samba parameters */
173   if (!isset($objectclasses['sambaSamAccount'])){
174     $messages['samba3']= _("SAMBA 3 support disabled, no schema seems to be installed");
175     $affich['samba3']= $messages['samba3']."<td class=\"check\">gosa+samba3.schema</td>";
176   }else{
177     $affich['samba3']=_("SAMBA 3 support enabled")."<td class=\"check\">gosa+samba3.schema</td>";
178   }
180   if (!isset($objectclasses['sambaAccount'])){
181     $messages['samba2']= _("SAMBA 2 support disabled, no schema seems to be installed");
182     $affich['samba2']=$messages['samba2']."<td class=\"check\">samba.schema</td>";
183   }else{
184     $affich['samba2']=_("SAMBA 2 support enabled")."<td class=\"check\">samba.schema</td>";
185   }
187   /* Check pureftp/dns/ */
188   if (!isset($objectclasses['PureFTPdUser'])){
189     $messages['pureftp']= _("Support for pureftp disabled, no schema seems to be installed");
190     $affich['pureftp']= $messages['pureftp']."<td class=\"check\">pureftpd.schema</td>";
191   }else{
192     $affich['pureftp']=_("Support for pureftp enabled")."<td class=\"check\">pureftpd.schema</td>";
193   }
195   if (!isset($objectclasses['gosaWebdavAccount'])){
196     $messages['webdav']= _("Support for WebDAV disabled, no schema seems to be installed");
197     $affich['webdav']=$messages['webdav']."<td class=\"check\"></td>";
198   }else{
199     $affich['webdav']=_("Support for WebDAV enabled")."<td class=\"check\">gosa+samba3.schema</td>";
200   }
202   if (!isset($objectclasses['phpgwAccount'])){
203     $messages['phpgroupware']= _("Support for phpgroupware disabled, no schema seems to be installed");
204     $affich['phpgroupware']=$messages['phpgroupware']."<td class=\"check\">phpgwaccount.schema</td>";
205   }else{
206     $affich['phpgroupware']=_("Support for phpgroupware enabled")."<td class=\"check\">phpgwaccount.schema</td>";
207   }
209   if (!isset($objectclasses['goFonAccount'])){
210     $messages['phoneaccount']= _("Support for gofon disabled, no schema seems to be installed");
211     $affich['phoneaccount']=$messages['phoneaccount']."<td class=\"check\">gofon.schema</td>";
212   }else{
213     $affich['phoneaccount']=_("Support for gofon enabled")."<td class=\"check\">gofon.schema</td>";
214   }
216   
217   if(($_SESSION['ldapconf']['mail_methods'][$_SESSION['ldapconf']['mail']] == "kolab"))
218   if(!isset($objectclasses['kolabInetOrgPerson']))
219     {
220     $messages['kolab']= _("Support for Kolab disabled, no schema seems to be installed, setting mail-method to cyrus");
221     $tmp = array_flip($_SESSION['ldapconf']['mail_methods']);
222     $_SESSION['ldapconf']['mail']=$tmp['cyrus'];
223     $affich['kolab']=$messages['kolab']."<td class=\"check\">kolab2.schema</td>";
224   }else{
225     $affich['kolab']=_("Support for Kolab enabled")."<td class=\"check\">gofon.schema</td>";
226   }
229   if($aff==0)return ($messages);
230   else return(array_merge($affich,$affich2));
237 function check(&$faults, $message, $description, $test, $required= TRUE)
239   $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;'>";
240   if ($test){
241     $msg.= _("OK")."<br>";
242   } else {
243     if (!$required){
244       $msg.="<font color=red>"._("Ignored")."</font><br>";
245     } else {
246       $msg.="<font color=red>"._("Failed")."</font><br>";
247       $faults++;
248     }
249   }
250   $msg.= "</td></tr><tr><td class='check' style='padding-left:20px;background-color:#F0F0F0;'>$description</td></tr></table><br>";
252   return $msg;
255 function perform_php_checks(&$faults)
257   global $check_globals;
259   $faults= 0;
260   $msg= "";
262   $msg.= "<h1>"._("PHP setup inspection")."</h1>";
263   $msg.= check (        $faults, _("Checking for PHP version (>=4.1.0)"),
264       _("PHP must be of version 4.1.0 or above for some functions and known bugs in PHP language."),
265       minimum_version('4.1.0'));
267   $msg.= check (  $faults, _("Checking for PHP version (<=5)"),
268       _("PHP must be below version 5."),
269       !minimum_version('5'));
272   $msg.= check (        $faults, _("Checking if register_globals is set to 'off'"),
273       _("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."),
274       $check_globals == 0, FALSE);
276   $msg.= check (        $faults, _("Checking for ldap module"),
277       _("This is the main module used by GOsa and therefore really required."),
278       function_exists('ldap_bind'));
280   $msg.= check (        $faults, _("Checking for gettext support"),
281       _("Gettext support is required for internationalized GOsa."), function_exists('bindtextdomain'));
283   $msg.= check (        $faults, _("Checking for iconv support"),
284       _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
285       function_exists('iconv'));
287   $msg.= check (        $faults, _("Checking for mhash module"),
288       _("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."),
289       function_exists('mhash'), FALSE);
291   $msg.= check (        $faults, _("Checking for imap module"),
292       _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
293       function_exists('imap_open'));
294   $msg.= check (        $faults, _("Checking for getacl in imap"),
295       _("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."),
296       function_exists('imap_getacl'), FALSE);
297   $msg.= check (        $faults, _("Checking for mysql module"),
298       _("MySQL support is needed for reading GOfax reports from databases."),
299       function_exists('mysql_query'), FALSE);
300   $msg.= check (        $faults, _("Checking for cups module"),
301       _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
302       function_exists('cups_get_dest_list'), FALSE);
303   $msg.= check (        $faults, _("Checking for kadm5 module"),
304       _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
305       function_exists('kadm5_init_with_password'), FALSE);
306   return ($msg);
310 function perform_additional_checks(&$faults)
312 # Programm check
313   $msg= "<h1>"._("Checking for some additional programms")."</h1>";
315 # Image Magick
316   $query= "LC_ALL=C LANG=C convert -help";
317   $output= shell_exec ($query);
318   if ($output != ""){
319     $lines= split ("\n", $output);
320     $version= preg_replace ("/^Version:[^I]+ImageMagick ([^\s]+).*/", "\\1", $lines[0]);
321     list($major, $minor)= split("\.", $version);
322     $msg.= check (      $faults, _("Checking for ImageMagick (>=5.4.0)"),
323         _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
324         ($major > 5 || ($major == 5 && $minor >= 4)));
325   } else {
326     $msg.= check (      $faults, _("Checking imagick module for PHP"),
327         _("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);
328   }
330 # Check for fping
331   $query= "LC_ALL=C LANG=C fping -v 2>&1";
332   $output= shell_exec ($query);
333   $have_fping= preg_match("/^fping:/", $output);
334   $msg.= check (        $faults, _("Checking for fping utility"),
335       _("The fping utility is only used if you've got a thin client based terminal environment running."),
336       $have_fping, FALSE);
338 # Check for smb hash generation tool
339   $query= "mkntpwd 2>&1";
340   $output= shell_exec ($query);
341   $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
342   $alt = 0;
344   if (!$have_mkntpwd){
345     $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
346     system ($query, $ret);
347     $alt= ($ret == 0);
348   }
350   $msg.= check (        $faults, _("Checking for a way to generate LM/NT password hashes"),
351       _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
352       ($have_mkntpwd || $alt));
353 # checking for some PHP.ini Options
355 /* seesio.auto_start should be off, in order to without trouble*/
357 $arra = ini_get_all();
359 /* This array contains folling info now : 
360   global_value  0
361   local_value   0
362   access        7               
364 -->Access types
365 PHP_INI_USER      1          Entry can be set in user scripts
366 PHP_INI_PERDIR    2          Entry can be set in php.ini, .htaccess or httpd.conf 
367 PHP_INI_SYSTEM    4          Entry can be set in php.ini or httpd.conf 
368 PHP_INI_ALL       7          Entry can be set anywhere 
370 */
372 $session_auto_start =     ($arra['session.auto_start']);
373 $implicit_flush     =     ($arra['implicit_flush']);
374 $max_execution_time =     ($arra['max_execution_time']);
375 $memory_limit =           ($arra['memory_limit']);
376 $expose_php =             ($arra['expose_php']);
377 $magic_quotes_gpc =       ($arra['magic_quotes_gpc']);
378 $register_globals =       ($arra['register_globals']);
381 // auto_register
382 $msg.= check (  $faults, _("PHP.ini check -> session.auto_register"),
383       _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini musst be 'Off'."),
384       (!$session_auto_start['local_value']));
388 //implicit_flush
389 $msg.= check (  $faults, _("PHP.ini check -> implicit_flush"),
390       _("This Option defines the Ouput handling, turn this Option off, to increase performance."),
391         !$implicit_flush['local_value'],0,false);
393 //max_execution_time
394 if($max_execution_time['local_value'] < 30 )
395   $max_execution_time['local_value']=false;
396 $msg.= check (  $faults, _("PHP.ini check -> max_execution_time"),
397       _("The Execution time, should be 30 seconds minimun, cause some actions will need huge ammount of time ."),
398         $max_execution_time['local_value'],0,false);
400 //memory_limit
401 if($memory_limit['local_value'] < 8 )
402   $memory_limit['local_value']=false;
403 $msg.= check (  $faults, _("PHP.ini check -> memory_limit"),
404       _("GOsa need at least 8M of memory, less will cause unpredictable errors, sometimes without error message!. Best would be 32 M here."),
405         !$implicit_flush['local_value'],0,false);
407 //expose_php
408 $msg.= check (  $faults, _("PHP.ini check -> expose_php"),
409       _("PHP won't send any Information about the Server you are running, should be a security fact."),
410         !$implicit_flush['local_value'],0,false);
412 //magic_quotes_gpc
413 $msg.= check (  $faults, _("PHP.ini check -> magic_quotes_gpc"),
414       _("Security option, php will escape all quotes in strings ."),
415         $magic_quotes_gpc['local_value'],0,false);
417   return $msg;
422 //! Added by Hickert
423 //
424 // Parse /contrib/gosa.conf to set user defined values
425 //This function may create the ldap.conf
426 // Lets try
427 function parse_contrib_conf()
429   /* First gather all needed informations */
433   /* Variables */
434   $str                = "";
435   $used_samba_version = 0;
436   $query              = ""; 
437   $fp                 = false;
438   $output             = "";
439   $needridbase_sid    = false;
440   $pwdhash            = "";
441   $replacements       = array();
442   $ldapconf           = $_SESSION['ldapconf']; // The Installation information
443   $classes            = $_SESSION['classes'];  // Class information needed to define which features are enabled
444   $possible_plugins   = array();
446   if(isset($classes['samba3']))  // means Samba 3 is disabled
447     $used_samba_version = 2;
448   else
449     $used_samba_version = 3;
452   if(file_exists("/usr/lib/gosa/mkntpasswd"))    {
453     $pwdhash  = "/usr/lib/gosa/mkntpasswd";
454   }
455   elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1")))    {
456     $pwdhash= "mkntpwd";
457   } else {
458     $pwdhash=addslashes('  perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
459     //    $pwdhash= 'perl -MCrypt::SmbHash -e \"ntlmgen \\"\\$ARGV[0]\\", \\$lm, \\$nt; print \\"\\${lm}:\\${nt}\\\";\"'; 
460   }
463   // Define which variables will be replaced
464   $replacements['{LOCATIONNAME}']           =   $ldapconf['location'];
465   $replacements['{SAMBAVERSION}']           =   $used_samba_version;
466   $replacements['{LDAPBASE}']               =   $ldapconf['base'];
467   $replacements['{LDAPADMIN}']              =   $ldapconf['admin'];
468   $replacements['{DNMODE}']                 =   $ldapconf['peopledn'];
469   $replacements['{LDAPHOST}']               =   $ldapconf['uri'];
470   $replacements['{PASSWORD}']               =   $ldapconf['password'];
471   $replacements['{CRYPT}']                  =   $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
472   $replacements['{SID}']                    =   "";
473   $replacements['{RIDBASE}']                =   "";
474   $replacements['{MAILMETHOD}']             =   $ldapconf['mail_methods'][$ldapconf['mail']];
475   $replacements['{SMBHASH}']                =   $pwdhash;
476   $replacements['{GOVERNMENTMODE}']         =   "false"; 
477   $replacements['{kolabAccount}']           =   "";
478   $replacements['{servKolab}']              =   "";
481   // This array contains all preg_replace syntax to delete all unused plugins
482   // THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes']
484   $possible_plugins['fonreport'][]      ="'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
485   $possible_plugins['phoneaccount'][]   ="'\n.*<tab.*phoneAccount.*>.*\n'i";
487   $possible_plugins['logview'][]        ="'\n.*<plugin.*logview+.*\n.*>.*\n'i";
489   $possible_plugins['pureftp'][]        ="'\n.*<tab.*pureftp.*>.*\n'i";
491   $possible_plugins['webdav'][]         ="'\n.*<tab.*webdav.*>.*\n'i";
493   $possible_plugins['phpgroupware'][]   ="'\n.*<tab.*phpgroupware.*>'i";
496   // Header information
497   // Needed to send the generated gosa.conf to the browser
498   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
499   header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
500   header("Cache-Control: no-cache");
501   header("Pragma: no-cache");
502   header("Cache-Control: post-check=0, pre-check=0");
503   header("Content-type: text/plain");
505   if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||  preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT']))
506   {
507     header('Content-Disposition: filename="gosa.conf"');
508   } else {
509     header('Content-Disposition: attachment; filename="gosa.conf"');
510   }
513   if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r"))
514   {
515     echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
516     // Don't write anything else
517   }
518   else
519   {
520     // Read out Data .....  
521     while(!feof($fp))
522     {
523       $str.= fread($fp,512);
524     }
527     
528     if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab")
529       {
530       $replacements['{kolabAccount}']  ="<tab class=\"kolabAccount\" />";
531       $replacements['{servKolab}']     ="<tab class=\"servkolab\" name=\"Kolab\" />";
532       }
533       
538     // Lets check which samba version we will use
540     // in case of samba 2 we don't need to add additional objets in gosa.conf
541     // in case of samba 3 we musst detect if theres an objectType = SambaObjekt defined
542     //   if theres is one, then do nothing, because the setup will detect the the SID themself
543     //   if theres none defined add SID and RIDBASE to gosa.conf
546     if($used_samba_version == 2)
547     {
548       // Do nothing ...
549     }
550     else
551     {
552       // Create LDAP connection, to check if theres a domain Objekt definen in the Ldap scheme
553       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
556       // Try to find a Samba Domain Objekt
557       $ldap->search("(objectClass=sambaDomain)");
559       // Something found ??? so we need to define ridbase an SID by ourselfs
560       if($ldap->count()< 1)
561       {
562         $replacements['{SID}']                  =   "sid=\"123412-11\"";
563         $replacements['{RIDBASE}']              =   "ridbase=\"1000\"";  
564       } 
565     }// else --> $used_samba_version == 2
567     // Data readed, types replaced, samba version detected and checked if we need to add SID and RIDBASE 
570     // Check if there is an ivbbEntry in the LDAP tree, in this case we will set the governmentmode to true
571     // Create LDAP connection, to check if theres a domain Objekt definen in the Ldap scheme
573     if(!isset($ldap))
574       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
577     // Try to find a Samba Domain Objekt
578     $ldap->search("(objectClass=ivbbEntry)");
580     // Something found ??? so we need to define ridbase an SID by ourselfs
581     if($ldap->count()> 0)
582     {
583       $replacements['{GOVERNMENTMODE}']                  =   "true";
584     }
587     // Replace all colleted information with placeholder
588     foreach($replacements as $key => $val)
589     {
590       $str = preg_replace("/".$key."/",$val,$str);
591       //      $str = ereg_replace($key,$val,$str);
592     }    
594     // Remove all unused plugins
595     foreach($possible_plugins as $plugin)
596     {
597       foreach($plugin as $key=>$val)
598       {
599         if(in_array($plugin,$classes))
600         {
601           $str = preg_replace($val,"\n",$str);
602         }
603       }
604     }
607   }// else -->  !$fp=fopen("../contrib/gosa.conf","r")
609   return ((($str)));
613 // This ist the first page shown in setup
614 // This page test some packages, like php version, ldap_module aso
615 // The funtion don't save anything, it tests only, when withoutput = false
616 // (called from setup.php);
617 function show_setup_page1($withoutput = true)
619   $smarty = get_smarty();  
621   $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
622   $smarty->assign ("tests", perform_php_checks($faults));
626   // This var is true if there is anything went wrong
627   if ($faults)
628   {
629     $smarty->assign("mode", "disabled");
630   }
632   // This line displays the template only if (withoutput is set)
633   if($withoutput) 
634     $smarty->display (get_template_path('headers.tpl'));
636   if (isset($_SESSION['errors']))
637   {
638     $smarty->assign("errors", $_SESSION['errors']);
639   }
641   if($withoutput)
642     $smarty->display (get_template_path('setup.tpl'));
644   return (!$faults);
653 /* Shows Setup_page 2*/
654 function show_setup_page2($withoutput = true)
656   $smarty = get_smarty();
658   $smarty->assign ("content", get_template_path('setup_step2.tpl'));
659   $smarty->assign ("tests", perform_additional_checks($faults));
661   if ($faults) {
662     $smarty->assign("mode", "disabled");
663   }
664   if($withoutput){
665     $smarty->display (get_template_path('headers.tpl'));
666   }
668   if (isset($_SESSION['errors']))  {
669     $smarty->assign("errors", $_SESSION['errors']);
670   }
671   if($withoutput){
672     $smarty->display (get_template_path('setup.tpl'));
673   }
674   return (!$faults);                               
678 /* Setup page 3 asks for the server address
679  "Now we're going to include your LDAP server and create an initial configuration"*/
680 function show_setup_page3($withoutput = true)
683   // Take the Post oder the Sessioin saved data  
684   if(isset($_POST['uri']))
685     $uri = $_POST['uri'];
686   elseif(isset($_SESSION['ldapconf']['uri']))
687     $uri = $_SESSION['ldapconf']['uri'];
689   // If Page called first time, field is empty 
690   if((!isset($uri))||(empty($uri)))
691     $uri = "ldap://localhost:389";
694   $smarty = get_smarty();
696   // if isset $uri save it to session
697   if(isset($uri))
698   {
699     $_SESSION['ldapconf']['uri'] = $uri;
700     $smarty->assign ("uri", validate($uri));
701   }
704   // No error till now
705   $fault = false;
708   // If we pushed the Button continue
709   if(isset($_POST['continue3']))
710     if(!isset($uri))
711     {
712       $fault = true;
713       // Output the Error
714       if($withoutput)
715       {
716         print_red (_("You've to specify an ldap server before continuing!"));
717         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
718       }
719     }
720   elseif (!$ds = @ldap_connect (validate($uri)))
721   {
722     $fault =true;
723     // Output the Error
724     if($withoutput)
725     {
726       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
727       $smarty->assign ("uri", validate($uri));
728       $smarty->assign ("content", get_template_path('setup_step3.tpl'));
729     }
730   }
731     else
732     {
733       // Try to bind the connection     
734       ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
736       // if we can't bind , print error
737       if (!$r  =  @ldap_bind ($ds))
738       {
739         $fault = true;
740         // Output the Error
741         if($withoutput)      
742         {
743           print_red (_("Can't bind to the specified LDAP server! Please make sure that is reachable for GOsa."));
744           $smarty->assign ("content", get_template_path('setup_step3.tpl'));
745           $smarty->assign ("uri", validate($uri));
746         }
747       }
748       else
749       {
750         $fault = false;
751       }
752     }
755   $smarty->assign ("content", get_template_path('setup_step3.tpl'));
758   // Load Header
759   if($withoutput)
760     $smarty->display (get_template_path('headers.tpl'));
762   // Set Errors to Smarty
763   if (isset($_SESSION['errors']))
764   {
765     $smarty->assign("errors", $_SESSION['errors']);
766   }
768   // Print out Template 
769   if($withoutput)
770     $smarty->display (get_template_path('setup.tpl'));
774   return (!$fault);                             
779 // Setup page 4
780 // This page asked for detailed info, like base dn or admin user
781 // 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
782 function show_setup_page4($withoutput = true)
786   require_once("class_password-methods.inc");
788   error_reporting(E_ALL);
793   $fault        = false;                        // If an error occures we set this var to true 
794   $smarty       = get_smarty();                 // Our smarty instance
795   $uri          = $_SESSION['ldapconf']['uri']; // This is the the connect path to the ldapserver like ldap://lo..
796   $ldapconf     = $_SESSION['ldapconf'];        // The ldap Configuration informations, we collected while setup 
797   $arr_crypts   = array();                      // array which includes contains all possible password crypting methods
798   $temp         = "";                           // Temp
799   $checkvars    = array("location","admin","password","peopleou","peopledn","arr_crypts","mail","uidbase");
802   if(!isset($_SESSION['ldapconf']['arr_cryptkeys']))
803   {
804     require_once("class_password-methods.inc");
805     $tmp = passwordMethod::get_available_methods_if_not_loaded();
806     $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
807   }
811   if(!isset($_SESSION['ldapconf']['mail_methods']))
812   {
813     $_SESSION['ldapconf']['mail_methods']=array();
814     $temp = get_available_mail_classes();
815     $_SESSION['ldapconf']['mail_methods']= $temp['name'];
816   }
821   // If there are some empty vars in ldapconnect
822   // This values also represent out default values 
824 # first try to get $base 
825   if(!$ds = @ldap_connect (validate($uri)))    
826   {
827     $fault = true;
828     if($withoutput)
829       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
830   }
831   elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3))    
832   {
833     $fault = true;
834     if($withoutput)
835       print_red (_("Can't bind to the specified LDAP server!. Please make sure that is reachable for GOsa."));
836   }
837   elseif(! $r =  @ldap_bind ($ds))    
838   {
839     $fault = true;
840     if($withoutput)
841       print_red (_("Can't bind to the specified LDAP server! Please make sure that is reachable for GOsa."));
842   }
843   else
844   {
845     $sr=      @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
848     $attr=    @ldap_get_entries($ds,$sr);
849     if((empty($attr)))
850     {
851       $base= "dc=example,dc=net";
854       if($withoutput)
855         print_red(_("Bind to server successful, but the server seems to be completly empty, please check all informations twice"));
857     }
858     else
859     {
860       $base= $attr[0]['dn'];
861     }
862   }
866   if(!isset($_SESSION['ldapconf']['base']))           $_SESSION['ldapconf']['base']         = $base;
867   if(!isset($_SESSION['ldapconf']['admin']))          $_SESSION['ldapconf']['admin']        = "cn=ldapadmin,".$base;
868   if(!isset($_SESSION['ldapconf']['peopleou']))       $_SESSION['ldapconf']['peopleou']     = "ou=people";
869   if(!isset($_SESSION['ldapconf']['groupou']))        $_SESSION['ldapconf']['groupou']      = "ou=groups";
870   if(!isset($_SESSION['ldapconf']['peopledn']))       $_SESSION['ldapconf']['peopledn']     = "cn";
871   if(!isset($_SESSION['ldapconf']['password']))       $_SESSION['ldapconf']['password']     = "";
872   if(!isset($_SESSION['ldapconf']['location']))       $_SESSION['ldapconf']['location']     = "Example";
873   if(!isset($_SESSION['ldapconf']['uidbase']))        $_SESSION['ldapconf']['uidbase']      = "1000";
874   if(!isset($_SESSION['ldapconf']['mail']))           $_SESSION['ldapconf']['mail']         = 0;
875   $tmp = array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
876   if(!isset($_SESSION['ldapconf']['arr_crypts']))     $_SESSION['ldapconf']['arr_crypts']   = $tmp['md5'];
879   // check Post data
881   if(isset($_POST['check']))
882   {
883     // Check if all needed vars are submitted
884     foreach($checkvars as $key)
885     {
886       if((isset($_POST[$key]))&&($_POST[$key]!=""))
887       {
888         $_SESSION['ldapconf'][$key] = $_POST[$key];
889       }
890       else
891       {
892         if($withoutput)
893         {
894           print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
895         }
896         $fault = true;
897       }
898     }
900     // check if another base is given ... (ldapadmin...dc=base,dc=de)   ..
902     $base     =   $_SESSION['ldapconf']['admin'];
903     $tmp      =   array_reverse ( split(",",$base));
904     $base     =   $tmp[1].",".$tmp[0];
905     $_SESSION['ldapconf']['base']         = $base;
908   }
912   $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
913   $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
915   foreach($_SESSION['ldapconf'] as $key => $val)
916   {
917     $smarty->assign($key,$val);
918   }
920   if(isset($_POST['check']))
921   {
922     $ldap= new LDAP($_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password'], $_SESSION['ldapconf']['uri']);
923   
924     $m= schema_check($_SESSION['ldapconf']['uri'], $_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password']);
925     $_SESSION['classes']= $m;
927     if ($ldap->error != "Success")
928     {
929       if($withoutput)
930       {
931         print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
932       }
933       $fault = true;
934     }
935   }
939   // Set smarty output
940   $smarty->assign ("content", get_template_path('setup_step4.tpl'));
942   $smarty->assign ("peopledns", array("cn", "uid"));
943   if($withoutput)
944     $smarty->display (get_template_path('headers.tpl'));
946   if(isset($_SESSION['errors']))
947   {
948     $smarty->assign("errors", $_SESSION['errors']);
949   }
950   if($withoutput)
951     $smarty->display (get_template_path('setup.tpl'));
954   return (!$fault);
962 // This page shows your configuration 
963 // and wants you to download the gosa.conf ....
964 function show_setup_page5($withoutput=true)
966   // Get ldapconf
967   $ldapconf= $_SESSION['ldapconf'];
969   // get smarty
970   $smarty = get_smarty();
972   if(isset($_SESSION['classes']))
973     $classes = $_SESSION['classes'];
975   $info= posix_getgrgid(posix_getgid());
976   $smarty->assign ("webgroup", $info['name']);
977   $smarty->assign ("path", CONFIG_DIR);
978   $message = "";
979   $message.="<table class=\"check\">";
980   $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
981   
982   if($withoutput)
983   {
984     $smarty->assign ("schemas", view_schema_check($m));
985     $smarty->assign ("content", get_template_path('setup_finish.tpl'));
986   }
987   // Output templates ....
989   if($withoutput)
990     $smarty->display (get_template_path('headers.tpl'));
992   if (isset($_SESSION['errors']))
993   {
994     $smarty->assign("errors", $_SESSION['errors']);
995   }
996   if($withoutput)
997     $smarty->display (get_template_path('setup.tpl'));
998   return(true);
1012 // this function is called by setup step 5, in order to create a missinf Administrator 
1013 // and or Administrational user
1014 // on success go on with setup_page5
1015 // else show this page aggain
1016 function create_user_for_setup($withoutput=true)
1019   error_reporting(E_ALL);
1021   global $samba;
1023   $ldapconf = $_SESSION['ldapconf'];
1024   $smarty = get_smarty();
1027   
1028   if(isset($_SESSION['classes']))
1029     $classes= $_SESSION['classes'];
1031   // Everything runns perfect ...
1032   // So we do a last test on this page
1033   // is there a user with ACLs :all which will be able to adminsitrate GOsa
1034   // We check that, if this user or group is missing we ask for creating them
1036   $ldap= new LDAP($_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password'], $_SESSION['ldapconf']['uri']);
1038   //  $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
1040   // Now we are testing for a group, with the rights :all
1041   $ldap->cd($ldapconf['base']);
1042   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
1044   $group_cnt       = $ldap->count();
1045   $data           = $ldap->fetch();
1046   $create_user    = false;
1048   // We need to create Administrative user and group
1049   // Because theres no Group found
1050   if($group_cnt < 1)
1051   {
1052     // Set var to create user
1053     $create_user    =   true;
1055     // Output error
1056     if(($withoutput)&&(!isset($_POST['new_admin'])))
1057       print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1058   }
1059   else
1060   {
1062     // We found an Administrative Group, is there a user too
1063     if(isset($data['memberUid'][0]))
1064     {
1065       $ldap->search("(&(objectClass=gosaAccount)(objectClass=person))",array("uid=".$data['memberUid'][0]));
1066       $data2      = $ldap->fetch();
1067       $user_cnt   = $ldap->count();
1068     }
1070     // We must create a user
1071     if (($ldap->count() < 1)||(!isset($data2)))
1072     {
1073       $create_user = true;
1074       if(($withoutput)&&(!isset($_POST['new_admin'])))
1075         print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1076     }
1077     else
1078     {
1079       // We don't need to add a user
1080       return(true);
1081     }
1083   }// if($group_cn)
1085   // We need to create a new user with group
1086   if(isset($_POST['new_admin']))
1087   {
1088     // Is there a running user ?
1089     // Then add additional
1091     if (isset($classes['samba3']))
1092     {
1093       $samba= "2";
1094       $lmPassword = "lmPassword";
1095       $ntPassword = "ntPassword";
1096     } else {
1097       $samba= "3";
1098       $lmPassword = "sambaLMPassword";
1099       $ntPassword = "sambaNtPassword";
1100     }
1103     // Nothing submitted
1104     if(( (empty($_POST['admin_name']))||(empty($_POST['admin_pass'])) )&&(!$create_user))
1105     {
1106       return(true);
1107     }
1109     // We have the order to create on Admin ^^
1110     // Detect Samba version to define the Attribute names shown below
1111     // go to base
1112     $ldap->cd($ldapconf['base']);
1114     // Define the user we are going to create
1115     $dn =  "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1118     $arr['objectClass'][0] ="person";
1119     $arr['objectClass'][1] ="organizationalPerson";
1120     $arr['objectClass'][2] ="inetOrgPerson";
1121     $arr['objectClass'][3] ="gosaAccount";
1122     $arr['uid']            = $_POST['admin_name'];
1123     $arr['cn']             = $_POST['admin_name'];
1124     $arr['sn']             = $_POST['admin_name'];
1126     $arr['givenName']     = "GOsa main administrator";
1127     $arr[$lmPassword]     = "10974C6EFC0AEE1917306D272A9441BB";
1128     $arr[$ntPassword]     = "38F3951141D0F71A039CFA9D1EC06378";
1129     $arr['userPassword']  = crypt_single($_POST['admin_pass'],"md5");
1130     if( ! $ldap->dn_exists ( $dn )) { 
1131       $ldap->cd($dn); 
1132       $ldap->create_missing_trees($dn);
1133       $ldap->add($arr);
1134       if($ldap->error!="Success")      {
1135         print_red("Can't create user, and / or Group, possibly this problem  depends on an empty LDAP server. Check your configuration and try again!");
1136       }
1137     }
1139     // theres already a group for administrator, so we only need to add the user
1140     if($group_cnt)
1141     {
1142       if(!isset($data['memberUid']))
1143       {
1144         $arrr['memberUid']= $_POST['admin_name'];
1145       }
1146       else
1147       {
1148         $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1149         $arrr['memberUid'] = $data['memberUid'];
1150         unset($arrr['memberUid']['count']);
1151       }
1152       $ldap->cd($data['dn']);
1153       $ldap->modify($arrr);
1154     }
1155     else
1156     {
1157       // there was no group defined, so we must create one
1158       $dn                       = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1159       $arrr['objectClass'][0]   = "gosaObject";
1160       $arrr['objectClass'][1]   = "posixGroup";
1161       $arrr['gosaSubtreeACL']   = ":all";
1162       $arrr['cn']               = "administrators";
1163       $arrr['gidNumber']        = "999";
1164       $arrr['memberUid']        = $_POST['admin_name'];
1165       $ldap->cd($dn);
1166       $ldap->add($arrr);
1167     }
1170     // We created the Group and the user, so we can go on with the next setup step
1171     return(true);
1172   }
1173   else
1174   {
1175     if(!($create_user))
1176     {
1177       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1178       $smarty->assign("exists",true);
1179     }
1180     else
1181     {
1182       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1183       $smarty->assign("exists",false);
1184     }
1185   }
1188   // Smarty outout  
1190   if($withoutput)
1191     $smarty->display (get_template_path('headers.tpl'));
1193   if (isset($_SESSION['errors']))
1194   {
1195     $smarty->assign("errors", $_SESSION['errors']);
1196   }
1197   if($withoutput)
1198     $smarty->display (get_template_path('setup.tpl'));
1201   return(false);
1205 // Returns the classnames auf the mail classes
1206 function get_available_mail_classes()
1208   $dir = opendir( "../include");
1209   $methods = array();
1210   $suffix = "class_mail-methods-";
1211   $lensuf = strlen($suffix);
1212   $prefix = ".inc";
1213   $lenpre = strlen($prefix);
1216   $i = 0;
1217   while (($file = readdir($dir)) !== false) 
1218   {
1219     if(stristr($file,$suffix))
1220     {
1221       $lenfile = strlen($file);
1222       $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1223       $methods['file'][$i] = $file;
1224       $methods[$i]['file'] = $file;
1225       $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1226       $i++;
1227     }
1228   }
1229   return($methods);
1238 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1239 ?>