1
0

Show admin page even without db connection

This commit is contained in:
Mike Schwörer 2019-12-28 23:52:19 +01:00
parent d0aea4e4e7
commit 3f4cc7875d
8 changed files with 101 additions and 38 deletions

View File

@ -782,6 +782,12 @@ html, body {
text-align: left;
}
.boxedcontent.alertbox {
background-color: #F52;
font-weight: bold;
text-align: center;
}
.egg_col_x5_0 {
fill: #eeeeee;
}
@ -837,6 +843,7 @@ html, body {
.keyvaluelist div span:first-child {
font-weight: bold;
min-width: 500px;
align-self: start;
}
.kvl_100 div span:first-child {

View File

@ -152,6 +152,7 @@ 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}
@ -163,7 +164,7 @@ html,body{margin:0;padding:0;height:100%}
.keyvaluelist{display:flex;flex-direction:column}
.keyvaluelist div{display:flex;flex-direction:row}
.keyvaluelist div span{align-self:center}
.keyvaluelist div span:first-child{font-weight:bold;min-width:500px}
.keyvaluelist div span:first-child{font-weight:bold;min-width:500px;align-self:start}
.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}

View File

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

View File

@ -32,6 +32,7 @@
span:first-child {
font-weight: bold;
min-width: 500px;
align-self: start;
}
}
}

View File

@ -4,7 +4,7 @@ function queryStatus(appendix, secret)
url: '/api/extendedgitgraph::status?secret='+secret,
success: function(result)
{
let ajaxOutput = $('#egh_ajaxOutput');
let ajaxOutput = $('#egg_ajaxOutput');
ajaxOutput.val(result + '\r\n' + appendix);
ajaxOutput.scrollTop(ajaxOutput[0].scrollHeight);
},

View File

