подпилена страница выполнения 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';
|
require_once __DIR__ . '/inc/header.php';
|
||||||
|
|
||||||
|
global $USER;
|
||||||
|
|
||||||
if (isset($_REQUEST['execute']) && $_REQUEST['execute'] == 'Y') {
|
if (isset($_REQUEST['execute']) && $_REQUEST['execute'] == 'Y') {
|
||||||
$_SESSION['phpcmd_query'] = $_REQUEST['query'];
|
$_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">
|
<div class="pageheader">
|
||||||
@@ -51,24 +67,24 @@
|
|||||||
<form action="" method="POST">
|
<form action="" method="POST">
|
||||||
<input type="hidden" name="execute" value="Y">
|
<input type="hidden" name="execute" value="Y">
|
||||||
|
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Models\\DB;');">DB</button>
|
<?php
|
||||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Models\\User;');">User</button>
|
$userCodes = $USER->getMetaObject()->getMetaByName('code');
|
||||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Models\\MQ;');">MQ</button>
|
if (!empty($userCodes)) {
|
||||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Cache;');">Cache</button>
|
foreach ($userCodes as $code) {
|
||||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Log;');">Log</button>
|
$element = unserialize($code['value']);
|
||||||
<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 button-get" type="button"
|
||||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Pagination;');">Pagination
|
onClick="addUseSection(this, <?= $code['id'] ?>, '<?= base64_encode(
|
||||||
</button>
|
$element['code']
|
||||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\Registry;');">Registry</button>
|
); ?>');"><?= $element['name']; ?></button>
|
||||||
<button class="btn btn-primary" type="button" onClick="addUseSection(this, 'use Core\\Helpers\\SystemFunctions;');">
|
<button class="btn btn-danger button-delete" type="button" onclick="deleteUserCode(<?= $code['id'] ?>)">X</button>
|
||||||
SystemFunctions
|
<?php
|
||||||
</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>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@@ -90,6 +106,11 @@
|
|||||||
} ?>>
|
} ?>>
|
||||||
<label for="use_pre" class="form-label"> Отображать результат выполнения как текст</label>
|
<label for="use_pre" class="form-label"> Отображать результат выполнения как текст</label>
|
||||||
</div>
|
</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">
|
<div class="mb-3">
|
||||||
<input class="btn btn-primary" type="submit" name="btn" value="Выполнить">
|
<input class="btn btn-primary" type="submit" name="btn" value="Выполнить">
|
||||||
</div>
|
</div>
|
||||||
@@ -98,50 +119,57 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
/*var editor = CodeMirror.fromTextArea(document.getElementById("query"), {
|
function b64EncodeUnicode(str) {
|
||||||
lineNumbers: true
|
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
|
||||||
});
|
function toSolidBytes(match, p1) {
|
||||||
|
return String.fromCharCode('0x' + p1);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
function addUseSection(button, text) {
|
function b64DecodeUnicode(str) {
|
||||||
editor.setValue(text + "\n" + editor.getValue());
|
return decodeURIComponent(atob(str).split('').map(function (c) {
|
||||||
//button.disabled = true;
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
||||||
console.log(button);
|
}).join(''));
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
function addUseSection(button, id, text) {
|
||||||
function addUseSection(button, text) {
|
|
||||||
editor = document.getElementById("query");
|
editor = document.getElementById("query");
|
||||||
editor.value = text + "\n" + editor.value;
|
editor.value = b64DecodeUnicode(text) + "\n";
|
||||||
//button.disabled = true;
|
}
|
||||||
console.log(button);
|
|
||||||
|
function deleteUserCode(id) {
|
||||||
|
window.location.href = "phpcmd.php?delMeta=" + id
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<?php if (isset($_REQUEST['execute']) and $_REQUEST['execute'] == 'Y') {
|
<?php
|
||||||
echo '<h2 class="entry-title">Результат</h2><p class="exec_result">';
|
if (isset($_REQUEST['execute']) and $_REQUEST['execute'] == 'Y') {
|
||||||
|
echo '<h2 class="entry-title">Результат</h2><p class="exec_result">';
|
||||||
|
|
||||||
$execResult = '';
|
$execResult = '';
|
||||||
try {
|
try {
|
||||||
ob_start();
|
ob_start();
|
||||||
eval($_REQUEST['query']);
|
eval($_REQUEST['query']);
|
||||||
$execResult = ob_get_clean();
|
$execResult = ob_get_clean();
|
||||||
if (isset($_REQUEST['use_pre']) and $_REQUEST['use_pre'] == 'Y') {
|
if (isset($_REQUEST['use_pre']) and $_REQUEST['use_pre'] == 'Y') {
|
||||||
echo '<pre>' . $execResult . '</pre>';
|
echo '<pre>' . $execResult . '</pre>';
|
||||||
} else {
|
} else {
|
||||||
echo $execResult;
|
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>
|
</div>
|
||||||
<!-- end table -->
|
<!-- end table -->
|
||||||
</div><!-- contentpanel -->
|
</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'; ?>
|
<?php require_once __DIR__ . '/inc/footer.php'; ?>
|
||||||
@@ -42,7 +42,6 @@
|
|||||||
foreach ($res as $meta) {
|
foreach ($res as $meta) {
|
||||||
$userMeta[] = [
|
$userMeta[] = [
|
||||||
'id' => $meta['id'],
|
'id' => $meta['id'],
|
||||||
'type' => $meta['type'],
|
|
||||||
'name' => $meta['name'],
|
'name' => $meta['name'],
|
||||||
'value' => $meta['value'],
|
'value' => $meta['value'],
|
||||||
];
|
];
|
||||||
@@ -75,40 +74,6 @@
|
|||||||
foreach ($res as $meta) {
|
foreach ($res as $meta) {
|
||||||
$userMeta[] = [
|
$userMeta[] = [
|
||||||
'id' => $meta['id'],
|
'id' => $meta['id'],
|
||||||
'type' => $meta['type'],
|
|
||||||
'name' => $meta['name'],
|
|
||||||
'value' => $meta['value'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
Cache::set($cacheId, $userMeta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $userMeta;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Получает указанные мета данные пользователя
|
|
||||||
*
|
|
||||||
* @param string|null $type Тип мета
|
|
||||||
*
|
|
||||||
* @return array|null
|
|
||||||
* @throws \Core\CoreException
|
|
||||||
*/
|
|
||||||
public function getMetaByType(string $type): ?array
|
|
||||||
{
|
|
||||||
$cacheId = md5('Meta_' . $this->user->getId() . '_getMetaByType');
|
|
||||||
if (Cache::check($cacheId)) {
|
|
||||||
$userMeta = Cache::get($cacheId);
|
|
||||||
} else {
|
|
||||||
/** @var $DB DB */
|
|
||||||
$DB = DB::getInstance();
|
|
||||||
$res = $DB->query('SELECT * FROM `' . self::TABLE . '` WHERE user_id=' . $this->user->getId() . ' AND type="' . $type . '"');
|
|
||||||
if (!empty($res)) {
|
|
||||||
$userMeta = [];
|
|
||||||
foreach ($res as $meta) {
|
|
||||||
$userMeta[] = [
|
|
||||||
'id' => $meta['id'],
|
|
||||||
'type' => $meta['type'],
|
|
||||||
'name' => $meta['name'],
|
'name' => $meta['name'],
|
||||||
'value' => $meta['value'],
|
'value' => $meta['value'],
|
||||||
];
|
];
|
||||||
@@ -129,32 +94,32 @@
|
|||||||
* @return int|null
|
* @return int|null
|
||||||
* @throws \Core\CoreException
|
* @throws \Core\CoreException
|
||||||
*/
|
*/
|
||||||
public function addMeta(string $name, ?string $value = null, string $type = 'default'): ?int
|
public function addMeta(string $name, ?string $value = null): ?int
|
||||||
{
|
{
|
||||||
$cacheId = md5('Meta_' . $this->user->getId() . '_getAllMeta');
|
$cacheId = md5('Meta_' . $this->user->getId() . '_getAllMeta');
|
||||||
Cache::delete($cacheId);
|
Cache::delete($cacheId);
|
||||||
|
|
||||||
/** @var $DB DB */
|
/** @var $DB DB */
|
||||||
$DB = DB::getInstance();
|
$DB = DB::getInstance();
|
||||||
return $DB->addItem(self::TABLE, ['user_id' => $this->user->getId(), 'name' => $name, 'value' => $value, 'type' => $type]);
|
return $DB->addItem(self::TABLE, ['user_id' => $this->user->getId(), 'name' => $name, 'value' => $value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Убирает пользователю указанные мета данные
|
* Убирает пользователю указанные мета данные
|
||||||
*
|
*
|
||||||
* @param string $name Имя мета
|
* @param int $id ID Мета
|
||||||
*
|
*
|
||||||
* @return int|null
|
* @return void
|
||||||
* @throws \Core\CoreException
|
* @throws \Core\CoreException
|
||||||
*/
|
*/
|
||||||
public function deleteMeta(string $name): void
|
public function deleteMeta(int $id): void
|
||||||
{
|
{
|
||||||
$cacheId = md5('Roles_' . $this->user->getId() . '_getRoles');
|
$cacheId = md5('Roles_' . $this->user->getId() . '_getRoles');
|
||||||
Cache::delete($cacheId);
|
Cache::delete($cacheId);
|
||||||
|
|
||||||
/** @var $DB DB */
|
/** @var $DB DB */
|
||||||
$DB = DB::getInstance();
|
$DB = DB::getInstance();
|
||||||
$DB->query('DELETE FROM ' . self::TABLE . ' WHERE user_id=' . $this->user->getId() . ' AND name="' . $name . '"');
|
$DB->query('DELETE FROM ' . self::TABLE . ' WHERE user_id=' . $this->user->getId() . ' AND id="' . $id . '"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user