1
0

/admin/ alephnote

This commit is contained in:
Mike Schwörer 2018-01-27 00:28:32 +01:00
parent e1fec28368
commit acc6443b55
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
15 changed files with 263 additions and 76 deletions

1
www/ajax/.htaccess Normal file
View File

@ -0,0 +1 @@
Deny from all

View File

@ -0,0 +1,36 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/alephnoteStatistics.php');
Database::connect();
?>
<div class="stripedtable_container">
<table class="stripedtable">
<thead>
<tr>
<th>ClientID</th>
<th>Version</th>
<th>Provider</th>
<th>NoteCount</th>
<th>LastChanged</th>
<th>CreatedAt</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
<?php foreach (AlephNoteStatistics::getAllActiveEntriesOrdered() as $entry): ?>
<tr>
<td><?php echo $entry['ClientID']; ?></td>
<td><?php echo $entry['Version']; ?></td>
<td><?php echo $entry['ProviderStr']; ?></td>
<td><?php echo $entry['NoteCount']; ?></td>
<td><?php echo $entry['LastChanged']; ?></td>
<td><?php echo $entry['CreatedAt']; ?></td>
<td><?php echo $entry['Comment']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

14
www/ajax/egh_redraw.php Normal file
View File

@ -0,0 +1,14 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../extern/egh/ExtendedGitGraph.php');
require_once (__DIR__ . '/../internals/mikeschergitgraph.php');
set_time_limit(900); // 15min
$v = MikescherGitGraph::create();
$v->init();
$v->updateFromCache();
$v->generate();
file_put_contents(__DIR__ . '/../dynamic/egh.html', $v->getAll());

15
www/ajax/egh_refresh.php Normal file
View File

@ -0,0 +1,15 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../extern/egh/ExtendedGitGraph.php');
require_once (__DIR__ . '/../internals/mikeschergitgraph.php');
set_time_limit(900); // 15min
$v = MikescherGitGraph::create();
$v->init();
$v->updateFromRemotes();
$v->generate();
file_put_contents(__DIR__ . '/../dynamic/egh.html', $v->getAll());

10
www/ajax/egh_status.php Normal file
View File

@ -0,0 +1,10 @@
<?php
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
if (key_exists('ajax_progress_egh_refresh', $_SESSION))
echo $_SESSION['ajax_progress_egh_refresh'];
else
echo '[[ NO SESSION STARTED ]]';
return;

View File

