Code

Dummy mail Mehtod for setup
[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 }
11 function view_schema_check($table)
12 {
13   $message="<table class=\"check\">";
15   foreach ($table as $key => $values){
16     $msg = $values['msg'];
17     $message.= "<tr><td class=\"check\">$msg";
19     if($values['status']) {
20       $message.="</td><td style='text-align:center' >
21         <img src=images/true.png alt='true' /></td></tr>";
22     } else {
23       $message.="</td><td style='text-align:center' >
24         <img src=images/button_cancel.png alt='false' /></td></tr>";
25     }
26   }
27   $message.="</table>";
28   
29   return $message;
30 }
33 function schema_check($server, $admin, $password, $aff=0)
34 {
35   global $config;
37   $messages= array();
38   $required_classes= array(
39       "gosaObject"            => array("version" => "2.4"),
40       "gosaAccount"           => array("version" => "2.4"),
41       "gosaLockEntry"         => array("version" => "2.4"),
42       "gosaCacheEntry"        => array("version" => "2.4"),
43       "gosaDepartment"        => array("version" => "2.4"),
45       "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
46       "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
47       "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
49       "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
50       "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
51       "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
52       "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
53       "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
55       "GOhard"                => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
56       "gotoTerminal"          => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
57       "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
58       "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
59       "goNfsServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
60       "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
61       "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
62       "goLdapServer"          => array("version" => "2.4"),
63       "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
64       "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
65       "goKrbServer"           => array("version" => "2.4"),
66       "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
67       );
69   /* Build LDAP connection */
70   $ds= ldap_connect ($server);
71   if (!$ds) {
72     return (array(array("msg" => _("Can't bind to LDAP. No schema check possible!"), "status" => FALSE)));
73   }
74   ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
75   $r= ldap_bind ($ds, $admin, $password);
77   /* Get base to look for schema */
78   $sr  = @ldap_read ($ds, "", "objectClass=*", array("subschemaSubentry"));
79   $attr= @ldap_get_entries($ds,$sr);
80   if (!isset($attr[0]['subschemasubentry'][0])){
81     return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
82   }
84   /* Get list of objectclasses */
85   $nb= $attr[0]['subschemasubentry'][0];
86   $objectclasses= array();
87   $sr= ldap_read ($ds, $nb, "objectClass=*", array("objectclasses"));
88   $attrs= ldap_get_entries($ds,$sr);
89   if (!isset($attrs[0])){
90     return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
91   }
92   foreach ($attrs[0]['objectclasses'] as $val){
93     $name= preg_replace("/^.* NAME\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $val);
94     if ($name != $val){
95       $objectclasses[$name]= $val;
96     }
97   }
98   /* Walk through objectclasses and check if they are needed or not */
99   foreach ($required_classes as $key => $value){
100     if (isset($value['class'])){
101       if (!is_array($value['class'])){
102         $classes= array($value['class']);
103       } else {
104         $classes= $value['class'];
105       }
107       /* Check if we are using the class that requires */
108       foreach($classes as $class){
109         if (!isset($objectclasses[$key])){
110           $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' is not present in LDAP setup"), $key, $class);
111           $messages[$key]['status'] = FALSE;
112         } else {
113           if (!check_schema_version($objectclasses[$key], $value['version'])){
114             $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' does not have version %s"), $key, $class, $value['version']);
115             $messages[$key]['status'] =FALSE;
116           }else {
117             if(!isset($affich2[$class])){
118               $affich2[$class]['msg']   = sprintf(_("Support for '%s' enabled"), $class)."<td class=\"check\"> ".$value['file']."</td>";
119               $affich2[$class]['status']= TRUE; 
120             }
121           }
122         }
124       }
125     } else {
126       /* Required class */
127       if (!isset($objectclasses[$key])){
128         $messages[$key]['msg']= sprintf(_("Required objectclass '%s' is not present in LDAP setup"), $key);
129         $messages[$key]['status'] = FALSE;  
130       } else {
131         if (!check_schema_version($objectclasses[$key], $value['version'])){
132           $messages[$key]['msg']= sprintf(_("Required objectclass '%s' does not have version %s"), $key, $value['version']);
133           $messages[$key]['status'] = FALSE;  
134         }
135       }
136     }
137   }
139   /* Check for correct samba parameters */
140   if (!isset($objectclasses['sambaSamAccount'])){
141     $messages['samba3']['msg']= _("SAMBA 3 support disabled, no schema seems to be installed");
142     $affich['samba3']['msg']= $messages['samba3']['msg']."<td class=\"check\">gosa+samba3.schema</td>";
143     $messages['samba3']['status']= FALSE;
144     $affich['samba3']['status']= FALSE;
145   }else{
146     $affich['samba3']['msg']= _("SAMBA 3 support enabled")."<td class=\"check\">gosa+samba3.schema</td>";
147     $affich['samba3']['status']= TRUE;
148   }
150   if (!isset($objectclasses['sambaAccount'])){
151     $messages['samba2']['msg']= _("SAMBA 2 support disabled, no schema seems to be installed");
152     $affich['samba2']['msg']= $messages['samba2']['msg']."<td class=\"check\">samba.schema</td>";
153     $messages['samba2']['status']= FALSE;
154     $affich['samba2']['status']= FALSE;
155   }else{
156     $affich['samba2']['msg']= _("SAMBA 2 support enabled")."<td class=\"check\">samba.schema</td>";
157     $affich['samba2']['status']= TRUE;
158   }
160   /* Check pureftp/dns/ */
161   if (!isset($objectclasses['PureFTPdUser'])){
162     $messages['pureftp']['msg']= _("Support for pureftp disabled, no schema seems to be installed");
163     $affich['pureftp']['msg']= $messages['pureftp']['msg']."<td class=\"check\">pureftpd.schema</td>";
164     $messages['pureftp']['status']= FALSE;
165     $affich['pureftp']['status']= FALSE;
166   }else{
167     $affich['pureftp']['msg']= _("Support for pureftp enabled")."<td class=\"check\">pureftpd.schema</td>";
168     $affich['pureftp']['status']= TRUE;
169   }
171   if (!isset($objectclasses['gosaWebdavAccount'])){
172     $messages['webdav']['msg']= _("Support for WebDAV disabled, no schema seems to be installed");
173     $affich['webdav']['msg']= $messages['webdav']['msg']."<td class=\"check\"></td>";
174     $messages['webdav']['status']= FALSE;
175     $affich['webdav']['status']= FALSE;
176   }else{
177     $affich['webdav']['msg']=_("Support for WebDAV enabled")."<td class=\"check\">gosa+samba3.schema</td>";
178     $affich['webdav']['status']= TRUE;
179   }
181   if (!isset($objectclasses['phpgwAccount'])){
182     $messages['phpgroupware']['msg']= _("Support for phpgroupware disabled, no schema seems to be installed");
183     $affich['phpgroupware']['msg']= $messages['phpgroupware']['msg']."<td class=\"check\">phpgwaccount.schema</td>";
184     $messages['phpgroupware']['status']= FALSE;
185     $affich['phpgroupware']['status']= FALSE;
186   }else{
187     $affich['phpgroupware']['msg']= _("Support for phpgroupware enabled")."<td class=\"check\">phpgwaccount.schema</td>";
188     $affich['phpgroupware']['status']= TRUE;
189   }
191   if (!isset($objectclasses['goFonAccount'])){
192     $messages['phoneaccount']['msg']= _("Support for gofon disabled, no schema seems to be installed");
193     $affich['phoneaccount']['msg']= $messages['phoneaccount']['msg']."<td class=\"check\">gofon.schema</td>";
194     $messages['phoneaccount']['status']= FALSE;
195     $affich['phoneaccount']['status']= FALSE;
196   }else{
197     $affich['phoneaccount']['msg']= _("Support for gofon enabled")."<td class=\"check\">gofon.schema</td>";
198     $affich['phoneaccount']['status']= true;
199   }
201   if(($_SESSION['ldapconf']['mail_methods'][$_SESSION['ldapconf']['mail']] == "kolab")){
202     if(!isset($objectclasses['kolabInetOrgPerson']))
203     {
204       $messages['kolab']['msg']= _("Support for Kolab disabled, no schema seems to be installed, setting mail-method to cyrus");
205       $affich['kolab']['msg']=$messages['kolab']['msg']."<td class=\"check\">kolab2.schema</td>";
207       $tmp= array_flip($_SESSION['ldapconf']['mail_methods']);
208       $_SESSION['ldapconf']['mail']=$tmp['cyrus'];
209       $messages['kolab']['status']= FALSE;
210       $affich['kolab']['status']= FALSE;
211     }else{
212       $affich['kolab']['msg']=_("Support for Kolab enabled")."<td class=\"check\">gofon.schema</td>";
213       $affich['kolab']['status']= TRUE;
214     }
215   }
216   if($aff==0){
217     return ($messages);
218   } else {
219     return(array_merge($affich,$affich2));
220   }
224 function check(&$faults, $message, $description, $test, $required= TRUE)
226   $msg= "<table class='check'><tr><td class='check' style='font-size:14px;'>$message</td>
227     <td rowspan=2 style='vertical-align:middle; text-align:center;width:45px;'>";
228   if ($test){
229     $msg.= _("OK")."<br>";
230   } else {
231     if (!$required){
232       $msg.="<font color=red>"._("Ignored")."</font><br>";
233     } else {
234       $msg.="<font color=red>"._("Failed")."</font><br>";
235       $faults++;
236     }
237   }
238   $msg.= "</td></tr><tr><td class='check' style='padding-left:20px;".
239          "background-color:#F0F0F0;'>$description</td></tr></table><br>";
241   return $msg;
244 function perform_php_checks(&$faults)
246   global $check_globals;
248   $faults= 0;
249   $msg= "";
251   $msg.= "<h1>"._("PHP setup inspection")."</h1>";
252   $msg.= check (        $faults, _("Checking for PHP version (>=4.1.0)"),
253       _("PHP must be of version 4.1.0 or above for some functions and known bugs in PHP language."),
254       version_compare(phpversion(), "4.1.0")>=0);
256   $msg.= check (        $faults, _("Checking if register_globals is set to 'off'"),
257       _("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."),
258       $check_globals == 0, FALSE);
260   $msg.= check (        $faults, _("Checking for ldap module"),
261       _("This is the main module used by GOsa and therefore really required."),
262       function_exists('ldap_bind'));
264   $msg.= check (        $faults, _("Checking for gettext support"),
265       _("Gettext support is required for internationalized GOsa."), function_exists('bindtextdomain'));
267   $msg.= check (        $faults, _("Checking for iconv support"),
268       _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
269       function_exists('iconv'));
271   $msg.= check (        $faults, _("Checking for mhash module"),
272       _("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."),
273       function_exists('mhash'), FALSE);
275   $msg.= check (        $faults, _("Checking for imap module"),
276       _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
277       function_exists('imap_open'));
278   $msg.= check (        $faults, _("Checking for getacl in imap"),
279       _("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."),
280       function_exists('imap_getacl'), FALSE);
281   $msg.= check (        $faults, _("Checking for mysql module"),
282       _("MySQL support is needed for reading GOfax reports from databases."),
283       function_exists('mysql_query'), FALSE);
284   $msg.= check (        $faults, _("Checking for cups module"),
285       _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
286       function_exists('cups_get_dest_list'), FALSE);
287   $msg.= check (        $faults, _("Checking for kadm5 module"),
288       _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
289       function_exists('kadm5_init_with_password'), FALSE);
290   $msg.= check (  $faults, _("Checking for snmp Module"),
291       _("Simple Network Management Protocol (SNMP) is required for client monitoring."),
292       function_exists('snmpgetnext'), FALSE);
293   return ($msg);
297 function perform_additional_checks(&$faults)
299   /* Programm check */
300   $msg= "<h1>"._("Checking for some additional programms")."</h1>";
302   /* Image Magick */
303   $query= "LC_ALL=C LANG=C convert -help";
304   $output= shell_exec ($query);
305   if ($output != ""){
306     $lines= split ("\n", $output);
307     $version= preg_replace ("/^Version:[^I]+ImageMagick ([^\s]+).*/", "\\1", $lines[0]);
308     list($major, $minor)= split("\.", $version);
309     $msg.= check (      $faults, _("Checking for ImageMagick (>=5.4.0)"),
310         _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
311         ($major > 5 || ($major == 5 && $minor >= 4)));
312   } else {
313     $msg.= check (      $faults, _("Checking imagick module for PHP"),
314         _("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);
315   }
317   /* Check for fping */
318   $query= "LC_ALL=C LANG=C fping -v 2>&1";
319   $output= shell_exec ($query);
320   $have_fping= preg_match("/^fping:/", $output);
321   $msg.= check (        $faults, _("Checking for fping utility"),
322       _("The fping utility is only used if you've got a thin client based terminal environment running."),
323       $have_fping, FALSE);
325   /* Check for smb hash generation tool */
326   $query= "mkntpwd 2>&1";
327   $output= shell_exec ($query);
328   $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
329   $alt = 0;
331   if (!$have_mkntpwd){
332     $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
333     system ($query, $ret);
334     $alt= ($ret == 0);
335   }
337   $msg.= check (        $faults, _("Checking for a way to generate LM/NT password hashes"),
338       _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
339       ($have_mkntpwd || $alt));
341   /* seesio.auto_start should be off, in order to without trouble*/
342   $arra = ini_get_all();
344   $session_auto_start = $arra['session.auto_start'];
345   $implicit_flush     = $arra['implicit_flush'];
346   $max_execution_time = $arra['max_execution_time'];
347   $memory_limit       = $arra['memory_limit'];
348   $expose_php         = $arra['expose_php'];
349   $magic_quotes_gpc   = $arra['magic_quotes_gpc'];
350   $register_globals   = $arra['register_globals'];
352   /* auto_register */
353   $msg.= check (  $faults, _("php.ini check -> session.auto_register"),
354       _("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']));
356   /* implicit_flush */
357   $msg.= check (  $faults, _("php.ini check -> implicit_flush"),
358       _("This option influences the Output handling. Turn this Option off, to increase performance."),
359       !$implicit_flush['local_value'],0,false);
361   /* max_execution_time */
362   if($max_execution_time['local_value'] < 30 ){
363     $max_execution_time['local_value']=false;
364   }
365   $msg.= check (  $faults, _("php.ini check -> max_execution_time"),
366       _("The Execution time should be at least 30 seconds, because some actions may consume more time."),
367       $max_execution_time['local_value'],0,false);
369   /* memory_limit */
370   if($memory_limit['local_value'] < 16 ){
371     $memory_limit['local_value']=false;
372   }
373   $msg.= check (  $faults, _("php.ini check -> memory_limit"),
374       _("GOsa needs at least 16MB of memory, less will cause unpredictable errors! Increase it for larger setups."),
375       !$implicit_flush['local_value'],0,false);
377   /* expose_php */
378   $msg.= check (  $faults, _("php.ini check -> expose_php"),
379       _("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."),
380       !$implicit_flush['local_value'],0,false);
382   /* magic_quotes_gpc */
383   $msg.= check (  $faults, _("php.ini check -> magic_quotes_gpc"),
384       _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."),
385       $magic_quotes_gpc['local_value'],0,false);
387   return $msg;
391 function parse_contrib_conf()
394   $str                = "";
395   $used_samba_version = 0;
396   $query              = ""; 
397   $fp                 = false;
398   $output             = "";
399   $needridbase_sid    = false;
400   $pwdhash            = "";
401   $replacements       = array();
402   $ldapconf           = $_SESSION['ldapconf']; // The Installation information
403   $classes            = $_SESSION['classes'];  // Class information needed to define which features are enabled
404   $possible_plugins   = array();
406   /* Which samba version do we use? */
407   if(isset($classes['samba3'])){
408     $used_samba_version = 2;
409   } else {
410     $used_samba_version = 3;
411   }
413   /* Look for samba password generation method */
414   if(file_exists("/usr/lib/gosa/mkntpasswd")){
415     $pwdhash  = "/usr/lib/gosa/mkntpasswd";
416   } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
417     $pwdhash= "mkntpwd";
418   } else {
419     $pwdhash=('perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
420   }
422   /* Define which variables will be replaced */
423   $replacements['{LOCATIONNAME}']  = $ldapconf['location'];
424   $replacements['{SAMBAVERSION}']  = $used_samba_version;
425   $replacements['{LDAPBASE}']      = $ldapconf['base'];
426   $replacements['{LDAPADMIN}']     = $ldapconf['admin'];
427   $replacements['{DNMODE}']        = $ldapconf['peopledn'];
428   $replacements['{LDAPHOST}']      = $ldapconf['uri'];
429   $replacements['{PASSWORD}']      = $ldapconf['password'];
430   $replacements['{CRYPT}']         = $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
431   $replacements['{SID}\n']         = "";
432   $replacements['{RIDBASE}\n']     = "";
433   if($ldapconf['mail'] == "disabled")
434     $replacements['{MAILMETHOD}']    = "";
435   else
436     $replacements['{MAILMETHOD}']    = $ldapconf['mail_methods'][$ldapconf['mail']];
437   if($ldapconf['mail'] == "disabled") 
438   $replacements['{SMBHASH}']       = $pwdhash;
439   $replacements['{GOVERNMENTMODE}']= "false"; 
440   $replacements['{kolabAccount}']  = "";
441   $replacements['{servKolab}']     = "";
443   /* This array contains all preg_replace syntax to delete all unused plugins
444      THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes'] */
445   $possible_plugins['fonreport'][]   = "'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
446   $possible_plugins['phoneaccount'][]= "'\n.*<tab.*phoneAccount.*>.*\n'i";
447   $possible_plugins['logview'][]     = "'\n.*<plugin.*logview+.*\n.*>.*\n'i";
448   $possible_plugins['pureftp'][]     = "'\n.*<tab.*pureftp.*>.*\n'i";
449   $possible_plugins['webdav'][]      = "'\n.*<tab.*webdav.*>.*\n'i";
450   $possible_plugins['phpgroupware'][]= "'\n.*<tab.*phpgroupware.*>.*\n'i";
452   /* Header information
453      Needed to send the generated gosa.conf to the browser */
454   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
455   header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
456   header("Cache-Control: no-cache");
457   header("Pragma: no-cache");
458   header("Cache-Control: post-check=0, pre-check=0");
459   header("Content-type: text/plain");
461   if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
462       preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
463     header('Content-Disposition: filename="gosa.conf"');
464   } else {
465     header('Content-Disposition: attachment; filename="gosa.conf"');
466   }
468   if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r")) {
469     echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
470   } else {
471     while(!feof($fp)) {
472       $str.= fread($fp,512);
473     }
475     if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab") {
476       $replacements['{kolabAccount}']  ="<tab class=\"kolabAccount\" />\n     ";
477       $replacements['{servKolab}']     ="<tab class=\"servkolab\" name=\"Kolab\" />";
478     }
480     if($used_samba_version == 2) {
481       /* Do nothing for samba 2... */
482     } else {
483       /* Create LDAP connection, to check if there's a domain
484          object defined in the LDAP schema */
485       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
487       /* Try to find a Samba Domain Objekt */
488       $ldap->search("(objectClass=sambaDomain)");
490       /* Something found ??? so we need to define ridbase an SID by ourselfs */
491       if($ldap->count()< 1) {
492         $replacements['{SID}']= "sid=\"123412-11\"";
493         $replacements['{RIDBASE}']= "ridbase=\"1000\"";  
494       } 
495     }
497     /* Data readed, types replaced, samba version detected and checked if
498        we need to add SID and RIDBASE. Check if there is an ivbbEntry in
499        the LDAP tree, in this case we will set the governmentmode to true.
500        Create LDAP connection, to check if theres a domain Objekt definen
501        in the LDAP schema. */
502     if(!isset($ldap)){
503       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
504     }
506     /* Try to find a Samba Domain Objekt */
507     $ldap->search("(objectClass=ivbbEntry)");
509     /* Something found ??? so we need to define ridbase an SID by ourselfs */
510     if($ldap->count()> 0) {
511       $replacements['{GOVERNMENTMODE}']= "true";
512     }
514     /* Replace all colleted information with placeholder */
515     foreach($replacements as $key => $val) {
516       $str = preg_replace("/".$key."/",$val,$str);
517     }    
519     /* Remove all unused plugins */
520     foreach($possible_plugins as $plugin) {
521       foreach($plugin as $key=>$val) {
522         if(in_array($plugin,$classes)) {
523           $str = preg_replace($val,"\n",$str);
524         }
525       }
526     }
527   }
529   return ((($str)));
533 /* Show setup_page 1 */
534 function show_setup_page1($withoutput = true)
536   $smarty = get_smarty();  
537   $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
538   $smarty->assign ("tests", perform_php_checks($faults));
540   /* This var is true if anything went wrong */
541   if ($faults){
542     $smarty->assign("mode", "disabled");
543   }
545   /* This line displays the template only if (withoutput is set) */
546   if($withoutput){
547     $smarty->display (get_template_path('headers.tpl'));
548   }
550   if (isset($_SESSION['errors'])){
551     $smarty->assign("errors", $_SESSION['errors']);
552   }
554   if($withoutput){
555     $smarty->display (get_template_path('setup.tpl'));
556   }
558   return (!$faults);
562 /* Show setup_page 2 */
563 function show_setup_page2($withoutput = true)
565   $smarty = get_smarty();
566   $smarty->assign ("content", get_template_path('setup_step2.tpl'));
567   $smarty->assign ("tests", perform_additional_checks($faults));
569   if ($faults) {
570     $smarty->assign("mode", "disabled");
571   }
572   if($withoutput){
573     $smarty->display (get_template_path('headers.tpl'));
574   }
575   if (isset($_SESSION['errors']))  {
576     $smarty->assign("errors", $_SESSION['errors']);
577   }
578   if($withoutput){
579     $smarty->display (get_template_path('setup.tpl'));
580   }
582   return (!$faults);                               
586 function show_setup_page3($withoutput = true)
588   $smarty = get_smarty();
590   /* Take the Post oder the Sessioin saved data */
591   if(isset($_POST['uri'])){
592     $uri = $_POST['uri'];
593   } elseif(isset($_SESSION['ldapconf']['uri'])){
594     $uri = $_SESSION['ldapconf']['uri'];
595   }
597   /* If Page called first time, field is empty */
598   if((!isset($uri))||(empty($uri))){
599     $uri = "ldap://localhost:389";
600   }
602   /* if isset $uri save it to session */
603   if(isset($uri)) {
604     $_SESSION['ldapconf']['uri'] = $uri;
605     $smarty->assign ("uri", validate($uri));
606   }
608   /* No error till now */
609   $fault = false;
611   /* If we pushed the Button continue */
612   if(isset($_POST['continue3'])){
613     if(!isset($uri)) {
614       $fault = true;
615       
616       /* Output the Error */
617       if($withoutput) {
618         print_red (_("You've to specify an ldap server before continuing!"));
619         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
620       }
621     }
622   } elseif (!$ds = @ldap_connect (validate($uri))) {
623     $fault =true;
624     
625     /* Output the Error */
626     if($withoutput) {
627       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
628       $smarty->assign ("uri", validate($uri));
629       $smarty->assign ("content", get_template_path('setup_step3.tpl'));
630     }
631   } else {
632     /* Try to bind the connection */    
633     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
635     /* if we can't bind , print error */
636     if (!$r  =  @ldap_bind ($ds)) {
637       $fault = true;
638     
639       /* Output the Error */
640       if($withoutput) {
641         print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
642         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
643         $smarty->assign ("uri", validate($uri));
644       }
645     } else {
646       $fault = false;
647     }
648   }
650   $smarty->assign ("content", get_template_path('setup_step3.tpl'));
652   /* Load Header */
653   if($withoutput){
654     $smarty->display (get_template_path('headers.tpl'));
655   }
657   /* Set Errors to Smarty */
658   if (isset($_SESSION['errors'])) {
659     $smarty->assign("errors", $_SESSION['errors']);
660   }
662   /* Print out Template */ 
663   if($withoutput){
664     $smarty->display (get_template_path('setup.tpl'));
665   }
667   return (!$fault);                             
671 function show_setup_page4($withoutput = true)
673   $smarty= get_smarty();      
675   if(!isset($_SESSION['ldapconf']['base'])){
676     $_SESSION['ldapconf']['base']= $base;
677   }
679   if(!isset($_SESSION['ldapconf']['base'])){
680     $_SESSION['ldapconf']['base']= $base;
681   }
682   require_once("class_password-methods.inc");
684   $fault     = false;              
685   $uri       = $_SESSION['ldapconf']['uri'];
686   $ldapconf  = $_SESSION['ldapconf'];
687   $arr_crypts= array();
688   $temp      = "";
689   $checkvars = array("location", "admin", "password", "peopleou", "base",
690                      "peopledn", "arr_crypts", "mail", "uidbase");
692   if(!isset($_SESSION['ldapconf']['arr_cryptkeys'])) {
693     require_once("class_password-methods.inc");
694     $tmp= passwordMethod::get_available_methods_if_not_loaded();
695     $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
696   }
698   if(!isset($_SESSION['ldapconf']['mail_methods'])) {
699     $_SESSION['ldapconf']['mail_methods']=array();
700     $temp = get_available_mail_classes();
701     $_SESSION['ldapconf']['mail_methods']= $temp['name'];
702   }
704   /* If there are some empty vars in ldapconnect -
705      these values also represent out default values */
706   if(!$ds = @ldap_connect (validate($uri))){
707     $fault = true;
708     if($withoutput){
709       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
710     }
711   } elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
712     $fault = true;
713     if($withoutput){
714       print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
715     }
716   } elseif(!$r= @ldap_bind ($ds)){
717     $fault = true;
718     if($withoutput){
719       print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
720     }
721   } else {
722     $sr=   @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
723     $attr= @ldap_get_entries($ds,$sr);
725     if((empty($attr))) {
726       $base= "dc=example,dc=net";
728       if($withoutput){
729         print_red(_("Bind to server successful, but the server seems to be completly empty, please check all informations twice"));
730       }
731       
732     } else {
733       $base= $attr[0]['dn'];
734     }
735   }
737   if(!isset($_SESSION['ldapconf']['base'])){
738     $_SESSION['ldapconf']['base']= $base;
739   }
740   if(!isset($_SESSION['ldapconf']['admin'])){
741     $_SESSION['ldapconf']['admin']= "cn=ldapadmin,".$base;
742   }
743   if(!isset($_SESSION['ldapconf']['peopleou'])){
744     $_SESSION['ldapconf']['peopleou']= "ou=people";
745   }
746   if(!isset($_SESSION['ldapconf']['groupou'])){
747     $_SESSION['ldapconf']['groupou']= "ou=groups";
748   }
749   if(!isset($_SESSION['ldapconf']['peopledn'])){
750     $_SESSION['ldapconf']['peopledn']= "cn";
751   }
752   if(!isset($_SESSION['ldapconf']['password'])){
753     $_SESSION['ldapconf']['password']= "";
754   }
755   if(!isset($_SESSION['ldapconf']['location'])){
756     $_SESSION['ldapconf']['location']= "Example";
757   }
758   if(!isset($_SESSION['ldapconf']['uidbase'])){
759     $_SESSION['ldapconf']['uidbase']= "1000";
760   }
761   if(!isset($_SESSION['ldapconf']['mail'])){
762     $_SESSION['ldapconf']['mail']= 0;
763   }
764   $tmp= array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
765   if(!isset($_SESSION['ldapconf']['arr_crypts'])){
766     $_SESSION['ldapconf']['arr_crypts']   = $tmp['md5'];
767   }
769   /* check POST data */
770   if(isset($_POST['check'])) {
772     /* Check if all needed vars are submitted */
773     foreach($checkvars as $key) {
774       if($key == "peopleou"){
775         continue;
776       }
777       if($key == "groupou"){
778         continue;
779       }
781       if((isset($_POST[$key]))&&($_POST[$key]!="")) {
782         $_SESSION['ldapconf'][$key] = $_POST[$key];
783       } else {
784         if($withoutput) {
785           print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
786         }
787         $fault = true;
788       }
789     }
790   }
792   /* Transfer base */
793   if(isset($_POST['base'])){
794     $_SESSION['ldapconf']['base']= $_POST['base'];
795   }
797   $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
798   $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
800   foreach($_SESSION['ldapconf'] as $key => $val) {
801     $smarty->assign($key,$val);
802   }
804   if(isset($_POST['check'])) {
805     $ldap= new LDAP($_SESSION['ldapconf']['admin'],
806                     $_SESSION['ldapconf']['password'],
807                     $_SESSION['ldapconf']['uri']);
809     $m= schema_check($_SESSION['ldapconf']['uri'],
810                     $_SESSION['ldapconf']['admin'],
811                     $_SESSION['ldapconf']['password']);
812     $_SESSION['classes']= $m;
814     if ($ldap->error != "Success") {
815       if($withoutput) {
816         print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
817       }
818       $fault = true;
819     }
820   }
822   /* Set smarty output */
823   $smarty->assign ("content", get_template_path('setup_step4.tpl'));
824   $smarty->assign ("peopledns", array("cn", "uid"));
825   if($withoutput){
826     $smarty->display (get_template_path('headers.tpl'));
827   }
828   if(isset($_SESSION['errors'])) {
829     $smarty->assign("errors", $_SESSION['errors']);
830   }
831   if($withoutput){
832     $smarty->display (get_template_path('setup.tpl'));
833   }
835   return (!$fault);
839 function show_setup_page5($withoutput=true)
841   /* Get ldapconf */
842   $ldapconf= $_SESSION['ldapconf'];
844   /* get smarty */
845   $smarty = get_smarty();
847   if(isset($_SESSION['classes'])){
848     $classes = $_SESSION['classes'];
849   }
851   $info= posix_getgrgid(posix_getgid());
852   $smarty->assign("webgroup", $info['name']);
853   $smarty->assign("path", CONFIG_DIR);
854   $message= "<table class=\"check\">";
855   $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
857   if($withoutput) {
858     $smarty->assign ("schemas", view_schema_check($m));
859     $smarty->assign ("content", get_template_path('setup_finish.tpl'));
860   }
861   
862   /* Output templates... */
863   if($withoutput){
864     $smarty->display (get_template_path('headers.tpl'));
865   }
866   if (isset($_SESSION['errors'])) {
867     $smarty->assign("errors", $_SESSION['errors']);
868   }
869   if($withoutput){
870     $smarty->display (get_template_path('setup.tpl'));
871   }
872   
873   return(true);
877 function create_user_for_setup($withoutput=true)
879   global $samba;
881   $ldapconf = $_SESSION['ldapconf'];
882   $smarty = get_smarty();
884   if(isset($_SESSION['classes'])){
885     $classes= $_SESSION['classes'];
886   }
888   /* Everything runns perfect ...
889      So we do a last test on this page
890      is there a user with ACLs :all which will be able to adminsitrate GOsa
891      We check that, if this user or group is missing we ask for creating them */
892   $ldap= new LDAP($_SESSION['ldapconf']['admin'],
893                   $_SESSION['ldapconf']['password'],
894                   $_SESSION['ldapconf']['uri']);
896   /* Now we are testing for a group, with the rights :all */
897   $ldap->cd($ldapconf['base']);
898   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
900   $group_cnt  = $ldap->count();
901   $data       = $ldap->fetch();
902   $create_user= false;
904   /* We need to create administrative user and group
905      because theres no group found */
906   if($group_cnt < 1) {
907     
908     /* Set var to create user */
909     $create_user=   true;
911     /* Output error */
912     if(($withoutput)&&(!isset($_POST['new_admin']))){
913       print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
914     }
916   } else {
918     /* We found an Administrative Group, is there a user, too */
919     if(isset($data['memberUid'][0])) {
920       $ldap->search("(&(objectClass=gosaAccount)(objectClass=person))",array("uid=".$data['memberUid'][0]));
921       $data2   = $ldap->fetch();
922     }
924     /* We must create a user */
925     if (($ldap->count() < 1)||(!isset($data2))) {
926       $create_user = true;
927       if(($withoutput)&&(!isset($_POST['new_admin']))){
928         print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
929       }
930     } else {
931       /* We don't need to add a user */
932       return(true);
933     }
935   }
937   /* We need to create a new user with group */
938   if(isset($_POST['new_admin']))
939   {
940     /* Adjust password attributes according to the samba version */
941     if (isset($classes['samba3'])) {
942       $samba= "2";
943       $lmPassword = "lmPassword";
944       $ntPassword = "ntPassword";
945     } else {
946       $samba= "3";
947       $lmPassword = "sambaLMPassword";
948       $ntPassword = "sambaNtPassword";
949     }
951     /* Nothing submitted */
952     if(( (empty($_POST['admin_name']))||(empty($_POST['admin_pass'])) )&&(!$create_user)) {
953       return(true);
954     }
956     /* We have the order to create on Admin ^^
957        Detect Samba version to define the Attribute names shown below */
958     $ldap->cd($ldapconf['base']);
960     /* Define the user we are going to create */
961     $dn= "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
962     $arr['objectClass'][0] ="person";
963     $arr['objectClass'][1] ="organizationalPerson";
964     $arr['objectClass'][2] ="inetOrgPerson";
965     $arr['objectClass'][3] ="gosaAccount";
966     $arr['uid']            = $_POST['admin_name'];
967     $arr['cn']             = $_POST['admin_name'];
968     $arr['sn']             = $_POST['admin_name'];
969     $arr['givenName']      = "GOsa main administrator";
970     $arr[$lmPassword]      = "10974C6EFC0AEE1917306D272A9441BB";
971     $arr[$ntPassword]      = "38F3951141D0F71A039CFA9D1EC06378";
972     $arr['userPassword']   = crypt_single($_POST['admin_pass'],"md5");
974     if( !$ldap->dn_exists ( $dn )){ 
975       $ldap->cd($dn); 
976       $ldap->create_missing_trees($dn);
977       $ldap->add($arr);
978       if($ldap->error!="Success"){
979         print_red("Can't create user, and / or Group, possibly this problem  depends on an empty LDAP server. Check your configuration and try again!");
980       }
981     }
983     /* There's already a group for administrator, so we only need to add the user */
984     if($group_cnt) {
986       if(!isset($data['memberUid'])) {
987         $arrr['memberUid']= $_POST['admin_name'];
988       } else {
989         $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
990         $arrr['memberUid'] = $data['memberUid'];
991         unset($arrr['memberUid']['count']);
992       }
994       $ldap->cd($data['dn']);
995       $ldap->modify($arrr);
997     } else {
998       
999       $dn                    = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1000       $arrr['objectClass'][0]= "gosaObject";
1001       $arrr['objectClass'][1]= "posixGroup";
1002       $arrr['gosaSubtreeACL']= ":all";
1003       $arrr['cn']            = "administrators";
1004       $arrr['gidNumber']     = "999";
1005       $arrr['memberUid']     = $_POST['admin_name'];
1006       $ldap->cd($dn);
1007       $ldap->add($arrr);
1008     }
1010     return(true);
1011   } else {
1013     if(!($create_user)) {
1014       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1015       $smarty->assign("exists",true);
1016     } else {
1017       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1018       $smarty->assign("exists",false);
1019     }
1021   }
1023   /* Smarty output */ 
1024   if($withoutput){
1025     $smarty->display (get_template_path('headers.tpl'));
1026   }
1027   if (isset($_SESSION['errors'])) {
1028     $smarty->assign("errors", $_SESSION['errors']);
1029   }
1030   if($withoutput){
1031     $smarty->display (get_template_path('setup.tpl'));
1032   }
1034   return(false);
1038 /* Returns the classnames auf the mail classes */
1039 function get_available_mail_classes()
1041   $dir = opendir( "../include");
1042   $methods = array();
1043   $suffix = "class_mail-methods-";
1044   $lensuf = strlen($suffix);
1045   $prefix = ".inc";
1046   $lenpre = strlen($prefix);
1048   $i = 0;
1049   while (($file = readdir($dir)) !== false){
1051     if(stristr($file,$suffix)) {
1052       $lenfile = strlen($file);
1053       $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1054       $methods['file'][$i] = $file;
1055       $methods[$i]['file'] = $file;
1056       $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1057       $i++;
1058     }
1060   }
1061   
1062   return($methods);
1065 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1066 ?>