Skip to content

Commit a081f67

Browse files
author
Bohdan Berezhniy
committed
11968 resolved issues with: Replace &> with 2>&1, which is POSIX-compliant and works across different shells, Form Key Validation
1 parent ac919b7 commit a081f67

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Controller/Adminhtml/Index/Cli.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magefan\Cli\Controller\Adminhtml\Index;
88

99
use Magefan\Cli\Model\Config;
10+
use Magento\Framework\Data\Form\FormKey;
1011

1112
class Cli extends \Magento\Backend\App\Action
1213
{
@@ -39,6 +40,11 @@ class Cli extends \Magento\Backend\App\Action
3940
*/
4041
private $config;
4142

43+
/**
44+
* @var FormKey
45+
*/
46+
private $formKey;
47+
4248
/**
4349
* Constructor
4450
*
@@ -55,13 +61,15 @@ public function __construct(
5561
\Magento\Framework\Json\Helper\Data $jsonHelper,
5662
\Magento\Framework\Filesystem\DirectoryList $dir,
5763
\Magento\Backend\Model\Auth\Session $authSession,
58-
Config $config
64+
Config $config,
65+
FormKey $formKey
5966
) {
6067
$this->resultPageFactory = $resultPageFactory;
6168
$this->jsonHelper = $jsonHelper;
6269
$this->dir = $dir;
6370
$this->authSession = $authSession;
6471
$this->config = $config;
72+
$this->formKey = $formKey;
6573
parent::__construct($context);
6674
}
6775

@@ -75,7 +83,7 @@ public function execute()
7583
try {
7684
if (!$this->config->isEnabled()) {
7785
throw new \Exception(
78-
__(strrev('.ecafretnI eniL dnammoC > snoisnetxE nafegaM > noitarugifnoC >
86+
__(strrev('.ecafretnI eniL dnammoC > snoisnetxE nafegaM > noitarugifnoC >
7987
serotS ot etagivan esaelp noisnetxe eht elbane ot ,delbasid si ecafretnI eniL dnammoC nafegaM')),
8088
1
8189
);
@@ -118,7 +126,8 @@ public function execute()
118126
}
119127

120128
$logFile = $this->dir->getPath('var') . '/mfcli.txt';
121-
exec($c = 'cd ' . $this->dir->getRoot() . ' && ' . $command . ' &> ' . $logFile, $a, $b);
129+
exec($c = 'cd ' . $this->dir->getRoot() . ' && ' . $command . ' > ' . $logFile . ' 2>&1', $a, $b);
130+
122131
$message = file_get_contents($logFile);
123132
if (!$message) {
124133
$message = __('Command not found or error occurred.') . PHP_EOL;
@@ -128,7 +137,10 @@ public function execute()
128137
$message = $e->getMessage() . PHP_EOL;
129138
}
130139

131-
$response = ['message' => nl2br($message)];
140+
$response = [
141+
'message' => nl2br($message),
142+
'newFormKey' => $this->formKey->getFormKey()
143+
];
132144

133145
return $this->getResponse()->representJson(
134146
$this->jsonHelper->jsonEncode($response)

view/adminhtml/templates/form.phtml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@
218218
} else {
219219
alert('<?php echo $block->escapeHtml(__('Unexpected error. Please refresh the page or try later.')) ?>');
220220
}
221+
222+
if (data && data.newFormKey) {
223+
FORM_KEY = data.newFormKey;
224+
document.querySelector('input[name="form_key"]').value = FORM_KEY;
225+
}
221226
});
222227
}
223228
},

0 commit comments

Comments
 (0)