Skip to content

Commit aa4554b

Browse files
authored
Merge pull request #5 from magefan/11968-magento-247p2-compatibility
11968 resolved issues with: Replace &> with 2>&1, which is POSIX-comp…
2 parents ac919b7 + c03558b commit aa4554b

File tree

2 files changed

+113
-91
lines changed

2 files changed

+113
-91
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: 97 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@
1010
* CLI template
1111
*
1212
* @var $block \Magefan\Cli\Block\Adminhtml\Form
13+
* @var $mfSecureRenderer \Magefan\Community\Api\SecureHtmlRendererInterface
1314
*
1415
* @codingStandardsIgnoreStart
1516
*/
16-
$exec = $block->execExist();
17-
$magentoCommands = $block->getMagentoCommands();
18-
$url = $block->getUrl('adminhtml/system_config/edit', ['section' => 'mfcli']);
17+
$exec = $block->execExist();
18+
$magentoCommands = $block->getMagentoCommands();
19+
$url = $block->getUrl('adminhtml/system_config/edit', ['section' => 'mfcli']);
20+
$script = '';
1921
?>
2022

2123
<?php if (!$block->isModuleEnabled()) {?>
22-
<div class="messages">
23-
<div class="message message-error error">
24-
<div data-ui-id="messages-message-error">
25-
<?= $block->escapeHtml(__(strrev(' ot etagivan esaelp noisnetxe eht elbane ot ,delbasid si ecafretnI eniL dnammoC nafegaM'))) ?><a href="<?= $block->escapeUrl($url) ?>" target="_blank"><?= $block->escapeHtml(__(strrev('ecafretnI eniL dnammoC > snoisnetxE nafegaM > noitarugifnoC > serotS'))) ?></a>
24+
<div class="messages">
25+
<div class="message message-error error">
26+
<div data-ui-id="messages-message-error">
27+
<?= $block->escapeHtml(__(strrev(' ot etagivan esaelp noisnetxe eht elbane ot ,delbasid si ecafretnI eniL dnammoC nafegaM'))) ?><a href="<?= $block->escapeUrl($url) ?>" target="_blank"><?= $block->escapeHtml(__(strrev('ecafretnI eniL dnammoC > snoisnetxE nafegaM > noitarugifnoC > serotS'))) ?></a>
28+
</div>
2629
</div>
2730
</div>
28-
</div>
2931
<?php } elseif (!count(array_filter($magentoCommands))) { ?>
3032
<div class="messages">
3133
<div class="message message-error error">
@@ -35,84 +37,85 @@
3537
</div>
3638
</div>
3739
<?php } else {?>
38-
<?php
40+
<?php
3941
$mostUsed = $magentoCommands['most_used'];
4042
$commands = $magentoCommands['commands'];
41-
?>
42-
<style>
43-
#shell-area{float:left;width:78%;margin:0;list-style:none;background:#141414;color:#45D40C;font:.8em 'Andale Mono',Consolas,'Courier New';line-height:1.6em;padding:10px; min-height:500px;max-height:500px;overflow-y: auto;}
44-
#shell-area input{width:80%; background: #141414;border:none;padding:10px;line-height:15px}
45-
#command-list ul{float:right;height:200px;width:20%;min-height:500px;max-height:500px;}
46-
#command-list ul{overflow:hidden;overflow-y:scroll;overflow-x:scroll;}
47-
#command-list li {padding-bottom: 10px}
48-
#command-list li .execute {padding-left: 10px}
49-
.row:after {content:'';display:table;clear:both;}
50-
.execute {cursor: pointer;}
51-
</style>
52-
53-
<div class="admin__scope-old">
54-
<div class="entry-edit form-inline">
55-
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" >
56-
<div class="entry-edit form-inline">
57-
<fieldset class="fieldset admin__fieldset ">
58-
<legend class="admin__legend legend">
59-
<span><?php echo $block->escapeHtml(__('Current User Identity Verification')) ?></span>
60-
</legend>
61-
<br>
62-
<div class="messages">
63-
</div>
64-
<div class="admin__field field field-current_password required _required" >
65-
<label class="label admin__field-label" for="user_current_password"><span><?php echo $block->escapeHtml(__('Your Password')) ?></span></label>
66-
<div class="admin__field-control control">
67-
<input id="user_current_password" name="current_password" value="" title="<?php echo $block->escapeHtml(__('Your Password')) ?>" class="input-text " type="password" >
68-
</div>
69-
</div>
70-
</fieldset>
71-
</div>
72-
</div>
73-
</div>
74-
</div>
75-
76-
<div class="row">
77-
<div id="shell-area">
78-
<div class="history-hld"></div>
79-
<div class="input-hld">
80-
<?php if ($exec) { ?>
81-
<?php echo $block->escapeHtml(__('Enter Command:')) ?><input id="command" />
82-
<?php } else { ?>
83-
<?php echo $block->escapeHtml(__('This command line is not accessible. Exec function is not allowed in PHP settings. Please use the standard CLI interface.')) ?>
84-
<?php } ?>
43+
?>
44+
<style>
45+
#shell-area{float:left;width:78%;margin:0;list-style:none;background:#141414;color:#45D40C;font:.8em 'Andale Mono',Consolas,'Courier New';line-height:1.6em;padding:10px; min-height:500px;max-height:500px;overflow-y: auto;}
46+
#shell-area input{width:80%; background: #141414;border:none;padding:10px;line-height:15px}
47+
#command-list ul{float:right;height:200px;width:20%;min-height:500px;max-height:500px;}
48+
#command-list ul{overflow:hidden;overflow-y:scroll;overflow-x:scroll;}
49+
#command-list li {padding-bottom: 10px}
50+
#command-list li .execute {padding-left: 10px}
51+
.row:after {content:'';display:table;clear:both;}
52+
.execute {cursor: pointer;}
53+
</style>
54+
55+
<div class="admin__scope-old">
56+
<div class="entry-edit form-inline">
57+
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" >
58+
<div class="entry-edit form-inline">
59+
<fieldset class="fieldset admin__fieldset ">
60+
<legend class="admin__legend legend">
61+
<span><?php echo $block->escapeHtml(__('Current User Identity Verification')) ?></span>
62+
</legend>
63+
<br>
64+
<div class="messages">
65+
</div>
66+
<div class="admin__field field field-current_password required _required" >
67+
<label class="label admin__field-label" for="user_current_password"><span><?php echo $block->escapeHtml(__('Your Password')) ?></span></label>
68+
<div class="admin__field-control control">
69+
<input id="user_current_password" name="current_password" value="" title="<?php echo $block->escapeHtml(__('Your Password')) ?>" class="input-text " type="password" >
70+
</div>
71+
</div>
72+
</fieldset>
73+
</div>
74+
</div>
8575
</div>
8676
</div>
87-
<div id="command-list">
88-
<ul>
89-
<?php if (count($mostUsed)) { ?>
90-
<p><?= $block->escapeHtml(__('Most Used Commands')) ?></p>
91-
<?php foreach ($mostUsed as $command) { ?>
77+
78+
<div class="row">
79+
<div id="shell-area">
80+
<div class="history-hld"></div>
81+
<div class="input-hld">
82+
<?php if ($exec) { ?>
83+
<?php echo $block->escapeHtml(__('Enter Command:')) ?><input id="command" />
84+
<?php } else { ?>
85+
<?php echo $block->escapeHtml(__('This command line is not accessible. Exec function is not allowed in PHP settings. Please use the standard CLI interface.')) ?>
86+
<?php } ?>
87+
</div>
88+
</div>
89+
<div id="command-list">
90+
<ul>
91+
<?php if (count($mostUsed)) { ?>
92+
<p><?= $block->escapeHtml(__('Most Used Commands')) ?></p>
93+
<?php foreach ($mostUsed as $command) { ?>
94+
<?php if ($command) { ?>
95+
<li>
96+
<span class="execute-label"><?= $block->escapeHtml($command) ?></span>
97+
<span class="execute" title="<?= $block->escapeHtml('Execute') ?>" data-name="<?= $block->escapeHtml($command) ?>">▶</span>
98+
</li>
99+
<?php } ?>
100+
<?php } ?>
101+
<br><hr><br>
102+
<?php } ?>
103+
<?php foreach ($commands as $command) { ?>
92104
<?php if ($command) { ?>
93105
<li>
94106
<span class="execute-label"><?= $block->escapeHtml($command) ?></span>
95-
<span class="execute" title="<?= $block->escapeHtml('Execute') ?>" data-name="<?= $block->escapeHtml($command) ?>">▶</span>
107+
<span class="execute" title="<?= $block->escapeHtml('Execute') ?>" data-name="<?= $block->escapeHtml($command) ?>">▶</span>
96108
</li>
97109
<?php } ?>
98110
<?php } ?>
99-
<br><hr><br>
100-
<?php } ?>
101-
<?php foreach ($commands as $command) { ?>
102-
<?php if ($command) { ?>
103-
<li>
104-
<span class="execute-label"><?= $block->escapeHtml($command) ?></span>
105-
<span class="execute" title="<?= $block->escapeHtml('Execute') ?>" data-name="<?= $block->escapeHtml($command) ?>">▶</span>
106-
</li>
107-
<?php } ?>
108-
<?php } ?>
109-
</ul>
111+
</ul>
112+
</div>
110113
</div>
111-
</div>
112114

113-
<?php if ($exec) { ?>
114-
<script>
115-
require(['jquery', 'Magento_Ui/js/modal/confirm'], function($, confirmation) {
115+
<?php if ($exec) { ?>
116+
117+
<?php $script .= "
118+
require(['jquery', 'Magento_Ui/js/modal/confirm'], function($, confirmation) {
116119
$(function(){
117120
$('#shell-area').click(function(){
118121
$('#command').focus();
@@ -134,13 +137,13 @@
134137
135138
function addCommand()
136139
{
137-
var $e = $('#command');
138-
v = $.trim($e.val());
140+
var e = $('#command');
141+
v = $.trim(e.val());
139142
if (v) {
140143
commandLog.push(v);
141144
}
142145
var commandLogIndex = 0;
143-
$e.val('');
146+
e.val('');
144147
}
145148
146149
function addContent(c)
@@ -152,7 +155,7 @@
152155
153156
var loading = false;
154157
$('#command').keydown(function(e) {
155-
var $e = $(this);
158+
var e = $(this);
156159
if(e.which == 40) { //up
157160
commandLogIndex--;
158161
if (commandLogIndex < 0) {
@@ -169,25 +172,25 @@
169172
if (loading) return;
170173
loading = true;
171174
172-
if (!$.trim($e.val())) {
175+
if (!$.trim(e.val())) {
173176
addContent('<br/>');
174177
loading = false;
175178
return;
176179
}
177180
178181
$.ajax({
179-
url: '<?php echo $block->escapeUrl($block->getUrl('*/*/cli')) ?>',
180-
data : {command:$e.val(),current_password:$('#user_current_password').val()},
182+
url: '" . $block->escapeUrl($block->getUrl('*/*/cli')) . "',
183+
data : {command:e.val(),current_password:$('#user_current_password').val()},
181184
type: 'POST',
182185
dataType: 'json',
183186
showLoader: true
184187
}).done(function (data) {
185188
loading = false;
186189
if (data && data.message) {
187-
addContent('<strong>$ </strong>' + $e.val() + '<br/>');
190+
addContent('<strong>$ </strong>' + e.val() + '<br/>');
188191
addContent(data.message);
189192
} else {
190-
alert('<?php echo $block->escapeHtml(__('Unexpected error. Please refresh the page or try later.')) ?>');
193+
alert('" . $block->escapeHtml(__('Unexpected error. Please refresh the page or try later.')) . "');
191194
}
192195
});
193196
}
@@ -205,7 +208,7 @@
205208
loading = true;
206209
207210
$.ajax({
208-
url: '<?php echo $block->escapeUrl($block->getUrl('*/*/cli')) ?>',
211+
url: '" . $block->escapeUrl($block->getUrl('*/*/cli')) . "',
209212
data : {command:'php ' + command,current_password:$('#user_current_password').val()},
210213
type: 'POST',
211214
dataType: 'json',
@@ -216,7 +219,12 @@
216219
addContent('<strong>$ </strong>' + command + '<br/>');
217220
addContent(data.message);
218221
} else {
219-
alert('<?php echo $block->escapeHtml(__('Unexpected error. Please refresh the page or try later.')) ?>');
222+
alert('" . $block->escapeHtml(__('Unexpected error. Please refresh the page or try later.')) . "');
223+
}
224+
225+
if (data && data.newFormKey) {
226+
FORM_KEY = data.newFormKey;
227+
document.querySelector('input[name=\"form_key\"]').value = FORM_KEY;
220228
}
221229
});
222230
}
@@ -237,6 +245,8 @@
237245
});
238246
})
239247
});
240-
</script>
241-
<?php } ?>
248+
"; ?>
249+
250+
<?= /* @noEscape */ $mfSecureRenderer->renderTag('script', [], $script, false) ?>
251+
<?php } ?>
242252
<?php } ?>

0 commit comments

Comments
 (0)