many fixes and expands and module expansions

This commit is contained in:
Dennis Eichhorn 2021-04-04 17:10:52 +02:00
parent 8fa0debbdf
commit 77a6043638
4 changed files with 179 additions and 92 deletions

View File

@ -47,6 +47,8 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/Monitoring/Theme/Backend/monitoring-dashboard'); $view->setTemplate('/Modules/Monitoring/Theme/Backend/monitoring-dashboard');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000706001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000706001, $request, $response));
$view->setData('logger', $this->app->logger);
return $view; return $view;
} }
@ -68,6 +70,8 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/Monitoring/Theme/Backend/monitoring-logs'); $view->setTemplate('/Modules/Monitoring/Theme/Backend/monitoring-logs');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000706001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000706001, $request, $response));
$view->setData('logger', $this->app->logger);
return $view; return $view;
} }
@ -89,6 +93,8 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/Monitoring/Theme/Backend/monitoring-logs-single'); $view->setTemplate('/Modules/Monitoring/Theme/Backend/monitoring-logs-single');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000706001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000706001, $request, $response));
$view->setData('logger', $this->app->logger);
return $view; return $view;
} }

View File

@ -12,54 +12,57 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
$logs = $this->app->logger->countLogs(); use phpOMS\System\SystemUtils;
$penetrators = $this->app->logger->getHighestPerpetrator();
$logger = $this->getData('logger');
$logs = $logger->countLogs();
$penetrators = $logger->getHighestPerpetrator();
echo $this->getData('nav')->render(); ?> echo $this->getData('nav')->render(); ?>
<div class="row"> <div class="row">
<div class="col-xs-12 col-md-4"> <div class="col-xs-12 col-md-4">
<section class="box wf-100"> <section class="portlet">
<header><h1><?= $this->getHtml('System'); ?></h1></header> <div class="portlet-head"><?= $this->getHtml('System'); ?></div>
<div class="inner"> <div class="portlet-body">
<table class="list wf-100"> <table class="list wf-100">
<tbody> <tbody>
<tr><td><?= $this->getHtml('OS'); ?><td><?= $this->printHtml(\php_uname('s')); ?> <tr><td><?= $this->getHtml('OS'); ?><td><?= $this->printHtml(\php_uname('s')); ?>
<tr><td><?= $this->getHtml('Version'); ?><td><?= $this->printHtml(\php_uname('v')); ?> <tr><td><?= $this->getHtml('Version'); ?><td><?= $this->printHtml(\php_uname('v')); ?>
<tr><td><?= $this->getHtml('Release'); ?><td><?= $this->printHtml(\php_uname('r')); ?> <tr><td><?= $this->getHtml('Release'); ?><td><?= $this->printHtml(\php_uname('r')); ?>
<tr><td><?= $this->getHtml('RAMUsage'); ?><td><?= $this->printHtml(\memory_get_usage(true) / (1024 * 1024)); ?> MB <tr><td><?= $this->getHtml('RAMUsage'); ?><td><?= $this->printHtml((string) (\memory_get_usage(true) / (1024 * 1024))); ?> MB
<tr><td><?= $this->getHtml('MemoryLimit'); ?><td><?= $this->printHtml(\ini_get('memory_limit')); ?> <tr><td><?= $this->getHtml('MemoryLimit'); ?><td><?= $this->printHtml(\ini_get('memory_limit')); ?>
<tr><td><?= $this->getHtml('SystemRAM'); ?><td><?= $this->printHtml(\phpOMS\System\SystemUtils::getRAM() / (1024)); ?> MB <tr><td><?= $this->getHtml('SystemRAM'); ?><td><?= $this->printHtml((string) (SystemUtils::getRAM() / (1024))); ?> MB
<tr><td><?= $this->getHtml('CPUUsage'); ?><td><?= $this->printHtml(\phpOMS\System\SystemUtils::getCpuUsage()); ?>% <tr><td><?= $this->getHtml('CPUUsage'); ?><td><?= $this->printHtml((string) SystemUtils::getCpuUsage()); ?>%
</table> </table>
</div> </div>
</section> </section>
</div> </div>
<div class="col-xs-12 col-md-4"> <div class="col-xs-12 col-md-4">
<section class="box wf-100"> <section class="portlet">
<header><h1><?= $this->getHtml('Logs'); ?></h1></header> <div class="portlet-head"><?= $this->getHtml('Logs'); ?></div>
<div class="inner"> <div class="portlet-body">
<table class="list wf-100"> <table class="list wf-100">
<tbody> <tbody>
<tr><td><?= $this->getHtml('Emergencies'); ?><td><?= $this->printHtml($logs['emergency'] ?? 0); ?> <tr><td><?= $this->getHtml('Emergencies'); ?><td><?= $this->printHtml((string) ($logs['emergency'] ?? 0)); ?>
<tr><td><?= $this->getHtml('Criticals'); ?><td><?= $this->printHtml($logs['critical'] ?? 0); ?> <tr><td><?= $this->getHtml('Criticals'); ?><td><?= $this->printHtml((string) ($logs['critical'] ?? 0)); ?>
<tr><td><?= $this->getHtml('Errors'); ?><td><?= $this->printHtml($logs['error'] ?? 0); ?> <tr><td><?= $this->getHtml('Errors'); ?><td><?= $this->printHtml((string) ($logs['error'] ?? 0)); ?>
<tr><td><?= $this->getHtml('Warnings'); ?><td><?= $this->printHtml($logs['warning'] ?? 0); ?> <tr><td><?= $this->getHtml('Warnings'); ?><td><?= $this->printHtml((string) ($logs['warning'] ?? 0)); ?>
<tr><td><?= $this->getHtml('Alerts'); ?><td><?= $this->printHtml($logs['alert'] ?? 0); ?> <tr><td><?= $this->getHtml('Alerts'); ?><td><?= $this->printHtml((string) ($logs['alert'] ?? 0)); ?>
<tr><td><?= $this->getHtml('Notices'); ?><td><?= $this->printHtml($logs['notice'] ?? 0); ?> <tr><td><?= $this->getHtml('Notices'); ?><td><?= $this->printHtml((string) ($logs['notice'] ?? 0)); ?>
<tr><td><?= $this->getHtml('Info'); ?><td><?= $this->printHtml($logs['info'] ?? 0); ?> <tr><td><?= $this->getHtml('Info'); ?><td><?= $this->printHtml((string) ($logs['info'] ?? 0)); ?>
<tr><td><?= $this->getHtml('Debug'); ?><td><?= $this->printHtml($logs['debug'] ?? 0); ?> <tr><td><?= $this->getHtml('Debug'); ?><td><?= $this->printHtml((string) ($logs['debug'] ?? 0)); ?>
<tr><td><?= $this->getHtml('Total'); ?><td><?= $this->printHtml(\array_sum($logs)); ?> <tr><td><?= $this->getHtml('Total'); ?><td><?= $this->printHtml((string) \array_sum($logs)); ?>
</table> </table>
</div> </div>
</section> </section>
</div> </div>
<div class="col-xs-12 col-md-4"> <div class="col-xs-12 col-md-4">
<section class="box wf-100"> <section class="portlet">
<header><h1><?= $this->getHtml('Penetrators'); ?></h1></header> <div class="portlet-head"><?= $this->getHtml('Penetrators'); ?></div>
<div class="inner"> <div class="portlet-body">
<table class="list wf-100"> <table class="list wf-100">
<tbody> <tbody>
<?php foreach ($penetrators as $ip => $count) : ?> <?php foreach ($penetrators as $ip => $count) : ?>

