diff --git a/admin/themes/default/css/installer.css b/admin/themes/default/css/installer.css index 60ad067e..988fe753 100644 --- a/admin/themes/default/css/installer.css +++ b/admin/themes/default/css/installer.css @@ -25,4 +25,21 @@ 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; } \ No newline at end of file diff --git a/content/README b/content/README deleted file mode 100644 index d68ab992..00000000 --- a/content/README +++ /dev/null @@ -1,2 +0,0 @@ -Set the correct permissions on this directory. -Check the documentation: http://docs.bludit.com/en/troubleshooting/writing-test-failure-err205 diff --git a/index.php b/index.php index add85269..365c449e 100644 --- a/index.php +++ b/index.php @@ -14,7 +14,7 @@ if( !file_exists('content/databases/site.php') ) exit('First, install Bludit'); } -// DEBUG: +// Load time init $loadTime = microtime(true); // Security constant @@ -24,7 +24,7 @@ define('BLUDIT', true); define('DS', DIRECTORY_SEPARATOR); // PHP paths -define('PATH_ROOT', __DIR__.DS); +define('PATH_ROOT', __DIR__.DS); define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS); // Init @@ -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()); diff --git a/install.php b/install.php index 4ff02f7c..1428236f 100644 --- a/install.php +++ b/install.php @@ -14,218 +14,246 @@ define('BLUDIT', true); define('DS', DIRECTORY_SEPARATOR); // PATHs -define('PATH_ROOT', __DIR__.DS); -define('PATH_CONTENT', PATH_ROOT.'content'.DS); -define('PATH_POSTS', PATH_CONTENT.'posts'.DS); -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('DOMAIN', getenv('HTTP_HOST')); +define('PATH_ROOT', __DIR__.DS); +define('PATH_CONTENT', PATH_ROOT.'content'.DS); +define('PATH_POSTS', PATH_CONTENT.'posts'.DS); +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(); + $stdOut = array(); + $dirpermissions = 0755; + $phpModules = array(); - if(function_exists('get_loaded_extensions')) - { - $phpModules = get_loaded_extensions(); - } + if(function_exists('get_loaded_extensions')) { + $phpModules = get_loaded_extensions(); + } - if(!version_compare(phpversion(), '5.3', '>=')) - { - $errorText = 'Current PHP version '.phpversion().', you need > 5.3. (ERR_202)'; - error_log($errorText, 0); - array_push($stdOut, $errorText); + if(!version_compare(phpversion(), '5.3', '>=')) + { + $errorText = 'Current PHP version '.phpversion().', you need > 5.3. (ERR_202)'; + error_log($errorText, 0); + array_push($stdOut, $errorText); - return $stdOut; - } + return $stdOut; + } - if(!file_exists(PATH_ROOT.'.htaccess')) - { - $errorText = 'Missing file, upload the file .htaccess (ERR_201)'; - error_log($errorText, 0); - array_push($stdOut, $errorText); - } + if(!file_exists(PATH_ROOT.'.htaccess')) + { + $errorText = 'Missing file, upload the file .htaccess (ERR_201)'; + error_log($errorText, 0); + array_push($stdOut, $errorText); + } - if(!in_array('dom', $phpModules)) - { - $errorText = 'PHP module DOM does not exist. (ERR_203)'; - error_log($errorText, 0); - array_push($stdOut, $errorText); - } + if(!in_array('dom', $phpModules)) + { + $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)'; - error_log($errorText, 0); - array_push($stdOut, $errorText); - } + if(!in_array('json', $phpModules)) + { + $errorText = 'PHP module JSON is not installed. (ERR_204)'; + error_log($errorText, 0); + array_push($stdOut, $errorText); + } - if(!is_writable(PATH_CONTENT)) - { - $errorText = 'Writing test failure, check directory content permissions. (ERR_205)'; - error_log($errorText, 0); - array_push($stdOut, $errorText); - } + if(!is_writable(PATH_CONTENT)) + { + $errorText = 'Writing test failure, check directory content permissions. (ERR_205)'; + error_log($errorText, 0); + array_push($stdOut, $errorText); + } - return $stdOut; + return $stdOut; } -function install($adminPassword, $email) +function install($adminPassword, $email, $language) { - $stdOut = array(); + $stdOut = array(); - // ============================================================================ - // Create directories - // ============================================================================ + // ============================================================================ + // Create directories + // ============================================================================ - // 7=read,write,execute | 5=read,execute - $dirpermissions = 0755; - $firstPostSlug = 'first-post'; + // 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_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_PAGES.'error', $dirpermissions, true)) + { + $errorText = 'Error when trying to created the directory=>'.PATH_PAGES.'error'; + error_log($errorText, 0); + } - if(!mkdir(PATH_PLUGINS_DATABASES.'pages', $dirpermissions, true)) - { - $errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES; - error_log($errorText, 0); - } + if(!mkdir(PATH_PLUGINS_DATABASES.'pages', $dirpermissions, true)) + { + $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); - } + if(!mkdir(PATH_UPLOADS, $dirpermissions, true)) + { + $errorText = 'Error when trying to created the directory=>'.PATH_UPLOADS; + error_log($errorText, 0); + } - // ============================================================================ - // Create files - // ============================================================================ + // ============================================================================ + // Create files + // ============================================================================ - $dataHead = "".PHP_EOL; + $dataHead = "".PHP_EOL; - // File pages.php - $data = array( - 'error'=>array( - 'description'=>'Error page', - 'username'=>'admin', - 'tags'=>'', - 'status'=>'published', - 'unixTimeCreated'=>1430686755, - 'unixTimeModified'=>0, - 'position'=>0 - ) - ); + // 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_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 - ) - ); - file_put_contents(PATH_DATABASES.'posts.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 + ) + ); + file_put_contents(PATH_DATABASES.'posts.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); - // File site.php - $data = array( - 'title'=>'Bludit', - 'slogan'=>'cms', - 'description'=>'', - 'footer'=>'Footer text - ©2015', - 'language'=>'english', - 'locale'=>'en_US', - 'timezone'=>'UTC', - 'theme'=>'pure', - 'adminTheme'=>'default', - 'homepage'=>'', - 'postsperpage'=>'6', - 'uriPost'=>'/post/', - 'uriPage'=>'/', - 'uriTag'=>'/tag/', - 'advancedOptions'=>'false', - 'url'=>'http://'.DOMAIN.HTML_PATH_ROOT - ); + // File site.php + $data = array( + 'title'=>'Bludit', + 'slogan'=>'cms', + 'description'=>'', + 'footer'=>'Footer text - ©2015', + 'language'=>$language, + 'locale'=>$language, + '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); + file_put_contents(PATH_DATABASES.'site.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); - $salt = getRandomString(); - $passwordHash = sha1($adminPassword.$salt); - $registered = time(); + $salt = getRandomString(); + $passwordHash = sha1($adminPassword.$salt); + $registered = time(); - // File users.php - $data = array( - 'admin'=>array( - 'firstName'=>'', - 'lastName'=>'', - 'twitter'=>'', - 'role'=>'admin', - 'password'=>$passwordHash, - 'salt'=>$salt, - 'email'=>$email, - 'registered'=>$registered - ) - ); + // File users.php + $data = array( + 'admin'=>array( + 'firstName'=>'', + 'lastName'=>'', + 'twitter'=>'', + 'role'=>'admin', + 'password'=>$passwordHash, + 'salt'=>$salt, + 'email'=>$email, + 'registered'=>$registered + ) + ); - file_put_contents(PATH_DATABASES.'users.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); + file_put_contents(PATH_DATABASES.'users.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); - // File plugins/pages/db.php - $data = array( - 'homeLink'=>true, - 'label'=>'Pages' - ); + // File plugins/pages/db.php + $data = array( + 'homeLink'=>true, + 'label'=>'Pages' + ); - file_put_contents(PATH_PLUGINS_DATABASES.'pages'.DS.'db.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); + file_put_contents(PATH_PLUGINS_DATABASES.'pages'.DS.'db.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 index.txt for error page + $data = 'Title: Error + Content: The page has not been found.'; - file_put_contents(PATH_PAGES.'error'.DS.'index.txt', $data, LOCK_EX); + file_put_contents(PATH_PAGES.'error'.DS.'index.txt', $data, LOCK_EX); -// File index.txt for welcome post -$data = 'title: First post + // File index.txt for welcome post + $data = 'Title: First post Content: Congratulations, you have installed **Bludit** successfully! @@ -239,32 +267,58 @@ What\'s next: - Read the [documentation](http://docs.bludit.com) for more information - Share with your friend :D'; - file_put_contents(PATH_POSTS.$firstPostSlug.DS.'index.txt', $data, LOCK_EX); + file_put_contents(PATH_POSTS.$firstPostSlug.DS.'index.txt', $data, LOCK_EX); - return true; + return true; +} + +function checkPOST($_POST) +{ + // Check empty password + if(empty($_POST['password'])) + { + return '
The password field is empty
'; + } + + // Check invalid email + if(!Valid::email($_POST['email'])) + { + return '
Your email address is invalid.
Proceed anyway!
'; + } + + // Sanitize email + $email = sanitize::email($_POST['email']); + + // Install Bludit + install($_POST['password'], $email, $_POST['language']); + + return true; } // ============================================================================ // MAIN // ============================================================================ -if( alreadyInstalled() ) -{ - exit('Bludit already installed'); +$error = ''; + +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; - } + $error = checkPOST($_POST); - exit(''); - } + if($error===true) + { + if(!headers_sent()) + { + header("Location:".HTML_PATH_ROOT, TRUE, 302); + exit; + } + + exit(''); + } } ?> @@ -272,73 +326,104 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) - - - + + + - Bludit Installer + Bludit Installer - - + + - - + +
-
-
-