@ -21,6 +21,16 @@ class Database
self::$PDO = new PDO($dsn, $CONFIG['user'], $CONFIG['password'], $opt);
}
public static function tryconnect()
{
try {
self::connect();
return true;
} catch (exception $e) {
return false;
}
}
public static function sql_query_num($query)
{
$r = self::$PDO->query($query)->fetch(PDO::FETCH_NUM)[0];

View File

@ -13,7 +13,7 @@ require_once (__DIR__ . '/../internals/programs.php');
require_once (__DIR__ . '/../internals/books.php');
require_once (__DIR__ . '/../internals/updateslog.php');
Database::connect();
$connected = Database::tryconnect();
$consistency_blog = Blog::checkConsistency();
$consistency_prog = Programs::checkConsistency();
@ -54,6 +54,12 @@ function dumpConsistency($c) {
<div class="contentheader"><h1>Admin</h1><hr/></div>
<?php if (!$connected): ?>
<div class="boxedcontent alertbox">
<div class="bc_data">Could not connect to database</div>
</div>
<?php endif; ?>
<!-- - - - - - - - - - - - - - - - - - - - - -->
<div class="boxedcontent">
@ -128,16 +134,20 @@ function dumpConsistency($c) {
<div class="boxedcontent">
<div class="bc_header">AlephNote</div>
<div class="bc_data">
<div class="keyvaluelist kvl_200">
<div><span>Total users:</span> <span><?php echo AlephNoteStatistics::getTotalUserCount(); ?></span></div>
<div><span>Users on latest version:</span> <span><?php echo AlephNoteStatistics::getUserCountFromLastVersion(); ?></span></div>
<div><span>Active users:</span> <span><?php echo AlephNoteStatistics::getActiveUserCount(32); ?></span></div>
<?php if ($connected): ?>
<div class="bc_data">
<div class="keyvaluelist kvl_200">
<div><span>Total users:</span> <span><?php echo AlephNoteStatistics::getTotalUserCount(); ?></span></div>
<div><span>Users on latest version:</span> <span><?php echo AlephNoteStatistics::getUserCountFromLastVersion(); ?></span></div>
<div><span>Active users:</span> <span><?php echo AlephNoteStatistics::getActiveUserCount(32); ?></span></div>
</div>
<br/>
<div id="an_ajax_target"></div>
<a class="button" href="javascript:startAjaxReplace('#an_ajax_target', '/api/alephnote::show?secret=<?php echo $CONFIG['ajax_secret'] ?>')">Show</a>
</div>
<br/>
<div id="an_ajax_target"></div>
<a class="button" href="javascript:startAjaxReplace('#an_ajax_target', '/api/alephnote::show?secret=<?php echo $CONFIG['ajax_secret'] ?>')">Show</a>
</div>
<?php else: ?>
<div class="bc_data keyvaluelist">Database not connected.</div>
<?php endif; ?>
</div>
@ -160,16 +170,20 @@ function dumpConsistency($c) {
<div class="boxedcontent">
<div class="bc_header">UpdatesLog</div>
<div class="bc_data keyvaluelist kvl_300">
<?php foreach (UpdatesLog::listProgramsInformation() as $info): ?>
<div><span><?php echo '[' . $info['name'] . '] Count:' ?></span> <span><a href="javascript:startAjaxReplace('#ul_ajax_target', '/admin/updates::show?secret=<?php echo $CONFIG['ajax_secret'] ?>&ulname=<?php echo $info['name'] ?>')"><?php echo $info['count_total']; ?></a></span></div>
<div><span><?php echo '[' . $info['name'] . '] Last query:' ?></span> <span><?php echo $info['last_query']; ?></span></div>
<div><span><?php echo '[' . $info['name'] . '] Count (1 week):' ?></span> <span><?php echo $info['count_week']; ?></span></div>
<hr />
<?php endforeach; ?>
<br/>
<div id="ul_ajax_target"></div>
</div>
<?php if ($connected): ?>
<div class="bc_data keyvaluelist kvl_300">
<?php foreach (UpdatesLog::listProgramsInformation() as $info): ?>
<div><span><?php echo '[' . $info['name'] . '] Count:' ?></span> <span><a href="javascript:startAjaxReplace('#ul_ajax_target', '/admin/updates::show?secret=<?php echo $CONFIG['ajax_secret'] ?>&ulname=<?php echo $info['name'] ?>')"><?php echo $info['count_total']; ?></a></span></div>
<div><span><?php echo '[' . $info['name'] . '] Last query:' ?></span> <span><?php echo $info['last_query']; ?></span></div>
<div><span><?php echo '[' . $info['name'] . '] Count (1 week):' ?></span> <span><?php echo $info['count_week']; ?></span></div>
<hr />
<?php endforeach; ?>
<br/>
<div id="ul_ajax_target"></div>
</div>
<?php else: ?>
<div class="bc_data keyvaluelist">Database not connected.</div>
<?php endif; ?>
</div>
<!-- - - - - - - - - - - - - - - - - - - - - -->
@ -177,22 +191,26 @@ function dumpConsistency($c) {
<div class="boxedcontent">
<div class="bc_header">Highscores</div>
<div class="bc_data keyvaluelist kvl_300">
<?php if ($connected): ?>
<div class="bc_data keyvaluelist kvl_300">
<?php foreach (Highscores::getAllGames() as $game): ?>
<?php foreach (Highscores::getAllGames() as $game): ?>
<div><span><?php echo '[' . $game['NAME'] . '] Entries:' ?></span> <span><a href="/highscores/list?gameid=<?php echo $game['ID']; ?>"><?php echo Highscores::getEntryCountFromGame($game['ID']); ?></a></span></div>
<div><span><?php echo '[' . $game['NAME'] . '] Highscore:' ?></span> <span><?php
$hs = Highscores::getOrderedEntriesFromGame($game['ID'], 1)[0];
echo $hs['POINTS'] . ' (' . $hs['PLAYER'] . ') @ ' . $hs['TIMESTAMP'];
?></span></div>
<div><span><?php echo '[' . $game['NAME'] . '] Last Update:' ?></span> <span><?php echo Highscores::getNewestEntriesFromGame($game['ID'], 1)[0]['TIMESTAMP']; ?></span></div>
<div><span><?php echo '[' . $game['NAME'] . '] Entries:' ?></span> <span><a href="/highscores/list?gameid=<?php echo $game['ID']; ?>"><?php echo Highscores::getEntryCountFromGame($game['ID']); ?></a></span></div>
<div><span><?php echo '[' . $game['NAME'] . '] Highscore:' ?></span> <span><?php
$hs = Highscores::getOrderedEntriesFromGame($game['ID'], 1)[0];
echo $hs['POINTS'] . ' (' . $hs['PLAYER'] . ') @ ' . $hs['TIMESTAMP'];
?></span></div>
<div><span><?php echo '[' . $game['NAME'] . '] Last Update:' ?></span> <span><?php echo Highscores::getNewestEntriesFromGame($game['ID'], 1)[0]['TIMESTAMP']; ?></span></div>
<hr />
<hr />
<?php endforeach; ?>
<?php endforeach; ?>
</div>
</div>
<?php else: ?>
<div class="bc_data keyvaluelist">Database not connected.</div>
<?php endif; ?>
</div>
@ -200,15 +218,34 @@ function dumpConsistency($c) {
<div class="boxedcontent">
<div class="bc_header">Configuration</div>
<div class="bc_data keyvaluelist kvl_200">
<?php
foreach ($CONFIG as $key => $value)
{
if ($key === 'extendedgitgraph') continue;
<?php foreach ($CONFIG as $key => $value): ?>
<div><span><?php echo $key; ?></span> <span><?php echo var_export($value, true); ?></span></div>
<?php endforeach; ?>
if (is_array($value))
echo '<div><span>' . $key . '</span> <span style="white-space: pre">' . json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . '</span></div>' . "\n";
else
echo '<div><span>' . $key . '</span> <span>' . nl2br(var_export($value, true)) . '</span></div>' . "\n";
}
?>
</div>
</div>
<div class="boxedcontent">
<div class="bc_header">Configuration['extendedgitgraph']</div>
<div class="bc_data keyvaluelist kvl_200">
<?php
foreach ($CONFIG['extendedgitgraph'] as $key => $value)
{
if (is_array($value))
echo '<div><span>' . $key . '</span> <span style="white-space: pre">' . json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . '</span></div>' . "\n";
else
echo '<div><span>' . $key . '</span> <span>' . nl2br(var_export($value, true)) . '</span></div>' . "\n";
}
?>
</div>
</div>
</div>

View File

@ -21,6 +21,7 @@ if (key_exists('username', $_GET) && key_exists('password', $_GET) && key_exists
}
$redirect = $OPTIONS['login_target'];
if (($redirect === '/' || $redirect === '') && isset($_GET['redirect'])) $redirect = $_GET['redirect'];
?>
<head>