/** * Makes sure that the config file is properly setup. */ function check_config($config_file) { # Read in config_default.php require_once LIBDIR . 'config_default.php'; # Make sure their PHP version is current enough if (strcmp(phpversion(), REQUIRED_PHP_VERSION) < 0) { system_message(array('title' => _('Incorrect version of PHP'), 'body' => sprintf('phpLDAPadmin requires PHP version %s or greater.<br /><small>(You are using %s)</small>', REQUIRED_PHP_VERSION, phpversion()), 'type' => 'error')); } $config = new Config(); if (file_exists(LIBDIR . 'config_custom.php') && is_readable(LIBDIR . 'config_custom.php')) { include LIBDIR . 'config_custom.php'; } ob_start(); require $config_file; $str = ''; if (ob_get_level()) { $str = ob_get_contents(); ob_end_clean(); } if ($str) { $str = strip_tags($str); $matches = array(); preg_match('/(.*):\\s+(.*):.*\\s+on line (\\d+)/', $str, $matches); if (isset($matches[1]) && isset($matches[2]) && isset($matches[3])) { $error_type = $matches[1]; $error = $matches[2]; $line_num = $matches[3]; $file = file($config_file); $body = '<h3 class="title">Config file ERROR</h3>'; $body .= sprintf('<h3 class="subtitle">%s (%s) on line %s</h3>', $error_type, $error, $line_num); $body .= '<center>'; $body .= sprintf('Looks like your config file has an ERROR on line %s.<br />', $line_num); $body .= 'Here is a snippet around that line <br />'; $body .= '<br />' . "\n"; $body .= '<div style="text-align: left; font-family: monospace; margin-left: 80px; margin-right: 80px; border: 1px solid black; padding: 10px;">'; for ($i = $line_num - 9; $i < $line_num + 5; $i++) { if ($i + 1 == $line_num) { $body .= '<div style="color:red;background:#fdd">'; } if ($i < 0) { continue; } $body .= sprintf('<b>%s</b>: %s<br />', $i + 1, $file[$i]); if ($i + 1 == $line_num) { $body .= '</div>'; } } $body .= '</div>'; $body .= '<br />'; $body .= 'Hint: Sometimes these errors are caused by lines <b>preceding</b> the line reported.'; $body .= '</center>'; $block = new block(); $block->SetBody($body); $www['page'] = new page(); $www['page']->block_add('body', $block); $www['page']->display(); die; } } # Check for server definitions. if (!isset($servers) || count($servers->GetServerList()) == 0) { error(_('Your config.php is missing Server Definitions. Please see the sample file config/config.php.example.'), 'error', 'index.php', true); } $config->setServers($servers); # Check the memory limit parameter. if (ini_get('memory_limit') > -1 && ini_get('memory_limit') < $config->getValue('session', 'memorylimit')) { system_message(array('title' => _('Memory Limit low.'), 'body' => sprintf('Your php memory limit is low - currently %s, you should increase it to atleast %s. This is normally controlled in /etc/php.ini.', ini_get('memory_limit'), $config->getValue('session', 'memorylimit')), 'type' => 'error')); } return $config; }