' : '') . phpversion() . '';
$their_php_version = '4.1.2+';
// Modules
$our_mysql = ( extension_loaded('mysql') ) ? 'Yes' : 'No';
$their_mysql = 'Yes';
$our_zlib = ( extension_loaded('zlib') ) ? 'Yes' : 'No';
$their_zlib = 'No';
if ( (phpversion() < '4.1.2') || (!extension_loaded('mysql')) )
{
$tpl->error_append('Sorry, your server does not meet the minimum requirements for EQdkp');
}
else
{
$tpl->message_append('EQdkp has scanned your server and determined that it meets the minimum requirements in order to install.');
}
//
// Output the page
//
$tpl->assign_vars(array(
'OUR_EQDKP_VERSION' => $our_eqdkp_version,
'THEIR_EQDKP_VERSION' => $their_eqdkp_version,
'OUR_PHP_VERSION' => $our_php_version,
'THEIR_PHP_VERSION' => $their_php_version,
'OUR_MYSQL' => $our_mysql,
'THEIR_MYSQL' => $their_mysql,
'OUR_ZLIB' => $our_zlib,
'THEIR_ZLIB' => $their_zlib)
);
$tpl->page_header();
$tpl->page_tail();
}
function process_step2()
{
global $eqdkp_root_path, $DEFAULTS, $DBALS, $LOCALES;
$tpl = new Template_Wrap('install_step2.html');
//
// Build the default language drop-down
//
$lang_path = $eqdkp_root_path . 'language/';
if ( $dir = @opendir($lang_path) )
{
while ( $file = @readdir($dir) )
{
if ( (!is_file($lang_path . $file)) && (!is_link($lang_path . $file)) && ($file != '.') && ($file != '..') && ($file != 'CVS') )
{
$tpl->assign_block_vars('language_row', array(
'VALUE' => $file,
'OPTION' => ucfirst(strtolower($file)),
'SELECTED' => ( $DEFAULTS['default_lang'] == ucfirst(strtolower($file)) ? 'selected="selected"' : '')
)
);
}
}
}
//
// Build the database drop-down
//
foreach ( $DBALS as $db_type => $db_options )
{
$tpl->assign_block_vars('dbal_row', array(
'VALUE' => $db_type,
'OPTION' => $db_options['label'])
);
}
foreach ( $LOCALES as $locale_type => $locale_desc )
{
$tpl->assign_block_vars('locale_row', array(
'VALUE' => $locale_desc['type'],
'OPTION' => $locale_type,
'SELECTED' => $DEFAULTS['default_lang'] == $locale_type ? 'selected="selected"' : '',
)
);
}
//
// Determine server settings
//
$server_name = ( !empty($_SERVER['HTTP_HOST']) ) ? $_SERVER['HTTP_HOST'] : $_ENV['HTTP_HOST'];
if ( (!empty($_SERVER['SERVER_PORT'])) || (!empty($_ENV['SERVER_PORT'])) )
{
$server_port = ( !empty($_SERVER['SERVER_PORT']) ) ? $_SERVER['SERVER_PORT'] : $_ENV['SERVER_PORT'];
}
else
{
$server_port = '80';
}
$server_path = str_replace('install.php', '', $_SERVER['PHP_SELF']);
$tpl->message_append('Before proceeding, please verify that the database name you provided is already created and that the user you provided has permission to create tables in that database');
//
// Output the page
//
$tpl->assign_vars(array(
'DB_HOST' => 'localhost',
'TABLE_PREFIX' => $DEFAULTS['table_prefix'],
'SERVER_NAME' => $server_name,
'SERVER_PORT' => $server_port,
'SERVER_PATH' => $server_path)
);
$tpl->page_header();
$tpl->page_tail();
}
function process_step3()
{
global $eqdkp_root_path, $DEFAULTS, $DBALS, $LOCALES;
$tpl = new Template_Wrap('install_step3.html');
//
// Get our posted data
//
$default_lang = post_or_db('default_lang', $DEFAULTS);
$dbtype = post_or_db('dbtype');
$dbhost = post_or_db('dbhost');
$dbname = post_or_db('dbname');
$dbuser = post_or_db('dbuser');
$dbpass = post_or_db('dbpass');
$default_locale = post_or_db('default_locale');
$table_prefix = post_or_db('table_prefix', $DEFAULTS);
$server_name = post_or_db('server_name');
$server_port = post_or_db('server_port');
$server_path = post_or_db('server_path');
define('CONFIG_TABLE', $table_prefix . 'config');
define('USERS_TABLE', $table_prefix . 'users');
$dbal_file = $eqdkp_root_path . 'dbal/' . $dbtype . '.php';
if ( !file_exists($dbal_file) )
{
$tpl->message_die('Unable to find the database abstraction layer for ' . $dbtype . ', check to make sure ' . $dbal_file . ' exists.');
}
//
// Database population
//
define('DEBUG', 2);
include_once($dbal_file);
$db = new SQL_DB($dbhost, $dbname, $dbuser, $dbpass, false);
// Check to make sure a connection was made
if ( !is_resource($db->link_id) )
{
$tpl->message_die('Failed to connect to database ' . $dbname . ' as ' . $dbuser . '@' . $dbhost . '
Restart Installation');
}
$db_structure_file = $eqdkp_root_path . 'dbal/structure/' . $dbtype . '_structure.sql';
$db_data_file = $eqdkp_root_path . 'dbal/structure/' . $dbtype . '_data.sql';
$remove_remarks_function = $DBALS[$dbtype]['comments'];
// I require MySQL version 4.0.4 minimum.
$server_version = mysql_get_server_info();
$client_version = mysql_get_client_info();
if ( (isset($server_version) && isset($client_version)) ) {
$tpl->message_append('MySQL client and server version 4.0.4 or higher and InnoDB table support are required for EQdkp.
You are running server version and client version
MySQL versions less than 4.0.4 will not work and are not supported. Versions less than 4.0.4
will experience data corruption, and we will not provide support for these installations.
');
}
else
{
$tpl->message_die('Failed to get version information for database ' . $dbname . ' as ' . $dbuser . '@' . $dbhost . '
Restart Installation');
}
// Parse structure file and create database tables
$sql = @fread(@fopen($db_structure_file, 'r'), @filesize($db_structure_file));
$sql = preg_replace('#eqdkp\_(\S+?)([\s\.,]|$)#', $table_prefix . '\\1\\2', $sql);
$sql = $remove_remarks_function($sql);
$sql = parse_sql($sql, $DBALS[$dbtype]['delim']);
$sql_count = count($sql);
$i = 0;
while ( $i < $sql_count )
{
if (isset($sql[$i]) && $sql[$i] != "") {
if ( !($db->query($sql[$i]) )) {
$tpl->message_die('Failed to connect to database ' . $dbname . ' as ' . $dbuser . '@' . $dbhost . '
Restart Installation');
}
}
$i++;
}
unset($sql);
// Parse the data file and populate the database tables
$sql = @fread(@fopen($db_data_file, 'r'), @filesize($db_data_file));
$sql = preg_replace('#eqdkp\_(\S+?)([\s\.,]|$)#', $table_prefix . '\\1\\2', $sql);
$sql = $remove_remarks_function($sql);
$sql = parse_sql($sql, $DBALS[$dbtype]['delim']);
$sql_count = count($sql);
$i = 0;
while ( $i < $sql_count )
{
if (isset($sql[$i]) && $sql[$i] != "") {
if ( !($db->query($sql[$i]) )) {
$tpl->message_die('Failed to connect to database ' . $dbname . ' as ' . $dbuser . '@' . $dbhost . '
Restart Installation');
}
}
$i++;
}
unset($sql);
//
// Update some config settings
//
$db->query('UPDATE ' . CONFIG_TABLE . " SET config_name='eqdkp_start' WHERE config_name='" . $table_prefix . "start'");
$db->query("UPDATE " . CONFIG_TABLE . " SET config_value='".$server_name."' WHERE config_name='server_name'");
$db->query("UPDATE " . CONFIG_TABLE . " SET config_value='".$server_port."' WHERE config_name='server_port'");
$db->query("UPDATE " . CONFIG_TABLE . " SET config_value='".$server_path."' WHERE config_name='server_path'");
$db->query("UPDATE " . CONFIG_TABLE . " SET config_value='".$default_lang."' WHERE config_name='default_lang'");
$db->query("UPDATE " . CONFIG_TABLE . " SET config_value='".$default_locale."' WHERE config_name='default_locale'");
//
// Write the config file
//
$config_file = "";
$config_file .= "";
// Set our permissions to execute-only
@umask(0111);
if ( !$fp = @fopen('config.php', 'w') )
{
$error_message = 'The config.php file couldn\'t be opened for writing. Paste the following in to config.php and save the
file to continue:
' . $config_file . '
';
$tpl->error_append($error_message);
}
else
{
@fputs($fp, $config_file);
@fclose($fp);
$tpl->message_append('Your configuration file has been written with the initial values, but installation will not be complete until
you create an administrator account in the next step.');
}
//
// Output the page
//
$tpl->page_header();
$tpl->page_tail();
}
function process_step4()
{
global $eqdkp_root_path, $DEFAULTS;
$tpl = new Template_Wrap('install_step4.html');
//
// Get our posted data
//
$username = post_or_db('username');
$user_password1 = post_or_db('user_password1');
$user_password2 = post_or_db('user_password2');
$user_email = post_or_db('user_email');
//
// Update admin account
//
include($eqdkp_root_path . 'config.php');
define('CONFIG_TABLE', $table_prefix . 'config');
define('USERS_TABLE', $table_prefix . 'users');
define('STYLES_TABLE', $table_prefix . 'styles');
define('DEBUG', 0);
switch ( $dbtype )
{
case 'mysql':
include_once($eqdkp_root_path . 'dbal/mysql.php');
break;
default:
include_once($eqdkp_root_path . 'dbal/mysql.php');
break;
}
$db = new SQL_DB($dbhost, $dbname, $dbuser, $dbpass, false);
$sql = 'SELECT config_value FROM ' . CONFIG_TABLE . " WHERE config_name='default_lang'";
$default_lang = $db->query_first($sql);
$query = $db->build_query('UPDATE', array(
'username' => $username,
'user_password' => ( $user_password1 == $user_password2 ) ? md5($user_password1) : md5('admin'),
'user_lang' => $default_lang,
'user_email' => $user_email,
'user_active' => '1')
);
$db->query('UPDATE ' . USERS_TABLE . ' SET ' . $query . " WHERE user_id='1'");
$db->query("UPDATE " . CONFIG_TABLE . " SET config_value='".$user_email."' WHERE config_name='admin_email'");
//
// Rewrite the config file to its final form
//
$config_file = file($eqdkp_root_path . 'config.php');
$config_file = implode("\n", $config_file);
$config_file = preg_replace('#\?>$#', '', $config_file);
$config_file .= 'define(\'EQDKP_INSTALLED\', true);' . "\n";
$config_file .= '?>';
// Set our permissions to execute-only
@umask(0111);
if ( !$fp = @fopen('config.php', 'w') )
{
$error_message = 'The config.php file couldn\'t be opened for writing. Paste the following in to config.php and save the
file to continue:
' . htmlspecialchars($config_file) . '
';
$tpl->error_append($error_message);
}
else
{
@fputs($fp, $config_file, strlen($config_file));
@fclose($fp);
}
//
// Print out the login form
//
if ( $user_password1 != $user_password2 )
{
$tpl->message_append('NOTICE
Your passwords did
not match, so it has been reset to admin. You can change it by logging in and going to your account settings.');
}
$tpl->message_append('Your administrator account has been created, log in above to be taken to the EQdkp configuration page.');
$tpl->page_header();
$tpl->page_tail();
}
// ---------------------------------------------------------
// Functions!
// ---------------------------------------------------------
/**
* Applies addslashes() to the provided data
*
* @param mixed $data Array of data or a single string
* @return mixed Array or string of data
*/
function slash_global_data(&$data)
{
if ( is_array($data) )
{
foreach ( $data as $k => $v )
{
$data[$k] = ( is_array($v) ) ? slash_global_data($v) : addslashes($v);
}
}
return $data;
}
/**
* Set $config_name to $config_value in CONFIG_TABLE
*
* @param mixed $config_name Config name, or associative array of name => value pairs
* @param string $config_value
* @return bool
*/
function config_set($config_name, $config_value='', $db = null)
{
if ( is_null($db) )
{
global $db;
}
if ( is_object($db) )
{
if ( is_array($config_name) )
{
foreach ( $config_name as $d_name => $d_value )
{
config_set($d_name, $d_value);
}
}
else
{
if ( $config_value == '' )
{
return false;
}
$sql = 'UPDATE ' . CONFIG_TABLE . "
SET config_value='" . strip_tags(htmlspecialchars($config_value)) . "'
WHERE config_name='" . $config_name . "'";
$db->query($sql);
return true;
}
}
return false;
}
/**
* Checks if a POST field value exists;
* If it does, we use that one, otherwise we use the optional database field value,
* or return a null string if $db_row contains no data
*
* @param string $post_field POST field name
* @param array $db_row Array of DB values
* @param string $db_field DB field name
* @return string
*/
function post_or_db($post_field, $db_row = array(), $db_field = '')
{
if ( @sizeof($db_row) > 0 )
{
if ( $db_field == '' )
{
$db_field = $post_field;
}
$db_value = $db_row[$db_field];
}
else
{
$db_value = '';
}
return ( (isset($_POST[$post_field])) || (!empty($_POST[$post_field])) ) ? $_POST[$post_field] : $db_value;
}
/**
* Removes comments from a SQL data file
*
* @param string $sql SQL file contents
* @return string
*/
function remove_remarks($sql)
{
if ( $sql == '' )
{
die('Could not obtain SQL structure/data');
}
$retval = '';
$lines = explode("\n", $sql);
unset($sql);
foreach ( $lines as $line )
{
// Only parse this line if there's something on it, and we're not on the last line
if ( strlen($line) > 0 )
{
// If '#' is the first character, strip the line
$retval .= ( substr($line, 0, 1) != '#' ) ? $line . "\n" : "\n";
}
}
unset($lines, $line);
return $retval;
}
/**
* Parse multi-line SQL statements into a single line
*
* @param string $sql SQL file contents
* @param char $delim End-of-statement SQL delimiter
* @return array
*/
function parse_sql($sql, $delim)
{
if ( $sql == '' )
{
die('Could not obtain SQL structure/data');
}
$retval = array();
$statements = explode($delim, $sql);
unset($sql);
$linecount = count($statements);
for ( $i = 0; $i < $linecount; $i++ )
{
if ( ($i != $linecount - 1) || (strlen($statements[$i]) > 0) )
{
$statements[$i] = trim($statements[$i]);
$statements[$i] = str_replace("\r\n", '', $statements[$i]) . "\n";
// Remove 2 or more spaces
$statements[$i] = preg_replace('#\s{2,}#', ' ', $statements[$i]);
$retval[] = trim($statements[$i]);
}
}
unset($statements);
return $retval;
}
?>