Check.php

This commit is contained in:
Antonin 2016-05-04 00:57:45 +02:00
parent ab0748597a
commit f046cbdf95
10 changed files with 369 additions and 5 deletions

221
admin/check.php Normal file
View File

@ -0,0 +1,221 @@
<?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
* Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft)
*
* =============================
*
* 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';
if (session_id() == '') {
session_start();
}
$ALLOWED_LANGUAGES = [
'fr' => 'Français',
'en' => 'English',
'oc' => 'Occitan',
'es' => 'Español',
'de' => 'Deutsch',
'it' => 'Italiano',
];
const DEFAULT_LANGUAGE = 'en';
require_once ROOT_DIR . 'app/inc/i18n.php';
require_once '../app/inc/php_version.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)
{
$values = array(
'danger' => 0,
'warning' => 1,
'info' => 2,
'success' => 3
);
$vA = $values[$a->type];
$vB = $values[$b->type];
if ($vA == $vB) {
return 0;
}
return ($vA < $vB) ? -1 : 1;
}
/**
* Vars
*/
$messages = array();
$inc_directory = ROOT_DIR. 'app/inc/';
$conf_filename = $inc_directory . 'config.php';
/**
* Messages
*/
// PHP Version
if (PHP_VERSION_ID >= php_string_to_version_id(PHP_NEEDED_VERSION)) {
$messages[] = new Message('info', __f('Check','PHP version %s is enough (needed at least PHP %s).',phpversion(), PHP_NEEDED_VERSION));
} else {
$messages[] = new Message('danger', __f('Check','Your PHP version (%s) is too old. This application needs at least PHP %s.',phpversion(), PHP_NEEDED_VERSION));
}
// 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.'));
}
// Is template compile dir writable ?
if (is_writable(ROOT_DIR . COMPILE_DIR)) {
$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 {
$messages[] = new Message('danger', __f('Check','The config file directory (%s) is not writable and the config file (%s) dos not exists.', $inc_directory, $conf_filename));
}
// 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.'));
}
// Datetime
if (!empty(ini_get('date.timezone'))) {
$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) {
if ($message->type == 'danger') {
$errors++;
} else if ($message->type == 'warning')
$warnings++;
}
$readyPercentage = round((count($messages)-$errors)*100/count($messages));
$readyClass = 'success';
if ($errors > 0) {
$readyClass = 'danger';
} else if ($warnings > 0) {
$readyClass = 'warning';
}
usort($messages, 'compareCheckMessage');
?>
<!DOCTYPE html>
<html lang="<?=$locale?>">
<head>
<meta charset="utf-8">
<title><?=__('Check', 'Installation checking') ?></title>
<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">
<select name="lang" class="form-control" title="<?=__('Language selector', 'Select the language')?>" >
<?php foreach ($ALLOWED_LANGUAGES as $lang_key => $language) { ?>
<option lang="fr" <?php if (substr($lang_key, 0, 2)==$locale) { echo 'selected';} ?> value="<?=substr($lang_key, 0, 2)?>"><?=$language?></option>
<?php } ?>
</select>
<span class="input-group-btn">
<button type="submit" class="btn btn-default btn-sm" title="<?=__('Language selector', 'Select the language')?>">OK</button>
</span>
</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) {
echo '<div class="alert alert-'. $message->type .'" role="alert">';
echo Utils::htmlEscape($message->message);
echo '<span class="sr-only">'. $message->type .'</span>';
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)) {
if ($errors == 0) {
?>
<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>
</body>

View File

@ -20,6 +20,12 @@
// FRAMADATE version
const VERSION = '1.0';
// PHP Needed version
const PHP_NEEDED_VERSION = '5.4.4';
// Config constants
const COMPILE_DIR = '/tpl_c/';
// Regex
const POLL_REGEX = '/^[a-z0-9-]*$/i';
const ADMIN_POLL_REGEX = '/^[a-z0-9]{24}$/i';

29
app/inc/php_version.php Normal file
View File

@ -0,0 +1,29 @@
<?php
function php_version_id_to_string($versionId) {
$major = substr($versionId, 0, 2);
$minor = substr($versionId, 2, 2);
$release = substr($versionId, 4, 2);
return $major.'.'.$minor.'.'.$release;
}
function php_version_to_version_id($major, $minor, $release) {
return ($major * 10000 +$minor * 100 + $release);
}
function php_string_to_version_id($version) {
$version = explode('.', $version);
return php_version_to_version_id($version[0], $version[1], $version[2]);
}
if (!defined('PHP_VERSION_ID')) {
$version = explode('.',PHP_VERSION);
define('PHP_VERSION_ID', php_version_to_version_id($version[0], $version[1], $version[2]));
}
if (PHP_VERSION_ID < 50207) { // This constants do not exists before 5.2.7
define('PHP_MAJOR_VERSION', $version[0]);
define('PHP_MINOR_VERSION', $version[1]);
define('PHP_RELEASE_VERSION', $version[2]);
}
?>

View File

@ -21,7 +21,7 @@ use Framadate\Utils;
require_once __DIR__ . '/../../vendor/smarty/smarty/libs/Smarty.class.php';
$smarty = new \Smarty();
$smarty->setTemplateDir(ROOT_DIR . '/tpl/');
$smarty->setCompileDir(ROOT_DIR . '/tpl_c/');
$smarty->setCompileDir(ROOT_DIR . COMPILE_DIR);
$smarty->setCacheDir(ROOT_DIR . '/cache/');
$smarty->caching = false;

View File

@ -384,5 +384,23 @@
"Passwords do not match": "DE_Les mot de passes ne correspondent pas.",
"Poll id already used": "DE_L'identifiant est déjà utilisé",
"You can't select more than %d dates": "DE_Vous ne pouvez pas choisir plus de %d dates"
},
"Check": {
"Installation checking": "DE_Vérifications de l'installation",
"Your PHP version (%s) is too old. This application needs at least PHP %s.": "DE_Votre version de PHP (%s) est trop vieille. Cette application a besoin de PHP %s au moins.",
"PHP version %s is enough (needed at least PHP %s).": "DE_Version de PHP %s suffisante (nécessite au moins PHP %s).",
"You need to enable the PHP Intl extension.": "DE_Vous devez activer l'extension PHP Intl.",
"PHP Intl extension is enabled.": "DE_L'extension PHP Intl est activée.",
"The template compile directory (%s) is not writable.": "DE_Le dossier de compilation des templates (%s) n'est pas accessible en écriture.",
"The template compile directory (%s) is writable.": "DE_Le dossier de compilation des templates (%s) est accessible en écriture.",
"The config file directory (%s) is not writable and the config file (%s) dos not exists.": "DE_Le dossier du fichier de configuration (%s) n'est pas accessible en écriture et le fichier de configuration (%s) n'éxiste pas.",
"The config file exists.": "DE_Le fichier de configuration existe.",
"The config file directory (%s) is writable.": "DE_Le dossier du fichier de configuration (%s) est accessible en écriture.",
"OpenSSL extension loaded.": "DE_L'extension PHP OpenSSL est chargée.",
"Consider enabling the PHP extension OpenSSL for increased security.": "DE_Veuillez considérer l'activation de l'extension PHP OpenSSL pour améliorer la sécurité.",
"date.timezone is set.": "DE_date.timezone est défini.",
"Consider setting the date.timezone in php.ini.": "DE_Veuillez considérer la définition de date.timezone dans le php.ini.",
"Check again": "DE_Vérifier à nouveau",
"Continue the installation": "DE_Continuer l'installation"
}
}

