private static function GetPDOType($str)
 {
     switch ($str) {
         case 'null':
             return PDO::PARAM_NULL;
             break;
         case 'bool':
             return PDO::PARAM_BOOL;
             break;
         case 'int':
             return PDO::PARAM_INT;
             break;
         case 'str':
             return PDO::PARAM_STR;
             break;
         case 'lob':
             return PDO::PARAM_LOB;
             break;
     }
     ul_fail('Unknown data type $str.');
     return 0;
 }
 public static function GetRemoteIP($trustHeaders = false)
 {
     $ip = '';
     if (strlen(UL_PROXY_HEADER) == 0) {
         if ($trustHeaders) {
             if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                 $ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2);
                 $ip = $ip[0];
                 if (self::ValidateIP($ip)) {
                     return $ip;
                 } else {
                     $ip = '';
                 }
             }
             if (!empty($_SERVER['HTTP_CLIENT_IP']) && self::ValidateIP($_SERVER['HTTP_CLIENT_IP'])) {
                 return $_SERVER['HTTP_CLIENT_IP'];
             }
             if (!empty($_SERVER['HTTP_X_FORWARDED']) && self::ValidateIP($_SERVER['HTTP_X_FORWARDED'])) {
                 return $_SERVER['HTTP_X_FORWARDED'];
             }
             if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && self::ValidateIP($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
                 return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
             }
             if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && self::ValidateIP($_SERVER['HTTP_FORWARDED_FOR'])) {
                 return $_SERVER['HTTP_FORWARDED_FOR'];
             }
             if (!empty($_SERVER['HTTP_FORWARDED']) && self::ValidateIP($_SERVER['HTTP_FORWARDED'])) {
                 return $_SERVER['HTTP_FORWARDED'];
             }
         }
         if (empty($ip)) {
             $ip = $_SERVER['REMOTE_ADDR'];
         }
         return $ip;
     } else {
         if (empty($_SERVER[UL_PROXY_HEADER])) {
             // This should really not happen, because if UL_PROXY_HEADER is set
             // it means by definition that all HTTP requests must have this header.
             ul_fail('Unexpected HTTP request.');
             return false;
         }
         $ip = explode(',', $_SERVER[UL_PROXY_HEADER]);
         if ($trustHeaders) {
             return $ip[0];
         } else {
             return end($ip);
         }
     }
 }
 private function BlockCheck($uid)
 {
     // Check if the IP is blocked
     if (UL_BF_IP_LOCKOUT > 0) {
         $block_expires = ulIpBlocker::IpBlocked(ulUtils::GetRemoteIP(false));
         if ($block_expires == false) {
             ul_fail('Failure during login, cannot get block status.');
             return false;
         }
         if ($block_expires > date_create('now')) {
             // IP is blocked
             return false;
         }
     }
     // Check if the user is blocked
     if (UL_BF_USER_LOCKOUT > 0) {
         $block_expires = $this->Backend->UserBlocked($uid);
         if (!is_object($block_expires) || get_class($block_expires) != 'DateTime') {
             ul_fail('Failure during login, cannot get block status.');
             return false;
         }
         if ($block_expires > date_create('now')) {
             // User is blocked
             return false;
         }
     }
     return true;
 }
 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;
 }
function sses_start($sid_regen_prob = UL_SESSION_REGEN_PROB)
{
    ulLog::DebugLog('Session start requested by host.', 0);
    if (!ulSessionManager::sessionStart($sid_regen_prob)) {
        // ulSessionManager::sessionStart does not start a new session
        // if it invalidated an old one. So we call it one more time
        // to actually try to start a new session.
        if (!ulSessionManager::sessionStart($sid_regen_prob)) {
            ulLog::DebugLog('Cannot start uLogin session.', 5);
            ul_fail('Cannot start session.');
            return false;
        }
        return true;
    } else {
        ulSessionManager::$TrustInvalidated = false;
    }
    return true;
}
 public static function DateTimeFromLdap($ldapTime)
 {
     $year = intval(substr($ldapTime, 0, 4));
     $month = intval(substr($ldapTime, 4, 2));
     $day = intval(substr($ldapTime, 6, 2));
     $hour = intval(substr($ldapTime, 8, 2));
     $minute = intval(substr($ldapTime, 10, 2));
     $sec = intval(substr($ldapTime, 12, 2));
     // Remove parts we have already processed
     // This will prevent us from having to keep track of the position in the string.
     $ldapTime = substr($ldapTime, 15);
     // Parse optional fraction
     $fraction = 0;
     if ($ldapTime[14] == '.' || $ldapTime[14] == ',') {
         $fraction = $ldapTime[15];
         $ldapTime = substr($ldapTime, 2);
     }
     $dt = new DateTime();
     $dt->setDate($year, $month, $day);
     $dt->setTime($hour, $minute, $sec);
     if (strlen($ldapTime) == 0) {
         // End of string, local timezone
     } else {
         if ($ldapTime[0] == '+' || $ldapTime[0] == '-') {
             // Local timezone
             //$offsetHour = substr($ldapTime, 1, 2);
             //$offsetMinute = substr($ldapTime, 3, 2);
         } else {
             if ($ldapTime[0] == 'Z') {
                 // UTC, convert to local
                 $offset = date('Z');
                 $di = new DateInterval("PT{$offsetS}");
                 $dt = $dt->add($di);
             } else {
                 ul_fail('Unsupported or corrupt datetime format.');
                 return false;
             }
         }
     }
     return $dt;
 }