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 "goShareServer" => 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 }
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 }
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 }
253 }
256 function check(&$faults, $message, $description, $test, $required= TRUE)
257 {
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;
274 }
276 function perform_php_checks(&$faults)
277 {
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 is_callable('ldap_bind'));
296 $msg.= check ( $faults, _("Checking for XML functions"),
297 _("XML functions are required to parse the configuration file."),
298 is_callable('xml_parser_create'));
300 $msg.= check ( $faults, _("Checking for gettext support"),
301 _("Gettext support is required for internationalized GOsa."),
302 is_callable('bindtextdomain'));
304 $msg.= check ( $faults, _("Checking for iconv support"),
305 _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
306 is_callable('iconv'));
308 $msg.= check ( $faults, _("Checking for mhash module"),
309 _("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."),
310 is_callable('mhash'), FALSE);
312 $msg.= check ( $faults, _("Checking for imap module"),
313 _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
314 is_callable('imap_open'));
316 $msg.= check ( $faults, _("Checking for getacl in imap"),
317 _("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."),
318 is_callable('imap_getacl'), FALSE);
320 $msg.= check ( $faults, _("Checking for mysql module"),
321 _("MySQL support is needed for reading GOfax reports from databases."),
322 is_callable('mysql_query'), FALSE);
324 $msg.= check ( $faults, _("Checking for cups module"),
325 _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
326 is_callable('cups_get_dest_list'), FALSE);
328 $msg.= check ( $faults, _("Checking for kadm5 module"),
329 _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
330 is_callable('kadm5_init_with_password'), FALSE);
332 $msg.= check ( $faults, _("Checking for snmp Module"),
333 _("Simple Network Management Protocol (SNMP) is required for client monitoring."),
334 is_callable('snmpget'), FALSE);
336 return ($msg);
337 }
339 function get_link($function_name) {
340 $result= "<a href='http://de.php.net/manual/en/function.";
342 /* Replace all underscores with hyphens (phpdoc convention) */
343 $function_name= str_replace("_", "-", $function_name);
345 /* Append to base URL */
346 $result.= $function_name.".php'>$function_name</a>";
348 return $result;
349 }
351 function perform_additional_function_checks(&$faults) {
352 global $check_globals;
354 $faults= 0;
355 $msg= "";
356 $functions= array();
358 $functions_list= '../include/functions_list.inc';
360 /* Make sure that we can read the file */
361 if(is_readable($functions_list)) {
362 /* Open filehandle */
363 $fh= fopen($functions_list,'rb');
364 if($fh!=null) {
365 $functions= eval(fread($fh,filesize($functions_list)));
366 }
367 }
369 $msg.= "<h1>"._("PHP detailed function inspection")."</h1>";
370 /* Only print message, if function is not callable */
371 foreach($functions as $key => $fn_name) {
372 if(!is_callable($fn_name)) {
373 $msg.= check ($faults, sprintf(_("Checking for function <b>%s</b>"), get_link($fn_name)),
374 sprintf(_("The function <b>%s</b> is used by GOsa. There is no information if it's optional or required yet."),get_link($fn_name)),
375 is_callable($fn_name), false);
376 }
377 }
378 return $msg;
379 }
381 function perform_additional_checks(&$faults)
382 {
383 $ret = NULL;
384 /* Programm check */
385 $msg= "<h1>"._("Checking for some additional programms")."</h1>";
387 /* Image Magick */
388 $query= "LC_ALL=C LANG=C convert -help";
389 $output= shell_exec ($query);
390 if ($output != ""){
391 $lines= split ("\n", $output);
392 $version= preg_replace ("/^Version:.+Magick ([^\s]+).*/", "\\1", $lines[0]);
393 list($major, $minor)= split("\.", $version);
394 $msg.= check ( $faults, _("Checking for ImageMagick (>=5.4.0)"),
395 _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
396 ($major > 5 || ($major == 5 && $minor >= 4)));
397 } else {
398 $msg.= check ( $faults, _("Checking imagick module for PHP"),
399 _("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);
400 }
402 /* Check for fping */
403 $query= "LC_ALL=C LANG=C fping -v 2>&1";
404 $output= shell_exec ($query);
405 $have_fping= preg_match("/^fping:/", $output);
406 $msg.= check ( $faults, _("Checking for fping utility"),
407 _("The fping utility is only used if you've got a thin client based terminal environment running."),
408 $have_fping, FALSE);
410 /* Check for smb hash generation tool */
411 $query= "mkntpwd 2>&1";
412 $output= shell_exec ($query);
413 $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
414 $alt = 0;
416 if (!$have_mkntpwd){
417 $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
418 system ($query, $ret);
419 $alt= ($ret == 0);
420 }
422 $msg.= check ( $faults, _("Checking for a way to generate LM/NT password hashes"),
423 _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
424 ($have_mkntpwd || $alt));
426 /* seesio.auto_start should be off, in order to without trouble*/
427 $session_auto_start = ini_get('session.auto_start');
428 $implicit_flush = ini_get('implicit_flush');
429 $max_execution_time = ini_get('max_execution_time');
430 $memory_limit = ini_get('memory_limit');
431 $expose_php = ini_get('expose_php');
432 $magic_quotes_gpc = ini_get('magic_quotes_gpc');
433 $register_globals = ini_get('register_globals');
435 /* auto_register */
436 $msg.= check ( $faults, _("php.ini check -> session.auto_register"),
437 _("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']));
439 /* implicit_flush */
440 $msg.= check ( $faults, _("php.ini check -> implicit_flush"),
441 _("This option influences the Output handling. Turn this Option off, to increase performance."),
442 !$implicit_flush['local_value'],0,false);
444 /* max_execution_time */
445 if($max_execution_time['local_value'] < 30 ){
446 $max_execution_time['local_value']=false;
447 }
448 $msg.= check ( $faults, _("php.ini check -> max_execution_time"),
449 _("The Execution time should be at least 30 seconds, because some actions may consume more time."),
450 $max_execution_time['local_value'],0,false);
452 /* memory_limit */
453 if($memory_limit['local_value'] < 16 ){
454 $memory_limit['local_value']=false;
455 }
456 $msg.= check ( $faults, _("php.ini check -> memory_limit"),
457 _("GOsa needs at least 16MB of memory, less will cause unpredictable errors! Increase it for larger setups."),
458 !$implicit_flush['local_value'],0,false);
460 /* expose_php */
461 $msg.= check ( $faults, _("php.ini check -> expose_php"),
462 _("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."),
463 !$implicit_flush['local_value'],0,false);
465 /* magic_quotes_gpc */
466 $msg.= check ( $faults, _("php.ini check -> magic_quotes_gpc"),
467 _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."),
468 $magic_quotes_gpc['local_value'],0,false);
470 return $msg;
471 }
474 function parse_contrib_conf()
475 {
477 $str = "";
478 $used_samba_version = 0;
479 $query = "";
480 $fp = false;
481 $output = "";
482 $needridbase_sid = false;
483 $pwdhash = "";
484 $replacements = array();
485 $ldapconf = $_SESSION['ldapconf']; // The Installation information
486 $classes = $_SESSION['classes']; // Class information needed to define which features are enabled
487 $possible_plugins = array();
489 /* Which samba version do we use? */
490 if(isset($classes['samba3'])){
491 $used_samba_version = 2;
492 } else {
493 $used_samba_version = 3;
494 }
496 /* Look for samba password generation method */
497 if(file_exists("/usr/lib/gosa/mkntpasswd")){
498 $pwdhash = "/usr/lib/gosa/mkntpasswd";
499 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
500 $pwdhash= "mkntpwd";
501 } else {
502 $pwdhash=('perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
503 }
505 /* Define which variables will be replaced */
506 $replacements['{LOCATIONNAME}'] = $ldapconf['location'];
507 $replacements['{SAMBAVERSION}'] = $used_samba_version;
508 $replacements['{LDAPBASE}'] = $ldapconf['base'];
509 $replacements['{LDAPADMIN}'] = $ldapconf['admin'];
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";
535 /*Header information
536 Needed to send the generated gosa.conf to the browser */
537 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
538 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
539 header("Cache-Control: no-cache");
540 header("Pragma: no-cache");
541 header("Cache-Control: post-check=0, pre-check=0");
542 header("Content-type: text/plain");
544 if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
545 preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
546 header('Content-Disposition: filename="gosa.conf"');
547 } else {
548 header('Content-Disposition: attachment; filename="gosa.conf"');
549 }
551 if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r")) {
552 echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
553 } else {
554 while(!feof($fp)) {
555 $str.= fread($fp,512);
556 }
558 if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab") {
559 $replacements['{kolabAccount}'] ="<tab class=\"kolabAccount\" />\n ";
560 $replacements['{servKolab}'] ="<tab class=\"servkolab\" name=\"Kolab\" />";
561 }
563 if($used_samba_version == 2) {
564 /* Do nothing for samba 2... */
565 } else {
566 /* Create LDAP connection, to check if there's a domain
567 object defined in the LDAP schema */
568 $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
570 /* Try to find a Samba Domain Objekt */
571 $ldap->search("(objectClass=sambaDomain)");
573 /* Something found ??? so we need to define ridbase an SID by ourselfs */
574 if($ldap->count()< 1) {
575 $replacements['{SID}']= "sid=\"123412-11\"";
576 $replacements['{RIDBASE}']= "ridbase=\"1000\"";
577 }
578 }
580 /* Data readed, types replaced, samba version detected and checked if
581 we need to add SID and RIDBASE. Check if there is an ivbbEntry in
582 the LDAP tree, in this case we will set the governmentmode to true.
583 Create LDAP connection, to check if theres a domain Objekt definen
584 in the LDAP schema. */
585 if(!isset($ldap)){
586 $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
587 }
589 /* Try to find a Samba Domain Objekt */
590 $ldap->search("(objectClass=ivbbEntry)");
592 /* Something found ??? so we need to define ridbase an SID by ourselfs */
593 if($ldap->count()> 0) {
594 $replacements['{GOVERNMENTMODE}']= "true";
595 }
597 /* Replace all colleted information with placeholder */
598 foreach($replacements as $key => $val) {
599 $str = preg_replace("/".$key."/",$val,$str);
600 }
602 if($ldapconf['mail'] == "disabled"){
603 $str = str_replace("mailMethod=\"{MAILMETHOD}\"","",$str);
604 }
607 /* Remove all unused plugins */
608 foreach($possible_plugins as $key=> $plugin) {
609 foreach($plugin as $key=>$val) {
610 if(in_array($plugin,$classes)) {
611 $str = preg_replace($val,"\n",$str);
612 }
613 }
614 }
615 }
617 return ((($str)));
618 }
621 /* Show setup_page 1 */
622 function show_setup_page1($withoutput = true)
623 {
624 $faults = array();
625 $smarty = get_smarty();
626 $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
627 $smarty->assign ("tests", perform_php_checks($faults));
628 $smarty->assign ("detailed_tests", perform_additional_function_checks($faults));
630 /* This var is true if anything went wrong */
631 if ($faults){
632 $smarty->assign("mode", "disabled");
633 }
635 /* This line displays the template only if (withoutput is set) */
636 if($withoutput){
637 $smarty->display (get_template_path('headers.tpl'));
638 }
640 if (isset($_SESSION['errors'])){
641 $smarty->assign("errors", $_SESSION['errors']);
642 }
644 if($withoutput){
645 $smarty->display (get_template_path('setup.tpl'));
646 }
648 return (!$faults);
649 }
652 /* Show setup_page 2 */
653 function show_setup_page2($withoutput = true)
654 {
655 $faults = array();
656 $smarty = get_smarty();
657 $smarty->assign ("content", get_template_path('setup_step2.tpl'));
658 $smarty->assign ("tests", perform_additional_checks($faults));
660 if ($faults) {
661 $smarty->assign("mode", "disabled");
662 }
663 if($withoutput){
664 $smarty->display (get_template_path('headers.tpl'));
665 }
666 if (isset($_SESSION['errors'])) {
667 $smarty->assign("errors", $_SESSION['errors']);
668 }
669 if($withoutput){
670 $smarty->display (get_template_path('setup.tpl'));
671 }
673 return (!$faults);
674 }
677 function show_setup_page3($withoutput = true)
678 {
679 $ds = NULL;
680 $smarty = get_smarty();
682 /* Take the Post oder the Sessioin saved data */
683 if(isset($_POST['uri'])){
684 $uri = $_POST['uri'];
685 } elseif(isset($_SESSION['ldapconf']['uri'])){
686 $uri = $_SESSION['ldapconf']['uri'];
687 }
689 /* If Page called first time, field is empty */
690 if((!isset($uri))||(empty($uri))){
691 $uri = "ldap://localhost:389";
692 }
694 /* if isset $uri save it to session */
695 if(isset($uri)) {
696 $_SESSION['ldapconf']['uri'] = $uri;
697 $smarty->assign ("uri", validate($uri));
698 }
700 /* No error till now */
701 $fault = false;
703 /* If we pushed the Button continue */
704 if(isset($_POST['continue3'])){
705 if(!isset($uri)) {
706 $fault = true;
708 /* Output the Error */
709 if($withoutput) {
710 print_red (_("You've to specify an ldap server before continuing!"));
711 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
712 }
713 }
714 } elseif (!$ds = @ldap_connect (validate($uri))) {
715 $fault =true;
717 /* Output the Error */
718 if($withoutput) {
719 print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
720 $smarty->assign ("uri", validate($uri));
721 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
722 }
723 } else {
724 /* Try to bind the connection */
725 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
727 /* if we can't bind , print error */
728 if (!$r = @ldap_bind ($ds)) {
729 $fault = true;
731 /* Output the Error */
732 if($withoutput) {
733 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
734 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
735 $smarty->assign ("uri", validate($uri));
736 }
737 } else {
738 $fault = false;
739 }
740 }
742 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
744 /* Load Header */
745 if($withoutput){
746 $smarty->display (get_template_path('headers.tpl'));
747 }
749 /* Set Errors to Smarty */
750 if (isset($_SESSION['errors'])) {
751 $smarty->assign("errors", $_SESSION['errors']);
752 }
754 /* Print out Template */
755 if($withoutput){
756 $smarty->display (get_template_path('setup.tpl'));
757 }
759 return (!$fault);
760 }
763 function show_setup_page4($withoutput = true)
764 {
765 $smarty= get_smarty();
767 // ?
768 if(!isset($_SESSION['ldapconf']['base'])){
769 $_SESSION['ldapconf']['base']= $base;
770 }
772 if(!isset($_SESSION['ldapconf']['base'])){
773 $_SESSION['ldapconf']['base']= $base;
774 }
775 require_once("class_password-methods.inc");
777 $fault = false;
778 $uri = $_SESSION['ldapconf']['uri'];
779 $ldapconf = $_SESSION['ldapconf'];
780 $arr_crypts= array();
781 $temp = "";
782 $checkvars = array("location", "admin", "password", "peopleou", "base",
783 "peopledn", "arr_crypts", "mail", "uidbase","errorlvl");
785 if(!isset($_SESSION['ldapconf']['arr_cryptkeys'])) {
786 require_once("class_password-methods.inc");
787 $tmp= passwordMethod::get_available_methods_if_not_loaded();
788 $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
789 }
791 if(!isset($_SESSION['ldapconf']['mail_methods'])) {
792 $_SESSION['ldapconf']['mail_methods']=array();
793 $temp = get_available_mail_classes();
794 $_SESSION['ldapconf']['mail_methods']= $temp['name'];
795 }
797 /* If there are some empty vars in ldapconnect -
798 these values also represent out default values */
799 if(!$ds = @ldap_connect (validate($uri))){
800 $fault = true;
801 if($withoutput){
802 print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
803 }
804 } elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
805 $fault = true;
806 if($withoutput){
807 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
808 }
809 } elseif(!$r= @ldap_bind ($ds)){
810 $fault = true;
811 if($withoutput){
812 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
813 }
814 } else {
815 $sr= @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
816 $attr= @ldap_get_entries($ds,$sr);
818 if((empty($attr))) {
819 $base= "dc=example,dc=net";
821 if($withoutput){
822 print_red(_("Bind to server successful, but the server seems to be completly empty, please check all informations twice"));
823 }
825 } else {
826 $base= $attr[0]['dn'];
827 }
828 }
830 if(!isset($_SESSION['ldapconf']['base'])){
831 $_SESSION['ldapconf']['base']= $base;
832 }
833 if(!isset($_SESSION['ldapconf']['admin'])){
834 $_SESSION['ldapconf']['admin']= "cn=ldapadmin,".$base;
835 }
836 if(!isset($_SESSION['ldapconf']['peopleou'])){
837 $_SESSION['ldapconf']['peopleou']= "ou=people";
838 }
839 if(!isset($_SESSION['ldapconf']['groupou'])){
840 $_SESSION['ldapconf']['groupou']= "ou=groups";
841 }
842 if(!isset($_SESSION['ldapconf']['peopledn'])){
843 $_SESSION['ldapconf']['peopledn']= "cn";
844 }
845 if(!isset($_SESSION['ldapconf']['password'])){
846 $_SESSION['ldapconf']['password']= "";
847 }
848 if(!isset($_SESSION['ldapconf']['location'])){
849 $_SESSION['ldapconf']['location']= "Example";
850 }
851 if(!isset($_SESSION['ldapconf']['uidbase'])){
852 $_SESSION['ldapconf']['uidbase']= "1000";
853 }
854 if(!isset($_SESSION['ldapconf']['mail'])){
855 $_SESSION['ldapconf']['mail']= 0;
856 }
857 $tmp= array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
858 if(!isset($_SESSION['ldapconf']['arr_crypts'])){
859 $_SESSION['ldapconf']['arr_crypts'] = $tmp['md5'];
860 }
862 /* check POST data */
863 if(isset($_POST['check'])) {
865 /* Check if all needed vars are submitted */
866 foreach($checkvars as $key) {
867 if($key == "peopleou"){
868 continue;
869 }
870 if($key == "groupou"){
871 continue;
872 }
874 if((isset($_POST[$key]))&&($_POST[$key]!="")) {
875 $_SESSION['ldapconf'][$key] = $_POST[$key];
876 } else {
877 if($withoutput) {
878 print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
879 }
880 $fault = true;
881 }
882 }
883 }
885 /* Transfer base */
886 if(isset($_POST['base'])){
887 $_SESSION['ldapconf']['base']= $_POST['base'];
888 }
890 $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
891 $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
893 foreach($_SESSION['ldapconf'] as $key => $val) {
894 $smarty->assign($key,$val);
895 }
897 if(isset($_POST['check'])) {
898 $ldap= new LDAP($_SESSION['ldapconf']['admin'],
899 $_SESSION['ldapconf']['password'],
900 $_SESSION['ldapconf']['uri']);
902 $m= schema_check($_SESSION['ldapconf']['uri'],
903 $_SESSION['ldapconf']['admin'],
904 $_SESSION['ldapconf']['password']);
905 $_SESSION['classes']= $m;
907 if(!is_schema_readable($ldapconf['uri'],$ldapconf['admin'],$ldapconf['password'])){
908 if($withoutput){
909 print_red(_("Can't read schema informations, GOsa needs to know your schema setup. Please verify that it is readable for GOsa"));
910 }
911 $fault=true;
912 }
916 if ($ldap->error != "Success") {
917 if($withoutput) {
918 print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
919 }
920 $fault = true;
921 }
922 }
924 /* Set smarty output */
925 $smarty->assign ("content", get_template_path('setup_step4.tpl'));
926 $smarty->assign ("peopledns", array("cn", "uid"));
927 if($withoutput){
928 $smarty->display (get_template_path('headers.tpl'));
929 }
930 if(isset($_SESSION['errors'])) {
931 $smarty->assign("errors", $_SESSION['errors']);
932 }
933 if($withoutput){
934 $smarty->display (get_template_path('setup.tpl'));
935 }
936 return (!$fault);
937 }
940 function show_setup_page5($withoutput=true)
941 {
942 /* Get ldapconf */
943 $ldapconf= $_SESSION['ldapconf'];
945 /* get smarty */
946 $smarty = get_smarty();
948 if(isset($_SESSION['classes'])){
949 $classes = $_SESSION['classes'];
950 }
952 $info= posix_getgrgid(posix_getgid());
953 $smarty->assign("webgroup", $info['name']);
954 $smarty->assign("path", CONFIG_DIR);
955 $message= "<table summary=\"\" class=\"check\">";
956 $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
958 if($withoutput) {
959 $smarty->assign ("schemas", view_schema_check($m));
960 $smarty->assign ("content", get_template_path('setup_finish.tpl'));
961 }
963 /* Output templates... */
964 if($withoutput){
965 $smarty->display (get_template_path('headers.tpl'));
966 }
967 if (isset($_SESSION['errors'])) {
968 $smarty->assign("errors", $_SESSION['errors']);
969 }
970 if($withoutput){
971 $smarty->display (get_template_path('setup.tpl'));
972 }
974 return(true);
975 }
978 function create_user_for_setup($withoutput=true)
979 {
980 global $samba;
982 $ldapconf = $_SESSION['ldapconf'];
983 $smarty = get_smarty();
985 $need_to_create_group = false;
986 $need_to_create_user = false;
988 $str_there="";
990 if(isset($_SESSION['classes'])){
991 $classes= $_SESSION['classes'];
992 }
994 /* Everything runns perfect ...
995 So we do a last test on this page
996 is there a user with ACLs :all which will be able to adminsitrate GOsa
997 We check that, if this user or group is missing we ask for creating them */
998 $ldap= new LDAP($_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password'], $_SESSION['ldapconf']['uri']);
1000 /*
1001 Now we are testing for a group, with the rights :all
1002 */
1004 $ldap->cd($ldapconf['base']);
1005 $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
1007 $group_cnt = $ldap->count();
1008 $data = $ldap->fetch();
1010 // $str_there = "Searching for Aminitrative users <br><br>";
1012 /*
1013 We need to create administrative user and group because theres no group found
1014 */
1015 if($group_cnt < 1) {
1017 /*
1018 Set var to create user
1019 */
1020 // $str_there = "no group found<br>";
1022 $need_to_create_group = true;
1023 $need_to_create_user = true;
1026 /* Output error */
1027 if(($withoutput)&&(!isset($_POST['new_admin']))){
1028 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1029 }
1030 } else {
1032 // $str_there = "Group found <br>".$data['dn'];
1034 $need_to_create_group = false;
1036 $ldap->clearResult();
1038 /* We found an Administrative Group, is there a user, too */
1039 if(isset($data['memberUid'][0])) {
1040 $str = "uid=".$data['memberUid']['0'];
1041 $ldap->search("(&(objectClass=gosaAccount)(objectClass=person)(".$str."))");
1042 $data2 = $ldap->fetch();
1044 /* We must create a user */
1045 if (($ldap->count() < 1)||(!isset($data2))) {
1046 // $str_there.="Missing user";
1048 $need_to_create_user = true;
1050 if(($withoutput)&&(!isset($_POST['new_admin']))){
1051 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1052 }
1053 }else {
1054 // $str_there.="<br>User found <br>".$data2['dn'];
1055 $need_to_create_user = false;
1056 }
1057 } else {
1058 $need_to_create_user=true;
1059 if(($withoutput)&&(!isset($_POST['new_admin']))){
1060 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1061 }
1062 // $str_there.="<br>No User found <br>";
1063 }
1064 }
1066 if(!($need_to_create_user&&$need_to_create_group))
1067 return(true);
1069 /* We need to create a new user with group */
1070 if(isset($_POST['new_admin']))
1071 {
1073 /* Adjust password attributes according to the samba version */
1074 if (isset($classes['samba3'])) {
1075 $samba= "2";
1076 $lmPassword = "lmPassword";
1077 $ntPassword = "ntPassword";
1078 } else {
1079 $samba= "3";
1080 $lmPassword = "sambaLMPassword";
1081 $ntPassword = "sambaNtPassword";
1082 }
1084 /* Nothing submitted */
1085 if(((empty($_POST['admin_name']))||(empty($_POST['admin_pass'])))) {
1086 return(true);
1087 }
1089 if($need_to_create_user) {
1090 /* We have the order to create an Admin */
1091 /* Define the user we are going to create */
1092 $dn= "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1093 $arr['objectClass'][0] ="person";
1094 $arr['objectClass'][1] ="organizationalPerson";
1095 $arr['objectClass'][2] ="inetOrgPerson";
1096 $arr['objectClass'][3] ="gosaAccount";
1097 $arr['uid'] = $_POST['admin_name'];
1098 $arr['cn'] = $_POST['admin_name'];
1099 $arr['sn'] = $_POST['admin_name'];
1100 $arr['givenName'] = "GOsa main administrator";
1101 $arr[$lmPassword] = "10974C6EFC0AEE1917306D272A9441BB";
1102 $arr[$ntPassword] = "38F3951141D0F71A039CFA9D1EC06378";
1103 $arr['userPassword'] = crypt_single($_POST['admin_pass'],"md5");
1106 if(!$ldap->dn_exists($dn)){
1107 $ldap->cd($dn);
1108 $ldap->create_missing_trees($dn);
1109 $ldap->cd($dn);
1110 $ldap->add($arr);
1111 if($ldap->error!="Success"){
1112 print_red($ldap->error);
1113 print_red("Can't create user, and / or Group, possibly this problem depends on an empty LDAP server. Check your configuration and try again!");
1114 }
1115 }
1116 }
1118 /* There's already a group for administrator, so we only need to add the user */
1119 if(!$need_to_create_group) {
1120 if(!isset($data['memberUid'])) {
1121 $arrr['memberUid']= $_POST['admin_name'];
1122 } else {
1123 $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1124 $arrr['memberUid'] = $data['memberUid'];
1125 unset($arrr['memberUid']['count']);
1127 $tmp = array_reverse($arrr['memberUid']);
1128 foreach($tmp as $tt){
1129 $tmp2[]=$tt;
1130 }
1131 $arrr['memberUid']= $tmp2;
1132 // $str_there="Group found<br>".$data['dn'];
1133 }
1135 $ldap->cd($data['dn']);
1136 $ldap->modify($arrr);
1138 } else {
1139 $dn = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1140 $arrr['objectClass'][0]= "gosaObject";
1141 $arrr['objectClass'][1]= "posixGroup";
1142 $arrr['gosaSubtreeACL']= ":all";
1143 $arrr['cn'] = "administrators";
1144 $arrr['gidNumber'] = "999";
1145 $arrr['memberUid'] = $_POST['admin_name'];
1147 $ldap->cd($dn);
1148 $ldap->create_missing_trees($dn);
1149 $ldap->cd($dn);
1151 $ldap->add($arrr);
1152 }
1153 return(true);
1154 } else {
1156 if((!isset($create_user))||(!($create_user))) {
1157 $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1158 $smarty->assign("exists",true);
1159 } else {
1160 $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1161 $smarty->assign("exists",false);
1162 }
1164 }
1166 /* Smarty output */
1167 if($withoutput){
1168 $smarty->display (get_template_path('headers.tpl'));
1169 }
1170 if (isset($_SESSION['errors'])) {
1171 $smarty->assign("errors", $_SESSION['errors']);
1172 }
1173 $smarty->assign("str_there",$str_there);
1174 if($withoutput){
1175 $smarty->display (get_template_path('setup.tpl'));
1176 }
1177 return(false);
1178 }
1181 /* Returns the classnames auf the mail classes */
1182 function get_available_mail_classes()
1183 {
1184 $dir = opendir( "../include");
1185 $methods = array();
1186 $suffix = "class_mail-methods-";
1187 $lensuf = strlen($suffix);
1188 $prefix = ".inc";
1189 $lenpre = strlen($prefix);
1191 $i = 0;
1192 while (($file = readdir($dir)) !== false){
1194 if(stristr($file,$suffix)) {
1195 $lenfile = strlen($file);
1196 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1197 $methods['file'][$i] = $file;
1198 $methods[$i]['file'] = $file;
1199 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1200 $i++;
1201 }
1203 }
1205 return($methods);
1206 }
1208 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1209 ?>