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('snmpget'), FALSE);
293 return ($msg);
294 }
297 function perform_additional_checks(&$faults)
298 {
299 /* Programm check */
300 $msg= "<h1>"._("Checking for some additional programms")."</h1>";
302 /* Image Magick */
303 $query= "LC_ALL=C LANG=C convert -help";
304 $output= shell_exec ($query);
305 if ($output != ""){
306 $lines= split ("\n", $output);
307 $version= preg_replace ("/^Version:.+Magick ([^\s]+).*/", "\\1", $lines[0]);
308 list($major, $minor)= split("\.", $version);
309 $msg.= check ( $faults, _("Checking for ImageMagick (>=5.4.0)"),
310 _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
311 ($major > 5 || ($major == 5 && $minor >= 4)));
312 } else {
313 $msg.= check ( $faults, _("Checking imagick module for PHP"),
314 _("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);
315 }
317 /* Check for fping */
318 $query= "LC_ALL=C LANG=C fping -v 2>&1";
319 $output= shell_exec ($query);
320 $have_fping= preg_match("/^fping:/", $output);
321 $msg.= check ( $faults, _("Checking for fping utility"),
322 _("The fping utility is only used if you've got a thin client based terminal environment running."),
323 $have_fping, FALSE);
325 /* Check for smb hash generation tool */
326 $query= "mkntpwd 2>&1";
327 $output= shell_exec ($query);
328 $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
329 $alt = 0;
331 if (!$have_mkntpwd){
332 $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
333 system ($query, $ret);
334 $alt= ($ret == 0);
335 }
337 $msg.= check ( $faults, _("Checking for a way to generate LM/NT password hashes"),
338 _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
339 ($have_mkntpwd || $alt));
341 /* seesio.auto_start should be off, in order to without trouble*/
342 $arra = ini_get_all();
344 $session_auto_start = $arra['session.auto_start'];
345 $implicit_flush = $arra['implicit_flush'];
346 $max_execution_time = $arra['max_execution_time'];
347 $memory_limit = $arra['memory_limit'];
348 $expose_php = $arra['expose_php'];
349 $magic_quotes_gpc = $arra['magic_quotes_gpc'];
350 $register_globals = $arra['register_globals'];
352 /* auto_register */
353 $msg.= check ( $faults, _("php.ini check -> session.auto_register"),
354 _("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']));
356 /* implicit_flush */
357 $msg.= check ( $faults, _("php.ini check -> implicit_flush"),
358 _("This option influences the Output handling. Turn this Option off, to increase performance."),
359 !$implicit_flush['local_value'],0,false);
361 /* max_execution_time */
362 if($max_execution_time['local_value'] < 30 ){
363 $max_execution_time['local_value']=false;
364 }
365 $msg.= check ( $faults, _("php.ini check -> max_execution_time"),
366 _("The Execution time should be at least 30 seconds, because some actions may consume more time."),
367 $max_execution_time['local_value'],0,false);
369 /* memory_limit */
370 if($memory_limit['local_value'] < 16 ){
371 $memory_limit['local_value']=false;
372 }
373 $msg.= check ( $faults, _("php.ini check -> memory_limit"),
374 _("GOsa needs at least 16MB of memory, less will cause unpredictable errors! Increase it for larger setups."),
375 !$implicit_flush['local_value'],0,false);
377 /* expose_php */
378 $msg.= check ( $faults, _("php.ini check -> expose_php"),
379 _("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."),
380 !$implicit_flush['local_value'],0,false);
382 /* magic_quotes_gpc */
383 $msg.= check ( $faults, _("php.ini check -> magic_quotes_gpc"),
384 _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."),
385 $magic_quotes_gpc['local_value'],0,false);
387 return $msg;
388 }
391 function parse_contrib_conf()
392 {
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 if($ldapconf['mail'] != "disabled"){
434 $replacements['{MAILMETHOD}'] = $ldapconf['mail_methods'][$ldapconf['mail']];
435 }
436 $replacements['{SMBHASH}'] = $pwdhash;
437 $replacements['{GOVERNMENTMODE}']= "false";
438 $replacements['{kolabAccount}'] = "";
439 $replacements['{servKolab}'] = "";
441 /* This array contains all preg_replace syntax to delete all unused plugins
442 THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes'] */
444 $possible_plugins['fonreport'][] = "'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
445 $possible_plugins['phoneaccount'][]= "'\n.*<tab.*phoneAccount.*>.*\n'i";
446 $possible_plugins['logview'][] = "'\n.*<plugin.*logview+.*\n.*>.*\n'i";
447 $possible_plugins['pureftp'][] = "'\n.*<tab.*pureftp.*>.*\n'i";
448 $possible_plugins['webdav'][] = "'\n.*<tab.*webdav.*>.*\n'i";
449 $possible_plugins['phpgroupware'][]= "'\n.*<tab.*phpgroupware.*>.*\n'i";
451 /* Header information
452 Needed to send the generated gosa.conf to the browser */
453 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
454 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
455 header("Cache-Control: no-cache");
456 header("Pragma: no-cache");
457 header("Cache-Control: post-check=0, pre-check=0");
458 header("Content-type: text/plain");
460 if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
461 preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
462 header('Content-Disposition: filename="gosa.conf"');
463 } else {
464 header('Content-Disposition: attachment; filename="gosa.conf"');
465 }
467 if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r")) {
468 echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
469 } else {
470 while(!feof($fp)) {
471 $str.= fread($fp,512);
472 }
474 if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab") {
475 $replacements['{kolabAccount}'] ="<tab class=\"kolabAccount\" />\n ";
476 $replacements['{servKolab}'] ="<tab class=\"servkolab\" name=\"Kolab\" />";
477 }
479 if($used_samba_version == 2) {
480 /* Do nothing for samba 2... */
481 } else {
482 /* Create LDAP connection, to check if there's a domain
483 object defined in the LDAP schema */
484 $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
486 /* Try to find a Samba Domain Objekt */
487 $ldap->search("(objectClass=sambaDomain)");
489 /* Something found ??? so we need to define ridbase an SID by ourselfs */
490 if($ldap->count()< 1) {
491 $replacements['{SID}']= "sid=\"123412-11\"";
492 $replacements['{RIDBASE}']= "ridbase=\"1000\"";
493 }
494 }
496 /* Data readed, types replaced, samba version detected and checked if
497 we need to add SID and RIDBASE. Check if there is an ivbbEntry in
498 the LDAP tree, in this case we will set the governmentmode to true.
499 Create LDAP connection, to check if theres a domain Objekt definen
500 in the LDAP schema. */
501 if(!isset($ldap)){
502 $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
503 }
505 /* Try to find a Samba Domain Objekt */
506 $ldap->search("(objectClass=ivbbEntry)");
508 /* Something found ??? so we need to define ridbase an SID by ourselfs */
509 if($ldap->count()> 0) {
510 $replacements['{GOVERNMENTMODE}']= "true";
511 }
513 /* Replace all colleted information with placeholder */
514 foreach($replacements as $key => $val) {
515 $str = preg_replace("/".$key."/",$val,$str);
516 }
518 if($ldapconf['mail'] == "disabled"){
519 $str = str_replace("mailMethod=\"{MAILMETHOD}\"","",$str);
520 }
523 /* Remove all unused plugins */
524 foreach($possible_plugins as $plugin) {
525 foreach($plugin as $key=>$val) {
526 if(in_array($plugin,$classes)) {
527 $str = preg_replace($val,"\n",$str);
528 }
529 }
530 }
531 }
533 return ((($str)));
534 }
537 /* Show setup_page 1 */
538 function show_setup_page1($withoutput = true)
539 {
540 $smarty = get_smarty();
541 $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
542 $smarty->assign ("tests", perform_php_checks($faults));
544 /* This var is true if anything went wrong */
545 if ($faults){
546 $smarty->assign("mode", "disabled");
547 }
549 /* This line displays the template only if (withoutput is set) */
550 if($withoutput){
551 $smarty->display (get_template_path('headers.tpl'));
552 }
554 if (isset($_SESSION['errors'])){
555 $smarty->assign("errors", $_SESSION['errors']);
556 }
558 if($withoutput){
559 $smarty->display (get_template_path('setup.tpl'));
560 }
562 return (!$faults);
563 }
566 /* Show setup_page 2 */
567 function show_setup_page2($withoutput = true)
568 {
569 $smarty = get_smarty();
570 $smarty->assign ("content", get_template_path('setup_step2.tpl'));
571 $smarty->assign ("tests", perform_additional_checks($faults));
573 if ($faults) {
574 $smarty->assign("mode", "disabled");
575 }
576 if($withoutput){
577 $smarty->display (get_template_path('headers.tpl'));
578 }
579 if (isset($_SESSION['errors'])) {
580 $smarty->assign("errors", $_SESSION['errors']);
581 }
582 if($withoutput){
583 $smarty->display (get_template_path('setup.tpl'));
584 }
586 return (!$faults);
587 }
590 function show_setup_page3($withoutput = true)
591 {
592 $smarty = get_smarty();
594 /* Take the Post oder the Sessioin saved data */
595 if(isset($_POST['uri'])){
596 $uri = $_POST['uri'];
597 } elseif(isset($_SESSION['ldapconf']['uri'])){
598 $uri = $_SESSION['ldapconf']['uri'];
599 }
601 /* If Page called first time, field is empty */
602 if((!isset($uri))||(empty($uri))){
603 $uri = "ldap://localhost:389";
604 }
606 /* if isset $uri save it to session */
607 if(isset($uri)) {
608 $_SESSION['ldapconf']['uri'] = $uri;
609 $smarty->assign ("uri", validate($uri));
610 }
612 /* No error till now */
613 $fault = false;
615 /* If we pushed the Button continue */
616 if(isset($_POST['continue3'])){
617 if(!isset($uri)) {
618 $fault = true;
620 /* Output the Error */
621 if($withoutput) {
622 print_red (_("You've to specify an ldap server before continuing!"));
623 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
624 }
625 }
626 } elseif (!$ds = @ldap_connect (validate($uri))) {
627 $fault =true;
629 /* Output the Error */
630 if($withoutput) {
631 print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
632 $smarty->assign ("uri", validate($uri));
633 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
634 }
635 } else {
636 /* Try to bind the connection */
637 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
639 /* if we can't bind , print error */
640 if (!$r = @ldap_bind ($ds)) {
641 $fault = true;
643 /* Output the Error */
644 if($withoutput) {
645 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
646 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
647 $smarty->assign ("uri", validate($uri));
648 }
649 } else {
650 $fault = false;
651 }
652 }
654 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
656 /* Load Header */
657 if($withoutput){
658 $smarty->display (get_template_path('headers.tpl'));
659 }
661 /* Set Errors to Smarty */
662 if (isset($_SESSION['errors'])) {
663 $smarty->assign("errors", $_SESSION['errors']);
664 }
666 /* Print out Template */
667 if($withoutput){
668 $smarty->display (get_template_path('setup.tpl'));
669 }
671 return (!$fault);
672 }
675 function show_setup_page4($withoutput = true)
676 {
677 $smarty= get_smarty();
679 if(!isset($_SESSION['ldapconf']['base'])){
680 $_SESSION['ldapconf']['base']= $base;
681 }
683 if(!isset($_SESSION['ldapconf']['base'])){
684 $_SESSION['ldapconf']['base']= $base;
685 }
686 require_once("class_password-methods.inc");
688 $fault = false;
689 $uri = $_SESSION['ldapconf']['uri'];
690 $ldapconf = $_SESSION['ldapconf'];
691 $arr_crypts= array();
692 $temp = "";
693 $checkvars = array("location", "admin", "password", "peopleou", "base",
694 "peopledn", "arr_crypts", "mail", "uidbase");
696 if(!isset($_SESSION['ldapconf']['arr_cryptkeys'])) {
697 require_once("class_password-methods.inc");
698 $tmp= passwordMethod::get_available_methods_if_not_loaded();
699 $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
700 }
702 if(!isset($_SESSION['ldapconf']['mail_methods'])) {
703 $_SESSION['ldapconf']['mail_methods']=array();
704 $temp = get_available_mail_classes();
705 $_SESSION['ldapconf']['mail_methods']= $temp['name'];
706 }
708 /* If there are some empty vars in ldapconnect -
709 these values also represent out default values */
710 if(!$ds = @ldap_connect (validate($uri))){
711 $fault = true;
712 if($withoutput){
713 print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
714 }
715 } elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
716 $fault = true;
717 if($withoutput){
718 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
719 }
720 } elseif(!$r= @ldap_bind ($ds)){
721 $fault = true;
722 if($withoutput){
723 print_red (_("Can't bind to the specified LDAP server! Please make sure that it is reachable for GOsa."));
724 }
725 } else {
726 $sr= @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
727 $attr= @ldap_get_entries($ds,$sr);
729 if((empty($attr))) {
730 $base= "dc=example,dc=net";
732 if($withoutput){
733 print_red(_("Bind to server successful, but the server seems to be completly empty, please check all informations twice"));
734 }
736 } else {
737 $base= $attr[0]['dn'];
738 }
739 }
741 if(!isset($_SESSION['ldapconf']['base'])){
742 $_SESSION['ldapconf']['base']= $base;
743 }
744 if(!isset($_SESSION['ldapconf']['admin'])){
745 $_SESSION['ldapconf']['admin']= "cn=ldapadmin,".$base;
746 }
747 if(!isset($_SESSION['ldapconf']['peopleou'])){
748 $_SESSION['ldapconf']['peopleou']= "ou=people";
749 }
750 if(!isset($_SESSION['ldapconf']['groupou'])){
751 $_SESSION['ldapconf']['groupou']= "ou=groups";
752 }
753 if(!isset($_SESSION['ldapconf']['peopledn'])){
754 $_SESSION['ldapconf']['peopledn']= "cn";
755 }
756 if(!isset($_SESSION['ldapconf']['password'])){
757 $_SESSION['ldapconf']['password']= "";
758 }
759 if(!isset($_SESSION['ldapconf']['location'])){
760 $_SESSION['ldapconf']['location']= "Example";
761 }
762 if(!isset($_SESSION['ldapconf']['uidbase'])){
763 $_SESSION['ldapconf']['uidbase']= "1000";
764 }
765 if(!isset($_SESSION['ldapconf']['mail'])){
766 $_SESSION['ldapconf']['mail']= 0;
767 }
768 $tmp= array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
769 if(!isset($_SESSION['ldapconf']['arr_crypts'])){
770 $_SESSION['ldapconf']['arr_crypts'] = $tmp['md5'];
771 }
773 /* check POST data */
774 if(isset($_POST['check'])) {
776 /* Check if all needed vars are submitted */
777 foreach($checkvars as $key) {
778 if($key == "peopleou"){
779 continue;
780 }
781 if($key == "groupou"){
782 continue;
783 }
785 if((isset($_POST[$key]))&&($_POST[$key]!="")) {
786 $_SESSION['ldapconf'][$key] = $_POST[$key];
787 } else {
788 if($withoutput) {
789 print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
790 }
791 $fault = true;
792 }
793 }
794 }
796 /* Transfer base */
797 if(isset($_POST['base'])){
798 $_SESSION['ldapconf']['base']= $_POST['base'];
799 }
801 $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
802 $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
804 foreach($_SESSION['ldapconf'] as $key => $val) {
805 $smarty->assign($key,$val);
806 }
808 if(isset($_POST['check'])) {
809 $ldap= new LDAP($_SESSION['ldapconf']['admin'],
810 $_SESSION['ldapconf']['password'],
811 $_SESSION['ldapconf']['uri']);
813 $m= schema_check($_SESSION['ldapconf']['uri'],
814 $_SESSION['ldapconf']['admin'],
815 $_SESSION['ldapconf']['password']);
816 $_SESSION['classes']= $m;
818 if ($ldap->error != "Success") {
819 if($withoutput) {
820 print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
821 }
822 $fault = true;
823 }
824 }
826 /* Set smarty output */
827 $smarty->assign ("content", get_template_path('setup_step4.tpl'));
828 $smarty->assign ("peopledns", array("cn", "uid"));
829 if($withoutput){
830 $smarty->display (get_template_path('headers.tpl'));
831 }
832 if(isset($_SESSION['errors'])) {
833 $smarty->assign("errors", $_SESSION['errors']);
834 }
835 if($withoutput){
836 $smarty->display (get_template_path('setup.tpl'));
837 }
839 return (!$fault);
840 }
843 function show_setup_page5($withoutput=true)
844 {
845 /* Get ldapconf */
846 $ldapconf= $_SESSION['ldapconf'];
848 /* get smarty */
849 $smarty = get_smarty();
851 if(isset($_SESSION['classes'])){
852 $classes = $_SESSION['classes'];
853 }
855 $info= posix_getgrgid(posix_getgid());
856 $smarty->assign("webgroup", $info['name']);
857 $smarty->assign("path", CONFIG_DIR);
858 $message= "<table class=\"check\">";
859 $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
861 if($withoutput) {
862 $smarty->assign ("schemas", view_schema_check($m));
863 $smarty->assign ("content", get_template_path('setup_finish.tpl'));
864 }
866 /* Output templates... */
867 if($withoutput){
868 $smarty->display (get_template_path('headers.tpl'));
869 }
870 if (isset($_SESSION['errors'])) {
871 $smarty->assign("errors", $_SESSION['errors']);
872 }
873 if($withoutput){
874 $smarty->display (get_template_path('setup.tpl'));
875 }
877 return(true);
878 }
881 function create_user_for_setup($withoutput=true)
882 {
883 global $samba;
885 $ldapconf = $_SESSION['ldapconf'];
886 $smarty = get_smarty();
888 if(isset($_SESSION['classes'])){
889 $classes= $_SESSION['classes'];
890 }
892 /* Everything runns perfect ...
893 So we do a last test on this page
894 is there a user with ACLs :all which will be able to adminsitrate GOsa
895 We check that, if this user or group is missing we ask for creating them */
896 $ldap= new LDAP($_SESSION['ldapconf']['admin'],
897 $_SESSION['ldapconf']['password'],
898 $_SESSION['ldapconf']['uri']);
900 /* Now we are testing for a group, with the rights :all */
901 $ldap->cd($ldapconf['base']);
902 $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
904 $group_cnt = $ldap->count();
905 $data = $ldap->fetch();
906 $create_user= false;
908 /* We need to create administrative user and group
909 because theres no group found */
910 if($group_cnt < 1) {
912 /* Set var to create user */
913 $create_user= true;
915 /* Output error */
916 if(($withoutput)&&(!isset($_POST['new_admin']))){
917 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
918 }
920 } else {
922 /* We found an Administrative Group, is there a user, too */
923 if(isset($data['memberUid'][0])) {
924 $ldap->search("(&(objectClass=gosaAccount)(objectClass=person))",array("uid=".$data['memberUid'][0]));
925 $data2 = $ldap->fetch();
926 }
928 /* We must create a user */
929 if (($ldap->count() < 1)||(!isset($data2))) {
930 $create_user = true;
931 if(($withoutput)&&(!isset($_POST['new_admin']))){
932 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
933 }
934 } else {
935 /* We don't need to add a user */
936 return(true);
937 }
939 }
941 /* We need to create a new user with group */
942 if(isset($_POST['new_admin']))
943 {
944 /* Adjust password attributes according to the samba version */
945 if (isset($classes['samba3'])) {
946 $samba= "2";
947 $lmPassword = "lmPassword";
948 $ntPassword = "ntPassword";
949 } else {
950 $samba= "3";
951 $lmPassword = "sambaLMPassword";
952 $ntPassword = "sambaNtPassword";
953 }
955 /* Nothing submitted */
956 if(( (empty($_POST['admin_name']))||(empty($_POST['admin_pass'])) )&&(!$create_user)) {
957 return(true);
958 }
960 /* We have the order to create on Admin ^^
961 Detect Samba version to define the Attribute names shown below */
962 $ldap->cd($ldapconf['base']);
964 /* Define the user we are going to create */
965 $dn= "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
966 $arr['objectClass'][0] ="person";
967 $arr['objectClass'][1] ="organizationalPerson";
968 $arr['objectClass'][2] ="inetOrgPerson";
969 $arr['objectClass'][3] ="gosaAccount";
970 $arr['uid'] = $_POST['admin_name'];
971 $arr['cn'] = $_POST['admin_name'];
972 $arr['sn'] = $_POST['admin_name'];
973 $arr['givenName'] = "GOsa main administrator";
974 $arr[$lmPassword] = "10974C6EFC0AEE1917306D272A9441BB";
975 $arr[$ntPassword] = "38F3951141D0F71A039CFA9D1EC06378";
976 $arr['userPassword'] = crypt_single($_POST['admin_pass'],"md5");
978 if( !$ldap->dn_exists ( $dn )){
979 $ldap->cd($dn);
980 $ldap->create_missing_trees($dn);
981 $ldap->add($arr);
982 if($ldap->error!="Success"){
983 print_red("Can't create user, and / or Group, possibly this problem depends on an empty LDAP server. Check your configuration and try again!");
984 }
985 }
987 /* There's already a group for administrator, so we only need to add the user */
988 if($group_cnt) {
990 if(!isset($data['memberUid'])) {
991 $arrr['memberUid']= $_POST['admin_name'];
992 } else {
993 $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
994 $arrr['memberUid'] = $data['memberUid'];
995 unset($arrr['memberUid']['count']);
996 }
998 $ldap->cd($data['dn']);
999 $ldap->modify($arrr);
1001 } else {
1003 $dn = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1004 $arrr['objectClass'][0]= "gosaObject";
1005 $arrr['objectClass'][1]= "posixGroup";
1006 $arrr['gosaSubtreeACL']= ":all";
1007 $arrr['cn'] = "administrators";
1008 $arrr['gidNumber'] = "999";
1009 $arrr['memberUid'] = $_POST['admin_name'];
1010 $ldap->cd($dn);
1011 $ldap->add($arrr);
1012 }
1014 return(true);
1015 } else {
1017 if(!($create_user)) {
1018 $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1019 $smarty->assign("exists",true);
1020 } else {
1021 $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1022 $smarty->assign("exists",false);
1023 }
1025 }
1027 /* Smarty output */
1028 if($withoutput){
1029 $smarty->display (get_template_path('headers.tpl'));
1030 }
1031 if (isset($_SESSION['errors'])) {
1032 $smarty->assign("errors", $_SESSION['errors']);
1033 }
1034 if($withoutput){
1035 $smarty->display (get_template_path('setup.tpl'));
1036 }
1038 return(false);
1039 }
1042 /* Returns the classnames auf the mail classes */
1043 function get_available_mail_classes()
1044 {
1045 $dir = opendir( "../include");
1046 $methods = array();
1047 $suffix = "class_mail-methods-";
1048 $lensuf = strlen($suffix);
1049 $prefix = ".inc";
1050 $lenpre = strlen($prefix);
1052 $i = 0;
1053 while (($file = readdir($dir)) !== false){
1055 if(stristr($file,$suffix)) {
1056 $lenfile = strlen($file);
1057 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1058 $methods['file'][$i] = $file;
1059 $methods[$i]['file'] = $file;
1060 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1061 $i++;
1062 }
1064 }
1066 return($methods);
1067 }
1069 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1070 ?>