2018-04-02 08:29:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is part of Zwii.
|
|
|
|
* For full copyright and license information, please see the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* @author Rémi Jean <remi.jean@outlook.com>
|
|
|
|
* @copyright Copyright (C) 2008-2018, Rémi Jean
|
2021-02-17 13:49:58 +01:00
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
2021-12-18 10:25:33 +01:00
|
|
|
* @copyright Copyright (C) 2018-2022, Frédéric Tempez
|
2018-04-02 08:29:19 +02:00
|
|
|
* @license GNU General Public License, version 3
|
2020-09-01 20:48:40 +02:00
|
|
|
* @link http://zwiicms.fr/
|
2018-04-02 08:29:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
class install extends common {
|
|
|
|
|
|
|
|
public static $actions = [
|
|
|
|
'index' => self::GROUP_VISITOR,
|
|
|
|
'steps' => self::GROUP_ADMIN,
|
2020-10-25 22:49:28 +01:00
|
|
|
'update' => self::GROUP_ADMIN
|
2018-04-02 08:29:19 +02:00
|
|
|
];
|
|
|
|
|
2021-10-19 19:14:52 +02:00
|
|
|
// Thèmes proposés à l'installation
|
|
|
|
public static $themes = [];
|
2019-05-02 13:21:48 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
public static $newVersion;
|
|
|
|
|
2019-05-02 13:21:48 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Installation
|
|
|
|
*/
|
|
|
|
public function index() {
|
|
|
|
// Accès refusé
|
|
|
|
if($this->getData(['user']) !== []) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-06-02 18:49:24 +02:00
|
|
|
'access' => false
|
2018-04-02 08:29:19 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Accès autorisé
|
|
|
|
else {
|
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
2020-09-09 17:21:02 +02:00
|
|
|
$success = true;
|
2018-04-02 08:29:19 +02:00
|
|
|
// Double vérification pour le mot de passe
|
|
|
|
if($this->getInput('installPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('installConfirmPassword', helper::FILTER_STRING_SHORT, true)) {
|
|
|
|
self::$inputNotices['installConfirmPassword'] = 'Incorrect';
|
2020-09-09 17:21:02 +02:00
|
|
|
$success = false;
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2020-09-09 17:21:02 +02:00
|
|
|
// Utilisateur
|
2018-04-02 08:29:19 +02:00
|
|
|
$userFirstname = $this->getInput('installFirstname', helper::FILTER_STRING_SHORT, true);
|
|
|
|
$userLastname = $this->getInput('installLastname', helper::FILTER_STRING_SHORT, true);
|
|
|
|
$userMail = $this->getInput('installMail', helper::FILTER_MAIL, true);
|
|
|
|
$userId = $this->getInput('installId', helper::FILTER_ID, true);
|
2022-02-26 14:46:43 +01:00
|
|
|
|
2021-10-19 19:14:52 +02:00
|
|
|
|
2020-09-08 21:25:42 +02:00
|
|
|
// Création de l'utilisateur si les données sont complétées.
|
2020-09-24 10:23:57 +02:00
|
|
|
// success retour de l'enregistrement des données
|
2022-02-26 14:46:43 +01:00
|
|
|
|
2020-09-24 10:23:57 +02:00
|
|
|
$success = $this->setData([
|
|
|
|
'user',
|
|
|
|
$userId,
|
|
|
|
[
|
|
|
|
'firstname' => $userFirstname,
|
|
|
|
'forgot' => 0,
|
|
|
|
'group' => self::GROUP_ADMIN,
|
|
|
|
'lastname' => $userLastname,
|
2020-10-31 17:55:54 +01:00
|
|
|
'pseudo' => 'Admin',
|
|
|
|
'signature' => 1,
|
2020-09-24 10:23:57 +02:00
|
|
|
'mail' => $userMail,
|
|
|
|
'password' => $this->getInput('installPassword', helper::FILTER_PASSWORD, true)
|
|
|
|
]
|
|
|
|
]);
|
2022-02-26 14:46:43 +01:00
|
|
|
|
2020-09-09 17:21:02 +02:00
|
|
|
// Compte créé, envoi du mail et création des données du site
|
|
|
|
if ($success) { // Formulaire complété envoi du mail
|
2020-09-24 10:23:57 +02:00
|
|
|
// Envoie le mail
|
|
|
|
// Sent contient true si réussite sinon code erreur d'envoi en clair
|
|
|
|
$sent = $this->sendMail(
|
|
|
|
$userMail,
|
|
|
|
'Installation de votre site',
|
|
|
|
'Bonjour' . ' <strong>' . $userFirstname . ' ' . $userLastname . '</strong>,<br><br>' .
|
|
|
|
'Voici les détails de votre installation.<br><br>' .
|
|
|
|
'<strong>URL du site :</strong> <a href="' . helper::baseUrl(false) . '" target="_blank">' . helper::baseUrl(false) . '</a><br>' .
|
|
|
|
'<strong>Identifiant du compte :</strong> ' . $this->getInput('installId') . '<br>',
|
|
|
|
null
|
|
|
|
);
|
2021-06-05 08:17:57 +02:00
|
|
|
// Nettoyer les cookies de langue d'une précédente installation
|
|
|
|
helper::deleteCookie('ZWII_I18N_SITE');
|
|
|
|
helper::deleteCookie('ZWII_I18N_SCRIPT');
|
2021-06-01 09:19:48 +02:00
|
|
|
// Installation du site de test
|
2020-09-24 10:23:57 +02:00
|
|
|
if ($this->getInput('installDefaultData',helper::FILTER_BOOLEAN) === FALSE) {
|
|
|
|
$this->initData('page','fr',true);
|
|
|
|
$this->initData('module','fr',true);
|
2020-11-18 21:45:36 +01:00
|
|
|
$this->setData(['module', 'blog', 'posts', 'mon-premier-article', 'userId', $userId]);
|
|
|
|
$this->setData(['module', 'blog', 'posts', 'mon-deuxieme-article', 'userId', $userId]);
|
|
|
|
$this->setData(['module', 'blog', 'posts', 'mon-troisieme-article', 'userId', $userId]);
|
2022-02-26 14:46:43 +01:00
|
|
|
}
|
2021-06-01 09:19:48 +02:00
|
|
|
// Images exemples livrées dans tous les cas
|
|
|
|
try {
|
|
|
|
// Décompression dans le dossier de fichier temporaires
|
|
|
|
if (file_exists(self::TEMP_DIR . 'files.tar.gz')) {
|
|
|
|
unlink(self::TEMP_DIR . 'files.tar.gz');
|
|
|
|
}
|
|
|
|
if (file_exists(self::TEMP_DIR . 'files.tar')) {
|
|
|
|
unlink(self::TEMP_DIR . 'files.tar');
|
|
|
|
}
|
|
|
|
copy('core/module/install/ressource/files.tar.gz', self::TEMP_DIR . 'files.tar.gz');
|
|
|
|
$pharData = new PharData(self::TEMP_DIR . 'files.tar.gz');
|
|
|
|
$pharData->decompress();
|
|
|
|
// Installation
|
|
|
|
$pharData->extractTo(__DIR__ . '/../../../', null, true);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$success = $e->getMessage();
|
|
|
|
}
|
|
|
|
unlink(self::TEMP_DIR . 'files.tar.gz');
|
|
|
|
unlink(self::TEMP_DIR . 'files.tar');
|
2022-02-07 10:32:36 +01:00
|
|
|
// Créer le dossier des fontes
|
|
|
|
if (!is_dir(self::DATA_DIR . 'fonts')) {
|
|
|
|
mkdir(self::DATA_DIR . 'fonts');
|
2022-02-26 14:46:43 +01:00
|
|
|
}
|
2020-09-24 10:23:57 +02:00
|
|
|
// Stocker le dossier d'installation
|
|
|
|
$this->setData(['core', 'baseUrl', helper::baseUrl(false,false) ]);
|
|
|
|
// Créer sitemap
|
|
|
|
$this->createSitemap();
|
2021-10-19 19:14:52 +02:00
|
|
|
|
2021-10-19 19:37:04 +02:00
|
|
|
// Installation du thème sélectionné
|
|
|
|
$dataThemes = file_get_contents('core/module/install/ressource/themes/themes.json');
|
2021-10-19 19:14:52 +02:00
|
|
|
$dataThemes = json_decode($dataThemes, true);
|
|
|
|
$themeId = $dataThemes [$this->getInput('installTheme', helper::FILTER_STRING_SHORT)]['filename'];
|
|
|
|
if ($themeId !== 'default' ) {
|
|
|
|
$theme = new theme;
|
|
|
|
$theme->import('core/module/install/ressource/themes/' . $themeId);
|
|
|
|
}
|
2021-10-19 19:37:04 +02:00
|
|
|
|
|
|
|
// Copie des thèmes dans les fichiers
|
|
|
|
if (!is_dir(self::FILE_DIR . 'source/theme' )) {
|
|
|
|
mkdir(self::FILE_DIR . 'source/theme');
|
|
|
|
}
|
|
|
|
$this->copyDir('core/module/install/ressource/themes', self::FILE_DIR . 'source/theme');
|
|
|
|
unlink(self::FILE_DIR . 'source/theme/themes.json');
|
2022-02-26 14:46:43 +01:00
|
|
|
|
2020-09-09 17:21:02 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl(false),
|
2021-05-24 18:43:16 +02:00
|
|
|
'notification' => $sent === true ? 'Installation terminée' : $sent,
|
|
|
|
'state' => ($sent === true && $success === true) ? true : null
|
2020-09-09 17:21:02 +02:00
|
|
|
]);
|
2019-12-10 10:53:31 +01:00
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2021-10-19 19:14:52 +02:00
|
|
|
// Récupération de la liste des thèmes
|
|
|
|
$dataThemes = file_get_contents('core/module/install/ressource/themes/themes.json');
|
|
|
|
$dataThemes = json_decode($dataThemes, true);
|
|
|
|
self::$themes = helper::arrayCollumn($dataThemes, 'name');
|
2022-02-26 14:46:43 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_LAYOUT_LIGHT,
|
|
|
|
'title' => 'Installation',
|
|
|
|
'view' => 'index'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Étapes de mise à jour
|
|
|
|
*/
|
|
|
|
public function steps() {
|
|
|
|
switch($this->getInput('step', helper::FILTER_INT)) {
|
|
|
|
// Préparation
|
|
|
|
case 1:
|
|
|
|
$success = true;
|
2020-06-01 08:19:34 +02:00
|
|
|
// RAZ la mise à jour auto
|
|
|
|
$this->setData(['core','updateAvailable', false]);
|
2020-02-18 11:18:27 +01:00
|
|
|
// Backup du dossier Data
|
|
|
|
helper::autoBackup(self::BACKUP_DIR,['backup','tmp','file']);
|
2020-06-14 10:36:36 +02:00
|
|
|
// Sauvegarde htaccess
|
|
|
|
if ($this->getData(['config','autoUpdateHtaccess'])) {
|
|
|
|
$success = copy('.htaccess', '.htaccess' . '.bak');
|
|
|
|
}
|
2020-02-18 11:18:27 +01:00
|
|
|
// Nettoyage des fichiers d'installation précédents
|
2020-06-14 10:36:36 +02:00
|
|
|
if(file_exists(self::TEMP_DIR.'update.tar.gz') && $success) {
|
2019-05-27 20:35:04 +02:00
|
|
|
$success = unlink(self::TEMP_DIR.'update.tar.gz');
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2020-06-14 10:36:36 +02:00
|
|
|
if(file_exists(self::TEMP_DIR.'update.tar') && $success) {
|
2019-05-27 20:35:04 +02:00
|
|
|
$success = unlink(self::TEMP_DIR.'update.tar');
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
|
|
|
'success' => $success,
|
|
|
|
'data' => null
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
// Téléchargement
|
|
|
|
case 2:
|
2022-02-10 14:43:00 +01:00
|
|
|
file_put_contents(self::TEMP_DIR.'update.tar.gz', helper::getUrlContents(common::ZWII_UPDATE_URL . common::ZWII_UPDATE_CHANNEL . '/update.tar.gz'));
|
|
|
|
$md5origin = helper::getUrlContents(common::ZWII_UPDATE_URL . common::ZWII_UPDATE_CHANNEL . '/update.md5');
|
2022-01-09 11:33:41 +01:00
|
|
|
$md5origin = (explode(' ',$md5origin));
|
|
|
|
$md5target = md5_file(self::TEMP_DIR.'update.tar.gz');
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
2022-01-09 11:33:41 +01:00
|
|
|
'success' => $md5origin[0] === $md5target,
|
2018-04-02 08:29:19 +02:00
|
|
|
'data' => null
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
// Installation
|
|
|
|
case 3:
|
|
|
|
$success = true;
|
|
|
|
// Check la réécriture d'URL avant d'écraser les fichiers
|
|
|
|
$rewrite = helper::checkRewrite();
|
|
|
|
// Décompression et installation
|
|
|
|
try {
|
|
|
|
// Décompression dans le dossier de fichier temporaires
|
2019-05-27 20:35:04 +02:00
|
|
|
$pharData = new PharData(self::TEMP_DIR.'update.tar.gz');
|
2018-04-02 08:29:19 +02:00
|
|
|
$pharData->decompress();
|
|
|
|
// Installation
|
|
|
|
$pharData->extractTo(__DIR__ . '/../../../', null, true);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$success = $e->getMessage();
|
|
|
|
}
|
2020-06-02 18:49:24 +02:00
|
|
|
// Nettoyage du dossier
|
2019-05-27 20:35:04 +02:00
|
|
|
if(file_exists(self::TEMP_DIR.'update.tar.gz')) {
|
|
|
|
unlink(self::TEMP_DIR.'update.tar.gz');
|
2019-05-19 21:21:36 +02:00
|
|
|
}
|
2019-05-27 20:35:04 +02:00
|
|
|
if(file_exists(self::TEMP_DIR.'update.tar')) {
|
|
|
|
unlink(self::TEMP_DIR.'update.tar');
|
2019-05-19 21:21:36 +02:00
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
|
|
|
'success' => $success,
|
|
|
|
'data' => $rewrite
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
// Configuration
|
|
|
|
case 4:
|
|
|
|
$success = true;
|
2019-06-04 20:29:42 +02:00
|
|
|
$rewrite = $this->getInput('data');
|
2018-04-02 08:29:19 +02:00
|
|
|
// Réécriture d'URL
|
2019-06-04 20:29:42 +02:00
|
|
|
if ($rewrite === "true") {
|
2018-04-02 08:29:19 +02:00
|
|
|
$success = (file_put_contents(
|
|
|
|
'.htaccess',
|
|
|
|
PHP_EOL .
|
2022-01-09 10:46:33 +01:00
|
|
|
'<IfModule mod_rewrite.c>' . PHP_EOL .
|
2018-04-02 08:29:19 +02:00
|
|
|
"\tRewriteEngine on" . PHP_EOL .
|
|
|
|
"\tRewriteBase " . helper::baseUrl(false, false) . PHP_EOL .
|
|
|
|
"\tRewriteCond %{REQUEST_FILENAME} !-f" . PHP_EOL .
|
|
|
|
"\tRewriteCond %{REQUEST_FILENAME} !-d" . PHP_EOL .
|
|
|
|
"\tRewriteRule ^(.*)$ index.php?$1 [L]" . PHP_EOL .
|
2022-01-09 10:46:33 +01:00
|
|
|
'</IfModule>',
|
2018-04-02 08:29:19 +02:00
|
|
|
FILE_APPEND
|
|
|
|
) !== false);
|
|
|
|
}
|
2020-06-14 10:36:36 +02:00
|
|
|
// Recopie htaccess
|
|
|
|
if ($this->getData(['config','autoUpdateHtaccess']) &&
|
|
|
|
$success && file_exists( '.htaccess.bak')
|
|
|
|
) {
|
|
|
|
// L'écraser avec le backup
|
|
|
|
$success = copy( '.htaccess.bak' ,'.htaccess' );
|
|
|
|
// Effacer l ebackup
|
|
|
|
unlink('.htaccess.bak');
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
|
|
|
'success' => $success,
|
|
|
|
'data' => null
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mise à jour
|
|
|
|
*/
|
|
|
|
public function update() {
|
|
|
|
// Nouvelle version
|
2022-02-10 14:43:00 +01:00
|
|
|
self::$newVersion = helper::getUrlContents(common::ZWII_UPDATE_URL . common::ZWII_UPDATE_CHANNEL . '/version');
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_LAYOUT_LIGHT,
|
|
|
|
'title' => 'Mise à jour',
|
|
|
|
'view' => 'update'
|
|
|
|
]);
|
|
|
|
}
|
2019-05-02 13:21:48 +02:00
|
|
|
|
|
|
|
|
2019-03-08 11:22:19 +01:00
|
|
|
}
|