Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
riconeitzel committed Oct 1, 2020
2 parents 3cd0668 + 49395e3 commit 59054db
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 23 deletions.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,26 @@ In order to see the rules page and configuration, logout and login again.

You can find the list of downloaded rules in `System > Tools > Mage One QPS Rules`


## Username + key
To use the QPS you need to [add your username and key in the configuration](https://my.mage-one.com/qps):

System > Konfiguration > General > Quick Protection System

# Uninstall
## with composer
- Remove module from `composer.json` and rerun `composer update mageone/qps`
- Drop the rules table: `DROP TABLE <prefix>mageone_qps_rules;`
## Configuration

## with modman or manually
- Remove the files from your installation
- Drop the rules table: `DROP TABLE <prefix>mageone_qps_rules;`

# Configuration

The rule processing must be enabled manually in `System > Config > Quick Protection System (General Tab)`.
### Access credentials and rules enabling
The rule processing must be enabled manually in `System > Config > Quick Protection System > Configuration`.

Rules can be automatically enabled after the hourly API sync, although we recommend enabling rules manually after testing them (this is our default setting).
Enabling or disabling rules is possible in `System > Tools > MageOne QPS Rules`

You have to enter a username and public key, which you can obtain from [https://my.mage-one.com/qps](https://my.mage-one.com/qps)

### Notification of new rules

You can send an email once new rules have been fetched. Configure the recipient's email address and enable the notification in `System > Tools > MageOne QPS Rules > Notification`

# How does it work?

Our module filters malicious requests based on rules. These rules will be provided by our API, which is part of [https://mage-one.com/](https://mage-one.com/). Rules are usually based on regex inspections of the _GLOBALS data.
Expand All @@ -74,6 +71,16 @@ After a successful installation and configuration you can enable our test rule `

After this test, please disable our test rule again.


# Uninstall
## with composer
- Remove module from `composer.json` and rerun `composer update mageone/qps`
- Drop the rules table: `DROP TABLE <prefix>mageone_qps_rules;`

## with modman or manually
- Remove the files from your installation
- Drop the rules table: `DROP TABLE <prefix>mageone_qps_rules;`

# Help

If you want to trigger the rule synchronisation manually, you can trigger the cron job via [n98-magerun](https://github.com/netz98/n98-magerun)
Expand Down
2 changes: 2 additions & 0 deletions modman
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
src/app/code/community/Mageone/Qps app/code/community/Mageone/Qps
src/app/locale/de_DE/Mageone_Qps.csv app/locale/de_DE/Mageone_Qps.csv
src/app/locale/en_US/Mageone_Qps.csv app/locale/en_US/Mageone_Qps.csv
src/app/locale/en_US/template/email/qps_ruleupdate.html app/locale/en_US/template/email/qps_ruleupdate.html
src/app/locale/de_DE/template/email/qps_ruleupdate.html app/locale/de_DE/template/email/qps_ruleupdate.html

src/app/etc/modules/Mageone_Qps.xml app/etc/modules/Mageone_Qps.xml
18 changes: 18 additions & 0 deletions src/app/code/community/Mageone/Qps/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ class Mageone_Qps_Helper_Data extends Mage_Core_Helper_Abstract
const QPS_PUBLIC_KEY = 'qps_section/config/public_key';
const QPS_USER = 'qps_section/config/user_name';
const QPS_RULE_AUTO_ENABLE = 'qps_section/config/rule_auto_enable';
const NOTIFICATION_STATUS = 'qps_section/notification/enabled';
const NOTIFICATION_EMAIL = 'qps_section/notification/email';

/**
* @return bool
*/
public function isNotificationEnabled(): bool
{
return Mage::getStoreConfigFlag(self::NOTIFICATION_STATUS);
}

/**
* @return string
*/
public function getNotificationEmail(): string
{
return Mage::getStoreConfig(self::NOTIFICATION_EMAIL);
}

/**
* @return bool
Expand Down
32 changes: 22 additions & 10 deletions src/app/code/community/Mageone/Qps/Model/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ class Mageone_Qps_Model_Cron
* @var Mageone_Qps_Helper_Data
*/
private $helper;
/**
* @var Mageone_Qps_Model_EmailService
*/
private $emailService;

public function __construct(array $args = [])
{
if (isset($args['client'])) {
$this->client = $args['client'];
}
$this->helper = Mage::helper('qps');
$this->helper = Mage::helper('qps');
$this->emailService = Mage::getModel('qps/emailService');
}

/**
Expand All @@ -28,18 +33,21 @@ public function getRules(): void
return;
}
try {
$security = Mage::getModel('qps/secService');
$client = $this->getClient();
$message = $security->encryptMessage(
json_encode([
'magento_version' => Mage::getVersion(),
'patches_list' => $this->getPatchList()
])
$sendNotification = false;
$security = Mage::getModel('qps/secService');
$client = $this->getClient();
$message = $security->encryptMessage(
json_encode(
[
'magento_version' => Mage::getVersion(),
'patches_list' => $this->getPatchList(),
])
);
$client->post($this->helper->getResourceUrl(),
$client->post(
$this->helper->getResourceUrl(),
[
'user' => $this->helper->getUserName(),
'message' => $message
'message' => $message,
]
);
if ($client->getStatus() !== 200) {
Expand All @@ -64,6 +72,7 @@ public function getRules(): void
// update rules, save to database and unset on collection
$rule = $collection->getItemByColumnValue('m1_key', $item['m1_key']) ?: Mage::getModel('qps/rule');
if ($rule->isObjectNew()) {
$sendNotification = true;
$rule->setEnabled($this->helper->isRuleAutoEnable());
}
$rule->addData($item)->save();
Expand All @@ -72,6 +81,9 @@ public function getRules(): void
// delete everything which was not updated and unset
$collection->walk('delete');
Mage::app()->cleanCache([Mageone_Qps_Model_Observer::QPS_CACHE_TAG]);
if ($sendNotification === true) {
$this->emailService->sendNotificationEmail($this->helper);
}
}
} catch (Exception $exception) {
Mage::logException($exception);
Expand Down
43 changes: 43 additions & 0 deletions src/app/code/community/Mageone/Qps/Model/EmailService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types = 1);

class Mageone_Qps_Model_EmailService
{

public function sendNotificationEmail(Mageone_Qps_Helper_Data $helper): void
{
if ($helper->isNotificationEnabled() === false) {
return;
}

if ($this->isEmailValid($helper->getNotificationEmail()) === false) {
Mage::log('QPS notification email address seems to be invalid. Please check your configuration!');

return;
}

$variables = [];
if (!$helper->isRuleAutoEnable()) {
$variables['notautoenable'] = 'true';
}

$mail = Mage::getModel('core/email_template');
try {
$mail->sendTransactional(
'mageone_qps_ruleupdate',
'general',
$helper->getNotificationEmail(),
'Mage One QPS',
$variables
);
} catch (Mage_Core_Exception $e) {
Mage::log('QPS notification email could not be send.');
}
}

private function isEmailValid($emailAddress): bool
{
return filter_var($emailAddress, FILTER_VALIDATE_EMAIL) !== false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Mageone_Qps_Adminhtml_QpsController extends Mage_Adminhtml_Controller_Acti
public function indexAction(): void
{
$this->loadLayout();
$this->_title($this->_getHelper()->__('Mage One QPS Rules'));
$this->_addContent($this->getLayout()->createBlock('qps/rule'));
$this->renderLayout();
}
Expand Down
9 changes: 9 additions & 0 deletions src/app/code/community/Mageone/Qps/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
</setup>
</qps_setup>
</resources>
<template>
<email>
<mageone_qps_ruleupdate translate="label" module="qps">
<label>QPS rule update</label>
<file>qps_ruleupdate.html</file>
<type>html</type>
</mageone_qps_ruleupdate>
</email>
</template>
<events>
<controller_front_init_before>
<observers>
Expand Down
32 changes: 30 additions & 2 deletions src/app/code/community/Mageone/Qps/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,43 @@
<qps_section translate="label" module="qps">
<label>Quick Protection System</label>
<tab>general</tab>
<frontend_type>text</frontend_type>
<sort_order>5000</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<groups>
<notification translate="label" module="qps">
<label>Notification</label>
<sort_order>200</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<enabled translate="label comment" module="qps">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<comment>Enable notifications</comment>
</enabled>
<email translate="label comment" module="qps">
<label>eMail Address</label>
<frontend_type>text</frontend_type>
<comment>Notify this email address, when new QPS rules are downloaded.</comment>
<validate>validate-email</validate>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>

</email>
</fields>
</notification>
<config translate="label" module="qps">
<label>Configuration</label>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
Expand Down
8 changes: 8 additions & 0 deletions src/app/locale/de_DE/Mageone_Qps.csv
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@
"Reset","Zurücksetzen"
"Save and Continue Edit","Speichern und weiterbearbeiten"
"Quick Protection System Section","Mage One QPS"

"Notify this email address, when new QPS rules are downloaded.","Diese E-Mail-Adresse bei neuen QPS-Regeln benachrichtigen."
"eMail Address","E-Mail-Adresse"
"Notification","Benachrichtigung"
"Enable notifications","Benachrichtigung aktivieren"

"Yes","Ja"
"No","Nein"
18 changes: 18 additions & 0 deletions src/app/locale/de_DE/template/email/qps_ruleupdate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--@subject Neue QPS Regeln aktualisiert! @-->
<!--@vars @-->
<!--@styles @-->

{{template config_path="design/email/header"}}
{{inlinecss file="email-inline.css"}}

<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="action-content">
<h1>Neue QPS Regeln in {{var store.getFrontendName()}}.</h1>
<p>Das Regelset für QPS wurde soeben aktualisiert.</p>
{{if notautoenable}}<p>Bitte prüfen und aktivieren Sie die neuen Regeln.</p>{{/if}}
</td>
</tr>
</table>

{{template config_path="design/email/footer"}}
8 changes: 8 additions & 0 deletions src/app/locale/en_US/Mageone_Qps.csv
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@
"Reset","Reset"
"Save and Continue Edit","Save and Continue Edit"
"Quick Protection System Section","Mage One QPS"

"Notification","Notification",
"Notify this email address, when new QPS rules are downloaded.","Notify this email address, when new QPS rules are downloaded."
"eMail Address","eMail Address"
"Enable notifications","Enable notifications"

"Yes","Yes"
"No","No"
18 changes: 18 additions & 0 deletions src/app/locale/en_US/template/email/qps_ruleupdate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--@subject New QPS rule were synced! @-->
<!--@vars @-->
<!--@styles @-->

{{template config_path="design/email/header"}}
{{inlinecss file="email-inline.css"}}

<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="action-content">
<h1>New QPS rules in {{var store.getFrontendName()}}.</h1>
<p>We just updated the QPS rule set.</p>
{{if notautoenable}}<p>Please review the rules and enable them accordingly.</p>{{/if}}
</td>
</tr>
</table>

{{template config_path="design/email/footer"}}

0 comments on commit 59054db

Please sign in to comment.