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 >
2024-12-23 15:24:11 +01:00
* @ copyright Copyright ( C ) 2018 - 2025 , Frédéric Tempez
2022-12-29 17:02:20 +01:00
* @ license CC Attribution - NonCommercial - NoDerivatives 4.0 International
2020-09-01 20:48:40 +02:00
* @ link http :// zwiicms . fr /
2018-04-02 08:29:19 +02:00
*/
2022-09-29 08:45:59 +02:00
class config extends common
{
2018-04-02 08:29:19 +02:00
public static $actions = [
'backup' => self :: GROUP_ADMIN ,
2022-09-29 08:45:59 +02:00
'copyBackups' => self :: GROUP_ADMIN ,
'delBackups' => self :: GROUP_ADMIN ,
2018-12-25 18:17:11 +01:00
'configMetaImage' => self :: GROUP_ADMIN ,
2024-09-07 14:27:05 +02:00
'sitemap' => 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 ,
2022-01-13 19:08:07 +01:00
'updateBaseUrl' => self :: GROUP_ADMIN ,
2020-05-30 12:04:45 +02:00
'script' => self :: GROUP_ADMIN ,
'logReset' => self :: GROUP_ADMIN ,
2022-09-29 08:45:59 +02:00
'logDownload' => self :: GROUP_ADMIN ,
2020-05-31 19:08:19 +02:00
'blacklistReset' => self :: GROUP_ADMIN ,
2024-09-18 19:34:04 +02:00
'blacklistDownload' => self :: GROUP_ADMIN ,
2024-12-19 22:06:12 +01:00
'testmail' => 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 = [
2023-06-29 10:30:12 +02:00
'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-04-02 08:29:19 +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
];
2021-10-11 17:07:09 +02:00
// Anonymisation des IP du journal
public static $anonIP = [
2022-10-14 10:20:29 +02:00
4 => 'Non tronquée' ,
2021-10-11 17:53:41 +02:00
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' ,
2023-06-29 10:30:12 +02:00
'alpha' => 'Lettres'
2021-11-12 18:22:06 +01:00
];
2023-02-07 11:21:21 +01:00
public static $updateDelay = [
86400 => '1' ,
172800 => '2' ,
345600 => '4' ,
604800 => '7' ,
1209600 => '14' ,
];
2021-10-11 17:07:09 +02:00
2021-10-01 15:53:38 +02:00
// Langue traduite courante
2022-09-28 14:58:21 +02:00
public static $i18nSite = 'fr_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
2022-01-05 18:13:25 +01:00
public static $onlineVersion = '' ;
public static $updateButtonText = 'Réinstaller' ;
2021-10-06 18:00:59 +02:00
2023-08-12 21:34:38 +02:00
public static $imageOpenGraph = [];
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
*/
2024-09-07 14:27:05 +02:00
public function sitemap ()
2022-09-29 08:45:59 +02:00
{
2023-06-29 10:30:12 +02:00
// La page n'existe pas
if (
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) !== true
) {
// Valeurs en sortie
$this -> addOutput ([
'access' => false
]);
} else {
// Mettre à jour le site map
$successSitemap = $this -> updateSitemap ();
2021-03-11 14:57:10 +01:00
2023-06-29 10:30:12 +02:00
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . 'config' ,
'notification' => $successSitemap ? helper :: translate ( 'La carte du site a été mise à jour' ) : helper :: translate ( 'Echec de l\'écriture, vérifiez les permissions' ),
'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
*/
2022-09-29 08:45:59 +02:00
public function backup ()
{
2020-02-10 16:36:57 +01:00
// Soumission du formulaire
2023-06-29 17:01:27 +02:00
if (
2023-06-30 09:09:39 +02:00
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) === true &&
2023-06-29 17:01:27 +02:00
$this -> isPost ()
) {
2020-05-25 11:58:54 +02:00
// Creation du ZIP
2022-09-29 08:45:59 +02: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
2022-09-29 08:45:59 +02:00
if ( ! is_dir ( self :: FILE_DIR . 'source/backup' )) {
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
2022-09-29 08:45:59 +02:00
$success = copy ( self :: TEMP_DIR . $fileName , self :: FILE_DIR . 'source/backup/' . $fileName );
2020-08-09 12:00:29 +02:00
// 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 ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( '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
*/
2022-09-29 08:45:59 +02:00
public function configMetaImage ()
{
2020-05-25 11:58:54 +02:00
// fonction désactivée pour un site local
2022-09-29 08:45:59 +02:00
if ( strpos ( helper :: baseUrl ( false ), 'localhost' ) > 0 or strpos ( helper :: baseUrl ( false ), '127.0.0.1' ) > 0 ) {
2022-08-29 14:15:08 +02:00
$site = 'https://zwiicms.fr/' ;
} else {
$site = helper :: baseUrl ( false );
}
2022-08-29 20:37:36 +02:00
2022-08-29 14:15:08 +02:00
// Clé de l'API
$token = $this -> getData ([ 'config' , 'seo' , 'keyApi' ]);
2020-05-25 11:58:54 +02:00
2022-08-29 20:37:36 +02:00
// Succès de l'opération par défaut
2022-06-10 18:40:55 +02:00
$success = false ;
2022-08-29 20:37:36 +02:00
$data = false ;
2022-06-10 18:40:55 +02:00
2022-08-29 20:37:36 +02:00
// lire l'API si le token est fourni
2022-09-29 08:45:59 +02:00
if ( ! empty ( $token )) {
2022-08-29 20:37:36 +02:00
// Tente de connecter 5 fois l'API
2022-09-29 08:45:59 +02:00
for ( $i = 0 ; $i < 5 ; $i ++ ) {
2022-08-29 20:37:36 +02:00
$data = helper :: getUrlContents ( 'https://shot.screenshotapi.net/screenshot?token=' . $token . '&url=' . $site . '&width=1200&height=627&output=json&file_type=jpeg&no_cookie_banners=true&wait_for_event=load' );
if ( $data !== false ) {
break ;
}
2022-06-10 18:40:55 +02:00
}
}
2022-08-29 14:15:08 +02:00
// Traitement des données reçues valides.
2023-06-29 10:30:12 +02:00
if ( ! empty ( $token ) && $data !== false ) {
2022-08-29 14:15:08 +02:00
$data = json_decode ( $data , true );
$img = $data [ 'screenshot' ];
2021-02-16 09:44:04 +01:00
// Effacer l'image et la miniature png
2022-09-29 08:45:59 +02:00
if ( file_exists ( self :: FILE_DIR . 'thumb/screenshot.jpg' )) {
unlink ( self :: FILE_DIR . 'thumb/screenshot.jpg' );
2021-02-16 09:44:04 +01:00
}
2022-09-29 08:45:59 +02:00
if ( file_exists ( self :: FILE_DIR . 'source/screenshot.jpg' )) {
unlink ( self :: FILE_DIR . 'source/screenshot.jpg' );
2019-06-20 18:58:49 +02:00
}
2022-09-29 08:45:59 +02:00
$success = copy ( $img , self :: FILE_DIR . 'source/screenshot.jpg' );
2019-06-18 10:13:09 +02:00
}
2022-08-29 20:37:36 +02:00
2023-06-29 10:30:12 +02:00
$notification = empty ( $token )
2022-09-29 08:45:59 +02:00
? 'La clé de l\'API ne peut pas être vide'
2023-06-29 10:30:12 +02:00
: ( $success === false ? 'Service en ligne inaccessible' : 'Capture d\'écran générée avec succès' );
2022-08-29 20:37:36 +02:00
2018-10-24 22:48:10 +02:00
// Valeurs en sortie
$this -> addOutput ([
2021-12-02 14:52:43 +01:00
'redirect' => helper :: baseUrl () . 'config' ,
2022-10-10 17:08:47 +02:00
'notification' => helper :: translate ( $notification ),
2022-09-29 08:45:59 +02:00
'state' => ( $success === false or empty ( $token )) ? 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
*/
2022-09-29 08:45:59 +02:00
public function restore ()
{
2019-12-10 10:53:31 +01:00
// Soumission du formulaire
2023-06-29 17:01:27 +02:00
if (
2023-06-30 09:09:39 +02:00
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) === true &&
2023-06-29 17:01:27 +02:00
$this -> isPost ()
) {
2021-11-21 17:16:47 +01:00
2021-11-15 21:44:12 +01:00
$success = false ;
2022-09-29 08:45:59 +02:00
if ( $this -> getInput ( 'configRestoreImportFile' , null , true )) {
2021-11-15 21:44:12 +01:00
$fileZip = $this -> getInput ( 'configRestoreImportFile' );
$file_parts = pathinfo ( $fileZip );
2022-12-14 14:12:05 +01:00
// Validité du nom du fichier sélectionné
2021-11-15 21:44:12 +01:00
if ( $file_parts [ 'extension' ] !== 'zip' ) {
// Valeurs en sortie erreur
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( 'Restaurer' ),
2021-12-01 18:25:50 +01:00
'view' => 'restore' ,
2022-10-10 17:08:47 +02:00
'notification' => helper :: translate ( 'Archive invalide' ),
2021-11-15 21:44:12 +01:00
'state' => false
2022-09-29 08:45:59 +02:00
]);
2021-11-15 21:44:12 +01:00
}
2022-12-14 14:12:05 +01:00
// Ouverture de l'archive
$zip = new ZipArchive ();
if ( $zip -> open ( self :: FILE_DIR . 'source/' . $fileZip ) === FALSE ) {
2021-11-15 21:44:12 +01:00
// Valeurs en sortie erreur
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( 'Restaurer' ),
2021-12-01 18:25:50 +01:00
'view' => 'restore' ,
2022-10-10 17:08:47 +02:00
'notification' => helper :: translate ( 'Archive invalide' ),
2021-11-15 21:44:12 +01:00
'state' => false
2022-09-29 08:45:59 +02:00
]);
2021-11-15 21:44:12 +01:00
}
2023-08-12 21:34:38 +02:00
2022-12-14 14:12:05 +01:00
// Extraction de l'archive dans un dossier temporaire
$tmpDir = uniqid ( 8 );
2022-09-29 08:45:59 +02:00
$success = $zip -> extractTo ( self :: TEMP_DIR . $tmpDir );
2022-12-14 14:12:05 +01:00
// Version de l'archive
$data = json_decode ( file_get_contents ( self :: TEMP_DIR . $tmpDir . '/data/core.json' ), true );
$dataVersion = $data [ 'core' ][ 'dataVersion' ];
// Version non prises en charge <9 ou erreur d'extraction
2023-06-29 10:30:12 +02:00
if ( intval ( substr ( $dataVersion , 0 , 1 )) <= 9 or ! $success ) {
2022-09-29 08:45:59 +02:00
// Valeurs en sortie erreur
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( 'Restaurer' ),
2022-09-29 08:45:59 +02:00
'view' => 'restore' ,
2022-10-10 17:08:47 +02:00
'notification' => helper :: translate ( 'Archive invalide' ),
2022-09-29 08:45:59 +02:00
'state' => false
]);
2021-11-15 21:44:12 +01:00
}
2022-12-14 14:12:05 +01:00
// Fermer le zip
2021-11-15 21:44:12 +01:00
$zip -> close ();
2020-05-25 11:58:54 +02:00
2022-12-14 14:12:05 +01:00
// Option active, préservation des utilisateurs
if ( $this -> getInput ( 'configRestoreImportUser' , helper :: FILTER_BOOLEAN ) === true ) {
$users = $this -> getData ([ 'user' ]);
}
// Copie dans le dossier /site/data
$success = $this -> copyDir ( self :: TEMP_DIR . $tmpDir , 'site/' );
2023-07-19 18:07:12 +02:00
$this -> deleteDir ( self :: TEMP_DIR . $tmpDir );
2022-12-14 14:12:05 +01:00
2021-11-15 21:44:12 +01:00
// Restaurer les users originaux d'une v10 si option cochée
2022-09-29 08:45:59 +02:00
if (
$this -> getInput ( 'configRestoreImportUser' , helper :: FILTER_BOOLEAN ) === true
) {
$this -> setData ([ 'user' , $users ]);
2021-11-15 21:44:12 +01:00
}
2020-05-07 08:36:24 +02:00
}
2022-09-29 08:45:59 +02:00
2019-12-10 10:53:31 +01:00
// Message de notification
2023-06-29 10:30:12 +02:00
$notification = $success === true ? 'Restauration effectuée avec succès' : 'Erreur inconnue' ;
$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
'redirect' => $redirect ,
2022-10-10 17:08:47 +02:00
'notification' => helper :: translate ( $notification ),
2019-12-10 10:53:31 +01:00
'state' => $success
]);
2020-05-25 11:58:54 +02:00
}
2019-12-10 10:53:31 +01:00
// Valeurs en sortie
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( '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
*/
2022-09-29 08:45:59 +02:00
public function index ()
{
2021-10-29 16:14:51 +02:00
// Soumission du formulaire
2023-06-29 17:01:27 +02:00
if (
2023-06-30 09:09:39 +02:00
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) === true &&
2023-06-29 17:01:27 +02:00
$this -> isPost ()
) {
2021-10-30 12:48:29 +02:00
// Basculement en mise à jour auto, remise à 0 du compteur
2022-09-29 08:45:59 +02:00
if (
$this -> getData ([ 'config' , 'autoUpdate' ]) === false &&
$this -> getInput ( 'configAutoUpdate' , helper :: FILTER_BOOLEAN ) === true
) {
$this -> setData ([ 'core' , 'lastAutoUpdate' , 0 ]);
}
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' ),
2022-09-29 08:45:59 +02:00
'proxyPort' => $this -> getInput ( 'configProxyPort' , helper :: FILTER_INT ),
2023-02-07 11:21:21 +01:00
'autoUpdateDelay' => $this -> getInput ( 'configAutoUpdateDelay' , 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' ),
2023-03-27 15:11:07 +02:00
'githubId' => $this -> getInput ( 'socialGithubId' ),
'redditId' => $this -> getInput ( 'socialRedditId' ),
'twitchId' => $this -> getInput ( 'socialTwitchId' ),
'vimeoId' => $this -> getInput ( 'socialVimeoId' ),
2023-06-29 10:30:12 +02:00
'steamId' => $this -> getInput ( 'socialSteamId' ),
2021-10-30 12:48:29 +02:00
],
'smtp' => [
2022-09-29 08:45:59 +02:00
'enable' => $this -> getInput ( 'smtpEnable' , helper :: FILTER_BOOLEAN ),
2023-03-26 16:22:02 +02:00
'host' => $this -> getInput ( 'smtpHost' , helper :: FILTER_STRING_SHORT ),
'port' => $this -> getInput ( 'smtpPort' , helper :: FILTER_INT ),
2022-09-29 08:45:59 +02:00
'auth' => $this -> getInput ( 'smtpAuth' , helper :: FILTER_BOOLEAN ),
2023-02-25 19:11:05 +01:00
'secure' => $this -> getInput ( 'smtpSecure' , helper :: FILTER_STRING_SHORT ),
2023-03-26 16:22:02 +02:00
'username' => $this -> getInput ( 'smtpUsername' , helper :: FILTER_STRING_SHORT ),
2023-06-29 10:30:12 +02:00
'password' => helper :: encrypt ( $this -> getInput ( 'smtpPassword' , helper :: FILTER_STRING_SHORT ), $this -> getInput ( 'smtpHost' , helper :: FILTER_STRING_SHORT )),
2023-02-23 16:02:06 +01:00
'from' => $this -> getInput ( 'smtpFrom' , helper :: FILTER_MAIL , true ),
2021-10-30 12:48:29 +02:00
],
'seo' => [
2022-09-29 08:45:59 +02:00
'robots' => $this -> getInput ( 'seoRobots' , helper :: FILTER_BOOLEAN ),
2023-08-12 21:34:38 +02:00
'openGraphImage' => $this -> getInput ( 'seoOpenGraphImage' , helper :: FILTER_STRING_SHORT ),
2021-10-30 12:48:29 +02:00
],
2021-10-30 18:59:58 +02:00
'connect' => [
2022-09-29 08:45:59 +02:00
'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' ),
2022-09-29 08:45:59 +02:00
'showPassword' => $this -> getInput ( 'connectShowPassword' , helper :: FILTER_BOOLEAN ),
2024-11-14 21:18:50 +01:00
'redirectLogin' => $this -> getInput ( 'connectRedirectLogin' , helper :: FILTER_BOOLEAN ),
2024-12-19 22:06:12 +01:00
'mailAuth' => $this -> getInput ( 'connectAuthMail' , helper :: FILTER_INT ),
2021-10-30 12:48:29 +02:00
]
]
]);
2021-10-30 18:36:43 +02:00
2024-12-21 22:46:56 +01:00
// Sauvegarde la position des onglets de la vue de l'utilisateur courant
$this -> setData ([
'user' ,
$this -> getUser ( 'id' ),
'view' ,
[
'config' => $this -> getInput ( 'containerSelected' ),
'page' => $this -> getData ([ 'user' , $this -> getUser ( 'id' ), 'view' , 'page' ]),
]
]);
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' );
2022-09-29 08:45:59 +02:00
foreach ( new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $path )) as $filename ) {
if ( strpos ( $filename , 'backup.json' )) {
2021-10-29 16:14:51 +02:00
unlink ( $filename );
}
}
2023-06-29 10:30:12 +02:00
if ( file_exists ( 'site/data/.backup' ))
unlink ( 'site/data/.backup' );
2021-10-29 16:14:51 +02:00
} else {
touch ( 'site/data/.backup' );
}
// Notice
2022-09-29 08:45:59 +02:00
if ( self :: $inputNotices === []) {
2021-10-29 16:14:51 +02:00
// Active la réécriture d'URL
2021-11-05 16:08:36 +01:00
$rewrite = $this -> getInput ( 'configRewrite' , helper :: FILTER_BOOLEAN );
2022-09-29 08:45:59 +02:00
if (
2021-10-29 16:14:51 +02:00
$rewrite
2022-09-29 08:45:59 +02:00
and helper :: checkRewrite () === false
2021-10-29 16:14:51 +02:00
) {
// Ajout des lignes dans le .htaccess
2022-04-28 11:04:01 +02:00
$fileContent = file_get_contents ( '.htaccess' );
2024-09-18 19:34:04 +02:00
$rewriteData =
2023-06-29 10:30:12 +02:00
'# URL rewriting' . PHP_EOL .
2022-09-29 08:45:59 +02:00
'<IfModule mod_rewrite.c>' . PHP_EOL .
" \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 .
'</IfModule>' . PHP_EOL .
2024-06-02 14:40:34 +02:00
'# URL rewriting' ;
2022-04-28 11:04:01 +02:00
$fileContent = str_replace ( '# URL rewriting' , $rewriteData , $fileContent );
2024-04-09 17:23:26 +02:00
$this -> secure_file_put_contents (
2021-10-29 16:14:51 +02:00
'.htaccess' ,
2022-04-28 11:04:01 +02:00
$fileContent
2021-10-29 16:14:51 +02:00
);
// 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
2022-09-29 08:45:59 +02:00
elseif (
2021-10-29 16:14:51 +02:00
$rewrite === false
2022-09-29 08:45:59 +02:00
and helper :: checkRewrite ()
2021-10-29 16:14:51 +02:00
) {
// Suppression des lignes dans le .htaccess
2022-04-28 11:04:01 +02:00
$fileContent = file_get_contents ( '.htaccess' );
$fileContent = explode ( '# URL rewriting' , $fileContent );
$fileContent = $fileContent [ 0 ] . '# URL rewriting' . $fileContent [ 2 ];
2024-04-09 17:23:26 +02:00
$this -> secure_file_put_contents (
2022-04-28 11:04:01 +02:00
'.htaccess' ,
$fileContent
);
2021-10-29 16:14:51 +02:00
// Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection)
helper :: $rewriteStatus = false ;
}
}
// Générer robots.txt et sitemap
2022-04-16 10:08:59 +02:00
$this -> siteMap ();
2021-10-29 16:14:51 +02:00
// Valeurs en sortie
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( 'Configuration' ),
2021-12-01 18:25:50 +01:00
'view' => 'index' ,
2022-10-10 17:08:47 +02:00
'notification' => helper :: translate ( 'Modifications enregistrées' ),
2021-10-29 16:14:51 +02:00
'state' => true
]);
}
2022-01-05 18:13:25 +01:00
2023-02-07 11:21:21 +01:00
// Activation du bouton de mise à jour
if (
helper :: checkNewVersion ( common :: ZWII_UPDATE_CHANNEL )
&& $this -> getData ([ 'core' , 'updateAvailable' ]) === false
&& $this -> getData ([ 'config' , 'autoUpdate' ])
) {
$this -> setData ([ 'core' , 'updateAvailable' , true ]);
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . 'config' ,
]);
}
2022-01-05 18:13:25 +01:00
// Variable de version
2023-02-06 21:45:41 +01:00
if ( helper :: checkNewVersion ( common :: ZWII_UPDATE_CHANNEL )) {
2024-02-03 09:49:30 +01:00
self :: $updateButtonText = helper :: translate ( 'Mise à jour' );
2022-01-05 18:13:25 +01:00
}
2023-08-27 22:56:07 +02:00
2023-02-07 11:21:21 +01:00
// Sélecteur de délais, compléter avec la traduction en jours
2023-06-29 10:30:12 +02:00
foreach ( self :: $updateDelay as $key => $value ) {
2023-02-07 11:21:21 +01:00
self :: $updateDelay [ $key ] = $key === 86400 ? $value . ' ' . helper :: translate ( 'jour' ) : $value . ' ' . helper :: translate ( 'jours' );
}
2023-08-12 21:34:38 +02:00
// Paramètres de l'image OpenGraph
$imagePath = self :: FILE_DIR . 'source/' . $this -> getData ([ 'config' , 'seo' , 'openGraphImage' ]);
// Par défaut
self :: $imageOpenGraph [ 'type' ] = '' ;
self :: $imageOpenGraph [ 'size' ] = '' ;
self :: $imageOpenGraph [ 'wide' ] = '' ;
self :: $imageOpenGraph [ 'height' ] = '' ;
self :: $imageOpenGraph [ 'ratio' ] = 0 ;
if (
$this -> getData ([ 'config' , 'seo' , 'openGraphImage' ])
&& file_exists ( $imagePath )
) {
// Infos sur l'image Open Graph
$typeMime = exif_imagetype ( $imagePath );
switch ( $typeMime ) {
case IMAGETYPE_JPEG :
$typeMime = 'jpeg' ;
break ;
case IMAGETYPE_PNG :
$typeMime = 'png' ;
break ;
2023-08-14 00:49:23 +02:00
default :
2023-08-27 22:56:07 +02:00
$typeMime = image_type_to_mime_type ( $typeMime );
2023-08-12 21:34:38 +02:00
}
self :: $imageOpenGraph [ 'type' ] = $typeMime ;
$imageSize = getimagesize ( $imagePath );
self :: $imageOpenGraph [ 'wide' ] = $imageSize [ 0 ];
self :: $imageOpenGraph [ 'height' ] = $imageSize [ 1 ];
self :: $imageOpenGraph [ 'ratio' ] = self :: $imageOpenGraph [ 'wide' ] / self :: $imageOpenGraph [ 'height' ];
self :: $imageOpenGraph [ 'size' ] = filesize ( $imagePath );
$tailleEnOctets = filesize ( $imagePath );
if ( $tailleEnOctets >= 1024 * 1024 ) {
// Si la taille est supérieure ou égale à 1 Mo, afficher en mégaoctets
self :: $imageOpenGraph [ 'size' ] = round ( $tailleEnOctets / ( 1024 * 1024 ), 2 ) . ' Mo' ;
} else {
// Sinon, afficher en kilooctets
self :: $imageOpenGraph [ 'size' ] = round ( $tailleEnOctets / 1024 , 2 ) . ' Ko' ;
}
}
2021-10-29 16:14:51 +02:00
// Valeurs en sortie
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( 'Configuration' ),
2021-10-30 12:48:29 +02:00
'view' => 'index'
2020-11-21 15:09:10 +01:00
]);
}
2021-10-29 16:14:51 +02:00
2022-09-29 08:45:59 +02:00
public function script ()
{
2020-05-12 16:28:10 +02:00
// Soumission du formulaire
2023-06-29 17:01:27 +02:00
if (
2023-06-30 09:09:39 +02:00
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) === true &&
2023-06-29 17:01:27 +02:00
$this -> isPost ()
) {
2020-05-12 16:28:10 +02:00
// Ecrire les fichiers de script
2020-05-12 16:40:33 +02:00
if ( $this -> geturl ( 2 ) === 'head' ) {
2024-04-09 17:23:26 +02:00
$this -> secure_file_put_contents ( self :: DATA_DIR . 'head.inc.html' , $this -> getInput ( 'configScriptHead' , null ));
2020-05-12 16:28:10 +02:00
}
2020-05-12 16:40:33 +02:00
if ( $this -> geturl ( 2 ) === 'body' ) {
2024-04-09 17:23:26 +02:00
$this -> secure_file_put_contents ( self :: DATA_DIR . 'body.inc.html' , $this -> getInput ( 'configScriptBody' , null ));
2020-05-25 11:58:54 +02:00
}
2020-05-12 16:28:10 +02:00
// Valeurs en sortie
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( 'Éditeur de script dans ' . ucfirst ( $this -> geturl ( 2 ))),
2021-12-01 18:25:50 +01:00
'vendor' => [
'codemirror'
],
'view' => 'script' ,
2020-05-12 16:28:10 +02:00
'state' => true
]);
}
// Valeurs en sortie
$this -> addOutput ([
2022-12-14 14:12:05 +01:00
'title' => sprintf ( helper :: translate ( 'Éditeur de script %s' ), ucfirst ( $this -> geturl ( 2 ))),
2020-05-12 16:28:10 +02:00
'vendor' => [
'codemirror'
],
'view' => 'script'
]);
}
2022-01-13 19:08:07 +01:00
2020-05-30 12:04:45 +02:00
/**
* Vider le fichier de log
*/
2022-09-29 08:45:59 +02:00
public function logReset ()
{
2023-07-04 19:03:27 +02:00
// Action interdite
if (
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) !== true
) {
2020-05-31 19:08:19 +02:00
// Valeurs en sortie
2022-09-29 08:45:59 +02:00
$this -> addOutput ([
2023-07-04 19:03:27 +02:00
'access' => false
2020-05-31 19:08:19 +02:00
]);
2020-06-02 18:49:24 +02:00
} else {
2023-07-04 19:03:27 +02:00
if ( file_exists ( self :: DATA_DIR . 'journal.log' )) {
unlink ( self :: DATA_DIR . 'journal.log' );
// Créer les en-têtes des journaux
$d = 'Date;Heure;IP;Id;Action' . PHP_EOL ;
2024-04-09 17:23:26 +02:00
$this -> secure_file_put_contents ( self :: DATA_DIR . 'journal.log' , $d );
2023-07-04 19:03:27 +02:00
// Valeurs en sortie
$this -> addOutput ([
'title' => helper :: translate ( 'Configuration' ),
'view' => 'index' ,
'notification' => helper :: translate ( 'Journal réinitialisé avec succès' ),
'state' => true
]);
} else {
// Valeurs en sortie
$this -> addOutput ([
'title' => helper :: translate ( 'Configuration' ),
'view' => 'index' ,
'notification' => helper :: translate ( 'Aucun journal à effacer' ),
'state' => false
]);
}
2020-05-31 19:08:19 +02:00
}
2022-09-29 08:45:59 +02:00
}
2020-05-30 12:04:45 +02:00
2022-09-29 08:45:59 +02:00
/**
* Télécharger le fichier de log
*/
public function logDownload ()
{
2023-07-04 19:03:27 +02:00
// Action interdite
if (
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) !== true
) {
2020-06-03 10:06:11 +02:00
// Valeurs en sortie
$this -> addOutput ([
2023-07-04 19:03:27 +02:00
'access' => false
2020-06-03 10:06:11 +02:00
]);
2023-07-04 19:03:27 +02:00
} else {
$fileName = self :: DATA_DIR . 'journal.log' ;
if ( file_exists ( $fileName )) {
ob_start ();
header ( 'Content-Description: File Transfer' );
header ( 'Content-Type: application/octet-stream' );
header ( 'Content-Disposition: attachment; filename="' . $fileName . '"' );
header ( 'Content-Length: ' . filesize ( $fileName ));
ob_clean ();
ob_end_flush ();
readfile ( $fileName );
exit ();
} else {
// Valeurs en sortie
$this -> addOutput ([
'title' => helper :: translate ( 'Configuration' ),
'view' => 'index' ,
'notification' => helper :: translate ( 'Aucun fichier journal à télécharger' ),
'state' => false
]);
}
2020-06-03 10:06:11 +02:00
}
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
*/
2022-09-29 08:45:59 +02:00
public function blacklistDownload ()
{
2023-07-04 19:03:27 +02:00
// Action interdite
if (
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) !== true
) {
2020-06-03 10:06:11 +02:00
// Valeurs en sortie
$this -> addOutput ([
2023-07-04 19:03:27 +02:00
'access' => false
2020-06-03 10:06:11 +02:00
]);
2023-07-04 19:03:27 +02:00
} else {
ob_start ();
$fileName = self :: TEMP_DIR . 'blacklist.log' ;
$d = 'Date dernière tentative;Heure dernière tentative;Id;Adresse IP;Nombre d\'échecs' . PHP_EOL ;
2024-04-09 17:23:26 +02:00
$this -> secure_file_put_contents ( $fileName , $d );
2023-07-04 19:03:27 +02:00
if ( file_exists ( $fileName )) {
$d = $this -> getData ([ 'blacklist' ]);
$data = '' ;
foreach ( $d as $key => $item ) {
2024-01-26 16:34:01 +01:00
$data .= helper :: dateUTF8 ( '%Y %m %d' , $item [ 'lastFail' ], self :: $i18nUI ) . ' - ' . helper :: dateUTF8 ( '%H:%M' , time (), self :: $i18nUI );
2023-07-04 19:03:27 +02:00
$data .= $key . ';' . $item [ 'ip' ] . ';' . $item [ 'connectFail' ] . PHP_EOL ;
}
2024-04-09 17:23:26 +02:00
$this -> secure_file_put_contents ( $fileName , $data , FILE_APPEND );
2023-07-04 19:03:27 +02:00
header ( 'Content-Description: File Transfer' );
header ( 'Content-Type: application/octet-stream' );
header ( 'Content-Transfer-Encoding: binary' );
header ( 'Content-Disposition: attachment; filename="' . $fileName . '"' );
header ( 'Content-Length: ' . filesize ( $fileName ));
ob_clean ();
ob_end_flush ();
readfile ( $fileName );
unlink ( self :: TEMP_DIR . 'blacklist.log' );
exit ();
} else {
// Valeurs en sortie
$this -> addOutput ([
2023-07-25 16:05:36 +02:00
'title' => helper :: translate ( 'Configuration' ),
2023-07-04 19:03:27 +02:00
'view' => 'index' ,
'notification' => helper :: translate ( 'Aucune liste noire à télécharger' ),
'state' => false
]);
}
2020-06-03 10:06:11 +02:00
}
2020-05-30 12:04:45 +02:00
}
2020-05-31 19:08:19 +02:00
/**
* Réinitialiser les ip blacklistées
*/
2022-09-29 08:45:59 +02:00
public function blacklistReset ()
{
2023-07-04 19:03:27 +02:00
// Action interdite
if (
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) !== true
) {
2020-05-31 19:08:19 +02:00
// Valeurs en sortie
2022-09-29 08:45:59 +02:00
$this -> addOutput ([
2023-07-04 19:03:27 +02:00
'access' => false
2020-05-31 19:08:19 +02:00
]);
} else {
2023-07-04 19:03:27 +02:00
if ( file_exists ( self :: DATA_DIR . 'blacklist.json' )) {
$this -> setData ([ 'blacklist' , []]);
// Valeurs en sortie
$this -> addOutput ([
'title' => helper :: translate ( 'Configuration' ),
'view' => 'index' ,
'notification' => helper :: translate ( 'Liste noire réinitialisée avec succès' ),
'state' => true
]);
} else {
// Valeurs en sortie
$this -> addOutput ([
'title' => helper :: translate ( 'Configuration' ),
'view' => 'index' ,
'notification' => helper :: translate ( 'Aucune liste noire à effacer' ),
'state' => false
]);
}
2020-05-31 19:08:19 +02:00
}
}
2021-06-04 13:00:35 +02:00
/**
* Récupération des backups auto dans le gestionnaire de fichiers
*/
2022-09-29 08:45:59 +02:00
public function copyBackups ()
{
2023-07-04 19:03:27 +02:00
// Action interdite
if (
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) !== true
) {
// Valeurs en sortie
$this -> addOutput ([
'access' => false
]);
} else {
2022-05-26 19:57:57 +02:00
2023-07-04 19:03:27 +02:00
$success = $this -> copyDir ( self :: BACKUP_DIR , self :: FILE_DIR . 'source/backup' );
2022-08-29 14:15:08 +02:00
2023-07-04 19:03:27 +02:00
// Valeurs en sortie
$this -> addOutput ([
'title' => helper :: translate ( 'Configuration' ),
'view' => 'index' ,
'notification' => $success ? helper :: translate ( 'Copie terminée avec succès' ) : helper :: translate ( 'Copie terminée avec des erreurs' ),
'state' => $success
]);
}
2021-06-04 13:00:35 +02:00
}
2022-01-21 19:11:51 +01:00
/**
2022-02-18 12:43:48 +01:00
* Vider le dosser des sauvegardes automatisées
2022-01-21 19:11:51 +01:00
*/
2022-09-29 08:45:59 +02:00
public function delBackups ()
{
2023-07-04 19:03:27 +02:00
// Action interdite
if (
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) !== true
) {
// Valeurs en sortie
$this -> addOutput ([
'access' => false
]);
} else {
$path = realpath ( self :: BACKUP_DIR );
$success = $fail = 0 ;
foreach ( new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $path )) as $filename ) {
if ( strpos ( $filename , '.zip' )) {
$r = unlink ( $filename );
$success = $r === true ? $success + 1 : $success ;
$fail = $r === false ? $fail + 1 : $fail ;
}
2022-02-18 12:43:48 +01:00
}
2023-07-04 19:03:27 +02:00
// Valeurs en sortie
$this -> addOutput ([
'title' => helper :: translate ( 'Configuration' ),
'view' => 'index' ,
'notification' => $success . helper :: translate ( 'Fichiers effacés' ) . ' - ' . helper :: translate ( 'Échecs' ) . ': ' . $fail ,
'state' => true
]);
2022-02-12 17:10:59 +01:00
}
}
2024-09-18 19:34:04 +02:00
2024-06-09 02:51:52 +02:00
/**
* Fonction pour vérifier la présence du module de réécriture
* @ return bool
*/
2024-09-18 19:34:04 +02:00
public function isModRewriteEnabled ()
{
2024-06-09 02:51:52 +02:00
// Check if Apache and mod_rewrite is loaded
if ( function_exists ( 'apache_get_modules' )) {
$modules = apache_get_modules ();
return in_array ( 'mod_rewrite' , $modules );
} else {
// Fallback if not using Apache or unable to detect modules
return getenv ( 'HTTP_MOD_REWRITE' ) == 'On' || getenv ( 'REDIRECT_STATUS' ) == '200' ;
}
}
2024-09-18 19:34:04 +02:00
2024-12-19 22:06:12 +01:00
/**
* Envoi un message de test
* @ return void
*/
public function testmail ()
{
$sent = $this -> sendMail (
$this -> getUser ( 'mail' ),
helper :: translate ( 'Test de la messagerie du site' ),
'<strong>' . $this -> getUser ( 'firstname' ) . ' ' . $this -> getUser ( 'lastname' ) . '</strong>,<br><br>' .
'<h4>' . helper :: translate ( 'Il semblerait que votre messagerie fonctionne correctement !' ) . '</h4>' ,
null ,
'no-reply@localhost'
);
if ( $sent !== true ) {
// Désactivation de l'authentification par email
$this -> setData ([ 'config' , 'connect' , 'mailAuth' , 0 ]);
// Journalisation
$this -> saveLog ( $sent );
}
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . 'config/' . $this -> getUrl ( 2 ),
'state' => $sent === true ? true : false ,
'notification' => $sent === true ? helper :: translate ( 'Message de test envoyé avec succès' ) : helper :: translate ( 'Message non envoyé' )
]);
}
2023-06-29 10:30:12 +02:00
}