I’m sorry, you are not logged in.
$active_device_id, (string) get_user_meta($user->ID, self::TOKEN_DEVICE_NAME_META_KEY, true) ); return false; } private static function record_device_security_event( WP_User $user, $event_type, $device_id, $device_name, $previous_device_id, $previous_device_name ) { $event = array( 'type' => sanitize_key($event_type), 'time' => time(), 'user_id' => (int) $user->ID, 'user_email' => $user->user_email, 'device_id' => sanitize_text_field((string) $device_id), 'device_name' => sanitize_text_field((string) $device_name), 'previous_device_id' => sanitize_text_field((string) $previous_device_id), 'previous_device_name' => sanitize_text_field((string) $previous_device_name), 'ip' => self::get_request_ip(), 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field((string) $_SERVER['HTTP_USER_AGENT']) : '', ); $log = get_user_meta($user->ID, self::DEVICE_LOGIN_LOG_META_KEY, true); if (!is_array($log)) { $log = array(); } array_unshift($log, $event); $log = array_slice($log, 0, 25); update_user_meta($user->ID, self::DEVICE_LOGIN_LOG_META_KEY, $log); self::notify_admin_of_device_security_event($event); } private static function notify_admin_of_device_security_event($event) { $admin_email = get_option('admin_email'); if (empty($admin_email) || !is_email($admin_email)) { return; } $subject = '[Havasu Scanner Feed] Possible account sharing'; $message = "A mobile account security event was recorded.\n\n"; $message .= 'Event: ' . $event['type'] . "\n"; $message .= 'Member: ' . $event['user_email'] . ' (user ID ' . $event['user_id'] . ")\n"; $message .= 'New/requesting device: ' . $event['device_name'] . ' [' . $event['device_id'] . "]\n"; $message .= 'Previous/active device: ' . $event['previous_device_name'] . ' [' . $event['previous_device_id'] . "]\n"; $message .= 'IP: ' . $event['ip'] . "\n"; $message .= 'User agent: ' . $event['user_agent'] . "\n"; $message .= 'Time: ' . gmdate('Y-m-d H:i:s', (int) $event['time']) . " UTC\n\n"; $message .= 'The newest login remains the only active app session for this member.'; wp_mail($admin_email, $subject, $message); } private static function get_request_ip() { $keys = array('HTTP_CF_CONNECTING_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR'); foreach ($keys as $key) { if (empty($_SERVER[$key])) { continue; } $value = sanitize_text_field((string) $_SERVER[$key]); $parts = explode(',', $value); $ip = trim($parts[0]); if (!empty($ip)) { return $ip; } } return ''; } private static function generate_token() { return bin2hex(random_bytes(32)); } private static function hash_token($token) { return hash('sha256', $token); } private static function get_user_from_request(WP_REST_Request $request) { $token = self::get_bearer_token(); if (empty($token)) { $token = sanitize_text_field($request->get_param('token')); } if (empty($token)) { return false; } $token_hash = self::hash_token($token); $users = get_users(array( 'meta_key' => self::TOKEN_META_KEY, 'meta_value' => $token_hash, 'number' => 1, 'fields' => 'all', )); if (empty($users)) { return false; } if (!self::request_matches_active_device($request, $users[0])) { return false; } return $users[0]; } private static function get_bearer_token() { $headers = array(); if (function_exists('getallheaders')) { $headers = getallheaders(); } $authorization = ''; if (!empty($headers['Authorization'])) { $authorization = $headers['Authorization']; } elseif (!empty($headers['authorization'])) { $authorization = $headers['authorization']; } elseif (!empty($_SERVER['HTTP_AUTHORIZATION'])) { $authorization = $_SERVER['HTTP_AUTHORIZATION']; } elseif (!empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) { $authorization = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; } if (preg_match('/Bearer\s+(.*)$/i', $authorization, $matches)) { return trim($matches[1]); } return ''; } } HSF_Mobile_API::init();
I’m sorry, you are not logged in.