';
return FALSE;
}
else
{
echo 'There seem to be no existing installation here, I am going to setup one now. ';
return TRUE;
}
}
// Check for PHP extensions.
function platform_is_ok ()
{
$nerrs = 0;
echo "
check item
result
\n";
echo '
PDO extension
';
if (class_exists ('PDO'))
echo '
Ok';
else
{
echo '
not found';
$nerrs++;
}
echo '
';
echo '
PDO-MySQL
';
if (defined ('PDO::MYSQL_ATTR_READ_DEFAULT_FILE'))
echo '
Ok';
else
{
echo '
not found';
$nerrs++;
}
echo '
';
echo '
hash functions
';
if (function_exists ('hash_algos'))
echo '
Ok';
else
{
echo '
not found';
$nerrs++;
}
echo '
';
echo '
SNMP extension
';
if (defined ('SNMP_NULL'))
echo '
Ok';
else
echo '
Not found. Live SNMP tab will not function properly until the extension is installed.';
echo '
';
echo '
GD functions
';
if (defined ('IMG_PNG'))
echo '
Ok';
else
{
echo '
not found';
$nerrs++;
}
echo '
';
echo '
HTTP scheme
';
if (!empty($_SERVER['HTTPS']))
echo '
HTTPs';
else
echo '
HTTP (all your passwords will be transmitted in cleartext)';
echo '
';
echo '
Multibyte string extension
';
if (defined ('MB_CASE_LOWER'))
echo '
Ok';
else
{
echo '
not found';
$nerrs++;
}
echo '
';
echo '
LDAP extension
';
if (defined ('LDAP_OPT_DEREF'))
echo '
Ok';
else
{
echo '
not found, LDAP authentication will not work';
}
echo '
';
echo "
\n";
return !$nerrs;
}
// Check that we can write to configuration file.
// If so, ask for DB connection paramaters and test
// the connection. Neither save the parameters nor allow
// going further until we succeed with the given
// credentials.
function init_config ()
{
if (!is_writable ('inc/secret.php'))
{
echo "The inc/secret.php file is not writable by web-server. Make sure it is.";
echo "The following commands should suffice:
touch inc/secret.php\nchmod 666 inc/secret.php
";
echo 'Fedora Linux with SELinux may require this file to be owned by specific user (apache) and/or executing "setenforce 0" for the time of installation. ';
echo 'SELinux may be turned back on with "setenforce 1" command.';
return FALSE;
}
if
(
!isset ($_REQUEST['save_config']) or
empty ($_REQUEST['mysql_host']) or
empty ($_REQUEST['mysql_db']) or
empty ($_REQUEST['mysql_username']) or
empty ($_REQUEST['mysql_password'])
)
{
echo "\n";
echo '
The above parameters did not work. Check and try again.
\n";
echo '
';
return FALSE;
}
$conf = fopen ('inc/secret.php', 'w+');
if ($conf === FALSE)
{
echo "Error: failed to open inc/secret.php for writing";
return FALSE;
}
fwrite ($conf, "\n");
fclose ($conf);
echo "The configuration file has been written successfully. ";
return TRUE;
}
function connect_to_db ()
{
require ('inc/secret.php');
global $dbxlink;
try
{
$dbxlink = new PDO ($pdo_dsn, $db_username, $db_password);
}
catch (PDOException $e)
{
die ('Error connecting to the database');
}
}
function init_database_static ()
{
connect_to_db ();
global $dbxlink;
$result = $dbxlink->query ('show tables');
$tables = $result->fetchAll (PDO::FETCH_NUM);
$result->closeCursor();
unset ($result);
if (count ($tables))
{
echo 'Your database is already holding ' . count ($tables);
echo ' tables, so I will stop here and let you check it yourself. ';
echo 'There is some important data there probably. ';
return FALSE;
}
echo 'Initializing the database... ';
echo '
";
$f = fopen ("install/init-${part}.sql", 'r');
if ($f === FALSE)
{
echo "Failed to open install/init-${part}.sql for reading";
return FALSE;
}
$longq = '';
while (!feof ($f))
{
$line = fgets ($f);
if (ereg ('^--', $line))
continue;
$longq .= $line;
}
fclose ($f);
$nq = $nerrs = 0;
foreach (explode (";\n", $longq) as $query)
{
if (empty ($query))
continue;
$nq++;
if ($dbxlink->exec ($query) === FALSE)
{
$nerrs++;
$errlist[] = $query;
}
}
echo "
${nq}
${nerrs}
\n";
}
echo '
';
if (count ($errlist))
{
echo '
The following queries failed:\n';
foreach ($errlist as $q)
echo "${q}\n\n";
echo '
';
return FALSE;
}
return TRUE;
}
function init_database_dynamic ()
{
connect_to_db();
global $dbxlink;
if (!isset ($_REQUEST['password']) or empty ($_REQUEST['password']))
{
$result = $dbxlink->query ('select count(user_id) from UserAccount where user_id = 1');
$row = $result->fetch (PDO::FETCH_NUM);
$nrecs = $row[0];
$result->closeCursor();
if (!$nrecs)
{
echo '
';
echo '
Administrator password not set
';
echo '
';
echo '
';
}
return FALSE;
}
else
{
$query = "INSERT INTO `UserAccount` (`user_id`, `user_name`, `user_enabled`, `user_password_hash`, `user_realname`) " .
"VALUES (1,'admin','yes',sha1('${_REQUEST['password']}'),'RackTables Administrator')";
$result = $dbxlink->exec ($query);
echo "Administrator password has been set successfully. ";
return TRUE;
}
}
function congrats ()
{
echo 'Congratulations! RackTables installation is complete. After pressing Proceed you will ';
echo 'enter the system. Authenticate with admin username. ';
echo "RackTables web-site runs some wiki pages ";
echo "and a bug tracker. We have also got ";
echo "a mailing list for users. Have fun. ";
return TRUE;
}
?>