Skip to content
Permalink
Browse files

Limit API connection "Login" logs to one per hour, otherwise it fills…

… the log table, and makes the analytics quite slow.
  • Loading branch information...
cdujeu committed May 1, 2015
1 parent b0d01aa commit 8346673be5cba86ab5413e88d170ca913610e9ee
Showing with 18 additions and 0 deletions.
  1. +18 −0 core/src/plugins/log.sql/class.sqlLogDriver.php
@@ -252,6 +252,24 @@ public function formatXmlLogItem($node, $icon, $dateattrib, $filename, $remote_i
*/
public function write2($level, $ip, $user, $source, $prefix, $message)
{
if($prefix == "Log In" && $message="context=API"){
// Limit the number of logs
$test = dibi::query('SELECT [logdate] FROM [ajxp_log] WHERE [user]=%s AND [message]=%s AND [params]=%s ORDER BY [logdate] DESC LIMIT 0,1', $user, $prefix, $message);
$lastInsert = $test->fetchSingle();
$now = new DateTime('NOW');
if(is_a($lastInsert, "DibiDateTime")){
$lastTimestamp = $lastInsert->getTimestamp();
}else{
$lastTimestamp = strtotime($lastInsert);
}
if($lastInsert !== false && $now->getTimestamp() - $lastTimestamp < 60 * 60){
// IGNORING, LIMIT API LOGINS TO ONE PER HOUR, OR IT WILL FILL THE LOGS
return;
}
}
if(AJXP_Utils::detectXSS($message)){
$message = "XSS Detected in Message!";
}
$log_row = Array(
'logdate' => new DateTime('NOW'),
'remote_ip' => $this->inet_ptod($ip),

0 comments on commit 8346673

Please sign in to comment.
You can’t perform that action at this time.