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
|
2020-08-08 17:06:06 +02:00
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
2020-03-15 20:53:13 +01:00
|
|
|
* @copyright Copyright (C) 2018-2020, 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
|
|
|
*/
|
|
|
|
|
|
|
|
class config extends common {
|
|
|
|
|
|
|
|
public static $actions = [
|
|
|
|
'backup' => self::GROUP_ADMIN,
|
2018-12-25 18:17:11 +01:00
|
|
|
'configMetaImage' => self::GROUP_ADMIN,
|
2019-05-02 13:21:48 +02:00
|
|
|
'generateFiles' => self::GROUP_ADMIN,
|
|
|
|
'updateRobots' => self::GROUP_ADMIN,
|
2019-12-10 10:53:31 +01:00
|
|
|
'index' => self::GROUP_ADMIN,
|
2020-11-21 15:09:10 +01:00
|
|
|
'advanced' => self::GROUP_ADMIN,
|
2020-05-07 08:36:24 +02:00
|
|
|
'manage' => self::GROUP_ADMIN,
|
2020-05-12 16:28:10 +02:00
|
|
|
'updateBaseUrl' => self::GROUP_ADMIN,
|
2020-05-30 12:04:45 +02:00
|
|
|
'script' => self::GROUP_ADMIN,
|
|
|
|
'logReset' => self::GROUP_ADMIN,
|
2020-05-31 19:08:19 +02:00
|
|
|
'logDownload'=> self::GROUP_ADMIN,
|
|
|
|
'blacklistReset' => self::GROUP_ADMIN,
|
2021-02-09 16:12:32 +01:00
|
|
|
'blacklistDownload' => self::GROUP_ADMIN,
|
|
|
|
'modules' => self::GROUP_ADMIN,
|
|
|
|
'moduleDelete' => self::GROUP_ADMIN
|
2020-05-31 19:08:19 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
];
|
2021-02-09 16:12:32 +01:00
|
|
|
|
|
|
|
public static $modInstal = [];
|
|
|
|
public static $str;
|
2020-05-25 11:58:54 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
public static $timezones = [
|
|
|
|
'Pacific/Midway' => '(GMT-11:00) Midway Island',
|
|
|
|
'US/Samoa' => '(GMT-11:00) Samoa',
|
|
|
|
'US/Hawaii' => '(GMT-10:00) Hawaii',
|
|
|
|
'US/Alaska' => '(GMT-09:00) Alaska',
|
|
|
|
'US/Pacific' => '(GMT-08:00) Pacific Time (US & Canada)',
|
|
|
|
'America/Tijuana' => '(GMT-08:00) Tijuana',
|
|
|
|
'US/Arizona' => '(GMT-07:00) Arizona',
|
|
|
|
'US/Mountain' => '(GMT-07:00) Mountain Time (US & Canada)',
|
|
|
|
'America/Chihuahua' => '(GMT-07:00) Chihuahua',
|
|
|
|
'America/Mazatlan' => '(GMT-07:00) Mazatlan',
|
|
|
|
'America/Mexico_City' => '(GMT-06:00) Mexico City',
|
|
|
|
'America/Monterrey' => '(GMT-06:00) Monterrey',
|
|
|
|
'Canada/Saskatchewan' => '(GMT-06:00) Saskatchewan',
|
|
|
|
'US/Central' => '(GMT-06:00) Central Time (US & Canada)',
|
|
|
|
'US/Eastern' => '(GMT-05:00) Eastern Time (US & Canada)',
|
|
|
|
'US/East-Indiana' => '(GMT-05:00) Indiana (East)',
|
|
|
|
'America/Bogota' => '(GMT-05:00) Bogota',
|
|
|
|
'America/Lima' => '(GMT-05:00) Lima',
|
|
|
|
'America/Caracas' => '(GMT-04:30) Caracas',
|
|
|
|
'Canada/Atlantic' => '(GMT-04:00) Atlantic Time (Canada)',
|
|
|
|
'America/La_Paz' => '(GMT-04:00) La Paz',
|
|
|
|
'America/Santiago' => '(GMT-04:00) Santiago',
|
|
|
|
'Canada/Newfoundland' => '(GMT-03:30) Newfoundland',
|
|
|
|
'America/Buenos_Aires' => '(GMT-03:00) Buenos Aires',
|
|
|
|
'Greenland' => '(GMT-03:00) Greenland',
|
|
|
|
'Atlantic/Stanley' => '(GMT-02:00) Stanley',
|
|
|
|
'Atlantic/Azores' => '(GMT-01:00) Azores',
|
|
|
|
'Atlantic/Cape_Verde' => '(GMT-01:00) Cape Verde Is.',
|
|
|
|
'Africa/Casablanca' => '(GMT) Casablanca',
|
|
|
|
'Europe/Dublin' => '(GMT) Dublin',
|
|
|
|
'Europe/Lisbon' => '(GMT) Lisbon',
|
|
|
|
'Europe/London' => '(GMT) London',
|
|
|
|
'Africa/Monrovia' => '(GMT) Monrovia',
|
|
|
|
'Europe/Amsterdam' => '(GMT+01:00) Amsterdam',
|
|
|
|
'Europe/Belgrade' => '(GMT+01:00) Belgrade',
|
|
|
|
'Europe/Berlin' => '(GMT+01:00) Berlin',
|
|
|
|
'Europe/Bratislava' => '(GMT+01:00) Bratislava',
|
|
|
|
'Europe/Brussels' => '(GMT+01:00) Brussels',
|
|
|
|
'Europe/Budapest' => '(GMT+01:00) Budapest',
|
|
|
|
'Europe/Copenhagen' => '(GMT+01:00) Copenhagen',
|
|
|
|
'Europe/Ljubljana' => '(GMT+01:00) Ljubljana',
|
|
|
|
'Europe/Madrid' => '(GMT+01:00) Madrid',
|
|
|
|
'Europe/Paris' => '(GMT+01:00) Paris',
|
|
|
|
'Europe/Prague' => '(GMT+01:00) Prague',
|
|
|
|
'Europe/Rome' => '(GMT+01:00) Rome',
|
|
|
|
'Europe/Sarajevo' => '(GMT+01:00) Sarajevo',
|
|
|
|
'Europe/Skopje' => '(GMT+01:00) Skopje',
|
|
|
|
'Europe/Stockholm' => '(GMT+01:00) Stockholm',
|
|
|
|
'Europe/Vienna' => '(GMT+01:00) Vienna',
|
|
|
|
'Europe/Warsaw' => '(GMT+01:00) Warsaw',
|
|
|
|
'Europe/Zagreb' => '(GMT+01:00) Zagreb',
|
|
|
|
'Europe/Athens' => '(GMT+02:00) Athens',
|
|
|
|
'Europe/Bucharest' => '(GMT+02:00) Bucharest',
|
|
|
|
'Africa/Cairo' => '(GMT+02:00) Cairo',
|
|
|
|
'Africa/Harare' => '(GMT+02:00) Harare',
|
|
|
|
'Europe/Helsinki' => '(GMT+02:00) Helsinki',
|
|
|
|
'Europe/Istanbul' => '(GMT+02:00) Istanbul',
|
|
|
|
'Asia/Jerusalem' => '(GMT+02:00) Jerusalem',
|
|
|
|
'Europe/Kiev' => '(GMT+02:00) Kyiv',
|
|
|
|
'Europe/Minsk' => '(GMT+02:00) Minsk',
|
|
|
|
'Europe/Riga' => '(GMT+02:00) Riga',
|
|
|
|
'Europe/Sofia' => '(GMT+02:00) Sofia',
|
|
|
|
'Europe/Tallinn' => '(GMT+02:00) Tallinn',
|
|
|
|
'Europe/Vilnius' => '(GMT+02:00) Vilnius',
|
|
|
|
'Asia/Baghdad' => '(GMT+03:00) Baghdad',
|
|
|
|
'Asia/Kuwait' => '(GMT+03:00) Kuwait',
|
|
|
|
'Europe/Moscow' => '(GMT+03:00) Moscow',
|
|
|
|
'Africa/Nairobi' => '(GMT+03:00) Nairobi',
|
|
|
|
'Asia/Riyadh' => '(GMT+03:00) Riyadh',
|
|
|
|
'Europe/Volgograd' => '(GMT+03:00) Volgograd',
|
|
|
|
'Asia/Tehran' => '(GMT+03:30) Tehran',
|
|
|
|
'Asia/Baku' => '(GMT+04:00) Baku',
|
|
|
|
'Asia/Muscat' => '(GMT+04:00) Muscat',
|
|
|
|
'Asia/Tbilisi' => '(GMT+04:00) Tbilisi',
|
|
|
|
'Asia/Yerevan' => '(GMT+04:00) Yerevan',
|
|
|
|
'Asia/Kabul' => '(GMT+04:30) Kabul',
|
|
|
|
'Asia/Yekaterinburg' => '(GMT+05:00) Ekaterinburg',
|
|
|
|
'Asia/Karachi' => '(GMT+05:00) Karachi',
|
|
|
|
'Asia/Tashkent' => '(GMT+05:00) Tashkent',
|
|
|
|
'Asia/Kolkata' => '(GMT+05:30) Kolkata',
|
|
|
|
'Asia/Kathmandu' => '(GMT+05:45) Kathmandu',
|
|
|
|
'Asia/Almaty' => '(GMT+06:00) Almaty',
|
|
|
|
'Asia/Dhaka' => '(GMT+06:00) Dhaka',
|
|
|
|
'Asia/Novosibirsk' => '(GMT+06:00) Novosibirsk',
|
|
|
|
'Asia/Bangkok' => '(GMT+07:00) Bangkok',
|
|
|
|
'Asia/Jakarta' => '(GMT+07:00) Jakarta',
|
|
|
|
'Asia/Krasnoyarsk' => '(GMT+07:00) Krasnoyarsk',
|
|
|
|
'Asia/Chongqing' => '(GMT+08:00) Chongqing',
|
|
|
|
'Asia/Hong_Kong' => '(GMT+08:00) Hong Kong',
|
|
|
|
'Asia/Irkutsk' => '(GMT+08:00) Irkutsk',
|
|
|
|
'Asia/Kuala_Lumpur' => '(GMT+08:00) Kuala Lumpur',
|
|
|
|
'Australia/Perth' => '(GMT+08:00) Perth',
|
|
|
|
'Asia/Singapore' => '(GMT+08:00) Singapore',
|
|
|
|
'Asia/Taipei' => '(GMT+08:00) Taipei',
|
|
|
|
'Asia/Ulaanbaatar' => '(GMT+08:00) Ulaan Bataar',
|
|
|
|
'Asia/Urumqi' => '(GMT+08:00) Urumqi',
|
|
|
|
'Asia/Seoul' => '(GMT+09:00) Seoul',
|
|
|
|
'Asia/Tokyo' => '(GMT+09:00) Tokyo',
|
|
|
|
'Asia/Yakutsk' => '(GMT+09:00) Yakutsk',
|
|
|
|
'Australia/Adelaide' => '(GMT+09:30) Adelaide',
|
|
|
|
'Australia/Darwin' => '(GMT+09:30) Darwin',
|
|
|
|
'Australia/Brisbane' => '(GMT+10:00) Brisbane',
|
|
|
|
'Australia/Canberra' => '(GMT+10:00) Canberra',
|
|
|
|
'Pacific/Guam' => '(GMT+10:00) Guam',
|
|
|
|
'Australia/Hobart' => '(GMT+10:00) Hobart',
|
|
|
|
'Australia/Melbourne' => '(GMT+10:00) Melbourne',
|
|
|
|
'Pacific/Port_Moresby' => '(GMT+10:00) Port Moresby',
|
|
|
|
'Australia/Sydney' => '(GMT+10:00) Sydney',
|
|
|
|
'Asia/Vladivostok' => '(GMT+10:00) Vladivostok',
|
|
|
|
'Asia/Magadan' => '(GMT+11:00) Magadan',
|
|
|
|
'Pacific/Auckland' => '(GMT+12:00) Auckland',
|
|
|
|
'Pacific/Fiji' => '(GMT+12:00) Fiji',
|
|
|
|
'Asia/Kamchatka' => '(GMT+12:00) Kamchatka'
|
|
|
|
];
|
2018-10-06 05:46:07 +02:00
|
|
|
// Nombre d'objets par page
|
|
|
|
public static $ItemsList = [
|
2018-10-06 06:19:54 +02:00
|
|
|
5 => '5 articles',
|
|
|
|
10 => '10 articles',
|
|
|
|
15 => '15 articles',
|
2020-05-25 11:58:54 +02:00
|
|
|
20 => '20 articles'
|
2018-10-06 05:46:07 +02:00
|
|
|
];
|
2020-05-10 18:06:57 +02:00
|
|
|
// Type de proxy
|
|
|
|
public static $proxyType = [
|
|
|
|
'tcp://' => 'TCP',
|
|
|
|
'http://' => 'HTTP'
|
|
|
|
];
|
|
|
|
// Authentification SMTP
|
|
|
|
public static $SMTPauth = [
|
|
|
|
true => 'Oui',
|
|
|
|
false => 'Non'
|
|
|
|
];
|
|
|
|
// Encryptation SMTP
|
|
|
|
public static $SMTPEnc = [
|
|
|
|
'' => 'Aucune',
|
|
|
|
'tls' => 'START TLS',
|
|
|
|
'ssl' => 'SSL/TLS'
|
|
|
|
];
|
2020-05-28 19:03:31 +02:00
|
|
|
// Sécurité de la connexion - tentative max avant blocage
|
|
|
|
public static $connectAttempt = [
|
2020-12-31 17:39:36 +01:00
|
|
|
999 => 'Sécurité désactivée',
|
2020-05-28 19:03:31 +02:00
|
|
|
3 => '3 tentatives',
|
|
|
|
5 => '5 tentatives',
|
2020-05-29 08:24:32 +02:00
|
|
|
10 => '10 tentatives'
|
2020-05-28 19:03:31 +02:00
|
|
|
];
|
|
|
|
// Sécurité de la connexion - durée du blocage
|
|
|
|
public static $connectTimeout = [
|
2020-12-31 17:39:36 +01:00
|
|
|
0 => 'Sécurité désactivée',
|
2020-05-30 12:17:54 +02:00
|
|
|
300 => '5 minutes',
|
|
|
|
600 => '10 minutes',
|
|
|
|
900 => '15 minutes'
|
2020-05-28 19:03:31 +02:00
|
|
|
];
|
2020-06-04 18:34:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Génére les fichiers pour les crawlers
|
|
|
|
*/
|
2019-05-02 13:21:48 +02:00
|
|
|
public function generateFiles() {
|
|
|
|
// Mettre à jour le site map
|
2019-12-10 10:53:31 +01:00
|
|
|
$successSitemap=$this->createSitemap();
|
2019-05-02 13:21:48 +02:00
|
|
|
|
2020-06-02 18:49:24 +02:00
|
|
|
// Créer un fichier robots.txt
|
2019-05-02 13:21:48 +02:00
|
|
|
$successRobots=$this->updateRobots();
|
|
|
|
if ( $successSitemap === true &&
|
|
|
|
$successRobots >= 100) {
|
|
|
|
$success = true;
|
|
|
|
} else {
|
|
|
|
$success = false;
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => ($successSitemap === true && $successRobots >= 100) ? 'Création réussie' : 'Echec d\'écriture',
|
2020-11-25 14:31:43 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/advanced',
|
2019-05-02 13:21:48 +02:00
|
|
|
'state' => ($successSitemap === true && $successRobots >=100) ? true : false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-25 11:58:54 +02:00
|
|
|
* Met à jour un fichier robots.txt lors du changement de réécriture
|
2019-05-02 13:21:48 +02:00
|
|
|
*/
|
|
|
|
|
2020-06-04 18:34:39 +02:00
|
|
|
private function updateRobots() {
|
2019-05-02 13:21:48 +02:00
|
|
|
// Créer le fichier robot si absent
|
|
|
|
if (!file_exists('robots.txt')) {
|
|
|
|
$this->createRobots();
|
|
|
|
}
|
|
|
|
// backup
|
|
|
|
rename ('robots.txt','robots.bak');
|
|
|
|
$fileold = fopen('robots.bak','r');
|
|
|
|
$filenew = fopen('robots.txt','w');
|
2020-05-25 11:58:54 +02:00
|
|
|
while(!feof($fileold)) {
|
2019-05-02 13:21:48 +02:00
|
|
|
$data = fgets($fileold);
|
|
|
|
if (strpos($data,'sitemap.xml') == 0) {
|
|
|
|
fwrite($filenew, $data);
|
|
|
|
} else {
|
2019-06-15 18:27:00 +02:00
|
|
|
fwrite($filenew, 'Sitemap: ' . helper::baseUrl(false) . 'sitemap.xml' . PHP_EOL);
|
|
|
|
fwrite($filenew, 'Sitemap: ' . helper::baseUrl(false) . 'sitemap.xml.gz' . PHP_EOL);
|
2019-05-02 13:21:48 +02:00
|
|
|
fwrite($filenew, '# ZWII CONFIG ---------' . PHP_EOL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($fileold);
|
|
|
|
unlink('robots.bak');
|
|
|
|
return(fclose($filenew));
|
|
|
|
}
|
2020-05-07 08:36:24 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Sauvegarde des données
|
|
|
|
*/
|
|
|
|
public function backup() {
|
2020-02-10 16:36:57 +01:00
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
2020-05-25 11:58:54 +02:00
|
|
|
// Creation du ZIP
|
2020-02-10 16:36:57 +01:00
|
|
|
$filter = $this->getInput('configBackupOption',helper::FILTER_BOOLEAN) === true ? ['backup','tmp'] : ['backup','tmp','file'];
|
|
|
|
$fileName = helper::autoBackup(self::TEMP_DIR,$filter);
|
2020-08-09 12:00:29 +02:00
|
|
|
// Créer le répertoire manquant
|
2020-08-08 17:06:06 +02:00
|
|
|
if (!is_dir(self::FILE_DIR.'source/backup')) {
|
|
|
|
mkdir(self::FILE_DIR.'source/backup');
|
|
|
|
}
|
2020-08-09 12:00:29 +02:00
|
|
|
// Copie dans les fichiers
|
|
|
|
$success = copy (self::TEMP_DIR . $fileName , self::FILE_DIR.'source/backup/' . $fileName);
|
|
|
|
// Détruire le temporaire
|
|
|
|
unlink(self::TEMP_DIR . $fileName);
|
2020-02-10 16:36:57 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-08-09 12:00:29 +02:00
|
|
|
'display' => self::DISPLAY_JSON,
|
|
|
|
'content' => json_encode($success)
|
2020-02-10 16:36:57 +01:00
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-05-07 16:51:24 +02:00
|
|
|
'title' => 'Sauvegarder',
|
2020-02-10 16:36:57 +01:00
|
|
|
'view' => 'backup'
|
|
|
|
]);
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
|
2018-10-24 15:50:07 +02:00
|
|
|
/**
|
2018-12-25 18:17:11 +01:00
|
|
|
* Réalise une copie d'écran du site
|
2018-10-24 15:50:07 +02:00
|
|
|
* https://www.codexworld.com/capture-screenshot-website-url-php-google-api/
|
|
|
|
*/
|
2018-12-25 18:17:11 +01:00
|
|
|
public function configMetaImage() {
|
2020-05-25 11:58:54 +02:00
|
|
|
// fonction désactivée pour un site local
|
|
|
|
if ( strpos(helper::baseUrl(false),'localhost') > 0 OR strpos(helper::baseUrl(false),'127.0.0.1') > 0) {
|
2020-10-12 09:49:17 +02:00
|
|
|
$site = 'https://zwiicms.fr/'; } else {
|
2018-10-24 22:48:10 +02:00
|
|
|
$site = helper::baseUrl(false); }
|
2020-05-25 11:58:54 +02:00
|
|
|
|
2019-06-18 10:13:09 +02:00
|
|
|
$success= false;
|
2020-05-21 12:01:46 +02:00
|
|
|
$googlePagespeedData = helper::urlGetContents('https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url='. $site .'&screenshot=true');
|
2019-06-18 10:13:09 +02:00
|
|
|
if ($googlePagespeedData !== false) {
|
|
|
|
$googlePagespeedData = json_decode($googlePagespeedData, true);
|
2020-05-21 12:01:46 +02:00
|
|
|
$data = str_replace('_','/',$googlePagespeedData['lighthouseResult']['audits']['final-screenshot']['details']['data']);
|
|
|
|
$data = str_replace('-','+',$data);
|
2020-05-25 11:58:54 +02:00
|
|
|
$img = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
|
2020-06-29 20:55:22 +02:00
|
|
|
$success = file_put_contents( self::FILE_DIR.'source/screenshot.jpg',$img) ;
|
|
|
|
// Effacer la miniature png
|
|
|
|
if (file_exists(self::FILE_DIR.'source/screenshot.png')) {
|
|
|
|
unlink (self::FILE_DIR.'source/screenshot.png');
|
2019-06-20 18:58:49 +02:00
|
|
|
}
|
2019-06-18 10:13:09 +02:00
|
|
|
}
|
2018-10-24 22:48:10 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-06-29 20:55:22 +02:00
|
|
|
'notification' => $success === false ? 'Service inaccessible ou erreur d\'écriture de l\'image' : 'Image générée avec succès',
|
2020-11-25 14:31:43 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'advanced',
|
2020-06-29 20:55:22 +02:00
|
|
|
'state' => $success === false ? false : true
|
2018-10-24 22:48:10 +02:00
|
|
|
]);
|
2020-05-25 11:58:54 +02:00
|
|
|
}
|
2018-10-24 15:50:07 +02:00
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
/**
|
|
|
|
* Procédure d'importation
|
|
|
|
*/
|
2020-05-07 08:36:24 +02:00
|
|
|
public function manage() {
|
2019-12-10 10:53:31 +01:00
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
2020-05-07 08:36:24 +02:00
|
|
|
//if ($this->getInput('configManageImportFile'))
|
|
|
|
$fileZip = $this->getInput('configManageImportFile');
|
2019-12-10 10:53:31 +01:00
|
|
|
$file_parts = pathinfo($fileZip);
|
|
|
|
$folder = date('Y-m-d-h-i-s', time());
|
|
|
|
$zip = new ZipArchive();
|
|
|
|
if ($file_parts['extension'] !== 'zip') {
|
|
|
|
// Valeurs en sortie erreur
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => 'Le fichier n\'est pas une archive valide',
|
2020-05-07 08:36:24 +02:00
|
|
|
'redirect' => helper::baseUrl() . 'config/manage',
|
2019-12-10 10:53:31 +01:00
|
|
|
'state' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$successOpen = $zip->open(self::FILE_DIR . 'source/' . $fileZip);
|
2020-05-25 11:58:54 +02:00
|
|
|
if ($successOpen === FALSE) {
|
2019-12-10 10:53:31 +01:00
|
|
|
// Valeurs en sortie erreur
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => 'Impossible de lire l\'archive',
|
2020-05-07 08:36:24 +02:00
|
|
|
'redirect' => helper::baseUrl() . 'config/manage',
|
2019-12-10 10:53:31 +01:00
|
|
|
'state' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Lire le contenu de l'archive dans le tableau files
|
2020-05-25 11:58:54 +02:00
|
|
|
for( $i = 0; $i < $zip->numFiles; $i++ ){
|
|
|
|
$stat = $zip->statIndex( $i );
|
|
|
|
$files [] = ( basename( $stat['name'] ));
|
2019-12-10 10:53:31 +01:00
|
|
|
}
|
2020-05-25 11:58:54 +02:00
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Détermination de la version à installer
|
2020-05-25 11:58:54 +02:00
|
|
|
if (in_array('theme.json',$files) === true &&
|
|
|
|
in_array('core.json',$files) === true &&
|
|
|
|
in_array ('user.json', $files) === false ) {
|
2019-12-10 10:53:31 +01:00
|
|
|
// V9 pas de fichier user dans l'archive
|
|
|
|
// Stocker le choix de conserver les users installées
|
|
|
|
$version = '9';
|
|
|
|
|
2020-05-25 11:58:54 +02:00
|
|
|
} elseif (in_array('theme.json',$files) === true &&
|
|
|
|
in_array('core.json',$files) === true &&
|
|
|
|
in_array ('user.json', $files) === true &&
|
2019-12-10 10:53:31 +01:00
|
|
|
in_array ('config.json', $files) === true ) {
|
2020-05-07 08:36:24 +02:00
|
|
|
// V10 valide
|
2019-12-10 10:53:31 +01:00
|
|
|
$version = '10';
|
|
|
|
// Option active, les users sont stockées
|
2020-05-25 11:58:54 +02:00
|
|
|
if ($this->getInput('configManageImportUser', helper::FILTER_BOOLEAN) === true ) {
|
|
|
|
$users = $this->getData(['user']);
|
|
|
|
}
|
2019-12-10 10:53:31 +01:00
|
|
|
} else { // Version invalide
|
|
|
|
// Valeurs en sortie erreur
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => 'Cette archive n\'est pas une sauvegarde valide',
|
2020-05-07 08:36:24 +02:00
|
|
|
'redirect' => helper::baseUrl() . 'config/manage',
|
2019-12-10 10:53:31 +01:00
|
|
|
'state' => false
|
|
|
|
]);
|
|
|
|
}
|
2019-12-17 10:34:34 +01:00
|
|
|
// Préserver les comptes des utilisateurs d'une version 9 si option cochée
|
2020-06-29 20:55:22 +02:00
|
|
|
// Positionnement d'une variable de session lue au constructeurs
|
2019-12-17 16:04:40 +01:00
|
|
|
if ($version === '9') {
|
2020-05-07 16:22:44 +02:00
|
|
|
$_SESSION['KEEP_USERS'] = $this->getInput('configManageImportUser', helper::FILTER_BOOLEAN);
|
2019-12-17 10:34:34 +01:00
|
|
|
}
|
2020-05-07 08:36:24 +02:00
|
|
|
// Extraire le zip ou 'site/'
|
2020-05-25 11:58:54 +02:00
|
|
|
$success = $zip->extractTo( 'site/' );
|
|
|
|
// Fermer l'archive
|
2019-12-10 10:53:31 +01:00
|
|
|
$zip->close();
|
2020-05-25 11:58:54 +02:00
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Restaurer les users originaux d'une v10 si option cochée
|
|
|
|
if (!empty($users) &&
|
|
|
|
$version === '10' &&
|
2020-05-25 11:58:54 +02:00
|
|
|
$this->getInput('configManageImportUser', helper::FILTER_BOOLEAN) === true) {
|
|
|
|
$this->setData(['user',$users]);
|
2020-05-07 08:36:24 +02:00
|
|
|
}
|
2020-05-09 12:06:22 +02:00
|
|
|
/*
|
2020-05-07 08:36:24 +02:00
|
|
|
if ($version === '9' ) {
|
2020-05-25 11:58:54 +02:00
|
|
|
$this->importData($this->getInput('configManageImportUser', helper::FILTER_BOOLEAN));
|
2020-05-07 08:36:24 +02:00
|
|
|
$this->setData(['core','dataVersion',0]);
|
2020-05-09 12:06:22 +02:00
|
|
|
}*/
|
2020-05-25 11:58:54 +02:00
|
|
|
|
2020-05-07 08:36:24 +02:00
|
|
|
// Met à jours les URL dans les contenus de page
|
2020-05-25 11:58:54 +02:00
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Message de notification
|
2020-05-25 11:58:54 +02:00
|
|
|
$notification = $success === true ? 'Restauration réalisée avec succès' : 'Erreur inconnue';
|
2020-05-07 08:36:24 +02:00
|
|
|
$redirect = $this->getInput('configManageImportUser', helper::FILTER_BOOLEAN) === true ? helper::baseUrl() . 'config/manage' : helper::baseUrl() . 'user/login/';
|
2020-05-25 11:58:54 +02:00
|
|
|
// Valeurs en sortie erreur
|
2019-12-10 10:53:31 +01:00
|
|
|
$this->addOutput([
|
|
|
|
'notification' => $notification,
|
|
|
|
'redirect' =>$redirect,
|
|
|
|
'state' => $success
|
|
|
|
]);
|
2020-05-25 11:58:54 +02:00
|
|
|
}
|
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-05-07 16:51:24 +02:00
|
|
|
'title' => 'Restaurer',
|
2020-05-07 08:36:24 +02:00
|
|
|
'view' => 'manage'
|
2019-12-10 10:53:31 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-10-24 22:48:10 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
public function index() {
|
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
2020-08-14 17:32:21 +02:00
|
|
|
$success = true;
|
|
|
|
// Empêcher la modification si défini dans footer
|
2020-09-25 16:38:40 +02:00
|
|
|
if ( $this->getData(['theme','footer','displaySearch']) === true
|
|
|
|
AND $this->getInput('configSearchPageId') === 'none'
|
2020-08-14 17:32:21 +02:00
|
|
|
){
|
2020-11-21 15:09:10 +01:00
|
|
|
$searchPageId = $this->getData(['locale','searchPageId']);
|
2020-08-14 17:32:21 +02:00
|
|
|
self::$inputNotices['configSearchPageId'] = 'Désactiver l\'option dans le pied de page';
|
|
|
|
$success = false;
|
2020-05-07 08:36:24 +02:00
|
|
|
} else {
|
2020-08-14 17:32:21 +02:00
|
|
|
$searchPageId = $this->getInput('configSearchPageId');
|
|
|
|
}
|
|
|
|
// Empêcher la modification si défini dans footer
|
2020-09-25 16:38:40 +02:00
|
|
|
if ( $this->getData(['theme','footer','displayLegal']) === true
|
|
|
|
AND $this->getInput('configLegalPageId') === 'none'
|
2020-08-14 17:32:21 +02:00
|
|
|
){
|
2020-11-21 15:09:10 +01:00
|
|
|
$legalPageId = $this->getData(['locale','legalPageId']);
|
2020-08-14 17:32:21 +02:00
|
|
|
self::$inputNotices['configLegalPageId'] = 'Désactiver l\'option dans le pied de page';
|
|
|
|
$success = false;
|
|
|
|
} else {
|
|
|
|
$legalPageId = $this->getInput('configLegalPageId');
|
2020-05-07 08:36:24 +02:00
|
|
|
}
|
2020-06-04 13:57:50 +02:00
|
|
|
// Sauvegarder
|
2018-04-02 08:29:19 +02:00
|
|
|
$this->setData([
|
2020-11-21 15:09:10 +01:00
|
|
|
'locale',
|
2018-04-02 08:29:19 +02:00
|
|
|
[
|
2019-12-11 22:42:05 +01:00
|
|
|
'homePageId' => $this->getInput('configHomePageId', helper::FILTER_ID, true),
|
2020-08-13 09:47:58 +02:00
|
|
|
'page404' => $this->getInput('configPage404'),
|
2020-08-13 14:11:33 +02:00
|
|
|
'page403' => $this->getInput('configPage403'),
|
2020-09-12 09:52:30 +02:00
|
|
|
'page302' => $this->getInput('configPage302'),
|
2020-08-14 17:32:21 +02:00
|
|
|
'legalPageId' => $legalPageId,
|
|
|
|
'searchPageId' => $searchPageId,
|
2020-05-25 11:58:54 +02:00
|
|
|
'metaDescription' => $this->getInput('configMetaDescription', helper::FILTER_STRING_LONG, true),
|
2020-11-21 15:09:10 +01:00
|
|
|
'title' => $this->getInput('configTitle', helper::FILTER_STRING_SHORT, true)
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
// Générer robots.txt et sitemap
|
|
|
|
$this->generateFiles();
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(),
|
|
|
|
'notification' => 'Modifications enregistrées',
|
|
|
|
'state' => $success
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Initialisation du screen - APPEL AUTO DESACTIVE POUR EVITER UN RALENTISSEMENT
|
|
|
|
/*
|
|
|
|
if (!file_exists(self::FILE_DIR.'source/screenshot.jpg')) {
|
|
|
|
$this->configMetaImage();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Configuration',
|
|
|
|
'view' => 'index'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration avancée
|
|
|
|
*/
|
|
|
|
public function advanced() {
|
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
|
|
|
$success = true;
|
|
|
|
// Basculement en mise à jour auto
|
|
|
|
// Remise à 0 du compteur
|
|
|
|
if ($this->getData(['config','autoUpdate']) === false &&
|
|
|
|
$this->getInput('configAdvancedAutoUpdate', helper::FILTER_BOOLEAN) === true) {
|
|
|
|
$this->setData(['core','lastAutoUpdate',0]);
|
|
|
|
}
|
|
|
|
// Sauvegarder
|
|
|
|
$this->setData([
|
|
|
|
'config',
|
|
|
|
[
|
|
|
|
'analyticsId' => $this->getInput('configAdvancedAnalyticsId'),
|
|
|
|
'autoBackup' => $this->getInput('configAdvancedAutoBackup', helper::FILTER_BOOLEAN),
|
|
|
|
'maintenance' => $this->getInput('configAdvancedMaintenance', helper::FILTER_BOOLEAN),
|
|
|
|
'cookieConsent' => $this->getInput('configAdvancedCookieConsent', helper::FILTER_BOOLEAN),
|
|
|
|
'favicon' => $this->getInput('configAdvancedFavicon'),
|
|
|
|
'faviconDark' => $this->getInput('configAdvancedFaviconDark'),
|
|
|
|
'social' => [
|
|
|
|
'facebookId' => $this->getInput('configAdvancedSocialFacebookId'),
|
|
|
|
'linkedinId' => $this->getInput('configAdvancedSocialLinkedinId'),
|
|
|
|
'instagramId' => $this->getInput('configAdvancedSocialInstagramId'),
|
|
|
|
'pinterestId' => $this->getInput('configAdvancedSocialPinterestId'),
|
|
|
|
'twitterId' => $this->getInput('configAdvancedSocialTwitterId'),
|
|
|
|
'youtubeId' => $this->getInput('configAdvancedSocialYoutubeId'),
|
|
|
|
'youtubeUserId' => $this->getInput('configAdvancedSocialYoutubeUserId'),
|
|
|
|
'githubId' => $this->getInput('configAdvancedSocialGithubId')
|
|
|
|
],
|
|
|
|
'timezone' => $this->getInput('configAdvancedTimezone', helper::FILTER_STRING_SHORT, true),
|
|
|
|
'itemsperPage' => $this->getInput('configAdvancedItemsperPage', helper::FILTER_INT,true),
|
|
|
|
'autoUpdate' => $this->getInput('configAdvancedAutoUpdate', helper::FILTER_BOOLEAN),
|
|
|
|
'autoUpdateHtaccess' => $this->getInput('configAdvancedAutoUpdateHtaccess', helper::FILTER_BOOLEAN),
|
|
|
|
'proxyType' => $this->getInput('configAdvancedProxyType'),
|
|
|
|
'proxyUrl' => $this->getInput('configAdvancedProxyUrl'),
|
|
|
|
'proxyPort' => $this->getInput('configAdvancedProxyPort',helper::FILTER_INT),
|
|
|
|
'captchaStrong' => $this->getInput('configAdvancedCaptchaStrong',helper::FILTER_BOOLEAN),
|
2020-05-10 18:06:57 +02:00
|
|
|
'smtp' => [
|
2020-11-21 15:09:10 +01:00
|
|
|
'enable' => $this->getInput('configAdvancedSmtpEnable',helper::FILTER_BOOLEAN),
|
|
|
|
'host' => $this->getInput('configAdvancedSmtpHost',helper::FILTER_STRING_SHORT),
|
|
|
|
'port' => $this->getInput('configAdvancedSmtpPort',helper::FILTER_INT),
|
|
|
|
'auth' => $this->getInput('configAdvancedSmtpAuth',helper::FILTER_BOOLEAN),
|
|
|
|
'secure' => $this->getInput('configAdvancedSmtpSecure'),
|
|
|
|
'username' => $this->getInput('configAdvancedSmtpUsername',helper::FILTER_STRING_SHORT),
|
|
|
|
'password' =>helper::encrypt($this->getData(['config','smtp','username']),$this->getInput('configAdvancedSmtpPassword')),
|
|
|
|
'sender' => $this->getInput('configAdvancedSmtpSender',helper::FILTER_MAIL)
|
2020-05-28 19:03:31 +02:00
|
|
|
],
|
|
|
|
'connect' => [
|
2020-11-21 15:09:10 +01:00
|
|
|
'attempt' => $this->getInput('configAdvancedConnectAttempt',helper::FILTER_INT),
|
|
|
|
'timeout' => $this->getInput('configAdvancedConnectTimeout',helper::FILTER_INT),
|
|
|
|
'log' => $this->getInput('configAdvancedConnectLog',helper::FILTER_BOOLEAN),
|
|
|
|
'captcha' => $this->getInput('configAdvancedConnectCaptcha',helper::FILTER_BOOLEAN),
|
2020-05-10 18:06:57 +02:00
|
|
|
]
|
2018-04-02 08:29:19 +02:00
|
|
|
]
|
2020-05-07 08:36:24 +02:00
|
|
|
]);
|
2021-01-06 19:31:55 +01:00
|
|
|
// Efface les fichiers de backup lorsque l'option est désactivée
|
|
|
|
if ($this->getInput('configAdvancedFileBackup', helper::FILTER_BOOLEAN) === false) {
|
|
|
|
$path = realpath('site/data');
|
|
|
|
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $filename)
|
|
|
|
{
|
|
|
|
if (strpos($filename,'backup.json')) {
|
|
|
|
unlink($filename);
|
|
|
|
}
|
|
|
|
}
|
2021-01-07 09:48:53 +01:00
|
|
|
if (file_exists('site/data/.backup')) unlink('site/data/.backup');
|
|
|
|
} else {
|
|
|
|
touch('site/data/.backup');
|
2021-01-06 19:31:55 +01:00
|
|
|
}
|
|
|
|
// Notice
|
2018-04-02 08:29:19 +02:00
|
|
|
if(self::$inputNotices === []) {
|
|
|
|
// Active la réécriture d'URL
|
|
|
|
$rewrite = $this->getInput('rewrite', helper::FILTER_BOOLEAN);
|
|
|
|
if(
|
|
|
|
$rewrite
|
|
|
|
AND helper::checkRewrite() === false
|
|
|
|
) {
|
|
|
|
// Ajout des lignes dans le .htaccess
|
|
|
|
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
|
|
|
|
);
|
|
|
|
// Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection)
|
|
|
|
helper::$rewriteStatus = true;
|
|
|
|
}
|
|
|
|
// Désactive la réécriture d'URL
|
|
|
|
elseif(
|
|
|
|
$rewrite === false
|
|
|
|
AND helper::checkRewrite()
|
|
|
|
) {
|
|
|
|
// Suppression des lignes dans le .htaccess
|
|
|
|
$htaccess = explode('# URL rewriting', file_get_contents('.htaccess'));
|
|
|
|
file_put_contents('.htaccess', $htaccess[0] . '# URL rewriting');
|
|
|
|
// Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection)
|
|
|
|
helper::$rewriteStatus = false;
|
|
|
|
}
|
2020-05-07 08:36:24 +02:00
|
|
|
// Met à jour la baseUrl
|
|
|
|
$this->setData(['core', 'baseUrl', helper::baseUrl(true,false) ]);
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2019-05-02 13:21:48 +02:00
|
|
|
// Générer robots.txt et sitemap
|
|
|
|
$this->generateFiles();
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
2021-02-09 16:12:32 +01:00
|
|
|
$notification = $notification . 'Modifications enregistrées';
|
2018-04-02 08:29:19 +02:00
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(),
|
2021-02-09 16:12:32 +01:00
|
|
|
'notification' => $notification,
|
2020-08-14 17:32:21 +02:00
|
|
|
'state' => $success
|
2018-04-02 08:29:19 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-11-21 15:09:10 +01:00
|
|
|
'title' => 'Configuration avancée',
|
|
|
|
'view' => 'advanced'
|
2018-04-02 08:29:19 +02:00
|
|
|
]);
|
|
|
|
}
|
2021-02-09 16:12:32 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Installation de modules à partir d'un zip normalisé
|
|
|
|
* Affichage des modules installés
|
|
|
|
*/
|
|
|
|
public function modules() {
|
|
|
|
|
|
|
|
// Préparation du tableau des modules installés
|
|
|
|
// Liste des modules installés (répertoire de module/)
|
|
|
|
if ($dh = opendir( 'module/' )) {
|
|
|
|
$i=0;
|
|
|
|
while (($dirmodule = readdir($dh)) !== false) {
|
|
|
|
if( $dirmodule !== '.' && $dirmodule !== '..'){
|
|
|
|
self::$modInstal[$i][0] = $dirmodule;
|
|
|
|
self::$modInstal[$i][1] = page::$moduleNames[$dirmodule];
|
|
|
|
// Lecture de la version pour les modules officiels et distribués
|
2021-02-09 18:04:24 +01:00
|
|
|
$blogversion = blog::VERSION;
|
|
|
|
$formversion = form::VERSION;
|
|
|
|
$galleryversion = gallery::VERSION;
|
|
|
|
$newsversion = news::VERSION;
|
|
|
|
$redirectionversion = redirection::VERSION;
|
|
|
|
$searchversion = search::VERSION;
|
2021-02-09 16:12:32 +01:00
|
|
|
self::$str = $dirmodule.'version';
|
|
|
|
self::$modInstal[$i][2] = '?';
|
|
|
|
if( ${self::$str} !== null){
|
|
|
|
self::$modInstal[$i][2] = ${self::$str};
|
|
|
|
}
|
|
|
|
// Lecture de la version pour les modules non distribués
|
|
|
|
elseif($this->getData(['module', '_gestion_modules_' , $dirmodule, 'version' ]) !== null){
|
|
|
|
self::$modInstal[$i][2] = $this->getData(['module', '_gestion_modules_' , $dirmodule, 'version' ]);
|
|
|
|
}
|
|
|
|
self::$modInstal[$i][3] = 'non';
|
|
|
|
self::$modInstal[$i][4] = '';
|
|
|
|
self::$modInstal[$i][5] = '';
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dh);
|
|
|
|
}
|
|
|
|
// Module utilisé ?
|
|
|
|
$nb = count(self::$modInstal);
|
|
|
|
for ($i = 0; $i < $nb; $i++) {
|
|
|
|
foreach( $this->getData(['page']) as $keyPage=>$valuePage){
|
|
|
|
if( $valuePage['moduleId'] === self::$modInstal[$i][0]){
|
|
|
|
self::$modInstal[$i][3] = 'oui';
|
|
|
|
if(self::$modInstal[$i][4] !==''){
|
|
|
|
self::$modInstal[$i][4] = self::$modInstal[$i][4].'<br>'.$valuePage['title'];
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
self::$modInstal[$i][4] = $valuePage['title'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$modulesDistrib = array('blog', 'form', 'gallery', 'news', 'redirection', 'search');
|
|
|
|
if( self::$modInstal[$i][4] =='' && array_search( self::$modInstal[$i][0], $modulesDistrib ) === false
|
|
|
|
&& $this->getData(['module', '_gestion_modules_', self::$modInstal[$i][0], 'delete' ]) === true){
|
|
|
|
self::$modInstal[$i][5] = template::button('moduleDelete' . self::$modInstal[$i][0], [
|
|
|
|
'class' => 'moduleDelete buttonRed',
|
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/moduleDelete/' . self::$modInstal[$i][0] . '/' . $_SESSION['csrf'],
|
|
|
|
'value' => template::ico('cancel')
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retour du formulaire ?
|
|
|
|
if($this->isPost()) {
|
|
|
|
// Installation d'un module
|
|
|
|
$success = true;
|
|
|
|
$checkValidMaj = $this->getInput('configModulesCheck', helper::FILTER_BOOLEAN);
|
|
|
|
$zipFilename = $this->getInput('configModulesInstallation', helper::FILTER_STRING_SHORT);
|
|
|
|
if( $zipFilename !== ''){
|
|
|
|
$tempFolder = uniqid();
|
|
|
|
$zip = new ZipArchive();
|
|
|
|
if ($zip->open(self::FILE_DIR.'source/'.$zipFilename) === TRUE) {
|
|
|
|
$notification = 'Archive ouverte';
|
|
|
|
mkdir (self::TEMP_DIR . $tempFolder);
|
|
|
|
$zip->extractTo(self::TEMP_DIR . $tempFolder );
|
|
|
|
// Archive de module ?
|
|
|
|
$success = false;
|
|
|
|
$notification = 'Ce n\'est pas l\'archive d\'un module !';
|
|
|
|
$moduleDir = self::TEMP_DIR . $tempFolder . '/module';
|
|
|
|
$moduleName = '';
|
|
|
|
if ( is_dir( $moduleDir )) {
|
|
|
|
// Lire le nom du module
|
|
|
|
if ($dh = opendir( $moduleDir )) {
|
|
|
|
while (($file = readdir($dh)) !== false) {
|
|
|
|
$moduleName = $file;
|
|
|
|
}
|
|
|
|
closedir($dh);
|
|
|
|
}
|
|
|
|
// Module normalisé ?
|
|
|
|
if( is_file( $moduleDir.'/'.$moduleName.'/'.$moduleName.'.php' ) AND is_file( $moduleDir.'/'.$moduleName.'/view/index/index.php' ) ){
|
|
|
|
|
|
|
|
// Lecture de info.json et mémorisation des 3 paramètres version, update et delete
|
|
|
|
$version = '?';
|
|
|
|
$update = '?';
|
|
|
|
$delete = false;
|
|
|
|
if( is_file( $moduleDir.'/'.$moduleName.'/info/info.json' )){
|
|
|
|
$json = file_get_contents( $moduleDir.'/'.$moduleName.'/info/info.json' );
|
|
|
|
$param = json_decode( $json, true);
|
|
|
|
if( $param['module'] === $moduleName && is_bool($param['update']) && is_bool($param['update'])){
|
|
|
|
$version = $param['version'];
|
|
|
|
$update = $param['update'];
|
|
|
|
$delete = $param['delete'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->setData(['module','_gestion_modules_',$moduleName, 'version', $version]);
|
|
|
|
$this->setData(['module','_gestion_modules_',$moduleName, 'update', $update]);
|
|
|
|
$this->setData(['module','_gestion_modules_',$moduleName, 'delete', $delete]);
|
|
|
|
|
|
|
|
// Module déjà installé ?
|
|
|
|
$moduleInstal = false;
|
|
|
|
foreach( self::$modInstal as $key=>$value){
|
|
|
|
if($moduleName === $value[0]){
|
|
|
|
if( $value[3] !== 'non'){
|
|
|
|
$notification = 'Module déjà installé et utilisé page '.$value[4];
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$notification = 'Module déjà installé et non utilisé';
|
|
|
|
}
|
|
|
|
$moduleInstal = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$validMaj = $checkValidMaj;
|
|
|
|
if(is_bool($update)){
|
|
|
|
$validMaj = $checkValidMaj && $update;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nouvelle installation ou mise à jour du module avec validation du concepteur et validation de l'utilisateur
|
|
|
|
if( ! $moduleInstal || ( $moduleInstal && $validMaj )){
|
|
|
|
// Copie récursive des dossiers
|
|
|
|
$this -> custom_copy( self::TEMP_DIR . $tempFolder, './' );
|
|
|
|
$success = true;
|
|
|
|
if( ! $moduleInstal ){
|
|
|
|
$notification = 'Module '.$moduleName.' installé';
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$notification = 'Module '.$moduleName.' mis à jour';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$success = false;
|
|
|
|
$notification = ' Vous devez cocher la case "Valider la mise à jour d\'un module déjà installé"';
|
|
|
|
if( $update === false){
|
|
|
|
$notification = ' Mise à jour par ce procédé interdite par le concepteur du module';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Supprimer le dossier temporaire même si le module est invalide
|
|
|
|
$this->removeDir(self::TEMP_DIR . $tempFolder);
|
|
|
|
$zip->close();
|
|
|
|
} else {
|
|
|
|
// erreur à l'ouverture
|
|
|
|
$success = false;
|
|
|
|
$notification = 'Impossible d\'ouvrir l\'archive';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(),
|
|
|
|
'notification' => $notification,
|
|
|
|
'state' => $success
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Gestion des modules',
|
|
|
|
'view' => 'modules'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Effacement d'un module installé et non utilisé
|
|
|
|
*/
|
|
|
|
public function moduleDelete() {
|
|
|
|
|
|
|
|
// Jeton incorrect
|
|
|
|
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'config/modules',
|
|
|
|
'state' => false,
|
|
|
|
'notification' => 'Action non autorisée'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
// suppression de la clef version du module
|
|
|
|
$this->deleteData(['module', '_gestion_modules_', $this->getUrl(2)]);
|
|
|
|
// Suppression des dossiers
|
|
|
|
if( $this->delete_directory('./module/'.$this->getUrl(2)) === true){
|
|
|
|
$success = true;
|
|
|
|
$notification = 'Module '.$this->getUrl(2) .' effacé du dossier /module/, il peut rester des données dans d\'autres dossiers';
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$success = false;
|
|
|
|
$notification = 'La suppression a échouée';
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'config/modules',
|
|
|
|
'notification' => $notification,
|
|
|
|
'state' => $success
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 16:28:10 +02:00
|
|
|
public function script() {
|
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
|
|
|
// Ecrire les fichiers de script
|
2020-05-12 16:40:33 +02:00
|
|
|
if ($this->geturl(2) === 'head') {
|
2020-05-12 16:28:10 +02:00
|
|
|
file_put_contents(self::DATA_DIR . 'head.inc.html',$this->getInput('configScriptHead',null));
|
|
|
|
}
|
2020-05-12 16:40:33 +02:00
|
|
|
if ($this->geturl(2) === 'body') {
|
2020-05-25 11:58:54 +02:00
|
|
|
file_put_contents(self::DATA_DIR . 'body.inc.html',$this->getInput('configScriptBody',null));
|
|
|
|
}
|
2020-05-12 16:28:10 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => 'Modifications enregistrées',
|
|
|
|
'redirect' => helper::baseUrl() . 'config/script/'. $this->geturl(2),
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Éditeur de script dans ' . ucfirst($this->geturl(2)) ,
|
|
|
|
'vendor' => [
|
|
|
|
'codemirror'
|
|
|
|
],
|
|
|
|
'view' => 'script'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-05-09 09:23:29 +02:00
|
|
|
/**
|
2020-06-02 18:49:24 +02:00
|
|
|
* Met à jour les données de site avec l'adresse transmise
|
2020-05-09 09:23:29 +02:00
|
|
|
*/
|
2020-05-25 11:58:54 +02:00
|
|
|
public function updateBaseUrl () {
|
2020-05-09 09:23:29 +02:00
|
|
|
// Supprimer l'information de redirection
|
|
|
|
$old = str_replace('?','',$this->getData(['core', 'baseUrl']));
|
|
|
|
$new = helper::baseUrl(false,false);
|
|
|
|
$c3 = 0;
|
|
|
|
$success = false ;
|
2020-05-25 11:58:54 +02:00
|
|
|
// Boucler sur les pages
|
2020-05-09 09:23:29 +02:00
|
|
|
foreach($this->getHierarchy(null,null,null) as $parentId => $childIds) {
|
|
|
|
$content = $this->getData(['page',$parentId,'content']);
|
2020-05-25 11:58:54 +02:00
|
|
|
$replace = str_replace( 'href="' . $old , 'href="'. $new , stripslashes($content),$c1) ;
|
|
|
|
$replace = str_replace( 'src="' . $old , 'src="'. $new , stripslashes($replace),$c2) ;
|
2020-05-07 15:59:23 +02:00
|
|
|
|
2020-05-09 09:23:29 +02:00
|
|
|
if ($c1 > 0 || $c2 > 0) {
|
|
|
|
$success = true;
|
|
|
|
$this->setData(['page',$parentId,'content', $replace ]);
|
|
|
|
$c3 += $c1 + $c2;
|
|
|
|
}
|
|
|
|
foreach($childIds as $childId) {
|
|
|
|
$content = $this->getData(['page',$childId,'content']);
|
2020-05-25 11:58:54 +02:00
|
|
|
$replace = str_replace( 'href="' . $old , 'href="'. $new , stripslashes($content),$c1) ;
|
|
|
|
$replace = str_replace( 'src="' . $old , 'src="'. $new , stripslashes($replace),$c2) ;
|
2020-05-07 15:07:26 +02:00
|
|
|
if ($c1 > 0 || $c2 > 0) {
|
2019-12-25 11:09:08 +01:00
|
|
|
$success = true;
|
2020-05-09 09:23:29 +02:00
|
|
|
$this->setData(['page',$childId,'content', $replace ]);
|
2020-05-07 15:59:23 +02:00
|
|
|
$c3 += $c1 + $c2;
|
2020-05-07 08:36:24 +02:00
|
|
|
}
|
2020-05-09 09:23:29 +02:00
|
|
|
}
|
2020-05-25 11:58:54 +02:00
|
|
|
}
|
2020-05-09 09:23:29 +02:00
|
|
|
// Traiter les modules dont la redirection
|
|
|
|
$content = $this->getdata(['module']);
|
|
|
|
$replace = $this->recursive_array_replace('href="' . $old , 'href="'. $new, $content, $c1);
|
|
|
|
$replace = $this->recursive_array_replace('src="' . $old , 'src="'. $new, $replace, $c2);
|
|
|
|
if ($content !== $replace) {
|
2020-05-25 11:58:54 +02:00
|
|
|
$this->setdata(['module',$replace]);
|
2020-05-09 09:23:29 +02:00
|
|
|
$c3 += $c1 + $c2;
|
|
|
|
$success = true;
|
|
|
|
}
|
|
|
|
// Mettre à jour la base URl
|
|
|
|
$this->setData(['core','baseUrl',helper::baseUrl(true,false)]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => $success ? $c3. ' conversion' . ($c3 > 1 ? 's' : '') . ' effectuée' . ($c3 > 1 ? 's' : '') : 'Aucune conversion',
|
|
|
|
'redirect' => helper::baseUrl() . 'config/manage',
|
|
|
|
'state' => $success ? true : false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-05-30 12:04:45 +02:00
|
|
|
/**
|
|
|
|
* Vider le fichier de log
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function logReset() {
|
2020-05-31 19:08:19 +02:00
|
|
|
if ( file_exists(self::DATA_DIR . 'journal.log') ) {
|
|
|
|
unlink(self::DATA_DIR . 'journal.log');
|
2020-06-03 10:06:11 +02:00
|
|
|
// Créer les en-têtes des journaux
|
2020-06-27 16:21:22 +02:00
|
|
|
$d = 'Date;Heure;IP;Id;Action' . PHP_EOL;
|
2020-06-03 10:06:11 +02:00
|
|
|
file_put_contents(self::DATA_DIR . 'journal.log',$d);
|
2020-05-31 19:08:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-11-25 14:31:43 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/advanced',
|
2020-05-31 19:08:19 +02:00
|
|
|
'notification' => 'Journal réinitialisé avec succès',
|
|
|
|
'state' => true
|
|
|
|
]);
|
2020-06-02 18:49:24 +02:00
|
|
|
} else {
|
2020-05-31 19:08:19 +02:00
|
|
|
// Valeurs en sortie
|
2020-05-30 12:04:45 +02:00
|
|
|
$this->addOutput([
|
2020-11-25 14:31:43 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/advanced',
|
2020-06-03 10:06:11 +02:00
|
|
|
'notification' => 'Aucun journal à effacer',
|
2020-05-31 19:08:19 +02:00
|
|
|
'state' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-05-30 12:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Télécharger le fichier de log
|
|
|
|
*/
|
|
|
|
public function logDownload() {
|
|
|
|
$fileName = self::DATA_DIR . 'journal.log';
|
2020-06-03 10:06:11 +02:00
|
|
|
if (file_exists($fileName)) {
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
|
|
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
|
|
|
header('Content-Length: ' . filesize($fileName));
|
|
|
|
readfile( $fileName);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_RAW
|
|
|
|
]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Configuration',
|
|
|
|
'view' => 'index'
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-11-25 14:31:43 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/advanced',
|
2020-06-03 10:06:11 +02:00
|
|
|
'notification' => 'Aucun fichier journal à télécharger',
|
|
|
|
'state' => false
|
|
|
|
]);
|
|
|
|
}
|
2020-05-31 19:08:19 +02:00
|
|
|
}
|
2020-05-30 12:04:45 +02:00
|
|
|
|
2020-05-31 19:08:19 +02:00
|
|
|
/**
|
|
|
|
* Tableau des IP blacklistés
|
|
|
|
*/
|
|
|
|
public function blacklistDownload () {
|
|
|
|
$fileName = self::TEMP_DIR . 'blacklist.log';
|
2020-06-03 10:06:11 +02:00
|
|
|
$d = 'Date dernière tentative;Heure dernière tentative;Id;Adresse IP;Nombre d\'échecs' . PHP_EOL;
|
|
|
|
file_put_contents($fileName,$d);
|
|
|
|
if ( file_exists($fileName) ) {
|
|
|
|
$d = $this->getData(['blacklist']);
|
|
|
|
$data = '';
|
|
|
|
foreach ($d as $key => $item) {
|
2020-11-01 13:38:25 +01:00
|
|
|
$data .= mb_detect_encoding(strftime('%d/%m/%y',$item['lastFail']), 'UTF-8', true)
|
|
|
|
? strftime('%d/%m/%y',$item['lastFail']) . ';' . utf8_encode(strftime('%R',$item['lastFail'])) . ';'
|
|
|
|
: utf8_encode(strftime('%d/%m/%y',$item['lastFail'])) . ';' . utf8_encode(strftime('%R',$item['lastFail'])) . ';' ;
|
2020-06-03 10:06:11 +02:00
|
|
|
$data .= $key . ';' . $item['ip'] . ';' . $item['connectFail'] . PHP_EOL;
|
|
|
|
}
|
|
|
|
file_put_contents($fileName,$data,FILE_APPEND);
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
|
|
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
|
|
|
header('Content-Length: ' . filesize($fileName));
|
|
|
|
readfile( $fileName);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_RAW
|
|
|
|
]);
|
|
|
|
unlink(self::TEMP_DIR . 'blacklist.log');
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Configuration',
|
|
|
|
'view' => 'index'
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-11-25 14:31:43 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/advanced',
|
2020-06-03 10:06:11 +02:00
|
|
|
'notification' => 'Aucune liste noire à télécharger',
|
|
|
|
'state' => false
|
|
|
|
]);
|
|
|
|
}
|
2020-05-30 12:04:45 +02:00
|
|
|
}
|
|
|
|
|
2020-05-31 19:08:19 +02:00
|
|
|
/**
|
|
|
|
* Réinitialiser les ip blacklistées
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function blacklistReset() {
|
|
|
|
if ( file_exists(self::DATA_DIR . 'blacklist.json') ) {
|
2020-11-25 14:31:43 +01:00
|
|
|
$this->setData(['blacklist',[]]);
|
2020-05-31 19:08:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-11-25 14:31:43 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/advanced',
|
2020-05-31 19:08:19 +02:00
|
|
|
'notification' => 'Liste noire réinitialisée avec succès',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-11-25 14:31:43 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/advanced',
|
2020-05-31 19:08:19 +02:00
|
|
|
'notification' => 'Pas de liste à effacer',
|
|
|
|
'state' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 12:04:45 +02:00
|
|
|
|
2020-05-09 12:52:29 +02:00
|
|
|
/**
|
|
|
|
* Fonction de parcours des données de module
|
|
|
|
* @param string $find donnée à rechercher
|
|
|
|
* @param string $replace donnée à remplacer
|
|
|
|
* @param array tableau à analyser
|
2020-06-02 18:49:24 +02:00
|
|
|
* @param int count nombres d'occurrences
|
2020-05-09 12:52:29 +02:00
|
|
|
* @return array avec les valeurs remplacées.
|
|
|
|
*/
|
2020-05-25 11:58:54 +02:00
|
|
|
private function recursive_array_replace ($find, $replace, $array, &$count) {
|
2020-05-09 09:23:29 +02:00
|
|
|
if (!is_array($array)) {
|
2020-05-25 11:58:54 +02:00
|
|
|
return str_replace($find, $replace, $array, $count);
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2020-05-25 11:58:54 +02:00
|
|
|
|
2020-05-09 09:23:29 +02:00
|
|
|
$newArray = [];
|
|
|
|
foreach ($array as $key => $value) {
|
2020-05-25 11:58:54 +02:00
|
|
|
$newArray[$key] = $this->recursive_array_replace($find, $replace, $value,$c);
|
2020-05-09 09:23:29 +02:00
|
|
|
$count += $c;
|
|
|
|
}
|
|
|
|
return $newArray;
|
|
|
|
}
|
2021-02-09 16:12:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copie récursive de dossiers
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private function custom_copy($src, $dst) {
|
|
|
|
// open the source directory
|
|
|
|
$dir = opendir($src);
|
|
|
|
// Make the destination directory if not exist
|
|
|
|
@mkdir($dst);
|
|
|
|
// Loop through the files in source directory
|
|
|
|
while( $file = readdir($dir) ) {
|
|
|
|
if (( $file != '.' ) && ( $file != '..' )) {
|
|
|
|
if ( is_dir($src . '/' . $file) ){
|
|
|
|
// Recursively calling custom copy function
|
|
|
|
// for sub directory
|
|
|
|
$this -> custom_copy($src . '/' . $file, $dst . '/' . $file);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy($src . '/' . $file, $dst . '/' . $file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Suppression d'un dossier et de ses sous-dossiers
|
|
|
|
*/
|
|
|
|
private function delete_directory($directory, $empty = false) {
|
|
|
|
if(substr($directory,-1) == "/") {
|
|
|
|
$directory = substr($directory,0,-1);
|
|
|
|
}
|
|
|
|
if(!file_exists($directory) || !is_dir($directory)) {
|
|
|
|
return false;
|
|
|
|
} elseif(!is_readable($directory)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$directoryHandle = opendir($directory);
|
|
|
|
while ($contents = readdir($directoryHandle)) {
|
|
|
|
if($contents != '.' && $contents != '..') {
|
|
|
|
$path = $directory . "/" . $contents;
|
|
|
|
if(is_dir($path)) {
|
|
|
|
$this->delete_directory($path);
|
|
|
|
} else {
|
|
|
|
unlink($path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($directoryHandle);
|
|
|
|
if($empty == false) {
|
|
|
|
if(!rmdir($directory)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-05-07 08:36:24 +02:00
|
|
|
|
2020-05-09 12:52:29 +02:00
|
|
|
}
|