Skip to content

Commit

Permalink
More improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagosampaio committed Aug 15, 2024
1 parent 75013a3 commit 5b15053
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Keep your Magento 2 store protected from suspicious and harmful requests with MagedIn_TrojanRequestBlocker. This robust extension acts as a shield, detecting and blocking malicious requests before they can disrupt your e-commerce operations. Whether it’s bots, fraudulent actions, or unusual traffic spikes, MagedIn_TrojanRequestBlocker is designed to guard your store from potentially harmful activity, ensuring a secure and smooth shopping experience for legitimate users.

[![Magento 2 Coding Standard](https://github.com/magedin/magento2-module-trojan-request-blocker/actions/workflows/coding-standard.yml/badge.svg)](https://github.com/magedin/magento2-module-trojan-request-blocker/actions/workflows/coding-standard.yml)

## Compatibility

- Magento 2.3
Expand Down
23 changes: 16 additions & 7 deletions Service/Patterns/TermsBlacklistPatterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem\Directory\ReadFactory;

/**
* This class tries to get the patterns from the .terms_blacklist file into the var directory.
Expand All @@ -24,23 +25,31 @@ class TermsBlacklistPatterns implements PatternsInterface
{
private const ADDITIONAL_PATTERNS_FILE = '.terms_blacklist';

/**
* @var array
*/
private array $patterns = [];

/**
* @var DirectoryList
*/
private DirectoryList $directoryList;

/**
* @var array
* @var ReadFactory
*/
private array $patterns = [];
private ReadFactory $directoryRead;

/**
* @param DirectoryList $directoryList
* @param ReadFactory $directoryRead
*/
public function __construct(
DirectoryList $directoryList
DirectoryList $directoryList,
ReadFactory $directoryRead
) {
$this->directoryList = $directoryList;
$this->directoryRead = $directoryRead;
}

/**
Expand All @@ -56,11 +65,11 @@ public function load(): array
} catch (FileSystemException $e) {
return $this->patterns;
}
$termsBlacklist = $varDirectory . DIRECTORY_SEPARATOR . self::ADDITIONAL_PATTERNS_FILE;
if (file_exists($termsBlacklist) && is_readable($termsBlacklist)) {
$content = explode(PHP_EOL, file_get_contents($termsBlacklist));
$read = $this->directoryRead->create($varDirectory);
if ($read->isExist(self::ADDITIONAL_PATTERNS_FILE) && $read->isReadable(self::ADDITIONAL_PATTERNS_FILE)) {
$content = explode(PHP_EOL, $read->readFile(self::ADDITIONAL_PATTERNS_FILE));
$content = array_filter($content);
array_map(function (string $term) use (&$patterns) {
array_map(function (string $term) {
$this->patterns[] = trim($term);
}, $content);
$this->patterns = array_unique($this->patterns);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magedin/module-trojan-request-blocker",
"description": "This robust extension acts as a shield, detecting and blocking malicious requests before they can disrupt your e-commerce operations. Whether it’s bots, fraudulent actions, or unusual traffic spikes, MagedIn_TrojanRequestBlocker is designed to guard your store from potentially harmful activity, ensuring a secure and smooth shopping experience for legitimate users.",
"description": "This robust extension acts as a shield, detecting and blocking malicious requests before they can disrupt your e-commerce operations. Whether it’s bots, fraudulent actions, or unusual traffic spikes, MagedIn_TrojanRequestBlocker is designed to guard your store from potentially harmful activity.",
"type": "magento2-module",
"require": {
"php": "^7.4||^8.0",
Expand Down

0 comments on commit 5b15053

Please sign in to comment.