continue working on selftest
This commit is contained in:
parent
335fc764e8
commit
a78d8ff9c9
6
.idea/jsLibraryMappings.xml
Normal file
6
.idea/jsLibraryMappings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptLibraryMappings">
|
||||
<file url="file://$PROJECT_DIR$/www/data/javascript/admin.js" libraries="{jquery-latest}" />
|
||||
</component>
|
||||
</project>
|
@ -8,5 +8,6 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="jquery-latest" level="application" />
|
||||
</component>
|
||||
</module>
|
@ -1,3 +1,4 @@
|
||||
@charset "UTF-8";
|
||||
/* 400px */
|
||||
body {
|
||||
background-color: #EEEEEE;
|
||||
@ -852,7 +853,7 @@ html, body {
|
||||
min-width: 300px;
|
||||
}
|
||||
|
||||
.consistency_result_ok, .consistency_result_warn, .consistency_result_err, .consistency_result_intermed, .consistency_result_running {
|
||||
.consistency_result {
|
||||
min-width: 400px;
|
||||
color: #222222;
|
||||
border: 1px solid #888;
|
||||
@ -860,6 +861,10 @@ html, body {
|
||||
margin: 1px 0;
|
||||
}
|
||||
|
||||
.consistency_result:after {
|
||||
content: " ";
|
||||
}
|
||||
|
||||
.consistency_result_ok {
|
||||
background: #00FF00;
|
||||
}
|
||||
|
5
www/data/css/styles.min.css
vendored
5
www/data/css/styles.min.css
vendored
@ -1,4 +1,4 @@
|
||||
body{background-color:#eee;color:#333;font-family:"Times New Roman",serif}
|
||||
@charset "UTF-8";body{background-color:#eee;color:#333;font-family:"Times New Roman",serif}
|
||||
#content{padding-top:64px;display:flex;justify-content:center;line-height:1.4;flex-direction:column;align-items:center}
|
||||
.content-responsive{margin-left:auto;margin-right:auto}
|
||||
@media(max-width:767px){.content-responsive{width:95%;width:calc(100% - 20px);margin-left:auto;margin-right:auto}}
|
||||
@ -167,7 +167,8 @@ html,body{margin:0;padding:0;height:100%}
|
||||
.kvl_100 div span:first-child{min-width:100px}
|
||||
.kvl_200 div span:first-child{min-width:200px}
|
||||
.kvl_300 div span:first-child{min-width:300px}
|
||||
.consistency_result_ok,.consistency_result_warn,.consistency_result_err,.consistency_result_intermed,.consistency_result_running{min-width:400px;color:#222;border:1px solid #888;padding:0 5px;margin:1px 0}
|
||||
.consistency_result{min-width:400px;color:#222;border:1px solid #888;padding:0 5px;margin:1px 0}
|
||||
.consistency_result:after{content:" "}
|
||||
.consistency_result_ok{background:#0f0}
|
||||
.consistency_result_warn{background:#ff0}
|
||||
.consistency_result_err{background:red}
|
||||
|
@ -41,7 +41,7 @@
|
||||
.kvl_200 div span:first-child { min-width: 200px; }
|
||||
.kvl_300 div span:first-child { min-width: 300px; }
|
||||
|
||||
.consistency_result_ok, .consistency_result_warn, .consistency_result_err, .consistency_result_intermed, .consistency_result_running {
|
||||
.consistency_result {
|
||||
min-width: 400px;
|
||||
color: $COL_ADMIN_STATUS_FG;
|
||||
border: $COL_ADMIN_STATUS_BORDER;
|
||||
@ -49,6 +49,8 @@
|
||||
margin: 1px 0;
|
||||
}
|
||||
|
||||
.consistency_result:after { content: '\00a0' }
|
||||
|
||||
.consistency_result_ok { background: $COL_ADMIN_OK; }
|
||||
.consistency_result_warn { background: $COL_ADMIN_WARN; }
|
||||
.consistency_result_err { background: $COL_ADMIN_ERROR; }
|
||||
|
@ -90,23 +90,14 @@ function refreshConsistencyDisplay(skip)
|
||||
$(apibutton).removeClass('consistency_result_intermed');
|
||||
$(apibutton).removeClass('consistency_result_running');
|
||||
|
||||
if (json.result === 0)
|
||||
{
|
||||
$(apibutton).addClass('consistency_result_ok');
|
||||
$(apibutton).text(json.message+" ");
|
||||
}
|
||||
else if (json.result === 1)
|
||||
{
|
||||
$(apibutton).addClass('consistency_result_warn');
|
||||
$(apibutton).text(json.message+" ");
|
||||
}
|
||||
else if (json.result === 2)
|
||||
{
|
||||
$(apibutton).addClass('consistency_result_err');
|
||||
$(apibutton).text(json.message+" ");
|
||||
}
|
||||
if (json.result === 0) $(apibutton).addClass('consistency_result_ok');
|
||||
if (json.result === 1) $(apibutton).addClass('consistency_result_warn');
|
||||
if (json.result === 2) $(apibutton).addClass('consistency_result_err');
|
||||
|
||||
setTimeout(() => refreshConsistencyDisplay(skip+1), 300);
|
||||
$(apibutton).text(json.message);
|
||||
$(apibutton).attr('title', json.long);
|
||||
|
||||
setTimeout(() => refreshConsistencyDisplay(skip+1), 10);
|
||||
})
|
||||
.fail((xhr, status, err) =>
|
||||
{
|
||||
@ -114,9 +105,9 @@ function refreshConsistencyDisplay(skip)
|
||||
$(apibutton).removeClass('consistency_result_running');
|
||||
|
||||
$(apibutton).addClass('consistency_result_err');
|
||||
$(apibutton).text(err+" ");
|
||||
$(apibutton).text(err);
|
||||
|
||||
setTimeout(() => refreshConsistencyDisplay(skip+1), 300);
|
||||
setTimeout(() => refreshConsistencyDisplay(skip+1), 10);
|
||||
});
|
||||
|
||||
}
|
||||
|
6
www/internals/iwebsitemodule.php
Normal file
6
www/internals/iwebsitemodule.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
interface IWebsiteModule
|
||||
{
|
||||
public function checkConsistency();
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class AdventOfCode
|
||||
class AdventOfCode implements IWebsiteModule
|
||||
{
|
||||
const YEARS =
|
||||
[
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class AlephNoteStatistics
|
||||
class AlephNoteStatistics implements IWebsiteModule
|
||||
{
|
||||
/** @var Website */
|
||||
private $site;
|
||||
@ -29,4 +29,9 @@ class AlephNoteStatistics
|
||||
{
|
||||
return $this->site->modules->Database()->sql_query_assoc('SELECT * FROM an_statslog WHERE NoteCount>0 ORDER BY LastChanged DESC');
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Blog
|
||||
class Blog implements IWebsiteModule
|
||||
{
|
||||
/** @var array */
|
||||
private $staticData;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Books
|
||||
class Books implements IWebsiteModule
|
||||
{
|
||||
/** @var Website */
|
||||
private $site;
|
||||
@ -40,7 +40,7 @@ class Books
|
||||
for ($i=1; $i <= $a['imagecount']; $i++)
|
||||
{
|
||||
$a['extraimages_urls'] []= '/data/images/book_img/' . $a['id'] . '_img' . $i . '.jpg';
|
||||
$a['extraimages_paths'] []= __DIR__ . '/../data/images/book_img/' . $a['id'] . '_img' . $i . '.jpg';
|
||||
$a['extraimages_paths'] []= __DIR__ . '/../../data/images/book_img/' . $a['id'] . '_img' . $i . '.jpg';
|
||||
}
|
||||
|
||||
$a['book_count'] = is_array($a['pdf']) ? count($a['pdf']) : 1;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Database
|
||||
class Database implements IWebsiteModule
|
||||
{
|
||||
/* @var PDO $pdo */
|
||||
private $pdo = NULL;
|
||||
@ -91,4 +91,9 @@ class Database
|
||||
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Euler
|
||||
class Euler implements IWebsiteModule
|
||||
{
|
||||
/** @var array */
|
||||
private $staticData;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Highscores
|
||||
class Highscores implements IWebsiteModule
|
||||
{
|
||||
/** @var Website */
|
||||
private $site;
|
||||
@ -105,4 +105,9 @@ class Highscores
|
||||
[ ':pid', $playerid, PDO::PARAM_INT ],
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
require_once (__DIR__ . '/../../extern/egg/ExtendedGitGraph2.php');
|
||||
|
||||
class MikescherGitGraph
|
||||
class MikescherGitGraph implements IWebsiteModule
|
||||
{
|
||||
/** @var ExtendedGitGraph2 */
|
||||
private $extgitgraph;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Programs
|
||||
class Programs implements IWebsiteModule
|
||||
{
|
||||
const PROG_LANGS = [ 'Java', 'C#', 'Delphi', 'PHP', 'C++' ];
|
||||
|
||||
@ -68,7 +68,7 @@ class Programs
|
||||
foreach ($a['extra_images'] as $fn)
|
||||
{
|
||||
$a['extraimages_urls'] []= '/data/images/program_img/' . $fn;
|
||||
$a['extraimages_paths'] []= __DIR__ . '/../data/images/program_img/' . $fn;
|
||||
$a['extraimages_paths'] []= __DIR__ . '/../../data/images/program_img/' . $fn;
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,7 +249,7 @@ class Programs
|
||||
|
||||
foreach ($prog['extraimages_paths'] as $eipath)
|
||||
{
|
||||
if (!file_exists($eipath)) return ['result'=>'err', 'message' => 'Extra-Image not found ' . $prog['title_short']];
|
||||
if (!file_exists($eipath)) return ['result'=>'err', 'message' => 'Extra-Image not found ' . $prog['name'], 'long' => $eipath];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class SelfTest
|
||||
class SelfTest implements IWebsiteModule
|
||||
{
|
||||
private const STATUS_ERROR = 2;
|
||||
private const STATUS_WARN = 1;
|
||||
@ -167,8 +167,15 @@ class SelfTest
|
||||
|
||||
try
|
||||
{
|
||||
//$r = curl_http_request($_SERVER['HTTP_HOST'] . $path);
|
||||
$r = curl_http_request('https://www.mikescher.com/' . $path);
|
||||
if (!Website::inst()->isProd()) return
|
||||
[
|
||||
'result' => self::STATUS_WARN,
|
||||
'message' => '{'.$xname.'} not executed: curl requests in dev mode prohibited',
|
||||
'long' => null,
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
$r = curl_http_request($_SERVER['HTTP_HOST'] . $path);
|
||||
if ($r['statuscode'] == $status) return
|
||||
[
|
||||
'result' => self::STATUS_OK,
|
||||
@ -191,7 +198,7 @@ class SelfTest
|
||||
[
|
||||
'result' => self::STATUS_ERROR,
|
||||
'message' => "{$xname} failed: " . $e->getMessage(),
|
||||
'long' => formatException($e),
|
||||
'long' => str_max_len($e->getMessage(), 48),
|
||||
'exception' => $e,
|
||||
];
|
||||
}
|
||||
@ -206,7 +213,58 @@ class SelfTest
|
||||
|
||||
private function addCheckConsistency(string $name, Closure $moduleSupplier)
|
||||
{
|
||||
//TODO
|
||||
$this->methods []=
|
||||
[
|
||||
'name' => $name,
|
||||
'func' => function() use ($name, $moduleSupplier)
|
||||
{
|
||||
$xname = explode('::', $name)[2];
|
||||
|
||||
try
|
||||
{
|
||||
/** @var IWebsiteModule $module */
|
||||
$module = $moduleSupplier();
|
||||
|
||||
$consistency = $module->checkConsistency();
|
||||
|
||||
if ($consistency['result'] === 'err') return
|
||||
[
|
||||
'result' => self::STATUS_ERROR,
|
||||
'message' => $consistency['message'],
|
||||
'long' => isset($consistency['long']) ? $consistency['long'] : null,
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
if ($consistency['result'] === 'warn') return
|
||||
[
|
||||
'result' => self::STATUS_WARN,
|
||||
'message' => $consistency['message'],
|
||||
'long' => isset($consistency['long']) ? $consistency['long'] : null,
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
if ($consistency['result'] === 'ok') return
|
||||
[
|
||||
'result' => self::STATUS_OK,
|
||||
'message' => 'OK',
|
||||
'long' => isset($consistency['long']) ? $consistency['long'] : null,
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
throw new Exception("Unknown result: " . print_r($consistency, true));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_ERROR,
|
||||
'message' => str_max_len($e->getMessage(), 48),
|
||||
'long' => formatException($e),
|
||||
'exception' => $e,
|
||||
];
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
private function addMethodPathResponse(string $name, int $statuscode, string $json_expected, string $path)
|
||||
@ -239,25 +297,53 @@ class SelfTest
|
||||
$rex = '/^' . str_replace('*', '([^:]*)', $filter) . '$/';
|
||||
|
||||
$fullmessage = '';
|
||||
$fullwarnmessage = '';
|
||||
|
||||
$warnings = 0;
|
||||
$count = 0;
|
||||
$lastresult = null;
|
||||
foreach ($this->methods as $method)
|
||||
{
|
||||
if (!preg_match($rex, $method['name'])) continue;
|
||||
|
||||
$r = $method['func']();
|
||||
if ($r['result'] !== self::STATUS_OK) return $r;
|
||||
$fullmessage = $fullmessage . $method['message'] . "\n";
|
||||
$lastresult = $r = $method['func']();
|
||||
if ($r['result'] === self::STATUS_ERROR) return $r;
|
||||
if ($r['result'] === self::STATUS_WARN) { $warnings++; $fullwarnmessage .= $r['message'] . "\n"; }
|
||||
$fullmessage .= $r['message'] . "\n";
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
if ($warnings > 0)
|
||||
{
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_OK,
|
||||
'message' => "{$count} methods succeeded",
|
||||
'long' => $fullmessage,
|
||||
'result' => self::STATUS_WARN,
|
||||
'message' => "$warnings/$count methods had warnings",
|
||||
'long' => $fullwarnmessage,
|
||||
'exception' => null,
|
||||
];
|
||||
}
|
||||
|
||||
if ($count === 0) return
|
||||
[
|
||||
'result' => self::STATUS_WARN,
|
||||
'message' => "No methods matched filter",
|
||||
'long' => null,
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_OK,
|
||||
'message' => "OK",
|
||||
'long' => "$count methods succeeded\n\n" . $fullmessage,
|
||||
'exception' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class UpdatesLog
|
||||
class UpdatesLog implements IWebsiteModule
|
||||
{
|
||||
/** @var Website */
|
||||
private $site;
|
||||
@ -61,4 +61,20 @@ class UpdatesLog
|
||||
[':lt', $limit, PDO::PARAM_INT],
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
$warn = null;
|
||||
|
||||
$this->load();
|
||||
|
||||
foreach ($this->staticData as $name => $data)
|
||||
{
|
||||
if (!key_exists('version', $data)) return ['result'=>'err', 'message' => 'Missing value [version]'];
|
||||
if (!key_exists('url', $data)) return ['result'=>'err', 'message' => 'Missing value [url]'];
|
||||
}
|
||||
|
||||
if ($warn != null) return $warn;
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class WebApps
|
||||
class WebApps implements IWebsiteModule
|
||||
{
|
||||
/** @var array */
|
||||
private $staticData;
|
||||
@ -28,4 +28,22 @@ class WebApps
|
||||
usort($data, function($a, $b) { return strcasecmp($b['date'], $a['date']); });
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
$warn = null;
|
||||
|
||||
$this->load();
|
||||
|
||||
$ids = [];
|
||||
|
||||
foreach ($this->staticData as $prog)
|
||||
{
|
||||
if (in_array($prog['id'], $ids)) return ['result'=>'err', 'message' => 'Duplicate id ' . $prog['id']];
|
||||
$ids []= $prog['id'];
|
||||
}
|
||||
|
||||
if ($warn != null) return $warn;
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
@ -220,6 +220,13 @@ function isHTTPRequest()
|
||||
return (!isset($_SERVER['HTTPS'])) || empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off";
|
||||
}
|
||||
|
||||
function str_max_len(string $str, int $max)
|
||||
{
|
||||
if (strlen($str) < $max) return $str;
|
||||
|
||||
return substr($str, 0, $max-3)."...";
|
||||
}
|
||||
|
||||
function formatException($e)
|
||||
{
|
||||
if ($e === null) return "NULL";
|
||||
|
@ -3,6 +3,7 @@
|
||||
require_once 'ruleengine.php';
|
||||
require_once 'urlroute.php';
|
||||
require_once 'pageframeoptions.php';
|
||||
require_once 'iwebsitemodule.php';
|
||||
require_once 'modules.php';
|
||||
require_once 'fragments.php';
|
||||
|
||||
|
@ -56,7 +56,7 @@ $connected = true; try { $SITE->modules->Database(); } catch (Exception $e) { $c
|
||||
<div class="bc_data">
|
||||
<div class="keyvaluelist kvl_200">
|
||||
<?php foreach ($SITE->modules->SelfTest()->listMethodGroups() as $group): ?>
|
||||
<div><span><?php echo $group['name']; ?></span><span class='consistency_result_intermed consistence_ajax_handler' data-filter="<?php echo $group['filter']; ?>"> </span></div>
|
||||
<div><span><?php echo $group['name']; ?></span><span class='consistency_result consistency_result_intermed consistence_ajax_handler' data-filter="<?php echo $group['filter']; ?>"> </span></div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<br/>
|
||||
|
Loading…
Reference in New Issue
Block a user