Code

8c19f8fa25c663d929fc843258029e0d708fd254
[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   $smarty = get_smarty();  
627   $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
628   $smarty->assign ("tests", perform_php_checks($faults));
629   $smarty->assign ("detailed_tests", perform_additional_function_checks($faults));
631   /* This var is true if anything went wrong */
632   if ($faults){
633     $smarty->assign("mode", "disabled");
634   }
636   /* This line displays the template only if (withoutput is set) */
637   if($withoutput){
638     $smarty->display (get_template_path('headers.tpl'));
639   }
641   if (isset($_SESSION['errors'])){
642     $smarty->assign("errors", $_SESSION['errors']);
643   }
645   if($withoutput){
646     $smarty->display (get_template_path('setup.tpl'));
647   }
649   return ($faults);
653 /* Show setup_page 2 */
654 function show_setup_page2($withoutput = true)
656   $faults = array();
657   $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   }
667   if (isset($_SESSION['errors']))  {
668     $smarty->assign("errors", $_SESSION['errors']);
669   }
670   if($withoutput){
671     $smarty->display (get_template_path('setup.tpl'));
672   }
674   return ($faults);                               
678 function show_setup_page3($withoutput = true)
680   $ds = NULL;
681   $smarty = get_smarty();
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'];
688   }
690   /* If Page called first time, field is empty */
691   if((!isset($uri))||(empty($uri))){
692     $uri = "ldap://localhost:389";
693   }
695   /* if isset $uri save it to session */
696   if(isset($uri)) {
697     $_SESSION['ldapconf']['uri'] = $uri;
698     $smarty->assign ("uri", validate($uri));
699   }
701   /* No error till now */
702   $fault = false;
704   if (!$ds = @ldap_connect (validate($uri))) {
705     $fault =true;
707     /* Output the Error */
708     if($withoutput) {
709       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
710       $smarty->assign ("uri", validate($uri));
711       $smarty->assign ("content", get_template_path('setup_step3.tpl'));
712     }
713   } else {
714     /* Try to bind the connection */    
715     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
717     /* if we can't bind , print error */
718     if (!$r  =  @ldap_bind ($ds)) {
719       $fault = true;
721       /* Output the Error */
722       if($withoutput) {
723         print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
724         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
725         $smarty->assign ("uri", validate($uri));
726       }
727     } else {
728       $fault = false;
729     }
730   }
732   $smarty->assign ("content", get_template_path('setup_step3.tpl'));
734   /* Load Header */
735   if($withoutput){
736     $smarty->display (get_template_path('headers.tpl'));
737   }
739   /* Set Errors to Smarty */
740   if (isset($_SESSION['errors'])) {
741     $smarty->assign("errors", $_SESSION['errors']);
742   }
744   /* Print out Template */ 
745   if($withoutput){
746     $smarty->display (get_template_path('setup.tpl'));
747   }
749   return ($fault);                             
753 function show_setup_page4($withoutput = true)
755   $smarty= get_smarty();      
757   /* check POST data */
758   if(isset($_POST['check'])) {
760     /* Check if all needed vars are submitted */
761     foreach($checkvars as $key) {
762       if($key == "peopleou"){
763         continue;
764       }
765       if($key == "groupou"){
766         continue;
767       }
769       if((isset($_POST[$key]))&&($_POST[$key]!="")) {
770         $_SESSION['ldapconf'][$key] = $_POST[$key];
771       } else {
772         if($withoutput) {
773           print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
774         }
775         $fault = true;
776       }
777     }
778   }
780   /* Transfer base */
781   if(isset($_POST['base'])){
782     $_SESSION['ldapconf']['base']= $_POST['base'];
783   }
785         // ?
786   if(!isset($_SESSION['ldapconf']['base'])){
787     $_SESSION['ldapconf']['base']= $base;
788   }
790   if(!isset($_SESSION['ldapconf']['base'])){
791     $_SESSION['ldapconf']['base']= $base;
792   }
793   require_once("class_password-methods.inc");
795   $fault     = false;              
796   $uri       = $_SESSION['ldapconf']['uri'];
797   $ldapconf  = $_SESSION['ldapconf'];
798   $arr_crypts= array();
799   $temp      = "";
800   $checkvars = array("location", "admin", "password", "peopleou", "base",
801       "peopledn", "arr_crypts", "mail", "uidbase","errorlvl");
803   if(!isset($_SESSION['ldapconf']['arr_cryptkeys'])) {
804     require_once("class_password-methods.inc");
805     $tmp= passwordMethod::get_available_methods_if_not_loaded();
806     $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
807   }
809   if(!isset($_SESSION['ldapconf']['mail_methods'])) {
810     $_SESSION['ldapconf']['mail_methods']=array();
811     $temp = get_available_mail_classes();
812     $_SESSION['ldapconf']['mail_methods']= $temp['name'];
813   }
815   /* If there are some empty vars in ldapconnect -
816      these values also represent out default values */
817   if(!$ds =  @ldap_connect (validate($uri))){
818     $fault = true;
819     if($withoutput){
820       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
821     }
822   } elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
823     $fault = true;
824     if($withoutput){
825       print_red (_("Can't set ldap protocol version 3."));
826     }
827   } elseif(!$r= @ldap_bind ($ds)){
828     $fault = true;
829     if($withoutput){
830       print_red (_("Could not bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
831     }
832   } else {
833     $sr=   @ldap_search ($r, NULL, "objectClass=*", array("namingContexts"));
834     $attr= @ldap_get_entries($ds,$sr);
836     if((empty($attr))) {
838       if($withoutput){
839 #        print_red(_("Bind to server successful, but the server seems to be completly empty, please check all information twice"));
840       }
842     } else {
843       $base= $attr[0]['dn'];
844     }
845   }
847   if(!isset($_SESSION['ldapconf']['base'])){
848     $_SESSION['ldapconf']['base']= $base;
849   }
850   if(!isset($_SESSION['ldapconf']['admin'])){
851     $_SESSION['ldapconf']['admin']= "cn=ldapadmin,".$base;
852   }
853   if(!isset($_SESSION['ldapconf']['peopleou'])){
854     $_SESSION['ldapconf']['peopleou']= "ou=people";
855   }
856   if(!isset($_SESSION['ldapconf']['groupou'])){
857     $_SESSION['ldapconf']['groupou']= "ou=groups";
858   }
859   if(!isset($_SESSION['ldapconf']['peopledn'])){
860     $_SESSION['ldapconf']['peopledn']= "cn";
861   }
862   if(!isset($_SESSION['ldapconf']['password'])){
863     $_SESSION['ldapconf']['password']= "";
864   }
865   if(!isset($_SESSION['ldapconf']['location'])){
866     $_SESSION['ldapconf']['location']= "Example";
867   }
868   if(!isset($_SESSION['ldapconf']['uidbase'])){
869     $_SESSION['ldapconf']['uidbase']= "1000";
870   }
871   if(!isset($_SESSION['ldapconf']['mail'])){
872     $_SESSION['ldapconf']['mail']= 0;
873   }
874   $tmp= array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
875   if(!isset($_SESSION['ldapconf']['arr_crypts'])){
876     $_SESSION['ldapconf']['arr_crypts']   = $tmp['md5'];
877   }
879   $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
880   $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
882   foreach($_SESSION['ldapconf'] as $key => $val) {
883     $smarty->assign($key,$val);
884   }
886   if(isset($_POST['check']) || (isset($_POST['admin'])) && isset($_POST['password'])) {
887     $ldap= new LDAP($_SESSION['ldapconf']['admin'],
888         $_SESSION['ldapconf']['password'],
889         $_SESSION['ldapconf']['uri']);
891     $m= schema_check($_SESSION['ldapconf']['uri'],
892         $_SESSION['ldapconf']['admin'],
893         $_SESSION['ldapconf']['password']);
894     $_SESSION['classes']= $m;
896     if(!is_schema_readable($ldapconf['uri'],$ldapconf['admin'],$ldapconf['password'])){
897       if($withoutput){
898         print_red(_("Can't read schema informations, GOsa needs to know your schema setup. Please verify that it is readable for GOsa"));
899       }
900       $fault=true;
901     }
905     if ($ldap->error != "Success") {
906       if($withoutput) {
907         print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
908       }
909       $fault = true;
910     }
911   }
913   /* Set smarty output */
914   $smarty->assign ("content", get_template_path('setup_step4.tpl'));
915   $smarty->assign ("peopledns", array("cn", "uid"));
916   if($withoutput){
917     $smarty->display (get_template_path('headers.tpl'));
918   }
919   if(isset($_SESSION['errors'])) {
920     $smarty->assign("errors", $_SESSION['errors']);
921   }
922   if($withoutput){
923     $smarty->display (get_template_path('setup.tpl'));
924   }
926   return ($fault);
930 function show_setup_page5($withoutput=true)
932   /* Get ldapconf */
933   $ldapconf= $_SESSION['ldapconf'];
935   /* get smarty */
936   $smarty = get_smarty();
938   if(isset($_SESSION['classes'])){
939     $classes = $_SESSION['classes'];
940   }
942   $info= posix_getgrgid(posix_getgid());
943   $smarty->assign("webgroup", $info['name']);
944   $smarty->assign("path", CONFIG_DIR);
945   $message= "<table summary=\"\" class=\"check\">";
946   $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
948   if($withoutput) {
949     $smarty->assign ("schemas", view_schema_check($m));
950     $smarty->assign ("content", get_template_path('setup_finish.tpl'));
951   }
953   /* Output templates... */
954   if($withoutput){
955     $smarty->display (get_template_path('headers.tpl'));
956   }
957   if (isset($_SESSION['errors'])) {
958     $smarty->assign("errors", $_SESSION['errors']);
959   }
960   if($withoutput){
961     $smarty->display (get_template_path('setup.tpl'));
962   }
964   return(true);
968 function create_user_for_setup($withoutput=true)
970   global $samba;
972   $ldapconf = $_SESSION['ldapconf'];
973   $smarty = get_smarty();
974   
975   $need_to_create_group = false;
976   $need_to_create_user  = false;
978   $str_there="";
980   if(isset($_SESSION['classes'])){
981     $classes= $_SESSION['classes'];
982   }
984   /* Everything runns perfect ...
985      So we do a last test on this page
986      is there a user with ACLs :all which will be able to adminsitrate GOsa
987      We check that, if this user or group is missing we ask for creating them */
988   $ldap= new LDAP($_SESSION['ldapconf']['admin'],    $_SESSION['ldapconf']['password'],   $_SESSION['ldapconf']['uri']);
990   /* 
991   Now we are testing for a group, with the rights :all 
992   */
993   
994   $ldap->cd($ldapconf['base']);
995   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
997   $group_cnt  = $ldap->count();
998   $data       = $ldap->fetch();
1000 //  $str_there  = "Searching for Aminitrative users <br><br>";
1002   /* 
1003   We need to create administrative user and group  because theres no group found 
1004   */
1005   if($group_cnt < 1) {
1006     
1007     /* 
1008     Set var to create user 
1009     */
1010 //    $str_there  =   "no group found<br>";
1012     $need_to_create_group = true;
1013     $need_to_create_user  = true;
1016     /* Output error */
1017     if(($withoutput)&&(!isset($_POST['new_admin']))){
1018       print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1019     }
1020   } else {
1021     
1022 //    $str_there = "Group found <br>".$data['dn'];    
1024     $need_to_create_group = false;
1025  
1026     $ldap->clearResult();
1027    
1028     /* We found an Administrative Group, is there a user, too */
1029     if(isset($data['memberUid'][0])) {
1030       $str = "uid=".$data['memberUid']['0'];
1031       $ldap->search("(&(objectClass=gosaAccount)(objectClass=person)(".$str."))");
1032       $data2   = $ldap->fetch();
1033   
1034       /* We must create a user */
1035       if (($ldap->count() < 1)||(!isset($data2))) {
1036 //        $str_there.="Missing user";
1037         
1038         $need_to_create_user = true;
1039       
1040         if(($withoutput)&&(!isset($_POST['new_admin']))){
1041           print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1042         }
1043       }else {
1044 //        $str_there.="<br>User found <br>".$data2['dn'];
1045         $need_to_create_user = false;
1046       }
1047     } else {
1048       $need_to_create_user=true;
1049       if(($withoutput)&&(!isset($_POST['new_admin']))){
1050           print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1051         }   
1052 //      $str_there.="<br>No User found <br>";
1053     }
1054   }
1056   if(!($need_to_create_user&&$need_to_create_group))
1057     return(true);
1059   /* We need to create a new user with group */
1060   if(isset($_POST['new_admin']))
1061   {
1062   
1063     /* Adjust password attributes according to the samba version */
1064     if (isset($classes['samba3'])) {
1065       $samba= "2";
1066       $lmPassword = "lmPassword";
1067       $ntPassword = "ntPassword";
1068     } else {
1069       $samba= "3";
1070       $lmPassword = "sambaLMPassword";
1071       $ntPassword = "sambaNtPassword";
1072     }
1074     /* Nothing submitted */
1075     if(((empty($_POST['admin_name']))||(empty($_POST['admin_pass'])))) {
1076       return(true);
1077     }
1079     if($need_to_create_user) {
1080       /* We have the order to create an Admin */
1081       /* Define the user we are going to create */
1082       $dn= "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1083       $arr['objectClass'][0] ="person";
1084       $arr['objectClass'][1] ="organizationalPerson";
1085       $arr['objectClass'][2] ="inetOrgPerson";
1086       $arr['objectClass'][3] ="gosaAccount";
1087       $arr['uid']            = $_POST['admin_name'];
1088       $arr['cn']             = $_POST['admin_name'];
1089       $arr['sn']             = $_POST['admin_name'];
1090       $arr['givenName']      = "GOsa main administrator";
1091       $arr[$lmPassword]      = "10974C6EFC0AEE1917306D272A9441BB";
1092       $arr[$ntPassword]      = "38F3951141D0F71A039CFA9D1EC06378";
1093       $arr['userPassword']   = crypt_single($_POST['admin_pass'],"md5");
1094     
1096       if(!$ldap->dn_exists($dn)){ 
1097         $ldap->cd($dn); 
1098         $ldap->create_missing_trees($dn);
1099         $ldap->cd($dn);
1100         $ldap->add($arr);
1101         if($ldap->error!="Success"){
1102           print_red($ldap->error);
1103           print_red("Can't create user, and / or Group, possibly this problem  depends on an empty LDAP server. Check your configuration and try again!");
1104         }
1105       }    
1106     }
1108     /* There's already a group for administrator, so we only need to add the user */
1109     if(!$need_to_create_group) {
1110       if(!isset($data['memberUid'])) {
1111         $arrr['memberUid']= $_POST['admin_name'];
1112       } else {
1113         $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1114         $arrr['memberUid'] = $data['memberUid'];
1115         unset($arrr['memberUid']['count']);
1116   
1117         $tmp = array_reverse($arrr['memberUid']);    
1118         foreach($tmp as $tt){
1119           $tmp2[]=$tt;
1120         }
1121         $arrr['memberUid']= $tmp2;
1122 //        $str_there="Group found<br>".$data['dn'];
1123       }
1125       $ldap->cd($data['dn']);
1126       $ldap->modify($arrr);
1128     } else {
1129       $dn                    = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1130       $arrr['objectClass'][0]= "gosaObject";
1131       $arrr['objectClass'][1]= "posixGroup";
1132       $arrr['gosaSubtreeACL']= ":all";
1133       $arrr['cn']            = "administrators";
1134       $arrr['gidNumber']     = "999";
1135       $arrr['memberUid']     = $_POST['admin_name'];
1137       $ldap->cd($dn);
1138       $ldap->create_missing_trees($dn);
1139       $ldap->cd($dn);
1141       $ldap->add($arrr);
1142     }
1143     return(true);
1144   } else {
1146     if((!isset($create_user))||(!($create_user))) {
1147       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1148       $smarty->assign("exists",true);
1149     } else {
1150       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1151       $smarty->assign("exists",false);
1152     }
1154   }
1156   /* Smarty output */ 
1157   if($withoutput){
1158     $smarty->display (get_template_path('headers.tpl'));
1159   }
1160   if (isset($_SESSION['errors'])) {
1161     $smarty->assign("errors", $_SESSION['errors']);
1162   }
1163   $smarty->assign("str_there",$str_there);
1164   if($withoutput){
1165     $smarty->display (get_template_path('setup.tpl'));
1166   }
1167   return(false);
1171 /* Returns the classnames auf the mail classes */
1172 function get_available_mail_classes()
1174   $dir = opendir( "../include");
1175   $methods = array();
1176   $suffix = "class_mail-methods-";
1177   $lensuf = strlen($suffix);
1178   $prefix = ".inc";
1179   $lenpre = strlen($prefix);
1181   $i = 0;
1182   while (($file = readdir($dir)) !== false){
1184     if(stristr($file,$suffix)) {
1185       $lenfile = strlen($file);
1186       $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1187       $methods['file'][$i] = $file;
1188       $methods[$i]['file'] = $file;
1189       $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1190       $i++;
1191     }
1193   }
1195   return($methods);
1198 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1199 ?>