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
|
|
|
|
* @license GNU General Public License, version 3
|
|
|
|
* @link http://zwiicms.com/
|
|
|
|
*/
|
|
|
|
|
|
|
|
class install extends common {
|
|
|
|
|
|
|
|
public static $actions = [
|
|
|
|
'index' => self::GROUP_VISITOR,
|
|
|
|
'steps' => self::GROUP_ADMIN,
|
|
|
|
'update' => self::GROUP_ADMIN
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $newVersion;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Installation
|
|
|
|
*/
|
|
|
|
public function index() {
|
|
|
|
// Accès refusé
|
|
|
|
if($this->getData(['user']) !== []) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Accès autorisé
|
|
|
|
else {
|
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
|
|
|
// 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';
|
|
|
|
}
|
|
|
|
// Crée l'utilisateur
|
|
|
|
$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);
|
|
|
|
$this->setData([
|
|
|
|
'user',
|
|
|
|
$userId,
|
|
|
|
[
|
|
|
|
'firstname' => $userFirstname,
|
|
|
|
'forgot' => 0,
|
|
|
|
'group' => self::GROUP_ADMIN,
|
|
|
|
'lastname' => $userLastname,
|
|
|
|
'mail' => $userMail,
|
|
|
|
'password' => $this->getInput('installPassword', helper::FILTER_PASSWORD, true)
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
// Configure certaines données par défaut
|
|
|
|
$this->setData(['module', 'blog', 'mon-premier-article', 'userId', $userId]);
|
|
|
|
$this->setData(['module', 'blog', 'mon-deuxieme-article', 'userId', $userId]);
|
|
|
|
$this->setData(['module', 'blog', 'mon-troisieme-article', 'userId', $userId]);
|
|
|
|
// Envoi le mail
|
|
|
|
$sent = $this->sendMail(
|
|
|
|
$userMail,
|
|
|
|
'Installation de votre site',
|
|
|
|
'Bonjour' . ' <strong>' . $userFirstname . ' ' . $userLastname . '</strong>,<br><br>' .
|
|
|
|
'Vous trouverez ci-dessous 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>' .
|
|
|
|
'<strong>Mot de passe du compte :</strong> ' . $this->getInput('installPassword')
|
|
|
|
);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl(false),
|
|
|
|
'notification' => ($sent === true ? 'Installation terminée' : $sent),
|
|
|
|
'state' => ($sent === true ? true : null)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// 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;
|
|
|
|
// Copie du fichier de données
|
2018-12-24 19:48:14 +01:00
|
|
|
copy('site/data/core.json', 'site/backup/' . date('Y-m-d', time()) . '-update.json');
|
2018-04-02 08:29:19 +02:00
|
|
|
// Nettoyage des fichiers temporaires
|
|
|
|
if(file_exists('site/tmp/update.tar.gz')) {
|
|
|
|
$success = unlink('site/tmp/update.tar.gz');
|
|
|
|
}
|
|
|
|
if(file_exists('site/tmp/update.tar')) {
|
|
|
|
$success = unlink('site/tmp/update.tar');
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
|
|
|
'success' => $success,
|
|
|
|
'data' => null
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
// Téléchargement
|
|
|
|
case 2:
|
|
|
|
// Téléchargement depuis le serveur de Zwii
|
2019-01-25 11:54:37 +01:00
|
|
|
$success = (file_put_contents('site/tmp/update.tar.gz', file_get_contents('https://zwiicms.com/update/update.tar.gz')) !== false);
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
|
|
|
'success' => $success,
|
|
|
|
'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
|
|
|
|
$pharData = new PharData('site/tmp/update.tar.gz');
|
|
|
|
$pharData->decompress();
|
|
|
|
// Installation
|
|
|
|
$pharData->extractTo(__DIR__ . '/../../../', null, true);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$success = $e->getMessage();
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
|
|
|
'success' => $success,
|
|
|
|
'data' => $rewrite
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
// Configuration
|
|
|
|
case 4:
|
|
|
|
$success = true;
|
|
|
|
// Réécriture d'URL
|
|
|
|
if($this->getInput('data', helper::FILTER_BOOLEAN)) {
|
|
|
|
$success = (file_put_contents(
|
|
|
|
'.htaccess',
|
|
|
|
PHP_EOL .
|
|
|
|
'<ifModule mod_rewrite.c>' . PHP_EOL .
|
|
|
|
"\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 .
|
|
|
|
'</ifModule>',
|
|
|
|
FILE_APPEND
|
|
|
|
) !== false);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => [
|
|
|
|
'success' => $success,
|
|
|
|
'data' => null
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mise à jour
|
|
|
|
*/
|
|
|
|
public function update() {
|
|
|
|
// Nouvelle version
|
2019-01-25 11:54:37 +01:00
|
|
|
self::$newVersion = file_get_contents('http://zwiicms.com/update/version');
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_LAYOUT_LIGHT,
|
|
|
|
'title' => 'Mise à jour',
|
|
|
|
'view' => 'update'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|