View File

@ -385,5 +385,23 @@
"Passwords do not match": "Passwords do not match.",
"Poll id already used": "Identifier is already used",
"You can't select more than %d dates": "You can't select more than %d dates"
}
},
"Check": {
"Installation checking": "Installation checking",
"Your PHP version (%s) is too old. This application needs at least PHP %s.": "Your PHP version (%s) is too old. This application needs at least PHP %s.",
"PHP version %s is enough (needed at least PHP %s).": "PHP version %s is enough (needed at least PHP %s).",
"You need to enable the PHP Intl extension.": "You need to enable the PHP Intl extension.",
"PHP Intl extension is enabled.": "PHP Intl extension is enabled.",
"The template compile directory (%s) is not writable.": "The template compile directory (%s) is not writable.",
"The template compile directory (%s) is writable.": "The template compile directory (%s) is writable.",
"The config file directory (%s) is not writable and the config file (%s) dos not exists.": "The config file directory (%s) is not writable and the config file (%s) dos not exists.",
"The config file exists.": "The config file exists.",
"The config file directory (%s) is writable.": "The config file directory (%s) is writable.",
"OpenSSL extension loaded.": "OpenSSL extension loaded.",
"Consider enabling the PHP extension OpenSSL for increased security.": "Consider enabling the PHP extension OpenSSL for increased security.",
"date.timezone is set.": "date.timezone is set.",
"Consider setting the date.timezone in php.ini.": "Consider setting the date.timezone in php.ini.",
"Check again": "Check again",
"Continue the installation": "Continue the installation"
}
}

