0,','"configCreateDate" => '.$configfilemtime.',',$settingsContents);
// Now update the config file
$fh = fopen(dirname(__FILE__)."/../data/".$settingsFile, 'w') or die("Can't update config file. Please set public write permissions on ".$settingsFile." and press refresh");
fwrite($fh, $settingsContents);
fclose($fh);
// Set the new value in array
$ICEcoderUserSettings['configCreateDate'] = $configfilemtime;
}
// On mismatch of settings file to system, rename to .old and reload
If ($ICEcoderUserSettings["versionNo"] != $ICEcoderSettings["versionNo"]) {
rename(dirname(__FILE__)."/../data/".$settingsFile,dirname(__FILE__)."/../data/".str_replace(".php",".old",$settingsFile));
header("Location: settings.php");
echo "";
die('Found old settings file, reloading...');
}
// Join ICEcoder settings and user settings together to make our final ICEcoder array
$ICEcoder = $ICEcoderSettings + $ICEcoderUserSettings;
// Include language file
// Load base first as foundation
include(dirname(__FILE__)."/../lang/".basename($ICEcoder['languageBase']));
$baseText = $text;
// Load chosen language ontop to replace base
include(dirname(__FILE__)."/../lang/".basename($ICEcoder['languageUser']));
$text = array_replace_recursive($baseText, $text);
$_SESSION['text'] = $text;
// Login not required or we're in demo mode and have password set in our settings, log us straight in
if ((!$ICEcoder['loginRequired'] || $ICEcoder['demoMode']) && $ICEcoder['password']!="") {$_SESSION['loggedIn']=true;};
$demoMode = $ICEcoder['demoMode'];
// Update this config file?
include(dirname(__FILE__)."/settings-update.php");
// Set loggedIn and username to false if not set as yet
if (!isset($_SESSION['loggedIn'])) {$_SESSION['loggedIn'] = false;};
if (!isset($_SESSION['username'])) {$_SESSION['username'] = false;};
// Attempt a login with password
if(isset($_POST['submit']) && $setPWorLogin=="login") {
// On success, set username if multiUser, loggedIn to true and redirect
if (verifyHash(strClean($_POST['password']),$ICEcoder["password"])==$ICEcoder["password"]) {
session_regenerate_id();
if ($ICEcoder["multiUser"]) {
$_SESSION['username'] = $_POST['username'];
}
$_SESSION['loggedIn'] = true;
include(dirname(__FILE__)."/../processes/on-user-login.php");
header('Location: ../');
echo "";
die('Logging you in...');
} else {
include(dirname(__FILE__)."/../processes/on-user-login-fail.php");
}
};
// Re-establish our loggedIn state and username
$_SESSION['loggedIn'] = $_SESSION['loggedIn'];
$_SESSION['username'] = $_SESSION['username'];
// Define the serverType, docRoot & iceRoot
$serverType = stristr($_SERVER['SERVER_SOFTWARE'], "win") ? "Windows" : "Linux";
$docRoot = rtrim(str_replace("\\","/",$ICEcoder['docRoot']));
$iceRoot = rtrim(str_replace("\\","/",$ICEcoder["root"]));
if ($_SESSION['loggedIn'] && basename($_SERVER['SCRIPT_NAME']) == "index.php") {
echo "";
}
// Establish the dir ICEcoders running from
$ICEcoderDirFullPath = rtrim(str_replace("\\","/",dirname($_SERVER['SCRIPT_FILENAME'])),"/lib");
$rootPrefix = '/'.str_replace("/","\/",preg_quote(str_replace("\\","/",$docRoot))).'/';
$ICEcoderDir = preg_replace($rootPrefix, '', $ICEcoderDirFullPath, 1);
// Setup our file security vars
$settingsArray = array("findFilesExclude","bannedFiles","allowedIPs");
for ($i=0;$iwindow.location='lib/login.php';";
} else {
header('Location: login.php');
echo "";
}
die('Redirecting to login...');
// If we are on the login screen and not logged in
// If we are on the login screen and not logged in
} elseif (!$_SESSION['loggedIn']) {
// If the password hasn't been set and we're setting it
if ($ICEcoder["password"] == "" && isset($_POST['submit']) && (strpos($_POST['submit'],"set password")>-1)) {
$password = generateHash(strClean($_POST['password']));
$settingsContents = getData("../data/".$settingsFile);
// Replace our empty password with the one submitted by user
$settingsContents = str_replace('"password" => "",','"password" => "'.$password.'",',$settingsContents);
// Also set the update checker preference
$checkUpdates = $_POST['checkUpdates']=="true" ? "true" : "false";
// once to cover the true setting, once to cover false
$settingsContents = str_replace('"checkUpdates" => true,','"checkUpdates" => '.$checkUpdates.',',$settingsContents);
$settingsContents = str_replace('"checkUpdates" => false,','"checkUpdates" => '.$checkUpdates.',',$settingsContents);
// Now update the config file
$fh = fopen("../data/".$settingsFile, 'w') or die("Can't update config file. Please set public write permissions on data/".$settingsFile." and press refresh");
fwrite($fh, $settingsContents);
fclose($fh);
// Create a duplicate version for the IP address of the domain if it doesn't exist yet
$serverAddr = $_SERVER['SERVER_ADDR'];
if ($serverAddr == "1" || $serverAddr == "::1") {
$serverAddr = "127.0.0.1";
}
$settingsFileAddr = 'config-'.$username.str_replace(".","_",$serverAddr).'.php';
if (!file_exists(dirname(__FILE__)."/../data/".$settingsFileAddr)) {
if (!copy(dirname(__FILE__)."/../data/".$settingsFile, dirname(__FILE__)."/../data/".$settingsFileAddr)) {
die("Couldn't create $settingsFileAddr. Maybe you need write permissions on the data folder?");
}
}
// Disable the enableRegistration config setting if the user had that option chosen
if (isset($_POST['disableFurtherRegistration'])) {
$updatedConfigSettingsFile = getData(dirname(__FILE__)."/../data/".$configSettings);
if ($fUConfigSettings = fopen(dirname(__FILE__)."/../data/".$configSettings, 'w')) {
$updatedConfigSettingsFile = str_replace('"enableRegistration" => true','"enableRegistration" => false',$updatedConfigSettingsFile);
fwrite($fUConfigSettings, $updatedConfigSettingsFile);
fclose($fUConfigSettings);
} else {
die("Cannot update config file data/".$configSettings.". Please check write permissions on data/ and try again");
}
}
// Set the session user level
if ($ICEcoder["multiUser"]) {
$_SESSION['username']=$_POST['username'];
}
$_SESSION['loggedIn'] = true;
include(dirname(__FILE__)."/../processes/on-user-new.php");
// Finally, load again as now this file has changed and auto login
header('Location: ../');
echo "";
die('Logging you in...');
}
// ===================================================
// We're likely showing the login screen at this point
// ===================================================
} elseif ($ICEcoder['loginRequired'] && $_SESSION['loggedIn'] && $ICEcoder["password"]=="") {
header("Location: ../?logout");
echo "";
die('Logging you out...');
} else {
// ==================================
// Continue with whatever we're doing
// ==================================
}