count ($stepfunc)) { require 'inc/init.php'; global $root; header ("Location: " . $root); exit; } $title = "RackTables installation: step ${step} of " . count ($stepfunc); ?> <?php echo $title; ?>
${title}

"; echo "

\n"; $testres = $stepfunc[$step] (); if ($testres) { $next_step = $step + 1; echo ""; } else { $next_step = $step; echo ""; } echo "\n"; ?>
'; 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 "\n"; echo ''; if (class_exists ('PDO')) echo ''; echo ''; if (defined ('PDO::MYSQL_ATTR_READ_DEFAULT_FILE')) echo ''; echo ''; if (function_exists ('hash_algos')) echo ''; echo ''; if (defined ('SNMP_NULL')) echo ''; echo ''; if (defined ('IMG_PNG')) echo ''; echo ''; if (!empty($_SERVER['HTTPS'])) echo ''; echo ''; if (defined ('MB_CASE_LOWER')) echo ''; echo ''; if (defined ('LDAP_OPT_DEREF')) echo ''; echo "
check itemresult
PDO extensionOk'; else { echo 'not found'; $nerrs++; } echo '
PDO-MySQLOk'; else { echo 'not found'; $nerrs++; } echo '
hash functionsOk'; else { echo 'not found'; $nerrs++; } echo '
SNMP extensionOk'; else echo 'Not found. Live SNMP tab will not function properly until the extension is installed.'; echo '
GD functionsOk'; else { echo 'not found'; $nerrs++; } echo '
HTTP schemeHTTPs'; else echo 'HTTP (all your passwords will be transmitted in cleartext)'; echo '
Multibyte string extensionOk'; else { echo 'not found'; $nerrs++; } echo '
LDAP extensionOk'; else { echo 'not found, LDAP authentication will not work'; } 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 ''; echo ""; echo "\n"; echo ""; echo "\n"; echo ""; echo "\n"; echo ""; echo "\n"; echo '
'; return FALSE; } $pdo_dsn = 'mysql:host=' . $_REQUEST['mysql_host'] . ';dbname=' . $_REQUEST['mysql_db']; try { $dbxlink = new PDO ($pdo_dsn, $_REQUEST['mysql_username'], $_REQUEST['mysql_password']); } catch (PDOException $e) { echo "\n"; echo ''; echo ""; echo "\n"; echo ""; echo "\n"; echo ""; echo "\n"; echo ""; echo "\n"; echo "\n"; echo '
The above parameters did not work. Check and try again.
'; 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 ''; echo ""; $errlist = array(); foreach (array ('structure', 'dictbase', 'dictvendors') as $part) { $filename = "install/init-${part}.sql"; 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 "\n"; } echo '
filequerieserrors
${filename}${nq}${nerrs}
'; 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 ''; echo ''; echo '
Administrator password not set
'; } 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; } ?>