Skip to content

Commit

Permalink
Merge pull request #123 from kykaalvi/forwarded-ip-address-logging
Browse files Browse the repository at this point in the history
Check if the Request IP Address is forwarded or using cloudflare
  • Loading branch information
jeremykenedy authored Jul 24, 2021
2 parents 52fb752 + bdc34d4 commit d59c065
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/App/Http/Traits/ActivityLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function activity($description = null, $details = null)
if (Crawler::isCrawler()) {
$userType = trans('LaravelLogger::laravel-logger.userTypes.crawler');
if (is_null($description)) {
$description = $userType.' '.trans('LaravelLogger::laravel-logger.verbTypes.crawled').' '.Request::fullUrl();
$description = $userType . ' ' . trans('LaravelLogger::laravel-logger.verbTypes.crawled') . ' ' . Request::fullUrl();
}
}

Expand All @@ -57,7 +57,15 @@ public static function activity($description = null, $details = null)
break;
}

$description = $verb.' '.Request::path();
$description = $verb . ' ' . Request::path();
}

if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$ip = $_SERVER["HTTP_CF_CONNECTING_IP"];
} elseif (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
$ip = Request::ip();
}

$data = [
Expand All @@ -66,7 +74,7 @@ public static function activity($description = null, $details = null)
'userType' => $userType,
'userId' => $userId,
'route' => Request::fullUrl(),
'ipAddress' => Request::ip(),
'ipAddress' => $ip,
'userAgent' => Request::header('user-agent'),
'locale' => Request::header('accept-language'),
'referer' => Request::header('referer'),
Expand All @@ -78,7 +86,7 @@ public static function activity($description = null, $details = null)
if ($validator->fails()) {
$errors = self::prepareErrorMessage($validator->errors(), $data);
if (config('LaravelLogger.logDBActivityLogFailuresToFile')) {
Log::error('Failed to record activity event. Failed Validation: '.$errors);
Log::error('Failed to record activity event. Failed Validation: ' . $errors);
}
} else {
self::storeActivity($data);
Expand Down

0 comments on commit d59c065

Please sign in to comment.