Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tell firewall that too many emails were sent
- Loading branch information
1 parent
fd8b6c1
commit 70ab665
Showing
6 changed files
with
206 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Events\Email; | ||
|
||
use App\Abstracts\Event; | ||
|
||
class TooManyEmailsSent extends Event | ||
{ | ||
public $user_id; | ||
|
||
public function __construct(int $user_id) | ||
{ | ||
$this->user_id = $user_id; | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Email; | ||
|
||
use App\Exceptions\Common\TooManyEmailsSent; | ||
use App\Events\Email\TooManyEmailsSent as Event; | ||
|
||
class ReportTooManyEmailsSent | ||
{ | ||
public function handle(Event $event): void | ||
{ | ||
report(new TooManyEmailsSent('Too many emails sent!')); | ||
} | ||
} |
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,72 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Email; | ||
|
||
use Akaunting\Firewall\Events\AttackDetected; | ||
use Akaunting\Firewall\Traits\Helper; | ||
use App\Events\Email\TooManyEmailsSent as Event; | ||
use Illuminate\Support\Facades\Config; | ||
|
||
class TellFirewallTooManyEmailsSent | ||
{ | ||
use Helper; | ||
|
||
public function handle(Event $event): void | ||
{ | ||
$this->request = request(); | ||
$this->middleware = 'too_many_emails_sent'; | ||
$this->user_id = $event->user_id; | ||
|
||
$this->loadConfig(); | ||
|
||
if ($this->skip($event)) { | ||
return; | ||
} | ||
|
||
$log = $this->log(); | ||
|
||
event(new AttackDetected($log)); | ||
} | ||
|
||
public function loadConfig(): void | ||
{ | ||
$config = array_merge_recursive( | ||
Config::get('firewall'), | ||
[ | ||
'middleware' => [ | ||
$this->middleware => [ | ||
'enabled' => env('FIREWALL_MIDDLEWARE_' . strtoupper($this->middleware) . '_ENABLED', env('FIREWALL_ENABLED', true)), | ||
|
||
'methods' => ['post'], | ||
|
||
'routes' => [ | ||
'only' => [], // i.e. 'contact' | ||
'except' => [], // i.e. 'admin/*' | ||
], | ||
|
||
'auto_block' => [ | ||
'attempts' => env('FIREWALL_MIDDLEWARE_' . strtoupper($this->middleware) . '_AUTO_BLOCK_ATTEMPTS', 20), | ||
'frequency' => 1 * 60, // 1 minute | ||
'period' => 30 * 60, // 30 minutes | ||
], | ||
], | ||
], | ||
] | ||
); | ||
|
||
Config::set('firewall', $config); | ||
} | ||
|
||
public function skip($event): bool | ||
{ | ||
if ($this->isDisabled()) { | ||
return true; | ||
} | ||
|
||
if ($this->isWhitelist()) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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
Oops, something went wrong.