Code

Updating spanish admin manual at 20050714
[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   $ds= ldap_connect ($server);
36   if (!$ds) {
37     return (false);
38   }
39   ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
40   $r= ldap_bind ($ds, $admin, $password);
42   /* Get base to look for schema */
43   $sr  = @ldap_read ($ds, "", "objectClass=*", array("subschemaSubentry"));
44   $attr= @ldap_get_entries($ds,$sr);
45   if (!isset($attr[0]['subschemasubentry'][0])){
46     return (false);
47   }
49   $nb= $attr[0]['subschemasubentry'][0];
50   $objectclasses= array();
51   $sr= ldap_read ($ds, $nb, "objectClass=*", array("objectclasses"));
52   $attrs= ldap_get_entries($ds,$sr);
53   if (!isset($attrs[0])){
54     return (false);
55   }
56   return(true);
57
59 function schema_check($server, $admin, $password, $aff=0,$CalledByIndexPhP=false)
60 {
61   global $config;
63   $messages= array();
64   $required_classes= array(
65       "gosaObject"            => array("version" => "2.4"),
66       "gosaAccount"           => array("version" => "2.4"),
67       "gosaLockEntry"         => array("version" => "2.4"),
68       "gosaCacheEntry"        => array("version" => "2.4"),
69       "gosaDepartment"        => array("version" => "2.4"),
71       "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
72       "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
73       "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
75       "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
76       "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
77       "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
78       "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
79       "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
81       "GOhard"                => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
82       "gotoTerminal"          => array("version" => "2.0", "class" => "terminals","file" => "goto.schema"),
83       "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
84       "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
85       "goNfsServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
86       "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
87       "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
88       "goLdapServer"          => array("version" => "2.4"),
89       "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
90       "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
91       "goKrbServer"           => array("version" => "2.4"),
92       "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
93       );
95   /* Build LDAP connection */
96   $ds= ldap_connect ($server);
97   if (!$ds) {
98     return (array(array("msg" => _("Can't bind to LDAP. No schema check possible!"), "status" => FALSE)));
99   }
100   ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
101   $r= ldap_bind ($ds, $admin, $password);
103   /* Get base to look for schema */
104   $sr  = @ldap_read ($ds, "", "objectClass=*", array("subschemaSubentry"));
105   $attr= @ldap_get_entries($ds,$sr);
106   if (!isset($attr[0]['subschemasubentry'][0])){
107     return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
108   }
110   /* Get list of objectclasses */
111   $nb= $attr[0]['subschemasubentry'][0];
112   $objectclasses= array();
113   $sr= ldap_read ($ds, $nb, "objectClass=*", array("objectclasses"));
114   $attrs= ldap_get_entries($ds,$sr);
115   if (!isset($attrs[0])){
116     return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
117   }
118   foreach ($attrs[0]['objectclasses'] as $val){
119     $name= preg_replace("/^.* NAME\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $val);
120     if ($name != $val){
121       $objectclasses[$name]= $val;
122     }
123   }
124   /* Walk through objectclasses and check if they are needed or not */
125   foreach ($required_classes as $key => $value){
126     if (isset($value['class'])){
127       if (!is_array($value['class'])){
128         $classes= array($value['class']);
129       } else {
130         $classes= $value['class'];
131       }
133       /* Check if we are using the class that requires */
134       foreach($classes as $class){
135         if (!isset($objectclasses[$key])){
136           $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' is not present in LDAP setup"), $key, $class);
137           $messages[$key]['status'] = FALSE;
138         } else {
139           if (!check_schema_version($objectclasses[$key], $value['version'])){
140             $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' does not have version %s"), $key, $class, $value['version']);
141             $messages[$key]['needonstartup'] = TRUE;
142             $messages[$key]['status'] =FALSE;
143           }else {
144             if(!isset($affich2[$class])){
145               $affich2[$class]['msg']   = sprintf(_("Support for '%s' enabled"), $class)."<td class=\"check\"> ".$value['file']."</td>";
146               $affich2[$class]['status']= TRUE; 
147             }
148           }
149         }
151       }
152     } else {
153       /* Required class */
154       if (!isset($objectclasses[$key])){
155         $messages[$key]['msg']= sprintf(_("Required objectclass '%s' is not present in LDAP setup"), $key);
156         $messages[$key]['status'] = FALSE;  
157       } else {
158         if (!check_schema_version($objectclasses[$key], $value['version'])){
159           $messages[$key]['msg']= sprintf(_("Required objectclass '%s' does not have version %s"), $key, $value['version']);
160           $messages[$key]['status'] = FALSE;  
161           $messages[$key]['needonstartup'] = TRUE;
162         }
163     
164       }
165     }
166   }
168   /* Check for correct samba parameters */
169   if (!isset($objectclasses['sambaSamAccount'])){
170     $messages['samba3']['msg']= _("SAMBA 3 support disabled, no schema seems to be installed");
171     $affich['samba3']['msg']= $messages['samba3']['msg']."<td class=\"check\">gosa+samba3.schema</td>";
172     $messages['samba3']['status']= FALSE;
173     $affich['samba3']['status']= FALSE;
174   }else{
175     $affich['samba3']['msg']= _("SAMBA 3 support enabled")."<td class=\"check\">gosa+samba3.schema</td>";
176     $affich['samba3']['status']= TRUE;
177   }
179   if (!isset($objectclasses['sambaAccount'])){
180     $messages['samba2']['msg']= _("SAMBA 2 support disabled, no schema seems to be installed");
181     $affich['samba2']['msg']= $messages['samba2']['msg']."<td class=\"check\">samba.schema</td>";
182     $messages['samba2']['status']= FALSE;
183     $affich['samba2']['status']= FALSE;
184   }else{
185     $affich['samba2']['msg']= _("SAMBA 2 support enabled")."<td class=\"check\">samba.schema</td>";
186     $affich['samba2']['status']= TRUE;
187   }
189   /* Check pureftp/dns/ */
190   if (!isset($objectclasses['PureFTPdUser'])){
191     $messages['pureftp']['msg']= _("Support for pureftp disabled, no schema seems to be installed");
192     $affich['pureftp']['msg']= $messages['pureftp']['msg']."<td class=\"check\">pureftpd.schema</td>";
193     $messages['pureftp']['status']= FALSE;
194     $affich['pureftp']['status']= FALSE;
195   }else{
196     $affich['pureftp']['msg']= _("Support for pureftp enabled")."<td class=\"check\">pureftpd.schema</td>";
197     $affich['pureftp']['status']= TRUE;
198   }
200   if (!isset($objectclasses['gosaWebdavAccount'])){
201     $messages['webdav']['msg']= _("Support for WebDAV disabled, no schema seems to be installed");
202     $affich['webdav']['msg']= $messages['webdav']['msg']."<td class=\"check\"></td>";
203     $messages['webdav']['status']= FALSE;
204     $affich['webdav']['status']= FALSE;
205   }else{
206     $affich['webdav']['msg']=_("Support for WebDAV enabled")."<td class=\"check\">gosa+samba3.schema</td>";
207     $affich['webdav']['status']= TRUE;
208   }
210   if (!isset($objectclasses['phpgwAccount'])){
211     $messages['phpgroupware']['msg']= _("Support for phpgroupware disabled, no schema seems to be installed");
212     $affich['phpgroupware']['msg']= $messages['phpgroupware']['msg']."<td class=\"check\">phpgwaccount.schema</td>";
213     $messages['phpgroupware']['status']= FALSE;
214     $affich['phpgroupware']['status']= FALSE;
215   }else{
216     $affich['phpgroupware']['msg']= _("Support for phpgroupware enabled")."<td class=\"check\">phpgwaccount.schema</td>";
217     $affich['phpgroupware']['status']= TRUE;
218   }
220   if (!isset($objectclasses['goFonAccount'])){
221     $messages['phoneaccount']['msg']= _("Support for gofon disabled, no schema seems to be installed");
222     $affich['phoneaccount']['msg']= $messages['phoneaccount']['msg']."<td class=\"check\">gofon.schema</td>";
223     $messages['phoneaccount']['status']= FALSE;
224     $affich['phoneaccount']['status']= FALSE;
225   }else{
226     $affich['phoneaccount']['msg']= _("Support for gofon enabled")."<td class=\"check\">gofon.schema</td>";
227     $affich['phoneaccount']['status']= true;
228   }
229   
230   /* Fix for PHP Fehler "Undefined index: ldapconf"
231    * Ablaufverfolgung[1]: Funktion schema_check Datei: /home/hickert/gosa/include/functions_setup.inc (Zeile 230)
232    */
233   if((isset($_SESSION['ldapconf']['mail_methods']))&&(isset($_SESSION['ldapconf']))){
234         if(($_SESSION['ldapconf']['mail_methods'][$_SESSION['ldapconf']['mail']] == "kolab")&&(!$CalledByIndexPhP)){
235           if(!isset($objectclasses['kolabInetOrgPerson']))  {
236             $messages['kolab']['msg']= _("Support for Kolab disabled, no schema seems to be installed, setting mail-method to cyrus");
237             $affich['kolab']['msg']=$messages['kolab']['msg']."<td class=\"check\">kolab2.schema</td>";
238             $tmp= array_flip($_SESSION['ldapconf']['mail_methods']);
239             $_SESSION['ldapconf']['mail']=$tmp['cyrus'];
240             $messages['kolab']['status']= FALSE;
241             $affich['kolab']['status']= FALSE;
242           }else{
243             $affich['kolab']['msg']=_("Support for Kolab enabled")."<td class=\"check\">gofon.schema</td>";
244             $affich['kolab']['status']= TRUE;
245           }
246         }
247   }
248   if($aff==0){
249     return ($messages);
250   } else {
251     return(array_merge($affich,$affich2));
252   }
256 function check(&$faults, $message, $description, $test, $required= TRUE)
258   $msg= "<table summary=\"\" class='check'><tr><td class='check' style='font-size:14px;'>$message</td>
259     <td rowspan=2 style='vertical-align:middle; text-align:center;width:45px;'>";
260   if ($test){
261     $msg.= _("OK")."<br>";
262   } else {
263     if (!$required){
264       $msg.="<font color=red>"._("Ignored")."</font><br>";
265     } else {
266       $msg.="<font color=red>"._("Failed")."</font><br>";
267       $faults++;
268     }
269   }
270   $msg.= "</td></tr><tr><td class='check' style='padding-left:20px;".
271     "background-color:#F0F0F0;'>$description</td></tr></table><br>";
273   return $msg;
276 function perform_php_checks(&$faults)
278   global $check_globals;
280   $faults= 0;
281   $msg= "";
283   $msg.= "<h1>"._("PHP setup inspection")."</h1>";
284   $msg.= check (        $faults, _("Checking for PHP version (>=4.1.0)"),
285       _("PHP must be of version 4.1.0 or above for some functions and known bugs in PHP language."),
286       version_compare(phpversion(), "4.1.0")>=0);
288   $msg.= check (        $faults, _("Checking if register_globals is set to 'off'"),
289       _("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."),
290       $check_globals == 0, FALSE);
292   $msg.= check (        $faults, _("Checking for ldap module"),
293       _("This is the main module used by GOsa and therefore really required."),
294       function_exists('ldap_bind'));
296   $msg.= check (  $faults, _("Checking for XML functions"),
297       _("XML functions are required to parse the configuration file."),
298       function_exists('xml_parser_create'));
300   $msg.= check (        $faults, _("Checking for gettext support"),
301       _("Gettext support is required for internationalized GOsa."), function_exists('bindtextdomain'));
303   $msg.= check (        $faults, _("Checking for iconv support"),
304       _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
305       function_exists('iconv'));
307   $msg.= check (        $faults, _("Checking for mhash module"),
308       _("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."),
309       function_exists('mhash'), FALSE);
311   $msg.= check (        $faults, _("Checking for imap module"),
312       _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
313       function_exists('imap_open'));
315   $msg.= check (        $faults, _("Checking for getacl in imap"),
316       _("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."),
317       function_exists('imap_getacl'), FALSE);
319   $msg.= check (        $faults, _("Checking for mysql module"),
320       _("MySQL support is needed for reading GOfax reports from databases."),
321       function_exists('mysql_query'), FALSE);
323   $msg.= check (        $faults, _("Checking for cups module"),
324       _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
325       function_exists('cups_get_dest_list'), FALSE);
327   $msg.= check (        $faults, _("Checking for kadm5 module"),
328       _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
329       function_exists('kadm5_init_with_password'), FALSE);
331   $msg.= check (  $faults, _("Checking for snmp Module"),
332       _("Simple Network Management Protocol (SNMP) is required for client monitoring."),
333       function_exists('snmpget'), FALSE);
334   return ($msg);
338 function perform_additional_checks(&$faults)
340   /* Programm check */
341   $msg= "<h1>"._("Checking for some additional programms")."</h1>";
343   /* Image Magick */
344   $query= "LC_ALL=C LANG=C convert -help";
345   $output= shell_exec ($query);
346   if ($output != ""){
347     $lines= split ("\n", $output);
348     $version= preg_replace ("/^Version:.+Magick ([^\s]+).*/", "\\1", $lines[0]);
349     list($major, $minor)= split("\.", $version);
350     $msg.= check (      $faults, _("Checking for ImageMagick (>=5.4.0)"),
351         _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
352         ($major > 5 || ($major == 5 && $minor >= 4)));
353   } else {
354     $msg.= check (      $faults, _("Checking imagick module for PHP"),
355         _("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);
356   }
358   /* Check for fping */
359   $query= "LC_ALL=C LANG=C fping -v 2>&1";
360   $output= shell_exec ($query);
361   $have_fping= preg_match("/^fping:/", $output);
362   $msg.= check (        $faults, _("Checking for fping utility"),
363       _("The fping utility is only used if you've got a thin client based terminal environment running."),
364       $have_fping, FALSE);
366   /* Check for smb hash generation tool */
367   $query= "mkntpwd 2>&1";
368   $output= shell_exec ($query);
369   $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
370   $alt = 0;
372   if (!$have_mkntpwd){
373     $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
374     system ($query, $ret);
375     $alt= ($ret == 0);
376   }
378   $msg.= check (        $faults, _("Checking for a way to generate LM/NT password hashes"),
379       _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
380       ($have_mkntpwd || $alt));
382   /* seesio.auto_start should be off, in order to without trouble*/
383   $session_auto_start = ini_get('session.auto_start');
384   $implicit_flush     = ini_get('implicit_flush');
385   $max_execution_time = ini_get('max_execution_time');
386   $memory_limit       = ini_get('memory_limit');
387   $expose_php         = ini_get('expose_php');
388   $magic_quotes_gpc   = ini_get('magic_quotes_gpc');
389   $register_globals   = ini_get('register_globals');
391   /* auto_register */
392   $msg.= check (  $faults, _("php.ini check -> session.auto_register"),
393       _("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']));
395   /* implicit_flush */
396   $msg.= check (  $faults, _("php.ini check -> implicit_flush"),
397       _("This option influences the Output handling. Turn this Option off, to increase performance."),
398       !$implicit_flush['local_value'],0,false);
400   /* max_execution_time */
401   if($max_execution_time['local_value'] < 30 ){
402     $max_execution_time['local_value']=false;
403   }
404   $msg.= check (  $faults, _("php.ini check -> max_execution_time"),
405       _("The Execution time should be at least 30 seconds, because some actions may consume more time."),
406       $max_execution_time['local_value'],0,false);
408   /* memory_limit */
409   if($memory_limit['local_value'] < 16 ){
410     $memory_limit['local_value']=false;
411   }
412   $msg.= check (  $faults, _("php.ini check -> memory_limit"),
413       _("GOsa needs at least 16MB of memory, less will cause unpredictable errors! Increase it for larger setups."),
414       !$implicit_flush['local_value'],0,false);
416   /* expose_php */
417   $msg.= check (  $faults, _("php.ini check -> expose_php"),
418       _("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."),
419       !$implicit_flush['local_value'],0,false);
421   /* magic_quotes_gpc */
422   $msg.= check (  $faults, _("php.ini check -> magic_quotes_gpc"),
423       _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."),
424       $magic_quotes_gpc['local_value'],0,false);
426   return $msg;
430 function parse_contrib_conf()
433   $str                = "";
434   $used_samba_version = 0;
435   $query              = ""; 
436   $fp                 = false;
437   $output             = "";
438   $needridbase_sid    = false;
439   $pwdhash            = "";
440   $replacements       = array();
441   $ldapconf           = $_SESSION['ldapconf']; // The Installation information
442   $classes            = $_SESSION['classes'];  // Class information needed to define which features are enabled
443   $possible_plugins   = array();
445   /* Which samba version do we use? */
446   if(isset($classes['samba3'])){
447     $used_samba_version = 2;
448   } else {
449     $used_samba_version = 3;
450   }
452   /* Look for samba password generation method */
453   if(file_exists("/usr/lib/gosa/mkntpasswd")){
454     $pwdhash  = "/usr/lib/gosa/mkntpasswd";
455   } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
456     $pwdhash= "mkntpwd";
457   } else {
458     $pwdhash=('perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
459   }
461   /* Define which variables will be replaced */
462   $replacements['{LOCATIONNAME}']  = $ldapconf['location'];
463   $replacements['{SAMBAVERSION}']  = $used_samba_version;
464   $replacements['{LDAPBASE}']      = $ldapconf['base'];
465   $replacements['{LDAPADMIN}']     = $ldapconf['admin'];
466   $replacements['{DNMODE}']        = $ldapconf['peopledn'];
467   $replacements['{LDAPHOST}']      = $ldapconf['uri'];
468   $replacements['{PASSWORD}']      = $ldapconf['password'];
469   $replacements['{CRYPT}']         = $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
470   $replacements['{SID}']         = "";
471   $replacements['{RIDBASE}']     = "";
472   if($ldapconf['mail'] != "disabled"){
473     $replacements['{MAILMETHOD}']    = $ldapconf['mail_methods'][$ldapconf['mail']];
474   }   
475   $replacements['{SMBHASH}']       = $pwdhash;
476   $replacements['{GOVERNMENTMODE}']= "false"; 
477   $replacements['{kolabAccount}']  = "";
478   $replacements['{servKolab}']     = "";
479   $replacements['{errorlvl}']     = $ldapconf['errorlvl'];
481   /* This array contains all preg_replace syntax to delete all unused plugins
482      THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes'] */
484   $possible_plugins['fonreport'][]   = "'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
485   $possible_plugins['phoneaccount'][]= "'\n.*<tab.*phoneAccount.*>.*\n'i";
486   $possible_plugins['logview'][]     = "'\n.*<plugin.*logview+.*\n.*>.*\n'i";
487   $possible_plugins['pureftp'][]     = "'\n.*<tab.*pureftp.*>.*\n'i";
488   $possible_plugins['webdav'][]      = "'\n.*<tab.*webdav.*>.*\n'i";
489   $possible_plugins['phpgroupware'][]= "'\n.*<tab.*phpgroupware.*>.*\n'i";
491   /*Header information
492      Needed to send the generated gosa.conf to the browser */
493   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
494   header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
495   header("Cache-Control: no-cache");
496   header("Pragma: no-cache");
497   header("Cache-Control: post-check=0, pre-check=0");
498   header("Content-type: text/plain");
500   if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
501       preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
502     header('Content-Disposition: filename="gosa.conf"');
503   } else {
504     header('Content-Disposition: attachment; filename="gosa.conf"');
505   }
507   if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r")) {
508     echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
509   } else {
510     while(!feof($fp)) {
511       $str.= fread($fp,512);
512     }
514     if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab") {
515       $replacements['{kolabAccount}']  ="<tab class=\"kolabAccount\" />\n     ";
516       $replacements['{servKolab}']     ="<tab class=\"servkolab\" name=\"Kolab\" />";
517     }
519     if($used_samba_version == 2) {
520       /* Do nothing for samba 2... */
521     } else {
522       /* Create LDAP connection, to check if there's a domain
523          object defined in the LDAP schema */
524       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
526       /* Try to find a Samba Domain Objekt */
527       $ldap->search("(objectClass=sambaDomain)");
528     
529       /* Something found ??? so we need to define ridbase an SID by ourselfs */
530       if($ldap->count()< 1) {
531         $replacements['{SID}']= "sid=\"123412-11\"";
532         $replacements['{RIDBASE}']= "ridbase=\"1000\"";  
533       } 
534     }
536     /* Data readed, types replaced, samba version detected and checked if
537        we need to add SID and RIDBASE. Check if there is an ivbbEntry in
538        the LDAP tree, in this case we will set the governmentmode to true.
539        Create LDAP connection, to check if theres a domain Objekt definen
540        in the LDAP schema. */
541     if(!isset($ldap)){
542       $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
543     }
545     /* Try to find a Samba Domain Objekt */
546     $ldap->search("(objectClass=ivbbEntry)");
548     /* Something found ??? so we need to define ridbase an SID by ourselfs */
549     if($ldap->count()> 0) {
550       $replacements['{GOVERNMENTMODE}']= "true";
551     }
553     /* Replace all colleted information with placeholder */
554     foreach($replacements as $key => $val) {
555       $str = preg_replace("/".$key."/",$val,$str);
556     }    
558     if($ldapconf['mail'] == "disabled"){
559       $str = str_replace("mailMethod=\"{MAILMETHOD}\"","",$str);
560     }
563     /* Remove all unused plugins */
564     foreach($possible_plugins as $key=> $plugin) {
565       foreach($plugin as $key=>$val) {
566         if(in_array($plugin,$classes)) {
567           $str = preg_replace($val,"\n",$str);
568         }
569       }
570     }
571   }
573   return ((($str)));
577 /* Show setup_page 1 */
578 function show_setup_page1($withoutput = true)
580   $smarty = get_smarty();  
581   $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
582   $smarty->assign ("tests", perform_php_checks($faults));
584   /* This var is true if anything went wrong */
585   if ($faults){
586     $smarty->assign("mode", "disabled");
587   }
589   /* This line displays the template only if (withoutput is set) */
590   if($withoutput){
591     $smarty->display (get_template_path('headers.tpl'));
592   }
594   if (isset($_SESSION['errors'])){
595     $smarty->assign("errors", $_SESSION['errors']);
596   }
598   if($withoutput){
599     $smarty->display (get_template_path('setup.tpl'));
600   }
602   return (!$faults);
606 /* Show setup_page 2 */
607 function show_setup_page2($withoutput = true)
609   $smarty = get_smarty();
610   $smarty->assign ("content", get_template_path('setup_step2.tpl'));
611   $smarty->assign ("tests", perform_additional_checks($faults));
613   if ($faults) {
614     $smarty->assign("mode", "disabled");
615   }
616   if($withoutput){
617     $smarty->display (get_template_path('headers.tpl'));
618   }
619   if (isset($_SESSION['errors']))  {
620     $smarty->assign("errors", $_SESSION['errors']);
621   }
622   if($withoutput){
623     $smarty->display (get_template_path('setup.tpl'));
624   }
626   return (!$faults);                               
630 function show_setup_page3($withoutput = true)
632   $smarty = get_smarty();
634   /* Take the Post oder the Sessioin saved data */
635   if(isset($_POST['uri'])){
636     $uri = $_POST['uri'];
637   } elseif(isset($_SESSION['ldapconf']['uri'])){
638     $uri = $_SESSION['ldapconf']['uri'];
639   }
641   /* If Page called first time, field is empty */
642   if((!isset($uri))||(empty($uri))){
643     $uri = "ldap://localhost:389";
644   }
646   /* if isset $uri save it to session */
647   if(isset($uri)) {
648     $_SESSION['ldapconf']['uri'] = $uri;
649     $smarty->assign ("uri", validate($uri));
650   }
652   /* No error till now */
653   $fault = false;
655   /* If we pushed the Button continue */
656   if(isset($_POST['continue3'])){
657     if(!isset($uri)) {
658       $fault = true;
660       /* Output the Error */
661       if($withoutput) {
662         print_red (_("You've to specify an ldap server before continuing!"));
663         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
664       }
665     }
666   } elseif (!$ds = @ldap_connect (validate($uri))) {
667     $fault =true;
669     /* Output the Error */
670     if($withoutput) {
671       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
672       $smarty->assign ("uri", validate($uri));
673       $smarty->assign ("content", get_template_path('setup_step3.tpl'));
674     }
675   } else {
676     /* Try to bind the connection */    
677     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
679     /* if we can't bind , print error */
680     if (!$r  =  @ldap_bind ($ds)) {
681       $fault = true;
683       /* Output the Error */
684       if($withoutput) {
685         print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
686         $smarty->assign ("content", get_template_path('setup_step3.tpl'));
687         $smarty->assign ("uri", validate($uri));
688       }
689     } else {
690       $fault = false;
691     }
692   }
694   $smarty->assign ("content", get_template_path('setup_step3.tpl'));
696   /* Load Header */
697   if($withoutput){
698     $smarty->display (get_template_path('headers.tpl'));
699   }
701   /* Set Errors to Smarty */
702   if (isset($_SESSION['errors'])) {
703     $smarty->assign("errors", $_SESSION['errors']);
704   }
706   /* Print out Template */ 
707   if($withoutput){
708     $smarty->display (get_template_path('setup.tpl'));
709   }
711   return (!$fault);                             
715 function show_setup_page4($withoutput = true)
717   $smarty= get_smarty();      
719   if(!isset($_SESSION['ldapconf']['base'])){
720     $_SESSION['ldapconf']['base']= $base;
721   }
723   if(!isset($_SESSION['ldapconf']['base'])){
724     $_SESSION['ldapconf']['base']= $base;
725   }
726   require_once("class_password-methods.inc");
728   $fault     = false;              
729   $uri       = $_SESSION['ldapconf']['uri'];
730   $ldapconf  = $_SESSION['ldapconf'];
731   $arr_crypts= array();
732   $temp      = "";
733   $checkvars = array("location", "admin", "password", "peopleou", "base",
734       "peopledn", "arr_crypts", "mail", "uidbase","errorlvl");
736   if(!isset($_SESSION['ldapconf']['arr_cryptkeys'])) {
737     require_once("class_password-methods.inc");
738     $tmp= passwordMethod::get_available_methods_if_not_loaded();
739     $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
740   }
742   if(!isset($_SESSION['ldapconf']['mail_methods'])) {
743     $_SESSION['ldapconf']['mail_methods']=array();
744     $temp = get_available_mail_classes();
745     $_SESSION['ldapconf']['mail_methods']= $temp['name'];
746   }
748   /* If there are some empty vars in ldapconnect -
749      these values also represent out default values */
750   if(!$ds = @ldap_connect (validate($uri))){
751     $fault = true;
752     if($withoutput){
753       print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
754     }
755   } elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
756     $fault = true;
757     if($withoutput){
758       print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
759     }
760   } elseif(!$r= @ldap_bind ($ds)){
761     $fault = true;
762     if($withoutput){
763       print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
764     }
765   } else {
766     $sr=   @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
767     $attr= @ldap_get_entries($ds,$sr);
769     if((empty($attr))) {
770       $base= "dc=example,dc=net";
772       if($withoutput){
773         print_red(_("Bind to server successful, but the server seems to be completly empty, please check all informations twice"));
774       }
776     } else {
777       $base= $attr[0]['dn'];
778     }
779   }
781   if(!isset($_SESSION['ldapconf']['base'])){
782     $_SESSION['ldapconf']['base']= $base;
783   }
784   if(!isset($_SESSION['ldapconf']['admin'])){
785     $_SESSION['ldapconf']['admin']= "cn=ldapadmin,".$base;
786   }
787   if(!isset($_SESSION['ldapconf']['peopleou'])){
788     $_SESSION['ldapconf']['peopleou']= "ou=people";
789   }
790   if(!isset($_SESSION['ldapconf']['groupou'])){
791     $_SESSION['ldapconf']['groupou']= "ou=groups";
792   }
793   if(!isset($_SESSION['ldapconf']['peopledn'])){
794     $_SESSION['ldapconf']['peopledn']= "cn";
795   }
796   if(!isset($_SESSION['ldapconf']['password'])){
797     $_SESSION['ldapconf']['password']= "";
798   }
799   if(!isset($_SESSION['ldapconf']['location'])){
800     $_SESSION['ldapconf']['location']= "Example";
801   }
802   if(!isset($_SESSION['ldapconf']['uidbase'])){
803     $_SESSION['ldapconf']['uidbase']= "1000";
804   }
805   if(!isset($_SESSION['ldapconf']['mail'])){
806     $_SESSION['ldapconf']['mail']= 0;
807   }
808   $tmp= array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
809   if(!isset($_SESSION['ldapconf']['arr_crypts'])){
810     $_SESSION['ldapconf']['arr_crypts']   = $tmp['md5'];
811   }
813   /* check POST data */
814   if(isset($_POST['check'])) {
816     /* Check if all needed vars are submitted */
817     foreach($checkvars as $key) {
818       if($key == "peopleou"){
819         continue;
820       }
821       if($key == "groupou"){
822         continue;
823       }
825       if((isset($_POST[$key]))&&($_POST[$key]!="")) {
826         $_SESSION['ldapconf'][$key] = $_POST[$key];
827       } else {
828         if($withoutput) {
829           print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
830         }
831         $fault = true;
832       }
833     }
834   }
836   /* Transfer base */
837   if(isset($_POST['base'])){
838     $_SESSION['ldapconf']['base']= $_POST['base'];
839   }
841   $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
842   $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
844   foreach($_SESSION['ldapconf'] as $key => $val) {
845     $smarty->assign($key,$val);
846   }
848   if(isset($_POST['check'])) {
849     $ldap= new LDAP($_SESSION['ldapconf']['admin'],
850         $_SESSION['ldapconf']['password'],
851         $_SESSION['ldapconf']['uri']);
853     $m= schema_check($_SESSION['ldapconf']['uri'],
854         $_SESSION['ldapconf']['admin'],
855         $_SESSION['ldapconf']['password']);
856     $_SESSION['classes']= $m;
858     if(!is_schema_readable($ldapconf['uri'],$ldapconf['admin'],$ldapconf['password'])){
859       if($withoutput){
860         print_red(_("Can't read schema informations, GOsa needs to know your schema setup. Please verify that it is readable for GOsa"));
861       }
862       $fault=true;
863     }
867     if ($ldap->error != "Success") {
868       if($withoutput) {
869         print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
870       }
871       $fault = true;
872     }
873   }
875   /* Set smarty output */
876   $smarty->assign ("content", get_template_path('setup_step4.tpl'));
877   $smarty->assign ("peopledns", array("cn", "uid"));
878   if($withoutput){
879     $smarty->display (get_template_path('headers.tpl'));
880   }
881   if(isset($_SESSION['errors'])) {
882     $smarty->assign("errors", $_SESSION['errors']);
883   }
884   if($withoutput){
885     $smarty->display (get_template_path('setup.tpl'));
886   }
887   return (!$fault);
891 function show_setup_page5($withoutput=true)
893   /* Get ldapconf */
894   $ldapconf= $_SESSION['ldapconf'];
896   /* get smarty */
897   $smarty = get_smarty();
899   if(isset($_SESSION['classes'])){
900     $classes = $_SESSION['classes'];
901   }
903   $info= posix_getgrgid(posix_getgid());
904   $smarty->assign("webgroup", $info['name']);
905   $smarty->assign("path", CONFIG_DIR);
906   $message= "<table summary=\"\" class=\"check\">";
907   $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
909   if($withoutput) {
910     $smarty->assign ("schemas", view_schema_check($m));
911     $smarty->assign ("content", get_template_path('setup_finish.tpl'));
912   }
914   /* Output templates... */
915   if($withoutput){
916     $smarty->display (get_template_path('headers.tpl'));
917   }
918   if (isset($_SESSION['errors'])) {
919     $smarty->assign("errors", $_SESSION['errors']);
920   }
921   if($withoutput){
922     $smarty->display (get_template_path('setup.tpl'));
923   }
925   return(true);
929 function create_user_for_setup($withoutput=true)
931   global $samba;
933   $ldapconf = $_SESSION['ldapconf'];
934   $smarty = get_smarty();
935   
936   $need_to_create_group = false;
937   $need_to_create_user  = false;
939   $str_there="";
941   if(isset($_SESSION['classes'])){
942     $classes= $_SESSION['classes'];
943   }
945   /* Everything runns perfect ...
946      So we do a last test on this page
947      is there a user with ACLs :all which will be able to adminsitrate GOsa
948      We check that, if this user or group is missing we ask for creating them */
949   $ldap= new LDAP($_SESSION['ldapconf']['admin'],    $_SESSION['ldapconf']['password'],   $_SESSION['ldapconf']['uri']);
951   /* 
952   Now we are testing for a group, with the rights :all 
953   */
954   
955   $ldap->cd($ldapconf['base']);
956   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
958   $group_cnt  = $ldap->count();
959   $data       = $ldap->fetch();
961 //  $str_there  = "Searching for Aminitrative users <br><br>";
963   /* 
964   We need to create administrative user and group  because theres no group found 
965   */
966   if($group_cnt < 1) {
967     
968     /* 
969     Set var to create user 
970     */
971 //    $str_there  =   "no group found<br>";
973     $need_to_create_group = true;
974     $need_to_create_user  = true;
977     /* Output error */
978     if(($withoutput)&&(!isset($_POST['new_admin']))){
979       print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
980     }
981   } else {
982     
983 //    $str_there = "Group found <br>".$data['dn'];    
985     $need_to_create_group = false;
986  
987     $ldap->clearResult();
988    
989     /* We found an Administrative Group, is there a user, too */
990     if(isset($data['memberUid'][0])) {
991       $str = "uid=".$data['memberUid']['0'];
992       $ldap->search("(&(objectClass=gosaAccount)(objectClass=person)(".$str."))");
993       $data2   = $ldap->fetch();
994   
995       /* We must create a user */
996       if (($ldap->count() < 1)||(!isset($data2))) {
997 //        $str_there.="Missing user";
998         
999         $need_to_create_user = true;
1000       
1001         if(($withoutput)&&(!isset($_POST['new_admin']))){
1002           print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1003         }
1004       }else {
1005 //        $str_there.="<br>User found <br>".$data2['dn'];
1006         $need_to_create_user = false;
1007       }
1008     } else {
1009       $need_to_create_user=true;
1010       if(($withoutput)&&(!isset($_POST['new_admin']))){
1011           print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1012         }   
1013 //      $str_there.="<br>No User found <br>";
1014     }
1015   }
1017   if(!($need_to_create_user&&$need_to_create_group))
1018     return(true);
1020   /* We need to create a new user with group */
1021   if(isset($_POST['new_admin']))
1022   {
1023   
1024     /* Adjust password attributes according to the samba version */
1025     if (isset($classes['samba3'])) {
1026       $samba= "2";
1027       $lmPassword = "lmPassword";
1028       $ntPassword = "ntPassword";
1029     } else {
1030       $samba= "3";
1031       $lmPassword = "sambaLMPassword";
1032       $ntPassword = "sambaNtPassword";
1033     }
1035     /* Nothing submitted */
1036     if(((empty($_POST['admin_name']))||(empty($_POST['admin_pass'])))) {
1037       return(true);
1038     }
1040     if($need_to_create_user) {
1041       /* We have the order to create an Admin */
1042       /* Define the user we are going to create */
1043       $dn= "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1044       $arr['objectClass'][0] ="person";
1045       $arr['objectClass'][1] ="organizationalPerson";
1046       $arr['objectClass'][2] ="inetOrgPerson";
1047       $arr['objectClass'][3] ="gosaAccount";
1048       $arr['uid']            = $_POST['admin_name'];
1049       $arr['cn']             = $_POST['admin_name'];
1050       $arr['sn']             = $_POST['admin_name'];
1051       $arr['givenName']      = "GOsa main administrator";
1052       $arr[$lmPassword]      = "10974C6EFC0AEE1917306D272A9441BB";
1053       $arr[$ntPassword]      = "38F3951141D0F71A039CFA9D1EC06378";
1054       $arr['userPassword']   = crypt_single($_POST['admin_pass'],"md5");
1055     
1057       if(!$ldap->dn_exists($dn)){ 
1058         $ldap->cd($dn); 
1059         $ldap->create_missing_trees($dn);
1060         $ldap->cd($dn);
1061         $ldap->add($arr);
1062         if($ldap->error!="Success"){
1063           print_red($ldap->error);
1064           print_red("Can't create user, and / or Group, possibly this problem  depends on an empty LDAP server. Check your configuration and try again!");
1065         }
1066       }    
1067     }
1069     /* There's already a group for administrator, so we only need to add the user */
1070     if(!$need_to_create_group) {
1071       if(!isset($data['memberUid'])) {
1072         $arrr['memberUid']= $_POST['admin_name'];
1073       } else {
1074         $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1075         $arrr['memberUid'] = $data['memberUid'];
1076         unset($arrr['memberUid']['count']);
1077   
1078         $tmp = array_reverse($arrr['memberUid']);    
1079         foreach($tmp as $tt){
1080           $tmp2[]=$tt;
1081         }
1082         $arrr['memberUid']= $tmp2;
1083 //        $str_there="Group found<br>".$data['dn'];
1084       }
1086       $ldap->cd($data['dn']);
1087       $ldap->modify($arrr);
1089     } else {
1090       $dn                    = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1091       $arrr['objectClass'][0]= "gosaObject";
1092       $arrr['objectClass'][1]= "posixGroup";
1093       $arrr['gosaSubtreeACL']= ":all";
1094       $arrr['cn']            = "administrators";
1095       $arrr['gidNumber']     = "999";
1096       $arrr['memberUid']     = $_POST['admin_name'];
1098       $ldap->cd($dn);
1099       $ldap->create_missing_trees($dn);
1100       $ldap->cd($dn);
1102       $ldap->add($arrr);
1103     }
1104     return(true);
1105   } else {
1107     if(!($create_user)) {
1108       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1109       $smarty->assign("exists",true);
1110     } else {
1111       $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1112       $smarty->assign("exists",false);
1113     }
1115   }
1117   /* Smarty output */ 
1118   if($withoutput){
1119     $smarty->display (get_template_path('headers.tpl'));
1120   }
1121   if (isset($_SESSION['errors'])) {
1122     $smarty->assign("errors", $_SESSION['errors']);
1123   }
1124   $smarty->assign("str_there",$str_there);
1125   if($withoutput){
1126     $smarty->display (get_template_path('setup.tpl'));
1127   }
1128   return(false);
1132 /* Returns the classnames auf the mail classes */
1133 function get_available_mail_classes()
1135   $dir = opendir( "../include");
1136   $methods = array();
1137   $suffix = "class_mail-methods-";
1138   $lensuf = strlen($suffix);
1139   $prefix = ".inc";
1140   $lenpre = strlen($prefix);
1142   $i = 0;
1143   while (($file = readdir($dir)) !== false){
1145     if(stristr($file,$suffix)) {
1146       $lenfile = strlen($file);
1147       $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1148       $methods['file'][$i] = $file;
1149       $methods[$i]['file'] = $file;
1150       $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1151       $i++;
1152     }
1154   }
1156   return($methods);
1159 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1160 ?>