Skip to content

Commit e5148f1

Browse files
committed
project to repo
0 parents  commit e5148f1

30 files changed

+2013
-0
lines changed

.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### OSX BOOGERS ###
2+
.DS_Store
3+
*._DS_Store
4+
._.DS_Store
5+
*._
6+
._*
7+
._.*
8+
9+
### WINDOWS BOOGERS ###
10+
Thumbs.db
11+
12+
### Sass ###
13+
/.sass-cache/*
14+
.sass-cache
15+
16+
### SUBLIMETEXT BOOGERS ###
17+
*.sublime-workspace
18+
19+
### PHPSTORM BOOGERS ###
20+
.idea/*
21+
/.idea/*
22+
23+
### DIFFERENT TYPE OF MASTER CONFIGS ###
24+
composer.lock
25+
composer.phar
26+
27+
### ASSET EXCLUSIONS ###
28+
vendor/
29+
/vendor
30+
/log

CODE_OF_CONDUCT.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 jeremykenedy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Laravel Logger
2+
3+
TODO:
4+
5+
1. Pagination
6+
2. Soft Deletes
7+
3. User Scaffolding Enabled Logic
8+
4. User Roles Scaffolding Logic
9+
5. Readme
10+
6. Unit Tests
11+
7. Release

composer.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "jeremykenedy/laravel-logger",
3+
"description": "Laravel Logger Package",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "jeremykenedy",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"minimum-stability": "dev",
12+
"require": {
13+
"php": ">=7.0.0",
14+
"jaybizzle/laravel-crawler-detect": "1.*"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"jeremykenedy\\LaravelLogger\\": "src/"
19+
},
20+
"files": [
21+
"src/app/Logic/Helpers/Helpers.php"
22+
]
23+
},
24+
"extra": {
25+
"laravel": {
26+
"providers": [
27+
"jeremykenedy\\LaravelLogger\\LaravelLoggerServiceProvider"
28+
]
29+
}
30+
},
31+
"config": {
32+
"sort-packages": true
33+
},
34+
"minimum-stability": "stable"
35+
}

src/.env.example

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
LARAVEL_LOGGER_DATABASE_CONNECTION=mysql
2+
LARAVEL_LOGGER_DATABASE_TABLE=laravel_logger_activity
3+
LARAVEL_LOGGER_MIDDLEWARE_ENABLED=true
4+
LARAVEL_LOGGER_USER_MODEL='App\Models\User'
5+
LARAVEL_LOGGER_DATATABLES_ENABLED=true
6+
LARAVEL_LOGGER_DASHBOARD_MENU_ENABLED=true
7+
LARAVEL_LOGGER_DASHBOARD_DRILLABLE=true
8+
LARAVEL_LOGGER_LOG_RECORD_FAILURES_TO_FILE=true

src/LaravelLoggerServiceProvider.php

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
3+
namespace jeremykenedy\LaravelLogger;
4+
5+
use Illuminate\Routing\Router;
6+
use Illuminate\Support\ServiceProvider;
7+
use jeremykenedy\LaravelLogger\App\Http\Middleware\LogActivity;
8+
9+
class LaravelLoggerServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* Indicates if loading of the provider is deferred.
13+
*
14+
* @var bool
15+
*/
16+
protected $defer = false;
17+
18+
/**
19+
* The event listener mappings for the applications auth scafolding.
20+
*
21+
* @var array
22+
*/
23+
protected $listeners = [
24+
25+
'Illuminate\Auth\Events\Attempting' => [
26+
'jeremykenedy\LaravelLogger\App\Listeners\LogAuthenticationAttempt',
27+
],
28+
29+
'Illuminate\Auth\Events\Authenticated' => [
30+
'jeremykenedy\LaravelLogger\App\Listeners\LogAuthenticated',
31+
],
32+
33+
'Illuminate\Auth\Events\Login' => [
34+
'jeremykenedy\LaravelLogger\App\Listeners\LogSuccessfulLogin',
35+
],
36+
37+
'Illuminate\Auth\Events\Failed' => [
38+
'jeremykenedy\LaravelLogger\App\Listeners\LogFailedLogin',
39+
],
40+
41+
'Illuminate\Auth\Events\Logout' => [
42+
'jeremykenedy\LaravelLogger\App\Listeners\LogSuccessfulLogout',
43+
],
44+
45+
'Illuminate\Auth\Events\Lockout' => [
46+
'jeremykenedy\LaravelLogger\App\Listeners\LogLockout',
47+
],
48+
49+
'Illuminate\Auth\Events\PasswordReset' => [
50+
'jeremykenedy\LaravelLogger\App\Listeners\LogPasswordReset',
51+
],
52+
53+
];
54+
55+
/**
56+
* Bootstrap the application services.
57+
*
58+
* @return void
59+
*/
60+
public function boot(Router $router)
61+
{
62+
$router->middlewareGroup('activity',[LogActivity::class]);
63+
$this->loadTranslationsFrom(__DIR__.'/resources/lang/', 'LaravelLogger');
64+
}
65+
66+
/**
67+
* Register the application services.
68+
*
69+
* @return void
70+
*/
71+
public function register()
72+
{
73+
$this->loadRoutesFrom(__DIR__.'/routes/web.php');
74+
$this->loadViewsFrom(__DIR__.'/resources/views/', 'LaravelLogger');
75+
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
76+
$this->mergeConfigFrom(__DIR__.'/config/laravel-logger.php', 'LaravelLogger');
77+
$this->registerEventListeners();
78+
$this->publishFiles();
79+
}
80+
81+
/**
82+
* Get the list of listeners and events
83+
*
84+
* @return array
85+
*/
86+
private function getListeners()
87+
{
88+
return $this->listeners;
89+
}
90+
91+
/**
92+
* Register the list of listeners and events
93+
*
94+
* @return void
95+
*/
96+
private function registerEventListeners()
97+
{
98+
$listeners = $this->getListeners();
99+
foreach ($listeners as $listenerKey => $listenerValues) {
100+
foreach ($listenerValues as $listenerValue) {
101+
\Event::listen($listenerKey,
102+
$listenerValue
103+
);
104+
}
105+
}
106+
}
107+
108+
/**
109+
* Publish files for Laravel Logger.
110+
*
111+
* @return void
112+
*/
113+
private function publishFiles()
114+
{
115+
$publishTag = 'laravellogger';
116+
117+
$this->publishes([
118+
__DIR__.'/config/laravel-logger.php' => base_path('config/laravel-logger.php'),
119+
], $publishTag);
120+
121+
$this->publishes([
122+
__DIR__.'/resources/views' => base_path('resources/views/vendor/laravel-logger'),
123+
], $publishTag);
124+
125+
$this->publishes([
126+
__DIR__.'/resources/lang' => base_path('resources/lang/vendor/laravel-logger'),
127+
], $publishTag);
128+
129+
}
130+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
namespace jeremykenedy\LaravelLogger\App\Http\Controllers;
4+
5+
use App\Http\Controllers\Controller;
6+
use Carbon\Carbon;
7+
use jeremykenedy\LaravelLogger\App\Http\Traits\IpAddressDetails;
8+
use jeremykenedy\LaravelLogger\App\Http\Traits\UserAgentDetails;
9+
use jeremykenedy\LaravelLogger\App\Models\Activity;
10+
use Illuminate\Http\Request;
11+
12+
class LaravelLoggerController extends Controller
13+
{
14+
use IpAddressDetails, UserAgentDetails;
15+
16+
/**
17+
* Create a new controller instance.
18+
*
19+
* @return void
20+
*/
21+
public function __construct()
22+
{
23+
$this->middleware('auth');
24+
}
25+
26+
/**
27+
* Show the activities log dashboard.
28+
*
29+
* @return \Illuminate\Http\Response
30+
*/
31+
public function showAccessLog()
32+
{
33+
34+
$activities = Activity::orderBy('created_at', 'desc')->get();
35+
36+
$activities->map(function ($activity) {
37+
$eventTime = Carbon::parse($activity->updated_at);
38+
$activity['timePassed'] = $eventTime->diffForHumans();
39+
$activity['userAgentDetails'] = UserAgentDetails::details($activity->useragent);
40+
$activity['langDetails'] = UserAgentDetails::localeLang($activity->locale);
41+
$activity['userDetails'] = config('LaravelLogger.defaultUserModel')::find($activity->userId);
42+
43+
return $activity;
44+
});
45+
46+
return View('LaravelLogger::logger.activity-log', compact('activities'));
47+
}
48+
49+
/**
50+
* Show an individual activity log entry.
51+
*
52+
* @return \Illuminate\Http\Response
53+
*/
54+
public function showAccessLogEntry(Request $request, $id)
55+
{
56+
$activity = Activity::findOrFail($id);
57+
58+
$userDetails = config('LaravelLogger.defaultUserModel')::find($activity->userId);
59+
$userAgentDetails = UserAgentDetails::details($activity->useragent);
60+
$ipAddressDetails = IpAddressDetails::checkIP($activity->ipAddress);
61+
$langDetails = UserAgentDetails::localeLang($activity->locale);
62+
$eventTime = Carbon::parse($activity->created_at);
63+
$timePassed = $eventTime->diffForHumans();
64+
65+
$userActivities = Activity::where('userId', $activity->userId)
66+
->orderBy('created_at', 'desc')
67+
->get();
68+
69+
$userActivities->map(function ($userActivity) {
70+
$eventTime = Carbon::parse($userActivity->updated_at);
71+
$userActivity['timePassed'] = $eventTime->diffForHumans();
72+
$userActivity['userAgentDetails'] = UserAgentDetails::details($userActivity->useragent);
73+
$userActivity['langDetails'] = UserAgentDetails::localeLang($userActivity->locale);
74+
$userActivity['userDetails'] = config('LaravelLogger.defaultUserModel')::find($userActivity->userId);
75+
76+
return $userActivity;
77+
});
78+
79+
$data = [
80+
'activity' => $activity,
81+
'userDetails' => $userDetails,
82+
'ipAddressDetails' => $ipAddressDetails,
83+
'timePassed' => $timePassed,
84+
'userAgentDetails' => $userAgentDetails,
85+
'langDetails' => $langDetails,
86+
'userActivities' => $userActivities,
87+
];
88+
89+
return View('LaravelLogger::logger.activity-log-item', $data);
90+
91+
}
92+
93+
}

0 commit comments

Comments
 (0)