10.2 Optimisation script protection login + journalisation IP

This commit is contained in:
Fred Tempez 2020-06-27 16:21:22 +02:00
parent ff4d03c18a
commit 9579315407
5 changed files with 49 additions and 20 deletions

View File

@ -17,6 +17,27 @@ class helper {
const FILTER_TIMESTAMP = 10;
const FILTER_URL = 11;
/**
* Récupérer l'adresse IP sans tenit compte du proxy
* @return string IP adress
* Cette focntion est utilisé par user
*/
public static function getIp() {
if(!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
/**
* Fonction pour récupérer le numéro de version en ligne
* @param string $url à récupérer

View File

@ -225,7 +225,7 @@ core.start = function() {
if(document.cookie.indexOf("ZWII_COOKIE_CONSENT") === -1) {
$("body").append(
$("<div>").attr("id", "cookieConsent").append(
$("<span>").text("En poursuivant votre navigation sur ce site, vous acceptez l'utilisation de cookies."),
$("<span>").text("En poursuivant votre navigation sur ce site, vous acceptez l'utilisation de cookies et de vos données de visite."),
$("<span>")
.attr("id", "cookieConsentConfirm")
.text("OK")

View File

@ -1331,7 +1331,7 @@ class common {
unlink(self::DATA_DIR . 'theme.css');
}
// Créer les en-têtes du journal
$d = 'Date;Heure;Id;Action' . PHP_EOL;
$d = 'Date;Heure;IP;Id;Action' . PHP_EOL;
file_put_contents(self::DATA_DIR . 'journal.log',$d);
// Init préservation htaccess
$this->setData(['config','autoUpdateHtaccess',false]);
@ -1352,7 +1352,6 @@ class common {
$this->setData(['theme','menu','memberBar',true]);
$this->deleteData(['theme','footer','displayMemberAccount']);
$this->deleteData(['theme','footer','displayMemberLogout']);
$this->setData(['core', 'dataVersion', 10201]);
}
}
@ -1634,6 +1633,7 @@ class core extends common {
}
// Journalisation
$dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ;
$dataLog .= helper::getIp() . ';';
$dataLog .= $this->getUser('id') ? $this->getUser('id') . ';' : 'anonyme' . ';';
$dataLog .= $this->getUrl();
$dataLog .= PHP_EOL;

View File

@ -612,7 +612,7 @@ class config extends common {
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;Id;Action' . PHP_EOL;
$d = 'Date;Heure;IP;Id;Action' . PHP_EOL;
file_put_contents(self::DATA_DIR . 'journal.log',$d);
// Valeurs en sortie
$this->addOutput([

View File

@ -349,18 +349,25 @@ class user extends common {
[
'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) + 1,
'lastFail' => time(),
'ip' => $_SERVER['REMOTE_ADDR']
'ip' => helper::getIp()
]
]);
if ( $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt']) ) {
$notification = 'Trop de tentatives, compte verrouillé';
} else {
$notification = 'Identifiant ou mot de passe incorrect';
}
// Verrouillage des IP
$ipBlackList = helper::arrayCollumn($this->getData(['blacklist']), 'ip');
if ( $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt'])
OR in_array($this->getData(['blacklist',$userId,'ip']),$ipBlackList) ) {
// Valeurs en sortie
$this->addOutput([
'notification' => $notification
'notification' => 'Trop de tentatives, compte verrouillé',
'redirect' => helper::baseUrl(),
'state' => false
]);
} else {
// Valeurs en sortie
$this->addOutput([
'notification' => 'Identifiant ou mot de passe incorrect'
]);
}
/**
* Le compte existe
*/
@ -419,6 +426,7 @@ class user extends common {
}
// Journalisation
$dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ;
$dataLog .= helper::getIp() . ';';
$dataLog .= $userId . ';' ;
$dataLog .= $this->getUrl() .';' ;
$dataLog .= 'échec de connexion' ;