cinfig à vérifier

This commit is contained in:
Fred Tempez 2021-10-29 19:25:17 +02:00
parent f891e5a0c1
commit 47775ec420
3 changed files with 79 additions and 258 deletions

View File

@ -406,58 +406,15 @@ class config extends common {
$this->setData(['user',$this->getuser('id'),'accessCsrf',$_SESSION['csrf']]);
}
// 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),
'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),
'autoDisconnect' => $this->getInput('configAdvancedAutoDisconnect',helper::FILTER_BOOLEAN),
'smtp' => [
'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)
],
'seo' => [
'robots' => $this->getInput('configAdvancedSeoRobots',helper::FILTER_BOOLEAN)
],
'connect' => [
'attempt' => $this->getInput('configAdvancedConnectAttempt',helper::FILTER_INT),
'timeout' => $this->getInput('configAdvancedConnectTimeout',helper::FILTER_INT),
'log' => $this->getInput('configAdvancedConnectLog',helper::FILTER_BOOLEAN),
'anonymousIp' => $this->getInput('configAdvancedConnectAnonymousIp',helper::FILTER_INT),
'captcha' => $this->getInput('configAdvancedConnectCaptcha',helper::FILTER_BOOLEAN),
],
'i18n' => [
'enable' => $this->getData(['config', 'i18n', 'enable'])
]
]
]);
$this->setData(['config', 'autoBackup', $this->getInput('configAdvancedAutoBackup', helper::FILTER_BOOLEAN)]);
$this->setData(['config', 'maintenance', $this->getInput('configAdvancedMaintenance', helper::FILTER_BOOLEAN)]);
$this->setData(['config', 'cookieConsent', $this->getInput('configAdvancedCookieConsent', helper::FILTER_BOOLEAN)]);
$this->setData(['config', 'favicon', $this->getInput('configAdvancedFavicon')]);
$this->setData(['config', 'faviconDark', $this->getInput('configAdvancedFaviconDark')]);
$this->setData(['config', 'timezone', $this->getInput('configAdvancedTimezone', helper::FILTER_STRING_SHORT, true)]);
$this->setData(['config', 'autoUpdate', $this->getInput('configAdvancedAutoUpdate', helper::FILTER_BOOLEAN)]);
$this->setData(['config', 'autoUpdateHtaccess', $this->getInput('configAdvancedAutoUpdateHtaccess', helper::FILTER_BOOLEAN)]);
// Efface les fichiers de backup lorsque l'option est désactivée
if ($this->getInput('configAdvancedFileBackup', helper::FILTER_BOOLEAN) === false) {
$path = realpath('site/data');
@ -561,14 +518,11 @@ class config extends common {
'sitemapPageLabel' => empty($this->getInput('configSitemapPageLabel', helper::FILTER_STRING_SHORT)) ? 'Plan du site' : $this->getInput('configSitemapPageLabel', helper::FILTER_STRING_SHORT),
'metaDescription' => $this->getInput('configMetaDescription', helper::FILTER_STRING_LONG, true),
'title' => $this->getInput('configTitle', helper::FILTER_STRING_SHORT, true)
]
],
]);
$this->setData(['config', 'i18n', 'enable', $this->getInput('configI18n',helper::FILTER_BOOLEAN) ]);
// Générer robots.txt et sitemap
$this->generateFiles();
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(),
@ -607,6 +561,18 @@ class config extends common {
* Sécurité de la connexion
**/
public function safety() {
// Soumission du formulaire
if($this->isPost()) {
$this->setData([ 'config', 'captchaStrong', $this->getInput('configAdvancedCaptchaStrong',helper::FILTER_BOOLEAN)]);
$this->setData([ 'config', 'autoDisconnect', $this->getInput('configAdvancedAutoDisconnect',helper::FILTER_BOOLEAN)]);
$this->setData([ 'config', 'connect' => [
'attempt' => $this->getInput('configAdvancedConnectAttempt',helper::FILTER_INT),
'timeout' => $this->getInput('configAdvancedConnectTimeout',helper::FILTER_INT),
'log' => $this->getInput('configAdvancedConnectLog',helper::FILTER_BOOLEAN),
'anonymousIp' => $this->getInput('configAdvancedConnectAnonymousIp',helper::FILTER_INT),
'captcha' => $this->getInput('configAdvancedConnectCaptcha',helper::FILTER_BOOLEAN)
]]);
}
// Valeurs en sortie
$this->addOutput([
'title' => 'Configuration avancée',
@ -620,68 +586,31 @@ class config extends common {
public function social() {
// Soumission du formulaire
if($this->isPost()) {
// 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]);
}
// Sauvegarder
$this->setData([
'locale',
[
'homePageId' => $this->getInput('configHomePageId', helper::FILTER_ID, true),
'page404' => $this->getInput('configPage404'),
'page403' => $this->getInput('configPage403'),
'page302' => $this->getInput('configPage302'),
'legalPageId' => $this->getInput('configLegalPageId'),
'searchPageId' => $this->getInput('configSearchPageId'),
'searchPageLabel' => empty($this->getInput('configSearchPageLabel', helper::FILTER_STRING_SHORT)) ? 'Rechercher' : $this->getInput('configSearchPageLabel', helper::FILTER_STRING_SHORT),
'legalPageLabel' => empty($this->getInput('configLegalPageLabel', helper::FILTER_STRING_SHORT)) ? 'Mentions légales' : $this->getInput('configLegalPageLabel', helper::FILTER_STRING_SHORT),
'sitemapPageLabel' => empty($this->getInput('configSitemapPageLabel', helper::FILTER_STRING_SHORT)) ? 'Plan du site' : $this->getInput('configSitemapPageLabel', helper::FILTER_STRING_SHORT),
'metaDescription' => $this->getInput('configMetaDescription', helper::FILTER_STRING_LONG, true),
'title' => $this->getInput('configTitle', helper::FILTER_STRING_SHORT, true)
]
]);
$this->setData([ 'config', 'analyticsId', $this->getInput('configAdvancedAnalyticsId')]);
$this->setData([ 'config', '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')
]]);
$this->setData(['config', 'i18n', 'enable', $this->getInput('configI18n',helper::FILTER_BOOLEAN) ]);
// Générer robots.txt et sitemap
$this->generateFiles();
$this->setData([ 'config', 'seo' => [
'robots' => $this->getInput('configAdvancedSeoRobots',helper::FILTER_BOOLEAN)
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(),
'notification' => 'Modifications enregistrées',
'notification' => 'Modifications enregistrées ' ,
'state' => true
]);
}
// Liste des pages
self::$pagesList = $this->getData(['page']);
foreach(self::$pagesList as $page => $pageId) {
if ($this->getData(['page',$page,'block']) === 'bar' ||
$this->getData(['page',$page,'disable']) === true) {
unset(self::$pagesList[$page]);
}
}
self::$orphansList = $this->getData(['page']);
foreach(self::$orphansList as $page => $pageId) {
if ($this->getData(['page',$page,'block']) === 'bar' ||
$this->getData(['page',$page,'disable']) === true ||
$this->getdata(['page',$page, 'position']) !== 0) {
unset(self::$orphansList[$page]);
}
}
// Valeurs en sortie
$this->addOutput([
'title' => 'Référencement',
@ -696,125 +625,21 @@ class config extends common {
public function network() {
// Soumission du formulaire
if($this->isPost()) {
// 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]);
}
// Eviter déconnexion automatique après son activation
if ( $this->getData(['config','autoDisconnect']) === false
AND $this->getInput('configAdvancedAutoDisconnect',helper::FILTER_BOOLEAN) === true ) {
$this->setData(['user',$this->getuser('id'),'accessCsrf',$_SESSION['csrf']]);
}
// 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),
'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),
'autoDisconnect' => $this->getInput('configAdvancedAutoDisconnect',helper::FILTER_BOOLEAN),
'smtp' => [
'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)
],
'seo' => [
'robots' => $this->getInput('configAdvancedSeoRobots',helper::FILTER_BOOLEAN)
],
'connect' => [
'attempt' => $this->getInput('configAdvancedConnectAttempt',helper::FILTER_INT),
'timeout' => $this->getInput('configAdvancedConnectTimeout',helper::FILTER_INT),
'log' => $this->getInput('configAdvancedConnectLog',helper::FILTER_BOOLEAN),
'anonymousIp' => $this->getInput('configAdvancedConnectAnonymousIp',helper::FILTER_INT),
'captcha' => $this->getInput('configAdvancedConnectCaptcha',helper::FILTER_BOOLEAN),
],
'i18n' => [
'enable' => $this->getData(['config', 'i18n', 'enable'])
]
]
]);
// 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);
}
}
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
$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 .
"\tRewriteCond %{SERVER_PORT} 80" . PHP_EOL .
"\tRewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,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;
}
// Met à jour la baseUrl
$this->setData(['core', 'baseUrl', helper::baseUrl(true,false) ]);
}
// Générer robots.txt et sitemap
$this->generateFiles();
$this->setData([ 'config', 'proxyType', $this->getInput('configAdvancedProxyType')]);
$this->setData([ 'config', 'proxyUrl', $this->getInput('configAdvancedProxyUrl')]);
$this->setData([ 'config', 'proxyUrl', $this->getInput('configAdvancedProxyUrl')]);
$this->setData([ 'config', 'smtp' => [
'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)
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(),

View File

@ -101,30 +101,6 @@
'help' => 'Vérifiez d\'abord que votre serveur autorise l\'URL rewriting (ce qui n\'est pas le cas chez Free).'
]); ?>
</div>
</div>
<div class="row">
<div class="col6">
<?php echo template::checkbox('configAdvancedCaptchaStrong', true, 'Captcha complexe', [
'checked' => $this->getData(['config','captchaStrong']),
'help' => 'Option recommandée pour sécuriser la connexion. S\'applique à tous les captchas du site. Le captcha simple se limite à une addition de nombres de 0 à 10. Le captcha complexe utilise quatre opérations de nombres de 0 à 20. Activation recommandée.'
]); ?>
</div>
<div class="col6">
<?php echo template::checkbox('configAdvancedAutoDisconnect', true, 'Déconnexion automatique de la session', [
'checked' => $this->getData(['config','autoDisconnect']),
'help' => 'Déconnecte les sessions ouvertes précédemment sur d\'autres navigateurs ou terminaux. Activation recommandée.'
]); ?>
</div>
</div>
<div class="row">
<div class="col6">
<?php echo template::checkbox('configAdvancedAutoBackup', true, 'Sauvegarde automatique quotidienne du site', [
'checked' => $this->getData(['config', 'autoBackup']),
'help' => 'Une archive contenant le dossier /site/data est copiée dans le dossier \'site/backup\'. La sauvegarde est conservée pendant 30 jours.</p><p>Les fichiers du site ne sont pas sauvegardés automatiquement. Activation recommandée.'
]); ?>
</div>
</div>
</div>
</div>
@ -167,11 +143,19 @@
<div class="block">
<h4>Maintenance</h4>
<div class="row">
<div class="col3">
<div class="col6">
<?php echo template::checkbox('configAdvancedAutoBackup', true, 'Sauvegarde automatique quotidienne du site', [
'checked' => $this->getData(['config', 'autoBackup']),
'help' => 'Une archive contenant le dossier /site/data est copiée dans le dossier \'site/backup\'. La sauvegarde est conservée pendant 30 jours.</p><p>Les fichiers du site ne sont pas sauvegardés automatiquement. Activation recommandée.'
]); ?>
</div>
<div class="col6">
<?php echo template::checkbox('configAdvancedMaintenance', true, 'Site en maintenance', [
'checked' => $this->getData(['config', 'maintenance'])
]); ?>
</div>
</div>
<div class="rows textAlignCenter">
<div class="col3">
<?php echo template::button('configBackupButton', [
'href' => helper::baseUrl() . 'config/backup',

View File

@ -63,6 +63,25 @@
<div class="col12">
<div class="block">
<h4>Sécurité de la connexion</h4>
<div class="row">
<div class="col4">
<?php echo template::checkbox('configAdvancedConnectCaptcha', true, 'Captcha à la connexion', [
'checked' => $this->getData(['config', 'connect','captcha'])
]); ?>
</div>
<div class="col4">
<?php echo template::checkbox('configAdvancedCaptchaStrong', true, 'Captcha complexe', [
'checked' => $this->getData(['config','captchaStrong']),
'help' => 'Option recommandée pour sécuriser la connexion. S\'applique à tous les captchas du site. Le captcha simple se limite à une addition de nombres de 0 à 10. Le captcha complexe utilise quatre opérations de nombres de 0 à 20. Activation recommandée.'
]); ?>
</div>
<div class="col4">
<?php echo template::checkbox('configAdvancedAutoDisconnect', true, 'Déconnexion automatique', [
'checked' => $this->getData(['config','autoDisconnect']),
'help' => 'Déconnecte les sessions ouvertes précédemment sur d\'autres navigateurs ou terminaux. Activation recommandée.'
]); ?>
</div>
</div>
<div class="row">
<div class="col3">
<?php echo template::select('configAdvancedConnectAttempt', $module::$connectAttempt , [
@ -98,13 +117,6 @@
]); ?>
</div>
</div>
<div class="row">
<div class="col6">
<?php echo template::checkbox('configAdvancedConnectCaptcha', true, 'Captcha à la connexion', [
'checked' => $this->getData(['config', 'connect','captcha'])
]); ?>
</div>
</div>
</div>
</div>
</div>