1
0

selftest on admin page (WIP)

This commit is contained in:
Mike Schwörer 2020-01-19 01:22:06 +01:00
parent 86648149e5
commit 335fc764e8
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
16 changed files with 540 additions and 58 deletions

2
.gitignore vendored
View File

@ -8,3 +8,5 @@ runtime/
**/.idea/dataSources*
config.php
www/dtest.php

View File

@ -6,6 +6,8 @@
<language minSize="100" name="PHP" />
</Languages>
</inspection_tool>
<inspection_tool class="HtmlUnknownTarget" enabled="true" level="INFORMATION" enabled_by_default="true" />
<inspection_tool class="PhpUnhandledExceptionInspection" enabled="true" level="INFORMATION" enabled_by_default="true" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />

View File

@ -0,0 +1,14 @@
<?php
require_once (__DIR__ . '/../internals/website.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
if (!isset($API_OPTIONS['filter'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
$json = $SITE->modules->SelfTest()->run($API_OPTIONS['filter']);
echo json_encode($json);

View File

@ -782,12 +782,6 @@ html, body {
text-align: left;
}
.boxedcontent.alertbox {
background-color: #F52;
font-weight: bold;
text-align: center;
}
.egg_col_x5_0 {
fill: #eeeeee;
}
@ -858,7 +852,7 @@ html, body {
min-width: 300px;
}
.consistency_result_ok, .consistency_result_warn, .consistency_result_err {
.consistency_result_ok, .consistency_result_warn, .consistency_result_err, .consistency_result_intermed, .consistency_result_running {
min-width: 400px;
color: #222222;
border: 1px solid #888;
@ -878,6 +872,15 @@ html, body {
background: #FF0000;
}
.consistency_result_intermed {
background: #EEEEEE;
}
.consistency_result_running {
background: #DDDDDD;
border: 1px solid #000;
}
.admincontent .boxedcontent hr {
width: 95%;
height: 1px;
@ -891,6 +894,54 @@ html, body {
color: #BB2222;
}
.boxedcontent.alertbox {
background-color: #FF4444;
color: #222222;
border: 1px solid #AA4444;
font-weight: bold;
text-align: center;
}
.boxedcontent.alertbox .bc_data {
padding-top: 2px;
padding-bottom: 2px;
}
.boxedcontent.warnbox {
background-color: #FFA726;
color: #333333;
border: 1px solid #444444;
font-weight: bold;
text-align: center;
}
.boxedcontent.warnbox .bc_data {
padding-top: 2px;
padding-bottom: 2px;
}
.boxedcontent.graybox {
background-color: #888888;
color: #222222;
border: 1px solid #444444;
font-weight: bold;
text-align: center;
}
.boxedcontent.graybox .bc_data {
padding-top: 2px;
padding-bottom: 2px;
}
.boxedcontent.successbox {
background-color: #168B00;
color: #222222;
border: 1px solid #444444;
font-weight: bold;
text-align: center;
}
.boxedcontent.successbox .bc_data {
padding-top: 2px;
padding-bottom: 2px;
}
/* 400px */
#loginform div {
display: flex;

View File

@ -152,7 +152,6 @@ html,body{margin:0;padding:0;height:100%}
.about_circles{display:flex;flex-direction:column}
.about_circles a{margin:5px 0}
.about_circles .iconbutton_light span{text-align:left}
.boxedcontent.alertbox{background-color:#F52;font-weight:bold;text-align:center}
.egg_col_x5_0{fill:#eee}
.egg_col_x5_1{fill:#6bcdff}
.egg_col_x5_2{fill:#00a1f3}
@ -168,12 +167,22 @@ 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{min-width:400px;color:#222;border:1px solid #888;padding:0 5px;margin:1px 0}
.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_ok{background:#0f0}
.consistency_result_warn{background:#ff0}
.consistency_result_err{background:red}
.consistency_result_intermed{background:#eee}
.consistency_result_running{background:#ddd;border:1px solid #000}
.admincontent .boxedcontent hr{width:95%;height:1px;border:0;color:#FFFFFF00;background:-moz-radial-gradient(circle,rgba(0,0,0,0.1),rgba(0,0,0,0));background:-webkit-radial-gradient(circle,rgba(0,0,0,0.1) 0,rgba(0,0,0,0) 100%)}
.admindberr{color:#b22}
.boxedcontent.alertbox{background-color:#f44;color:#222;border:1px solid #a44;font-weight:bold;text-align:center}
.boxedcontent.alertbox .bc_data{padding-top:2px;padding-bottom:2px}
.boxedcontent.warnbox{background-color:#ffa726;color:#333;border:1px solid #444;font-weight:bold;text-align:center}
.boxedcontent.warnbox .bc_data{padding-top:2px;padding-bottom:2px}
.boxedcontent.graybox{background-color:#888;color:#222;border:1px solid #444;font-weight:bold;text-align:center}
.boxedcontent.graybox .bc_data{padding-top:2px;padding-bottom:2px}
.boxedcontent.successbox{background-color:#168b00;color:#222;border:1px solid #444;font-weight:bold;text-align:center}
.boxedcontent.successbox .bc_data{padding-top:2px;padding-bottom:2px}
#loginform div{display:flex;flex-direction:column}
#loginform div button{margin:10px 0;padding:0}
.loginerror{display:flex;background:#f44;color:#222;border:1px solid #a44;border-radius:2px;font-weight:bold;padding:0 5px;margin:5px 0 20px 0}

View File

@ -112,12 +112,6 @@
}
.boxedcontent.alertbox {
background-color: #F52;
font-weight: bold;
text-align: center;
}
@if $CFG_EGG_THEME == 'standard'
{
// ==== STANDARD ====

View File

@ -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_ok, .consistency_result_warn, .consistency_result_err, .consistency_result_intermed, .consistency_result_running {
min-width: 400px;
color: $COL_ADMIN_STATUS_FG;
border: $COL_ADMIN_STATUS_BORDER;
@ -52,6 +52,8 @@
.consistency_result_ok { background: $COL_ADMIN_OK; }
.consistency_result_warn { background: $COL_ADMIN_WARN; }
.consistency_result_err { background: $COL_ADMIN_ERROR; }
.consistency_result_intermed { background: $COL_ADMIN_INTERMED; }
.consistency_result_running { background: $COL_ADMIN_RUNNING; border: $COL_ADMIN_STATUS_BORDER_ACTIVE; }
.admincontent .boxedcontent hr {
@ -64,3 +66,51 @@
}
.admindberr { color: $COL_ADMIN_STATUS_DB_ERROR; }
.boxedcontent.alertbox {
background-color: $COL_TOAST_ERROR_BG;
color: $COL_TOAST_ERROR_FG;
border: $COL_TOAST_ERROR_BORDER;
font-weight: bold;
text-align: center;
.bc_data {
padding-top: 2px;
padding-bottom: 2px;
}
}
.boxedcontent.warnbox {
background-color: $COL_TOAST_WARN_BG;
color: $COL_TOAST_WARN_FG;
border: $COL_TOAST_WARN_BORDER;
font-weight: bold;
text-align: center;
.bc_data {
padding-top: 2px;
padding-bottom: 2px;
}
}
.boxedcontent.graybox {
background-color: $COL_TOAST_GRAY_BG;
color: $COL_TOAST_GRAY_FG;
border: $COL_TOAST_GRAY_BORDER;
font-weight: bold;
text-align: center;
.bc_data {
padding-top: 2px;
padding-bottom: 2px;
}
}
.boxedcontent.successbox {
background-color: $COL_TOAST_SUCCESS_BG;
color: $COL_TOAST_SUCCESS_FG;
border: $COL_TOAST_SUCCESS_BORDER;
font-weight: bold;
text-align: center;
.bc_data {
padding-top: 2px;
padding-bottom: 2px;
}
}

View File

@ -119,6 +119,18 @@ $COL_TOAST_ERROR_FG: #222222;
$COL_TOAST_ERROR_BG: #FF4444;
$COL_TOAST_ERROR_BORDER: 1px solid #AA4444;
$COL_TOAST_WARN_FG: #333333;
$COL_TOAST_WARN_BG: #FFA726;
$COL_TOAST_WARN_BORDER: $LAYER1_BORDER;
$COL_TOAST_GRAY_FG: #222222;
$COL_TOAST_GRAY_BG: #888888;
$COL_TOAST_GRAY_BORDER: $LAYER1_BORDER;
$COL_TOAST_SUCCESS_FG: #222222;
$COL_TOAST_SUCCESS_BG: #168B00;
$COL_TOAST_SUCCESS_BORDER: $LAYER1_BORDER;
// ------------------------------------
$COL_EULER_TIME_0_SAT: #00AA00;
@ -152,9 +164,12 @@ $AOC_DESCRIPTION_BG: #333333;
$COL_ADMIN_OK: #00FF00;
$COL_ADMIN_WARN: #FFFF00;
$COL_ADMIN_ERROR: #FF0000;
$COL_ADMIN_INTERMED: #EEEEEE;
$COL_ADMIN_RUNNING: #DDDDDD;
$COL_ADMIN_STATUS_FG: #222222;
$COL_ADMIN_STATUS_BORDER: 1px solid #888;
$COL_ADMIN_STATUS_BORDER_ACTIVE: 1px solid #000;
$COL_ADMIN_STATUS_DB_ERROR: #BB2222;

View File

@ -70,3 +70,59 @@ function startAjaxReplace(target, url)
async: true
});
}
function refreshConsistencyDisplay(skip)
{
let i = 0;
for (let apibutton of $('.consistence_ajax_handler').toArray())
{
if (i++ !== skip) continue;
const filter = $(apibutton).data('filter');
$(apibutton).removeClass('consistency_result_intermed');
$(apibutton).addClass('consistency_result_running');
$.ajax('/api/site::selftest?filter=' + filter)
.done((data, status, xhr) =>
{
let json = JSON.parse(data);
$(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+" ");
}
setTimeout(() => refreshConsistencyDisplay(skip+1), 300);
})
.fail((xhr, status, err) =>
{
$(apibutton).removeClass('consistency_result_intermed');
$(apibutton).removeClass('consistency_result_running');
$(apibutton).addClass('consistency_result_err');
$(apibutton).text(err+" ");
setTimeout(() => refreshConsistencyDisplay(skip+1), 300);
});
}
}
$(function()
{
setTimeout(() => refreshConsistencyDisplay(0), 200);
});

View File

@ -53,11 +53,9 @@ $URL_RULES =
[ 'url' => ['log'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ],
[ 'url' => ['blogpost', 'index'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ],
[ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['blog', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['blog', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ],
[ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['log', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ],
[ 'url' => ['log', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ],
[ 'url' => ['blogpost', 'view'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%GET%', 'subview' => '' ], ],

View File

@ -15,6 +15,7 @@ class Modules
/** @var WebApps|null */ private $webapps = null;
/** @var MikescherGitGraph|null */ private $extendedgitgraph = null;
/** @var Highscores|null */ private $highscores = null;
/** @var SelfTest|null */ private $selftest = null;
/** @var Website */
private $site;
@ -89,4 +90,10 @@ class Modules
if ($this->highscores === null) { require_once 'modules/highscores.php'; $this->highscores = new Highscores($this->site); }
return $this->highscores;
}
public function SelfTest(): SelfTest
{
if ($this->selftest === null) { require_once 'modules/selftest.php'; $this->selftest = new SelfTest(); }
return $this->selftest;
}
}

View File

@ -45,6 +45,13 @@ class AdventOfCode
return $this->staticData;
}
public function listAllDays()
{
$r = [];
foreach ($this->staticData as $yeardata) foreach ($yeardata as $year => $daydata) $r []= $daydata;
return $this->staticData;
}
public function listSingleYear($year)
{
return $this->staticData[$year];
@ -84,6 +91,7 @@ class AdventOfCode
$a['file_challenge'] = (__DIR__ . '/../../statics/aoc/'.$year.'/'.$n2p.'_challenge.txt');
$a['file_input'] = (__DIR__ . '/../../statics/aoc/'.$year.'/'.$n2p.'_input.txt');
$a['year'] = $year;
$a['date'] = $year . '-' . 12 . '-' . $n2p;
$solutionfiles = [];

View File

@ -0,0 +1,263 @@
<?php
class SelfTest
{
private const STATUS_ERROR = 2;
private const STATUS_WARN = 1;
private const STATUS_OK = 0;
private const DISPLAY_NAMES =
[
'web::main' => 'Website (http)',
'web::programs' => 'Programs (http)',
'web::books' => 'Books (http)',
'web::blog' => 'Blog (http)',
'web::webapps' => 'WebApps (http)',
'web::euler' => 'Project Euler (http)',
'web::aoc' => 'Advent of code (http)',
'api::default' => 'API',
'api::highscore' => 'Highscores API',
];
private $methods = [];
public function __construct()
{
$this->init();
}
private function init()
{
$this->addMethodPathStatus("web::main::index-1", 200, '');
$this->addMethodPathStatus("web::main::index-2", 200, '/index');
$this->addMethodPathStatus("web::main::index-3", 200, '/index.php');
$this->addMethodPathStatus("web::main::index-4", 200, '/msmain/index');
$this->addMethodPathStatus("web::main::about-1", 200, '/about');
$this->addMethodPathStatus("web::main::about-2", 200, '/msmain/about');
$this->addMethodPathStatus("web::main::login-1", 200, '/login');
$this->addMethodPathStatus("web::main::404-1", 404, '/asdf');
$this->addMethodRedirect( "web::main::redirect-1", '');
$this->addMethodRedirect( "web::main::redirect-2", '/about');
$this->addHTTPSRedirect( "web::main::redirect-3", '/about');
$this->addMethodPathStatus( "web::programs::programs-list-1", 200, '/programs');
$this->addMethodPathStatus( "web::programs::programs-list-2", 200, '/programs/index');
$this->addMethodPathStatus( "web::programs::programs-list-3", 200, '/downloads/details.php');
$this->addMethodPathStatus( "web::programs::programs-list-4", 200, '/downloads/downloads.php');
$this->addMethodMultiPathStatus("web::programs::programs-filtered-1", 200, '/programs/index?categoryfilter={0}', function(){ return array_key_map_unique(Website::inst()->modules->Programs()->listAll(), 'category'); });
$this->addMethodMultiPathStatus("web::programs::programs-filtered-2", 200, '/programs/cat/{0}', function(){ return array_key_map_unique(Website::inst()->modules->Programs()->listAll(), 'category'); });
$this->addMethodMultiPathStatus("web::programs::programs-show-1", 200, '/programs/view/{0}', function(){ return array_key_map(Website::inst()->modules->Programs()->listAll(), 'internal_name'); });
$this->addMethodMultiPathStatus("web::programs::programs-show-2", 200, '/programs/view?id={0}', function(){ return array_key_map(Website::inst()->modules->Programs()->listAll(), 'internal_name'); });
$this->addMethodMultiPathStatus("web::programs::programs-show-3", 200, '{0}', function(){ return array_key_map(Website::inst()->modules->Programs()->listAll(), 'url'); });
$this->addMethodMultiPathStatus("web::programs::programs-download-1", 301, '/downloads/{0}', function(){ return array_key_map(Website::inst()->modules->Programs()->listAll(), 'internal_name'); });
$this->addMethodMultiPathStatus("web::programs::programs-download-2", 301, '/programs/download/{0}', function(){ return array_key_map(Website::inst()->modules->Programs()->listAll(), 'internal_name'); });
$this->addMethodMultiPathStatus("web::programs::programs-download-3", 301, '/programs/download?id={0}', function(){ return array_key_map(Website::inst()->modules->Programs()->listAll(), 'internal_name'); });
$this->addMethodPathStatus( "web::programs::programs-404-1", 404, '/programs/view/asdf_not_found');
$this->addMethodPathStatus( "web::programs::programs-404-2", 404, '/programs/download/asdf_not_found');
$this->addMethodExtProgLinks( "web::programs::programs-ext-links");
$this->addMethodPathStatus( "web::books::books-list-1", 200, '/books');
$this->addMethodPathStatus( "web::books::books-list-2", 200, '/books/list');
$this->addMethodMultiPathStatus("web::books::books-show-1", 200, '/books/view/{0}', function(){ return array_key_map(Website::inst()->modules->Books()->listAll(), 'id'); });
$this->addMethodMultiPathStatus("web::books::books-show-2", 200, '{0}', function(){ return array_key_map(Website::inst()->modules->Books()->listAll(), 'url'); });
$this->addMethodPathStatus( "web::books::books-404-1", 404, '/books/view/asdf/not_found');
$this->addMethodPathStatus( "web::blog::blog-list-1", 200, '/blog');
$this->addMethodPathStatus( "web::blog::blog-list-2", 200, '/log');
$this->addMethodPathStatus( "web::blog::blog-list-3", 200, '/blogpost/index');
$this->addMethodMultiPathStatus("web::blog::blog-show-1", 200, '/blog/{0}', function(){ return array_key_map(Website::inst()->modules->Blog()->listAll(), 'id'); });
$this->addMethodMultiPathStatus("web::blog::blog-show-2", 200, '/log/{0}', function(){ return array_key_map(Website::inst()->modules->Blog()->listAll(), 'id'); });
$this->addMethodMultiPathStatus("web::blog::blog-show-3", 200, '/blogpost/view?id={0}', function(){ return array_key_map(Website::inst()->modules->Blog()->listAll(), 'id'); });
$this->addMethodMultiPathStatus("web::blog::blog-show-4", 200, '{0}', function(){ return array_key_map(Website::inst()->modules->Blog()->listAll(), 'url'); });
$this->addMethodPathStatus( "web::blog::blog-404-1", 404, '/blog/999999');
$this->addMethodPathStatus( "web::blog::blog-404-2", 404, '/blog/999999/Notfound');
$this->addMethodPathStatus( "web::blog::blog-404-3", 404, '/blog/asdf');
$this->addMethodPathStatus("web::webapps::webapps-list-1", 200, '/webapps');
$this->addMethodPathStatus( "web::euler::euler-list-1", 200, '/blog/1/Project_Euler_with_Befunge');
$this->addMethodMultiPathStatus("web::euler::euler-show-1", 200, '{0}', function(){ return array_key_map(Website::inst()->modules->Euler()->listAll(), 'url'); });
$this->addMethodPathStatus( "web::euler::euler-404-1", 404, '/blog/1/Project_Euler_with_Befunge/problem-A');
$this->addMethodPathStatus( "web::euler::euler-404-2", 404, '/blog/1/Project_Euler_with_Befunge/problem-99999');
$this->addMethodPathStatus( "web::euler::euler-404-3", 404, '/blog/1/Project_Euler_with_Befunge/asdf');
$this->addMethodMultiPathStatus("web::aoc::aoc-list-1", 200, '{0}', function(){ return array_map(function($x){return Website::inst()->modules->AdventOfCode()->getURLForYear($x);},Website::inst()->modules->AdventOfCode()->listYears()); });
$this->addMethodMultiPathStatus("web::aoc::aoc-show-1", 200, '{0}', function(){ return array_key_map(Website::inst()->modules->AdventOfCode()->listAllDays(), 'url'); });
$this->addMethodPathStatus( "web::aoc::aoc-404-1", 404, '/blog/25/Advent_of_Code_2017/day-26');
$this->addMethodPathStatus( "web::aoc::aoc-404-2", 404, '/blog/23/Advent_of_Code_2018/day-27');
$this->addMethodPathStatus( "web::aoc::aoc-404-3", 404, '/blog/24/Advent_of_Code_2019/day-28');
$this->addCheckConsistency("modules::database::database-check-consistency", function(){ return Website::inst()->modules->Database(); });
$this->addCheckConsistency("modules::blog::blog-check-consistency", function(){ return Website::inst()->modules->Blog(); });
$this->addCheckConsistency("modules::euler::euler-check-consistency", function(){ return Website::inst()->modules->Euler(); });
$this->addCheckConsistency("modules::books::books-check-consistency", function(){ return Website::inst()->modules->Books(); });
$this->addCheckConsistency("modules::extgitgraph::extgitgraph-check-consistency", function(){ return Website::inst()->modules->ExtendedGitGraph(); });
$this->addCheckConsistency("modules::programs::programs-check-consistency", function(){ return Website::inst()->modules->Programs(); });
$this->addCheckConsistency("modules::books::books-check-consistency", function(){ return Website::inst()->modules->Books(); });
$this->addCheckConsistency("modules::adventofcode::adventofcode-check-consistency", function(){ return Website::inst()->modules->AdventOfCode(); });
$this->addCheckConsistency("modules::anstatistics::anstatistics-check-consistency", function(){ return Website::inst()->modules->AlephNoteStatistics(); });
$this->addCheckConsistency("modules::updateslog::updateslog-check-consistency", function(){ return Website::inst()->modules->UpdatesLog(); });
$this->addCheckConsistency("modules::webapps::webapps-check-consistency", function(){ return Website::inst()->modules->WebApps(); });
$this->addCheckConsistency("modules::highscores::highscores-check-consistency", function(){ return Website::inst()->modules->Highscores(); });
$ajaxsecret = Website::inst()->config['ajax_secret'];
$this->addMethodPathResponse( "api::default::base-test-2", 200, '{}', '/api/test');
$this->addMethodPathResponse( "api::default::base-test-4", 200, '{}', '/api/base::test');
$this->addMethodMultiPathStatus("api::default::updatecheck-1", 200, '/update.php?name={0}', function(){ return array_keys(Website::inst()->modules->UpdatesLog()->listUpdateData()); });
$this->addMethodMultiPathStatus("api::default::updatecheck-2", 200, '/update.php/{0}', function(){ return array_keys(Website::inst()->modules->UpdatesLog()->listUpdateData()); });
$this->addMethodMultiPathStatus("api::default::updatecheck-3", 200, '/update?name={0}', function(){ return array_keys(Website::inst()->modules->UpdatesLog()->listUpdateData()); });
$this->addMethodMultiPathStatus("api::default::updatecheck-4", 200, '/update/{0}', function(){ return array_keys(Website::inst()->modules->UpdatesLog()->listUpdateData()); });
$this->addMethodMultiPathStatus("api::default::updatecheck-5", 200, '/update2?name={0}', function(){ return array_keys(Website::inst()->modules->UpdatesLog()->listUpdateData()); });
$this->addMethodMultiPathStatus("api::default::updatecheck-6", 200, '/api/update?name={0}', function(){ return array_keys(Website::inst()->modules->UpdatesLog()->listUpdateData()); });
$this->addMethodMultiPathStatus("api::default::updatecheck-7", 200, '/api/update/{0}', function(){ return array_keys(Website::inst()->modules->UpdatesLog()->listUpdateData()); });
$this->addMethodPathStatus( "api::default::egg-status", 200, "/api/extendedgitgraph::status?ajax_secret=$ajaxsecret");
$this->addMethodPathStatus( "api::default::an-show", 200, "/api/alephnote::show?ajax_secret=$ajaxsecret");
$this->addMethodPathStatus( "api::default::updates-show", 200, "/api/updates::show?ajax_secret=$ajaxsecret");
$this->addMethodPathStatus( "api::default::aoc-ajax", 200, "/api/html::panel_aoc_calendar");
$this->addMethodPathStatus( "api::default::404-1", 404, '/api/update/no_prog_xx');
$this->addMethodPathStatus( "api::default::404-2", 404, '/api/asdf::notfound');
$this->addMethodPathStatus( "api::highscore::listgames-1", 200, "/highscores/list.php");
$this->addMethodPathStatus( "api::highscore::listgames-2", 200, "/highscores/list");
$this->addMethodPathStatus( "api::highscore::listgames-3", 200, "/highscores/listgames");
$this->addMethodMultiPathStatus("api::highscore::listentries-1", 200, "/highscores/list.php?gameid={0}", function(){ return [1,2,3,4,5,6]; });
$this->addMethodMultiPathStatus("api::highscore::listentries-2", 200, "/highscores/list?gameid={0}", function(){ return [1,2,3,4,5,6]; });
$this->addMethodMultiPathStatus("api::highscore::listentries-3", 200, "/highscores/listentries?gameid={0}", function(){ return [1,2,3,4,5,6]; });
$this->addMethodMultiPathStatus("api::highscore::top50-1", 200, "/highscores/list_top50.php?gameid={0}", function(){ return [1,2,3,4,5,6]; });
$this->addMethodMultiPathStatus("api::highscore::top50-2", 200, "/highscores/list_top50?gameid={0}", function(){ return [1,2,3,4,5,6]; });
$this->addMethodGitStatusCheck("backend::git::git-status");
}
/** @noinspection PhpUnhandledExceptionInspection */
public function listMethodGroups()
{
$data = [];
foreach ($this->methods as $method)
{
$parts = explode('::', $method['name']);
if (count($parts) !== 3) throw new Exception();
$data []= ($parts[0] . '::' . $parts[1]);
}
$data = array_unique($data);
$result = [];
foreach ($data as $d)
{
$result []=
[
'name' => key_exists($d, self::DISPLAY_NAMES) ? self::DISPLAY_NAMES[$d] : $d,
'filter' => $d.'::*',
'base' => $d
];
}
return $result;
}
private function addMethodPathStatus(string $name, int $status, string $path)
{
$this->methods []=
[
'name' => $name,
'func' => function() use ($name, $path, $status)
{
$xname = explode('::', $name)[2];
try
{
//$r = curl_http_request($_SERVER['HTTP_HOST'] . $path);
$r = curl_http_request('https://www.mikescher.com/' . $path);
if ($r['statuscode'] == $status) return
[
'result' => self::STATUS_OK,
'message' => "{".$xname."} succeeded",
'long' => null,
'exception' => null,
];
return
[
'result' => self::STATUS_ERROR,
'message' => '{'.$xname.'} failed: Request returned wrong statuscode',
'long' => 'Wrong HTTP Statuscode (Expected: ['.$status.']; Found: ['.$r['statuscode'].'])' . "\n" . "Response:\n" . $r['output'],
'exception' => null,
];
}
catch (Exception $e)
{
return
[
'result' => self::STATUS_ERROR,
'message' => "{$xname} failed: " . $e->getMessage(),
'long' => formatException($e),
'exception' => $e,
];
}
}
];
}
private function addMethodMultiPathStatus(string $name, int $status, string $path, Closure $supplier)
{
//TODO
}
private function addCheckConsistency(string $name, Closure $moduleSupplier)
{
//TODO
}
private function addMethodPathResponse(string $name, int $statuscode, string $json_expected, string $path)
{
//TODO
}
private function addMethodGitStatusCheck(string $name)
{
//TODO
}
private function addMethodExtProgLinks(string $name)
{
//TODO
}
private function addMethodRedirect(string $name, string $url)
{
//TODO
}
private function addHTTPSRedirect(string $name)
{
//TODO
}
public function run($filter)
{
$rex = '/^' . str_replace('*', '([^:]*)', $filter) . '$/';
$fullmessage = '';
$count = 0;
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";
$count++;
}
return
[
'result' => self::STATUS_OK,
'message' => "{$count} methods succeeded",
'long' => $fullmessage,
'exception' => null,
];
}
}

View File

@ -246,3 +246,33 @@ function formatException($e)
return 'object';
}
function array_key_map_unique(array $array, string $key)
{
$r = [];
foreach ($array as $d) if (!in_array($d[$key], $r)) $r []= $d[$key];
return $r;
}
function array_key_map(array $array, string $key)
{
$r = [];
foreach ($array as $d) $r []= $d[$key];
return $r;
}
function curl_http_request($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$redirect = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
curl_close($ch);
return [ 'output'=>$output, 'statuscode'=>$httpcode, 'redirect'=>$redirect ];
}

View File

@ -17,24 +17,6 @@ $FRAME_OPTIONS->addScript('/data/javascript/admin.js', true);
$connected = true; try { $SITE->modules->Database(); } catch (Exception $e) { $connected = false; }
$rok = ['result'=>'ok','message'=>''];
$consistency_blog = $rok; try { $consistency_blog = $SITE->modules->Blog()->checkConsistency(); } catch (Exception $e) { $consistency_blog = ['result'=>'ok', 'message'=>"$e"]; }
$consistency_prog = $rok; try { $consistency_prog = $SITE->modules->Programs()->checkConsistency(); } catch (Exception $e) { $consistency_prog = ['result'=>'ok', 'message'=>"$e"]; }
$consistency_euler = $rok; try { $consistency_euler = $SITE->modules->Euler()->checkConsistency(); } catch (Exception $e) { $consistency_euler = ['result'=>'ok', 'message'=>"$e"]; }
$consistency_books = $rok; try { $consistency_books = $SITE->modules->Books()->checkConsistency(); } catch (Exception $e) { $consistency_books = ['result'=>'ok', 'message'=>"$e"]; }
$consistency_egg = $rok; try { $consistency_egg = $SITE->modules->ExtendedGitGraph()->checkConsistency(); } catch (Exception $e) { $consistency_egg = ['result'=>'ok', 'message'=>"$e"]; }
$consistency_progimg = $rok; try { $consistency_progimg = $SITE->modules->Programs()->checkThumbnails(); } catch (Exception $e) { $consistency_progimg = ['result'=>'ok', 'message'=>"$e"]; }
$consistency_bookimg = $rok; try { $consistency_bookimg = $SITE->modules->Books()->checkThumbnails(); } catch (Exception $e) { $consistency_bookimg = ['result'=>'ok', 'message'=>"$e"]; }
$consistency_aoc = $rok; try { $consistency_aoc = $SITE->modules->AdventOfCode()->checkConsistency(); } catch (Exception $e) { $consistency_aoc = ['result'=>'ok', 'message'=>"$e"]; }
function dumpConsistency($c)
{
if ($c['result']==='ok') echo "<span class='consistency_result_ok'>OK</span>";
else if ($c['result']==='warn') echo "<span class='consistency_result_warn'>".$c['message']."</span>";
else echo "<span class='consistency_result_err'>".$c['message']."</span>";
}
?>
<div class="admincontent">
@ -47,6 +29,12 @@ function dumpConsistency($c)
</div>
<?php endif; ?>
<?php if (!$SITE->isProd()): ?>
<div class="boxedcontent warnbox">
<div class="bc_data">Website runs in /dev/ mode</div>
</div>
<?php endif; ?>
<!-- - - - - - - - - - - - - - - - - - - - - -->
<div class="boxedcontent">
@ -67,19 +55,13 @@ function dumpConsistency($c)
<div class="bc_data">
<div class="keyvaluelist kvl_200">
<div><span>Program thumbnails:</span> <?php dumpConsistency($consistency_progimg); ?></div>
<div><span>ExtendedGitGraph:</span> <?php dumpConsistency($consistency_egg); ?></div>
<div><span>Book thumbnails:</span> <?php dumpConsistency($consistency_bookimg); ?></div>
<div><span>Blog data:</span> <?php dumpConsistency($consistency_blog); ?></div>
<div><span>Euler data:</span> <?php dumpConsistency($consistency_euler); ?></div>
<div><span>AdventOfCode data:</span> <?php dumpConsistency($consistency_aoc); ?></div>
<div><span>Programs data:</span> <?php dumpConsistency($consistency_prog); ?></div>
<div><span>Books data:</span> <?php dumpConsistency($consistency_books); ?></div>
<?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']; ?>">&nbsp;</span></div>
<?php endforeach; ?>
</div>
<br/>
<a class="button" href="/api/site::createProgramThumbnails">Update Program Thumbnails</a>
<a class="button" href="/api/site::createBookThumbnails">Update Book Thumbnails</a>
</div>
</div>

View File

@ -19,6 +19,7 @@ $API_COMMANDS =
'site::createprogramthumbnails' => [ 'src' => __DIR__.'/../commands/site_createProgramThumbnails.php', 'auth' => 'admin' ],
'site::createbookthumbnails' => [ 'src' => __DIR__.'/../commands/site_createBookThumbnails.php', 'auth' => 'admin' ],
'site::selftest' => [ 'src' => __DIR__.'/../commands/site_selftest.php', 'auth' => 'admin' ],
'server::setselfaddress' => [ 'src' => __DIR__.'/../commands/server_setselfaddress.php', 'auth' => 'none' ],
'server::gitwebhook' => [ 'src' => __DIR__.'/../commands/server_gitwebhook.php', 'auth' => 'webhook_secret' ],