diff -Naur -x '*~' -x '*.orig' -x '*.rej' cacti-0.8.7e/include/auth.php cacti-0.8.7e-fix-installer-crash/include/auth.php --- cacti-0.8.7e/include/auth.php 2009-12-13 18:15:46.000000000 +0100 +++ cacti-0.8.7e-fix-installer-crash/include/auth.php 2009-12-13 15:57:02.000000000 +0100 @@ -25,7 +25,7 @@ include("./include/global.php"); /* check to see if this is a new installation */ -if (db_fetch_cell("select cacti from version") != $config["cacti_version"]) { +if ($database_empty || db_fetch_cell("select cacti from version") != $config["cacti_version"]) { header ("Location: install/"); exit; } diff -Naur -x '*~' -x '*.orig' -x '*.rej' cacti-0.8.7e/include/global.php cacti-0.8.7e-fix-installer-crash/include/global.php --- cacti-0.8.7e/include/global.php 2009-12-13 18:15:46.000000000 +0100 +++ cacti-0.8.7e-fix-installer-crash/include/global.php 2009-12-13 15:58:34.000000000 +0100 @@ -201,18 +201,37 @@ /* include base modules */ include("/usr/share/php/adodb/adodb.inc.php"); include($config["library_path"] . "/database.php"); +include_once($config["library_path"] . "/functions.php"); + +/* check that the absolute necessary mysql PHP module is loaded (install checks the rest), and report back if not */ +/* also checks memory_limit - the ADODB call below will hit low memory_limits */ +early_environment_checks(); + +/* Check that the database has tables in it - can't use db_fetch_assoc because that uses read_config_option! */ +$result = mysql_query("show tables from $database_default"); +if(mysql_num_rows($result)==0) +{ + $database_empty = true; +} +else +{ + $database_empty = false; +} /* connect to the database server */ db_connect_real($database_hostname, $database_username, $database_password, $database_default, $database_type, $database_port); /* include additional modules */ -include_once($config["library_path"] . "/functions.php"); include_once($config["include_path"] . "/global_constants.php"); include_once($config["library_path"] . "/plugins.php"); include_once($config["include_path"] . "/plugins.php"); include_once($config["include_path"] . "/global_arrays.php"); include_once($config["include_path"] . "/global_settings.php"); -include_once($config["include_path"] . "/global_form.php"); +if(!$database_empty) +{ + // avoid running read_config_option against an empty DB - this isn't needed during the install process anyway + include_once($config["include_path"] . "/global_form.php"); +} include_once($config["library_path"] . "/html.php"); include_once($config["library_path"] . "/html_form.php"); include_once($config["library_path"] . "/html_utility.php"); diff -Naur -x '*~' -x '*.orig' -x '*.rej' cacti-0.8.7e/install/index.php cacti-0.8.7e-fix-installer-crash/install/index.php --- cacti-0.8.7e/install/index.php 2009-12-13 18:15:46.000000000 +0100 +++ cacti-0.8.7e-fix-installer-crash/install/index.php 2009-12-13 15:57:02.000000000 +0100 @@ -32,7 +32,14 @@ $cacti_versions = array("0.8", "0.8.1", "0.8.2", "0.8.2a", "0.8.3", "0.8.3a", "0.8.4", "0.8.5", "0.8.5a", "0.8.6", "0.8.6a", "0.8.6b", "0.8.6c", "0.8.6d", "0.8.6e", "0.8.6f", "0.8.6g", "0.8.6h", "0.8.6i", "0.8.6j", "0.8.6k", "0.8.7", "0.8.7a", "0.8.7b", "0.8.7c", "0.8.7d", "0.8.7e"); -$old_cacti_version = db_fetch_cell("select cacti from version"); +if(! $database_empty) +{ + $old_cacti_version = db_fetch_cell("select cacti from version"); +} +else +{ + $old_cacti_version = ""; +} /* try to find current (old) version in the array */ $old_version_index = array_search($old_cacti_version, $cacti_versions); @@ -60,7 +67,7 @@ } function verify_php_extensions() { - $extensions = array("session", "sockets", "mysql", "xml"); + $extensions = array("session", "sockets", "mysql", "xml", "pcre"); $ok = true; $missing_extension = " <p style='font-family: Verdana, Arial; font-size: 16px; font-weight: bold; color: red;'>Error</p> <p style='font-family: Verdana, Arial; font-size: 12px;'>The following PHP extensions are missing:</p><ul>"; diff -Naur -x '*~' -x '*.orig' -x '*.rej' cacti-0.8.7e/lib/functions.php cacti-0.8.7e-fix-installer-crash/lib/functions.php --- cacti-0.8.7e/lib/functions.php 2009-12-13 18:15:46.000000000 +0100 +++ cacti-0.8.7e-fix-installer-crash/lib/functions.php 2009-12-13 15:57:02.000000000 +0100 @@ -2047,4 +2047,64 @@ return $string; } +function early_environment_checks() +{ + $mem_allowed = ini_get("memory_limit"); + $mem_allowed_int = return_bytes($mem_allowed); + + // capture the PHP "General Info" table + ob_start(); + phpinfo(INFO_GENERAL); + $s = ob_get_contents(); + ob_end_clean(); + foreach (explode("\n",$s) as $line) + { + $line = str_replace('<tr><td class="e">','',$line); + $line = str_replace('</td></tr>','',$line); + $line = str_replace(' </td><td class="v">',' => ',$line); + $sep_pos = strpos($line," => "); + if($sep_pos!==FALSE) + { + // by here, it should be a straight "name => value" + $name = substr($line,0,$sep_pos); + $value = substr($line,$sep_pos+4); + $php_general[$name] = $value; + } + } + + $ini_file = $php_general['Loaded Configuration File']; + + if(($mem_allowed_int>0) && ($mem_allowed_int < 128000000)) + { + die('memory_limit is '.$mem_allowed.' - You should increase this value to at least 128M in your php.ini ('.$ini_file.')'); + } + + if (!function_exists('mysql_data_seek')) + { + die ("\n\nNo 'mysql' PHP extension is loaded. This is required by Cacti. Check your php.ini file ($ini_file).\n"); + } +} + + function return_bytes($val) { + $val = trim($val); + if($val != '') + { + $last = strtolower($val{strlen($val)-1}); + switch($last) { + // The 'G' modifier is available since PHP 5.1.0 + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + } + else + { + $val = 0; + } + + return $val; +} ?> diff -Naur -x '*~' -x '*.orig' -x '*.rej' cacti-0.8.7e/lib/plugins.php cacti-0.8.7e-fix-installer-crash/lib/plugins.php --- cacti-0.8.7e/lib/plugins.php 2009-12-13 18:15:46.000000000 +0100 +++ cacti-0.8.7e-fix-installer-crash/lib/plugins.php 2009-12-13 18:15:31.000000000 +0100 @@ -22,11 +22,15 @@ * @return mixed $data */ function api_plugin_hook ($name) { - global $config, $plugin_hooks; + global $config, $plugin_hooks, $database_empty; $data = func_get_args(); $ret = ''; $p = array(); + if ($database_empty) { + return; + } + $result = db_fetch_assoc("SELECT name, file, function FROM plugin_hooks WHERE status = 1 AND hook = '$name'", false); if (count($result)) { foreach ($result as $hdata) {