' . safeHTMLstr(mysqli_connect_error()); } else { // Specify UTF-8 use for connection if (mysqli_query($dbtest, "SET NAMES " . OCC_DB_ENCODING . " COLLATE " . OCC_DB_COLLATION)) { // Create DB? if (isset($_POST['dbcreate']) && ($_POST['dbcreate'] == 1)) { if (preg_match("/^[\w-]+$/", $_POST['dbname'])) { $q = "CREATE DATABASE `" . $_POST['dbname'] . "` DEFAULT CHARACTER SET " . OCC_DB_ENCODING . " DEFAULT COLLATE " . OCC_DB_COLLATION; if (!mysqli_query($dbtest, $q) && (mysqli_errno($dbtest) != 1007)) { // 1007=exists $e = 'Unable to create database ' . safeHTMLstr($_POST['dbname']) . ". DB Error:
" . safeHTMLstr(mysqli_error($dbtest) . " (" . mysqli_errno($dbtest) . ")"); } } else { $e = 'Database name limited to letters, numbers, hyphen, and underscore'; } } } else { $e = 'Unable to set database connection with encoding ' . OCC_DB_ENCODING . ' and collation ' . OCC_DB_COLLATION . '. Check the MySQL version.'; } if (empty($e)) { // Check prefix if (!empty($_POST['dbprefix']) && (!preg_match("/^[\w-]{0,40}$/",$_POST['dbprefix']))) { $e = 'Invalid table prefix; use up to 40 letters, numbers, and the underscore.'; } // Attempt to access DB elseif (!mysqli_select_db($dbtest, $_POST['dbname'])) { $e = 'Unable to access database ' . safeHTMLstr($_POST['dbname']); } else { // Save db info if (! $fp = fopen(OCC_LIB_DIR . 'config-sample.php', 'r')) { err('Config template file (lib/config-sample.php) does not exist. Check that you have a full OpenConf distribution and click the Restart Install link above.', $hdr, $hdrfn, false); } if (!$optionFile = fread($fp, filesize(OCC_LIB_DIR . 'config-sample.php'))) { fclose($fp); err("Unable to read from config file", $hdr, $hdrfn, false); } fclose($fp); replaceConstantValue('OCC_SESSION_VAR_NAME', 'OPENCONF' . substr(oc_idGen(),3,4), $optionFile); // assign a (hopefully) unique session name in case of multiple installations replaceConstantValue('OCC_ENC_KEY', oc_idGen(64), $optionFile); // assign a unique encryption key replaceConstantValue('OCC_DB_USER', $_POST['dbuser'], $optionFile); replaceConstantValue('OCC_DB_PASSWORD', $_POST['dbpw'], $optionFile); replaceConstantValue('OCC_DB_HOST', $_POST['dbhost'], $optionFile); replaceConstantValue('OCC_DB_PORT', $_POST['dbport'], $optionFile); replaceConstantValue('OCC_DB_NAME', $_POST['dbname'], $optionFile); replaceConstantValue('OCC_DB_PREFIX', $_POST['dbprefix'], $optionFile); replaceConstantValue('OCC_DB_USE_SSL', ((isset($_POST['dbssl']) && ($_POST['dbssl'] == 1)) ? 1 : 0), $optionFile); replaceConstantValue('OCC_DB_SSL_NOVERIFY', ((isset($_POST['dbssl_noverify']) && ($_POST['dbssl_noverify'] == 1)) ? 1 : 0), $optionFile); replaceConstantValue('OCC_DB_SSL_KEY', varValue('dbssl_key', $_POST), $optionFile); replaceConstantValue('OCC_DB_SSL_CERT', varValue('dbssl_cert', $_POST), $optionFile); replaceConstantValue('OCC_DB_SSL_CA', varValue('dbssl_ca', $_POST), $optionFile); replaceConstantValue('OCC_DB_SSL_CAPATH', varValue('dbssl_capth', $_POST), $optionFile); replaceConstantValue('OCC_DB_SSL_CIPHER', varValue('dbssl_cipher', $_POST), $optionFile); if (! $fp = fopen(OCC_CONFIG_FILE,'w')) { err('Config file (config.php) cannot be created or is not writeable. Try creating a blank config.php file manually and ensure file permissions allow config.php to be written to by the server; then click the Restart Install link above.', $hdr, $hdrfn, false); } if (!fwrite($fp, $optionFile)) { fclose($fp); err("Unable to write to config file", $hdr, $hdrfn, false); } fclose($fp); // Load schema if (isset($_POST['dbschema']) && ($_POST['dbschema'] == 1)) { if ($dbfile = file_get_contents(OCC_LIB_DIR . "DB.sql")) { // create tables if (preg_match_all("/(CREATE [^;]+);/", $dbfile, $matches)) { foreach ($matches[1] as $m) { // add table prefix $m = preg_replace("/(CREATE TABLE `?)/", "$1" . slashQuote(stripslashes($_POST['dbprefix'])), $m); // add encoding and collation $m .= " DEFAULT CHARACTER SET " . OCC_DB_ENCODING . " COLLATE " . OCC_DB_COLLATION; if (!mysqli_query($dbtest, $m)) { $e = "Error on loading schema -- " . safeHTMLstr(mysqli_error($dbtest)) . ".
Database may need to be reset"; break; } } } else { err("No schema found in DB.sql file", $hdr, $hdrfn, false); } // insert data if (empty($e) && preg_match_all("/(INSERT [^;]+);/", $dbfile, $matches)) { foreach ($matches[1] as $m) { // add table prefix $m = preg_replace("/(INSERT INTO `?)/", "$1" . slashQuote(stripslashes($_POST['dbprefix'])), $m); if (!mysqli_query($dbtest, $m)) { $e = "Error on loading schema -- " . safeHTMLstr(mysqli_error($dbtest)) . ".
Database may need to be reset"; break; } } } } else { $e = 'Unable to load schema from DB.sql. Try loading it manually (see INSTALL instructions).'; } } if (empty($e)) { mysqli_close($dbtest); header("Location: install-account.php"); exit; } } } mysqli_close($dbtest); } } $dbuser = varValue('dbuser', $_POST); $dbname = varValue('dbname', $_POST); $dbhost = varValue('dbhost', $_POST); $dbport = varValue('dbport', $_POST, 3306); $dbprefix = varValue('dbprefix', $_POST); $dbssl = varValue('dbssl', $_POST); $dbssl_noverify = varValue('dbssl_verify', $_POST); $dbssl_key = varValue('dbssl_key', $_POST); $dbssl_cert = varValue('dbssl_cert', $_POST); $dbssl_ca = varValue('dbssl_ca', $_POST); $dbssl_capath = varValue('dbssl_capath', $_POST); $dbssl_cipher = varValue('dbssl_cipher', $_POST); } else { $dbuser = (defined('OCC_DB_USER') ? OCC_DB_USER : ''); $dbname = (defined('OCC_DB_NAME') ? OCC_DB_NAME : ''); $dbhost = (defined('OCC_DB_HOST') ? OCC_DB_HOST : ''); $dbport = (defined('OCC_DB_PORT') ? OCC_DB_PORT : 3306); $dbprefix = (defined('OCC_DB_PREFIX') ? OCC_DB_PREFIX : ''); $dbssl = (defined('OCC_DB_USE_SSL') ? OCC_DB_USE_SSL : ''); $dbssl_noverify = (defined('OCC_DB_SSL_NOVERIFY') ? OCC_DB_SSL_NOVERIFY : 1); $dbssl_key = (defined('OCC_DB_SSL_KEY') ? OCC_DB_SSL_KEY : ''); $dbssl_cert = (defined('OCC_DB_SSL_CERT') ? OCC_DB_SSL_CERT : ''); $dbssl_ca = (defined('OCC_DB_SSL_CA') ? OCC_DB_SSL_CA : ''); $dbssl_capath = (defined('OCC_DB_SSL_CAPATH') ? OCC_DB_SSL_CAPATH : ''); $dbssl_cipher = (defined('OCC_DB_SSL_CIPHER') ? OCC_DB_SSL_CIPHER : ''); } printHeader($hdr,$hdrfn); print '

Step 1 of 5: Enter Database Settings

'; if (!empty($e)) { print '

' . $e . '

'; } print '
'; print '
Database General Settings
The database user must have the following database privileges: ALTER, CREATE, DELETE, DROP, INSERT, SELECT, TRUNCATE, UPDATE
valid characters:  a-z   0-9   _   -
optional
Database SSL Settings
All fields are optional. Enter full path names.

The above information is stored in config.php'; if (defined('OCC_DB_NAME') && (OCC_DB_NAME != '')) { print '.
If you already configured config.php and loaded the schema, you may skip to the next step.'; } print '

'; printFooter(); ?>