Skip to content

Commit

Permalink
logging ip addresses with other log info
Browse files Browse the repository at this point in the history
  • Loading branch information
MelonSmasher committed Dec 12, 2017
1 parent b80207f commit fd68fe1
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 100 deletions.
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AccountCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function __construct(Account $account)
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if (auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AccountDestroyed.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function __construct(Account $account)
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if (auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AccountRestored.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function __construct(Account $account)
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if (auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AccountUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function __construct(Account $account)
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if (auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AccountViewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function __construct(Account $account)
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AccountsViewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public function __construct($accountIds = [])
'account_ids' => $accountIds,
'account_id_count' => count($accountIds),
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AssignedCourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function __construct(Account $account, Course $course)
'course_code' => $course->code,
'course_label' => $course->label,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AssignedDepartment.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function __construct(Account $account, Department $department)
'department_code' => $department->code,
'department_label' => $department->label,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];


Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AssignedDuty.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public function __construct(Account $account, Duty $duty)
'duty_code' => $duty->code,
'duty_label' => $duty->label,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AssignedRoom.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function __construct(Account $account, Room $room)
'room_number' => $room->room_number,
'room_building_label' => $room->building->label,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/AssignedSchool.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function __construct(Account $account, School $school)
'school_code' => $school->code,
'school_label' => $school->label,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/UnassignedCourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function __construct(Account $account, Course $course)
'course_code' => $course->code,
'course_label' => $course->label,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/UnassignedDepartment.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function __construct(Account $account, Department $department)
'course_code' => $department->code,
'course_label' => $department->label,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/UnassignedDuty.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function __construct(Account $account, Duty $duty)
'duty_code' => $duty->code,
'duty_label' => $duty->label,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/UnassignedRoom.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function __construct(Account $account, Room $room)
'room_code' => $room->code,
'room_label' => $room->label,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Account/UnassignedSchool.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function __construct(Account $account, School $school)
'school_code' => $school->code,
'school_label' => $school->label,
'requester_id' => 0,
'requester_name' => 'System'
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

if ($user = auth()->user()) {
Expand Down
9 changes: 2 additions & 7 deletions app/Events/Api/Authentication/AuthenticationFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@ class AuthenticationFailure extends Event
public function __construct(Request $request)
{

$ip = \Request::ip();
$proxyIP = null;
if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
$proxyIP = $ip;
$ip = $_SERVER['HTTP_X_REAL_IP'];
}
$ip = getRequestIP();

$logMessage = $ip . ' failed to authenticated with the API - ';
$logContext = [
'proxy_ip' => $proxyIP,
'proxy_ip' => getRequestIP(true),
'requester_ip' => $ip,
'request' => $request->toArray()
];
Expand Down
4 changes: 3 additions & 1 deletion app/Events/Api/Authentication/AuthenticationSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function __construct(User $user)
$logMessage = $user->name . ' authenticated with the API - ';
$logContext = [
'requester_id' => $user->id,
'requester_name' => $user->name
'requester_name' => $user->name,
'requester_ip' => getRequestIP(),
'proxy_ip' => getRequestIP(true)
];

Log::info($logMessage, $logContext);
Expand Down
174 changes: 98 additions & 76 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,82 +8,81 @@
* Global helpers file with misc functions
*/

if (! function_exists('app_name')) {
/**
* Helper to grab the application name
*
* @return mixed
*/
function app_name()
{
return config('app.name');
}
}

if (! function_exists('access')) {
/**
* Access (lol) the Access:: facade as a simple function
*/
function access()
{
return app('access');
}
}

if ( ! function_exists('history'))
{
/**
* Access the history facade anywhere
*/
function history()
{
return app('history');
}
}

if (! function_exists('gravatar')) {
/**
* Access the gravatar helper
*/
function gravatar()
{
return app('gravatar');
}
}

if (! function_exists('getFallbackLocale')) {
/**
* Get the fallback locale
*
* @return \Illuminate\Foundation\Application|mixed
*/
function getFallbackLocale()
{
return config('app.fallback_locale');
}
}

if (! function_exists('getLanguageBlock')) {

/**
* Get the language block with a fallback
*
* @param $view
* @param array $data
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
function getLanguageBlock($view, $data = [])
{
$components = explode("lang", $view);
$current = $components[0]."lang.".app()->getLocale().".".$components[1];
$fallback = $components[0]."lang.".getFallbackLocale().".".$components[1];

if (view()->exists($current)) {
return view($current, $data);
} else {
return view($fallback, $data);
}
}
if (!function_exists('app_name')) {
/**
* Helper to grab the application name
*
* @return mixed
*/
function app_name()
{
return config('app.name');
}
}

if (!function_exists('access')) {
/**
* Access (lol) the Access:: facade as a simple function
*/
function access()
{
return app('access');
}
}

if (!function_exists('history')) {
/**
* Access the history facade anywhere
*/
function history()
{
return app('history');
}
}

if (!function_exists('gravatar')) {
/**
* Access the gravatar helper
*/
function gravatar()
{
return app('gravatar');
}
}

if (!function_exists('getFallbackLocale')) {
/**
* Get the fallback locale
*
* @return \Illuminate\Foundation\Application|mixed
*/
function getFallbackLocale()
{
return config('app.fallback_locale');
}
}

if (!function_exists('getLanguageBlock')) {

/**
* Get the language block with a fallback
*
* @param $view
* @param array $data
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
function getLanguageBlock($view, $data = [])
{
$components = explode("lang", $view);
$current = $components[0] . "lang." . app()->getLocale() . "." . $components[1];
$fallback = $components[0] . "lang." . getFallbackLocale() . "." . $components[1];

if (view()->exists($current)) {
return view($current, $data);
} else {
return view($fallback, $data);
}
}
}

/**
Expand Down Expand Up @@ -966,4 +965,27 @@ function ($message) use ($full_name, $from_address, $to_address, $subject) {
->to($to_address, $full_name)
->subject($subject);
});
}

/**
* @param bool $ofProxy
* @return string
*/
function getRequestIP($ofProxy = false)
{
$ip = \Request::ip();

if (!$ofProxy) {
if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} else if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
$ip = $_SERVER['HTTP_X_REAL_IP'];
}
} else {
if (empty($_SERVER['HTTP_X_REAL_IP'])) {
$ip = null;
}
}

return $ip;
}

0 comments on commit fd68fe1

Please sign in to comment.