Skip to content

Commit

Permalink
Fix getting unixtimestamp field in sqlite.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsoares committed May 12, 2018
1 parent 9ac9d10 commit 8f574e4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rcguard.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ public function loginform($loginform)

if ($failed_attempts > 0) {
$query = sprintf(
"SELECT %s AS last, %s AS time FROM %s WHERE ip = ? AND hits >= ?",
"SELECT %s AS lasttime, %s AS nowtime FROM %s WHERE ip = ? AND hits >= ?",
$this->unixtimestamp('last'), $this->unixtimestamp('NOW()'),
$this->table_name
);

$query = $rcmail->db->query($query, $client_ip, $failed_attempts);
$query = $rcmail->db->query($query, $client_ip, $failed_attempts);
$result = $rcmail->db->fetch_assoc($query);
$expire = $rcmail->config->get('expire_time');
$expire = intval($rcmail->config->get('expire_time')) * 60;

if ($result && $result['last'] + $expire * 60 < $result['time']) {
if ($result && $result['lasttime'] + $expire < $result['nowtime']) {
$this->flush_rcguard();
$result = 0;
}
Expand Down Expand Up @@ -186,7 +186,7 @@ private function flush_rcguard()
$rcmail->db->query(
"DELETE FROM ".$this->table_name . " WHERE " .
$this->unixtimestamp('last') . " + ? < " . $this->unixtimestamp('NOW()'),
$rcmail->config->get('expire_time') * 60
intval($rcmail->config->get('expire_time')) * 60
);
}

Expand All @@ -196,10 +196,10 @@ private function unixtimestamp($field)

switch ($rcmail->db->db_provider) {
case 'sqlite':
$field = preg_replace('/now\(\)/i', "'now'", $field);
$ts = "strftime('%s', $field)";
$ts = (stripos($field, 'NOW()') !== false) ? $this->unixnow() : $field;
break;
case 'pgsql':
case 'postgres':
$ts = "EXTRACT (EPOCH FROM $field)";
break;
default:
Expand Down

0 comments on commit 8f574e4

Please sign in to comment.