'base_data',
'base_url' => 'base_data',
'main_title' => 'base_data',
'slogan' => 'base_data',
'webmaster' => 'base_data',
// database_config
'mysql_host' => 'database_config',
'mysql_dbase' => 'database_config',
'mysql_prefix' => 'database_config',
'mysql_engine' => 'database_config',
'mysql_login' => 'database_config',
'mysql_password1' => 'database_config',
'mysql_password2' => 'database_config',
// smtp_config
'smtp_host' => 'smtp_config',
'smtp_user' => 'smtp_config',
'smtp_password1' => 'smtp_config',
'smtp_password2' => 'smtp_config',
// other_config
'output_mode' => 'other_config',
'warn_no_pass' => 'other_config',
'write_footer' => 'other_config',
'enable_backlink' => 'other_config',
// first_admin
'admin_login' => 'first_admin',
'admin_email' => 'first_admin',
'admin_password1' => 'first_admin',
'admin_password2' => 'first_admin',
);
// Set mininmum password length/score and other config entries
setConfigEntry('min_password_length', 5);
setConfigEntry('min_password_score' , 3);
setConfigEntry('verbose_sql' , 'N');
}
// Write the local config-local.php file from "template"
function doInstallWriteLocalConfigurationFile ($path, $url, $title, $slogan, $email, $noPassword, $writeFooter, $backLink, $databaseHost, $databaseName, $databaseLogin, $databasePassword, $databasePrefix, $tableType, $databaseExtension, $smtpHost, $smtpUser, $smtpPassword) {
// Copy the config template and verify it
copyFileVerified($path . 'inc/config-local.php.dist', $path . getCachePath() . 'config-local.php', 0644);
/*
* Ok, all done. So we can write the config data to the php files. Do only
* write these if they differ from auto-detected values.
*/
if ($path != getPath()) {
changeDataInLocalConfigurationFile('SERVER-PATH', "setConfigEntry('PATH', '", "');", $path, 0);
} // END - if
if ($url != getUrl()) {
changeDataInLocalConfigurationFile('HOST-URL', "setConfigEntry('URL', '", "');", $url, 0);
} // END - if
// Write more data
changeDataInLocalConfigurationFile('MAIN-TITLE', "setConfigEntry('MAIN_TITLE', '", "');", $title, 0);
changeDataInLocalConfigurationFile('SLOGAN', "setConfigEntry('SLOGAN', '", "');", $slogan, 0);
changeDataInLocalConfigurationFile('WEBMASTER', "setConfigEntry('WEBMASTER', '", "');", $email, 0);
changeDataInLocalConfigurationFile('NULLPASS-WARNING', "setConfigEntry('WARN_NO_PASS', '", "');", $noPassword, 0);
changeDataInLocalConfigurationFile('WRITE-FOOTER', "setConfigEntry('WRITE_FOOTER', '", "');", $writeFooter, 0);
changeDataInLocalConfigurationFile('BACKLINK', "setConfigEntry('ENABLE_BACKLINK', '", "');", $backLink, 0);
// @TODO DEACTIVATED: changeDataInLocalConfigurationFile('OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestElement('omode'), 0);
changeDataInLocalConfigurationFile('MYSQL-HOST', " 'host' => '", "',", $databaseHost, 0);
changeDataInLocalConfigurationFile('MYSQL-DBASE', " 'dbase' => '", "',", $databaseName, 0);
changeDataInLocalConfigurationFile('MYSQL-LOGIN', " 'login' => '", "',", $databaseLogin, 0);
changeDataInLocalConfigurationFile('MYSQL-PASSWORD', " 'password' => '", "',", $databasePassword, 0);
changeDataInLocalConfigurationFile('MYSQL-PREFIX', "setConfigEntry('_MYSQL_PREFIX', '", "');", $databasePrefix, 0);
changeDataInLocalConfigurationFile('TABLE-TYPE', "setConfigEntry('_TABLE_TYPE', '", "');", $tableType, 0);
changeDataInLocalConfigurationFile('DATABASE-TYPE', "setConfigEntry('_DB_TYPE', '", "');", $databaseExtension, 0);
changeDataInLocalConfigurationFile('SMTP-HOSTNAME', "setConfigEntry('SMTP_HOSTNAME', '", "');", $smtpHost, 0);
changeDataInLocalConfigurationFile('SMTP-USER', "setConfigEntry('SMTP_USER', '", "');", $smtpUser, 0);
changeDataInLocalConfigurationFile('SMTP-PASSWORD', "setConfigEntry('SMTP_PASSWORD', '", "');", $smtpPassword, 0);
// Generate a long site-key and write it
changeDataInLocalConfigurationFile('SITE-KEY', "setConfigEntry('SITE_KEY', '", "');", generatePassword(50), 0);
// Script is now installed
return changeDataInLocalConfigurationFile('INSTALLED', "setConfigEntry('MAILER_INSTALLED', '", "');", 'Y', 0);
}
// Adds a given template with content to install output stream
function addTemplateToInstallContent ($template, $content = array()) {
// Load the template
$out = loadTemplate($template, TRUE, $content);
// Add it to output
addToInstallContent($out);
}
// Add it to install content
function addToInstallContent ($out) {
// Set or add it...
if (!isset($GLOBALS['install_content'])) {
// Set it
$GLOBALS['install_content'] = $out;
} else {
// Add it
$GLOBALS['install_content'] .= $out;
} // END - if
}
// Somewhat getter for installer content
function getInstallerContent () {
// Is it here?
if (isset($GLOBALS['install_content'])) {
// Yes, then use it
$content = $GLOBALS['install_content'];
} else {
// Nothing found, this needs fixing
$content = returnMessage('{--INSTALLER_CONTENT_404--}');
}
// Return content
return $content;
}
// Read a given SQL dump
function readSqlDump ($FQFN) {
// Load the file
$content = readFromFile($FQFN);
// Remove some unwanted chars
$content = str_replace(array(chr(13), PHP_EOL . PHP_EOL), array('', PHP_EOL), $content);
// Return the content
return $content;
}
// Generates the installer menu by simply loading another template
function generateInstallerMenu () {
// Load installer menu template
$OUT = loadTemplate('install_menu', TRUE);
// Return loaded content
return $OUT;
}
// Generate the install footer navigation by simply loading another template
function generateInstallerFooterNavigation () {
// Load installer menu template
$OUT = loadTemplate('install_footer', TRUE);
// Return loaded content
return $OUT;
}
// Generate an option list for database types for given default value
function generateInstallerDatabaseTypeOptions () {
return generateOptions(
'/ARRAY/',
array(
'MyISAM',
'InnoDB'
),
array(
'{--INSTALLER_TABLE_TYPE_MYISAM--}',
'{--INSTALLER_TABLE_TYPE_INNODB--}'
),
getSession('mysql_engine')
);
}
// Generate an option list for database extensions for given default value
function generateInstallerDatabaseExtensionOptions () {
// Init all arrays
$keys = array();
$values = array();
$foundExtensions = array();
// Scan directory
$drivers = getArrayFromDirectory('inc/db/', 'lib-', FALSE, FALSE);
// Remove prefix + extension
foreach ($drivers as $key => $driver) {
// Remove driver
$drivers[$key] = substr($driver, 4, -4);
// Is the corresponding extension loaded?
if (isPhpExtensionLoaded($drivers[$key])) {
// Then add it
array_push($foundExtensions, $drivers[$key]);
} // END - if
} // END - foreach
// Generate list for keys/values ("translations")
foreach ($foundExtensions as $extension) {
// Use it as direct key
array_push($keys, $extension);
// Add "translation" function around it as value
array_push($values, '{%pipe,translatePhpExtension=' . $extension . '%}');
} // END - if
// Get a directory list
return generateOptions(
'/ARRAY/',
$keys,
$values,
getSession('database_extension')
);
}
// Generate an option list for output mode types for given default value
function generateInstallerOutputModeOptions ($defaultValue) {
return generateOptions(
'/ARRAY/',
array('render', 'direct'),
array('{--INSTALLER_MODE_RENDER--}', '{--INSTALLER_MODE_DIRECT--}'),
$defaultValue
);
}
// Checks whether we have an AJAX-enabled installer which defaults to red pill
function isAjaxInstaller () {
// Get the session data and compare it against 'ajax'
$isAjaxInstaller = (getSession('installer') == 'ajax');
// Return it
return $isAjaxInstaller;
}
// Checks whether we have an plain installer which defaults to red pill
function isPlainInstaller () {
// Get the session data and compare it against 'plain'
$isPlainInstaller = (getSession('installer') == 'plain');
// Return it
return $isPlainInstaller;
}
// Handle all given failed fields
function handleInstallerFailedFields ($failedFields) {
// Don't do anything with no array or no entries
if (!isFilledArray($failedFields)) {
// Abort here
reportBug(__FUNCTION__, __LINE__, 'failedFields[]=' . gettype($failedFields) . ' verification failed');
} // END - if
// Handle all
$out = '
';
foreach ($failedFields as $key => $field) {
// "Translate" it
$out .= '- {--INSTALLER_FIELD_FAILED_' . strtoupper($field) . '--}
';
} // END - foreach
$out .= '
';
// Return it
return $out;
}
// Checks given key/value pair if it is valid by a call-back
function isInstallerDataValid (&$saveStatus, $key, $value) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ' - ENTERED!');
// Generate call-back function based on given key
$callbackName = 'isInstaller' . capitalizeUnderscoreString($key) . 'Valid';
// Is the function there?
if (!function_exists($callbackName)) {
// Not found, which is not bad, but it means this data is always valid
//* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' not found. saveStatus[status]=' . $saveStatus['status'] . ', key=' . $key . ', value=' . $value);
// All fine (CAREFULL!)
return TRUE;
} // END - if
// Then call it back
$isValid = (bool) call_user_func($callbackName, $value);
// Is it not valid?
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',isValid=' . intval($isValid));
if ($isValid === FALSE) {
// Then add it to saveStatus
array_push($saveStatus['failed_fields'], $key);
} // END - if
// Return status
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT!');
return $isValid;
}
// Post-check on installer data
function doInstallerPostCheck ($currentTab, &$saveStatus) {
// Debug message
//* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status'] . ' - ENTERED!');
// Create the call-back function on 'tab'
$callbackName = 'isInstallerPost' . capitalizeUnderscoreString($currentTab) . 'Valid';
// Is the function there?
if (!function_exists($callbackName)) {
// Not found, which is not bad, but it means the post-check won't be run
/* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' not found. saveStatus[status]=' . $saveStatus['status'] . ', currentTab=' . $currentTab);
// Abort here
return FALSE;
} // END - if
// Init 'tab-specific error message'
$GLOBALS['installer_post_error'][$currentTab] = '';
$GLOBALS['installer_failed_fields'][$currentTab] = array();
// Debug message
//* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Calling function ' . $callbackName . ',currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status']);
// Then call it back
$isValid = (bool) call_user_func($callbackName, $currentTab);
// Is it not valid?
if (($isValid === FALSE) || (isFilledArray($GLOBALS['installer_failed_fields'][$currentTab]))) {
// Then change status and message
$saveStatus['status'] = 'failed';
$saveStatus['message'] = '{%message,INSTALLER_POST_CHECK_' . strtoupper($currentTab) . '_FAILED=' . $GLOBALS['installer_post_error'][$currentTab] . '%}';
// Is there failed fields?
if (isFilledArray($GLOBALS['installer_failed_fields'][$currentTab])) {
// Then merge both
$saveStatus['failed_fields'] = merge_array($saveStatus['failed_fields'], $GLOBALS['installer_failed_fields'][$currentTab]);
} // END - if
} // END - if
// Debug message
//* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status'] . ' - EXIT!');
}
// Determines an installer group by given key
function determineInstallerGroupByKey ($key) {
// Try to look it up
if (!isset($GLOBALS['installer_groups'][$key])) {
// Log missing entry
logDebugMessage(__FUNCTION__, __LINE__, 'Cannot determine installer group, returning dummy group. key=' . $key);
// Return dummy group
return 'dummy';
} // END - if
// Return it
return $GLOBALS['installer_groups'][$key];
}
// Adds given key/value pair to an overview group
function addKeyValueToInstallerOverviewGroup ($key, $value) {
// First determine the group by given key
$group = determineInstallerGroupByKey($key);
// Depending on the group, add it for later usage (to render the overview page)
$GLOBALS['installer_overview'][$group][$key] = $value;
}
//-----------------------------------------------------------------------------
// Template call-back functions
//-----------------------------------------------------------------------------
// ----------------- Extensions -----------------
// Generates (and returns) a table from all extensions
function generateInstallerExtensionTable () {
// Generate extension list
$extensions = loadAllExtensionsByTemplate();
// "Walk" through all
$OUT = '';
foreach ($extensions as $extension) {
// Remove prefix + suffix
$ext_name = substr(basename($extension), 4, -4);
// Is the extension not in development and not admintheme* ?
if ((loadExtension($ext_name, 'test', '0.0.0', TRUE)) && (isExtensionProductive($ext_name)) && (substr($ext_name, 0, 10) != 'admintheme')) {
// Default is not disabled
$disabled = '';
if (in_array($ext_name, array('sql_patches', 'timezone'))) {
// Always keep this enabled
$disabled = ' disabled="disabled"';
} // END - if
// Initialize content array
$content = array(
'ext_name' => $ext_name,
'ext_version' => getExtensionVersion($ext_name),
'checked' => getExtensionSelectedFromSession($ext_name, 'extensions'),
'disabled' => $disabled,
'description' => loadTemplate('ext_' . $ext_name, TRUE),
);
// Load row template
$OUT .= loadTemplate('install_list_extensions_row', TRUE, $content);
} // END - if
} // END - foreach
// Load main template
return loadTemplate('install_list_extensions', TRUE, $OUT);
}
//-----------------------------------------------------------------------------
// Call-back functions to check validity
//-----------------------------------------------------------------------------
// ----------------- Base data -----------------
// Call-back function to check validity of 'base_path'
function isInstallerBasePathValid ($value) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
// Is it a directory and if some typical files could be found
$isValid = (
// Is it a directory?
(isDirectory($value))
&&
// Doesn't contain dots
(strpos($value, '..') === FALSE)
&&
// Is there a trailing slash?
(substr($value, -1, 1) == '/')
&&
// Is mysql-manager.php there?
(isFileReadable($value . 'inc/mysql-manager.php'))
&&
// What about gen_sql_patches.php?
(isFileReadable($value . 'inc/gen_sql_patches.php'))
&&
// And how about referral-functions.php?
(isFileReadable($value . 'inc/referral-functions.php'))
);
// Return it
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
return $isValid;
}
// Call-back function to check validity of 'base_url'
function isInstallerBaseUrlValid ($value) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
// Is it same as URL
$isValid = (
// Same as URL?
($value == getUrl())
|| (
// Starts with http:// or https:// ?
((substr($value, 0, 7) == 'http://') || (substr($value, 0, 8) == 'https://'))
&&
// Has no trailing slash?
(substr($value, -1, 1) != '/')
&&
// And total length is at least 6+8=14 chars long? (https://foo.ba)
(strlen($value) >= 14)
&&
// Is the URL valid?
(isUrlValid($value))
));
// Return it
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
return $isValid;
}
// Call-back function to checl validity of 'main_title'
function isInstallerMainTitleValid ($value) {
// Is it valid?
// @TODO Comparing with DEFAULT_MAIN_TITLE doesn't work
$isValid = ((strlen($value) >= 4) && ($value != getMessage('DEFAULT_MAIN_TITLE')));
// Return it
return $isValid;
}
// Call-back function to checl validity of 'slogan'
function isInstallerSloganValid ($value) {
// Is it valid?
$isValid = ((strlen($value) >= 4) && ($value != getMessage('DEFAULT_SLOGAN')));
// Return it
return $isValid;
}
// Call-back function to check validity of 'webmaster'
function isInstallerWebmasterValid ($value) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
// Is it a valid email address?
$isValid = ((
// Is it a valid email address?
(isEmailValid($value))
||
// Or is there 'localhost/127.0.0.1' as hostname? Then don't check email address (e.g. you@localhost)
(isDeveloperSystem())
) && (
// Is not default "email address"
$value != getMessage('DEFAULT_WEBMASTER')
) && (
strlen($value) >= 11
));
// Return it
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
return $isValid;
}
// ----------------- Database configuration -----------------
// Call-back function to check validity of 'mysql_host'
function isInstallerMysqlHostValid ($value) {
// This value must match a hostname or IP address
$isValid = (
// Shall not be empty
(!empty($value)) && (
// Is localhost/127.0.0.1? (mostly the case)
(in_array($value, array('localhost', '127.0.0.1')))
||
// IP number match (this regex was taken from www.regexlib.com)
(preg_match('/((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]))/', $value))
||
// Host name match
(preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/', $value))
));
// Return it
return $isValid;
}
// Call-back function to check validity of 'mysql_engine'
function isInstallerMysqlEngineValid ($value) {
// This value must be 'MyISAM' or 'InnoDB'
$isValid = in_array($value, array('MyISAM', 'InnoDB'));
// Return it
return $isValid;
}
// Call-back function to check validity of 'mysql_dbase'
function isInstallerMysqlDbaseValid ($value) {
// This value must not be empty
$isValid = ((!empty($value)) && ($value != 'your_database'));
// Return it
return $isValid;
}
// Call-back function to check validity of 'mysql_login'
function isInstallerMysqlLoginValid ($value) {
// This value must not be empty
$isValid = ((!empty($value)) && ($value != 'your_login'));
// Return it
return $isValid;
}
// Call-back function to check validity of 'mysql_prefix'
function isInstallerMysqlPrefixValid ($value) {
// This value must not be empty
$isValid = !empty($value);
// Return it
return $isValid;
}
// ----------------- SMTP configuration -----------------
// ----------------- Other configuration -----------------
// ----------------- First administator -----------------
// Call-back function to check validity of 'admin_login'
function isInstallerAdminLoginValid ($value) {
// Length should not be shorter than 4 characters
return (strlen($value) >= 4);
}
// Call-back function to check validity of 'admin_email'
function isInstallerAdminEmailValid ($value) {
// Just call webmaster-check function
return isInstallerWebmasterValid($value);
}
// Call-back function to check validity of 'admin_password1'
function isInstallerAdminPassword1Valid ($value) {
// Check if it is strong
return isStrongPassword($value);
}
// Call-back function to check validity of 'admin_password2'
function isInstallerAdminPassword2Valid ($value) {
// Check if it is strong
return isStrongPassword($value);
}
// ----------------- Extensions -----------------
// Call-back function to check 'sel' (array!)
function isInstallerSelValid ($value) {
// $value is not an array, is really bad.
if (!is_array($value)) {
// Is no array
reportBug(__FUNCTION__, __LINE__, 'sel,value[]=' . gettype($value) . '!=array');
} // END - if
// Add always missing ext-sql_patches
$value['sql_patches'] = '1';
// Default is fine
$isValid = TRUE;
// "Walk" through all extensions
foreach ($value as $ext_name => $sel) {
// Is this extension choosen?
if ($sel != '1') {
// Skip this
continue;
} // END - if
// Can it be loaded?
$isValid = (($isValid) && (loadExtension($ext_name, 'test', '0.0.0', TRUE)));
} // END - foreach
// Remove 'sel' from POST data as it cannot be saved
unsetPostRequestElement('sel');
// Save it in session (sorry to do that here :( )
setSession('extensions', implode(':', array_keys($value)));
// Return result
return $isValid;
}
//-----------------------------------------------------------------------------
// Call-back functions to post-check validity
//-----------------------------------------------------------------------------
// Call-back function to check if base data is valid
function isInstallerPostBaseDataValid ($currentTab) {
// By default it is not valid
$isValid = FALSE;
// Is the base path valid?
if (!isInstallerBasePathValid(postRequestElement('base_path'))) {
// Then mark it
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_BASE_PATH_INVALID--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'base_path');
return FALSE;
} elseif (!isInstallerBaseUrlValid(postRequestElement('base_url'))) {
// Then mark it
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_BASE_URL_INVALID--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'base_url');
return FALSE;
} elseif (strlen(postRequestElement('main_title')) < 3) {
// To short
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_MAIN_TITLE_INVALID--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'main_title');
return FALSE;
} elseif (strlen(postRequestElement('slogan')) < 3) {
// To short
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_SLOGAN_INVALID--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'slogan');
return FALSE;
} elseif (!isInstallerWebmasterValid(postRequestElement('webmaster'))) {
// Then mark it
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_WEBMASTER_INVALID--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'webmaster');
return FALSE;
} else {
// All fine
$isValid = TRUE;
// Remember this tab in session
installTabOkay($currentTab);
}
// Return it
return $isValid;
}
// Call-back function to check if database configuration in POST is valid
function isInstallerPostDatabaseConfigValid ($currentTab) {
// By default nothing is valid
$isValid = FALSE;
$engineValid = FALSE;
$missingTables = 0;
// Do both passwords match?
if ((!isPostRequestElementSet('mysql_password1')) && (isPostRequestElementSet('mysql_password2'))) {
// Password 1 not set
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORD1_EMPTY--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password1');
return FALSE;
} elseif ((isPostRequestElementSet('mysql_password1')) && (!isPostRequestElementSet('mysql_password2'))) {
// Password 2 not set
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORD2_EMPTY--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password2');
return FALSE;
} elseif (postRequestElement('mysql_password1') != postRequestElement('mysql_password2')) {
// Passwords mismatch
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORDS_MISMATCH--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password1', 'mysql_password2');
return FALSE;
} // END - if
// Remove any previous flag
unsetSqlLinkUp(__FUNCTION__, __LINE__);
// Try to connect to the database
sqlConnectToDatabase(postRequestElement('mysql_host'), postRequestElement('mysql_login'), postRequestElement('mysql_password1'), __FUNCTION__, __LINE__);
// Is the link up
if (!isSqlLinkUp()) {
// Cannot connect to database
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_CONNECT_ERROR--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_login', 'mysql_password1', 'mysql_password2');
return FALSE;
} // END - if
// Then attempt to select the database
if (!sqlSelectDatabase(postRequestElement('mysql_dbase'), __FUNCTION__, __LINE__)) {
// Could not find database
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_SELECT_FAILED--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_dbase');
// Disconnect here, we don't need idle database connections laying around
sqlCloseLink(__FUNCTION__, __LINE__);
// Abort here
return FALSE;
} // END - if
// Set database name and prefix
setConfigEntry('__DB_NAME' , postRequestElement('mysql_dbase'));
setConfigEntry('_MYSQL_PREFIX', postRequestElement('mysql_prefix'));
// Get an array of all supported engines
$engines = getArrayFromSupportedSqlEngines(postRequestElement('mysql_engine'));
// Is this an array?
if (!is_array($engines)) {
// Something bad happened
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_ENGINES_SQL_ERROR--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
// Disconnect here, we don't need idle database connections laying around
sqlCloseLink(__FUNCTION__, __LINE__);
// Abort here
return FALSE;
} elseif (!isFilledArray($engines)) {
// No engine is active
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_NO_ENGINES_ACTIVE--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
// Disconnect here, we don't need idle database connections laying around
sqlCloseLink(__FUNCTION__, __LINE__);
// Abort here
return FALSE;
}
// Then check all, if the requested is working
foreach ($engines as $engineArray) {
// By default the selected engine is not valid
$engineValid = FALSE;
// Is the engine there?
if (strtolower($engineArray['Engine']) == strtolower(postRequestElement('mysql_engine'))) {
// Okay, engine is found
$engineValid = TRUE;
break;
} // END - if
} // END - foreach
// So, is the engine found?
if ($engineValid === FALSE) {
// Requested engine is not active
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_ENGINE_UNSUPPORTED--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
// Disconnect here, we don't need idle database connections laying around
sqlCloseLink(__FUNCTION__, __LINE__);
// Abort here
return FALSE;
} // END - if
// Init some known tables
$tables = array(
// Admins
'admins' => TRUE,
// Admin menu
'admin_menu' => TRUE,
// Categories
'cats' => TRUE,
// Configuration
'config' => TRUE,
// Extensions
'extensions' => TRUE,
// Guest menu
'guest_menu' => TRUE,
// Max receive
'max_receive' => TRUE,
// Member menu
'member_menu' => TRUE,
// Module registry
'mod_reg' => TRUE,
// Payments
'payments' => TRUE,
// Sending pool
'pool' => TRUE,
// Referral banner
'refbanner' => TRUE,
// Referral levels
'refdepths' => TRUE,
// Referral system
'refsystem' => TRUE,
// Task system
'task_system' => TRUE,
);
// So check if all tables are not there
foreach ($tables as $tableName => $isFound) {
// Check it out
$tables[$tableName] = ifSqlTableExists($tableName);
// Is it (hopefully not) there?
if ($tables[$tableName] === FALSE) {
// This does not exist
$missingTables++;
} // END - if
} // END - foreach
// Determine final status (simply compare both counts
$isValid = (count($tables) == $missingTables);
// Disconnect here, we don't need idle database connections laying around
sqlCloseLink(__FUNCTION__, __LINE__);
// If the status is true, disconnect the database
if ($isValid === FALSE) {
// Still something bad happened (e.g. tables found)
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_IN_USE--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_dbase');
} else {
// Remember this tab in session
installTabOkay($currentTab);
}
// Return status
return $isValid;
}
// Call-back function to check if first admin data is valid
function isInstallerPostFirstAdminValid ($currentTab) {
// Is all data valid?
if (!isPostRequestElementSet('admin_login')) {
// Login not set
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_LOGIN_EMPTY--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_login');
return FALSE;
} elseif (strlen(postRequestElement('admin_login')) < 4) {
// Login to short
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_LOGIN_SHORT--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_login');
return FALSE;
} elseif (!isPostRequestElementSet('admin_email')) {
// Email address not set
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_EMAIL_EMPTY--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_email');
return FALSE;
} elseif (!isInstallerAdminEmailValid(postRequestElement('admin_email'))) {
// Invalid email address
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_EMAIL_INVALID--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_email');
return FALSE;
} elseif ((!isPostRequestElementSet('admin_password1')) && (isPostRequestElementSet('admin_password2'))) {
// Password 1 not set
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_PASSWORD1_EMPTY--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_password1');
return FALSE;
} elseif ((isPostRequestElementSet('admin_password1')) && (!isPostRequestElementSet('admin_password2'))) {
// Password 2 not set
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_PASSWORD2_EMPTY--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_password2');
return FALSE;
} elseif (postRequestElement('admin_password1') != postRequestElement('admin_password2')) {
// Passwords mismatch
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_PASSWORDS_MISMATCH--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_password1', 'admin_password2');
return FALSE;
} elseif (!isStrongPassword(postRequestElement('admin_password1'))) {
// Weak passwords entered
$GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_PASSWORDS_WEAK--}';
array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_password1', 'admin_password2');
return FALSE;
} // END - if
// All tests passed
return TRUE;
}
// Store given tab in session
function installTabOkay ($currentTab) {
// Is it set?
if (isSessionVariableSet('installer_okay')) {
// Is this tab already found?
if (strpos(getSession('installer_okay'), $currentTab) === FALSE) {
// Then extend it
setSession('installer_okay', getSession('installer_okay') . ';' . $currentTab);
} // END - if
} else {
// Initially set it
setSession('installer_okay', $currentTab);
}
}
// Checks whether at least the required tabs are completed
function isInstallationDataCompleted () {
// Check both
$isCompleted = (
(isSessionVariableSet('installer_okay')) &&
(strpos(getSession('installer_okay'), 'base_data') !== FALSE) &&
(strpos(getSession('installer_okay'), 'database_config') !== FALSE)
);
// Return it
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCompleted=' . intval($isCompleted) . ',installer_okay=' . getSession('installer_okay'));
return $isCompleted;
}
// Call-back function to check if enable_backlink is Y/N
function isInstallerEnableBacklinkValid ($currentTab) {
// Check and return it
return in_array($currentTab, array('Y', 'N'));
}
// Call-back function to check if warn_no_pass is Y/N
function isInstallerWarnNoPassValid ($currentTab) {
// Check and return it
return in_array($currentTab, array('Y', 'N'));
}
// Call-back function to check if write_footer is Y/N
function isInstallerWriteFooterValid ($currentTab) {
// Check and return it
return in_array($currentTab, array('Y', 'N'));
}
// Call-back function to check if output_mode is Y/N
function isInstallerOutputModeValid ($currentTab) {
// Check and return it
return in_array($currentTab, array('render', 'direct'));
}
// Wrapper to import given installation SQL dump
function importInstallSqlDump ($dumpName) {
// Import the file
importSqlDump('install', $dumpName, 'install');
}
// Wrapper to check if tables.sql and menu-foo.sql are readable
function isInstallerSqlsReadable ($path) {
// Determine it
return ((isFileReadable($path . 'install/tables.sql')) && (isFileReadable($path . 'install/menu-' . getLanguage() . '.sql')));
}
// [EOF]
?>