2016-05-04 00:57:45 +02:00
< ? php
/**
* This software is governed by the CeCILL - B license . If a copy of this license
* is not distributed with this file , you can obtain one at
* http :// www . cecill . info / licences / Licence_CeCILL - B_V1 - en . txt
*
* Authors of STUdS ( initial project ) : Guilhem BORGHESI ( borghesi @ unistra . fr ) and Raphaël DROZ
2016-08-04 21:51:37 +02:00
* Authors of Framadate / OpenSondage : Framasoft ( https :// github . com / framasoft )
2016-05-04 00:57:45 +02:00
*
* =============================
*
* Ce logiciel est régi par la licence CeCILL - B . Si une copie de cette licence
* ne se trouve pas avec ce fichier vous pouvez l ' obtenir sur
* http :// www . cecill . info / licences / Licence_CeCILL - B_V1 - fr . txt
*
* Auteurs de STUdS ( projet initial ) : Guilhem BORGHESI ( borghesi @ unistra . fr ) et Raphaël DROZ
* Auteurs de Framadate / OpenSondage : Framasoft ( https :// github . com / framasoft )
*/
use Framadate\Message ;
use Framadate\Utils ;
define ( 'ROOT_DIR' , __DIR__ . '/../' );
/**
* Checking for missing vendors .
*/
if ( ! file_exists ( ROOT_DIR . 'vendor/autoload.php' ) || ! file_exists ( ROOT_DIR . 'vendor/o80/i18n/src/shortcuts.php' )) {
die ( " ERROR: You should use <code>composer install</code> to fetch dependant libraries. " );
}
/**
* Stripped ini sequence
*/
require_once ROOT_DIR . 'vendor/autoload.php' ;
require_once ROOT_DIR . 'vendor/o80/i18n/src/shortcuts.php' ;
require_once ROOT_DIR . 'app/inc/constants.php' ;
2018-02-19 00:18:43 +01:00
if ( session_id () === '' ) {
2016-05-04 00:57:45 +02:00
session_start ();
}
$ALLOWED_LANGUAGES = [
'fr' => 'Français' ,
'en' => 'English' ,
'oc' => 'Occitan' ,
'es' => 'Español' ,
'de' => 'Deutsch' ,
'it' => 'Italiano' ,
2016-07-31 00:31:43 +02:00
'br' => 'Brezhoneg' ,
2016-05-04 00:57:45 +02:00
];
const DEFAULT_LANGUAGE = 'en' ;
require_once ROOT_DIR . 'app/inc/i18n.php' ;
/**
* Function to sort messages by type ( priorise errors on warning , warning on info , etc . )
*
* @ param Message $a
* @ param Message $b
* @ return int
*/
function compareCheckMessage ( Message $a , Message $b )
{
2018-02-19 00:18:43 +01:00
$values = [
2016-05-04 00:57:45 +02:00
'danger' => 0 ,
'warning' => 1 ,
'info' => 2 ,
'success' => 3
2018-02-19 00:18:43 +01:00
];
2016-05-04 00:57:45 +02:00
$vA = $values [ $a -> type ];
$vB = $values [ $b -> type ];
2018-02-19 00:18:43 +01:00
if ( $vA === $vB ) {
2016-05-04 00:57:45 +02:00
return 0 ;
}
return ( $vA < $vB ) ? - 1 : 1 ;
}
/**
* Vars
*/
2018-02-19 00:18:43 +01:00
$messages = [];
$inc_directory = ROOT_DIR . 'app/inc/' ;
2016-05-04 00:57:45 +02:00
$conf_filename = $inc_directory . 'config.php' ;
/**
* Messages
*/
// PHP Version
2018-02-21 11:17:55 +01:00
if ( version_compare ( PHP_VERSION , PHP_NEEDED_VERSION ) >= 0 ) {
2018-02-19 19:50:50 +01:00
$messages [] = new Message ( 'info' , __f ( 'Check' , 'PHP version %s is enough (needed at least PHP %s).' , PHP_MAJOR_VERSION . " . " . PHP_MINOR_VERSION , PHP_NEEDED_VERSION ));
2016-05-04 00:57:45 +02:00
} else {
2018-02-19 19:35:41 +01:00
$messages [] = new Message ( 'danger' , __f ( 'Check' , 'Your PHP version (%s) is too old. This application needs at least PHP %s.' , phpversion (), PHP_NEEDED_VERSION ));
2016-05-04 00:57:45 +02:00
}
// INTL extension
if ( extension_loaded ( 'intl' )) {
$messages [] = new Message ( 'info' , __ ( 'Check' , 'PHP Intl extension is enabled.' ));
} else {
$messages [] = new Message ( 'danger' , __ ( 'Check' , 'You need to enable the PHP Intl extension.' ));
}
2016-12-27 15:15:26 +01:00
// Is template compile dir exists and writable ?
if ( ! file_exists ( ROOT_DIR . COMPILE_DIR )) {
2016-12-27 18:11:52 +01:00
$messages [] = new Message ( 'danger' , __f ( 'Check' , 'The template compile directory (%s) doesn\'t exist in "%s". Retry the installation process.' , COMPILE_DIR , realpath ( ROOT_DIR )));
2016-12-27 15:15:26 +01:00
} elseif ( is_writable ( ROOT_DIR . COMPILE_DIR )) {
2016-05-04 00:57:45 +02:00
$messages [] = new Message ( 'info' , __f ( 'Check' , 'The template compile directory (%s) is writable.' , realpath ( ROOT_DIR . COMPILE_DIR )));
} else {
$messages [] = new Message ( 'danger' , __f ( 'Check' , 'The template compile directory (%s) is not writable.' , realpath ( ROOT_DIR . COMPILE_DIR )));
}
// Does config.php exists or is writable ?
if ( file_exists ( $conf_filename )) {
$messages [] = new Message ( 'info' , __ ( 'Check' , 'The config file exists.' ));
} elseif ( is_writable ( $inc_directory )) {
$messages [] = new Message ( 'info' , __ ( 'Check' , 'The config file directory (%s) is writable.' , $inc_directory ));
} else {
2018-01-04 22:53:12 +01:00
$messages [] = new Message ( 'danger' , __f ( 'Check' , 'The config file directory (%s) is not writable and the config file (%s) does not exists.' , $inc_directory , $conf_filename ));
2016-05-04 00:57:45 +02:00
}
// Security
if ( extension_loaded ( 'openssl' )) {
$messages [] = new Message ( 'info' , __ ( 'Check' , 'OpenSSL extension loaded.' ));
} else {
$messages [] = new Message ( 'warning' , __ ( 'Check' , 'Consider enabling the PHP extension OpenSSL for increased security.' ));
}
2018-02-20 17:44:08 +01:00
if ( ini_get ( 'session.cookie_httponly' ) === '1' ) {
$messages [] = new Message ( 'info' , __ ( 'Check' , 'Cookies are served from HTTP only.' ));
} else {
$messages [] = new Message ( 'warning' , __ ( 'Check' , " Consider setting « session.cookie_httponly = 1 » inside your php.ini or add « php_value session.cookie_httponly 1 » to your .htaccess so that cookies can't be accessed through Javascript. " ));
}
2016-05-04 00:57:45 +02:00
// Datetime
2016-07-07 12:29:16 +02:00
$timezone = ini_get ( 'date.timezone' );
if ( ! empty ( $timezone )) {
2016-05-04 00:57:45 +02:00
$messages [] = new Message ( 'info' , __ ( 'Check' , 'date.timezone is set.' ));
} else {
$messages [] = new Message ( 'warning' , __ ( 'Check' , 'Consider setting the date.timezone in php.ini.' ));
}
// The percentage of steps needed to be ready to launch the application
$errors = 0 ;
$warnings = 0 ;
foreach ( $messages as $message ) {
2018-02-19 00:18:43 +01:00
if ( $message -> type === 'danger' ) {
2016-05-04 00:57:45 +02:00
$errors ++ ;
2018-02-19 00:18:43 +01:00
} else if ( $message -> type === 'warning' ) {
2016-05-04 00:57:45 +02:00
$warnings ++ ;
2016-05-04 11:12:59 +02:00
}
2016-05-04 00:57:45 +02:00
}
$readyPercentage = round (( count ( $messages ) - $errors ) * 100 / count ( $messages ));
2016-05-04 11:12:59 +02:00
2016-05-04 00:57:45 +02:00
if ( $errors > 0 ) {
$readyClass = 'danger' ;
} else if ( $warnings > 0 ) {
$readyClass = 'warning' ;
2016-05-04 11:12:59 +02:00
} else {
$readyClass = 'success' ;
2016-05-04 00:57:45 +02:00
}
usort ( $messages , 'compareCheckMessage' );
?>
<! DOCTYPE html >
< html lang = " <?= $locale ?> " >
< head >
< meta charset = " utf-8 " >
2016-05-04 11:12:59 +02:00
< title >< ? = __ ( 'Check' , 'Installation checking' ) ?> </title>
2016-05-04 00:57:45 +02:00
< link rel = " stylesheet " href = " ../css/bootstrap.min.css " >
< link rel = " stylesheet " href = " ../css/style.css " >
< link rel = " stylesheet " href = " ../css/frama.css " >
</ head >
< body >
< div class = " container ombre " >
< div class = " row " >
< form method = " get " action = " " class = " hidden-print " >
< div class = " input-group input-group-sm pull-right col-xs-12 col-sm-2 " >
2018-07-06 18:06:35 +02:00
< select name = " lang " class = " form-control " title = " <?=__('Language selector', 'Select language')?> " >
2016-05-04 00:57:45 +02:00
< ? php foreach ( $ALLOWED_LANGUAGES as $lang_key => $language ) { ?>
2018-02-19 00:18:43 +01:00
< option lang = " fr " < ? php if ( substr ( $lang_key , 0 , 2 ) === $locale ) { echo 'selected' ;} ?> value="<?=substr($lang_key, 0, 2)?>"><?=$language?></option>
2016-05-04 00:57:45 +02:00
< ? php } ?>
</ select >
2018-07-06 18:06:35 +02:00
< span class = " input-group-btn " >
< button type = " submit " class = " btn btn-default btn-sm " title = " <?=__('Language selector', 'Select language')?> " > OK </ button >
</ span >
2016-05-04 00:57:45 +02:00
</ div >
</ form >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
< h1 >< ? = __ ( 'Check' , 'Installation checking' ) ?> </h1>
< div >
< div class = " progress " >
< div class = " progress-bar progress-bar-<?= $readyClass ?> " role = " progressbar " aria - valuenow = " <?= $readyPercentage ?> " aria - valuemin = " 0 " aria - valuemax = " 100 " style = " width: <?= $readyPercentage ?>%; " >
< ? = $readyPercentage ?> %
</ div >
</ div >
</ div >
< div >
< ? php
foreach ( $messages as $message ) {
2018-02-19 00:18:43 +01:00
echo '<div class="alert alert-' . $message -> type . '" role="alert">' ;
2016-05-04 00:57:45 +02:00
echo Utils :: htmlEscape ( $message -> message );
2018-02-19 00:18:43 +01:00
echo '<span class="sr-only">' . $message -> type . '</span>' ;
2016-05-04 00:57:45 +02:00
echo '</div>' ;
}
?>
</ div >
</ div >
< div class = " text-center " >
< a class = " btn btn-info " role = " button " href = " " >< span class = " glyphicon glyphicon-refresh " aria - hidden = " true " ></ span > < ? = __ ( 'Check' , 'Check again' ) ?> </a>
< ? php
if ( ! is_file ( $conf_filename )) {
2018-02-19 00:18:43 +01:00
if ( $errors === 0 ) {
2016-05-04 00:57:45 +02:00
?>
< a class = " btn btn-primary " role = " button " href = " <?= Utils::get_server_name() . 'admin/install.php' ?> " >< span class = " glyphicon glyphicon-arrow-right " aria - hidden = " true " ></ span > < ? = __ ( 'Check' , 'Continue the installation' ) ?> </a>
< ? php
}
} else {
?>
< a class = " btn btn-primary " role = " button " href = " <?= Utils::get_server_name() . 'admin/'?> " >< span class = " glyphicon glyphicon-arrow-left " aria - hidden = " true " ></ span > < ? = __ ( 'Admin' , 'Back to administration' ) ?> </a>
< ? php
}
?>
</ div >
</ div >
</ div >
2016-07-31 00:31:43 +02:00
</ body >