View File

@ -15,36 +15,37 @@ declare(strict_types=1);
/** /**
* @var \phpOMS\Views\View $this * @var \phpOMS\Views\View $this
*/ */
$logs = \array_reverse($this->app->logger->get(25), true); $logger = $this->getData('logger');
$logs = \array_reverse($logger->get(25), true);
echo $this->getData('nav')->render(); ?> echo $this->getData('nav')->render(); ?>
<div class="row"> <div class="row">
<div class="box col-xs-12 wf-100"> <div class="col-xs-12">
<table class="default"> <div class="portlet">
<caption><?= $this->getHtml('Logs'); ?><i class="fa fa-download floatRight download btn"></i></caption> <div class="portlet-head"><?= $this->getHtml('Modules'); ?><i class="fa fa-download floatRight download btn"></i></div>
<thead> <table class="default">
<tr> <thead>
<td><?= $this->getHtml('Timestamp'); ?> <tr>
<td><?= $this->getHtml('Level'); ?> <td><?= $this->getHtml('Timestamp'); ?>
<td><?= $this->getHtml('Source'); ?> <td><?= $this->getHtml('Level'); ?>
<td class="wf-100"><?= $this->getHtml('Message'); ?> <td><?= $this->getHtml('Source'); ?>
<tfoot> <td class="wf-100"><?= $this->getHtml('Message'); ?>
<tr> <tbody>
<td colspan="5"> <?php foreach ($logs as $key => $value) :
<tbody> $url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/monitoring/logs/single?{?}&id=' . $key); ?>
<?php foreach ($logs as $key => $value) : <tr>
$url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/monitoring/logs/single?{?}&id=' . $key); ?> <td><a href=<?= $this->printHtml($url); ?>><i class="fa fa-clock-o"></i> <?= $this->printHtml($value[0] ?? ''); ?></a>
<tr> <td><a href=<?= $this->printHtml($url); ?>><i class="fa fa-<?= $this->printHtml(\in_array($value[1], ['notice', 'info', 'debug']) ? 'info-circle' : 'warning'); ?>"></i> <?= $this->printHtml($value[1] ?? ''); ?></a>
<td><a href=<?= $this->printHtml($url); ?>><i class="fa fa-clock-o"></i> <?= $this->printHtml($value[0] ?? ''); ?></a> <td><a href=<?= $this->printHtml($url); ?>><i class="fa fa-wifi"></i> <?= $this->printHtml($value[2] ?? ''); ?></a>
<td><a href=<?= $this->printHtml($url); ?>><i class="fa fa-<?= $this->printHtml(\in_array($value[1], ['notice', 'info', 'debug']) ? 'info-circle' : 'warning'); ?>"></i> <?= $this->printHtml($value[1] ?? ''); ?></a> <td><a href=<?= $this->printHtml($url); ?>><i class="fa fa-commenting"></i> <?= $this->printHtml($value[7] ?? ''); ?></a>
<td><a href=<?= $this->printHtml($url); ?>><i class="fa fa-wifi"></i> <?= $this->printHtml($value[2] ?? ''); ?></a> <?php endforeach;
<td><a href=<?= $this->printHtml($url); ?>><i class="fa fa-commenting"></i> <?= $this->printHtml($value[7] ?? ''); ?></a> if (!isset($key)) : ?>
<?php endforeach; <tr>
if (!isset($key)) : ?> <td colspan="4">
<tr> <?php endif; ?>
<td colspan="4"> </table>
<?php endif; ?> </div>
</table>
</div> </div>
</div> </div>

