Файл: install/index.php
Строк: 296
<?php
$config['version'] = 'v5.0 Beta';
$config['webtheme'] = 'mobile_default'; // default web theme
$config['mobtheme'] = 'mobile_default'; // default web theme
$config['language'] = 'english'; // default language
$languages = array('english', 'russian', 'ukrainian', 'uzbek', 'lithuanian');
define('TIME', time());
$debugmode = 0;
if ($debugmode) {
@error_reporting(E_ALL);
@ini_set('display_errors', true);
@ini_set('html_errors', true);
@ini_set('error_reporting', E_ALL);
} else {
@error_reporting(E_ALL ^ E_NOTICE);
@ini_set('display_errors', false);
@ini_set('html_errors', false);
@ini_set('error_reporting', E_ALL ^ E_NOTICE);
}
require_once '../core/functions.php';
function split_sql($sql) {
$sql = trim($sql);
$sql = preg_replace("|n#[^n]*n|", "n", $sql);
$buffer = array();
$ret = array();
$in_string = false;
for ($i = 0; $i < strlen($sql) - 1; $i++) {
if ($sql[$i] == ";" && !$in_string) {
$ret[] = substr($sql, 0, $i);
$sql = substr($sql, $i + 1);
$i = 0;
}
if ($in_string && ($sql[$i] == $in_string) && $buffer[1] != "\") {
$in_string = false;
} elseif (!$in_string && ($sql[$i] == '"' || $sql[$i] == "'") && (!isset ($buffer[0]) || $buffer[0] != "\")) {
$in_string = $sql[$i];
}
if (isset ($buffer[1])) {
$buffer[0] = $buffer[1];
}
$buffer[1] = $sql[$i];
}
if (!empty ($sql)) {
$ret[] = $sql;
}
return ($ret);
}
$cookieTheme = isset($_COOKIE['theme']) ? abs(intval($_COOKIE['theme'])) : detectMob();
switch ($cookieTheme)
{
case 1: $config['theme'] = $config['webtheme']; break;
default: $config['theme'] = $config['mobtheme']; break;
}
$lng = isset($_COOKIE['lng']) ? check($_COOKIE['lng']) : FALSE;
if ($lng) {
if (in_array($lng, $languages)) {
$config['language'] = $lng;
}
}
require_once 'language/'.$config['language'].'.php';
$config['title'] = $lang['Installation'];
require_once 'html/header.htm';
$lng = isset($_POST['lng']) ? check($_POST['lng']) : FALSE;
if ($lng && in_array($lng, $languages))
{
setcookie("lng", $lng, time() + 3600 * 24 * 365, '/', '');
redirect('/install');
}
echo '<div class="content2">
<b>'.$lang['Step'].' 1</b>: '.$lang['Set_your_default_language'].'
<form action="" method="post" name="form">
<select name="lng">';
foreach ($languages as $language)
{
$checked = $language == $config['language'] ? ' selected="selected"' : FALSE;
echo '<option value="'.$language.'"'.$checked.'>'.$language.'</option>';
}
echo '
</select><br>
<input name="submit" type="submit" value="'.$lang['Save_Changes'].'">
</form>
</div>
<div class="content2"><b>'.$lang['Step'].' 2</b>: '.$lang['Check_permissions'].' & '.$lang['Establish_connection'].'<br>';
if (!is_writable('../uploads/'))
{
$error_uploads = str_replace('%dir%', '<b>/uploads/</b>', $lang['No_write_permission_to_directory']);
echo $error_uploads.'<br />';
$error_step2 = 1;
}
if (!is_writable('../cache/'))
{
$lang['No_write_permission_to_directory'] = str_replace('%dir%', '<b>/cache/</b>', $lang['No_write_permission_to_directory']);
echo $lang['No_write_permission_to_directory'].'<br />';
$error_step2 = 1;
}
if (!is_writable('../config.php'))
{
$lang['No_permission_to_write_to_file'] = str_replace('%file%', '<b>/config.php</b>', $lang['No_permission_to_write_to_file']);
echo $lang['No_permission_to_write_to_file'].'<br />';
$error_step2 = 1;
}
if (isset($error_step2))
{
echo '<hr><b>'.$lang['Installation_cannot_proceed_due_to_a_permissions_problem'].'</b>';
}
//
// step 3:
else
{
require_once '../config.php';
if (defined('HOME') && defined('HTTPHOME') && defined('DBHOST') && defined('DBNAME') && defined('DBUSER') && defined('DBPASS'))
{
try {
$dbh = new PDO('mysql:host='.DBHOST.';port=3306;dbname='.DBNAME, DBUSER, DBPASS);
} catch (PDOException $e) {
$error_e = '<b>Connection failed: ' . $e->getMessage().'</b><br>';
}
}
else
{
$error_e = 1;
}
if (isset($error_e))
{
$host = isset($_POST['host']) ? htmlspecialchars($_POST['host']) : FALSE;
$dbname = isset($_POST['dbname']) ? htmlspecialchars($_POST['dbname']) : FALSE;
$dbuser = isset($_POST['dbuser']) ? htmlspecialchars($_POST['dbuser']) : FALSE;
$userpass = isset($_POST['userpass']) ? htmlspecialchars($_POST['userpass']) : FALSE;
if ($host && $dbname && $dbuser && $userpass)
{
try {
$dbh = new PDO('mysql:host='.$host.';port=3306;dbname='.$dbname, $dbuser, $userpass);
$home = $_SERVER['HTTP_HOST'];
$charset = 'charset';
$debugmode = 'debugmode';
$dbfile = "<?php
define('HOME', '$home');
define('HTTPHOME', 'http://$home/');
define('DBHOST', '$host');
define('DBPORT', '3306');
define('DBNAME', '$dbname');
define('DBUSER', '$dbuser');
define('DBPASS', '$userpass');
$$charset = 'utf-8';
$$debugmode = 0;";
$put = file_put_contents('../config.php', $dbfile);
if (!$put == FALSE)
{
@chmod('../config.php', 0664);
redirect('/install');
}
} catch (PDOException $e) {
$error_step3 = '<b>Connection failed: ' . $e->getMessage().'</b><br>';
}
}
echo isset($error_step3) ? $error_step3 : FALSE;
echo '
<form action="" method="post" name="form">
'.$lang['MySQL_Server'].'<br /><input name="host" type="text" value="'.($host ? $host : 'localhost').'"><br />
'.$lang['Database_Name'].'<br><input name="dbname" type="text" value="'.$dbname.'"><br />
'.$lang['Database_User'].'<br><input name="dbuser" type="text" value="'.$dbuser.'"><br />
'.$lang['Database_User_Password'].'<br><input name="userpass" type="password" value="'.$userpass.'"><br />
<input name="submit" type="submit" value="'.$lang['Establish_connection'].'">
</form>
';
}
else
{
echo $lang['Connection_Established'].'</div><div class="content2"><b>'.$lang['Step'].' 3</b>: '.$lang['Create_an_administrator_account'].'<br>';
$username = isset($_POST['username']) ? check($_POST['username']) : FALSE;
$password = isset($_POST['password']) ? check($_POST['password']) : FALSE;
$email = isset($_POST['email']) ? check($_POST['email']) : FALSE;
require_once '../core/mysqlpdo.php';
$table_exists = DB::run()->querySingle("SELECT count(`table_name`) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = 'users';", array(DBNAME));
if (!$table_exists)
{
if ($username && $password && $email)
{
$query = file_get_contents('coolcms.sql');
$pieces = split_sql($query);
for ($i = 0; $i < count($pieces); $i++) {
$pieces[$i] = trim($pieces[$i]);
if (!empty ($pieces[$i]) && $pieces[$i] != "#") {
DB::run()->query($pieces[$i]);
}
}
DB::run()->query("insert into `users` set
`username` = ?,
`password` = ?,
`email` = ?,
`verified` = 1,
`access` = 2,
`regtime` = ?,
`lastseen` = ?,
`theme` = ?,
`language` = ?,
`ipp` = 10;
", array(
$username,
hash('sha512', md5(md5($password))),
$email,
TIME,
TIME,
$config['theme'],
$config['language']
));
$message = str_replace('%version%', $config['version'], $lang['If_you_can_see_this message__']);
DB::run()->query("insert into `news` set `userid` = 1, `subject` = ?, `message` = ?, `time` = ?;", array($lang['Welcome'], $message, TIME));
DB::run()->query("update `configuration` set `value` = ? where `name` = ?;", array(HOME, 'title'));
DB::run()->query("update `configuration` set `value` = ? where `name` = ?;", array($config['language'], 'language'));
echo $lang['Congrats'].'!<br>
'.$lang['Your_account_has_been_created_successfully'].'.<br>
'.$lang['Your_account_details'].':<br>
'.$lang['Username'].': <b>'.$username.'</b><br>
'.$lang['Password'].': <b>'.$password.'</b><br>
'.$lang['Email'].': '.$email.'<br>
'.$lang['Autologin_Link'].'<br>
<input name="autologin" type="text" value="'.HTTPHOME.$username.':'.$password.'"><br>
<a href="'.HTTPHOME.$username.':'.$password.'">'.$lang['Sign_In'].'</a>';
}
else
{
echo '
<form action="" method="post" name="form">
'.$lang['Username'].' (a-z)<br><input name="username" type="text" value="'.$username.'"><br>
'.$lang['Password'].'<br><input name="password" type="password" value="'.$password.'"><br>
'.$lang['Email'].'<br><input name="email" type="text" value="'.$email.'"><br>
<input name="submit" type="submit" value="'.$lang['Finish'].'">
</form>
</div>';
}
}
else
{
redirect(HTTPHOME);
}
}
}
echo '</div>';
require_once 'html/footer.htm';