Installer minor changes

This commit is contained in:
dignajar 2015-08-04 00:10:12 -03:00
parent 6c9fb2a0c1
commit 951cb8f613
7 changed files with 359 additions and 269 deletions

View File

@ -26,3 +26,20 @@ h1.title {
td {
text-align: center;
}
.tools-message {
display: block;
position: relative;
top: 0;
right: 0;
left: 0;
bottom: 0;
max-width: none;
margin-bottom: 30px;
}
#jscompleteEmail {
border-bottom: 1px solid #fff;
display: inline-block;
cursor: pointer;
}

View File

@ -1,2 +0,0 @@
Set the correct permissions on this directory.
Check the documentation: http://docs.bludit.com/en/troubleshooting/writing-test-failure-err205

View File

@ -14,7 +14,7 @@ if( !file_exists('content/databases/site.php') )
exit('<a href="./install.php">First, install Bludit</a>');
}
// DEBUG:
// Load time init
$loadTime = microtime(true);
// Security constant
@ -40,10 +40,3 @@ else
{
require(PATH_BOOT.'site.php');
}
// DEBUG:
// Print all variables/objects
//print_r(get_defined_vars());
//var_dump($_SESSION);
//var_dump($Login->fingerPrint());

View File

@ -21,39 +21,67 @@ define('PATH_UPLOADS', PATH_CONTENT.'uploads'.DS);
define('PATH_PAGES', PATH_CONTENT.'pages'.DS);
define('PATH_DATABASES', PATH_CONTENT.'databases'.DS);
define('PATH_PLUGINS_DATABASES',PATH_CONTENT.'databases'.DS.'plugins'.DS);
define('PATH_KERNEL', PATH_ROOT.'kernel'.DS);
define('PATH_HELPERS', PATH_KERNEL.'helpers'.DS);
define('PATH_LANGUAGES', PATH_ROOT.'languages'.DS);
define('PATH_ABSTRACT', PATH_KERNEL.'abstract'.DS);
define('DOMAIN', getenv('HTTP_HOST'));
// HTML PATHs
$base = (dirname(getenv('SCRIPT_NAME'))==DS)?'/':dirname(getenv('SCRIPT_NAME')).'/';
define('HTML_PATH_ROOT', $base);
// JSON
if(!defined('JSON_PRETTY_PRINT')) {
define('JSON_PRETTY_PRINT', 128);
}
// Helpers class
include(PATH_HELPERS.'sanitize.class.php');
include(PATH_HELPERS.'valid.class.php');
include(PATH_ABSTRACT.'dbjson.class.php');
// ============================================================================
// FUNCTIONS
// ============================================================================
// Generate a random string
function getLanguageList()
{
$files = glob(PATH_LANGUAGES.'*.json');
$tmp = array();
foreach($files as $file)
{
$t = new dbJSON($file, false);
$native = $t->db['language-data']['native'];
$locale = basename($file, '.json');
$tmp[$locale] = $native;
}
return $tmp;
}
// 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);
}
function alreadyInstalled()
{
// Check if Bludit is installed.
function alreadyInstalled() {
return file_exists(PATH_DATABASES.'site.php');
}
// Check the system, permissions, php version, modules, etc.
// Returns an array with the problems otherwise empty array.
function checkSystem()
{
$stdOut = array();
$dirpermissions = 0755;
$phpModules = array();
if(function_exists('get_loaded_extensions'))
{
if(function_exists('get_loaded_extensions')) {
$phpModules = get_loaded_extensions();
}
@ -75,14 +103,14 @@ function checkSystem()
if(!in_array('dom', $phpModules))
{
$errorText = 'PHP module DOM does not exist. (ERR_203)';
$errorText = 'PHP module DOM is not installed. (ERR_203)';
error_log($errorText, 0);
array_push($stdOut, $errorText);
}
if(!in_array('json', $phpModules))
{
$errorText = 'PHP module JSON does not exist. (ERR_204)';
$errorText = 'PHP module JSON is not installed. (ERR_204)';
error_log($errorText, 0);
array_push($stdOut, $errorText);
}
@ -97,7 +125,7 @@ function checkSystem()
return $stdOut;
}
function install($adminPassword, $email)
function install($adminPassword, $email, $language)
{
$stdOut = array();
@ -174,8 +202,8 @@ function install($adminPassword, $email)
'slogan'=>'cms',
'description'=>'',
'footer'=>'Footer text - ©2015',
'language'=>'english',
'locale'=>'en_US',
'language'=>$language,
'locale'=>$language,
'timezone'=>'UTC',
'theme'=>'pure',
'adminTheme'=>'default',
@ -225,7 +253,7 @@ function install($adminPassword, $email)
file_put_contents(PATH_PAGES.'error'.DS.'index.txt', $data, LOCK_EX);
// File index.txt for welcome post
$data = 'title: First post
$data = 'Title: First post
Content:
Congratulations, you have installed **Bludit** successfully!
@ -244,18 +272,44 @@ What\'s next:
return true;
}
function checkPOST($_POST)
{
// Check empty password
if(empty($_POST['password']))
{
return '<div>The password field is empty</div>';
}
// Check invalid email
if(!Valid::email($_POST['email']))
{
return '<div>Your email address is invalid.</div><div id="jscompleteEmail">Proceed anyway!</div>';
}
// Sanitize email
$email = sanitize::email($_POST['email']);
// Install Bludit
install($_POST['password'], $email, $_POST['language']);
return true;
}
// ============================================================================
// MAIN
// ============================================================================
if( alreadyInstalled() )
{
$error = '';
if( alreadyInstalled() ) {
exit('Bludit already installed');
}
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
if(install($_POST['password'],$_POST['email']))
$error = checkPOST($_POST);
if($error===true)
{
if(!headers_sent())
{
@ -263,7 +317,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
exit;
}
exit('<meta http-equiv="refresh" content="0; url="'.HTML_PATH_ROOT.'" />');
exit('<meta http-equiv="refresh" content="0; url="'.HTML_PATH_ROOT.'">');
}
}
@ -299,19 +353,38 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
?>
<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">
<?php
if(!empty($error)) {
echo '<div class="tools-message tools-message-red">'.$error.'</div>';
}
?>
<form id="jsformInstaller" 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">
<input type="text" name="password" id="jspassword" placeholder="Password, visible field!" class="width-100" autocomplete="off" maxlength="100" value="<?php echo isset($_POST['password'])?$_POST['password']:'' ?>">
</label>
<label>
<input type="text" name="email" placeholder="Email" class="width-100" autocomplete="off">
<input type="text" name="email" id="jsemail" placeholder="Email" class="width-100" autocomplete="off" maxlength="100">
</label>
<label for="jslanguage">
<select id="jslanguage" name="language" class="width-100">
<?php
$htmlOptions = getLanguageList();
foreach($htmlOptions as $locale=>$nativeName) {
echo '<option value="'.$locale.'">'.$nativeName.'</option>';
}
?>
</select>
</label>
<p>
@ -324,7 +397,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
}
else
{
echo '<div class="unit-centered unit-40">';
echo '<div class="unit-centered unit-50">';
echo '<table class="table-stripped">';
foreach ($system as $value)
@ -336,9 +409,21 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
echo '</div';
}
?>
</div>
</div>
<script>
$(document).ready(function()
{
$("#jscompleteEmail").on("click", function() {
$("#jsemail").val('noreply@localhost.com');
if(!$("jspassword").val()) {
$("#jsformInstaller").submit();
}
});
});
</script>
</div>
</div>
</div>
</body>
</html>

View File

@ -113,6 +113,7 @@ include(PATH_HELPERS.'theme.class.php');
include(PATH_HELPERS.'session.class.php');
include(PATH_HELPERS.'redirect.class.php');
include(PATH_HELPERS.'sanitize.class.php');
include(PATH_HELPERS.'valid.class.php');
include(PATH_HELPERS.'filesystem.class.php');
include(PATH_HELPERS.'alert.class.php');
include(PATH_HELPERS.'paginator.class.php');

View File

@ -55,35 +55,17 @@ class Sanitize {
return true;
}
// old
public static function ip($ip)
public static function email($email)
{
return filter_var($ip, FILTER_VALIDATE_IP);
return( filter_var($email, FILTER_SANITIZE_EMAIL) );
}
public static function mail($mail)
public static function url($url)
{
return filter_var($mail, FILTER_VALIDATE_EMAIL);
return( filter_var($url, FILTER_SANITIZE_URL) );
}
public static function int($int)
{
if($int === 0)
return( true );
elseif (filter_var($int, FILTER_VALIDATE_INT) === false )
return( false );
else
return( true );
}
// Remove all characters except digits
public static function sanitize_float($value)
{
return( filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND) );
}
// Valid an integer positive
public static function sanitize_int($value)
public static function int($value)
{
$value = (int)$value;
@ -93,17 +75,4 @@ class Sanitize {
return 0;
}
public static function sanitize_email($value)
{
return( filter_var($value, FILTER_SANITIZE_EMAIL) );
}
public static function sanitize_url($value)
{
return( filter_var($value, FILTER_SANITIZE_URL) );
}
// Convert all applicable characters to HTML entities incluye acentos
}

View File

@ -0,0 +1,27 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
class Valid {
public static function ip($ip)
{
return filter_var($ip, FILTER_VALIDATE_IP);
}
public static function email($email)
{
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
public static function int($int)
{
if($int === 0) {
return true;
}
elseif(filter_var($int, FILTER_VALIDATE_INT) === false ) {
return false;
}
return true;
}
}