-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from julienloizelet/feat/metrics
Feat/metrics
- Loading branch information
Showing
30 changed files
with
813 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* CrowdSec_Engine Extension | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the MIT LICENSE | ||
* that is bundled with this package in the file LICENSE | ||
* | ||
* @category CrowdSec | ||
* @package CrowdSec_Engine | ||
* @copyright Copyright (c) 2023+ CrowdSec | ||
* @author CrowdSec team | ||
* @see https://crowdsec.net CrowdSec Official Website | ||
* @license MIT LICENSE | ||
* | ||
*/ | ||
|
||
/** | ||
* | ||
* @category CrowdSec | ||
* @package CrowdSec_Engine | ||
* @module Engine | ||
* @author CrowdSec team | ||
* | ||
*/ | ||
|
||
namespace CrowdSec\Engine\Block\Adminhtml\Report; | ||
|
||
use CrowdSec\Engine\CapiEngine\Remediation; | ||
use CrowdSec\Engine\Helper\Data as Helper; | ||
use CrowdSec\Engine\Constants; | ||
use Magento\Backend\Block\Template; | ||
use Magento\Backend\Block\Template\Context; | ||
use Magento\Backend\Model\UrlInterface as BackendUrlInterface; | ||
|
||
class Metrics extends Template | ||
{ | ||
/** | ||
* @var Remediation | ||
*/ | ||
private $remediation; | ||
/** | ||
* @var Helper | ||
*/ | ||
private $helper; | ||
|
||
/** | ||
* @var BackendUrlInterface | ||
*/ | ||
private $backendUrl; | ||
|
||
/** | ||
* @param Remediation $remediation | ||
* @param Helper $helper | ||
* @param BackendUrlInterface $backendUrl | ||
* @param Context $context | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Remediation $remediation, | ||
Helper $helper, | ||
BackendUrlInterface $backendUrl, | ||
Context $context, | ||
array $data = [] | ||
) { | ||
$this->remediation = $remediation; | ||
$this->helper = $helper; | ||
$this->backendUrl = $backendUrl; | ||
$data = array_merge($data, [ | ||
'origin_capi' => Constants::ORIGIN_CAPI, | ||
'origin_lists' => Constants::ORIGIN_LISTS, | ||
'origin_crowdsec' => Constants::ORIGIN | ||
]); | ||
parent::__construct($context, $data); | ||
} | ||
|
||
/** | ||
* Retrieves origin count cached item | ||
* | ||
* @return array | ||
* @throws \Psr\Cache\InvalidArgumentException | ||
*/ | ||
public function getOriginsCount(): array | ||
{ | ||
|
||
return $this->remediation->getOriginsCount(); | ||
} | ||
|
||
/** | ||
* Retrieves "should bounce ban" setting | ||
* | ||
* @return bool | ||
*/ | ||
public function isBanBouncingEnabled(): bool | ||
{ | ||
return $this->helper->shouldBounceBan(); | ||
} | ||
|
||
/** | ||
* Retrieves "should ban locally" setting | ||
* | ||
* @return bool | ||
*/ | ||
public function isLocalBanEnabled(): bool | ||
{ | ||
return $this->helper->shouldBanLocally(); | ||
} | ||
|
||
/** | ||
* Retrieves "fallback" setting | ||
* | ||
* @return string | ||
*/ | ||
public function getFallback(): string | ||
{ | ||
return $this->helper->getFallbackRemediation(); | ||
} | ||
|
||
/** | ||
* Retrieves settings url | ||
* | ||
* @return string | ||
*/ | ||
public function getSettingsUrl() | ||
{ | ||
return $this->backendUrl->getUrl('adminhtml/system_config/edit/', ['section' => 'crowdsec_engine']); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* CrowdSec_Engine Extension | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the MIT LICENSE | ||
* that is bundled with this package in the file LICENSE | ||
* | ||
* @category CrowdSec | ||
* @package CrowdSec_Engine | ||
* @copyright Copyright (c) 2023+ CrowdSec | ||
* @author CrowdSec team | ||
* @see https://crowdsec.net CrowdSec Official Website | ||
* @license MIT LICENSE | ||
* | ||
*/ | ||
|
||
/** | ||
* | ||
* @category CrowdSec | ||
* @package CrowdSec_Engine | ||
* @module Engine | ||
* @author CrowdSec team | ||
* | ||
*/ | ||
|
||
namespace CrowdSec\Engine\Model\Config\Source; | ||
|
||
use CrowdSec\Engine\Constants; | ||
use CrowdSec\RemediationEngine\CapiRemediation; | ||
use Magento\Framework\Data\OptionSourceInterface; | ||
|
||
class Fallback implements OptionSourceInterface | ||
{ | ||
/** | ||
* Options getter | ||
* | ||
* @return array | ||
*/ | ||
public function toOptionArray(): array | ||
{ | ||
$result = []; | ||
$orderedRemediations = array_merge(CapiRemediation::ORDERED_REMEDIATIONS, [Constants::REMEDIATION_BYPASS]); | ||
foreach ($orderedRemediations as $remediation) { | ||
$result[] = ['value' => $remediation, 'label' => __("$remediation")]; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
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.