подпилена страница выполнения PHP кода на использования мета данных пользователей
This commit is contained in:
1 parent
d6c2a58951
commit
c2031769cf
2 files changed
+95
-92
No files matched your search
+89
-51
@@ -23,8 +23,24 @@
|
||||
|
||||
require_once __DIR__ . '/inc/header.php';
|
||||
|
||||
global $USER;
|
||||
|
||||
if (isset($_REQUEST['execute']) && $_REQUEST['execute'] == 'Y') {
|
||||
$_SESSION['phpcmd_query'] = $_REQUEST['query'];
|
||||
|
||||
if (isset($_REQUEST['save']) and $_REQUEST['save'] == 'Y') {
|
||||
$arQuery = explode(PHP_EOL, $_REQUEST['query']);
|
||||
if (stristr($arQuery[0], '//title: ')) {
|
||||
$queryName = str_replace('//title: ', '', $arQuery[0]);
|
||||
} else {
|
||||
$queryName = 'PHP код ' . date('d.m H:i');
|
||||
}
|
||||
$USER->getMetaObject()->addMeta('code', serialize(['name' => $queryName, 'code' => $_REQUEST['query']]));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['delMeta'])) {
|
||||
$USER->getMetaObject()->deleteMeta($_REQUEST['delMeta']);
|
||||
}
|
||||
?>
|
||||
<div class="pageheader">
|
||||
@@ -51,24 +67,24 @@
|
||||
<form action="" method="POST">
|
||||
<input type="hidden" name="execute" value="Y">
|
||||
|
||||
|
||||
<div class="mb-3">
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Models\\DB;');">DB</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Models\\User;');">User</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Models\\MQ;');">MQ</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Cache;');">Cache</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Log;');">Log</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Files;');">Files</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Mail;');">Mail</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Pagination;');">Pagination
|
||||
</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Registry;');">Registry</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\SystemFunctions;');">
|
||||
SystemFunctions
|
||||
</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Zip;');">Zip</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\CoreException;');">CoreException
|
||||
</button>
|
||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Template;');">Template</button>
|
||||
<?php
|
||||
$userCodes = $USER->getMetaObject()->getMetaByName('code');
|
||||
if (!empty($userCodes)) {
|
||||
foreach ($userCodes as $code) {
|
||||
$element = unserialize($code['value']);
|
||||
?>
|
||||
<button class="btn btn-primary button-get" type="button"
|
||||
onClick="addUseSection(this, <?= $code['id'] ?>, '<?= base64_encode(
|
||||
$element['code']
|
||||
); ?>');"><?= $element['name']; ?></button>
|
||||
<button class="btn btn-danger button-delete" type="button" onclick="deleteUserCode(<?= $code['id'] ?>)">X</button>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
@@ -90,6 +106,11 @@
|
||||
} ?>>
|
||||
<label for="use_pre" class="form-label"> Отображать результат выполнения как текст</label>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
|
||||
<input id="save" type="checkbox" name="save" value="Y">
|
||||
<label for="save" class="form-label"> Сохранить вариант кода</label>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input class="btn btn-primary" type="submit" name="btn" value="Выполнить">
|
||||
</div>
|
||||
@@ -98,50 +119,57 @@
|
||||
</form>
|
||||
|
||||
<script>
|
||||
/*var editor = CodeMirror.fromTextArea(document.getElementById("query"), {
|
||||
lineNumbers: true
|
||||
});
|
||||
function b64EncodeUnicode(str) {
|
||||
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
|
||||
function toSolidBytes(match, p1) {
|
||||
return String.fromCharCode('0x' + p1);
|
||||
}));
|
||||
}
|
||||
|
||||
function addUseSection(button, text) {
|
||||
editor.setValue(text + "\n" + editor.getValue());
|
||||
//button.disabled = true;
|
||||
console.log(button);
|
||||
}*/
|
||||
function b64DecodeUnicode(str) {
|
||||
return decodeURIComponent(atob(str).split('').map(function (c) {
|
||||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
||||
}).join(''));
|
||||
}
|
||||
|
||||
|
||||
function addUseSection(button, text) {
|
||||
function addUseSection(button, id, text) {
|
||||
editor = document.getElementById("query");
|
||||
editor.value = text + "\n" + editor.value;
|
||||
//button.disabled = true;
|
||||
console.log(button);
|
||||
editor.value = b64DecodeUnicode(text) + "\n";
|
||||
}
|
||||
|
||||
function deleteUserCode(id) {
|
||||
window.location.href = "phpcmd.php?delMeta=" + id
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php if (isset($_REQUEST['execute']) and $_REQUEST['execute'] == 'Y') {
|
||||
echo '<h2 class="entry-title">Результат</h2><p class="exec_result">';
|
||||
<?php
|
||||
if (isset($_REQUEST['execute']) and $_REQUEST['execute'] == 'Y') {
|
||||
echo '<h2 class="entry-title">Результат</h2><p class="exec_result">';
|
||||
|
||||
$execResult = '';
|
||||
try {
|
||||
ob_start();
|
||||
eval($_REQUEST['query']);
|
||||
$execResult = ob_get_clean();
|
||||
if (isset($_REQUEST['use_pre']) and $_REQUEST['use_pre'] == 'Y') {
|
||||
echo '<pre>' . $execResult . '</pre>';
|
||||
} else {
|
||||
echo $execResult;
|
||||
$execResult = '';
|
||||
try {
|
||||
ob_start();
|
||||
eval($_REQUEST['query']);
|
||||
$execResult = ob_get_clean();
|
||||
if (isset($_REQUEST['use_pre']) and $_REQUEST['use_pre'] == 'Y') {
|
||||
echo '<pre>' . $execResult . '</pre>';
|
||||
} else {
|
||||
echo $execResult;
|
||||
}
|
||||
} catch (ParseError $p) {
|
||||
echo '<div class="alert alert-danger"><p><strong>(ParseError)</strong> Ошибка парсинга: ' . $p->getMessage()
|
||||
. '</p></div>';
|
||||
} catch (Throwable $e) {
|
||||
echo '<div class="alert alert-danger"><p><strong>(Throwable)</strong> Ошибка при выполнении: ' . $e->getMessage()
|
||||
. '</p></div>';
|
||||
} catch (Error $e) {
|
||||
echo '<div class="alert alert-danger"><p><strong>(Error)</strong> Ошибка при выполнении: ' . $e->getMessage()
|
||||
. '</p></div>';
|
||||
}
|
||||
} catch (ParseError $p) {
|
||||
echo '<div class="alert alert-danger"><p><strong>(ParseError)</strong> Ошибка парсинга: ' . $p->getMessage() . '</p></div>';
|
||||
} catch (Throwable $e) {
|
||||
echo '<div class="alert alert-danger"><p><strong>(Throwable)</strong> Ошибка при выполнении: ' . $e->getMessage()
|
||||
. '</p></div>';
|
||||
} catch (Error $e) {
|
||||
echo '<div class="alert alert-danger"><p><strong>(Error)</strong> Ошибка при выполнении: ' . $e->getMessage() . '</p></div>';
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
}
|
||||
echo '</p>';
|
||||
}
|
||||
?>
|
||||
|
||||
<!----->
|
||||
@@ -149,4 +177,14 @@
|
||||
</div>
|
||||
<!-- end table -->
|
||||
</div><!-- contentpanel -->
|
||||
<style>
|
||||
button.btn.btn-primary.button-get {
|
||||
border-radius: 3px 0px 0px 3px;
|
||||
}
|
||||
|
||||
button.btn.btn-danger.button-delete {
|
||||
margin-left: -5px;
|
||||
border-radius: 0px 3px 3px 0px;
|
||||
}
|
||||
</style>
|
||||
<?php require_once __DIR__ . '/inc/footer.php'; ?>
|
||||
Reference in new issue
Block a user