Code

8dac4a887251575c429fca4f54059b077f0b7125
[gosa.git] / include / functions_setup.inc
1 <?php
3 function check_schema_version($description, $version)
4 {
5   $desc= preg_replace("/^.* DESC\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $description);
7   return preg_match("/\(v$version\)/", $desc);
8 }
11 function view_schema_check($table)
12 {
13   $message="<table summary=\"\" class=\"check\">";
15   foreach ($table as $key => $values){
16     $msg = $values['msg'];
17     $message.= "<tr><td class=\"check\">$msg";
19     if($values['status']) {
20       $message.="</td><td style='text-align:center' >
21         <img src=images/true.png alt='true' /></td></tr>";
22     } else {
23       $message.="</td><td style='text-align:center' >
24         <img src=images/button_cancel.png alt='false' /></td></tr>";
25     }
26   }
27   $message.="</table>";
29   return $message;
30 }
33 function is_schema_readable($server, $admin, $password)
34 {
35   $ldap = new LDAP($admin,$password,$server);
36   $tmp = $ldap->get_objectclasses();
38   if(count($tmp)){
39     return(true);
40   }
41   return(false);
42
44 function schema_check($server, $admin, $password, $aff=0,$CalledByIndexPhP=false)
45 {
46   global $config;
48   $messages= array();
49   $required_classes= array(
50       "gosaObject"            => array("version" => "2.4"),
51       "gosaAccount"           => array("version" => "2.4"),
52       "gosaLockEntry"         => array("version" => "2.4"),
53       "gosaCacheEntry"        => array("version" => "2.4"),
54       "gosaDepartment"        => array("version" => "2.4"),
56       "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
57       "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
58       "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
60       "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
61       "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
62       "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
63       "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
64       "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
66       "GOhard"                => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
67       "gotoTerminal"          => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
68       "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
69       "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
70       "goShareServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
71       "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
72       "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
73       "goLdapServer"          => array("version" => "2.4"),
74       "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
75       "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
76       "goKrbServer"           => array("version" => "2.4"),
77       "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
78       );
80   /* Get objectclasses */
81   $ldap = new LDAP($admin,$password, $server);
82   $objectclasses = $ldap->get_objectclasses(); 
83   if(count($objectclasses) == 0){
84     return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
85   }
87   /* Walk through objectclasses and check if they are needed or not */
88   foreach ($required_classes as $key => $value){
89     if (isset($value['class'])){
90       if (!is_array($value['class'])){
91         $classes= array($value['class']);
92       } else {
93         $classes= $value['class'];
94       }
96       /* Check if we are using the class that requires */
97       foreach($classes as $class){
98         if (!isset($objectclasses[$key])){
99           $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' is not present in LDAP setup"), $key, $class);
100           $messages[$key]['status'] = FALSE;
101         } else {
102           if (!check_schema_version($objectclasses[$key], $value['version'])){
103             $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' does not have version %s"), $key, $class, $value['version']);
104             $messages[$key]['needonstartup'] = TRUE;
105             $messages[$key]['status'] =FALSE;
106           }else {
107             if(!isset($affich2[$class])){
108               $affich2[$class]['msg']   = sprintf(_("Support for '%s' enabled"), $class)."<td class=\"check\"> ".$value['file']."</td>";
109               $affich2[$class]['status']= TRUE; 
110             }
111           }
112         }
114       }
115     } else {
116       /* Required class */
117       if (!isset($objectclasses[$key])){
118         $messages[$key]['msg']= sprintf(_("Required objectclass '%s' is not present in LDAP setup"), $key);
119         $messages[$key]['status'] = FALSE;  
120       } else {
121         if (!check_schema_version($objectclasses[$key], $value['version'])){
122           $messages[$key]['msg']= sprintf(_("Required objectclass '%s' does not have version %s"), $key, $value['version']);
123           $messages[$key]['status'] = FALSE;  
124           $messages[$key]['needonstartup'] = TRUE;
125         }
126     
127       }
128     }
129   }
131   /* Check for correct samba parameters */
132   if (!isset($objectclasses['sambaSamAccount'])){
133     $messages['samba3']['msg']= _("SAMBA 3 support disabled, no schema seems to be installed");
134     $affich['samba3']['msg']= $messages['samba3']['msg']."<td class=\"check\">gosa+samba3.schema</td>";
135     $messages['samba3']['status']= FALSE;
136     $affich['samba3']['status']= FALSE;
137   }else{
138     $affich['samba3']['msg']= _("SAMBA 3 support enabled")."<td class=\"check\">gosa+samba3.schema</td>";
139     $affich['samba3']['status']= TRUE;
140   }
142   if (!isset($objectclasses['sambaAccount'])){
143     $messages['samba2']['msg']= _("SAMBA 2 support disabled, no schema seems to be installed");
144     $affich['samba2']['msg']= $messages['samba2']['msg']."<td class=\"check\">samba.schema</td>";
145     $messages['samba2']['status']= FALSE;
146     $affich['samba2']['status']= FALSE;
147   }else{
148     $affich['samba2']['msg']= _("SAMBA 2 support enabled")."<td class=\"check\">samba.schema</td>";
149     $affich['samba2']['status']= TRUE;
150   }
152   /* Check pureftp/dns/ */
153   if (!isset($objectclasses['PureFTPdUser'])){
154     $messages['pureftp']['msg']= _("Support for pureftp disabled, no schema seems to be installed");
155     $affich['pureftp']['msg']= $messages['pureftp']['msg']."<td class=\"check\">pureftpd.schema</td>";
156     $messages['pureftp']['status']= FALSE;
157     $affich['pureftp']['status']= FALSE;
158   }else{
159     $affich['pureftp']['msg']= _("Support for pureftp enabled")."<td class=\"check\">pureftpd.schema</td>";
160     $affich['pureftp']['status']= TRUE;
161   }
163   if (!isset($objectclasses['gosaWebdavAccount'])){
164     $messages['webdav']['msg']= _("Support for WebDAV disabled, no schema seems to be installed");
165     $affich['webdav']['msg']= $messages['webdav']['msg']."<td class=\"check\"></td>";
166     $messages['webdav']['status']= FALSE;
167     $affich['webdav']['status']= FALSE;
168   }else{
169     $affich['webdav']['msg']=_("Support for WebDAV enabled")."<td class=\"check\">gosa+samba3.schema</td>";
170     $affich['webdav']['status']= TRUE;
171   }
173   if (!isset($objectclasses['phpgwAccount'])){
174     $messages['phpgroupware']['msg']= _("Support for phpgroupware disabled, no schema seems to be installed");
175     $affich['phpgroupware']['msg']= $messages['phpgroupware']['msg']."<td class=\"check\">phpgwaccount.schema</td>";
176     $messages['phpgroupware']['status']= FALSE;
177     $affich['phpgroupware']['status']= FALSE;
178   }else{
179     $affich['phpgroupware']['msg']= _("Support for phpgroupware enabled")."<td class=\"check\">phpgwaccount.schema</td>";
180     $affich['phpgroupware']['status']= TRUE;
181   }
182   
183   if (!isset($objectclasses['trustAccount'])){
184     $messages['trustAccount']['msg']= _("Support for trustAccount disabled, no schema seems to be installed");
185     $affich['trustAccount']['msg']= $messages['trustAccount']['msg']."<td class=\"check\">trust.schema</td>";
186     $messages['trustAccount']['status']= FALSE;
187     $affich['trustAccount']['status']= FALSE;
188   }else{
189     $affich['trustAccount']['msg']= _("Support for trustAccount enabled")."<td class=\"check\">trust.schema</td>";
190     $affich['trustAccount']['status']= TRUE;
191   }
193   if (!isset($objectclasses['goFonAccount'])){
194     $messages['phoneaccount']['msg']= _("Support for gofon disabled, no schema seems to be installed");
195     $affich['phoneaccount']['msg']= $messages['phoneaccount']['msg']."<td class=\"check\">gofon.schema</td>";
196     $messages['phoneaccount']['status']= FALSE;
197     $affich['phoneaccount']['status']= FALSE;
198   }else{
199     $affich['phoneaccount']['msg']= _("Support for gofon enabled")."<td class=\"check\">gofon.schema</td>";
200     $affich['phoneaccount']['status']= true;
201   }
203   if (!isset($objectclasses['nagiosContact'])){
204     $messages['nagioscontact']['msg']= _("Support for nagios disabled, no schema seems to be installed");
205     $affich['nagioscontact']['msg']= $messages['nagioscontact']['msg']."<td class=\"check\">nagios.schema</td>";
206     $messages['nagioscontact']['status']= FALSE;
207     $affich['nagioscontact']['status']= FALSE;
208   }else{
209     $affich['nagioscontact']['msg']= _("Support for nagios enabled")."<td class=\"check\">nagios.schema</td>";
210     $affich['nagioscontact']['status']= true;
211   }
212   
213   if ((!isset($objectclasses['apple-user'])) || (!isset($objectclasses['mount'])) ){
214     $messages['netatalk']['msg']= _("Support for netatalk disabled, no schema seems to be installed");
215     $affich['netatalk']['msg']= $messages['netatalk']['msg']."<td class=\"check\">apple.schema</td>";
216     $messages['netatalk']['status']= FALSE;
217     $affich['netatalk']['status']= FALSE;
218   }else{
219     $affich['netatalk']['msg']= _("Support for netatalk enabled")."<td class=\"check\">apple.schema</td>";
220     $affich['netatalk']['status']= true;
221   }
222   
223   /* Fix for PHP Fehler "Undefined index: ldapconf"
224    * Ablaufverfolgung[1]: Funktion schema_check Datei: /home/hickert/gosa/include/functions_setup.inc (Zeile 230)
225    */
226   if((isset($_SESSION['ldapconf']['mail_methods']))&&(isset($_SESSION['ldapconf']))){
227         if(($_SESSION['ldapconf']['mail_methods'][$_SESSION['ldapconf']['mail']] == "kolab")&&(!$CalledByIndexPhP)){
228           if(!isset($objectclasses['kolabInetOrgPerson']))  {
229             $messages['kolab']['msg']= _("Support for Kolab disabled, no schema seems to be installed, setting mail-method to cyrus");
230             $affich['kolab']['msg']=$messages['kolab']['msg']."<td class=\"check\">kolab2.schema</td>";
231             $tmp= array_flip($_SESSION['ldapconf']['mail_methods']);
232             $_SESSION['ldapconf']['mail']=$tmp['cyrus'];
233             $messages['kolab']['status']= FALSE;
234             $affich['kolab']['status']= FALSE;
235           }else{
236             $affich['kolab']['msg']=_("Support for Kolab enabled")."<td class=\"check\">gofon.schema</td>";
237             $affich['kolab']['status']= TRUE;
238           }
239         }
240   }
241   if($aff==0){
242     return ($messages);
243   } else {
244     return(array_merge($affich,$affich2));
245   }
249 function check(&$faults, $message, $description, $test, $required= TRUE)
251   $msg= "<table summary=\"\" class='check'><tr><td class='check' style='font-size:14px;'>$message</td>
252     <td rowspan=2 style='vertical-align:middle; text-align:center;width:45px;'>";
253   if ($test){
254     $msg.= _("OK")."<br>";
255   } else {
256     if (!$required){
257       $msg.="<font color=red>"._("Ignored")."</font><br>";
258     } else {
259       $msg.="<font color=red>"._("Failed")."</font><br>";
260       $faults++;
261     }
262   }
263   $msg.= "</td></tr><tr><td class='check' style='padding-left:20px;".
264     "background-color:#F0F0F0;'>$description</td></tr></table><br>";
266   return $msg;
269 function perform_php_checks(&$faults)
271   global $check_globals;
273   $faults= 0;
274   $msg= "";
276   $msg.= "<h1>"._("PHP setup inspection")."</h1>";
278   $msg.= check (        $faults, _("Checking for PHP version (>=4.1.0)"),
279       _("PHP must be of version 4.1.0 or above for some functions and known bugs in PHP language."),
280       version_compare(phpversion(), "4.1.0")>=0);
282   $msg.= check (        $faults, _("Checking if register_globals is set to 'off'"),
283       _("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."),
284       $check_globals == 0, FALSE);
285   
286   $msg.= check (  $faults, _("PHP session.gc_maxlifetime (>= 86400 seconds)."),
287       _("PHP uses this value for the garbage collector to delete old sessions, setting this value to one day will prevent loosing session and cookie  before they really timeout."),
288       ini_get("session.gc_maxlifetime") >= 86400,FALSE);
290   $msg.= check (        $faults, _("Checking for ldap module"),
291       _("This is the main module used by GOsa and therefore really required."),
292       is_callable('ldap_bind'));
294   $msg.= check (  $faults, _("Checking for XML functions"),
295       _("XML functions are required to parse the configuration file."),
296       is_callable('xml_parser_create'));
298   $msg.= check (        $faults, _("Checking for gettext support"),
299       _("Gettext support is required for internationalized GOsa."),
300       is_callable('bindtextdomain'));
302   $msg.= check (        $faults, _("Checking for iconv support"),
303       _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
304       is_callable('iconv'));
306   $msg.= check (        $faults, _("Checking for mhash module"),
307       _("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."),
308       is_callable('mhash'), FALSE);
310   $msg.= check (        $faults, _("Checking for imap module"),
311       _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
312       is_callable('imap_open'));
314   $msg.= check (        $faults, _("Checking for getacl in imap"),
315       _("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."),
316       is_callable('imap_getacl'), FALSE);
318   $msg.= check (        $faults, _("Checking for mysql module"),
319       _("MySQL support is needed for reading GOfax reports from databases."),
320       is_callable('mysql_query'), FALSE);
322   $msg.= check (        $faults, _("Checking for cups module"),
323       _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
324       is_callable('cups_get_dest_list'), FALSE);
326   $msg.= check (        $faults, _("Checking for kadm5 module"),
327       _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
328       is_callable('kadm5_init_with_password'), FALSE);
330   $msg.= check (  $faults, _("Checking for snmp Module"),
331       _("Simple Network Management Protocol (SNMP) is required for client monitoring."),
332       is_callable('snmpget'), FALSE);
334   return ($msg);
337 function get_link($function_name) {
338   $result= "<a href='http://de.php.net/manual/en/function.";
340   /* Replace all underscores with hyphens (phpdoc convention) */
341   $function_name= str_replace("_", "-", $function_name);
343   /* Append to base URL */
344   $result.= $function_name.".php'>$function_name</a>";
346   return $result;
349 function perform_additional_function_checks(&$faults) {
350   global $check_globals;
352   $faults= 0;
353   $msg= "";
354   $functions= array();
355   
356   $functions_list= '../include/functions_list.inc';
358   /* Make sure that we can read the file */
359   if(is_readable($functions_list)) {
360     /* Open filehandle */
361     $fh= fopen($functions_list,'rb');
362     if($fh!=null) {
363       $functions= eval(fread($fh,filesize($functions_list)));
364     }
365   }
367   $msg.= "<h1>"._("PHP detailed function inspection")."</h1>";
368   /* Only print message, if function is not callable */
369   foreach($functions as $key => $fn_name) {
370     if(!is_callable($fn_name)) {
371       $msg.= check ($faults, sprintf(_("Checking for function %s"), "<b>".get_link($fn_name)."</b>"),
372         sprintf(_("The function %s is used by GOsa. There is no information if it's optional or required yet."), "<b>".get_link($fn_name)."</b>"),
373         is_callable($fn_name), false);
374     }
375   }
376   return $msg;
379 function perform_additional_checks(&$faults)
381   $ret = NULL;
382   /* Programm check */
383   $msg= "<h1>"._("Checking for some additional programms")."</h1>";
385   /* Image Magick */
386   $query= "LC_ALL=C LANG=C convert -help";
387   $output= shell_exec ($query);
388   if ($output != ""){
389     $lines= split ("\n", $output);
390     $version= preg_replace ("/^Version:.+Magick ([^\s]+).*/", "\\1", $lines[0]);
391     list($major, $minor)= split("\.", $version);
392     $msg.= check (      $faults, _("Checking for ImageMagick (>=5.4.0)"),
393         _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
394         ($major > 5 || ($major == 5 && $minor >= 4)));
395   } else {
396     $msg.= check (      $faults, _("Checking imagick module for PHP"),
397         _("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);
398   }
400   /* Check for fping */
401   $query= "LC_ALL=C LANG=C fping -v 2>&1";
402   $output= shell_exec ($query);
403   $have_fping= preg_match("/^fping:/", $output);
404   $msg.= check (        $faults, _("Checking for fping utility"),
405       _("The fping utility is only used if you've got a thin client based terminal environment running."),
406       $have_fping, FALSE);
408   /* Check for smb hash generation tool */
409   $query= "mkntpwd 2>&1";
410   $output= shell_exec ($query);
411   $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
412   $alt = 0;
414   if (!$have_mkntpwd){
415     $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
416     system ($query, $ret);
417     $alt= ($ret == 0);
418   }
420   $msg.= check (        $faults, _("Checking for a way to generate LM/NT password hashes"),
421       _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
422       ($have_mkntpwd || $alt));
424   /* seesio.auto_start should be off, in order to without trouble*/
425   $session_auto_start = ini_get('session.auto_start');
426   $implicit_flush     = ini_get('implicit_flush');
427   $max_execution_time = ini_get('max_execution_time');
428   $memory_limit       = ini_get('memory_limit');
429   $expose_php         = ini_get('expose_php');
430   $magic_quotes_gpc   = ini_get('magic_quotes_gpc');
431   $register_globals   = ini_get('register_globals');
433   /* auto_register */
434   $msg.= check (  $faults, _("php.ini check -> session.auto_register"),
435       _("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']));
437   /* implicit_flush */
438   $msg.= check (  $faults, _("php.ini check -> implicit_flush"),
439       _("This option influences the Output handling. Turn this Option off, to increase performance."),
440       !$implicit_flush['local_value'],0,false);
442   /* max_execution_time */
443   if($max_execution_time['local_value'] < 30 ){
444     $max_execution_time['local_value']=false;
445   }
446   $msg.= check (  $faults, _("php.ini check -> max_execution_time"),
447       _("The Execution time should be at least 30 seconds, because some actions may consume more time."),
448       $max_execution_time['local_value'],0,false);
450   /* memory_limit */
451   if($memory_limit['local_value'] < 16 ){
452     $memory_limit['local_value']=false;
453   }
454   $msg.= check (  $faults, _("php.ini check -> memory_limit"),
455       _("GOsa needs at least 16MB of memory, less will cause unpredictable errors! Increase it for larger setups."),
456       !$implicit_flush['local_value'],0,false);
458   /* expose_php */
459   $msg.= check (  $faults, _("php.ini check -> expose_php"),
460       _("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."),
461       !$implicit_flush['local_value'],0,false);
463   /* magic_quotes_gpc */
464   $msg.= check (  $faults, _("php.ini check -> magic_quotes_gpc"),
465       _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."),
466       $magic_quotes_gpc['local_value'],0,false);
468   return $msg;
472 function parse_contrib_conf()
475   $str                = "";
476   $used_samba_version = 0;
477   $query              = ""; 
478   $fp                 = false;
479   $output             = "";
480   $needridbase_sid    = false;
481   $pwdhash            = "";
482   $replacements       = array();
483   $ldapconf           = $_SESSION['ldapconf']; // The Installation information
484   $classes            = $_SESSION['classes'];  // Class information needed to define which features are enabled
485   $possible_plugins   = array();
487   /* Which samba version do we use? */
488   if(isset($classes['samba3'])){
489     $used_samba_version = 2;
490   } else {
491     $used_samba_version = 3;
492   }
494   /* Look for samba password generation method */
495   if(file_exists("/usr/bin/mkntpasswd")){
496     $pwdhash  = "/usr/bin/mkntpasswd";
497   } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
498     $pwdhash= "mkntpwd";
499   } else {
500     $pwdhash=('perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
501   }
504   /* Define which variables will be replaced */
505   $replacements['{LOCATIONNAME}']  = $ldapconf['location'];
506   $replacements['{SAMBAVERSION}']  = $used_samba_version;
507   $replacements['{LDAPBASE}']      = $ldapconf['base'];
508   $replacements['{LDAPADMIN}']     = $ldapconf['admin'];
509   $replacements['{UIDBASE}']       = $ldapconf['uidbase'];
510   $replacements['{DNMODE}']        = $ldapconf['peopledn'];
511   $replacements['{LDAPHOST}']      = $ldapconf['uri'];
512   $replacements['{PASSWORD}']      = $ldapconf['password'];
513   $replacements['{CRYPT}']         = $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
514   $replacements['{SID}']         = "";
515   $replacements['{RIDBASE}']     = "";
516   if($ldapconf['mail'] != "disabled"){
517     $replacements['{MAILMETHOD}']    = $ldapconf['mail_methods'][$ldapconf['mail']];
518   }   
519   $replacements['{SMBHASH}']       = $pwdhash;
520   $replacements['{GOVERNMENTMODE}']= "false"; 
521   $replacements['{kolabAccount}']  = "";
522   $replacements['{servKolab}']     = "";
523   $replacements['{errorlvl}']     = $ldapconf['errorlvl'];
525   /* This array contains all preg_replace syntax to delete all unused plugins
526      THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes'] */
528   $possible_plugins['fonreport'][]   = "'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
529   $possible_plugins['phoneaccount'][]= "'\n.*<tab.*phoneAccount.*>.*\n'i";
530   $possible_plugins['logview'][]     = "'\n.*<plugin.*logview+.*\n.*>.*\n'i";
531   $possible_plugins['pureftp'][]     = "'\n.*<tab.*pureftp.*>.*\n'i";
532   $possible_plugins['webdav'][]      = "'\n.*<tab.*webdav.*>.*\n'i";
533   $possible_plugins['phpgroupware'][]= "'\n.*<tab.*phpgroupware.*>.*\n'i";
534   $possible_plugins['netatalk'][0]    = "'\n.*<plugin.*netatalk+.*\n.*>.*\n'i";
535   $possible_plugins['netatalk'][1]    = "'\n.*<tab.*netatalk.*>.*\n'i";
537   /*Header information
538      Needed to send the generated gosa.conf to the browser */
539   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
540   header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
541   header("Cache-Control: no-cache");
542   header("Pragma: no-cache");
543   header("Cache-Control: post-check=0, pre-check=0");
544   header("Content-type: text/plain");
546   if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
547       preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
548     header('Content-Disposition: filename="gosa.conf"');
549   } else {
550     header('Content-Disposition: attachment; filename="gosa.conf"');
551   }
553   if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r")) {
554     echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
555   } else {
556     while(!feof($fp)) {
557       $str.= fread($fp,512);
558     }
560     if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab") {
561       $replacements['{kolabAccount}']  ="<tab class=\"kolabAccount\" />\n     ";
562       $replacements['{servKolab}']     ="<tab class=\"servkolab\" name=\"Kolab\" />";
563     }
565     if($used_samba_version == 2) {
566       /* Do nothing for samba 2... */
567     } else {
568       /* Create LDAP connection, to check if there's a domain
569          object defined in the LDAP schema */
570       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
572       /* Try to find a Samba Domain Objekt */
573       $ldap->search("(objectClass=sambaDomain)");
574     
575       /* Something found ??? so we need to define ridbase an SID by ourselfs */
576       if($ldap->count()< 1) {
577         $replacements['{SID}']= "sid=\"123412-11\"";
578         $replacements['{RIDBASE}']= "ridbase=\"1000\"";  
579       } 
580     }
582     /* Data readed, types replaced, samba version detected and checked if
583        we need to add SID and RIDBASE. Check if there is an ivbbentry in
584        the LDAP tree, in this case we will set the governmentmode to true.
585        Create LDAP connection, to check if theres a domain Objekt definen
586        in the LDAP schema. */
587     if(!isset($ldap)){
588       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
589     }
591     /* Try to find a Samba Domain Objekt */
592     $ldap->search("(objectClass=ivbbentry)");
594     /* Something found ??? so we need to define ridbase an SID by ourselfs */
595     if($ldap->count()> 0) {
596       $replacements['{GOVERNMENTMODE}']= "true";
597     }
599     /* Replace all colleted information with placeholder */
600     foreach($replacements as $key => $val) {
601       $str = preg_replace("/".$key."/",$val,$str);
602     }    
604     if($ldapconf['mail'] == "disabled"){
605       $str = str_replace("mailMethod=\"{MAILMETHOD}\"","",$str);
606     }
608     /* Remove all unused plugins */
609     foreach(array_keys($possible_plugins) as $akey) {
610       if(array_key_exists($akey,$classes)) {
611         foreach($possible_plugins[$akey] as $key=>$val) {
612           $str = preg_replace($val,"\n",$str);
613         }
614       }
615     }
616   }
618   return ((($str)));
622 /* Show setup_page 1 */
623 function show_setup_page1($withoutput = true)
625   $faults   = false;
626   $faults2  = false;
627   $smarty = get_smarty();  
628   $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
629   $smarty->assign ("tests", perform_php_checks($faults));
630   $smarty->assign ("detailed_tests", perform_additional_function_checks($faults2));
632   $faults = $faults || $faults2;
634   /* This var is true if anything went wrong */
635   if ($faults){
636     $smarty->assign("mode", "disabled");
637   }
639   /* This line displays the template only if (withoutput is set) */
640   if($withoutput){
641     $smarty->display (get_template_path('headers.tpl'));
642   }
644   if (isset($_SESSION['errors'])){
645     $smarty->assign("errors", $_SESSION['errors']);
646   }
648   if($withoutput){
649     $smarty->display (get_template_path('setup.tpl'));
650   }
652   return ($faults);
656 /* Show setup_page 2 */
657 function show_setup_page2($withoutput = true)
659   $faults = false;
660   $smarty = get_smarty();
661   $smarty->assign ("content", get_template_path('setup_step2.tpl'));
662   $smarty->assign ("tests", perform_additional_checks($faults));
664   if ($faults) {
665     $smarty->assign("mode", "disabled");
666   }
667   if($withoutput){
668     $smarty->display (get_template_path('headers.tpl'));
669   }
670   if (isset($_SESSION['errors']))  {
671     $smarty->assign("errors", $_SESSION['errors']);
672   }
673   if($withoutput){
674     $smarty->display (get_template_path('setup.tpl'));
675   }
677   return ($faults);                               
681 function show_setup_page3($withoutput = true)
683   $ds = NULL;
684   $smarty = get_smarty();
686   /* Take the Post oder the Sessioin saved data */
687   if(isset($_POST['uri'])){
688     $uri = $_POST['uri'];
689   } elseif(isset($_SESSION['ldapconf']['uri'])){
690     $uri = $_SESSION['ldapconf']['uri'];
691   }
693   /* If Page called first time, field is empty */
694   if((!isset($uri))||(empty($uri))){
695     $uri = "ldap://localhost:389";
696   }
698   /* if isset $uri save it to session */
699   if(isset($uri)) {
700     $_SESSION['ldapconf']['uri'] = $uri;
701     $smarty->assign ("uri", validate($uri));
702   }
704   /* No error till now */
705   $fault = false;
707   if (!$ds = @ldap_connect (validate($uri))) {
708     $fault =true;
710     /* Output the Error */
711     if($withoutput) {
712       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
713       $smarty->assign ("uri", validate($uri));
714       $smarty->assign ("content", get_template_path('setup_step3.tpl'));
715     }
716   } else {
717     /* Try to bind the connection */    
718     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
720     /* if we can't bind , print error */
721     if (!$r  =  @ldap_bind ($ds)) {
722       $fault = true;
724       /* Output the Error */
725       if($withoutput) {
726         print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
727         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
728         $smarty->assign ("uri", validate($uri));
729       }
730     } else {
731       $fault = false;
732     }
733   }
735   $smarty->assign ("content", get_template_path('setup_step3.tpl'));
737   /* Load Header */
738   if($withoutput){
739     $smarty->display (get_template_path('headers.tpl'));
740   }
742   /* Set Errors to Smarty */
743   if (isset($_SESSION['errors'])) {
744     $smarty->assign("errors", $_SESSION['errors']);
745   }
747   /* Print out Template */ 
748   if($withoutput){
749     $smarty->display (get_template_path('setup.tpl'));
750   }
752   return ($fault);                             
756 function show_setup_page4($withoutput = true)
758   $smarty= get_smarty();      
760   /* check POST data */
761   if(isset($_POST['check'])) {
763     /* Check if all needed vars are submitted */
764     foreach($checkvars as $key) {
765       if($key == "peopleou"){
766         continue;
767       }
768       if($key == "groupou"){
769         continue;
770       }
772       if((isset($_POST[$key]))&&($_POST[$key]!="")) {
773         $_SESSION['ldapconf'][$key] = $_POST[$key];
774       } else {
775         if($withoutput) {
776           print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
777         }
778         $fault = true;
779       }
780     }
781   }
783   /* Transfer base */
784   if(isset($_POST['base'])){
785     $_SESSION['ldapconf']['base']= $_POST['base'];
786   }
788         // ?
789   if(!isset($_SESSION['ldapconf']['base'])){
790     $_SESSION['ldapconf']['base']= $base;
791   }
793   if(!isset($_SESSION['ldapconf']['base'])){
794     $_SESSION['ldapconf']['base']= $base;
795   }
796   require_once("class_password-methods.inc");
798   $fault     = false;              
799   $uri       = $_SESSION['ldapconf']['uri'];
800   $ldapconf  = $_SESSION['ldapconf'];
801   $arr_crypts= array();
802   $temp      = "";
803   $checkvars = array("location", "admin", "password", "peopleou", "base",
804       "peopledn", "arr_crypts", "mail", "uidbase","errorlvl");
806   if(!isset($_SESSION['ldapconf']['arr_cryptkeys'])) {
807     require_once("class_password-methods.inc");
808     $tmp= passwordMethod::get_available_methods_if_not_loaded();
809     $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
810   }
812   if(!isset($_SESSION['ldapconf']['mail_methods'])) {
813     $_SESSION['ldapconf']['mail_methods']=array();
814     $temp = get_available_mail_classes();
815     $_SESSION['ldapconf']['mail_methods']= $temp['name'];
816   }
818   /* If there are some empty vars in ldapconnect -
819      these values also represent out default values */
820   if(!$ds =  @ldap_connect (validate($uri))){
821     $fault = true;
822     if($withoutput){
823       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
824     }
825   } elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
826     $fault = true;
827     if($withoutput){
828       print_red (_("Can't set ldap protocol version 3."));
829     }
830   } elseif(!$r= @ldap_bind ($ds)){
831     $fault = true;
832     if($withoutput){
833       print_red (_("Could not bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
834     }
835   } else {
836     $sr=   @ldap_search ($r, NULL, "objectClass=*", array("namingContexts"));
837     $attr= @ldap_get_entries($ds,$sr);
839     if((empty($attr))) {
841       if($withoutput){
842 #        print_red(_("Bind to server successful, but the server seems to be completly empty, please check all information twice"));
843       }
845     } else {
846       $base= $attr[0]['dn'];
847     }
848   }
850   if(!isset($_SESSION['ldapconf']['base'])){
851     $_SESSION['ldapconf']['base']= $base;
852   }
853   if(!isset($_SESSION['ldapconf']['admin'])){
854     $_SESSION['ldapconf']['admin']= "cn=ldapadmin,".$base;
855   }
856   if(!isset($_SESSION['ldapconf']['peopleou'])){
857     $_SESSION['ldapconf']['peopleou']= "ou=people";
858   }
859   if(!isset($_SESSION['ldapconf']['groupou'])){
860     $_SESSION['ldapconf']['groupou']= "ou=groups";
861   }
862   if(!isset($_SESSION['ldapconf']['peopledn'])){
863     $_SESSION['ldapconf']['peopledn']= "cn";
864   }
865   if(!isset($_SESSION['ldapconf']['password'])){
866     $_SESSION['ldapconf']['password']= "";
867   }
868   if(!isset($_SESSION['ldapconf']['location'])){
869     $_SESSION['ldapconf']['location']= "Example";
870   }
871   if(!isset($_SESSION['ldapconf']['uidbase'])){
872     $_SESSION['ldapconf']['uidbase']= "1000";
873   }
874   if(!isset($_SESSION['ldapconf']['mail'])){
875     $_SESSION['ldapconf']['mail']= 0;
876   }
877   $tmp= array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
878   if(!isset($_SESSION['ldapconf']['arr_crypts'])){
879     $_SESSION['ldapconf']['arr_crypts']   = $tmp['md5'];
880   }
882   $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
883   $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
885   foreach($_SESSION['ldapconf'] as $key => $val) {
886     $smarty->assign($key,$val);
887   }
889   if(isset($_POST['check']) || (isset($_POST['admin'])) && isset($_POST['password'])) {
890     $ldap= new LDAP($_SESSION['ldapconf']['admin'],
891         $_SESSION['ldapconf']['password'],
892         $_SESSION['ldapconf']['uri']);
894     $m= schema_check($_SESSION['ldapconf']['uri'],
895         $_SESSION['ldapconf']['admin'],
896         $_SESSION['ldapconf']['password']);
897     $_SESSION['classes']= $m;
899     if(!is_schema_readable($ldapconf['uri'],$ldapconf['admin'],$ldapconf['password'])){
900       if($withoutput){
901         print_red(_("Can't read schema informations, GOsa needs to know your schema setup. Please verify that it is readable for GOsa"));
902       }
903       $fault=true;
904     }
908     if ($ldap->error != "Success") {
909       if($withoutput) {
910         print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
911       }
912       $fault = true;
913     }
914   }
916   /* Set smarty output */
917   $smarty->assign ("content", get_template_path('setup_step4.tpl'));
918   $smarty->assign ("peopledns", array("cn", "uid"));
919   if($withoutput){
920     $smarty->display (get_template_path('headers.tpl'));
921   }
922   if(isset($_SESSION['errors'])) {
923     $smarty->assign("errors", $_SESSION['errors']);
924   }
925   if($withoutput){
926     $smarty->display (get_template_path('setup.tpl'));
927   }
929   return ($fault);
933 function show_setup_page5($withoutput=true)
935   /* Get ldapconf */
936   $ldapconf= $_SESSION['ldapconf'];
938   /* get smarty */
939   $smarty = get_smarty();
941   if(isset($_SESSION['classes'])){
942     $classes = $_SESSION['classes'];
943   }
945   $info= posix_getgrgid(posix_getgid());
946   $smarty->assign("webgroup", $info['name']);
947   $smarty->assign("path", CONFIG_DIR);
948   $message= "<table summary=\"\" class=\"check\">";
949   $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
951   if($withoutput) {
952     $smarty->assign ("schemas", view_schema_check($m));
953     $smarty->assign ("content", get_template_path('setup_finish.tpl'));
954   }
956   /* Output templates... */
957   if($withoutput){
958     $smarty->display (get_template_path('headers.tpl'));
959   }
960   if (isset($_SESSION['errors'])) {
961     $smarty->assign("errors", $_SESSION['errors']);
962   }
963   if($withoutput){
964     $smarty->display (get_template_path('setup.tpl'));
965   }
967   return(true);
971 function create_user_for_setup($withoutput=true)
973   global $samba;
975   $ldapconf = $_SESSION['ldapconf'];
976   $smarty = get_smarty();
977   
978   $need_to_create_group = false;
979   $need_to_create_user  = false;
981   $str_there="";
983   if(isset($_SESSION['classes'])){
984     $classes= $_SESSION['classes'];
985   }
987   /* Everything runns perfect ...
988      So we do a last test on this page
989      is there a user with ACLs :all which will be able to adminsitrate GOsa
990      We check that, if this user or group is missing we ask for creating them */
991   $ldap= new LDAP($_SESSION['ldapconf']['admin'],    $_SESSION['ldapconf']['password'],   $_SESSION['ldapconf']['uri']);
993   /* 
994   Now we are testing for a group, with the rights :all 
995   */
996   
997   $ldap->cd($ldapconf['base']);
998   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
1000   $group_cnt  = $ldap->count();
1001   $data       = $ldap->fetch();
1003 //  $str_there  = "Searching for Aminitrative users <br><br>";
1005   /* 
1006   We need to create administrative user and group  because theres no group found 
1007   */
1008   if($group_cnt < 1) {
1009     
1010     /* 
1011     Set var to create user 
1012     */
1013 //    $str_there  =   "no group found<br>";
1015     $need_to_create_group = true;
1016     $need_to_create_user  = true;
1019     /* Output error */
1020     if(($withoutput)&&(!isset($_POST['new_admin']))){
1021       print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1022     }
1023   } else {
1024     
1025 //    $str_there = "Group found <br>".$data['dn'];    
1027     $need_to_create_group = false;
1028  
1029     $ldap->clearResult();
1030    
1031     /* We found an Administrative Group, is there a user, too */
1032     if(isset($data['memberUid'][0])) {
1033       $str = "uid=".$data['memberUid']['0'];
1034       $ldap->search("(&(objectClass=gosaAccount)(objectClass=person)(".$str."))");
1035       $data2   = $ldap->fetch();
1036   
1037       /* We must create a user */
1038       if (($ldap->count() < 1)||(!isset($data2))) {
1039 //        $str_there.="Missing user";
1040         
1041         $need_to_create_user = true;
1042       
1043         if(($withoutput)&&(!isset($_POST['new_admin']))){
1044           print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1045         }
1046       }else {
1047 //        $str_there.="<br>User found <br>".$data2['dn'];
1048         $need_to_create_user = false;
1049       }
1050     } else {
1051       $need_to_create_user=true;
1052       if(($withoutput)&&(!isset($_POST['new_admin']))){
1053           print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1054         }   
1055 //      $str_there.="<br>No User found <br>";
1056     }
1057   }
1059   if(!($need_to_create_user&&$need_to_create_group))
1060     return(true);
1062   /* We need to create a new user with group */
1063   if(isset($_POST['new_admin']))
1064   {
1065   
1066     /* Adjust password attributes according to the samba version */
1067     if (isset($classes['samba3'])) {
1068       $samba= "2";
1069       $lmPassword = "lmPassword";
1070       $ntPassword = "ntPassword";
1071     } else {
1072       $samba= "3";
1073       $lmPassword = "sambaLMPassword";
1074       $ntPassword = "sambaNtPassword";
1075     }
1077     /* Nothing submitted */
1078     if(((empty($_POST['admin_name']))||(empty($_POST['admin_pass'])))) {
1079       return(true);
1080     }
1082     if($need_to_create_user) {
1083       /* We have the order to create an Admin */
1084       /* Define the user we are going to create */
1085       $dn= "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1086       $arr['objectClass'][0] ="person";
1087       $arr['objectClass'][1] ="organizationalPerson";
1088       $arr['objectClass'][2] ="inetOrgPerson";
1089       $arr['objectClass'][3] ="gosaAccount";
1090       $arr['uid']            = $_POST['admin_name'];
1091       $arr['cn']             = $_POST['admin_name'];
1092       $arr['sn']             = $_POST['admin_name'];
1093       $arr['givenName']      = "GOsa main administrator";
1094       $arr[$lmPassword]      = "10974C6EFC0AEE1917306D272A9441BB";
1095       $arr[$ntPassword]      = "38F3951141D0F71A039CFA9D1EC06378";
1096       $arr['userPassword']   = crypt_single($_POST['admin_pass'],"md5");
1097     
1099       if(!$ldap->dn_exists($dn)){ 
1100         $ldap->cd($dn); 
1101         $ldap->create_missing_trees($dn);
1102         $ldap->cd($dn);
1103         $ldap->add($arr);
1104         if($ldap->error!="Success"){
1105           print_red($ldap->error);
1106           print_red("Can't create user, and / or Group, possibly this problem  depends on an empty LDAP server. Check your configuration and try again!");
1107         }
1108       }    
1109     }
1111     /* There's already a group for administrator, so we only need to add the user */
1112     if(!$need_to_create_group) {
1113       if(!isset($data['memberUid'])) {
1114         $arrr['memberUid']= $_POST['admin_name'];
1115       } else {
1116         $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1117         $arrr['memberUid'] = $data['memberUid'];
1118         unset($arrr['memberUid']['count']);
1119   
1120         $tmp = array_reverse($arrr['memberUid']);    
1121         foreach($tmp as $tt){
1122           $tmp2[]=$tt;
1123         }
1124         $arrr['memberUid']= $tmp2;
1125 //        $str_there="Group found<br>".$data['dn'];
1126       }
1128       $ldap->cd($data['dn']);
1129       $ldap->modify($arrr);
1131     } else {
1132       $dn                    = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1133       $arrr['objectClass'][0]= "gosaObject";
1134       $arrr['objectClass'][1]= "posixGroup";
1135       $arrr['gosaSubtreeACL']= ":all";
1136       $arrr['cn']            = "administrators";
1137       $arrr['gidNumber']     = "999";
1138       $arrr['memberUid']     = $_POST['admin_name'];
1140       $ldap->cd($dn);
1141       $ldap->create_missing_trees($dn);
1142       $ldap->cd($dn);
1144       $ldap->add($arrr);
1145     }
1146     return(true);
1147   } else {
1149     if((!isset($create_user))||(!($create_user))) {
1150       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1151       $smarty->assign("exists",true);
1152     } else {
1153       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1154       $smarty->assign("exists",false);
1155     }
1157   }
1159   /* Smarty output */ 
1160   if($withoutput){
1161     $smarty->display (get_template_path('headers.tpl'));
1162   }
1163   if (isset($_SESSION['errors'])) {
1164     $smarty->assign("errors", $_SESSION['errors']);
1165   }
1166   $smarty->assign("str_there",$str_there);
1167   if($withoutput){
1168     $smarty->display (get_template_path('setup.tpl'));
1169   }
1170   return(false);
1174 /* Returns the classnames auf the mail classes */
1175 function get_available_mail_classes()
1177   $dir = opendir( "../include");
1178   $methods = array();
1179   $suffix = "class_mail-methods-";
1180   $lensuf = strlen($suffix);
1181   $prefix = ".inc";
1182   $lenpre = strlen($prefix);
1184   $i = 0;
1185   while (($file = readdir($dir)) !== false){
1187     if(stristr($file,$suffix)) {
1188       $lenfile = strlen($file);
1189       $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1190       $methods['file'][$i] = $file;
1191       $methods[$i]['file'] = $file;
1192       $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1193       $i++;
1194     }
1196   }
1198   return($methods);
1201 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1202 ?>