-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
11 changed files
with
171 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,17 @@ class Actionlog extends SnipeModel | |
|
||
protected $table = 'action_logs'; | ||
public $timestamps = true; | ||
protected $fillable = ['created_at', 'item_type', 'user_id', 'item_id', 'action_type', 'note', 'target_id', 'target_type', 'stored_eula']; | ||
protected $fillable = [ | ||
'created_at', | ||
'item_type', | ||
'user_id', | ||
'item_id', | ||
'action_type', | ||
'note', | ||
'target_id', | ||
'target_type', | ||
'stored_eula' | ||
]; | ||
|
||
use Searchable; | ||
|
||
|
@@ -34,7 +44,15 @@ class Actionlog extends SnipeModel | |
* | ||
* @var array | ||
*/ | ||
protected $searchableAttributes = ['action_type', 'note', 'log_meta','user_id']; | ||
protected $searchableAttributes = [ | ||
'action_type', | ||
'note', | ||
'log_meta', | ||
'user_id', | ||
'remote_ip', | ||
'user_agent', | ||
'action_source' | ||
]; | ||
|
||
/** | ||
* The relations and their attributes that should be included when searching the model. | ||
|
@@ -248,6 +266,9 @@ public function get_src($type = 'assets', $fieldname = 'filename') | |
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; | ||
|
@@ -312,4 +333,29 @@ public function getListingOfActionLogsChronologicalOrder() | |
->orderBy('created_at', 'asc') | ||
->get(); | ||
} | ||
|
||
/** | ||
* Determines what the type of request is so we can log it to the action_log | ||
* | ||
* @author A. Gianotto <[email protected]> | ||
* @since v6.3.0 | ||
* @return string | ||
*/ | ||
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'; | ||
|
||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
database/migrations/2023_12_14_032522_add_remote_ip_and_action_source_to_action_logs.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class AddRemoteIpAndActionSourceToActionLogs extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('action_logs', function (Blueprint $table) { | ||
$table->string('action_source')->nullable()->default(null); | ||
$table->ipAddress('remote_ip')->nullable()->default(null); | ||
$table->string('user_agent')->nullable()->default(null); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('action_logs', function (Blueprint $table) { | ||
if (Schema::hasColumn('action_logs', 'action_source')) { | ||
$table->dropColumn('action_source'); | ||
} | ||
if (Schema::hasColumn('action_logs', 'remote_ip')) { | ||
$table->dropColumn('remote_ip'); | ||
} | ||
if (Schema::hasColumn('action_logs', 'user_agent')) { | ||
$table->dropColumn('user_agent'); | ||
} | ||
}); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
database/migrations/2023_12_15_024643_add_indexes_to_new_activity_report_fields.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class AddIndexesToNewActivityReportFields extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('action_logs', function (Blueprint $table) { | ||
$table->index('action_type'); | ||
$table->index('remote_ip'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('action_logs', function (Blueprint $table) { | ||
$table->dropIndex(['action_type']); | ||
$table->dropIndex(['remote_ip']); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters