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 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 schema_check($server, $admin, $password, $aff=0)
34 {
35 global $config;
37 $messages= array();
38 $required_classes= array(
39 "gosaObject" => array("version" => "2.4"),
40 "gosaAccount" => array("version" => "2.4"),
41 "gosaLockEntry" => array("version" => "2.4"),
42 "gosaCacheEntry" => array("version" => "2.4"),
43 "gosaDepartment" => array("version" => "2.4"),
45 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
46 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
47 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
49 "gosaUserTemplate" => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
50 "gosaMailAccount" => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
51 "gosaProxyAccount" => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
52 "gosaApplication" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
53 "gosaApplicationGroup" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
55 "GOhard" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
56 "gotoTerminal" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
57 "goServer" => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
58 "goTerminalServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
59 "goNfsServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
60 "goNtpServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
61 "goSyslogServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
62 "goLdapServer" => array("version" => "2.4"),
63 "goCupsServer" => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
64 "goImapServer" => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
65 "goKrbServer" => array("version" => "2.4"),
66 "goFaxServer" => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
67 );
69 /* Build LDAP connection */
70 $ds= ldap_connect ($server);
71 if (!$ds) {
72 return (array(array("msg" => _("Can't bind to LDAP. No schema check possible!"), "status" => FALSE)));
73 }
74 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
75 $r= ldap_bind ($ds, $admin, $password);
77 /* Get base to look for schema */
78 $sr = @ldap_read ($ds, "", "objectClass=*", array("subschemaSubentry"));
79 $attr= @ldap_get_entries($ds,$sr);
80 if (!isset($attr[0]['subschemasubentry'][0])){
81 return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
82 }
84 /* Get list of objectclasses */
85 $nb= $attr[0]['subschemasubentry'][0];
86 $objectclasses= array();
87 $sr= ldap_read ($ds, $nb, "objectClass=*", array("objectclasses"));
88 $attrs= ldap_get_entries($ds,$sr);
89 if (!isset($attrs[0])){
90 return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
91 }
92 foreach ($attrs[0]['objectclasses'] as $val){
93 $name= preg_replace("/^.* NAME\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $val);
94 if ($name != $val){
95 $objectclasses[$name]= $val;
96 }
97 }
98 /* Walk through objectclasses and check if they are needed or not */
99 foreach ($required_classes as $key => $value){
100 if (isset($value['class'])){
101 if (!is_array($value['class'])){
102 $classes= array($value['class']);
103 } else {
104 $classes= $value['class'];
105 }
107 /* Check if we are using the class that requires */
108 foreach($classes as $class){
109 if (!isset($objectclasses[$key])){
110 $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' is not present in LDAP setup"), $key, $class);
111 $messages[$key]['status'] = FALSE;
112 } else {
113 if (!check_schema_version($objectclasses[$key], $value['version'])){
114 $messages[$key]['msg']= sprintf(_("Optional objectclass '%s' required by plugin '%s' does not have version %s"), $key, $class, $value['version']);
115 $messages[$key]['status'] =FALSE;
116 }else {
117 if(!isset($affich2[$class])){
118 $affich2[$class]['msg'] = sprintf(_("Support for '%s' enabled"), $class)."<td class=\"check\"> ".$value['file']."</td>";
119 $affich2[$class]['status']= TRUE;
120 }
121 }
122 }
124 }
125 } else {
126 /* Required class */
127 if (!isset($objectclasses[$key])){
128 $messages[$key]['msg']= sprintf(_("Required objectclass '%s' is not present in LDAP setup"), $key);
129 $messages[$key]['status'] = FALSE;
130 } else {
131 if (!check_schema_version($objectclasses[$key], $value['version'])){
132 $messages[$key]['msg']= sprintf(_("Required objectclass '%s' does not have version %s"), $key, $value['version']);
133 $messages[$key]['status'] = FALSE;
134 }
135 }
136 }
137 }
139 /* Check for correct samba parameters */
140 if (!isset($objectclasses['sambaSamAccount'])){
141 $messages['samba3']['msg']= _("SAMBA 3 support disabled, no schema seems to be installed");
142 $affich['samba3']['msg']= $messages['samba3']['msg']."<td class=\"check\">gosa+samba3.schema</td>";
143 $messages['samba3']['status']= FALSE;
144 $affich['samba3']['status']= FALSE;
145 }else{
146 $affich['samba3']['msg']= _("SAMBA 3 support enabled")."<td class=\"check\">gosa+samba3.schema</td>";
147 $affich['samba3']['status']= TRUE;
148 }
150 if (!isset($objectclasses['sambaAccount'])){
151 $messages['samba2']['msg']= _("SAMBA 2 support disabled, no schema seems to be installed");
152 $affich['samba2']['msg']= $messages['samba2']['msg']."<td class=\"check\">samba.schema</td>";
153 $messages['samba2']['status']= FALSE;
154 $affich['samba2']['status']= FALSE;
155 }else{
156 $affich['samba2']['msg']= _("SAMBA 2 support enabled")."<td class=\"check\">samba.schema</td>";
157 $affich['samba2']['status']= TRUE;
158 }
160 /* Check pureftp/dns/ */
161 if (!isset($objectclasses['PureFTPdUser'])){
162 $messages['pureftp']['msg']= _("Support for pureftp disabled, no schema seems to be installed");
163 $affich['pureftp']['msg']= $messages['pureftp']['msg']."<td class=\"check\">pureftpd.schema</td>";
164 $messages['pureftp']['status']= FALSE;
165 $affich['pureftp']['status']= FALSE;
166 }else{
167 $affich['pureftp']['msg']= _("Support for pureftp enabled")."<td class=\"check\">pureftpd.schema</td>";
168 $affich['pureftp']['status']= TRUE;
169 }
171 if (!isset($objectclasses['gosaWebdavAccount'])){
172 $messages['webdav']['msg']= _("Support for WebDAV disabled, no schema seems to be installed");
173 $affich['webdav']['msg']= $messages['webdav']['msg']."<td class=\"check\"></td>";
174 $messages['webdav']['status']= FALSE;
175 $affich['webdav']['status']= FALSE;
176 }else{
177 $affich['webdav']['msg']=_("Support for WebDAV enabled")."<td class=\"check\">gosa+samba3.schema</td>";
178 $affich['webdav']['status']= TRUE;
179 }
181 if (!isset($objectclasses['phpgwAccount'])){
182 $messages['phpgroupware']['msg']= _("Support for phpgroupware disabled, no schema seems to be installed");
183 $affich['phpgroupware']['msg']= $messages['phpgroupware']['msg']."<td class=\"check\">phpgwaccount.schema</td>";
184 $messages['phpgroupware']['status']= FALSE;
185 $affich['phpgroupware']['status']= FALSE;
186 }else{
187 $affich['phpgroupware']['msg']= _("Support for phpgroupware enabled")."<td class=\"check\">phpgwaccount.schema</td>";
188 $affich['phpgroupware']['status']= TRUE;
189 }
191 if (!isset($objectclasses['goFonAccount'])){
192 $messages['phoneaccount']['msg']= _("Support for gofon disabled, no schema seems to be installed");
193 $affich['phoneaccount']['msg']= $messages['phoneaccount']['msg']."<td class=\"check\">gofon.schema</td>";
194 $messages['phoneaccount']['status']= FALSE;
195 $affich['phoneaccount']['status']= FALSE;
196 }else{
197 $affich['phoneaccount']['msg']= _("Support for gofon enabled")."<td class=\"check\">gofon.schema</td>";
198 $affich['phoneaccount']['status']= true;
199 }
201 if(($_SESSION['ldapconf']['mail_methods'][$_SESSION['ldapconf']['mail']] == "kolab")){
202 if(!isset($objectclasses['kolabInetOrgPerson']))
203 {
204 $messages['kolab']['msg']= _("Support for Kolab disabled, no schema seems to be installed, setting mail-method to cyrus");
205 $affich['kolab']['msg']=$messages['kolab']['msg']."<td class=\"check\">kolab2.schema</td>";
207 $tmp= array_flip($_SESSION['ldapconf']['mail_methods']);
208 $_SESSION['ldapconf']['mail']=$tmp['cyrus'];
209 $messages['kolab']['status']= FALSE;
210 $affich['kolab']['status']= FALSE;
211 }else{
212 $affich['kolab']['msg']=_("Support for Kolab enabled")."<td class=\"check\">gofon.schema</td>";
213 $affich['kolab']['status']= TRUE;
214 }
215 }
216 if($aff==0){
217 return ($messages);
218 } else {
219 return(array_merge($affich,$affich2));
220 }
221 }
224 function check(&$faults, $message, $description, $test, $required= TRUE)
225 {
226 $msg= "<table class='check'><tr><td class='check' style='font-size:14px;'>$message</td>
227 <td rowspan=2 style='vertical-align:middle; text-align:center;width:45px;'>";
228 if ($test){
229 $msg.= _("OK")."<br>";
230 } else {
231 if (!$required){
232 $msg.="<font color=red>"._("Ignored")."</font><br>";
233 } else {
234 $msg.="<font color=red>"._("Failed")."</font><br>";
235 $faults++;
236 }
237 }
238 $msg.= "</td></tr><tr><td class='check' style='padding-left:20px;".
239 "background-color:#F0F0F0;'>$description</td></tr></table><br>";
241 return $msg;
242 }
244 function perform_php_checks(&$faults)
245 {
246 global $check_globals;
248 $faults= 0;
249 $msg= "";
251 $msg.= "<h1>"._("PHP setup inspection")."</h1>";
252 $msg.= check ( $faults, _("Checking for PHP version (>=4.1.0)"),
253 _("PHP must be of version 4.1.0 or above for some functions and known bugs in PHP language."),
254 version_compare(phpversion(), "4.1.0")>=0);
256 $msg.= check ( $faults, _("Checking if register_globals is set to 'off'"),
257 _("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."),
258 $check_globals == 0, FALSE);
260 $msg.= check ( $faults, _("Checking for ldap module"),
261 _("This is the main module used by GOsa and therefore really required."),
262 function_exists('ldap_bind'));
264 $msg.= check ( $faults, _("Checking for gettext support"),
265 _("Gettext support is required for internationalized GOsa."), function_exists('bindtextdomain'));
267 $msg.= check ( $faults, _("Checking for iconv support"),
268 _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
269 function_exists('iconv'));
271 $msg.= check ( $faults, _("Checking for mhash module"),
272 _("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."),
273 function_exists('mhash'), FALSE);
275 $msg.= check ( $faults, _("Checking for imap module"),
276 _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
277 function_exists('imap_open'));
278 $msg.= check ( $faults, _("Checking for getacl in imap"),
279 _("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."),
280 function_exists('imap_getacl'), FALSE);
281 $msg.= check ( $faults, _("Checking for mysql module"),
282 _("MySQL support is needed for reading GOfax reports from databases."),
283 function_exists('mysql_query'), FALSE);
284 $msg.= check ( $faults, _("Checking for cups module"),
285 _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
286 function_exists('cups_get_dest_list'), FALSE);
287 $msg.= check ( $faults, _("Checking for kadm5 module"),
288 _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
289 function_exists('kadm5_init_with_password'), FALSE);
290 $msg.= check ( $faults, _("Checking for snmp module"),
291 _("Simple Network Management Protocol (SNMP) is required for client monitoring."),
292 function_exists('snmpgetnext'), FALSE);
294 return ($msg);
295 }
298 function perform_additional_checks(&$faults)
299 {
300 /* Programm check */
301 $msg= "<h1>"._("Checking for some additional programms")."</h1>";
303 /* Image Magick */
304 $query= "LC_ALL=C LANG=C convert -help";
305 $output= shell_exec ($query);
306 if ($output != ""){
307 $lines= split ("\n", $output);
308 $version= preg_replace ("/^Version:[^I]+ImageMagick ([^\s]+).*/", "\\1", $lines[0]);
309 list($major, $minor)= split("\.", $version);
310 $msg.= check ( $faults, _("Checking for ImageMagick (>=5.4.0)"),
311 _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
312 ($major > 5 || ($major == 5 && $minor >= 4)));
313 } else {
314 $msg.= check ( $faults, _("Checking imagick module for PHP"),
315 _("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);
316 }
318 /* Check for fping */
319 $query= "LC_ALL=C LANG=C fping -v 2>&1";
320 $output= shell_exec ($query);
321 $have_fping= preg_match("/^fping:/", $output);
322 $msg.= check ( $faults, _("Checking for fping utility"),
323 _("The fping utility is only used if you've got a thin client based terminal environment running."),
324 $have_fping, FALSE);
326 /* Check for smb hash generation tool */
327 $query= "mkntpwd 2>&1";
328 $output= shell_exec ($query);
329 $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
330 $alt = 0;
332 if (!$have_mkntpwd){
333 $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
334 system ($query, $ret);
335 $alt= ($ret == 0);
336 }
338 $msg.= check ( $faults, _("Checking for a way to generate LM/NT password hashes"),
339 _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
340 ($have_mkntpwd || $alt));
342 /* seesio.auto_start should be off, in order to without trouble*/
343 $arra = ini_get_all();
345 $session_auto_start = $arra['session.auto_start'];
346 $implicit_flush = $arra['implicit_flush'];
347 $max_execution_time = $arra['max_execution_time'];
348 $memory_limit = $arra['memory_limit'];
349 $expose_php = $arra['expose_php'];
350 $magic_quotes_gpc = $arra['magic_quotes_gpc'];
351 $register_globals = $arra['register_globals'];
353 /* auto_register */
354 $msg.= check ( $faults, _("php.ini check -> session.auto_register"),
355 _("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']));
357 /* implicit_flush */
358 $msg.= check ( $faults, _("php.ini check -> implicit_flush"),
359 _("This option influences the Output handling. Turn this Option off, to increase performance."),
360 !$implicit_flush['local_value'],0,false);
362 /* max_execution_time */
363 if($max_execution_time['local_value'] < 30 ){
364 $max_execution_time['local_value']=false;
365 }
366 $msg.= check ( $faults, _("php.ini check -> max_execution_time"),
367 _("The Execution time should be at least 30 seconds, because some actions may consume more time."),
368 $max_execution_time['local_value'],0,false);
370 /* memory_limit */
371 if($memory_limit['local_value'] < 16 ){
372 $memory_limit['local_value']=false;
373 }
374 $msg.= check ( $faults, _("php.ini check -> memory_limit"),
375 _("GOsa needs at least 16MB of memory, less will cause unpredictable errors! Increase it for larger setups."),
376 !$implicit_flush['local_value'],0,false);
378 /* expose_php */
379 $msg.= check ( $faults, _("php.ini check -> expose_php"),
380 _("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."),
381 !$implicit_flush['local_value'],0,false);
383 /* magic_quotes_gpc */
384 $msg.= check ( $faults, _("php.ini check -> magic_quotes_gpc"),
385 _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."),
386 $magic_quotes_gpc['local_value'],0,false);
388 return $msg;
389 }
392 function parse_contrib_conf()
393 {
394 $str = "";
395 $used_samba_version = 0;
396 $query = "";
397 $fp = false;
398 $output = "";
399 $needridbase_sid = false;
400 $pwdhash = "";
401 $replacements = array();
402 $ldapconf = $_SESSION['ldapconf']; // The Installation information
403 $classes = $_SESSION['classes']; // Class information needed to define which features are enabled
404 $possible_plugins = array();
406 /* Which samba version do we use? */
407 if(isset($classes['samba3'])){
408 $used_samba_version = 2;
409 } else {
410 $used_samba_version = 3;
411 }
413 /* Look for samba password generation method */
414 if(file_exists("/usr/lib/gosa/mkntpasswd")){
415 $pwdhash = "/usr/lib/gosa/mkntpasswd";
416 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
417 $pwdhash= "mkntpwd";
418 } else {
419 $pwdhash=('perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
420 }
422 /* Define which variables will be replaced */
423 $replacements['{LOCATIONNAME}'] = $ldapconf['location'];
424 $replacements['{SAMBAVERSION}'] = $used_samba_version;
425 $replacements['{LDAPBASE}'] = $ldapconf['base'];
426 $replacements['{LDAPADMIN}'] = $ldapconf['admin'];
427 $replacements['{DNMODE}'] = $ldapconf['peopledn'];
428 $replacements['{LDAPHOST}'] = $ldapconf['uri'];
429 $replacements['{PASSWORD}'] = $ldapconf['password'];
430 $replacements['{CRYPT}'] = $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
431 $replacements['{SID}\n'] = "";
432 $replacements['{RIDBASE}\n'] = "";
433 $replacements['{MAILMETHOD}'] = $ldapconf['mail_methods'][$ldapconf['mail']];
434 $replacements['{SMBHASH}'] = $pwdhash;
435 $replacements['{GOVERNMENTMODE}']= "false";
436 $replacements['{kolabAccount}'] = "";
437 $replacements['{servKolab}'] = "";
439 /* This array contains all preg_replace syntax to delete all unused plugins
440 THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes'] */
441 $possible_plugins['fonreport'][] = "'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
442 $possible_plugins['phoneaccount'][]= "'\n.*<tab.*phoneAccount.*>.*\n'i";
443 $possible_plugins['logview'][] = "'\n.*<plugin.*logview+.*\n.*>.*\n'i";
444 $possible_plugins['pureftp'][] = "'\n.*<tab.*pureftp.*>.*\n'i";
445 $possible_plugins['webdav'][] = "'\n.*<tab.*webdav.*>.*\n'i";
446 $possible_plugins['phpgroupware'][]= "'\n.*<tab.*phpgroupware.*>.*\n'i";
448 /* Header information
449 Needed to send the generated gosa.conf to the browser */
450 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
451 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
452 header("Cache-Control: no-cache");
453 header("Pragma: no-cache");
454 header("Cache-Control: post-check=0, pre-check=0");
455 header("Content-type: text/plain");
457 if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
458 preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
459 header('Content-Disposition: filename="gosa.conf"');
460 } else {
461 header('Content-Disposition: attachment; filename="gosa.conf"');
462 }
464 if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r")) {
465 echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
466 } else {
467 while(!feof($fp)) {
468 $str.= fread($fp,512);
469 }
471 if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab") {
472 $replacements['{kolabAccount}'] ="<tab class=\"kolabAccount\" />\n ";
473 $replacements['{servKolab}'] ="<tab class=\"servkolab\" name=\"Kolab\" />";
474 }
476 if($used_samba_version == 2) {
477 /* Do nothing for samba 2... */
478 } else {
479 /* Create LDAP connection, to check if there's a domain
480 object defined in the LDAP schema */
481 $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
483 /* Try to find a Samba Domain Objekt */
484 $ldap->search("(objectClass=sambaDomain)");
486 /* Something found ??? so we need to define ridbase an SID by ourselfs */
487 if($ldap->count()< 1) {
488 $replacements['{SID}']= "sid=\"123412-11\"";
489 $replacements['{RIDBASE}']= "ridbase=\"1000\"";
490 }
491 }
493 /* Data readed, types replaced, samba version detected and checked if
494 we need to add SID and RIDBASE. Check if there is an ivbbEntry in
495 the LDAP tree, in this case we will set the governmentmode to true.
496 Create LDAP connection, to check if theres a domain Objekt definen
497 in the LDAP schema. */
498 if(!isset($ldap)){
499 $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
500 }
502 /* Try to find a Samba Domain Objekt */
503 $ldap->search("(objectClass=ivbbEntry)");
505 /* Something found ??? so we need to define ridbase an SID by ourselfs */
506 if($ldap->count()> 0) {
507 $replacements['{GOVERNMENTMODE}']= "true";
508 }
510 /* Replace all colleted information with placeholder */
511 foreach($replacements as $key => $val) {
512 $str = preg_replace("/".$key."/",$val,$str);
513 }
515 /* Remove all unused plugins */
516 foreach($possible_plugins as $plugin) {
517 foreach($plugin as $key=>$val) {
518 if(in_array($plugin,$classes)) {
519 $str = preg_replace($val,"\n",$str);
520 }
521 }
522 }
523 }
525 return ((($str)));
526 }
529 /* Show setup_page 1 */
530 function show_setup_page1($withoutput = true)
531 {
532 $smarty = get_smarty();
533 $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
534 $smarty->assign ("tests", perform_php_checks($faults));
536 /* This var is true if anything went wrong */
537 if ($faults){
538 $smarty->assign("mode", "disabled");
539 }
541 /* This line displays the template only if (withoutput is set) */
542 if($withoutput){
543 $smarty->display (get_template_path('headers.tpl'));
544 }
546 if (isset($_SESSION['errors'])){
547 $smarty->assign("errors", $_SESSION['errors']);
548 }
550 if($withoutput){
551 $smarty->display (get_template_path('setup.tpl'));
552 }
554 return (!$faults);
555 }
558 /* Show setup_page 2 */
559 function show_setup_page2($withoutput = true)
560 {
561 $smarty = get_smarty();
562 $smarty->assign ("content", get_template_path('setup_step2.tpl'));
563 $smarty->assign ("tests", perform_additional_checks($faults));
565 if ($faults) {
566 $smarty->assign("mode", "disabled");
567 }
568 if($withoutput){
569 $smarty->display (get_template_path('headers.tpl'));
570 }
571 if (isset($_SESSION['errors'])) {
572 $smarty->assign("errors", $_SESSION['errors']);
573 }
574 if($withoutput){
575 $smarty->display (get_template_path('setup.tpl'));
576 }
578 return (!$faults);
579 }
582 function show_setup_page3($withoutput = true)
583 {
584 $smarty = get_smarty();
586 /* Take the Post oder the Sessioin saved data */
587 if(isset($_POST['uri'])){
588 $uri = $_POST['uri'];
589 } elseif(isset($_SESSION['ldapconf']['uri'])){
590 $uri = $_SESSION['ldapconf']['uri'];
591 }
593 /* If Page called first time, field is empty */
594 if((!isset($uri))||(empty($uri))){
595 $uri = "ldap://localhost:389";
596 }
598 /* if isset $uri save it to session */
599 if(isset($uri)) {
600 $_SESSION['ldapconf']['uri'] = $uri;
601 $smarty->assign ("uri", validate($uri));
602 }
604 /* No error till now */
605 $fault = false;
607 /* If we pushed the Button continue */
608 if(isset($_POST['continue3'])){
609 if(!isset($uri)) {
610 $fault = true;
612 /* Output the Error */
613 if($withoutput) {
614 print_red (_("You've to specify an ldap server before continuing!"));
615 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
616 }
617 }
618 } elseif (!$ds = @ldap_connect (validate($uri))) {
619 $fault =true;
621 /* Output the Error */
622 if($withoutput) {
623 print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
624 $smarty->assign ("uri", validate($uri));
625 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
626 }
627 } else {
628 /* Try to bind the connection */
629 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
631 /* if we can't bind , print error */
632 if (!$r = @ldap_bind ($ds)) {
633 $fault = true;
635 /* Output the Error */
636 if($withoutput) {
637 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
638 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
639 $smarty->assign ("uri", validate($uri));
640 }
641 } else {
642 $fault = false;
643 }
644 }
646 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
648 /* Load Header */
649 if($withoutput){
650 $smarty->display (get_template_path('headers.tpl'));
651 }
653 /* Set Errors to Smarty */
654 if (isset($_SESSION['errors'])) {
655 $smarty->assign("errors", $_SESSION['errors']);
656 }
658 /* Print out Template */
659 if($withoutput){
660 $smarty->display (get_template_path('setup.tpl'));
661 }
663 return (!$fault);
664 }
667 function show_setup_page4($withoutput = true)
668 {
669 $smarty= get_smarty();
671 if(!isset($_SESSION['ldapconf']['base'])){
672 $_SESSION['ldapconf']['base']= $base;
673 }
675 if(!isset($_SESSION['ldapconf']['base'])){
676 $_SESSION['ldapconf']['base']= $base;
677 }
678 require_once("class_password-methods.inc");
680 $fault = false;
681 $uri = $_SESSION['ldapconf']['uri'];
682 $ldapconf = $_SESSION['ldapconf'];
683 $arr_crypts= array();
684 $temp = "";
685 $checkvars = array("location", "admin", "password", "peopleou", "base",
686 "peopledn", "arr_crypts", "mail", "uidbase");
688 if(!isset($_SESSION['ldapconf']['arr_cryptkeys'])) {
689 require_once("class_password-methods.inc");
690 $tmp= passwordMethod::get_available_methods_if_not_loaded();
691 $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
692 }
694 if(!isset($_SESSION['ldapconf']['mail_methods'])) {
695 $_SESSION['ldapconf']['mail_methods']=array();
696 $temp = get_available_mail_classes();
697 $_SESSION['ldapconf']['mail_methods']= $temp['name'];
698 }
700 /* If there are some empty vars in ldapconnect -
701 these values also represent out default values */
702 if(!$ds = @ldap_connect (validate($uri))){
703 $fault = true;
704 if($withoutput){
705 print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
706 }
707 } elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
708 $fault = true;
709 if($withoutput){
710 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
711 }
712 } elseif(!$r= @ldap_bind ($ds)){
713 $fault = true;
714 if($withoutput){
715 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
716 }
717 } else {
718 $sr= @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
719 $attr= @ldap_get_entries($ds,$sr);
721 if((empty($attr))) {
722 $base= "dc=example,dc=net";
724 if($withoutput){
725 print_red(_("Bind to server successful, but the server seems to be completly empty, please check all informations twice"));
726 }
728 } else {
729 $base= $attr[0]['dn'];
730 }
731 }
733 if(!isset($_SESSION['ldapconf']['base'])){
734 $_SESSION['ldapconf']['base']= $base;
735 }
736 if(!isset($_SESSION['ldapconf']['admin'])){
737 $_SESSION['ldapconf']['admin']= "cn=ldapadmin,".$base;
738 }
739 if(!isset($_SESSION['ldapconf']['peopleou'])){
740 $_SESSION['ldapconf']['peopleou']= "ou=people";
741 }
742 if(!isset($_SESSION['ldapconf']['groupou'])){
743 $_SESSION['ldapconf']['groupou']= "ou=groups";
744 }
745 if(!isset($_SESSION['ldapconf']['peopledn'])){
746 $_SESSION['ldapconf']['peopledn']= "cn";
747 }
748 if(!isset($_SESSION['ldapconf']['password'])){
749 $_SESSION['ldapconf']['password']= "";
750 }
751 if(!isset($_SESSION['ldapconf']['location'])){
752 $_SESSION['ldapconf']['location']= "Example";
753 }
754 if(!isset($_SESSION['ldapconf']['uidbase'])){
755 $_SESSION['ldapconf']['uidbase']= "1000";
756 }
757 if(!isset($_SESSION['ldapconf']['mail'])){
758 $_SESSION['ldapconf']['mail']= 0;
759 }
760 $tmp= array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
761 if(!isset($_SESSION['ldapconf']['arr_crypts'])){
762 $_SESSION['ldapconf']['arr_crypts'] = $tmp['md5'];
763 }
765 /* check POST data */
766 if(isset($_POST['check'])) {
768 /* Check if all needed vars are submitted */
769 foreach($checkvars as $key) {
770 if($key == "peopleou"){
771 continue;
772 }
773 if($key == "groupou"){
774 continue;
775 }
777 if((isset($_POST[$key]))&&($_POST[$key]!="")) {
778 $_SESSION['ldapconf'][$key] = $_POST[$key];
779 } else {
780 if($withoutput) {
781 print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
782 }
783 $fault = true;
784 }
785 }
786 }
788 /* Transfer base */
789 if(isset($_POST['base'])){
790 $_SESSION['ldapconf']['base']= $_POST['base'];
791 }
793 $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
794 $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
796 foreach($_SESSION['ldapconf'] as $key => $val) {
797 $smarty->assign($key,$val);
798 }
800 if(isset($_POST['check'])) {
801 $ldap= new LDAP($_SESSION['ldapconf']['admin'],
802 $_SESSION['ldapconf']['password'],
803 $_SESSION['ldapconf']['uri']);
805 $m= schema_check($_SESSION['ldapconf']['uri'],
806 $_SESSION['ldapconf']['admin'],
807 $_SESSION['ldapconf']['password']);
808 $_SESSION['classes']= $m;
810 if ($ldap->error != "Success") {
811 if($withoutput) {
812 print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
813 }
814 $fault = true;
815 }
816 }
818 /* Set smarty output */
819 $smarty->assign ("content", get_template_path('setup_step4.tpl'));
820 $smarty->assign ("peopledns", array("cn", "uid"));
821 if($withoutput){
822 $smarty->display (get_template_path('headers.tpl'));
823 }
824 if(isset($_SESSION['errors'])) {
825 $smarty->assign("errors", $_SESSION['errors']);
826 }
827 if($withoutput){
828 $smarty->display (get_template_path('setup.tpl'));
829 }
831 return (!$fault);
832 }
835 function show_setup_page5($withoutput=true)
836 {
837 /* Get ldapconf */
838 $ldapconf= $_SESSION['ldapconf'];
840 /* get smarty */
841 $smarty = get_smarty();
843 if(isset($_SESSION['classes'])){
844 $classes = $_SESSION['classes'];
845 }
847 $info= posix_getgrgid(posix_getgid());
848 $smarty->assign("webgroup", $info['name']);
849 $smarty->assign("path", CONFIG_DIR);
850 $message= "<table class=\"check\">";
851 $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
853 if($withoutput) {
854 $smarty->assign ("schemas", view_schema_check($m));
855 $smarty->assign ("content", get_template_path('setup_finish.tpl'));
856 }
858 /* Output templates... */
859 if($withoutput){
860 $smarty->display (get_template_path('headers.tpl'));
861 }
862 if (isset($_SESSION['errors'])) {
863 $smarty->assign("errors", $_SESSION['errors']);
864 }
865 if($withoutput){
866 $smarty->display (get_template_path('setup.tpl'));
867 }
869 return(true);
870 }
873 function create_user_for_setup($withoutput=true)
874 {
875 global $samba;
877 $ldapconf = $_SESSION['ldapconf'];
878 $smarty = get_smarty();
880 if(isset($_SESSION['classes'])){
881 $classes= $_SESSION['classes'];
882 }
884 /* Everything runns perfect ...
885 So we do a last test on this page
886 is there a user with ACLs :all which will be able to adminsitrate GOsa
887 We check that, if this user or group is missing we ask for creating them */
888 $ldap= new LDAP($_SESSION['ldapconf']['admin'],
889 $_SESSION['ldapconf']['password'],
890 $_SESSION['ldapconf']['uri']);
892 /* Now we are testing for a group, with the rights :all */
893 $ldap->cd($ldapconf['base']);
894 $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
896 $group_cnt = $ldap->count();
897 $data = $ldap->fetch();
898 $create_user= false;
900 /* We need to create administrative user and group
901 because theres no group found */
902 if($group_cnt < 1) {
904 /* Set var to create user */
905 $create_user= true;
907 /* Output error */
908 if(($withoutput)&&(!isset($_POST['new_admin']))){
909 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
910 }
912 } else {
914 /* We found an Administrative Group, is there a user, too */
915 if(isset($data['memberUid'][0])) {
916 $ldap->search("(&(objectClass=gosaAccount)(objectClass=person))",array("uid=".$data['memberUid'][0]));
917 $data2 = $ldap->fetch();
918 }
920 /* We must create a user */
921 if (($ldap->count() < 1)||(!isset($data2))) {
922 $create_user = true;
923 if(($withoutput)&&(!isset($_POST['new_admin']))){
924 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
925 }
926 } else {
927 /* We don't need to add a user */
928 return(true);
929 }
931 }
933 /* We need to create a new user with group */
934 if(isset($_POST['new_admin']))
935 {
936 /* Adjust password attributes according to the samba version */
937 if (isset($classes['samba3'])) {
938 $samba= "2";
939 $lmPassword = "lmPassword";
940 $ntPassword = "ntPassword";
941 } else {
942 $samba= "3";
943 $lmPassword = "sambaLMPassword";
944 $ntPassword = "sambaNtPassword";
945 }
947 /* Nothing submitted */
948 if(( (empty($_POST['admin_name']))||(empty($_POST['admin_pass'])) )&&(!$create_user)) {
949 return(true);
950 }
952 /* We have the order to create on Admin ^^
953 Detect Samba version to define the Attribute names shown below */
954 $ldap->cd($ldapconf['base']);
956 /* Define the user we are going to create */
957 $dn= "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
958 $arr['objectClass'][0] ="person";
959 $arr['objectClass'][1] ="organizationalPerson";
960 $arr['objectClass'][2] ="inetOrgPerson";
961 $arr['objectClass'][3] ="gosaAccount";
962 $arr['uid'] = $_POST['admin_name'];
963 $arr['cn'] = $_POST['admin_name'];
964 $arr['sn'] = $_POST['admin_name'];
965 $arr['givenName'] = "GOsa main administrator";
966 $arr[$lmPassword] = "10974C6EFC0AEE1917306D272A9441BB";
967 $arr[$ntPassword] = "38F3951141D0F71A039CFA9D1EC06378";
968 $arr['userPassword'] = crypt_single($_POST['admin_pass'],"md5");
970 if( !$ldap->dn_exists ( $dn )){
971 $ldap->cd($dn);
972 $ldap->create_missing_trees($dn);
973 $ldap->add($arr);
974 if($ldap->error!="Success"){
975 print_red("Can't create user, and / or Group, possibly this problem depends on an empty LDAP server. Check your configuration and try again!");
976 }
977 }
979 /* There's already a group for administrator, so we only need to add the user */
980 if($group_cnt) {
982 if(!isset($data['memberUid'])) {
983 $arrr['memberUid']= $_POST['admin_name'];
984 } else {
985 $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
986 $arrr['memberUid'] = $data['memberUid'];
987 unset($arrr['memberUid']['count']);
988 }
990 $ldap->cd($data['dn']);
991 $ldap->modify($arrr);
993 } else {
995 $dn = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
996 $arrr['objectClass'][0]= "gosaObject";
997 $arrr['objectClass'][1]= "posixGroup";
998 $arrr['gosaSubtreeACL']= ":all";
999 $arrr['cn'] = "administrators";
1000 $arrr['gidNumber'] = "999";
1001 $arrr['memberUid'] = $_POST['admin_name'];
1002 $ldap->cd($dn);
1003 $ldap->add($arrr);
1004 }
1006 return(true);
1007 } else {
1009 if(!($create_user)) {
1010 $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1011 $smarty->assign("exists",true);
1012 } else {
1013 $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1014 $smarty->assign("exists",false);
1015 }
1017 }
1019 /* Smarty output */
1020 if($withoutput){
1021 $smarty->display (get_template_path('headers.tpl'));
1022 }
1023 if (isset($_SESSION['errors'])) {
1024 $smarty->assign("errors", $_SESSION['errors']);
1025 }
1026 if($withoutput){
1027 $smarty->display (get_template_path('setup.tpl'));
1028 }
1030 return(false);
1031 }
1034 /* Returns the classnames auf the mail classes */
1035 function get_available_mail_classes()
1036 {
1037 $dir = opendir( "../include");
1038 $methods = array();
1039 $suffix = "class_mail-methods-";
1040 $lensuf = strlen($suffix);
1041 $prefix = ".inc";
1042 $lenpre = strlen($prefix);
1044 $i = 0;
1045 while (($file = readdir($dir)) !== false){
1047 if(stristr($file,$suffix)) {
1048 $lenfile = strlen($file);
1049 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1050 $methods['file'][$i] = $file;
1051 $methods[$i]['file'] = $file;
1052 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1053 $i++;
1054 }
1056 }
1058 return($methods);
1059 }
1061 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1062 ?>