<?php
/**
* installer.inc
* Setting up the system for the first time.
* @copyright Copyright(c) 2002-2009 Bjorn Winberg
* @author Bjorn Winberg <cms@anomalye.net>
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License version 2
* @package AnomalyWiki
*/
system_loadSettings('installer');
$GLOBALS['sysEnv']['var']['system']['modules']['installer'] = array(
'name' => system_loadStr('INSTALLER_MODULE'),
'version' => '0.6.0',
);
/**
* Standard display function.
*/
function installer_controller(){
system_readParamStr('confirm', 0, $GLOBALS['_S']['system']['LENGTH_S'], '');
if($GLOBALS['_S']['system']['ENABLE_INSTALLER'] != 'true'){
trigger_error(system_loadStr('SYSTEM_PERMISSIONDENIED'), E_USER_WARNING);
return false;
}
if($GLOBALS['_S']['system']['INSTALLER_PASSWORD'] != $GLOBALS['_IN']['confirm']['enc']){
trigger_error(system_loadStr('SYSTEM_PERMISSIONDENIED'), E_USER_WARNING);
return false;
}
if($GLOBALS['_IN']['a']['enc'] == 'install1'){
return installer_installCore();
}
else{
installer_verifySystem();
return system_applyTemplate('installer_user.inc');
}
}
/*
* Setup the core system.
* @access private
*/
function installer_installCore(){
system_loadModule('authadmin');
system_loadModule('auth');
system_readParamStr('name', 1, $GLOBALS['_S']['system']['LENGTH_XS']);
system_parseAsUId('name');
system_readParamStr('password', 1, $GLOBALS['_S']['system']['LENGTH_S']);
system_readParamStr('confirmpass', 1, $GLOBALS['_S']['system']['LENGTH_S']);
$protectedNames = explode(rawurlencode(','),rawurlencode($GLOBALS['_S']['auth']['PROTECTED_NAMES']));
if(array_search($GLOBALS['_IN']['name']['enc'], $protectedNames) !== false){
trigger_error(system_loadStr('AUTH_REGISTER_FAIL'), E_USER_WARNING);
return system_applyTemplate('installer_user.inc');
}
if($GLOBALS['_IN']['password']['enc'] == '' || $GLOBALS['_IN']['name']['enc'] == ''){
trigger_error(system_loadStr('SYSTEM_DATA_INPUT_FAIL'), E_USER_WARNING);
return system_applyTemplate('installer_user.inc');
}
if($GLOBALS['_IN']['password']['enc'] != $GLOBALS['_IN']['confirmpass']['enc']){
trigger_error(system_loadStr('AUTH_PASS_CONFIRM_FAIL'), E_USER_WARNING);
return system_applyTemplate('installer_user.inc');
}
$userList = system_dbRead(system_dbKey('AUTH_USERLIST'));
if($userList !== false){
trigger_error(system_loadStr('INSTALLER_DATABASEFOUND'), E_USER_WARNING);
return system_applyTemplate('installer_user.inc');
}
$actions[rawurlencode('ARTICLE/DELETE_*')] = 0;
$actions[rawurlencode('ARTICLE/EDIT_*')] = 0;
$actions[rawurlencode('ARTICLE/HISTORY_*')] = 0;
$actions[rawurlencode('AUTH/ADMIN_*')] = 0;
$actions[rawurlencode('AUTH/LOGIN_*')] = 0;
$actions[rawurlencode('AUTH/LOGOUT_*')] = 0;
$actions[rawurlencode('AUTH/REGISTER_*')] = 0;
$actions[rawurlencode('AUTH/UPLOAD_*')] = 0;
$actions[rawurlencode('CATEGORY/BROWSE_*')] = 0;
$actions[rawurlencode('COMMENT/ADD_*')] = 0;
$actions[rawurlencode('COMMENT/LIST_*')] = 0;
$actions[rawurlencode('COMMENT/DELETE_*')] = 0;
$actions[rawurlencode('COMMENT/EDITALL_*')] = 0;
$actions[rawurlencode('COMMENT/EDITSELF_*')] = 0;
$actions[rawurlencode('FILES/BROWSE_*')] = 0;
$actions[rawurlencode('FILES/DELETE_*')] = 0;
$actions[rawurlencode('FILES/DOWNLOAD_*')] = 0;
$actions[rawurlencode('FILES/OLDDOWNLOAD_*')] = 0;
$actions[rawurlencode('FILES/MKDIR_*')] = 0;
$actions[rawurlencode('FILES/UPLOAD_*')] = 0;
$actions[rawurlencode('LAYOUT_*')] = 0;
$actions[rawurlencode('LAYOUT_ADMIN')] = 0;
$actions[rawurlencode('LAYOUT_TOOLBOX')] = 0;
$actions[rawurlencode('LAYOUT_EVERYBODY')] = 0;
$actions[rawurlencode('LOGS_*')] = 0;
$actions[rawurlencode('MENUEDITOR/ADMIN_*')] = 0;
$actions[rawurlencode('SETTINGS/ADMIN_*')] = 0;
$actions[rawurlencode('STATS_*')] = 0;
$actions[rawurlencode('STATS_VISITORS')] = 0;
$actions[rawurlencode('STATS_REFERERS')] = 0;
$actions[rawurlencode('STATS_DOMAINS')] = 0;
$actions[rawurlencode('STATS_DELETE')] = 0;
$actions[rawurlencode('STATS_ONLINE')] = 0;
$actions[rawurlencode('STATS_SILLYDB')] = 0;
system_dbWrite(system_dbKey('AUTH_ACTIONLIST'), $actions);
$groups[rawurlencode('User')]['description'] = '';
$groups[rawurlencode('User')]['actions'][rawurlencode('AUTH/LOGOUT_*')] = 0;
$groups[rawurlencode('User')]['actions'][rawurlencode('AUTH/UPLOAD_*')] = 0;
$groups[rawurlencode('User')]['actions'][rawurlencode('CATEGORY/BROWSE_*')] = 0;
$groups[rawurlencode('User')]['actions'][rawurlencode('COMMENT/ADD_*')] = 0;
$groups[rawurlencode('User')]['actions'][rawurlencode('COMMENT/LIST_*')] = 0;
$groups[rawurlencode('User')]['actions'][rawurlencode('LAYOUT_EVERYBODY')] = 0;
$groups[rawurlencode('User')]['actions'][rawurlencode('LAYOUT_TOOLBOX')] = 0;
$groups[rawurlencode('User')]['actions'][rawurlencode('FILES/DOWNLOAD_*')] = 0;
$groups[rawurlencode('User')]['actions'][rawurlencode('STATS_ONLINE')] = 0;
$groups[rawurlencode('Guest')]['description'] = '';
$groups[rawurlencode('Guest')]['actions'][rawurlencode('AUTH/REGISTER_*')] = 0;
$groups[rawurlencode('Guest')]['actions'][rawurlencode('AUTH/LOGIN_*')] = 0;
$groups[rawurlencode('Guest')]['actions'][rawurlencode('COMMENT/LIST_*')] = 0;
$groups[rawurlencode('Guest')]['actions'][rawurlencode('FILES/DOWNLOAD_*')] = 0;
$groups[rawurlencode('Guest')]['actions'][rawurlencode('LAYOUT_EVERYBODY')] = 0;
$groups[rawurlencode('Guest')]['actions'][rawurlencode('STATS_ONLINE')] = 0;
$groups[rawurlencode('Administrator')]['description'] = '';
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('AUTH/ADMIN_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('AUTH/REGISTER_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('AUTH/UPLOAD_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('ARTICLE/DELETE_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('ARTICLE/EDIT_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('ARTICLE/HISTORY_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('CATEGORY/BROWSE_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('COMMENT/ADD_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('COMMENT/LIST_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('COMMENT/DELETE_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('COMMENT/EDITALL_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('COMMENT/EDITSELF_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('FILES/BROWSE_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('FILES/DELETE_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('FILES/DOWNLOAD_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('FILES/OLDDOWNLOAD_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('FILES/MKDIR_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('FILES/UPLOAD_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('LAYOUT_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('LOGS_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('MENUEDITOR/ADMIN_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('STATS_*')] = 0;
$groups[rawurlencode('Administrator')]['actions'][rawurlencode('SETTINGS/ADMIN_*')] = 0;
system_dbWrite(system_dbKey('AUTH_GROUPLIST'), $groups);
$userItem['authGroups'][rawurlencode('Administrator')] = 0;
$userItem['authGroups'][rawurlencode('User')] = 0;
$userItem['nameDisplay'] = $GLOBALS['_IN']['name']['enc'];
$userItem['randomSalt'] = rand();
$userItem['saltedHash'] = auth_hmacMd5($userItem['randomSalt'], $GLOBALS['_IN']['password']['src']);
$userItem['stats'] = array();
$userItem['creationTime'] = time();
$userItem['IPs'] = array($_SERVER['REMOTE_ADDR'] => $userItem['creationTime']);
$userItem['previousLogin'] = false;
$userItem['currentLogin'] = false;
$userDbKey = system_dbKey('AUTH_USER', array($userItem['nameDisplay']));
system_dbWrite($userDbKey, $userItem);
$userList[$userItem['nameDisplay']] = true;
system_dbWrite(system_dbKey('AUTH_USERLIST'), $userList);
auth_setLoggedSession(false);
system_logEntry(time(), 'system', system_loadStr('INSTALLER_LOG'));
$globalFile = $GLOBALS['_C']['SYSTEM_INI_FULLDIR'] . DIRECTORY_SEPARATOR . 'system.ini';
$globalSettings = parse_ini_file($globalFile, true);
$globalSettings['system']['ENABLE_INSTALLER'] = 'false';
system_saveSettings($globalFile, $globalSettings);
trigger_error(system_loadStr('INSTALLER_OK'), E_USER_NOTICE);
system_resetSettings();
}
/**
* Try to verify that the web server meets the requirements to run Anomaly Wiki.
* @return bool True if requirements are met or if unable to tell conclusively.
*/
function installer_verifySystem(){
$phpVerBits = explode('.', phpversion());
if(($phpVerBits[0] == 4 && $phpVerBits[1] >= 3) || $phpVerBits[0] > 4){
trigger_error(system_loadStr('INSTALLER_VER_OK', array(phpversion())), E_USER_NOTICE);
}
else{
trigger_error(system_loadStr('INSTALLER_VER_FAIL', array(phpversion())), E_USER_WARNING);
return false;
}
}
?>