View File

@ -384,5 +384,23 @@
"Passwords do not match": "ES_Les mot de passes ne correspondent pas.",
"Poll id already used": "ES_L'identifiant est déjà utilisé",
"You can't select more than %d dates": "ES_Vous ne pouvez pas choisir plus de %d dates"
}
},
"Check": {
"Installation checking": "ES_Vérifications de l'installation",
"Your PHP version (%s) is too old. This application needs at least PHP %s.": "ES_Votre version de PHP (%s) est trop vieille. Cette application a besoin de PHP %s au moins.",
"PHP version %s is enough (needed at least PHP %s).": "ES_Version de PHP %s suffisante (nécessite au moins PHP %s).",
"You need to enable the PHP Intl extension.": "ES_Vous devez activer l'extension PHP Intl.",
"PHP Intl extension is enabled.": "ES_L'extension PHP Intl est activée.",
"The template compile directory (%s) is not writable.": "ES_Le dossier de compilation des templates (%s) n'est pas accessible en écriture.",
"The template compile directory (%s) is writable.": "ES_Le dossier de compilation des templates (%s) est accessible en écriture.",
"The config file directory (%s) is not writable and the config file (%s) dos not exists.": "ES_Le dossier du fichier de configuration (%s) n'est pas accessible en écriture et le fichier de configuration (%s) n'éxiste pas.",
"The config file exists.": "ES_Le fichier de configuration existe.",
"The config file directory (%s) is writable.": "ES_Le dossier du fichier de configuration (%s) est accessible en écriture.",
"OpenSSL extension loaded.": "ES_L'extension PHP OpenSSL est chargée.",
"Consider enabling the PHP extension OpenSSL for increased security.": "ES_Veuillez considérer l'activation de l'extension PHP OpenSSL pour améliorer la sécurité.",
"date.timezone is set.": "ES_date.timezone est défini.",
"Consider setting the date.timezone in php.ini.": "ES_Veuillez considérer la définition de date.timezone dans le php.ini.",
"Check again": "ES_Vérifier à nouveau",
"Continue the installation": "ES_Continuer l'installation"
}
}

View File

@ -398,5 +398,23 @@
"Passwords do not match": "Les mots de passe ne correspondent pas.",
"Poll id already used": "L'identifiant est déjà utilisé",
"You can't select more than %d dates": "Vous ne pouvez pas choisir plus de %d dates"
},
"Check": {
"Installation checking": "Vérifications de l'installation",
"Your PHP version (%s) is too old. This application needs at least PHP %s.": "Votre version de PHP (%s) est trop vieille. Cette application a besoin de PHP %s au moins.",
"PHP version %s is enough (needed at least PHP %s).": "Version de PHP %s suffisante (nécessite au moins PHP %s).",
"You need to enable the PHP Intl extension.": "Vous devez activer l'extension PHP Intl.",
"PHP Intl extension is enabled.": "L'extension PHP Intl est activée.",
"The template compile directory (%s) is not writable.": "Le dossier de compilation des templates (%s) n'est pas accessible en écriture.",
"The template compile directory (%s) is writable.": "Le dossier de compilation des templates (%s) est accessible en écriture.",
"The config file directory (%s) is not writable and the config file (%s) dos not exists.": "Le dossier du fichier de configuration (%s) n'est pas accessible en écriture et le fichier de configuration (%s) n'éxiste pas.",
"The config file exists.": "Le fichier de configuration existe.",
"The config file directory (%s) is writable.": "Le dossier du fichier de configuration (%s) est accessible en écriture.",
"OpenSSL extension loaded.": "L'extension PHP OpenSSL est chargée.",
"Consider enabling the PHP extension OpenSSL for increased security.": "Veuillez considérer l'activation de l'extension PHP OpenSSL pour améliorer la sécurité.",
"date.timezone is set.": "date.timezone est défini.",
"Consider setting the date.timezone in php.ini.": "Veuillez considérer la définition de date.timezone dans le php.ini.",
"Check again": "Vérifier à nouveau",
"Continue the installation": "Continuer l'installation"
}
}

