public static function Clean()
 {
     // We have found a nonce, invalidate it
     $now = ulUtils::nowstring();
     $stmt = ulPdoDb::Prepare('session', 'DELETE FROM ul_nonces WHERE nonce_expires<?');
     if (!ulPdoDb::BindExec($stmt, NULL, array(&$now, 'str'))) {
         ul_db_fail();
         return false;
     }
     return true;
 }
 public static function IpBlocked($ip)
 {
     $block_expires = NULL;
     $stmt = ulPdoDb::Prepare('log', 'SELECT block_expires FROM ul_blocked_ips WHERE ip=?');
     if (!ulPdoDb::BindExec($stmt, array(&$block_expires, 'str'), array(&$ip, 'str'))) {
         ul_db_fail();
         return false;
     }
     if (ulPdoDb::Fetch($stmt)) {
         $block_expires = new DateTime($block_expires);
         if ($block_expires <= date_create('now')) {
             self::SetBlock($ip, 0);
         }
     } else {
         $block_expires = new DateTime('1000 years ago');
     }
     return $block_expires;
 }
Esempio n. 3
0
 public static function TableExists($dbuser, $table_name)
 {
     self::Connect($dbuser);
     // Add compatible syntax for sqlite
     $query = self::$dbcon->getAttribute(PDO::ATTR_DRIVER_NAME) === 'sqlite' ? 'SELECT name FROM sqlite_master WHERE type = "table" AND name = ?' : 'SHOW TABLES LIKE ?';
     $stmt = ulPdoDb::Prepare($dbuser, $query);
     if (false === $stmt) {
         ul_db_fail();
     }
     if (!ulPdoDb::BindExec($stmt, NULL, array(&$table_name, 'str'))) {
         return false;
     }
     if (!ulPdoDb::Fetch($stmt)) {
         return false;
     }
     return true;
 }
Esempio n. 4
0
 public static function GetIpLastLoginAgo($ip)
 {
     if (UL_LOG == false) {
         // We don't have the required information
         return false;
     }
     // Get the number of login attempts to an account
     $last_login = '';
     $stmt = ulPdoDb::Prepare('log', "SELECT timestamp FROM ul_log WHERE ip=? AND action='auth-success' ORDER BY timestamp DESC LIMIT 1");
     if (!ulPdoDb::BindExec($stmt, array(&$last_login, 'str'), array(&$ip, 'str'))) {
         return false;
     }
     if (!ulPdoDb::Fetch($stmt)) {
         // No successful login yet or no such user.
         return false;
     }
     return time() - strtotime($last_login);
 }
function CheckDBTables()
{
    return ulPdoDb::TableExists('session', 'ul_sessions') && ulPdoDb::TableExists('log', 'ul_blocked_ips') && ulPdoDb::TableExists('log', 'ul_log') && ulPdoDb::TableExists('session', 'ul_nonces');
}
 public function gc()
 {
     $now = ulUtils::nowstring();
     // Delete old sessions
     $stmt = ulPdoDb::Prepare('session', 'DELETE FROM ul_sessions WHERE session_expires<=?');
     ulPdoDb::BindExec($stmt, NULL, array(&$now, 'str'));
     return true;
 }
 protected function UserBlockExpires($uid, &$flagged)
 {
     $expires = NULL;
     $flagged = false;
     $stmt = ulPdoDb::Prepare('auth', 'SELECT block_expires FROM ul_logins WHERE id=?');
     if (!ulPdoDb::BindExec($stmt, array(&$expires, 'str'), array(&$uid, 'int'))) {
         ul_db_fail();
         return ulLoginBackend::BACKEND_ERROR;
     }
     if (!ulPdoDb::Fetch($stmt)) {
         return ulLoginBackend::NO_SUCH_USER;
     }
     return new DateTime($expires);
 }