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 >
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
*/
class config extends common {
public static $actions = [
'backup' => self :: GROUP_ADMIN ,
2021-06-04 13:00:35 +02:00
'copyBackups' => 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 ,
2019-12-10 10:53:31 +01:00
'index' => self :: GROUP_ADMIN ,
2021-06-04 13:00:35 +02:00
'restore' => 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-06-04 13:00:35 +02:00
'blacklistDownload' => self :: GROUP_ADMIN ,
2018-04-02 08:29:19 +02:00
];
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'
];
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
];
2021-10-11 17:07:09 +02:00
// Anonymisation des IP du journal
public static $anonIP = [
2021-10-11 17:53:41 +02:00
4 => 'Non tronquées' ,
3 => 'Niveau 1 (192.168.12.x)' ,
2021-10-11 17:07:09 +02:00
2 => 'Niveau 2 (192.168.x.x)' ,
2021-10-11 17:53:41 +02:00
1 => 'Niveau 3 (192.x.x.x)' ,
2021-10-11 17:07:09 +02:00
];
2021-11-12 18:22:06 +01:00
public static $captchaTypes = [
'num' => 'Chiffres' ,
'alpha' => 'Lettres'
];
2021-10-11 17:07:09 +02:00
2021-10-01 15:53:38 +02:00
// Langue traduite courante
public static $i18nSite = 'fr' ;
2020-06-04 18:34:39 +02:00
2021-10-06 18:00:59 +02:00
// Variable pour construire la liste des pages du site
2021-10-06 18:18:41 +02:00
public static $pagesList = [];
public static $orphansList = [];
2022-01-05 18:13:25 +01:00
public static $onlineVersion = '' ;
public static $updateButtonText = 'Réinstaller' ;
2021-10-06 18:00:59 +02:00
2020-06-04 18:34:39 +02:00
/**
* Génére les fichiers pour les crawlers
2021-03-11 14:57:10 +01:00
* Sitemap compressé et non compressé
* Robots . txt
2020-06-04 18:34:39 +02:00
*/
2019-05-02 13:21:48 +02:00
public function generateFiles () {
2021-03-11 14:57:10 +01:00
2019-05-02 13:21:48 +02:00
// Mettre à jour le site map
2019-12-10 10:53:31 +01:00
$successSitemap = $this -> createSitemap ();
2019-05-02 13:21:48 +02:00
// Valeurs en sortie
$this -> addOutput ([
2021-12-02 14:52:43 +01:00
/* 'title' => 'Configuration' ,
'view' => 'index' , */
'redirect' => helper :: baseUrl () . 'config' ,
2021-08-10 22:59:29 +02:00
'notification' => $successSitemap ? 'Mises à jour des fichiers sitemap et robots.txt' : 'Echec d\'écriture, le site map n\'a pas été mis à jour' ,
2021-09-14 20:54:31 +02:00
'state' => $successSitemap
2019-05-02 13:21:48 +02:00
]);
}
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' )) {
2021-09-29 14:50:25 +02:00
mkdir ( self :: FILE_DIR . 'source/backup' , 0755 );
2020-08-08 17:06:06 +02:00
}
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 ;
2022-02-10 14:43:00 +01:00
$googlePagespeedData = helper :: getUrlContents ( '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 ));
2021-02-16 09:44:04 +01:00
// Effacer l'image et la miniature png
if ( file_exists ( self :: FILE_DIR . 'thumb/screenshot.jpg' )) {
unlink ( self :: FILE_DIR . 'thumb/screenshot.jpg' );
}
if ( file_exists ( self :: FILE_DIR . 'source/screenshot.jpg' )) {
unlink ( self :: FILE_DIR . 'source/screenshot.jpg' );
2019-06-20 18:58:49 +02:00
}
2021-02-16 09:44:04 +01:00
$success = file_put_contents ( self :: FILE_DIR . 'source/screenshot.jpg' , $img ) ;
2019-06-18 10:13:09 +02:00
}
2018-10-24 22:48:10 +02:00
// Valeurs en sortie
$this -> addOutput ([
2021-12-02 14:52:43 +01:00
/* 'title' => 'Configuration' ,
'view' => 'index' , */
'redirect' => helper :: baseUrl () . 'config' ,
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' ,
'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
*/
2021-06-04 13:00:35 +02:00
public function restore () {
2019-12-10 10:53:31 +01:00
// Soumission du formulaire
2021-11-15 21:44:12 +01:00
if ( $this -> isPost () ) {
2021-11-21 17:16:47 +01:00
2021-11-15 21:44:12 +01:00
$success = false ;
if ( $this -> getInput ( 'configRestoreImportFile' , null , true ) ) {
$fileZip = $this -> getInput ( 'configRestoreImportFile' );
$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 ([
2021-12-01 18:25:50 +01:00
'title' => 'Restaurer' ,
'view' => 'restore' ,
2021-11-15 21:44:12 +01:00
'notification' => 'Le fichier n\'est pas une archive valide' ,
'state' => false
]);
}
$successOpen = $zip -> open ( self :: FILE_DIR . 'source/' . $fileZip );
if ( $successOpen === FALSE ) {
// Valeurs en sortie erreur
$this -> addOutput ([
2021-12-01 18:25:50 +01:00
'title' => 'Restaurer' ,
'view' => 'restore' ,
2021-11-15 21:44:12 +01:00
'notification' => 'Impossible de lire l\'archive' ,
'state' => false
]);
}
// Lire le contenu de l'archive dans le tableau files
for ( $i = 0 ; $i < $zip -> numFiles ; $i ++ ){
$stat = $zip -> statIndex ( $i );
$files [] = ( basename ( $stat [ 'name' ] ));
}
2020-05-25 11:58:54 +02:00
2021-11-15 21:44:12 +01:00
// Lire la dataversion
$tmpDir = uniqid ( 4 );
$success = $zip -> extractTo ( self :: TEMP_DIR . $tmpDir );
$data = file_get_contents ( self :: TEMP_DIR . $tmpDir . '/data/core.json' );
$obj = json_decode ( $data );
$dataVersion = strval ( $obj -> core -> dataVersion );
switch ( strlen ( $dataVersion )) {
case 4 :
if ( substr ( $dataVersion , 0 , 1 ) === '9' ) {
$version = 9 ;
} else {
$version = 0 ;
}
break ;
case 5 :
$version = substr ( $dataVersion , 0 , 2 );
break ;
default :
2021-09-14 20:54:31 +02:00
$version = 0 ;
2021-11-15 21:44:12 +01:00
break ;
}
$this -> removeDir ( self :: TEMP_DIR . $tmpDir );
2019-12-10 10:53:31 +01:00
2021-11-15 21:44:12 +01:00
if ( $version >= 10 ) {
// Option active, les users sont stockées
if ( $this -> getInput ( 'configRestoreImportUser' , helper :: FILTER_BOOLEAN ) === true ) {
$users = $this -> getData ([ 'user' ]);
}
} elseif ( $version === 0 ) { // Version invalide
// Valeurs en sortie erreur
$this -> addOutput ([
2021-12-01 18:25:50 +01:00
'title' => 'Restaurer' ,
'view' => 'restore' ,
2021-11-15 21:44:12 +01:00
'notification' => 'Cette archive n\'est pas une sauvegarde valide' ,
'state' => false
]);
2021-09-14 20:54:31 +02:00
}
2021-11-15 21:44:12 +01:00
// Préserver les comptes des utilisateurs d'une version 9 si option cochée
// Positionnement d'une variable de session lue au constructeurs
if ( $version === 9 ) {
$_SESSION [ 'KEEP_USERS' ] = $this -> getInput ( 'configRestoreImportUser' , helper :: FILTER_BOOLEAN );
}
// Extraire le zip ou 'site/'
$this -> removeDir ( self :: DATA_DIR );
$success = $zip -> extractTo ( 'site/' );
// Fermer l'archive
$zip -> close ();
2020-05-25 11:58:54 +02:00
2021-09-14 20:54:31 +02:00
2021-11-15 21:44:12 +01:00
// Restaurer les users originaux d'une v10 si option cochée
if ( ! empty ( $users ) &&
$version >= 10 &&
$this -> getInput ( 'configRestoreImportUser' , helper :: FILTER_BOOLEAN ) === true ) {
$this -> setData ([ 'user' , $users ]);
}
2020-05-07 08:36:24 +02:00
}
2019-12-10 10:53:31 +01:00
// Message de notification
2021-12-01 18:25:50 +01:00
$notification = $success === true ? 'Restaurer effectuée avec succès' : 'Erreur inconnue' ;
2021-06-04 13:00:35 +02:00
$redirect = $this -> getInput ( 'configRestoreImportUser' , helper :: FILTER_BOOLEAN ) === true ? helper :: baseUrl () . 'config/restore' : 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 ([
2021-12-02 14:52:43 +01:00
/* 'title' => 'Restaurer' ,
'view' => 'restore' , */
'redirect' => $redirect ,
2019-12-10 10:53:31 +01:00
'notification' => $notification ,
'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' ,
2021-06-04 13:00:35 +02:00
'view' => 'restore'
2019-12-10 10:53:31 +01:00
]);
}
2021-10-30 12:48:29 +02:00
/**
* Configuration
2021-10-29 16:14:51 +02:00
*/
public function index () {
// Soumission du formulaire
if ( $this -> isPost ()) {
2021-10-30 12:48:29 +02:00
// Basculement en mise à jour auto, remise à 0 du compteur
2021-10-29 16:14:51 +02:00
if ( $this -> getData ([ 'config' , 'autoUpdate' ]) === false &&
2021-10-30 12:48:29 +02:00
$this -> getInput ( 'configAutoUpdate' , helper :: FILTER_BOOLEAN ) === true ) {
2021-10-29 16:14:51 +02:00
$this -> setData ([ 'core' , 'lastAutoUpdate' , 0 ]);
}
2021-10-30 12:48:29 +02:00
2021-10-29 16:14:51 +02:00
// Eviter déconnexion automatique après son activation
2021-10-30 18:48:33 +02:00
if ( $this -> getData ([ 'config' , 'connect' , 'autoDisconnect' ]) === false
2021-10-30 12:48:29 +02:00
AND $this -> getInput ( 'configAutoDisconnect' , helper :: FILTER_BOOLEAN ) === true ) {
2021-10-29 16:14:51 +02:00
$this -> setData ([ 'user' , $this -> getuser ( 'id' ), 'accessCsrf' , $_SESSION [ 'csrf' ]]);
}
2021-10-30 12:48:29 +02:00
// Répercuter la suppression de la page dans la configuration du footer
if ( $this -> getData ([ 'theme' , 'footer' , 'displaySearch' ]) === true
AND $this -> getInput ( 'configSearchPageId' ) === 'none'
){
$this -> setData ([ 'theme' , 'footer' , 'displaySearch' , false ]);
}
if ( $this -> getData ([ 'theme' , 'footer' , 'displayLegal' ]) === true
AND $this -> getInput ( 'configLegalPageId' ) === 'none'
){
$this -> setData ([ 'theme' , 'footer' , 'displayLegal' , false ]);
}
2021-11-21 17:16:47 +01:00
2021-10-30 12:48:29 +02:00
// Sauvegarder les locales
$this -> setData ([
'locale' ,
[
2021-10-30 18:36:43 +02:00
'homePageId' => $this -> getInput ( 'localeHomePageId' , helper :: FILTER_ID , true ),
'page404' => $this -> getInput ( 'localePage404' ),
'page403' => $this -> getInput ( 'localePage403' ),
'page302' => $this -> getInput ( 'localePage302' ),
'legalPageId' => $this -> getInput ( 'localeLegalPageId' ),
'searchPageId' => $this -> getInput ( 'localeSearchPageId' ),
'searchPageLabel' => empty ( $this -> getInput ( 'localeSearchPageLabel' , helper :: FILTER_STRING_SHORT )) ? 'Rechercher' : $this -> getInput ( 'localeSearchPageLabel' , helper :: FILTER_STRING_SHORT ),
'legalPageLabel' => empty ( $this -> getInput ( 'localeLegalPageLabel' , helper :: FILTER_STRING_SHORT )) ? 'Mentions légales' : $this -> getInput ( 'localeLegalPageLabel' , helper :: FILTER_STRING_SHORT ),
'sitemapPageLabel' => empty ( $this -> getInput ( 'localeSitemapPageLabel' , helper :: FILTER_STRING_SHORT )) ? 'Plan du site' : $this -> getInput ( 'localeSitemapPageLabel' , helper :: FILTER_STRING_SHORT ),
'metaDescription' => $this -> getInput ( 'localeMetaDescription' , helper :: FILTER_STRING_LONG , true ),
2021-11-27 16:20:25 +01:00
'title' => $this -> getInput ( 'localeTitle' , helper :: FILTER_STRING_SHORT , true ),
'cookies' => [
// Les champs sont obligatoires si l'option consentement des cookies est active
2022-01-24 16:53:04 +01:00
'mainLabel' => $this -> getInput ( 'localeCookiesZwiiText' , helper :: FILTER_STRING_LONG , $this -> getData ([ 'config' , 'cookieConsent' , helper :: FILTER_BOOLEAN ])),
'gaLabel' => $this -> getInput ( 'localeCookiesGaText' , helper :: FILTER_STRING_LONG , $this -> getData ([ 'config' , 'cookieConsent' , helper :: FILTER_BOOLEAN ])),
'titleLabel' => $this -> getInput ( 'localeCookiesTitleText' , helper :: FILTER_STRING_SHORT , $this -> getData ([ 'config' , 'cookieConsent' , helper :: FILTER_BOOLEAN ])),
'linkLegalLabel' => $this -> getInput ( 'localeCookiesLinkMlText' , helper :: FILTER_STRING_SHORT , $this -> getData ([ 'config' , 'cookieConsent' , helper :: FILTER_BOOLEAN ])),
'checkboxGaLabel' => $this -> getInput ( 'localeCookiesCheckboxGaText' , helper :: FILTER_STRING_SHORT , $this -> getData ([ 'config' , 'cookieConsent' , helper :: FILTER_BOOLEAN ])),
'cookiesFooterText' => $this -> getInput ( 'localeCookiesFooterText' , helper :: FILTER_STRING_SHORT , $this -> getData ([ 'config' , 'cookieConsent' , helper :: FILTER_BOOLEAN ])),
'buttonValidLabel' => $this -> getInput ( 'localeCookiesButtonText' , helper :: FILTER_STRING_SHORT , $this -> getData ([ 'config' , 'cookieConsent' , helper :: FILTER_BOOLEAN ]))
2021-11-27 16:20:25 +01:00
]
2021-10-30 12:48:29 +02:00
]
]);
2021-10-29 19:25:17 +02:00
2021-10-30 12:48:29 +02:00
// Sauvegarder la configuration
$this -> setData ([
'config' ,
[
'favicon' => $this -> getInput ( 'configFavicon' ),
'faviconDark' => $this -> getInput ( 'configFaviconDark' ),
2021-10-30 18:36:43 +02:00
'timezone' => $this -> getInput ( 'configTimezone' , helper :: FILTER_STRING_SHORT , true ),
2021-10-30 18:12:34 +02:00
'autoUpdate' => $this -> getInput ( 'configAutoUpdate' , helper :: FILTER_BOOLEAN ),
'autoUpdateHtaccess' => $this -> getInput ( 'configAutoUpdateHtaccess' , helper :: FILTER_BOOLEAN ),
2021-10-30 18:36:43 +02:00
'autoBackup' => $this -> getInput ( 'configAutoBackup' , helper :: FILTER_BOOLEAN ),
'maintenance' => $this -> getInput ( 'configMaintenance' , helper :: FILTER_BOOLEAN ),
2021-11-27 16:20:25 +01:00
'cookieConsent' => $this -> getInput ( 'configCookieConsent' , helper :: FILTER_BOOLEAN ),
2021-10-30 18:12:34 +02:00
'proxyType' => $this -> getInput ( 'configProxyType' ),
'proxyUrl' => $this -> getInput ( 'configProxyUrl' ),
'proxyPort' => $this -> getInput ( 'configProxyPort' , helper :: FILTER_INT ),
2021-10-30 12:48:29 +02:00
'social' => [
2021-10-30 18:59:58 +02:00
'facebookId' => $this -> getInput ( 'socialFacebookId' ),
'linkedinId' => $this -> getInput ( 'socialLinkedinId' ),
'instagramId' => $this -> getInput ( 'socialInstagramId' ),
'pinterestId' => $this -> getInput ( 'socialPinterestId' ),
'twitterId' => $this -> getInput ( 'socialTwitterId' ),
'youtubeId' => $this -> getInput ( 'socialYoutubeId' ),
'youtubeUserId' => $this -> getInput ( 'socialYoutubeUserId' ),
'githubId' => $this -> getInput ( 'socialGithubId' )
2021-10-30 12:48:29 +02:00
],
'smtp' => [
2021-10-30 18:59:58 +02:00
'enable' => $this -> getInput ( 'smtpEnable' , helper :: FILTER_BOOLEAN ),
2021-12-12 19:52:23 +01:00
'host' => $this -> getInput ( 'smtpHost' , helper :: FILTER_STRING_SHORT , $this -> getInput ( 'smtpEnable' , helper :: FILTER_BOOLEAN )),
'port' => $this -> getInput ( 'smtpPort' , helper :: FILTER_INT , $this -> getInput ( 'smtpEnable' , helper :: FILTER_BOOLEAN )),
2021-10-30 18:59:58 +02:00
'auth' => $this -> getInput ( 'smtpAuth' , helper :: FILTER_BOOLEAN ),
2021-12-12 19:52:23 +01:00
'secure' => $this -> getInput ( 'smtpSecure' , helper :: FILTER_BOOLEAN ),
'username' => $this -> getInput ( 'smtpUsername' , helper :: FILTER_STRING_SHORT , $this -> getInput ( 'smtpAuth' , helper :: FILTER_BOOLEAN )),
2021-12-13 13:30:20 +01:00
'password' => helper :: encrypt ( $this -> getData ([ 'config' , 'smtp' , 'username' ]), $this -> getInput ( 'smtpPassword' , null , $this -> getInput ( 'smtpAuth' , helper :: FILTER_BOOLEAN ))),
2021-10-30 18:59:58 +02:00
'sender' => $this -> getInput ( 'smtpSender' , helper :: FILTER_MAIL )
2021-10-30 12:48:29 +02:00
],
'seo' => [
2021-10-30 18:59:58 +02:00
'robots' => $this -> getInput ( 'seoRobots' , helper :: FILTER_BOOLEAN ),
'analyticsId' => $this -> getInput ( 'seoAnalyticsId' )
2021-10-30 12:48:29 +02:00
],
2021-10-30 18:59:58 +02:00
'connect' => [
'attempt' => $this -> getInput ( 'connectAttempt' , helper :: FILTER_INT ),
'timeout' => $this -> getInput ( 'connectTimeout' , helper :: FILTER_INT ),
'log' => $this -> getInput ( 'connectLog' , helper :: FILTER_BOOLEAN ),
'anonymousIp' => $this -> getInput ( 'connectAnonymousIp' , helper :: FILTER_INT ),
'captcha' => $this -> getInput ( 'connectCaptcha' , helper :: FILTER_BOOLEAN ),
'captchaStrong' => $this -> getInput ( 'connectCaptchaStrong' , helper :: FILTER_BOOLEAN ),
'autoDisconnect' => $this -> getInput ( 'connectAutoDisconnect' , helper :: FILTER_BOOLEAN ),
2021-12-17 18:18:24 +01:00
'captchaType' => $this -> getInput ( 'connectCaptchaType' ),
2021-12-19 15:51:41 +01:00
'showPassword' => $this -> getInput ( 'connectShowPassword' , helper :: FILTER_BOOLEAN )
2021-10-30 12:48:29 +02:00
],
'i18n' => [
2021-10-31 16:18:49 +01:00
'enable' => $this -> getInput ( 'localei18n' , helper :: FILTER_BOOLEAN ),
'scriptGoogle' => $this -> getData ([ 'config' , 'i18n' , 'scriptGoogle' ]),
'showCredits' => $this -> getData ([ 'config' , 'i18n' , 'showCredits' ]),
'autoDetect' => $this -> getData ([ 'config' , 'i18n' , 'autoDetect' ]),
2021-12-03 17:43:28 +01:00
//'admin' => $this->getData(['config', 'i18n', 'admin']),
2021-10-31 16:18:49 +01:00
'fr' => $this -> getData ([ 'config' , 'i18n' , 'fr' ]),
'de' => $this -> getData ([ 'config' , 'i18n' , 'de' ]),
'en' => $this -> getData ([ 'config' , 'i18n' , 'en' ]),
'es' => $this -> getData ([ 'config' , 'i18n' , 'es' ]),
'it' => $this -> getData ([ 'config' , 'i18n' , 'it' ]),
'nl' => $this -> getData ([ 'config' , 'i18n' , 'nl' ]),
'pt' => $this -> getData ([ 'config' , 'i18n' , 'pt' ])
2021-10-30 12:48:29 +02:00
]
]
]);
2021-10-30 18:36:43 +02:00
2021-10-29 16:14:51 +02:00
// Efface les fichiers de backup lorsque l'option est désactivée
2021-10-30 12:48:29 +02:00
if ( $this -> getInput ( 'configFileBackup' , helper :: FILTER_BOOLEAN ) === false ) {
2021-10-29 16:14:51 +02:00
$path = realpath ( 'site/data' );
foreach ( new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $path )) as $filename )
{
if ( strpos ( $filename , 'backup.json' )) {
unlink ( $filename );
}
}
if ( file_exists ( 'site/data/.backup' )) unlink ( 'site/data/.backup' );
} else {
touch ( 'site/data/.backup' );
}
// Notice
if ( self :: $inputNotices === []) {
// Active la réécriture d'URL
2021-11-05 16:08:36 +01:00
$rewrite = $this -> getInput ( 'configRewrite' , helper :: FILTER_BOOLEAN );
2021-10-29 16:14:51 +02:00
if (
$rewrite
AND helper :: checkRewrite () === false
) {
// Ajout des lignes dans le .htaccess
file_put_contents (
'.htaccess' ,
PHP_EOL .
2022-01-08 18:30:56 +01:00
'<IfModule mod_rewrite.c>' . PHP_EOL .
2021-10-29 16:14:51 +02:00
" \t RewriteEngine on " . PHP_EOL .
" \t RewriteBase " . helper :: baseUrl ( false , false ) . PHP_EOL .
" \t RewriteCond % { REQUEST_FILENAME} !-f " . PHP_EOL .
" \t RewriteCond % { REQUEST_FILENAME} !-d " . PHP_EOL .
" \t RewriteRule ^(.*) $ index.php? $ 1 [L] " . PHP_EOL .
2022-01-08 18:30:56 +01:00
'</IfModule>' ,
2021-10-29 16:14:51 +02:00
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 ;
}
// Met à jour la baseUrl
$this -> setData ([ 'core' , 'baseUrl' , helper :: baseUrl ( true , false ) ]);
}
// Générer robots.txt et sitemap
$this -> generateFiles ();
// Valeurs en sortie
$this -> addOutput ([
2021-12-01 18:25:50 +01:00
'title' => 'Configuration' ,
'view' => 'index' ,
2021-10-29 16:14:51 +02:00
'notification' => 'Modifications enregistrées ' ,
'state' => true
]);
}
2021-10-30 12:48:29 +02:00
// Générer la list des pages disponibles
2021-10-06 18:18:41 +02:00
self :: $pagesList = $this -> getData ([ 'page' ]);
foreach ( self :: $pagesList as $page => $pageId ) {
2021-10-06 18:00:59 +02:00
if ( $this -> getData ([ 'page' , $page , 'block' ]) === 'bar' ||
$this -> getData ([ 'page' , $page , 'disable' ]) === true ) {
2021-10-06 18:18:41 +02:00
unset ( self :: $pagesList [ $page ]);
2021-10-06 18:00:59 +02:00
}
}
2021-10-06 18:18:41 +02:00
self :: $orphansList = $this -> getData ([ 'page' ]);
foreach ( self :: $orphansList as $page => $pageId ) {
2021-10-06 18:00:59 +02:00
if ( $this -> getData ([ 'page' , $page , 'block' ]) === 'bar' ||
$this -> getData ([ 'page' , $page , 'disable' ]) === true ||
$this -> getdata ([ 'page' , $page , 'position' ]) !== 0 ) {
2021-10-06 18:18:41 +02:00
unset ( self :: $orphansList [ $page ]);
2021-10-06 18:00:59 +02:00
}
}
2022-01-05 18:13:25 +01:00
// Variable de version
2022-02-10 14:43:00 +01:00
self :: $onlineVersion = helper :: getUrlContents ( common :: ZWII_UPDATE_URL . common :: ZWII_UPDATE_CHANNEL . '/version' );
2022-01-09 11:23:31 +01:00
if ( self :: $onlineVersion > common :: ZWII_VERSION ) {
2022-01-05 18:13:25 +01:00
self :: $updateButtonText = " Mettre à jour " ;
}
2021-10-29 16:14:51 +02:00
// Valeurs en sortie
$this -> addOutput ([
2021-10-30 12:48:29 +02:00
'title' => 'Configuration' ,
'view' => 'index'
2020-11-21 15:09:10 +01:00
]);
}
2021-10-29 16:14:51 +02:00
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 ([
2021-12-01 18:25:50 +01:00
'title' => 'Éditeur de script dans ' . ucfirst ( $this -> geturl ( 2 )) ,
'vendor' => [
'codemirror'
],
'view' => 'script' ,
2020-05-12 16:28:10 +02:00
'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 ) {
2021-11-16 08:57:33 +01:00
$content = $this -> getPage ( $parentId , self :: $i18n );
2021-12-15 18:04:18 +01:00
$titre = $this -> getData ([ 'page' , $parentId , 'title' ]);
2021-11-16 08:57:33 +01:00
$content = $titre . ' ' . $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 ;
2021-11-16 08:57:33 +01:00
$this -> setPage ( $parentId , $replace , self :: $i18n );
2020-05-09 09:23:29 +02:00
$c3 += $c1 + $c2 ;
}
foreach ( $childIds as $childId ) {
2021-11-16 08:57:33 +01:00
$content = $this -> getPage ( $childId , self :: $i18n );
$content = $titre . ' ' . $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 ;
2021-11-16 08:57:33 +01:00
$this -> setPage ( $childId , $replace , self :: $i18n );
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 ([
2021-12-01 18:25:50 +01:00
'title' => 'Restaurer' ,
'view' => 'restore' ,
2020-05-09 09:23:29 +02:00
'notification' => $success ? $c3 . ' conversion' . ( $c3 > 1 ? 's' : '' ) . ' effectuée' . ( $c3 > 1 ? 's' : '' ) : 'Aucune conversion' ,
'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 ([
2021-12-01 18:25:50 +01:00
'title' => 'Configuration' ,
'view' => 'index' ,
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 ([
2021-12-01 18:25:50 +01:00
'title' => 'Configuration' ,
'view' => 'index' ,
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
*/
2021-05-20 21:52:09 +02:00
public function logDownload () {
2020-05-30 12:04:45 +02:00
$fileName = self :: DATA_DIR . 'journal.log' ;
2020-06-03 10:06:11 +02:00
if ( file_exists ( $fileName )) {
2021-05-19 20:28:40 +02:00
ob_start ();
2020-06-03 10:06:11 +02:00
header ( 'Content-Type: application/octet-stream' );
header ( 'Content-Disposition: attachment; filename="' . $fileName . '"' );
header ( 'Content-Length: ' . filesize ( $fileName ));
2021-05-20 21:52:09 +02:00
ob_clean ();
2021-05-19 20:28:40 +02:00
ob_end_flush ();
2020-06-03 10:06:11 +02:00
readfile ( $fileName );
2021-05-19 20:28:40 +02:00
exit ();
2020-06-03 10:06:11 +02:00
} else {
// Valeurs en sortie
$this -> addOutput ([
2021-12-01 18:25:50 +01:00
'title' => 'Configuration' ,
'view' => 'index' ,
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 () {
2021-05-19 20:28:40 +02:00
ob_start ();
2020-05-31 19:08:19 +02:00
$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 ));
2021-05-20 21:52:09 +02:00
ob_clean ();
2021-05-19 20:28:40 +02:00
ob_end_flush ();
2020-06-03 10:06:11 +02:00
readfile ( $fileName );
unlink ( self :: TEMP_DIR . 'blacklist.log' );
2021-05-19 20:28:40 +02:00
exit ();
2020-06-03 10:06:11 +02:00
} else {
// Valeurs en sortie
$this -> addOutput ([
2021-12-01 18:25:50 +01:00
'title' => 'Configuration' ,
'view' => 'index' ,
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 ([
2021-12-01 18:25:50 +01:00
'title' => 'Configuration' ,
'view' => 'index' ,
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 ([
2021-12-01 18:25:50 +01:00
'title' => 'Configuration' ,
'view' => 'index' ,
2020-05-31 19:08:19 +02:00
'notification' => 'Pas de liste à effacer' ,
'state' => false
]);
}
}
2021-06-04 13:00:35 +02:00
/**
* Récupération des backups auto dans le gestionnaire de fichiers
*/
public function copyBackups () {
// Créer le répertoire manquant
if ( ! is_dir ( self :: FILE_DIR . 'source/backup' )) {
2021-09-29 14:50:25 +02:00
mkdir ( self :: FILE_DIR . 'source/backup' , 0755 );
2021-06-04 13:00:35 +02:00
}
2021-06-04 18:37:17 +02:00
$this -> copyDir ( self :: BACKUP_DIR , self :: FILE_DIR . 'source/backup' );
2021-06-04 13:00:35 +02:00
// Valeurs en sortie
$this -> addOutput ([
2021-12-01 18:25:50 +01:00
'title' => 'Configuration' ,
'view' => 'index' ,
2021-06-04 13:00:35 +02:00
'notification' => 'Copie terminée' ,
'state' => true
]);
}
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 ;
}
2020-05-09 12:52:29 +02:00
}