Bludit Installer

-

Welcome to the Bludit installer

+
+
+

Bludit Installer

+

Welcome to the Bludit installer

- + if(empty($system)) + { + ?> -

Complete the form, choose a password for the username admin

-
-
+

Complete the form, choose a password for the username admin

- +
- + '.$error.'
'; + } + ?> - + -

- -

-
-
+ - '; - echo ''; + - foreach ($system as $value) - { - echo ''; - } + - echo '
'.$value.'
'; - echo ' + + +

+ +

+ +
+ + '; + echo ''; + + foreach ($system as $value) + { + echo ''; + } + + echo '
'.$value.'
'; + echo ' +
+
+ + -
-
\ No newline at end of file diff --git a/kernel/boot/init.php b/kernel/boot/init.php index 2f083113..08f30f4b 100644 --- a/kernel/boot/init.php +++ b/kernel/boot/init.php @@ -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'); diff --git a/kernel/helpers/sanitize.class.php b/kernel/helpers/sanitize.class.php index 47c17938..fa39496f 100644 --- a/kernel/helpers/sanitize.class.php +++ b/kernel/helpers/sanitize.class.php @@ -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 - - -} +} \ No newline at end of file diff --git a/kernel/helpers/valid.class.php b/kernel/helpers/valid.class.php new file mode 100644 index 00000000..507c172f --- /dev/null +++ b/kernel/helpers/valid.class.php @@ -0,0 +1,27 @@ +