10.2.dev19 verrou connexion sans userId valide
This commit is contained in:
parent
d74a6e620c
commit
f50e2ab8c2
@ -39,7 +39,7 @@ class common {
|
||||
const ACCESS_TIMER = 1800;
|
||||
|
||||
// Numéro de version
|
||||
const ZWII_VERSION = '10.2.00.dev18';
|
||||
const ZWII_VERSION = '10.2.00.dev19';
|
||||
const ZWII_UPDATE_CHANNEL = "v10";
|
||||
|
||||
public static $actions = [];
|
||||
@ -1589,7 +1589,7 @@ class core extends common {
|
||||
// Journalisation
|
||||
$dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ;
|
||||
$dataLog .= $_SERVER['REMOTE_ADDR'] . ';' ;
|
||||
$dataLog .= $this->getUser('id') . ';' ;
|
||||
$dataLog .= $this->getUser('id') ? $this->getUser('id') . ';' : 'visiteur' . ';';
|
||||
$dataLog .= $this->getUrl();
|
||||
$dataLog .= PHP_EOL;
|
||||
if ($this->getData(['config','connect','log'])) {
|
||||
|
@ -26,7 +26,10 @@ class config extends common {
|
||||
'updateBaseUrl' => self::GROUP_ADMIN,
|
||||
'script' => self::GROUP_ADMIN,
|
||||
'logReset' => self::GROUP_ADMIN,
|
||||
'logDownload'=> self::GROUP_ADMIN
|
||||
'logDownload'=> self::GROUP_ADMIN,
|
||||
'blacklistReset' => self::GROUP_ADMIN,
|
||||
'blacklistDownload' => self::GROUP_ADMIN
|
||||
|
||||
];
|
||||
|
||||
public static $timezones = [
|
||||
@ -603,6 +606,7 @@ class config extends common {
|
||||
*/
|
||||
|
||||
public function logReset() {
|
||||
if ( file_exists(self::DATA_DIR . 'journal.log') ) {
|
||||
unlink(self::DATA_DIR . 'journal.log');
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
@ -611,6 +615,16 @@ class config extends common {
|
||||
'notification' => 'Journal réinitialisé avec succès',
|
||||
'state' => true
|
||||
]);
|
||||
} else {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => 'Configuration',
|
||||
'view' => 'index',
|
||||
'notification' => 'Pas de journal à effacer',
|
||||
'state' => false
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -619,10 +633,7 @@ class config extends common {
|
||||
* Télécharger le fichier de log
|
||||
*/
|
||||
public function logDownload() {
|
||||
// Creation du ZIP
|
||||
$fileName = self::DATA_DIR . 'journal.log';
|
||||
|
||||
// Téléchargement du ZIP
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
||||
header('Content-Length: ' . filesize($fileName));
|
||||
@ -638,6 +649,58 @@ class config extends common {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tableau des IP blacklistés
|
||||
*/
|
||||
public function blacklistDownload () {
|
||||
$d = $this->getData(['blacklist']);
|
||||
$data = '';
|
||||
foreach ($d as $key => $item) {
|
||||
$data .= $key . ';' . $item['ip'] . PHP_EOL;
|
||||
}
|
||||
$fileName = self::TEMP_DIR . 'blacklist.log';
|
||||
file_put_contents($fileName,$data);
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
||||
header('Content-Length: ' . filesize($fileName));
|
||||
readfile( $fileName);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_RAW
|
||||
]);
|
||||
unlink(self::TEMP_DIR . 'blacklist.tmp');
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => 'Configuration',
|
||||
'view' => 'index'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Réinitialiser les ip blacklistées
|
||||
*/
|
||||
|
||||
public function blacklistReset() {
|
||||
if ( file_exists(self::DATA_DIR . 'blacklist.json') ) {
|
||||
unlink(self::DATA_DIR . 'blacklist.json');
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => 'Configuration',
|
||||
'view' => 'index',
|
||||
'notification' => 'Liste noire réinitialisée avec succès',
|
||||
'state' => true
|
||||
]);
|
||||
} else {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => 'Configuration',
|
||||
'view' => 'index',
|
||||
'notification' => 'Pas de liste à effacer',
|
||||
'state' => false
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fonction de parcours des données de module
|
||||
|
@ -350,7 +350,7 @@
|
||||
<div class="row">
|
||||
<div class="col12">
|
||||
<div class="block">
|
||||
<h4>Options avancées</h4>
|
||||
<h4>Sécurité</h4>
|
||||
<div class="row">
|
||||
<div class="col3">
|
||||
<?php echo template::select('configConnectAttempt', $module::$connectAttempt , [
|
||||
@ -364,7 +364,51 @@
|
||||
'selected' => $this->getData(['config', 'connect', 'timeout'])
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3 verticalAlignBottom">
|
||||
<?php echo template::button('configConnectblacListDownload', [
|
||||
'href' => helper::baseUrl() . 'config/blacklistDownload',
|
||||
'value' => 'IP liste noire',
|
||||
'ico' => 'download'
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3 verticalAlignBottom">
|
||||
<?php echo template::button('ConfigConnectReset', [
|
||||
'class' => 'buttonRed',
|
||||
'href' => helper::baseUrl() . 'config/blacklistReset',
|
||||
'value' => 'Réinitialisation liste',
|
||||
'ico' => 'cancel'
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col3 verticalAlignBottom">
|
||||
<?php echo template::checkbox('configConnectLog', true, 'Activer la journalisation', [
|
||||
'checked' => $this->getData(['config', 'connect', 'log'])
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3 offset3">
|
||||
<?php echo template::button('ConfigLogDownload', [
|
||||
'href' => helper::baseUrl() . 'config/logDownload',
|
||||
'value' => 'Téléchargement du journal',
|
||||
'ico' => 'download'
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3">
|
||||
<?php echo template::button('ConfigLogReset', [
|
||||
'class' => 'buttonRed',
|
||||
'href' => helper::baseUrl() . 'config/logReset',
|
||||
'value' => 'Réinitialisation du journal',
|
||||
'ico' => 'cancel'
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col12">
|
||||
<div class="block">
|
||||
<h4>Options de script</h4>
|
||||
<div class="row">
|
||||
<div class="col3">
|
||||
<?php echo template::text('configAnalyticsId', [
|
||||
@ -389,28 +433,6 @@
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col3 verticalAlignBottom">
|
||||
<?php echo template::checkbox('configConnectLog', true, 'Activer la journalisation', [
|
||||
'checked' => $this->getData(['config', 'connect', 'log'])
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3">
|
||||
<?php echo template::button('ConfigLogDownload', [
|
||||
'href' => helper::baseUrl() . 'config/logDownload',
|
||||
'value' => 'Téléchargement du journal',
|
||||
'ico' => 'download'
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3">
|
||||
<?php echo template::button('ConfigLogReset', [
|
||||
'class' => 'buttonRed',
|
||||
'href' => helper::baseUrl() . 'config/logReset',
|
||||
'value' => 'Réinitialisation du journal',
|
||||
'ico' => 'cancel'
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -332,7 +332,7 @@ class user extends common {
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
$userId = $this->getInput('userLoginId', helper::FILTER_ID, true);
|
||||
// le userId n'existe pas
|
||||
// le userId n'existe pas, créer une entré dans la liste noire
|
||||
if( !$this->getData(['user', $userId])) {
|
||||
//Stockage de l'IP
|
||||
$this->setData([
|
||||
@ -343,15 +343,6 @@ class user extends common {
|
||||
'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) ? $this->getData(['blacklist',$userId,'connectFail']) + 1 : 1
|
||||
]
|
||||
]);
|
||||
// Après les tentatives autorisées, bloquer l'IP.
|
||||
if ( $this->getData(['blacklist',$userId,'connectFail']) > $this->getData(['config', 'connect', 'attempt']) ||
|
||||
array_search($_SERVER['REMOTE_ADDR'],helper::arrayCollumn($this->getData(['blacklist']), 'ip')) ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl(),
|
||||
'state' => false
|
||||
]);
|
||||
}
|
||||
}
|
||||
// Contrôle du timeout pas de vérification du mot de passe si le temps est dépassé.
|
||||
// Connexion si les informations sont correctes
|
||||
@ -389,10 +380,9 @@ class user extends common {
|
||||
}
|
||||
// Sinon notification d'échec
|
||||
else {
|
||||
// Incrémenter le compteur d'échec de connexion si l'utilisateur existe
|
||||
// L'utilisateur existe : incrémenter le compteur d'échec de connexion
|
||||
if ( is_array($this->getdata(['user',$userId])) ) {
|
||||
$this->setData(['user',$userId,'connectFail',$this->getdata(['user',$userId,'connectFail']) + 1 ]);
|
||||
}
|
||||
// Mettre à jour le timer et notifier
|
||||
if ( $this->getdata(['user',$userId,'connectFail']) > $this->getData(['config', 'connect', 'attempt'])) {
|
||||
$notification = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.';
|
||||
@ -403,6 +393,15 @@ class user extends common {
|
||||
} else {
|
||||
$notification = 'Identifiant ou mot de passe incorrect';
|
||||
}
|
||||
// L'utilisateur n'existe pas
|
||||
// Bloquer l'IP après les tentatives autorisées,
|
||||
} elseif (
|
||||
$this->getData(['blacklist',$userId,'connectFail']) > $this->getData(['config', 'connect', 'attempt']) ||
|
||||
array_search($_SERVER['REMOTE_ADDR'],helper::arrayCollumn($this->getData(['blacklist']), 'ip'))
|
||||
) {
|
||||
$notification = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.';
|
||||
}
|
||||
|
||||
// Journalisation
|
||||
$dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ;
|
||||
$dataLog .= $_SERVER['REMOTE_ADDR'] . ';' ;
|
||||
|
Loading…
Reference in New Issue
Block a user