@ -159,6 +159,35 @@ body {
text-align: center;
font-size: 14pt; }
.stripedtable_container {
overflow-x: auto; }
.stripedtable {
border-collapse: collapse;
text-align: left;
width: 100%;
border: 1px solid #666; }
.stripedtable td, .stripedtable th {
padding: 3px 10px; }
.stripedtable thead th {
background-color: #7D7D7D;
color: #FFFFFF;
font-weight: bold;
border-left: 1px solid #444; }
.stripedtable thead th:first-child {
border: none; }
.stripedtable tbody td {
border-left: 1px solid #666;
font-weight: normal; }
.stripedtable tbody .alt td {
background: #EBEBEB; }
.stripedtable tbody td:first-child {
border-left: none; }
.stripedtable tbody tr:last-child td {
border-bottom: none; }
.stripedtable tbody tr:nth-child(odd) {
background-color: #ccc; }
/* 400px */
#headerdiv {
z-index: 999;

View File

@ -31,6 +31,16 @@ body{background-color:#EEE;color:#CCC;font-family:serif}
.iconbutton_light:hover{cursor:pointer;background-color:#555}
.iconbutton_light svg{width:14pt;height:14pt;margin:0 4px;fill:#000}
.iconbutton_light span{flex-grow:1;text-align:center;font-size:14pt}
.stripedtable_container{overflow-x:auto}
.stripedtable{border-collapse:collapse;text-align:left;width:100%;border:1px solid #666}
.stripedtable td,.stripedtable th{padding:3px 10px}
.stripedtable thead th{background-color:#7d7d7d;color:#fff;font-weight:bold;border-left:1px solid #444}
.stripedtable thead th:first-child{border:0}
.stripedtable tbody td{border-left:1px solid #666;font-weight:normal}
.stripedtable tbody .alt td{background:#ebebeb}
.stripedtable tbody td:first-child{border-left:0}
.stripedtable tbody tr:last-child td{border-bottom:0}
.stripedtable tbody tr:nth-child(odd){background-color:#ccc}
#headerdiv{z-index:999;background-color:#333;display:flex;border-bottom:1px solid #111;box-shadow:0 0 8px #000;position:fixed;width:100%}
#headerdiv .logowrapper{flex:initial;margin:0;padding:0;height:42px}
#headerdiv .logowrapper .logo{min-width:197.5px;height:30px;margin:4px 0 8px 6px;flex:initial}

View File

@ -182,5 +182,51 @@ body {
font-size: 14pt;
}
}
.stripedtable_container {
overflow-x: auto;
}
.stripedtable
{
border-collapse: collapse;
text-align: left;
width: 100%;
border: 1px solid #666;
td, th {
padding: 3px 10px;
}
thead th {
background-color: #7D7D7D;
color: #FFFFFF;
font-weight: bold;
border-left: 1px solid #444;
}
thead th:first-child {
border: none;
}
tbody td {
border-left: 1px solid #666;
font-weight: normal;
}
tbody .alt td {
background: #EBEBEB;
}
tbody td:first-child {
border-left: none;
}
tbody tr:last-child td {
border-bottom: none;
}
tbody tr:nth-child(odd) {
background-color: #ccc;
}
}

View File

@ -52,4 +52,21 @@ function startAjaxRedraw(secret)
},
async: true
});
}
function startAjaxReplace(target, url)
{
$(target).html("Waiting ...");
jQuery.ajax({
url: url,
success: function(result)
{
$(target).html(result);
},
error: function( jqXHR, textStatus, errorThrown)
{
$(target).html('AN ERROR OCCURED:' + '<br/>' + textStatus);
},
async: true
});
}

View File

@ -37,7 +37,10 @@ $URL_RULES =
[ 'url' => ['api', 'statsping'], 'target' => 'pages/api_stats.php', 'options' => [ 'Name' => '%GET%', 'ClientID' => '%GET%', 'Version' => '%GET%', 'ProviderStr' => '%GET%', 'ProviderID' => '%GET%', 'NoteCount' => '%GET%', ], ],
[ 'url' => ['admin'], 'target' => 'pages/admin.php', 'options' => [ '_opt' => 'password'], ],
[ 'url' => ['admin', 'egh', '?{cmd}'], 'target' => 'pages/admin_egh.php', 'options' => [ 'cmd' => '%URL%', 'secret' => '%GET%' ], ],
[ 'url' => ['admin', 'egh', '?{cmd}'], 'target' => 'pages/su_ajax.php', 'options' => [ 'suffix' => 'egh', 'cmd' => '%URL%', 'secret' => '%GET%' ], ],
[ 'url' => ['su_ajax', '?{cmd}'], 'target' => 'pages/su_ajax.php', 'options' => [ 'suffix' => '', 'cmd' => '%URL%', 'secret' => '%GET%' ], ],
[ 'url' => ['su_ajax'], 'target' => 'pages/su_ajax.php', 'options' => [ 'suffix' => '', 'cmd' => '%GET%', 'secret' => '%GET%' ], ],
[ 'url' => ['blog'], 'target' => 'pages/blog_list.php', 'options' => [], ],
[ 'url' => ['log'], 'target' => 'pages/blog_list.php', 'options' => [], ],

View File

@ -0,0 +1,26 @@
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
require_once (__DIR__ . '/../internals/database.php');
class AlephNoteStatistics
{
public static function getTotalUserCount()
{
return Database::sql_query_num('SELECT COUNT(*) FROM ms4_an_statslog WHERE NoteCount>0');
}
public static function getUserCountFromLastVersion()
{
return Database::sql_query_num('SELECT COUNT(*) FROM ms4_an_statslog WHERE NoteCount>0 AND Version = (SELECT Version FROM ms4_an_statslog ORDER BY Version DESC LIMIT 1)');
}
public static function getActiveUserCount($days)
{
return Database::sql_query_num('SELECT COUNT(*) FROM ms4_an_statslog WHERE NoteCount>0 AND LastChanged > NOW() - INTERVAL '.$days.' DAY');
}
public static function getAllActiveEntriesOrdered()
{
return Database::sql_query_assoc('SELECT * FROM ms4_an_statslog WHERE NoteCount>0 ORDER BY LastChanged DESC');
}
}

View File

@ -0,0 +1,29 @@
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../extern/egh/ExtendedGitGraph.php');
class MikescherGitGraph
{
public static function create()
{
global $CONFIG;
$v = new ExtendedGitGraph(__DIR__ . '/../temp/egh_cache.bin', ExtendedGitGraph::OUT_SESSION, __DIR__ . '/../temp/egh_log{num}.log');
$v->addRemote('github-user', null, 'Mikescher', 'Mikescher');
//$v->addRemote('github-user', null, 'Mikescher', 'Sam-Development');
//$v->addRemote('github-repository', null, 'Mikescher', 'Anastron/ColorRunner');
$v->addRemote('gitea-repository', null, 'Mikescher', 'Mikescher/server-scripts');
$v->addRemote('gitea-repository', null, 'Mikescher', 'Mikescher/apache-sites');
$v->addRemote('gitea-repository', null, 'Mikescher', 'Mikescher/MVU_API');
$v->setColorScheme($CONFIG['egh_theme']);
$v->ConnectionGithub->setAPIToken($CONFIG['egh_token']);
$v->ConnectionGitea->setURL('https://gogs.mikescher.com');
return $v;
}
}

View File

@ -62,14 +62,15 @@ Database::connect();
<div class="bc_data">
<div class="keyvaluelist kvl_200">
<div><span>Total users:</span> <span><?php echo 0; ?></span></div>
<div><span>Users on latest version:</span> <span><?php echo 0; ?></span></div>
<div><span>Active users:</span> <span><?php echo 0; ?></span></div>
<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>
<br/>
<a class="button" href="javascript:showAlephNoteData('<?php echo $CONFIG['ajax_secret'] ?>')">Show</a>
<a class="button" href="javascript:startAjaxReplace('#an_ajax_target', '/su_ajax/alephNoteTable?secret=<?php echo $CONFIG['ajax_secret'] ?>')">Show</a>
</div>

View File

@ -1,70 +0,0 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../extern/egh/ExtendedGitGraph.php');
$cmd = $OPTIONS['cmd'];
$secret = $OPTIONS['secret'];
if ($secret !== $CONFIG['ajax_secret'])
die('Unauthorized.');
function create()
{
global $CONFIG;
$v = new ExtendedGitGraph(__DIR__ . '/../temp/egh_cache.bin', ExtendedGitGraph::OUT_SESSION, __DIR__ . '/../temp/egh_log{num}.log');
$v->addRemote('github-user', null, 'Mikescher', 'Mikescher');
//$v->addRemote('github-user', null, 'Mikescher', 'Sam-Development');
//$v->addRemote('github-repository', null, 'Mikescher', 'Anastron/ColorRunner');
$v->addRemote('gitea-repository', null, 'Mikescher', 'Mikescher/server-scripts');
$v->addRemote('gitea-repository', null, 'Mikescher', 'Mikescher/apache-sites');
$v->addRemote('gitea-repository', null, 'Mikescher', 'Mikescher/MVU_API');
$v->setColorScheme($CONFIG['egh_theme']);
$v->ConnectionGithub->setAPIToken($CONFIG['egh_token']);
$v->ConnectionGitea->setURL('https://gogs.mikescher.com');
return $v;
}
if ($cmd === 'status')
{
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
if (key_exists('ajax_progress_egh_refresh', $_SESSION))
echo $_SESSION['ajax_progress_egh_refresh'];
else
echo '[[ NO SESSION STARTED ]]';
return;
}
else if ($cmd === 'refresh')
{
set_time_limit(900); // 15min
$v = create();
$v->init();
$v->updateFromRemotes();
$v->generate();
file_put_contents(__DIR__ . '/../dynamic/egh.html', $v->getAll());
}
else if ($cmd === 'redraw')
{
set_time_limit(900); // 15min
$v = create();
$v->init();
$v->updateFromCache();
$v->generate();
file_put_contents(__DIR__ . '/../dynamic/egh.html', $v->getAll());
}
else
{
die('Wrong command.');
}

20
www/pages/su_ajax.php Normal file
View File

@ -0,0 +1,20 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../extern/egh/ExtendedGitGraph.php');
$cmd = $OPTIONS['cmd'];
$secret = $OPTIONS['secret'];
if (isset($OPTIONS['suffix'])) $cmd = $OPTIONS['suffix'] . '::' . $cmd;
$cmd = strtolower($cmd);
if ($secret !== $CONFIG['ajax_secret']) die('Unauthorized.');
if ($cmd === 'egh::status') { include (__DIR__ . '/../ajax/egh_status.php'); exit; }
if ($cmd === 'egh::refresh') { include (__DIR__ . '/../ajax/egh_refresh.php'); exit; }
if ($cmd === 'egh::redraw') { include (__DIR__ . '/../ajax/egh_redraw.php'); exit; }
if ($cmd === 'alephnotetable') { include (__DIR__ . '/../ajax/an_activeusers.php'); exit; }
die('Wrong command.');