View File

@ -382,5 +382,23 @@
"CANT_CONNECT_TO_DATABASE": "Impossibile connettersi al database",
"Poll id already used": "IT_L'identifiant est déjà utilisé",
"You can't select more than %d dates": "IT_Vous ne pouvez pas choisir plus de %d dates"
}
},
"Check": {
"Installation checking": "IT_Vérifications de l'installation",
"Your PHP version (%s) is too old. This application needs at least PHP %s.": "IT_Votre version de PHP (%s) est trop vieille. Cette application a besoin de PHP %s au moins.",
"PHP version %s is enough (needed at least PHP %s).": "IT_Version de PHP %s suffisante (nécessite au moins PHP %s).",
"You need to enable the PHP Intl extension.": "IT_Vous devez activer l'extension PHP Intl.",
"PHP Intl extension is enabled.": "IT_L'extension PHP Intl est activée.",
"The template compile directory (%s) is not writable.": "IT_Le dossier de compilation des templates (%s) n'est pas accessible en écriture.",
"The template compile directory (%s) is writable.": "IT_Le dossier de compilation des templates (%s) est accessible en écriture.",
"The config file directory (%s) is not writable and the config file (%s) dos not exists.": "IT_Le dossier du fichier de configuration (%s) n'est pas accessible en écriture et le fichier de configuration (%s) n'éxiste pas.",
"The config file exists.": "IT_Le fichier de configuration existe.",
"The config file directory (%s) is writable.": "IT_Le dossier du fichier de configuration (%s) est accessible en écriture.",
"OpenSSL extension loaded.": "IT_L'extension PHP OpenSSL est chargée.",
"Consider enabling the PHP extension OpenSSL for increased security.": "IT_Veuillez considérer l'activation de l'extension PHP OpenSSL pour améliorer la sécurité.",
"date.timezone is set.": "IT_date.timezone est défini.",
"Consider setting the date.timezone in php.ini.": "IT_Veuillez considérer la définition de date.timezone dans le php.ini.",
"Check again": "IT_Vérifier à nouveau",
"Continue the installation": "IT_Continuer l'installation"
}
}

View File

@ -380,5 +380,23 @@
"MISSING_VALUES": "Mancan de valors",
"CANT_CONNECT_TO_DATABASE": "Impossible de se connectar a la banca de donadas",
"You can't select more than %d dates": "OC_Vous ne pouvez pas choisir plus de %d dates"
}
},
"Check": {
"Installation checking": "OC_Vérifications de l'installation",
"Your PHP version (%s) is too old. This application needs at least PHP %s.": "OC_Votre version de PHP (%s) est trop vieille. Cette application a besoin de PHP %s au moins.",
"PHP version %s is enough (needed at least PHP %s).": "OC_Version de PHP %s suffisante (nécessite au moins PHP %s).",
"You need to enable the PHP Intl extension.": "OC_Vous devez activer l'extension PHP Intl.",
"PHP Intl extension is enabled.": "OC_L'extension PHP Intl est activée.",
"The template compile directory (%s) is not writable.": "OC_Le dossier de compilation des templates (%s) n'est pas accessible en écriture.",
"The template compile directory (%s) is writable.": "OC_Le dossier de compilation des templates (%s) est accessible en écriture.",
"The config file directory (%s) is not writable and the config file (%s) dos not exists.": "OC_Le dossier du fichier de configuration (%s) n'est pas accessible en écriture et le fichier de configuration (%s) n'éxiste pas.",
"The config file exists.": "OC_Le fichier de configuration existe.",
"The config file directory (%s) is writable.": "OC_Le dossier du fichier de configuration (%s) est accessible en écriture.",
"OpenSSL extension loaded.": "OC_L'extension PHP OpenSSL est chargée.",
"Consider enabling the PHP extension OpenSSL for increased security.": "OC_Veuillez considérer l'activation de l'extension PHP OpenSSL pour améliorer la sécurité.",
"date.timezone is set.": "OC_date.timezone est défini.",
"Consider setting the date.timezone in php.ini.": "OC_Veuillez considérer la définition de date.timezone dans le php.ini.",
"Check again": "OC_Vérifier à nouveau",
"Continue the installation": "OC_Continuer l'installation"
}
}