public static function Exists($action)
 {
     // See if there is a nonce like the one requested
     $exists = 0;
     $stmt = ulPdoDb::Prepare('session', 'SELECT COUNT(*) FROM ul_nonces WHERE action=?');
     if (!ulPdoDb::BindExec($stmt, array(&$exists, 'int'), array(&$action, 'str'))) {
         ul_db_fail();
         return false;
     }
     ulPdoDb::Fetch($stmt);
     return $exists > 0;
 }
 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;
 }
Example #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;
 }
Example #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);
 }
 public function read($id)
 {
     if ($this->Lock($id) != true) {
         return false;
     }
     // Even if we don't have data, we need to return an empty string
     $data = '';
     // Read database
     $now = ulUtils::nowstring();
     $stmt = ulPdoDb::Prepare('session', 'SELECT data FROM ul_sessions WHERE id=? AND session_expires>?');
     if (!ulPdoDb::BindExec($stmt, array(&$data, 'lob'), array(&$id, 'str', &$now, 'str'))) {
         ul_db_fail('Session management error.');
         return false;
     }
     if (!ulPdoDb::Fetch($stmt)) {
         ul_fail('Error reading session.');
         return false;
     }
     return $data;
 }
 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);
 }