Added user agent to log method

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2023-12-14 14:33:39 +00:00
parent 70303c2b2d
commit 40052e99a7

View file

@ -266,6 +266,9 @@ class Actionlog extends SnipeModel
public function logaction($actiontype)
{
$this->action_type = $actiontype;
$this->remote_ip = request()->ip();
$this->user_agent = request()->header('User-Agent');
$this->action_source = $this->determineActionSource();
if ($this->save()) {
return true;
@ -330,4 +333,22 @@ class Actionlog extends SnipeModel
->orderBy('created_at', 'asc')
->get();
}
public function determineActionSource() {
// This is an API call
if (((request()->header('content-type') && (request()->header('accept'))=='application/json'))
&& (starts_with(request()->header('authorization'), 'Bearer '))) {
return 'api';
}
// This is probably NOT an API call
if (request()->filled('_token')) {
return 'gui';
}
// We're not sure, probably cli
return 'cli/unknown';
}
}