Skip to content

Commit ab4dba0

Browse files
authored
Merge pull request #217 from Inchoo/feature/#194-web-application-firewall
Feature/#194 web application firewall
2 parents 6cdce58 + f914069 commit ab4dba0

File tree

11 files changed

+652
-3
lines changed

11 files changed

+652
-3
lines changed

Diff for: Block/System/Config/Form/Field/WafBtn.php

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Fastly CDN for Magento
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Fastly CDN for Magento End User License Agreement
8+
* that is bundled with this package in the file LICENSE_FASTLY_CDN.txt.
9+
*
10+
* DISCLAIMER
11+
*
12+
* Do not edit or add to this file if you wish to upgrade Fastly CDN to newer
13+
* versions in the future. If you wish to customize this module for your
14+
* needs please refer to http://www.magento.com for more information.
15+
*
16+
* @category Fastly
17+
* @package Fastly_Cdn
18+
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
19+
* @license BSD, see LICENSE_FASTLY_CDN.txt
20+
*/
21+
namespace Fastly\Cdn\Block\System\Config\Form\Field;
22+
23+
use Fastly\Cdn\Model\Config;
24+
use Magento\Backend\Block\Template\Context;
25+
use Magento\Config\Block\System\Config\Form\Field;
26+
use Magento\Framework\Data\Form\Element\AbstractElement;
27+
28+
/**
29+
* Class WafBtn
30+
*
31+
* @package Fastly\Cdn\Block\System\Config\Form\Field
32+
*/
33+
class WafBtn extends Field
34+
{
35+
protected function _construct() // @codingStandardsIgnoreLine - required by parent class
36+
{
37+
$this->_template = 'Fastly_Cdn::system/config/form/field/wafBtn.phtml';
38+
39+
parent::_construct();
40+
}
41+
42+
/**
43+
* Remove scope label
44+
*
45+
* @param AbstractElement $element
46+
* @return string
47+
*/
48+
public function render(AbstractElement $element)
49+
{
50+
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
51+
return parent::render($element);
52+
}
53+
54+
/**
55+
* Return element html
56+
*
57+
* @param AbstractElement $element
58+
* @return string
59+
*/
60+
protected function _getElementHtml(AbstractElement $element) // @codingStandardsIgnoreLine - required by parent class
61+
{
62+
return $this->_toHtml();
63+
}
64+
65+
/**
66+
* Return ajax url for collect button
67+
*
68+
* @return string
69+
*/
70+
public function getAjaxUrl()
71+
{
72+
return $this->getUrl('adminhtml/fastlyCdn/vcl/serviceinfo');
73+
}
74+
75+
/**
76+
* @return string
77+
* @throws \Magento\Framework\Exception\LocalizedException
78+
*/
79+
public function getButtonHtml()
80+
{
81+
$button = $this->getLayout()->createBlock(
82+
'Magento\Backend\Block\Widget\Button'
83+
)->setData([
84+
'id' => 'toggle_waf',
85+
'label' => __('Enable/Disable')
86+
]);
87+
88+
return $button->toHtml();
89+
}
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Fastly CDN for Magento
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Fastly CDN for Magento End User License Agreement
8+
* that is bundled with this package in the file LICENSE_FASTLY_CDN.txt.
9+
*
10+
* DISCLAIMER
11+
*
12+
* Do not edit or add to this file if you wish to upgrade Fastly CDN to newer
13+
* versions in the future. If you wish to customize this module for your
14+
* needs please refer to http://www.magento.com for more information.
15+
*
16+
* @category Fastly
17+
* @package Fastly_Cdn
18+
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
19+
* @license BSD, see LICENSE_FASTLY_CDN.txt
20+
*/
21+
namespace Fastly\Cdn\Controller\Adminhtml\FastlyCdn\Vcl;
22+
23+
use Fastly\Cdn\Model\Config;
24+
use Fastly\Cdn\Model\Api;
25+
use Magento\Backend\App\Action;
26+
use Magento\Backend\App\Action\Context;
27+
use Magento\Framework\Controller\Result\Json;
28+
use Magento\Framework\Controller\Result\JsonFactory;
29+
30+
/**
31+
* Class GetFastlyServiceInfo
32+
*
33+
* @package Fastly\Cdn\Controller\Adminhtml\FastlyCdn\Vcl
34+
*/
35+
class GetFastlyServiceInfo extends Action
36+
{
37+
/**
38+
* @var Api
39+
*/
40+
private $api;
41+
/**
42+
* @var Config
43+
*/
44+
private $config;
45+
/**
46+
* @var JsonFactory
47+
*/
48+
private $resultJsonFactory;
49+
50+
/**
51+
* GetFastlyServiceInfo constructor.
52+
*
53+
* @param Context $context
54+
* @param Config $config
55+
* @param Api $api
56+
* @param JsonFactory $resultJsonFactory
57+
*/
58+
public function __construct(
59+
Context $context,
60+
Config $config,
61+
Api $api,
62+
JsonFactory $resultJsonFactory
63+
) {
64+
$this->api = $api;
65+
$this->config = $config;
66+
$this->resultJsonFactory = $resultJsonFactory;
67+
68+
parent::__construct($context);
69+
}
70+
71+
/**
72+
* @return \Magento\Framework\App\ResponseInterface|Json|\Magento\Framework\Controller\ResultInterface
73+
*/
74+
public function execute()
75+
{
76+
$result = $this->resultJsonFactory->create();
77+
try {
78+
$serviceInfo = $this->api->getServiceDetails();
79+
return $result->setData([
80+
'status' => true,
81+
'service_info' => $serviceInfo
82+
]);
83+
} catch (\Exception $e) {
84+
return $result->setData([
85+
'status' => false,
86+
'msg' => $e->getMessage()
87+
]);
88+
}
89+
}
90+
}
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Fastly CDN for Magento
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Fastly CDN for Magento End User License Agreement
8+
* that is bundled with this package in the file LICENSE_FASTLY_CDN.txt.
9+
*
10+
* DISCLAIMER
11+
*
12+
* Do not edit or add to this file if you wish to upgrade Fastly CDN to newer
13+
* versions in the future. If you wish to customize this module for your
14+
* needs please refer to http://www.magento.com for more information.
15+
*
16+
* @category Fastly
17+
* @package Fastly_Cdn
18+
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
19+
* @license BSD, see LICENSE_FASTLY_CDN.txt
20+
*/
21+
namespace Fastly\Cdn\Controller\Adminhtml\FastlyCdn\Vcl;
22+
23+
use Fastly\Cdn\Model\Config;
24+
use Fastly\Cdn\Model\Api;
25+
use Magento\Backend\App\Action;
26+
use Magento\Backend\App\Action\Context;
27+
use Magento\Framework\Controller\Result\Json;
28+
use Magento\Framework\Controller\Result\JsonFactory;
29+
30+
/**
31+
* Class GetOwaspSettings
32+
*
33+
* @package Fastly\Cdn\Controller\Adminhtml\FastlyCdn\Vcl
34+
*/
35+
class GetOwaspSettings extends Action
36+
{
37+
/**
38+
* @var Api
39+
*/
40+
private $api;
41+
/**
42+
* @var Config
43+
*/
44+
private $config;
45+
/**
46+
* @var JsonFactory
47+
*/
48+
private $resultJsonFactory;
49+
50+
/**
51+
* GetOwaspSettings constructor.
52+
*
53+
* @param Context $context
54+
* @param Config $config
55+
* @param Api $api
56+
* @param JsonFactory $resultJsonFactory
57+
*/
58+
public function __construct(
59+
Context $context,
60+
Config $config,
61+
Api $api,
62+
JsonFactory $resultJsonFactory
63+
) {
64+
$this->api = $api;
65+
$this->config = $config;
66+
$this->resultJsonFactory = $resultJsonFactory;
67+
68+
parent::__construct($context);
69+
}
70+
71+
/**
72+
* @return \Magento\Framework\App\ResponseInterface|Json|\Magento\Framework\Controller\ResultInterface
73+
*/
74+
public function execute()
75+
{
76+
$result = $this->resultJsonFactory->create();
77+
try {
78+
$id = $this->getRequest()->getParam('id');
79+
$wafSettings = $this->api->getOwaspSettings($id);
80+
81+
return $result->setData([
82+
'status' => true,
83+
'owasp_settings' => $wafSettings
84+
]);
85+
} catch (\Exception $e) {
86+
return $result->setData([
87+
'status' => false,
88+
'msg' => $e->getMessage()
89+
]);
90+
}
91+
}
92+
}
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Fastly CDN for Magento
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Fastly CDN for Magento End User License Agreement
8+
* that is bundled with this package in the file LICENSE_FASTLY_CDN.txt.
9+
*
10+
* DISCLAIMER
11+
*
12+
* Do not edit or add to this file if you wish to upgrade Fastly CDN to newer
13+
* versions in the future. If you wish to customize this module for your
14+
* needs please refer to http://www.magento.com for more information.
15+
*
16+
* @category Fastly
17+
* @package Fastly_Cdn
18+
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
19+
* @license BSD, see LICENSE_FASTLY_CDN.txt
20+
*/
21+
namespace Fastly\Cdn\Controller\Adminhtml\FastlyCdn\Vcl;
22+
23+
use Fastly\Cdn\Model\Config;
24+
use Fastly\Cdn\Model\Api;
25+
use Magento\Backend\App\Action;
26+
use Magento\Backend\App\Action\Context;
27+
use Magento\Framework\Controller\Result\Json;
28+
use Magento\Framework\Controller\Result\JsonFactory;
29+
30+
/**
31+
* Class GetFastlyServiceInfo
32+
*
33+
* @package Fastly\Cdn\Controller\Adminhtml\FastlyCdn\Vcl
34+
*/
35+
class GetWafSettings extends Action
36+
{
37+
/**
38+
* @var Api
39+
*/
40+
private $api;
41+
/**
42+
* @var Config
43+
*/
44+
private $config;
45+
/**
46+
* @var JsonFactory
47+
*/
48+
private $resultJsonFactory;
49+
50+
/**
51+
* GetFastlyServiceInfo constructor.
52+
*
53+
* @param Context $context
54+
* @param Config $config
55+
* @param Api $api
56+
* @param JsonFactory $resultJsonFactory
57+
*/
58+
public function __construct(
59+
Context $context,
60+
Config $config,
61+
Api $api,
62+
JsonFactory $resultJsonFactory
63+
) {
64+
$this->api = $api;
65+
$this->config = $config;
66+
$this->resultJsonFactory = $resultJsonFactory;
67+
68+
parent::__construct($context);
69+
}
70+
71+
/**
72+
* @return \Magento\Framework\App\ResponseInterface|Json|\Magento\Framework\Controller\ResultInterface
73+
*/
74+
public function execute()
75+
{
76+
$result = $this->resultJsonFactory->create();
77+
try {
78+
$id = $this->getRequest()->getParam('id');
79+
$wafSettings = $this->api->getWafSettings($id);
80+
81+
return $result->setData([
82+
'status' => true,
83+
'waf_settings' => $wafSettings
84+
]);
85+
} catch (\Exception $e) {
86+
return $result->setData([
87+
'status' => false,
88+
'msg' => $e->getMessage()
89+
]);
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)