View File

@ -19,13 +19,39 @@ use phpOMS\System\File\Local\Directory;
use phpOMS\System\File\Local\File; use phpOMS\System\File\Local\File;
use phpOMS\Uri\HttpUri; use phpOMS\Uri\HttpUri;
$fileHashs = \file_get_contents(__DIR__ . '/../../../../hashs.txt'); /* Rest::request(
new HttpRequest(
new HttpUri('https://raw.githubusercontent.com/Orange-Management/Build/master/hashs.txt')
)
)->getBody(); */
$hashs = [];
$fp = \fopen("php://memory", 'r+');
\fputs($fp, $fileHashs);
\rewind($fp);
while($line = \fgets($fp)){
$line = \trim($line);
if ($line === '') {
continue;
}
$whitespace = \stripos($line, ' ');
$length = \strlen($line);
$hash = \substr($line, 0, $whitespace);
$file = \trim(\substr($line, $whitespace + 2), '.\\/');
$hashs[$file] = $hash;
}
\fclose($fp);
echo $this->getData('nav')->render(); ?> echo $this->getData('nav')->render(); ?>
<div class="row"> <div class="row">
<div class="col-xs-12 col-md-4"> <div class="col-xs-12 col-md-4">
<section class="box wf-100"> <section class="portlet">
<header><h1><?= $this->getHtml('PHPSettings'); ?></h1></header> <div class="portlet-head"><?= $this->getHtml('PHPSettings'); ?></div>
<div class="inner"> <div class="portlet-body">
<table class="list wf-100"> <table class="list wf-100">
<tbody> <tbody>
<tr><td><?= $this->getHtml('DisabledFunctions'); ?><td><?= PhpCode::isDisabled(PhpCode::$disabledFunctions) ? $this->getHtml('OK') : $this->getHtml('NG'); ?> <tr><td><?= $this->getHtml('DisabledFunctions'); ?><td><?= PhpCode::isDisabled(PhpCode::$disabledFunctions) ? $this->getHtml('OK') : $this->getHtml('NG'); ?>
@ -38,74 +64,125 @@ echo $this->getData('nav')->render(); ?>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<div class="box wf-100"> <div class="portlet">
<table class="default"> <div class="portlet-head"><?= $this->getHtml('Inspection'); ?><i class="fa fa-download floatRight download btn"></i></div>
<caption><?= $this->getHtml('Inspection'); ?><i class="fa fa-download floatRight download btn"></i></caption> <table id="fileList" class="default">
<thead> <thead>
<tr> <tr>
<td><?= $this->getHtml('Status'); ?> <td><?= $this->getHtml('Status'); ?>
<label for="fileList-sort-1">
<input type="radio" name="fileList-sort" id="fileList-sort-1">
<i class="sort-asc fa fa-chevron-up"></i>
</label>
<label for="fileList-sort-2">
<input type="radio" name="fileList-sort" id="fileList-sort-2">
<i class="sort-desc fa fa-chevron-down"></i>
</label>
<label>
<i class="filter fa fa-filter"></i>
</label>
<td class="wf-100"><?= $this->getHtml('File'); ?> <td class="wf-100"><?= $this->getHtml('File'); ?>
<label for="fileList-sort-3">
<input type="radio" name="fileList-sort" id="fileList-sort-3">
<i class="sort-asc fa fa-chevron-up"></i>
</label>
<label for="fileList-sort-4">
<input type="radio" name="fileList-sort" id="fileList-sort-4">
<i class="sort-desc fa fa-chevron-down"></i>
</label>
<label>
<i class="filter fa fa-filter"></i>
</label>
<td><?= $this->getHtml('Unicode'); ?> <td><?= $this->getHtml('Unicode'); ?>
<label for="fileList-sort-5">
<input type="radio" name="fileList-sort" id="fileList-sort-5">
<i class="sort-asc fa fa-chevron-up"></i>
</label>
<label for="fileList-sort-6">
<input type="radio" name="fileList-sort" id="fileList-sort-6">
<i class="sort-desc fa fa-chevron-down"></i>
</label>
<label>
<i class="filter fa fa-filter"></i>
</label>
<td><?= $this->getHtml('Deprecated'); ?> <td><?= $this->getHtml('Deprecated'); ?>
<label for="fileList-sort-7">
<input type="radio" name="fileList-sort" id="fileList-sort-7">
<i class="sort-asc fa fa-chevron-up"></i>
</label>
<label for="fileList-sort-8">
<input type="radio" name="fileList-sort" id="fileList-sort-8">
<i class="sort-desc fa fa-chevron-down"></i>
</label>
<label>
<i class="filter fa fa-filter"></i>
</label>
<td><?= $this->getHtml('Modified'); ?> <td><?= $this->getHtml('Modified'); ?>
<label for="fileList-sort-9">
<input type="radio" name="fileList-sort" id="fileList-sort-9">
<i class="sort-asc fa fa-chevron-up"></i>
</label>
<label for="fileList-sort-10">
<input type="radio" name="fileList-sort" id="fileList-sort-10">
<i class="sort-desc fa fa-chevron-down"></i>
</label>
<label>
<i class="filter fa fa-filter"></i>
</label>
<td><?= $this->getHtml('Integrity'); ?> <td><?= $this->getHtml('Integrity'); ?>
<label for="fileList-sort-11">
<input type="radio" name="fileList-sort" id="fileList-sort-11">
<i class="sort-asc fa fa-chevron-up"></i>
</label>
<label for="fileList-sort-12">
<input type="radio" name="fileList-sort" id="fileList-sort-12">
<i class="sort-desc fa fa-chevron-down"></i>
</label>
<label>
<i class="filter fa fa-filter"></i>
</label>
<tbody> <tbody>
<?php <?php
$files = Directory::listByExtension(__DIR__ . '/../../../../phpOMS/', 'php', 'tests(\/|\\\)'); $files = Directory::listByExtension(__DIR__ . '/../../../../phpOMS/', 'php', 'tests(\/|\\\)');
foreach ($files as $file) : $content = \file_get_contents(__DIR__ . '/../../../../phpOMS/' . $file); ?> foreach ($files as $file) : $content = \file_get_contents(__DIR__ . '/../../../../phpOMS/' . $file); ?>
<tr> <tr>
<td> <td><?= ($unicode = PhpCode::hasUnicode($content)) || ($deprecated = PhpCode::hasDeprecatedFunction($content)) || !($integrity = PhpCode::validateFileIntegrity(
__DIR__ . '/../../../../phpOMS/' . $file,
$hashs['phpOMS/' . $file] ?? ''
)) ? $this->getHtml('NG') : $this->getHtml('OK'); ?>
<td><?= $file; ?> <td><?= $file; ?>
<td><?= PhpCode::hasUnicode($content) ? $this->getHtml('NG') : $this->getHtml('OK'); ?> <td><?= $unicode ? $this->getHtml('NG') : $this->getHtml('OK'); ?>
<td><?= PhpCode::hasDeprecatedFunction($content) ? $this->getHtml('NG') : $this->getHtml('OK'); ?> <td><?= $deprecated ? $this->getHtml('NG') : $this->getHtml('OK'); ?>
<td><?= File::changed(__DIR__ . '/../../../../phpOMS/' . $file)->format('Y-m-d'); ?> <td><?= File::changed(__DIR__ . '/../../../../phpOMS/' . $file)->format('Y-m-d'); ?>
<td> <td><?= $integrity ? $this->getHtml('OK') : $this->getHtml('NG'); ?>
<?= \phpOMS\Security\PhpCode::validateStringIntegrity(
$content,
Rest::request(
new HttpRequest(
new HttpUri('https://raw.githubusercontent.com/Orange-Management/phpOMS/develop/' . $file)
)
)->getBody()
) ? $this->getHtml('OK') : $this->getHtml('NG'); ?>
<?php endforeach; ?> <?php endforeach; ?>
<?php <?php
$files = Directory::listByExtension(__DIR__ . '/../../../../Model/', 'php', 'tests(\/|\\\)'); $files = Directory::listByExtension(__DIR__ . '/../../../../Model/', 'php', 'tests(\/|\\\)');
foreach ($files as $file) : $content = \file_get_contents(__DIR__ . '/../../../../Model/' . $file); ?> foreach ($files as $file) : $content = \file_get_contents(__DIR__ . '/../../../../Model/' . $file); ?>
<tr> <tr>
<td> <td><?= ($unicode = PhpCode::hasUnicode($content)) || ($deprecated = PhpCode::hasDeprecatedFunction($content)) || !($integrity = PhpCode::validateFileIntegrity(
__DIR__ . '/../../../../Model/' . $file,
$hashs['Model/' . $file] ?? ''
)) ? $this->getHtml('NG') : $this->getHtml('OK'); ?>
<td><?= $file; ?> <td><?= $file; ?>
<td><?= PhpCode::hasUnicode($content) ? $this->getHtml('NG') : $this->getHtml('OK'); ?> <td><?= $unicode ? $this->getHtml('NG') : $this->getHtml('OK'); ?>
<td><?= PhpCode::hasDeprecatedFunction($content) ? $this->getHtml('NG') : $this->getHtml('OK'); ?> <td><?= $deprecated ? $this->getHtml('NG') : $this->getHtml('OK'); ?>
<td><?= File::changed(__DIR__ . '/../../../../Model/' . $file)->format('Y-m-d'); ?> <td><?= File::changed(__DIR__ . '/../../../../Model/' . $file)->format('Y-m-d'); ?>
<td> <td><?= $integrity ? $this->getHtml('OK') : $this->getHtml('NG'); ?>
<?= \phpOMS\Security\PhpCode::validateStringIntegrity(
$content,
Rest::request(
new HttpRequest(
new HttpUri('https://raw.githubusercontent.com/Orange-Management/Model/develop/' . $file)
)
)->getBody()
) ? $this->getHtml('OK') : $this->getHtml('NG'); ?>
<?php endforeach; ?> <?php endforeach; ?>
<?php <?php
$files = Directory::listByExtension(__DIR__ . '/../../../../Modules/', 'php', 'tests(\/|\\\)'); $files = Directory::listByExtension(__DIR__ . '/../../../../Modules/', 'php', 'tests(\/|\\\)');
foreach ($files as $file) : $content = \file_get_contents(__DIR__ . '/../../../../Modules/' . $file); ?> foreach ($files as $file) : $content = \file_get_contents(__DIR__ . '/../../../../Modules/' . $file); ?>
<tr> <tr>
<td> <td><?= ($unicode = PhpCode::hasUnicode($content)) || ($deprecated = PhpCode::hasDeprecatedFunction($content)) || !($integrity = PhpCode::validateFileIntegrity(
__DIR__ . '/../../../../Modules/' . $file,
$hashs['Modules/' . $file] ?? ''
)) ? $this->getHtml('NG') : $this->getHtml('OK'); ?>
<td><?= $file; ?> <td><?= $file; ?>
<td><?= PhpCode::hasUnicode($content) ? $this->getHtml('NG') : $this->getHtml('OK'); ?> <td><?= $unicode ? $this->getHtml('NG') : $this->getHtml('OK'); ?>
<td><?= PhpCode::hasDeprecatedFunction($content) ? $this->getHtml('NG') : $this->getHtml('OK'); ?> <td><?= $deprecated ? $this->getHtml('NG') : $this->getHtml('OK'); ?>
<td><?= File::changed(__DIR__ . '/../../../../Modules/' . $file)->format('Y-m-d'); ?> <td><?= File::changed(__DIR__ . '/../../../../Modules/' . $file)->format('Y-m-d'); ?>
<td> <td><?= $integrity ? $this->getHtml('OK') : $this->getHtml('NG'); ?>
<?= \phpOMS\Security\PhpCode::validateStringIntegrity(
$content,
Rest::request(
new HttpRequest(
new HttpUri('https://raw.githubusercontent.com/Orange-Management/Modules/develop/' . $file)
)
)->getBody()
) ? $this->getHtml('OK') : $this->getHtml('NG'); ?>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
</div> </div>