2015-03-08 18:02:59 +01:00
|
|
|
<?php
|
2015-05-05 03:00:01 +02:00
|
|
|
// Security constant
|
2015-03-08 18:02:59 +01:00
|
|
|
define('BLUDIT', true);
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
// PATHs
|
2015-03-08 18:02:59 +01:00
|
|
|
define('PATH_ROOT', __DIR__.'/');
|
|
|
|
define('PATH_CONTENT', PATH_ROOT.'content/');
|
2015-05-19 01:22:05 +02:00
|
|
|
define('PATH_POSTS', PATH_CONTENT.'posts/');
|
|
|
|
define('PATH_UPLOADS', PATH_CONTENT.'uploads/');
|
2015-05-05 03:00:01 +02:00
|
|
|
define('PATH_PAGES', PATH_CONTENT.'pages/');
|
|
|
|
define('PATH_DATABASES', PATH_CONTENT.'databases/');
|
|
|
|
define('PATH_PLUGINS_DATABASES', PATH_CONTENT.'databases/plugins/');
|
2015-05-15 00:07:45 +02:00
|
|
|
define('DOMAIN', getenv('HTTP_HOST'));
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
$base = (dirname(getenv('SCRIPT_NAME'))=='/')?'/':dirname(getenv('SCRIPT_NAME')).'/';
|
|
|
|
define('HTML_PATH_ROOT', $base);
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
if(!defined('JSON_PRETTY_PRINT')) {
|
|
|
|
define('JSON_PRETTY_PRINT', 128);
|
|
|
|
}
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
// ============================================================================
|
|
|
|
// FUNCTIONS
|
|
|
|
// ============================================================================
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
// Generate a random string
|
|
|
|
// Thanks, http://stackoverflow.com/questions/4356289/php-random-string-generator
|
|
|
|
function getRandomString($length = 10) {
|
|
|
|
return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
function alreadyInstalled()
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2015-05-15 00:07:45 +02:00
|
|
|
return file_exists(PATH_DATABASES.'site.php');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
function checkSystem()
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2015-05-15 00:07:45 +02:00
|
|
|
$stdOut = array();
|
|
|
|
$dirpermissions = 0755;
|
|
|
|
$phpModules = array();
|
|
|
|
|
|
|
|
if(function_exists('get_loaded_extensions'))
|
|
|
|
{
|
|
|
|
$phpModules = get_loaded_extensions();
|
|
|
|
}
|
|
|
|
|
2015-05-19 01:22:05 +02:00
|
|
|
if(!file_exists(PATH_ROOT.'.htaccess'))
|
|
|
|
{
|
|
|
|
$errorText = 'Missing file, upload the file .htaccess';
|
|
|
|
error_log($errorText, 0);
|
|
|
|
array_push($stdOut, $errorText);
|
|
|
|
}
|
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
if(!version_compare(phpversion(), '5.2', '>'))
|
|
|
|
{
|
|
|
|
$errorText = 'Current PHP version '.phpversion().', but you need > 5.3';
|
|
|
|
error_log($errorText, 0);
|
|
|
|
array_push($stdOut, $errorText);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!in_array('dom', $phpModules))
|
|
|
|
{
|
|
|
|
$errorText = 'PHP module DOM does not exist';
|
|
|
|
error_log($errorText, 0);
|
|
|
|
array_push($stdOut, $errorText);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!in_array('json', $phpModules))
|
|
|
|
{
|
|
|
|
$errorText = 'PHP module JSON does not exist';
|
|
|
|
error_log($errorText, 0);
|
|
|
|
array_push($stdOut, $errorText);
|
|
|
|
}
|
|
|
|
|
2015-05-19 05:08:16 +02:00
|
|
|
if(!@mkdir(PATH_CONTENT.'asd'))
|
2015-05-15 00:07:45 +02:00
|
|
|
{
|
2015-05-19 05:08:16 +02:00
|
|
|
$errorText = 'Writing test failure, check directory content permissions. (Error 2005)';
|
2015-05-15 00:07:45 +02:00
|
|
|
error_log($errorText, 0);
|
|
|
|
array_push($stdOut, $errorText);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $stdOut;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
function install($adminPassword, $email)
|
|
|
|
{
|
|
|
|
$stdOut = array();
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Create directories
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// 7=read,write,execute | 5=read,execute
|
|
|
|
$dirpermissions = 0755;
|
|
|
|
$firstPostSlug = 'first-post';
|
|
|
|
|
|
|
|
if(!mkdir(PATH_POSTS.$firstPostSlug, $dirpermissions, true))
|
|
|
|
{
|
|
|
|
$errorText = 'Error when trying to created the directory=>'.PATH_POSTS.$firstPostSlug;
|
|
|
|
error_log($errorText, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!mkdir(PATH_PAGES.'error', $dirpermissions, true))
|
|
|
|
{
|
|
|
|
$errorText = 'Error when trying to created the directory=>'.PATH_PAGES.'error';
|
|
|
|
error_log($errorText, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!mkdir(PATH_PLUGINS_DATABASES, $dirpermissions, true))
|
|
|
|
{
|
2015-05-19 01:22:05 +02:00
|
|
|
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES;
|
|
|
|
error_log($errorText, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!mkdir(PATH_UPLOADS, $dirpermissions, true))
|
|
|
|
{
|
|
|
|
$errorText = 'Error when trying to created the directory=>'.PATH_UPLOADS;
|
|
|
|
error_log($errorText, 0);
|
2015-05-15 00:07:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Create files
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
$dataHead = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>".PHP_EOL;
|
|
|
|
|
|
|
|
// File pages.php
|
|
|
|
$data = array(
|
|
|
|
'error'=>array(
|
|
|
|
'description'=>'Error page',
|
|
|
|
'username'=>'admin',
|
|
|
|
'tags'=>'',
|
|
|
|
'status'=>'published',
|
|
|
|
'unixTimeCreated'=>1430686755,
|
|
|
|
'unixTimeModified'=>0,
|
|
|
|
'position'=>0
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
file_put_contents(PATH_DATABASES.'pages.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
|
|
|
|
|
|
|
// File posts.php
|
|
|
|
$data = array(
|
|
|
|
$firstPostSlug=>array(
|
|
|
|
'description'=>'Welcome to Bludit',
|
|
|
|
'username'=>'admin',
|
|
|
|
'status'=>'published',
|
|
|
|
'tags'=>'welcome, bludit, cms',
|
|
|
|
'allowComments'=>false,
|
|
|
|
'unixTimeCreated'=>1430875199,
|
|
|
|
'unixTimeModified'=>0
|
2015-05-05 03:00:01 +02:00
|
|
|
)
|
2015-05-15 00:07:45 +02:00
|
|
|
);
|
|
|
|
file_put_contents(PATH_DATABASES.'posts.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
|
|
|
|
|
|
|
// File site.php
|
|
|
|
$data = array(
|
2015-05-19 01:22:05 +02:00
|
|
|
'title'=>'Bludit',
|
|
|
|
'slogan'=>'cms',
|
2015-05-15 00:07:45 +02:00
|
|
|
'description'=>'',
|
|
|
|
'footer'=>'Footer text - ©2015',
|
|
|
|
'language'=>'english',
|
|
|
|
'locale'=>'en_EN',
|
|
|
|
'timezone'=>'UTC',
|
|
|
|
'theme'=>'pure',
|
|
|
|
'adminTheme'=>'default',
|
|
|
|
'homepage'=>'',
|
|
|
|
'postsperpage'=>'6',
|
|
|
|
'uriPost'=>'/post/',
|
|
|
|
'uriPage'=>'/',
|
|
|
|
'uriTag'=>'/tag/',
|
|
|
|
'advancedOptions'=>'false',
|
|
|
|
'url'=>'http://'.DOMAIN.HTML_PATH_ROOT
|
|
|
|
);
|
|
|
|
|
|
|
|
file_put_contents(PATH_DATABASES.'site.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
$salt = getRandomString();
|
|
|
|
$passwordHash = sha1($adminPassword.$salt);
|
|
|
|
$registered = time();
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
// File users.php
|
|
|
|
$data = array(
|
|
|
|
'admin'=>array(
|
|
|
|
'firstName'=>'',
|
|
|
|
'lastName'=>'',
|
|
|
|
'twitter'=>'',
|
|
|
|
'role'=>'admin',
|
|
|
|
'password'=>$passwordHash,
|
|
|
|
'salt'=>$salt,
|
|
|
|
'email'=>$email,
|
|
|
|
'registered'=>$registered
|
|
|
|
)
|
|
|
|
);
|
2015-05-07 03:00:01 +02:00
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
file_put_contents(PATH_DATABASES.'users.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
|
|
|
|
|
|
|
// File index.txt for error page
|
|
|
|
$data = 'Title: Error
|
|
|
|
Content: The page has not been found.';
|
|
|
|
|
|
|
|
file_put_contents(PATH_PAGES.'error/index.txt', $data, LOCK_EX);
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-05-07 03:00:01 +02:00
|
|
|
// File index.txt for welcome post
|
2015-05-15 00:07:45 +02:00
|
|
|
$data = 'title: First post
|
2015-05-07 03:00:01 +02:00
|
|
|
Content:
|
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
Congratulations, you have installed **Bludit** successfully!
|
|
|
|
---
|
|
|
|
|
|
|
|
What\'s next:
|
|
|
|
---
|
|
|
|
- Administrate your Bludit from the [Admin Area](./admin/)
|
|
|
|
- Follow Bludit on [Twitter](https://twitter.com/bludit) / Facebook / Google+
|
2015-05-07 03:00:01 +02:00
|
|
|
- Visit the forum for support
|
|
|
|
- Read the documentation for more information
|
|
|
|
- Share with your friend :D';
|
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
file_put_contents(PATH_POSTS.$firstPostSlug.'/index.txt', $data, LOCK_EX);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// MAIN
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
if( alreadyInstalled() )
|
|
|
|
{
|
|
|
|
exit('Bludit already installed');
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
|
|
|
{
|
|
|
|
if(install($_POST['password'],$_POST['email']))
|
|
|
|
{
|
|
|
|
if(!headers_sent())
|
|
|
|
{
|
|
|
|
header("Location:".HTML_PATH_ROOT, TRUE, 302);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit('<meta http-equiv="refresh" content="0; url="'.HTML_PATH_ROOT.'" />');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<!doctype html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<base href="admin/themes/default/">
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
|
|
|
<title>Bludit Installer</title>
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="./css/kube.min.css">
|
|
|
|
<link rel="stylesheet" href="./css/installer.css">
|
|
|
|
|
|
|
|
<script src="./js/jquery.min.js"></script>
|
|
|
|
<script src="./js/kube.min.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="units-row">
|
|
|
|
<div class="unit-centered unit-60">
|
|
|
|
<div class="main">
|
|
|
|
<h1 class="title">Bludit Installer</h1>
|
|
|
|
<p>Welcome to the Bludit installer</p>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
$system = checkSystem();
|
|
|
|
|
|
|
|
if(empty($system))
|
|
|
|
{
|
|
|
|
?>
|
|
|
|
|
|
|
|
<p>Complete the form, choose a password for the username <strong>admin</strong></p>
|
|
|
|
<div class="unit-centered unit-40">
|
|
|
|
<form method="post" action="" class="forms" autocomplete="off">
|
|
|
|
|
|
|
|
<label>
|
|
|
|
<input type="text" value="admin" disabled="disabled" class="width-100">
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
<input type="password" name="password" placeholder="Password" class="width-100" autocomplete="off">
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
<input type="text" name="email" placeholder="Email" class="width-100" autocomplete="off">
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
<button class="btn btn-blue width-100">Install</button>
|
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo '<div class="unit-centered unit-40">';
|
|
|
|
echo '<table class="table-stripped">';
|
|
|
|
|
|
|
|
foreach ($system as $value)
|
|
|
|
{
|
|
|
|
echo '<tr><td>'.$value.'</td></tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '</table>';
|
|
|
|
echo '</div';
|
|
|
|
}
|
|
|
|
?>
|
2015-05-07 03:00:01 +02:00
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|