84ce3d8c4baf01773457a589767fb1b51584a49a
1 <?php
3 function minimum_version($vercheck)
4 {
5 $minver = (int)str_replace('.', '', $vercheck);
6 $curver = (int)str_replace('.', '', phpversion());
8 if($curver >= $minver){
9 return (true);
10 }
12 return (false);
13 }
16 function check_schema_version($description, $version)
17 {
18 $desc= preg_replace("/^.* DESC\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $description);
20 return preg_match("/\(v$version\)/", $desc);
21 }
23 function view_schema_check($table)
24 {
25 $message="<table class=\"check\">";
26 foreach ($table as $key => $msg){
27 $message.= "<tr><td class=\"check\">$msg";
28 if(strstr($msg,"enabled")) {
29 $message.="</td><td style='text-align:center' ><img src=images/true.png alt='true' /></td></tr>";
30 }
31 else
32 {
33 $message.="</td><td style='text-align:center' ><img src=images/button_cancel.png alt='false' /></td></tr>";}
34 }
35 $message.="</table>";
36 return $message;
37 }
39 function schema_check($server, $admin, $password,$aff=0)
40 {
41 global $config;
44 $messages= array();
45 $required_classes= array(
46 "gosaObject" => array("version" => "2.1"),
47 "gosaAccount" => array("version" => "2.1.2"),
48 "gosaLockEntry" => array("version" => "2.1"),
49 "gosaCacheEntry" => array("version" => "2.1"),
50 "gosaDepartment" => array("version" => "2.1"),
52 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
53 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
54 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
56 "gosaUserTemplate" => array("version" => "2.1", "class" => "posixAccount","file" => "nis.schema"),
57 "gosaMailAccount" => array("version" => "2.1", "class" => "mailAccount","file" => "gosa+samba3.schema"),
58 "gosaProxyAccount" => array("version" => "2.1.2", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
59 "gosaApplication" => array("version" => "2.1", "class" => "appgroup","file" => "gosa.schema"),
60 "gosaApplicationGroup" => array("version" => "2.1", "class" => "appgroup","file" => "gosa.schema"),
62 "GOhard" => array("version" => "2.1", "class" => "terminals","file" => "goto.schema"),
63 "gotoTerminal" => array("version" => "2.0", "class" => "terminals","file" => "goto.schema"),
64 "goServer" => array("version" => "2.1","class" => "server","file" => "goserver.schema"),
65 "goTerminalServer" => array("version" => "2.1", "class" => "terminals","file" => "goto.schema"),
66 "goNfsServer" => array("version" => "2.1", "class" => "terminals","file" => "goto.schema"),
67 "goNtpServer" => array("version" => "2.1", "class" => "terminals","file" => "goto.schema"),
68 "goSyslogServer" => array("version" => "2.1", "class" => "terminals","file" => "goto.schema"),
69 "goLdapServer" => array("version" => "2.1"),
70 "goCupsServer" => array("version" => "2.1", "class" => array("posixAccount", "terminals"),),
71 "goImapServer" => array("version" => "2.1", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
72 "goKrbServer" => array("version" => "2.1"),
73 "goFaxServer" => array("version" => "2.1", "class" => "gofaxAccount","file" => "gofax.schema"),
75 );
77 /* Build LDAP connection */
78 $ds= ldap_connect ($server);
79 if (!$ds) {
80 return (array(_("Can't bind to LDAP. No schema check possible!")));
81 }
82 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
83 $r= ldap_bind ($ds, $admin, $password);
85 /* Get base to look for schema */
86 $sr = @ldap_read ($ds, "", "objectClass=*", array("subschemaSubentry"));
87 $attr= @ldap_get_entries($ds,$sr);
88 if (!isset($attr[0]['subschemasubentry'][0])){
89 return (array(_("Can't get schema information from server. No schema check possible!")));
90 }
92 /* Get list of objectclasses */
93 $nb= $attr[0]['subschemasubentry'][0];
94 $objectclasses= array();
95 $sr= ldap_read ($ds, $nb, "objectClass=*", array("objectclasses"));
96 $attrs= ldap_get_entries($ds,$sr);
97 if (!isset($attrs[0])){
98 return (array(_("Can't get schema information from server. No schema check possible!")));
99 }
100 foreach ($attrs[0]['objectclasses'] as $val){
101 $name= preg_replace("/^.* NAME\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $val);
102 if ($name != $val){
103 $objectclasses[$name]= $val;
104 }
105 }
106 /* Walk through objectclasses and check if they are needed or not */
107 foreach ($required_classes as $key => $value){
108 if (isset($value['class'])){
109 if (!is_array($value['class'])){
110 $classes= array($value['class']);
111 } else {
112 $classes= $value['class'];
113 }
115 /* Check if we are using the class that requires */
116 foreach($classes as $class){
117 if (!isset($objectclasses[$key])){
118 $messages[$key]= sprintf(_("Optional objectclass '%s' required by plugin '%s' is not present in LDAP setup"), $key, $class);
119 } else {
120 if (!check_schema_version($objectclasses[$key], $value['version'])){
121 $messages[$key]= sprintf(_("Optional objectclass '%s' required by plugin '%s' does not have version %s"), $key, $class, $value['version']);
122 }else {
123 if(!isset($affich2[$class])){
124 $affich2[$class]="Support for <b>$class</b> enabled <td class=\"check\"> ".$value['file']."</td>";
125 }
126 }
127 }
129 }
130 } else {
131 /* Required class */
132 if (!isset($objectclasses[$key])){
133 $messages[$key]= sprintf(_("Required objectclass '%s' is not present in LDAP setup"), $key);
134 } else {
135 if (!check_schema_version($objectclasses[$key], $value['version'])){
136 $messages[$key]= sprintf(_("Required objectclass '%s' does not have version %s"), $key, $value['version']);
137 }
138 }
139 }
140 }
142 /* Check for correct samba parameters */
143 if (!isset($objectclasses['sambaSamAccount'])){
144 $messages['samba3']= _("<b>SAMBA 3</b> support disabled, no schema seems to be installed");
145 $affich['samba3']= $messages['samba3']."<td class=\"check\">gosa+samba3.schema</td>";
146 }else{$affich['samba3']=_("<b>SAMBA 3</b> support enabled<td class=\"check\">gosa+samba3.schema</td>");}
148 if (!isset($objectclasses['sambaAccount'])){
149 $messages['samba2']= _("<b>SAMBA 2</b> support disabled, no schema seems to be installed");
150 $affich['samba2']=$messages['samba2']."<td class=\"check\">samba.schema</td>";
151 }else{$affich['samba2']=_("<b>SAMBA 2</b> support enabled<td class=\"check\">samba.schema</td>");}
153 /* Check pureftp/dns/ */
154 if (!isset($objectclasses['PureFTPdUser'])){
155 $messages['pureftp']= _("Support for <b>pureftp</b> disabled, no schema seems to be installed");
156 $affich['pureftp']= $messages['pureftp']."<td class=\"check\">pureftpd.schema</td>";
157 }else{$affich['pureftp']=_("Support for <b>pureftp</b> enabled<td class=\"check\">pureftpd.schema</td>");}
159 if (!isset($objectclasses['gosaWebdavAccount'])){
160 $messages['webdav']= _("Support for <b>WebDAV</b> disabled, no schema seems to be installed");
161 $affich['webdav']=$messages['webdav']."<td class=\"check\"></td>";
162 }else{$affich['webdav']=_("Support for <b>WebDAV</b> enabled<td class=\"check\">gosa+samba3.schema</td>");}
164 if (!isset($objectclasses['phpgwAccount'])){
165 $messages['phpgroupware']= _("Support for <b>phpgroupware</b> disabled, no schema seems to be installed");
166 $affich['phpgroupware']=$messages['phpgroupware']."<td class=\"check\">phpgwaccount.schema</td>";
167 }else{$affich['phpgroupware']=_("Support for <b>phpgroupware</b> enabled<td class=\"check\">phpgwaccount.schema</td>");}
169 if (!isset($objectclasses['goFonAccount'])){
170 $messages['phoneaccount']= _("Support for <b>gofon</b> disabled, no schema seems to be installed");
171 $affich['phoneaccount']=$messages['phoneaccount']."<td class=\"check\">gofon.schema</td>";
172 }else{$affich['phoneaccount']=_("Support for <b>gofon</b> enabled<td class=\"check\">gofon.schema</td>");}
175 if(($_SESSION['ldapconf']['mail_methods'][$_SESSION['ldapconf']['mail']] == "kolab"))
176 if(!isset($objectclasses['kolabInetOrgPerson']))
177 {
178 $messages['kolab']= _("Support for <b>Kolab</b> disabled, no schema seems to be installed, setting mail-method to cyrus");
179 $tmp = array_flip($_SESSION['ldapconf']['mail_methods']);
180 $_SESSION['ldapconf']['mail']=$tmp['cyrus'];
181 $affich['kolab']=$messages['kolab']."<td class=\"check\">kolab2.schema</td>";
182 }else{$affich['kolab']=_("Support for <b>Kolab</b> enabled<td class=\"check\">gofon.schema</td>");}
185 if($aff==0)return ($messages);
186 else return(array_merge($affich,$affich2));
189 }
193 function check(&$faults, $message, $description, $test, $required= TRUE)
194 {
195 $msg= "<table class='check'><tr><td class='check' style='font-size:14px;'>$message</td><td rowspan=2 style='vertical-align:middle; text-align:center;width:45px;'>";
196 if ($test){
197 $msg.= _("OK")."<br>";
198 } else {
199 if (!$required){
200 $msg.="<font color=red>"._("Ignored")."</font><br>";
201 } else {
202 $msg.="<font color=red>"._("Failed")."</font><br>";
203 $faults++;
204 }
205 }
206 $msg.= "</td></tr><tr><td class='check' style='padding-left:20px;background-color:#F0F0F0;'>$description</td></tr></table><br>";
208 return $msg;
209 }
211 function perform_php_checks(&$faults)
212 {
213 global $check_globals;
215 $faults= 0;
216 $msg= "";
218 $msg.= "<h1>"._("PHP setup inspection")."</h1>";
219 $msg.= check ( $faults, _("Checking for PHP version (>=4.1.0)"),
220 _("PHP must be of version 4.1.0 or above for some functions and known bugs in PHP language."),
221 minimum_version('4.1.0'));
223 $msg.= check ( $faults, _("Checking if register_globals is set to 'off'"),
224 _("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."),
225 $check_globals == 0, FALSE);
227 $msg.= check ( $faults, _("Checking for ldap module"),
228 _("This is the main module used by GOsa and therefore really required."),
229 function_exists('ldap_bind'));
231 $msg.= check ( $faults, _("Checking for gettext support"),
232 _("Gettext support is required for internationalized GOsa."), function_exists('bindtextdomain'));
234 $msg.= check ( $faults, _("Checking for iconv support"),
235 _("This module is used by GOsa to convert samba munged dial informations and is therefore required."),
236 function_exists('iconv'));
238 $msg.= check ( $faults, _("Checking for mhash module"),
239 _("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."),
240 function_exists('mhash'), FALSE);
242 $msg.= check ( $faults, _("Checking for imap module"),
243 _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users."),
244 function_exists('imap_open'));
245 $msg.= check ( $faults, _("Checking for getacl in imap"),
246 _("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."),
247 function_exists('imap_getacl'), FALSE);
248 $msg.= check ( $faults, _("Checking for mysql module"),
249 _("MySQL support is needed for reading GOfax reports from databases."),
250 function_exists('mysql_query'), FALSE);
251 $msg.= check ( $faults, _("Checking for cups module"),
252 _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module."),
253 function_exists('cups_get_dest_list'), FALSE);
254 $msg.= check ( $faults, _("Checking for kadm5 module"),
255 _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network."),
256 function_exists('kadm5_init_with_password'), FALSE);
257 return ($msg);
258 }
261 function perform_additional_checks(&$faults)
262 {
263 # Programm check
264 $msg= "<h1>"._("Checking for some additional programms")."</h1>";
266 # Image Magick
267 $query= "LC_ALL=C LANG=C convert -help";
268 $output= shell_exec ($query);
269 if ($output != ""){
270 $lines= split ("\n", $output);
271 $version= preg_replace ("/^Version:[^I]+ImageMagick ([^\s]+).*/", "\\1", $lines[0]);
272 list($major, $minor)= split("\.", $version);
273 $msg.= check ( $faults, _("Checking for ImageMagick (>=5.4.0)"),
274 _("ImageMagick is used to convert user supplied images to fit the suggested size and the unified JPEG format."),
275 ($major > 5 || ($major == 5 && $minor >= 4)));
276 } else {
277 $msg.= check ( $faults, _("Checking imagick module for PHP"),
278 _("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);
279 }
281 # Check for fping
282 $query= "LC_ALL=C LANG=C fping -v 2>&1";
283 $output= shell_exec ($query);
284 $have_fping= preg_match("/^fping:/", $output);
285 $msg.= check ( $faults, _("Checking for fping utility"),
286 _("The fping utility is only used if you've got a thin client based terminal environment running."),
287 $have_fping, FALSE);
289 # Check for smb hash generation tool
290 $query= "mkntpwd 2>&1";
291 $output= shell_exec ($query);
292 $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
293 $alt = 0;
295 if (!$have_mkntpwd){
296 $query= "LC_ALL=C LANG=C perl -MCrypt::SmbHash -e 'ntlmgen \"PASSWD\", \$lm, \$nt; print \"\${lm}:\${nt}\\n\";' &>/dev/null";
297 system ($query, $ret);
298 $alt= ($ret == 0);
299 }
301 $msg.= check ( $faults, _("Checking for a way to generate LM/NT password hashes"),
302 _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes."),
303 ($have_mkntpwd || $alt));
304 # checking for some PHP.ini Options
306 /* seesio.auto_start should be off, in order to without trouble*/
308 $arra = ini_get_all();
310 /* This array contains folling info now :
311 global_value 0
312 local_value 0
313 access 7
315 -->Access types
316 PHP_INI_USER 1 Entry can be set in user scripts
317 PHP_INI_PERDIR 2 Entry can be set in php.ini, .htaccess or httpd.conf
318 PHP_INI_SYSTEM 4 Entry can be set in php.ini or httpd.conf
319 PHP_INI_ALL 7 Entry can be set anywhere
321 */
323 $session_auto_start = ($arra['session.auto_start']);
324 $implicit_flush = ($arra['implicit_flush']);
325 $max_execution_time = ($arra['max_execution_time']);
326 $memory_limit = ($arra['memory_limit']);
327 $expose_php = ($arra['expose_php']);
328 $magic_quotes_gpc = ($arra['magic_quotes_gpc']);
329 $register_globals = ($arra['register_globals']);
332 // auto_register
333 $msg.= check ( $faults, _("PHP.ini check -> session.auto_register"),
334 _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini musst be 'Off'."),
335 (!$session_auto_start['local_value']));
339 //implicit_flush
340 $msg.= check ( $faults, _("PHP.ini check -> implicit_flush"),
341 _("This Option defines the Ouput handling, turn this Option off, to increase performance."),
342 !$implicit_flush['local_value'],0,false);
344 //max_execution_time
345 if($max_execution_time['local_value'] < 30 )
346 $max_execution_time['local_value']=false;
347 $msg.= check ( $faults, _("PHP.ini check -> max_execution_time"),
348 _("The Execution time, should be 30 seconds minimun, cause some actions will need huge ammount of time ."),
349 $max_execution_time['local_value'],0,false);
351 //memory_limit
352 if($memory_limit['local_value'] < 8 )
353 $memory_limit['local_value']=false;
354 $msg.= check ( $faults, _("PHP.ini check -> memory_limit"),
355 _("GOsa need at least 8M of memory, less will cause unpredictable errors, sometimes without error message!. Best would be 32 M here."),
356 !$implicit_flush['local_value'],0,false);
358 //expose_php
359 $msg.= check ( $faults, _("PHP.ini check -> expose_php"),
360 _("PHP won't send any Information about the Server you are running, should be a security fact."),
361 !$implicit_flush['local_value'],0,false);
363 //magic_quotes_gpc
364 $msg.= check ( $faults, _("PHP.ini check -> magic_quotes_gpc"),
365 _("Security option, php will escape all quotes in strings ."),
366 $magic_quotes_gpc['local_value'],0,false);
368 return $msg;
369 }
373 //! Added by Hickert
374 //
375 // Parse /contrib/gosa.conf to set user defined values
376 //This function may create the ldap.conf
377 // Lets try
378 function parse_contrib_conf()
379 {
380 /* First gather all needed informations */
384 /* Variables */
385 $str = "";
386 $used_samba_version = 0;
387 $query = "";
388 $fp = false;
389 $output = "";
390 $needridbase_sid = false;
391 $pwdhash = "";
392 $replacements = array();
393 $ldapconf = $_SESSION['ldapconf']; // The Installation information
394 $classes = $_SESSION['classes']; // Class information needed to define which features are enabled
395 $possible_plugins = array();
397 if(isset($classes['samba3'])) // means Samba 3 is disabled
398 $used_samba_version = 2;
399 else
400 $used_samba_version = 3;
403 if(file_exists("/usr/lib/gosa/mkntpasswd")) {
404 $pwdhash = "/usr/lib/gosa/mkntpasswd";
405 }
406 elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))) {
407 $pwdhash= "mkntpwd";
408 } else {
409 $pwdhash=addslashes(' perl -MCrypt::SmbHash -e "ntlmgen \"\$ARGV[0]\", \$lm, \$nt; print \"\${lm}:\${nt}\n\";" $1');
410 // $pwdhash= 'perl -MCrypt::SmbHash -e \"ntlmgen \\"\\$ARGV[0]\\", \\$lm, \\$nt; print \\"\\${lm}:\\${nt}\\\";\"';
411 }
414 // Define which variables will be replaced
415 $replacements['{LOCATIONNAME}'] = $ldapconf['location'];
416 $replacements['{SAMBAVERSION}'] = $used_samba_version;
417 $replacements['{LDAPBASE}'] = $ldapconf['base'];
418 $replacements['{LDAPADMIN}'] = $ldapconf['admin'];
419 $replacements['{DNMODE}'] = $ldapconf['peopledn'];
420 $replacements['{LDAPHOST}'] = $ldapconf['uri'];
421 $replacements['{PASSWORD}'] = $ldapconf['password'];
422 $replacements['{CRYPT}'] = $ldapconf['arr_cryptkeys'][$ldapconf['arr_crypts']];
423 $replacements['{SID}'] = "";
424 $replacements['{RIDBASE}'] = "";
425 $replacements['{MAILMETHOD}'] = $ldapconf['mail_methods'][$ldapconf['mail']];
426 $replacements['{SMBHASH}'] = $pwdhash;
427 $replacements['{GOVERNMENTMODE}'] = "false";
428 $replacements['{kolabAccount}'] = "";
432 // This array contains all preg_replace syntax to delete all unused plugins
433 // THE kEY MUST BE THE CLASSNAME so we can check it with $ldapconf['classes']
435 $possible_plugins['fonreport'][] ="'\n.*<plugin.*fonreport+.*\n.*>.*\n'i";
436 $possible_plugins['phoneaccount'][] ="'\n.*<tab.*phoneAccount.*>.*\n'i";
438 $possible_plugins['logview'][] ="'\n.*<plugin.*logview+.*\n.*>.*\n'i";
440 $possible_plugins['pureftp'][] ="'\n.*<tab.*pureftp.*>.*\n'i";
442 $possible_plugins['webdav'][] ="'\n.*<tab.*webdav.*>.*\n'i";
444 $possible_plugins['phpgroupware'][] ="'\n.*<tab.*phpgroupware.*>'i";
447 // Header information
448 // Needed to send the generated gosa.conf to the browser
449 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
450 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
451 header("Cache-Control: no-cache");
452 header("Pragma: no-cache");
453 header("Cache-Control: post-check=0, pre-check=0");
454 header("Content-type: text/plain");
456 if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT']))
457 {
458 header('Content-Disposition: filename="gosa.conf"');
459 } else {
460 header('Content-Disposition: attachment; filename="gosa.conf"');
461 }
464 if(!$fp=fopen(CONFIG_TEMPLATE_DIR."/gosa.conf","r"))
465 {
466 echo "Can't open file ".CONFIG_TEMPLATE_DIR."/gosa.conf";
467 // Don't write anything else
468 }
469 else
470 {
471 // Read out Data .....
472 while(!feof($fp))
473 {
474 $str.= fread($fp,512);
475 }
479 if($ldapconf['mail_methods'][$ldapconf['mail']]=="kolab")
480 {
481 $replacements['{kolabAccount}'] ="<tab class=\"kolabAccount\" />";
482 }
488 // Lets check which samba version we will use
490 // in case of samba 2 we don't need to add additional objets in gosa.conf
491 // in case of samba 3 we musst detect if theres an objectType = SambaObjekt defined
492 // if theres is one, then do nothing, because the setup will detect the the SID themself
493 // if theres none defined add SID and RIDBASE to gosa.conf
496 if($used_samba_version == 2)
497 {
498 // Do nothing ...
499 }
500 else
501 {
502 // Create LDAP connection, to check if theres a domain Objekt definen in the Ldap scheme
503 $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
506 // Try to find a Samba Domain Objekt
507 $ldap->search("(objectClass=sambaDomain)");
509 // Something found ??? so we need to define ridbase an SID by ourselfs
510 if($ldap->count()< 1)
511 {
512 $replacements['{SID}'] = "sid=\"123412-11\"";
513 $replacements['{RIDBASE}'] = "ridbase=\"1000\"";
514 }
515 }// else --> $used_samba_version == 2
517 // Data readed, types replaced, samba version detected and checked if we need to add SID and RIDBASE
520 // Check if there is an ivbbEntry in the LDAP tree, in this case we will set the governmentmode to true
521 // Create LDAP connection, to check if theres a domain Objekt definen in the Ldap scheme
523 if(!isset($ldap))
524 $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
527 // Try to find a Samba Domain Objekt
528 $ldap->search("(objectClass=ivbbEntry)");
530 // Something found ??? so we need to define ridbase an SID by ourselfs
531 if($ldap->count()> 0)
532 {
533 $replacements['{GOVERNMENTMODE}'] = "true";
534 }
537 // Replace all colleted information with placeholder
538 foreach($replacements as $key => $val)
539 {
540 $str = preg_replace("/".$key."/",$val,$str);
541 // $str = ereg_replace($key,$val,$str);
542 }
544 // Remove all unused plugins
545 foreach($possible_plugins as $plugin)
546 {
547 foreach($plugin as $key=>$val)
548 {
549 if(in_array($plugin,$classes))
550 {
551 $str = preg_replace($val,"\n",$str);
552 }
553 }
554 }
557 }// else --> !$fp=fopen("../contrib/gosa.conf","r")
559 return ((($str)));
560 }
563 // This ist the first page shown in setup
564 // This page test some packages, like php version, ldap_module aso
565 // The funtion don't save anything, it tests only, when withoutput = false
566 // (called from setup.php);
567 function show_setup_page1($withoutput = true)
568 {
569 $smarty = get_smarty();
571 $smarty->assign ("content", get_template_path('setup_introduction.tpl'));
572 $smarty->assign ("tests", perform_php_checks($faults));
576 // This var is true if there is anything went wrong
577 if ($faults)
578 {
579 $smarty->assign("mode", "disabled");
580 }
582 // This line displays the template only if (withoutput is set)
583 if($withoutput)
584 $smarty->display (get_template_path('headers.tpl'));
586 if (isset($_SESSION['errors']))
587 {
588 $smarty->assign("errors", $_SESSION['errors']);
589 }
591 if($withoutput)
592 $smarty->display (get_template_path('setup.tpl'));
594 return (!$faults);
595 }
603 /* Shows Setup_page 2*/
604 function show_setup_page2($withoutput = true)
605 {
606 $smarty = get_smarty();
608 $smarty->assign ("content", get_template_path('setup_step2.tpl'));
609 $smarty->assign ("tests", perform_additional_checks($faults));
611 if ($faults) {
612 $smarty->assign("mode", "disabled");
613 }
614 if($withoutput){
615 $smarty->display (get_template_path('headers.tpl'));
616 }
618 if (isset($_SESSION['errors'])) {
619 $smarty->assign("errors", $_SESSION['errors']);
620 }
621 if($withoutput){
622 $smarty->display (get_template_path('setup.tpl'));
623 }
624 return (!$faults);
625 }
628 /* Setup page 3 asks for the server address
629 "Now we're going to include your LDAP server and create an initial configuration"*/
630 function show_setup_page3($withoutput = true)
631 {
633 // Take the Post oder the Sessioin saved data
634 if(isset($_POST['uri']))
635 $uri = $_POST['uri'];
636 elseif(isset($_SESSION['ldapconf']['uri']))
637 $uri = $_SESSION['ldapconf']['uri'];
639 // If Page called first time, field is empty
640 if((!isset($uri))||(empty($uri)))
641 $uri = "ldap://localhost:389";
644 $smarty = get_smarty();
646 // if isset $uri save it to session
647 if(isset($uri))
648 {
649 $_SESSION['ldapconf']['uri'] = $uri;
650 $smarty->assign ("uri", validate($uri));
651 }
654 // No error till now
655 $fault = false;
658 // If we pushed the Button continue
659 if(isset($_POST['continue3']))
660 if(!isset($uri))
661 {
662 $fault = true;
663 // Output the Error
664 if($withoutput)
665 {
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 {
672 $fault =true;
673 // Output the Error
674 if($withoutput)
675 {
676 print_red (_("Can't connect to the specified LDAP server! Please make sure that is reachable for GOsa."));
677 $smarty->assign ("uri", validate($uri));
678 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
679 }
680 }
681 else
682 {
683 // Try to bind the connection
684 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
686 // if we can't bind , print error
687 if (!$r = @ldap_bind ($ds))
688 {
689 $fault = true;
690 // Output the Error
691 if($withoutput)
692 {
693 print_red (_("Can't bind to the specified LDAP server! Please make sure that is reachable for GOsa."));
694 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
695 $smarty->assign ("uri", validate($uri));
696 }
697 }
698 else
699 {
700 $fault = false;
701 }
702 }
705 $smarty->assign ("content", get_template_path('setup_step3.tpl'));
708 // Load Header
709 if($withoutput)
710 $smarty->display (get_template_path('headers.tpl'));
712 // Set Errors to Smarty
713 if (isset($_SESSION['errors']))
714 {
715 $smarty->assign("errors", $_SESSION['errors']);
716 }
718 // Print out Template
719 if($withoutput)
720 $smarty->display (get_template_path('setup.tpl'));
724 return (!$fault);
725 }
729 // Setup page 4
730 // This page asked for detailed info, like base dn or admin user
731 // if evrything is ok , but there's a missing user with ACL :all we show a a user creation page before we show page 5
732 function show_setup_page4($withoutput = true)
733 {
736 require_once("class_password-methods.inc");
738 error_reporting(E_ALL);
743 $fault = false; // If an error occures we set this var to true
744 $smarty = get_smarty(); // Our smarty instance
745 $uri = $_SESSION['ldapconf']['uri']; // This is the the connect path to the ldapserver like ldap://lo..
746 $ldapconf = $_SESSION['ldapconf']; // The ldap Configuration informations, we collected while setup
747 $arr_crypts = array(); // array which includes contains all possible password crypting methods
748 $temp = ""; // Temp
749 $checkvars = array("location","admin","password","peopleou","peopledn","arr_crypts","mail","uidbase");
752 if(!isset($_SESSION['ldapconf']['arr_cryptkeys']))
753 {
754 require_once("class_password-methods.inc");
755 $tmp = passwordMethod::get_available_methods_if_not_loaded();
756 $_SESSION['ldapconf']['arr_cryptkeys']= $tmp['name'];
757 }
761 if(!isset($_SESSION['ldapconf']['mail_methods']))
762 {
763 $_SESSION['ldapconf']['mail_methods']=array();
764 $temp = get_available_mail_classes();
765 $_SESSION['ldapconf']['mail_methods']= $temp['name'];
766 }
771 // If there are some empty vars in ldapconnect
772 // This values also represent out default values
774 # first try to get $base
775 if(!$ds = @ldap_connect (validate($uri)))
776 {
777 $fault = true;
778 }
779 elseif(!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3))
780 {
781 $fault = true;
782 }
783 elseif(! $r = @ldap_bind ($ds))
784 {
785 $fault = true;
786 }
787 else
788 {
789 $sr= @ldap_search ($ds, "", "objectClass=*", array("namingContexts"));
792 $attr= @ldap_get_entries($ds,$sr);
793 if((empty($attr)))
794 {
795 $base= "dc=example,dc=net";
798 if($withoutput)
799 print_red(_("Bind to server successfull, but the server seems to be completly empty, please check all informations twice"));
801 }
802 else
803 {
804 $base= $attr[0]['dn'];
805 }
806 }
810 if(!isset($_SESSION['ldapconf']['base'])) $_SESSION['ldapconf']['base'] = $base;
811 if(!isset($_SESSION['ldapconf']['admin'])) $_SESSION['ldapconf']['admin'] = "cn=ldapadmin,".$base;
812 if(!isset($_SESSION['ldapconf']['peopleou'])) $_SESSION['ldapconf']['peopleou'] = "ou=people";
813 if(!isset($_SESSION['ldapconf']['groupou'])) $_SESSION['ldapconf']['groupou'] = "ou=groups";
814 if(!isset($_SESSION['ldapconf']['peopledn'])) $_SESSION['ldapconf']['peopledn'] = "cn";
815 if(!isset($_SESSION['ldapconf']['password'])) $_SESSION['ldapconf']['password'] = "";
816 if(!isset($_SESSION['ldapconf']['location'])) $_SESSION['ldapconf']['location'] = "Example";
817 if(!isset($_SESSION['ldapconf']['uidbase'])) $_SESSION['ldapconf']['uidbase'] = "1000";
818 if(!isset($_SESSION['ldapconf']['mail'])) $_SESSION['ldapconf']['mail'] = 0;
819 $tmp = array_flip($_SESSION['ldapconf']['arr_cryptkeys']);
820 if(!isset($_SESSION['ldapconf']['arr_crypts'])) $_SESSION['ldapconf']['arr_crypts'] = $tmp['md5'];
823 // check Post data
825 if(isset($_POST['check']))
826 {
827 // Check if all needed vars are submitted
828 foreach($checkvars as $key)
829 {
830 if((isset($_POST[$key]))&&($_POST[$key]!=""))
831 {
832 $_SESSION['ldapconf'][$key] = $_POST[$key];
833 }
834 else
835 {
836 if($withoutput)
837 {
838 print_red(sprintf(_("You're missing the required attribute '%s' from this formular. Please complete!"), $key));
839 }
840 $fault = true;
841 }
842 }
844 // check if another base is given ... (ldapadmin...dc=base,dc=de) ..
846 $base = $_SESSION['ldapconf']['admin'];
847 $tmp = array_reverse ( split(",",$base));
848 $base = $tmp[1].",".$tmp[0];
849 $_SESSION['ldapconf']['base'] = $base;
852 }
856 $smarty->assign("arr_cryptkeys",$_SESSION['ldapconf']['arr_cryptkeys']);
857 $smarty->assign("mail_methods", $_SESSION['ldapconf']['mail_methods']);
859 foreach($_SESSION['ldapconf'] as $key => $val)
860 {
861 $smarty->assign($key,$val);
862 }
864 if(isset($_POST['check']))
865 {
866 $ldap= new LDAP($_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password'], $_SESSION['ldapconf']['uri']);
868 $m= schema_check($_SESSION['ldapconf']['uri'], $_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password']);
869 $_SESSION['classes']= $m;
871 if ($ldap->error != "Success")
872 {
873 if($withoutput)
874 {
875 print_red(sprintf(_("Can't log into LDAP server. Reason was: %s."), $ldap->get_error()));
876 }
877 $fault = true;
878 }
879 }
883 // Set smarty output
884 $smarty->assign ("content", get_template_path('setup_step4.tpl'));
886 $smarty->assign ("peopledns", array("cn", "uid"));
887 if($withoutput)
888 $smarty->display (get_template_path('headers.tpl'));
890 if(isset($_SESSION['errors']))
891 {
892 $smarty->assign("errors", $_SESSION['errors']);
893 }
894 if($withoutput)
895 $smarty->display (get_template_path('setup.tpl'));
898 return (!$fault);
901 }
906 // This page shows your configuration
907 // and wants you to download the gosa.conf ....
908 function show_setup_page5($withoutput=true)
909 {
910 // Get ldapconf
911 $ldapconf= $_SESSION['ldapconf'];
913 // get smarty
914 $smarty = get_smarty();
916 if(isset($_SESSION['classes']))
917 $classes = $_SESSION['classes'];
919 $info= posix_getgrgid(posix_getgid());
920 $smarty->assign ("webgroup", $info['name']);
921 $smarty->assign ("path", CONFIG_DIR);
922 $message = "";
923 $message.="<table class=\"check\">";
924 $m= schema_check($ldapconf['uri'], $ldapconf['admin'], $ldapconf['password'],1);
926 if($withoutput)
927 {
928 $smarty->assign ("schemas", view_schema_check($m));
929 $smarty->assign ("content", get_template_path('setup_finish.tpl'));
930 }
931 // Output templates ....
933 if($withoutput)
934 $smarty->display (get_template_path('headers.tpl'));
936 if (isset($_SESSION['errors']))
937 {
938 $smarty->assign("errors", $_SESSION['errors']);
939 }
940 if($withoutput)
941 $smarty->display (get_template_path('setup.tpl'));
942 return(true);
943 }
956 // this function is called by setup step 5, in order to create a missinf Administrator
957 // and or Administrational user
958 // on success go on with setup_page5
959 // else show this page aggain
960 function create_user_for_setup($withoutput=true)
961 {
963 error_reporting(E_ALL);
965 global $samba;
967 $ldapconf = $_SESSION['ldapconf'];
968 $smarty = get_smarty();
972 if(isset($_SESSION['classes']))
973 $classes= $_SESSION['classes'];
975 // Everything runns perfect ...
976 // So we do a last test on this page
977 // is there a user with ACLs :all which will be able to adminsitrate GOsa
978 // We check that, if this user or group is missing we ask for creating them
980 $ldap= new LDAP($_SESSION['ldapconf']['admin'], $_SESSION['ldapconf']['password'], $_SESSION['ldapconf']['uri']);
982 // $ldap= new LDAP($ldapconf['admin'], $ldapconf['password'], $ldapconf['uri']);
984 // Now we are testing for a group, with the rights :all
985 $ldap->cd($ldapconf['base']);
986 $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
988 $group_cnt = $ldap->count();
989 $data = $ldap->fetch();
990 $create_user = false;
992 // We need to create Administrative user and group
993 // Because theres no Group found
994 if($group_cnt < 1)
995 {
996 // Set var to create user
997 $create_user = true;
999 // Output error
1000 if(($withoutput)&&(!isset($_POST['new_admin'])))
1001 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1002 }
1003 else
1004 {
1006 // We found an Administrative Group, is there a user too
1007 if(isset($data['memberUid'][0]))
1008 {
1009 $ldap->search("(&(objectClass=gosaAccount)(objectClass=person))",array("uid=".$data['memberUid'][0]));
1010 $data2 = $ldap->fetch();
1011 $user_cnt = $ldap->count();
1012 }
1014 // We must create a user
1015 if (($ldap->count() < 1)||(!isset($data2)))
1016 {
1017 $create_user = true;
1018 if(($withoutput)&&(!isset($_POST['new_admin'])))
1019 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
1020 }
1021 else
1022 {
1023 // We don't need to add a user
1024 return(true);
1025 }
1027 }// if($group_cn)
1029 // We need to create a new user with group
1030 if(isset($_POST['new_admin']))
1031 {
1032 // Is there a running user ?
1033 // Then add additional
1035 if (isset($classes['samba3']))
1036 {
1037 $samba= "2";
1038 $lmPassword = "lmPassword";
1039 $ntPassword = "ntPassword";
1040 } else {
1041 $samba= "3";
1042 $lmPassword = "sambaLMPassword";
1043 $ntPassword = "sambaNtPassword";
1044 }
1047 // Nothing submitted
1048 if(( (empty($_POST['admin_name']))||(empty($_POST['admin_pass'])) )&&(!$create_user))
1049 {
1050 return(true);
1051 }
1053 // We have the order to create on Admin ^^
1054 // Detect Samba version to define the Attribute names shown below
1055 // go to base
1056 $ldap->cd($ldapconf['base']);
1058 // Define the user we are going to create
1059 $dn = "cn=".$_POST['admin_name'].",".$ldapconf['peopleou'].",".$ldapconf['base'];
1062 $arr['objectClass'][0] ="person";
1063 $arr['objectClass'][1] ="organizationalPerson";
1064 $arr['objectClass'][2] ="inetOrgPerson";
1065 $arr['objectClass'][3] ="gosaAccount";
1066 $arr['uid'] = $_POST['admin_name'];
1067 $arr['cn'] = $_POST['admin_name'];
1068 $arr['sn'] = $_POST['admin_name'];
1070 $arr['givenName'] = "GOsa main administrator";
1071 $arr[$lmPassword] = "10974C6EFC0AEE1917306D272A9441BB";
1072 $arr[$ntPassword] = "38F3951141D0F71A039CFA9D1EC06378";
1073 $arr['userPassword'] = crypt_single($_POST['admin_pass'],"md5");
1074 if( ! $ldap->dn_exists ( $dn )) {
1075 $ldap->cd($dn);
1076 $ldap->create_missing_trees($dn);
1077 $ldap->add($arr);
1078 if($ldap->error!="Success") {
1079 print_red("Can't create user, and / or Group, possibly this problem depends on an empty LDAP server. Check your configuration and try again!");
1080 }
1081 }
1083 // theres already a group for administrator, so we only need to add the user
1084 if($group_cnt)
1085 {
1086 if(!isset($data['memberUid']))
1087 {
1088 $arrr['memberUid']= $_POST['admin_name'];
1089 }
1090 else
1091 {
1092 $data['memberUid'][$data['memberUid']['count']]=$_POST['admin_name'];
1093 $arrr['memberUid'] = $data['memberUid'];
1094 unset($arrr['memberUid']['count']);
1095 }
1096 $ldap->cd($data['dn']);
1097 $ldap->modify($arrr);
1098 }
1099 else
1100 {
1101 // there was no group defined, so we must create one
1102 $dn = "cn=administrators,".$ldapconf['groupou'].",".$ldapconf['base'];
1103 $arrr['objectClass'][0] = "gosaObject";
1104 $arrr['objectClass'][1] = "posixGroup";
1105 $arrr['gosaSubtreeACL'] = ":all";
1106 $arrr['cn'] = "administrators";
1107 $arrr['gidNumber'] = "999";
1108 $arrr['memberUid'] = $_POST['admin_name'];
1109 $ldap->cd($dn);
1110 $ldap->add($arrr);
1111 }
1114 // We created the Group and the user, so we can go on with the next setup step
1115 return(true);
1116 }
1117 else
1118 {
1119 if(!($create_user))
1120 {
1121 $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1122 $smarty->assign("exists",true);
1123 }
1124 else
1125 {
1126 $smarty->assign ("content", get_template_path('setup_useradmin.tpl'));
1127 $smarty->assign("exists",false);
1128 }
1129 }
1132 // Smarty outout
1134 if($withoutput)
1135 $smarty->display (get_template_path('headers.tpl'));
1137 if (isset($_SESSION['errors']))
1138 {
1139 $smarty->assign("errors", $_SESSION['errors']);
1140 }
1141 if($withoutput)
1142 $smarty->display (get_template_path('setup.tpl'));
1145 return(false);
1146 }
1149 // Returns the classnames auf the mail classes
1150 function get_available_mail_classes()
1151 {
1152 $dir = opendir( "../include");
1153 $methods = array();
1154 $suffix = "class_mail-methods-";
1155 $lensuf = strlen($suffix);
1156 $prefix = ".inc";
1157 $lenpre = strlen($prefix);
1160 $i = 0;
1161 while (($file = readdir($dir)) !== false)
1162 {
1163 if(stristr($file,$suffix))
1164 {
1165 $lenfile = strlen($file);
1166 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1167 $methods['file'][$i] = $file;
1168 $methods[$i]['file'] = $file;
1169 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
1170 $i++;
1171 }
1172 }
1173 return($methods);
1174 }
1182 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1183 ?>