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 }
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 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);
335 }
338 function perform_additional_checks(&$faults)
339 {
340 $ret = NULL;
341 /* Programm check */
342 $msg= "<h1>"._("Checking for some additional programms")."</h1>";
344 /* Image Magick */
345 $query= "LC_ALL=C LANG=C convert -help";
346 $output= shell_exec ($query);
347 if ($output != ""){
348 $lines= split ("\n", $output);
349 $version= preg_replace ("/^Version:.+Magick ([^\s]+).*/", "\\1", $lines[0]);
350 list($major, $minor)= split("\.", $version);
351 $msg.= check ( $faults, _("Checking for ImageMagick (>=5.4.0)"),
352 _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
353 ($major > 5 || ($major == 5 && $minor >= 4)));
354 } else {
355 $msg.= check ( $faults, _("Checking imagick module for PHP"),
356 _("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);
357 }
359 /* Check for fping */
360 $query= "LC_ALL=C LANG=C fping -v 2>&1";
361 $output= shell_exec ($query);
362 $have_fping= preg_match("/^fping:/", $output);
363 $msg.= check ( $faults, _("Checking for fping utility"),
364 _("The fping utility is only used if you've got a thin client based terminal environment running."),
365 $have_fping, FALSE);
367 /* Check for smb hash generation tool */
368 $query= "mkntpwd 2>&1";
369 $output= shell_exec ($query);
370 $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
371 $alt = 0;
373 if (!$have_mkntpwd){
374 $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
375 system ($query, $ret);
376 $alt= ($ret == 0);
377 }
379 $msg.= check ( $faults, _("Checking for a way to generate LM/NT password hashes"),
380 _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
381 ($have_mkntpwd || $alt));
383 /* seesio.auto_start should be off, in order to without trouble*/
384 $session_auto_start = ini_get('session.auto_start');
385 $implicit_flush = ini_get('implicit_flush');
386 $max_execution_time = ini_get('max_execution_time');
387 $memory_limit = ini_get('memory_limit');
388 $expose_php = ini_get('expose_php');
389 $magic_quotes_gpc = ini_get('magic_quotes_gpc');
390 $register_globals = ini_get('register_globals');
392 /* auto_register */
393 $msg.= check ( $faults, _("php.ini check -> session.auto_register"),
394 _("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']));
396 /* implicit_flush */
397 $msg.= check ( $faults, _("php.ini check -> implicit_flush"),
398 _("This option influences the Output handling. Turn this Option off, to increase performance."),
399 !$implicit_flush['local_value'],0,false);
401 /* max_execution_time */
402 if($max_execution_time['local_value'] < 30 ){
403 $max_execution_time['local_value']=false;
404 }
405 $msg.= check ( $faults, _("php.ini check -> max_execution_time"),
406 _("The Execution time should be at least 30 seconds, because some actions may consume more time."),
407 $max_execution_time['local_value'],0,false);
409 /* memory_limit */
410 if($memory_limit['local_value'] < 16 ){
411 $memory_limit['local_value']=false;
412 }
413 $msg.= check ( $faults, _("php.ini check -> memory_limit"),
414 _("GOsa needs at least 16MB of memory, less will cause unpredictable errors! Increase it for larger setups."),
415 !$implicit_flush['local_value'],0,false);
417 /* expose_php */
418 $msg.= check ( $faults, _("php.ini check -> expose_php"),
419 _("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."),
420 !$implicit_flush['local_value'],0,false);
422 /* magic_quotes_gpc */
423 $msg.= check ( $faults, _("php.ini check -> magic_quotes_gpc"),
424 _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."),
425 $magic_quotes_gpc['local_value'],0,false);
427 return $msg;
428 }
431 function parse_contrib_conf()
432 {
434 $str = "";
435 $used_samba_version = 0;
436 $query = "";
437 $fp = false;
438 $output = "";
439 $needridbase_sid = false;
440 $pwdhash = "";
441 $replacements = array();
442 $ldapconf = $_SESSION['ldapconf']; // The Installation information
443 $classes = $_SESSION['classes']; // Class information needed to define which features are enabled
444 $possible_plugins = array();
446 /* Which samba version do we use? */
447 if(isset($classes['samba3'])){
448 $used_samba_version = 2;
449 } else {
450 $used_samba_version = 3;
451 }
453 /* Look for samba password generation method */
454 if(file_exists("/usr/lib/gosa/mkntpasswd")){
455 $pwdhash = "/usr/lib/gosa/mkntpasswd";
456 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
457 $pwdhash= "mkntpwd";
458 } else {
459 $pwdhash=('perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
460 }
462 /* Define which variables will be replaced */
463 $replacements['{LOCATIONNAME}'] = $ldapconf['location'];
464 $replacements['{SAMBAVERSION}'] = $used_samba_version;
465 $replacements['{LDAPBASE}'] = $ldapconf['base'];
466 $replacements['{LDAPADMIN}'] = $ldapconf['admin'];
467 $replacements['{DNMODE}'] = $ldapconf['peopledn'];
468 $replacements['{LDAPHOST}'] = $ldapconf['uri'];
469 $replacements['{PASSWORD}'] = $ldapconf['password'];
470 $replacements['{CRYPT}'] = $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
471 $replacements['{SID}'] = "";
472 $replacements['{RIDBASE}'] = "";
473 if($ldapconf['mail'] != "disabled"){
474 $replacements['{MAILMETHOD}'] = $ldapconf['mail_methods'][$ldapconf['mail']];
475 }
476 $replacements['{SMBHASH}'] = $pwdhash;
477 $replacements['{GOVERNMENTMODE}']= "false";
478 $replacements['{kolabAccount}'] = "";
479 $replacements['{servKolab}'] = "";
480 $replacements['{errorlvl}'] = $ldapconf['errorlvl'];
482 /* This array contains all preg_replace syntax to delete all unused plugins
483 THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes'] */
485 $possible_plugins['fonreport'][] = "'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
486 $possible_plugins['phoneaccount'][]= "'\n.*<tab.*phoneAccount.*>.*\n'i";
487 $possible_plugins['logview'][] = "'\n.*<plugin.*logview+.*\n.*>.*\n'i";
488 $possible_plugins['pureftp'][] = "'\n.*<tab.*pureftp.*>.*\n'i";
489 $possible_plugins['webdav'][] = "'\n.*<tab.*webdav.*>.*\n'i";
490 $possible_plugins['phpgroupware'][]= "'\n.*<tab.*phpgroupware.*>.*\n'i";
492 /*Header information
493 Needed to send the generated gosa.conf to the browser */
494 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
495 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
496 header("Cache-Control: no-cache");
497 header("Pragma: no-cache");
498 header("Cache-Control: post-check=0, pre-check=0");
499 header("Content-type: text/plain");
501 if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
502 preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
503 header('Content-Disposition: filename="gosa.conf"');
504 } else {
505 header('Content-Disposition: attachment; filename="gosa.conf"');
506 }
508 if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r")) {
509 echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
510 } else {
511 while(!feof($fp)) {
512 $str.= fread($fp,512);
513 }
515 if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab") {
516 $replacements['{kolabAccount}'] ="<tab class=\"kolabAccount\" />\n ";
517 $replacements['{servKolab}'] ="<tab class=\"servkolab\" name=\"Kolab\" />";
518 }
520 if($used_samba_version == 2) {
521 /* Do nothing for samba 2... */
522 } else {
523 /* Create LDAP connection, to check if there's a domain
524 object defined in the LDAP schema */
525 $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
527 /* Try to find a Samba Domain Objekt */
528 $ldap->search("(objectClass=sambaDomain)");
530 /* Something found ??? so we need to define ridbase an SID by ourselfs */
531 if($ldap->count()< 1) {
532 $replacements['{SID}']= "sid=\"123412-11\"";
533 $replacements['{RIDBASE}']= "ridbase=\"1000\"";
534 }
535 }
537 /* Data readed, types replaced, samba version detected and checked if
538 we need to add SID and RIDBASE. Check if there is an ivbbEntry in
539 the LDAP tree, in this case we will set the governmentmode to true.
540 Create LDAP connection, to check if theres a domain Objekt definen
541 in the LDAP schema. */
542 if(!isset($ldap)){
543 $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
544 }
546 /* Try to find a Samba Domain Objekt */
547 $ldap->search("(objectClass=ivbbEntry)");
549 /* Something found ??? so we need to define ridbase an SID by ourselfs */
550 if($ldap->count()> 0) {
551 $replacements['{GOVERNMENTMODE}']= "true";
552 }
554 /* Replace all colleted information with placeholder */
555 foreach($replacements as $key => $val) {
556 $str = preg_replace("/".$key."/",$val,$str);
557 }
559 if($ldapconf['mail'] == "disabled"){
560 $str = str_replace("mailMethod=\"{MAILMETHOD}\"","",$str);
561 }
564 /* Remove all unused plugins */
565 foreach($possible_plugins as $key=> $plugin) {
566 foreach($plugin as $key=>$val) {
567 if(in_array($plugin,$classes)) {
568 $str = preg_replace($val,"\n",$str);
569 }
570 }
571 }
572 }
574 return ((($str)));
575 }
578 /* Show setup_page 1 */
579 function show_setup_page1($withoutput = true)
580 {
581 $faults = array();
582 $smarty = get_smarty();
583 $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
584 $smarty->assign ("tests", perform_php_checks($faults));
586 /* This var is true if anything went wrong */
587 if ($faults){
588 $smarty->assign("mode", "disabled");
589 }
591 /* This line displays the template only if (withoutput is set) */
592 if($withoutput){
593 $smarty->display (get_template_path('headers.tpl'));
594 }
596 if (isset($_SESSION['errors'])){
597 $smarty->assign("errors", $_SESSION['errors']);
598 }
600 if($withoutput){
601 $smarty->display (get_template_path('setup.tpl'));
602 }
604 return (!$faults);
605 }
608 /* Show setup_page 2 */
609 function show_setup_page2($withoutput = true)
610 {
611 $faults = array();
612 $smarty = get_smarty();
613 $smarty->assign ("content", get_template_path('setup_step2.tpl'));
614 $smarty->assign ("tests", perform_additional_checks($faults));
616 if ($faults) {
617 $smarty->assign("mode", "disabled");
618 }
619 if($withoutput){
620 $smarty->display (get_template_path('headers.tpl'));
621 }
622 if (isset($_SESSION['errors'])) {
623 $smarty->assign("errors", $_SESSION['errors']);
624 }
625 if($withoutput){
626 $smarty->display (get_template_path('setup.tpl'));
627 }
629 return (!$faults);
630 }
633 function show_setup_page3($withoutput = true)
634 {
635 $ds = NULL;
636 $smarty = get_smarty();
638 /* Take the Post oder the Sessioin saved data */
639 if(isset($_POST['uri'])){
640 $uri = $_POST['uri'];
641 } elseif(isset($_SESSION['ldapconf']['uri'])){
642 $uri = $_SESSION['ldapconf']['uri'];
643 }
645 /* If Page called first time, field is empty */
646 if((!isset($uri))||(empty($uri))){
647 $uri = "ldap://localhost:389";
648 }
650 /* if isset $uri save it to session */
651 if(isset($uri)) {
652 $_SESSION['ldapconf']['uri'] = $uri;
653 $smarty->assign ("uri", validate($uri));
654 }
656 /* No error till now */
657 $fault = false;
659 /* If we pushed the Button continue */
660 if(isset($_POST['continue3'])){
661 if(!isset($uri)) {
662 $fault = true;
664 /* Output the Error */
665 if($withoutput) {
666 print_red (_("You've to specify an ldap server before continuing!"));
667 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
668 }
669 }
670 } elseif (!$ds = @ldap_connect (validate($uri))) {
671 $fault =true;
673 /* Output the Error */
674 if($withoutput) {
675 print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
676 $smarty->assign ("uri", validate($uri));
677 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
678 }
679 } else {
680 /* Try to bind the connection */
681 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
683 /* if we can't bind , print error */
684 if (!$r = @ldap_bind ($ds)) {
685 $fault = true;
687 /* Output the Error */
688 if($withoutput) {
689 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
690 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
691 $smarty->assign ("uri", validate($uri));
692 }
693 } else {
694 $fault = false;
695 }
696 }
698 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
700 /* Load Header */
701 if($withoutput){
702 $smarty->display (get_template_path('headers.tpl'));
703 }
705 /* Set Errors to Smarty */
706 if (isset($_SESSION['errors'])) {
707 $smarty->assign("errors", $_SESSION['errors']);
708 }
710 /* Print out Template */
711 if($withoutput){
712 $smarty->display (get_template_path('setup.tpl'));
713 }
715 return (!$fault);
716 }
719 function show_setup_page4($withoutput = true)
720 {
721 $smarty= get_smarty();
723 // ?
724 if(!isset($_SESSION['ldapconf']['base'])){
725 $_SESSION['ldapconf']['base']= $base;
726 }
728 if(!isset($_SESSION['ldapconf']['base'])){
729 $_SESSION['ldapconf']['base']= $base;
730 }
731 require_once("class_password-methods.inc");
733 $fault = false;
734 $uri = $_SESSION['ldapconf']['uri'];
735 $ldapconf = $_SESSION['ldapconf'];
736 $arr_crypts= array();
737 $temp = "";
738 $checkvars = array("location", "admin", "password", "peopleou", "base",
739 "peopledn", "arr_crypts", "mail", "uidbase","errorlvl");
741 if(!isset($_SESSION['ldapconf']['arr_cryptkeys'])) {
742 require_once("class_password-methods.inc");
743 $tmp= passwordMethod::get_available_methods_if_not_loaded();
744 $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
745 }
747 if(!isset($_SESSION['ldapconf']['mail_methods'])) {
748 $_SESSION['ldapconf']['mail_methods']=array();
749 $temp = get_available_mail_classes();
750 $_SESSION['ldapconf']['mail_methods']= $temp['name'];
751 }
753 /* If there are some empty vars in ldapconnect -
754 these values also represent out default values */
755 if(!$ds = @ldap_connect (validate($uri))){
756 $fault = true;
757 if($withoutput){
758 print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
759 }
760 } elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
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 } elseif(!$r= @ldap_bind ($ds)){
766 $fault = true;
767 if($withoutput){
768 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
769 }
770 } else {
771 $sr= @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
772 $attr= @ldap_get_entries($ds,$sr);
774 if((empty($attr))) {
775 $base= "dc=example,dc=net";
777 if($withoutput){
778 print_red(_("Bind to server successful, but the server seems to be completly empty, please check all informations twice"));
779 }
781 } else {
782 $base= $attr[0]['dn'];
783 }
784 }
786 if(!isset($_SESSION['ldapconf']['base'])){
787 $_SESSION['ldapconf']['base']= $base;
788 }
789 if(!isset($_SESSION['ldapconf']['admin'])){
790 $_SESSION['ldapconf']['admin']= "cn=ldapadmin,".$base;
791 }
792 if(!isset($_SESSION['ldapconf']['peopleou'])){
793 $_SESSION['ldapconf']['peopleou']= "ou=people";
794 }
795 if(!isset($_SESSION['ldapconf']['groupou'])){
796 $_SESSION['ldapconf']['groupou']= "ou=groups";
797 }
798 if(!isset($_SESSION['ldapconf']['peopledn'])){
799 $_SESSION['ldapconf']['peopledn']= "cn";
800 }
801 if(!isset($_SESSION['ldapconf']['password'])){
802 $_SESSION['ldapconf']['password']= "";
803 }
804 if(!isset($_SESSION['ldapconf']['location'])){
805 $_SESSION['ldapconf']['location']= "Example";
806 }
807 if(!isset($_SESSION['ldapconf']['uidbase'])){
808 $_SESSION['ldapconf']['uidbase']= "1000";
809 }
810 if(!isset($_SESSION['ldapconf']['mail'])){
811 $_SESSION['ldapconf']['mail']= 0;
812 }
813 $tmp= array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
814 if(!isset($_SESSION['ldapconf']['arr_crypts'])){
815 $_SESSION['ldapconf']['arr_crypts'] = $tmp['md5'];
816 }
818 /* check POST data */
819 if(isset($_POST['check'])) {
821 /* Check if all needed vars are submitted */
822 foreach($checkvars as $key) {
823 if($key == "peopleou"){
824 continue;
825 }
826 if($key == "groupou"){
827 continue;
828 }
830 if((isset($_POST[$key]))&&($_POST[$key]!="")) {
831 $_SESSION['ldapconf'][$key] = $_POST[$key];
832 } else {
833 if($withoutput) {
834 print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
835 }
836 $fault = true;
837 }
838 }
839 }
841 /* Transfer base */
842 if(isset($_POST['base'])){
843 $_SESSION['ldapconf']['base']= $_POST['base'];
844 }
846 $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
847 $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
849 foreach($_SESSION['ldapconf'] as $key => $val) {
850 $smarty->assign($key,$val);
851 }
853 if(isset($_POST['check'])) {
854 $ldap= new LDAP($_SESSION['ldapconf']['admin'],
855 $_SESSION['ldapconf']['password'],
856 $_SESSION['ldapconf']['uri']);
858 $m= schema_check($_SESSION['ldapconf']['uri'],
859 $_SESSION['ldapconf']['admin'],
860 $_SESSION['ldapconf']['password']);
861 $_SESSION['classes']= $m;
863 if(!is_schema_readable($ldapconf['uri'],$ldapconf['admin'],$ldapconf['password'])){
864 if($withoutput){
865 print_red(_("Can't read schema informations, GOsa needs to know your schema setup. Please verify that it is readable for GOsa"));
866 }
867 $fault=true;
868 }
872 if ($ldap->error != "Success") {
873 if($withoutput) {
874 print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
875 }
876 $fault = true;
877 }
878 }
880 /* Set smarty output */
881 $smarty->assign ("content", get_template_path('setup_step4.tpl'));
882 $smarty->assign ("peopledns", array("cn", "uid"));
883 if($withoutput){
884 $smarty->display (get_template_path('headers.tpl'));
885 }
886 if(isset($_SESSION['errors'])) {
887 $smarty->assign("errors", $_SESSION['errors']);
888 }
889 if($withoutput){
890 $smarty->display (get_template_path('setup.tpl'));
891 }
892 return (!$fault);
893 }
896 function show_setup_page5($withoutput=true)
897 {
898 /* Get ldapconf */
899 $ldapconf= $_SESSION['ldapconf'];
901 /* get smarty */
902 $smarty = get_smarty();
904 if(isset($_SESSION['classes'])){
905 $classes = $_SESSION['classes'];
906 }
908 $info= posix_getgrgid(posix_getgid());
909 $smarty->assign("webgroup", $info['name']);
910 $smarty->assign("path", CONFIG_DIR);
911 $message= "<table summary=\"\" class=\"check\">";
912 $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
914 if($withoutput) {
915 $smarty->assign ("schemas", view_schema_check($m));
916 $smarty->assign ("content", get_template_path('setup_finish.tpl'));
917 }
919 /* Output templates... */
920 if($withoutput){
921 $smarty->display (get_template_path('headers.tpl'));
922 }
923 if (isset($_SESSION['errors'])) {
924 $smarty->assign("errors", $_SESSION['errors']);
925 }
926 if($withoutput){
927 $smarty->display (get_template_path('setup.tpl'));
928 }
930 return(true);
931 }
934 function create_user_for_setup($withoutput=true)
935 {
936 global $samba;
938 $ldapconf = $_SESSION['ldapconf'];
939 $smarty = get_smarty();
941 $need_to_create_group = false;
942 $need_to_create_user = false;
944 $str_there="";
946 if(isset($_SESSION['classes'])){
947 $classes= $_SESSION['classes'];
948 }
950 /* Everything runns perfect ...
951 So we do a last test on this page
952 is there a user with ACLs :all which will be able to adminsitrate GOsa
953 We check that, if this user or group is missing we ask for creating them */
954 $ldap= new LDAP($_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password'], $_SESSION['ldapconf']['uri']);
956 /*
957 Now we are testing for a group, with the rights :all
958 */
960 $ldap->cd($ldapconf['base']);
961 $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
963 $group_cnt = $ldap->count();
964 $data = $ldap->fetch();
966 // $str_there = "Searching for Aminitrative users <br><br>";
968 /*
969 We need to create administrative user and group because theres no group found
970 */
971 if($group_cnt < 1) {
973 /*
974 Set var to create user
975 */
976 // $str_there = "no group found<br>";
978 $need_to_create_group = true;
979 $need_to_create_user = true;
982 /* Output error */
983 if(($withoutput)&&(!isset($_POST['new_admin']))){
984 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
985 }
986 } else {
988 // $str_there = "Group found <br>".$data['dn'];
990 $need_to_create_group = false;
992 $ldap->clearResult();
994 /* We found an Administrative Group, is there a user, too */
995 if(isset($data['memberUid'][0])) {
996 $str = "uid=".$data['memberUid']['0'];
997 $ldap->search("(&(objectClass=gosaAccount)(objectClass=person)(".$str."))");
998 $data2 = $ldap->fetch();
1000 /* We must create a user */
1001 if (($ldap->count() < 1)||(!isset($data2))) {
1002 // $str_there.="Missing user";
1004 $need_to_create_user = true;
1006 if(($withoutput)&&(!isset($_POST['new_admin']))){
1007 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1008 }
1009 }else {
1010 // $str_there.="<br>User found <br>".$data2['dn'];
1011 $need_to_create_user = false;
1012 }
1013 } else {
1014 $need_to_create_user=true;
1015 if(($withoutput)&&(!isset($_POST['new_admin']))){
1016 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1017 }
1018 // $str_there.="<br>No User found <br>";
1019 }
1020 }
1022 if(!($need_to_create_user&&$need_to_create_group))
1023 return(true);
1025 /* We need to create a new user with group */
1026 if(isset($_POST['new_admin']))
1027 {
1029 /* Adjust password attributes according to the samba version */
1030 if (isset($classes['samba3'])) {
1031 $samba= "2";
1032 $lmPassword = "lmPassword";
1033 $ntPassword = "ntPassword";
1034 } else {
1035 $samba= "3";
1036 $lmPassword = "sambaLMPassword";
1037 $ntPassword = "sambaNtPassword";
1038 }
1040 /* Nothing submitted */
1041 if(((empty($_POST['admin_name']))||(empty($_POST['admin_pass'])))) {
1042 return(true);
1043 }
1045 if($need_to_create_user) {
1046 /* We have the order to create an Admin */
1047 /* Define the user we are going to create */
1048 $dn= "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1049 $arr['objectClass'][0] ="person";
1050 $arr['objectClass'][1] ="organizationalPerson";
1051 $arr['objectClass'][2] ="inetOrgPerson";
1052 $arr['objectClass'][3] ="gosaAccount";
1053 $arr['uid'] = $_POST['admin_name'];
1054 $arr['cn'] = $_POST['admin_name'];
1055 $arr['sn'] = $_POST['admin_name'];
1056 $arr['givenName'] = "GOsa main administrator";
1057 $arr[$lmPassword] = "10974C6EFC0AEE1917306D272A9441BB";
1058 $arr[$ntPassword] = "38F3951141D0F71A039CFA9D1EC06378";
1059 $arr['userPassword'] = crypt_single($_POST['admin_pass'],"md5");
1062 if(!$ldap->dn_exists($dn)){
1063 $ldap->cd($dn);
1064 $ldap->create_missing_trees($dn);
1065 $ldap->cd($dn);
1066 $ldap->add($arr);
1067 if($ldap->error!="Success"){
1068 print_red($ldap->error);
1069 print_red("Can't create user, and / or Group, possibly this problem depends on an empty LDAP server. Check your configuration and try again!");
1070 }
1071 }
1072 }
1074 /* There's already a group for administrator, so we only need to add the user */
1075 if(!$need_to_create_group) {
1076 if(!isset($data['memberUid'])) {
1077 $arrr['memberUid']= $_POST['admin_name'];
1078 } else {
1079 $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1080 $arrr['memberUid'] = $data['memberUid'];
1081 unset($arrr['memberUid']['count']);
1083 $tmp = array_reverse($arrr['memberUid']);
1084 foreach($tmp as $tt){
1085 $tmp2[]=$tt;
1086 }
1087 $arrr['memberUid']= $tmp2;
1088 // $str_there="Group found<br>".$data['dn'];
1089 }
1091 $ldap->cd($data['dn']);
1092 $ldap->modify($arrr);
1094 } else {
1095 $dn = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1096 $arrr['objectClass'][0]= "gosaObject";
1097 $arrr['objectClass'][1]= "posixGroup";
1098 $arrr['gosaSubtreeACL']= ":all";
1099 $arrr['cn'] = "administrators";
1100 $arrr['gidNumber'] = "999";
1101 $arrr['memberUid'] = $_POST['admin_name'];
1103 $ldap->cd($dn);
1104 $ldap->create_missing_trees($dn);
1105 $ldap->cd($dn);
1107 $ldap->add($arrr);
1108 }
1109 return(true);
1110 } else {
1112 if((!isset($create_user))||(!($create_user))) {
1113 $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1114 $smarty->assign("exists",true);
1115 } else {
1116 $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1117 $smarty->assign("exists",false);
1118 }
1120 }
1122 /* Smarty output */
1123 if($withoutput){
1124 $smarty->display (get_template_path('headers.tpl'));
1125 }
1126 if (isset($_SESSION['errors'])) {
1127 $smarty->assign("errors", $_SESSION['errors']);
1128 }
1129 $smarty->assign("str_there",$str_there);
1130 if($withoutput){
1131 $smarty->display (get_template_path('setup.tpl'));
1132 }
1133 return(false);
1134 }
1137 /* Returns the classnames auf the mail classes */
1138 function get_available_mail_classes()
1139 {
1140 $dir = opendir( "../include");
1141 $methods = array();
1142 $suffix = "class_mail-methods-";
1143 $lensuf = strlen($suffix);
1144 $prefix = ".inc";
1145 $lenpre = strlen($prefix);
1147 $i = 0;
1148 while (($file = readdir($dir)) !== false){
1150 if(stristr($file,$suffix)) {
1151 $lenfile = strlen($file);
1152 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1153 $methods['file'][$i] = $file;
1154 $methods[$i]['file'] = $file;
1155 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1156 $i++;
1157 }
1159 }
1161 return($methods);
1162 }
1164 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1165 ?>