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/
|
|
|
|
*/
|
|
|
|
|
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,
|
2019-05-02 13:21:48 +02:00
|
|
|
'update' => self::GROUP_ADMIN,
|
|
|
|
'removeAll' => self::GROUP_ADMIN,
|
2018-04-02 08:29:19 +02:00
|
|
|
];
|
|
|
|
|
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()) {
|
2019-12-10 10:53:31 +01:00
|
|
|
//$sent = $success = false;
|
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';
|
|
|
|
}
|
|
|
|
// 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);
|
2020-02-07 09:11:22 +01:00
|
|
|
// Bannière par défaut
|
|
|
|
// Créer les dossiers
|
2020-04-15 10:28:53 +02:00
|
|
|
if (!is_dir(self::FILE_DIR.'source/banniere/')) {
|
|
|
|
mkdir(self::FILE_DIR.'source/banniere/');}
|
2020-06-02 18:49:24 +02:00
|
|
|
if (!is_dir(self::FILE_DIR.'thumb/banniere/')) {
|
2020-04-15 10:28:53 +02:00
|
|
|
mkdir(self::FILE_DIR.'thumb/banniere/');
|
2020-02-07 09:11:22 +01:00
|
|
|
}
|
|
|
|
// Copier les fichiers
|
2020-04-15 10:28:53 +02:00
|
|
|
copy('core/module/install/ressource/file/source/banniere960.jpg',self::FILE_DIR.'source/banniere/banniere960.jpg');
|
|
|
|
copy('core/module/install/ressource/file/thumb/banniere960.jpg',self::FILE_DIR.'thumb/banniere/banniere960.jpg');
|
2020-02-07 09:11:22 +01:00
|
|
|
// Copie des icônes
|
2020-06-02 18:49:24 +02:00
|
|
|
copy('core/module/install/ressource/file/source/favicon.ico',self::FILE_DIR.'source/favicon.ico');
|
|
|
|
copy('core/module/install/ressource/file/source/faviconDark.ico',self::FILE_DIR.'source/faviconDark.ico');
|
2019-05-02 13:21:48 +02:00
|
|
|
// Configure certaines données par défaut
|
2020-06-02 18:49:24 +02:00
|
|
|
if ($this->getInput('installDefaultData',helper::FILTER_BOOLEAN) === TRUE) {
|
2019-12-10 10:53:31 +01:00
|
|
|
$this->initData('page','fr',true);
|
|
|
|
$this->initData('module','fr',true);
|
2019-05-02 13:21:48 +02:00
|
|
|
$this->setData(['module', 'blog', 'mon-premier-article', 'userId', $userId]);
|
|
|
|
$this->setData(['module', 'blog', 'mon-deuxieme-article', 'userId', $userId]);
|
2020-06-02 18:49:24 +02:00
|
|
|
$this->setData(['module', 'blog', 'mon-troisieme-article', 'userId', $userId]);
|
|
|
|
}
|
2019-12-10 10:53:31 +01:00
|
|
|
$success = $this->setData([
|
2018-04-02 08:29:19 +02:00
|
|
|
'user',
|
|
|
|
$userId,
|
|
|
|
[
|
|
|
|
'firstname' => $userFirstname,
|
|
|
|
'forgot' => 0,
|
|
|
|
'group' => self::GROUP_ADMIN,
|
|
|
|
'lastname' => $userLastname,
|
|
|
|
'mail' => $userMail,
|
2020-07-02 19:58:35 +02:00
|
|
|
'password' => $this->getInput('installPassword', helper::FILTER_PASSWORD, true),
|
2020-07-07 15:04:19 +02:00
|
|
|
'pseudo' => $userFirstname,
|
2020-07-10 16:57:21 +02:00
|
|
|
'signature'=> self::SIGNATURE_PSEUDO
|
2018-04-02 08:29:19 +02:00
|
|
|
]
|
|
|
|
]);
|
2020-06-02 18:49:24 +02:00
|
|
|
if ($success === true) { // Formulaire complété envoi du mail
|
2019-12-10 10:53:31 +01:00
|
|
|
// Envoie le mail
|
|
|
|
$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>' .
|
2020-02-27 15:54:57 +01:00
|
|
|
'<strong>Identifiant du compte :</strong> ' . $this->getInput('installId') . '<br>',
|
|
|
|
null
|
2019-12-10 10:53:31 +01:00
|
|
|
);
|
|
|
|
// Stocker le dossier d'installation
|
|
|
|
$this->setData(['core', 'baseUrl', helper::baseUrl(false,false) ]);
|
|
|
|
// Générer un fichier robots.txt
|
|
|
|
$this->createRobots();
|
|
|
|
// Créer sitemap
|
2020-06-02 18:49:24 +02:00
|
|
|
$this->createSitemap();
|
|
|
|
// Valeurs en sortie
|
2019-12-10 10:53:31 +01:00
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl(false),
|
|
|
|
'notification' => ($sent === true ? 'Installation terminée' : $sent),
|
|
|
|
'state' => ($sent === true ? true : null)
|
|
|
|
]);
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2020-06-02 18:49:24 +02: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:
|
|
|
|
// Téléchargement depuis le serveur de Zwii
|
2020-04-28 10:34:11 +02:00
|
|
|
$success = (file_put_contents(self::TEMP_DIR.'update.tar.gz', helper::urlGetContents('https://zwiicms.com/update/' . common::ZWII_UPDATE_CHANNEL . '/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
|
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 .
|
|
|
|
'<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);
|
|
|
|
}
|
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
|
2020-04-28 10:34:11 +02:00
|
|
|
self::$newVersion = helper::urlGetContents('http://zwiicms.com/update/' . 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
|
|
|
|
|
|
|
/**
|
|
|
|
* Effacer un dossier non vide.
|
|
|
|
*/
|
|
|
|
private function removeAll ( $path ) {
|
|
|
|
foreach ( new DirectoryIterator($path) as $item ):
|
|
|
|
if ( $item->isFile() ) unlink($item->getRealPath());
|
|
|
|
if ( !$item->isDot() && $item->isDir() ) $this->removeAll($item->getRealPath());
|
|
|
|
endforeach;
|
2020-06-02 18:49:24 +02:00
|
|
|
|
2019-05-02 13:21:48 +02:00
|
|
|
rmdir($path);
|
|
|
|
}
|
|
|
|
|
2019-03-08 11:22:19 +01:00
|
|
|
}
|