Refactor [su_ajax|admin_cmd|api_webhook] methods into single /api/ interface
This commit is contained in:
@@ -45,7 +45,7 @@ global $OPTIONS;
|
||||
<div class="boxedcontent">
|
||||
<div class="bc_header">My git timeline</div>
|
||||
|
||||
<div class="bc_data about_egh_container">
|
||||
<div class="bc_data about_egg_container">
|
||||
|
||||
<?php print(MikescherGitGraph::get()); ?>
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ $consistency_blog = Blog::checkConsistency();
|
||||
$consistency_prog = Programs::checkConsistency();
|
||||
$consistency_euler = Euler::checkConsistency();
|
||||
$consistency_books = Books::checkConsistency();
|
||||
$consistency_egh = MikescherGitGraph::checkConsistency();
|
||||
$consistency_egg = MikescherGitGraph::checkConsistency();
|
||||
$consistency_progimg = Programs::checkThumbnails();
|
||||
$consistency_bookimg = Books::checkThumbnails();
|
||||
$consistency_aoc = AdventOfCode::checkConsistency();
|
||||
@@ -75,7 +75,7 @@ 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_egh); ?></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>
|
||||
@@ -84,8 +84,8 @@ function dumpConsistency($c) {
|
||||
<div><span>Books data:</span> <?php dumpConsistency($consistency_books); ?></div>
|
||||
</div>
|
||||
<br/>
|
||||
<a class="button" href="/admin/cmd/createProgramThumbnails">Update Program Thumbnails</a>
|
||||
<a class="button" href="/admin/cmd/createBookThumbnails">Update Book Thumbnails</a>
|
||||
<a class="button" href="/api/site::createProgramThumbnails">Update Program Thumbnails</a>
|
||||
<a class="button" href="/api/site::createBookThumbnails">Update Book Thumbnails</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -115,7 +115,7 @@ function dumpConsistency($c) {
|
||||
|
||||
<div class="bc_data">
|
||||
|
||||
<textarea class="egh_ajaxOutput" id="egh_ajaxOutput" readonly="readonly"></textarea>
|
||||
<textarea class="egg_ajaxOutput" id="egg_ajaxOutput" readonly="readonly"></textarea>
|
||||
<a class="button" href="javascript:startAjaxRefresh('<?php echo $CONFIG['ajax_secret'] ?>')">Update</a>
|
||||
<a class="button" href="javascript:startAjaxRedraw('<?php echo $CONFIG['ajax_secret'] ?>')">Redraw</a>
|
||||
|
||||
@@ -136,7 +136,7 @@ function dumpConsistency($c) {
|
||||
</div>
|
||||
<br/>
|
||||
<div id="an_ajax_target"></div>
|
||||
<a class="button" href="javascript:startAjaxReplace('#an_ajax_target', '/su_ajax/alephNoteTable?secret=<?php echo $CONFIG['ajax_secret'] ?>')">Show</a>
|
||||
<a class="button" href="javascript:startAjaxReplace('#an_ajax_target', '/api/alephnote::show?secret=<?php echo $CONFIG['ajax_secret'] ?>')">Show</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -162,7 +162,7 @@ function dumpConsistency($c) {
|
||||
|
||||
<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', '/su_ajax/updateslog?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'] . '] 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 />
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
global $OPTIONS;
|
||||
|
||||
require_once (__DIR__ . '/../internals/base.php');
|
||||
require_once (__DIR__ . '/../internals/books.php');
|
||||
require_once (__DIR__ . '/../internals/programs.php');
|
||||
|
||||
$cmd = $OPTIONS['cmd'];
|
||||
|
||||
if ($cmd === 'createProgramThumbnails')
|
||||
{
|
||||
echo '<!DOCTYPE html>';
|
||||
echo '<html lang="en">';
|
||||
echo '<head>';
|
||||
echo '<meta charset="utf-8">';
|
||||
echo '<title>Mikescher.com - AdminExec</title>';
|
||||
echo '<link rel="icon" type="image/png" href="/data/images/favicon.png"/>';
|
||||
echo '<link rel="canonical" href="https://www.mikescher.com/logout"/>';
|
||||
echo '<meta http-equiv="refresh" content="3;url=/admin;"/>';
|
||||
echo '</head>';
|
||||
echo '<body>';
|
||||
|
||||
foreach (Programs::listAll() as $prog)
|
||||
{
|
||||
echo 'Create preview for ' . $prog['name'] . '<br/>' . "\n";
|
||||
Programs::createPreview($prog);
|
||||
}
|
||||
echo 'Finished.' . '<br/>' . "\n";
|
||||
|
||||
echo '<script>setTimeout(function () { window.location.href = "/admin"; }, 3000);</script>';
|
||||
echo '</body>';
|
||||
echo '</html>';
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($cmd === 'createBookThumbnails')
|
||||
{
|
||||
echo '<!DOCTYPE html>';
|
||||
echo '<html lang="en">';
|
||||
echo '<head>';
|
||||
echo '<meta charset="utf-8">';
|
||||
echo '<title>Mikescher.com - AdminExec</title>';
|
||||
echo '<link rel="icon" type="image/png" href="/data/images/favicon.png"/>';
|
||||
echo '<link rel="canonical" href="https://www.mikescher.com/logout"/>';
|
||||
echo '<meta http-equiv="refresh" content="3; url=/admin; ?>" />';
|
||||
echo '</head>';
|
||||
echo '<body>';
|
||||
|
||||
foreach (Books::listAll() as $book)
|
||||
{
|
||||
echo 'Create preview for ' . $book['title'] . '<br/>' . "\n";
|
||||
Books::createPreview($book);
|
||||
}
|
||||
echo 'Finished.' . '<br/>' . "\n";
|
||||
|
||||
echo '<script>setTimeout(function () { window.location.href = "/admin"; }, 3000);</script>';
|
||||
echo '</body>';
|
||||
echo '</html>';
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
die('Wrong command.');
|
||||
89
www/pages/api.php
Normal file
89
www/pages/api.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
global $OPTIONS;
|
||||
|
||||
require_once (__DIR__ . '/../internals/base.php');
|
||||
|
||||
$API_COMMANDS =
|
||||
[
|
||||
'base::test' => [ 'src' => __DIR__.'/../commands/base_test.php', 'auth' => 'none' ],
|
||||
|
||||
'progs::updatecheck' => [ 'src' => __DIR__.'/../commands/progs_updatecheck.php', 'auth' => 'none' ],
|
||||
|
||||
'site::createProgramThumbnails' => [ 'src' => __DIR__.'/../commands/site_createProgramThumbnails.php', 'auth' => 'admin' ],
|
||||
'site::createBookThumbnails' => [ 'src' => __DIR__.'/../commands/site_createBookThumbnails.php', 'auth' => 'admin' ],
|
||||
|
||||
'server::setselfaddress' => [ 'src' => __DIR__.'/../commands/server_setselfaddress.php', 'auth' => 'none' ],
|
||||
'server::gitwebhook' => [ 'src' => __DIR__.'/../commands/server_gitwebhook.php', 'auth' => 'webhook_secret' ],
|
||||
'server::backupupload' => [ 'src' => __DIR__.'/../commands/server_backupupload.php', 'auth' => 'upload_secret' ],
|
||||
|
||||
'extendedgitgraph::status' => [ 'src' => __DIR__.'/../commands/extendedgitgraph_status.php', 'auth' => 'ajax_secret' ],
|
||||
'extendedgitgraph::redraw' => [ 'src' => __DIR__.'/../commands/extendedgitgraph_redraw.php', 'auth' => 'ajax_secret' ],
|
||||
'extendedgitgraph::refresh' => [ 'src' => __DIR__.'/../commands/extendedgitgraph_refresh.php', 'auth' => 'ajax_secret' ],
|
||||
|
||||
'alephnote::statsping' => [ 'src' => __DIR__.'/../commands/alephnote_statsping.php', 'auth' => 'none' ],
|
||||
'alephnote::show' => [ 'src' => __DIR__.'/../commands/alephnote_show.php', 'auth' => 'ajax_secret' ],
|
||||
|
||||
'updates::show' => [ 'src' => __DIR__.'/../commands/updates_show.php', 'auth' => 'ajax_secret' ],
|
||||
];
|
||||
|
||||
$cmd = strtolower($OPTIONS['cmd']);
|
||||
|
||||
if (!array_key_exists($cmd, $API_COMMANDS))
|
||||
{
|
||||
print(" \n");
|
||||
print(" \n");
|
||||
print(" ... \n");
|
||||
print(" ;::::; \n");
|
||||
print(" ;::::; :; \n");
|
||||
print(" ;:::::' :; \n");
|
||||
print(" ;:::::; ;. \n");
|
||||
print(" ,:::::' ; OOO\\ \n");
|
||||
print(" ::::::; ; OOOOO\\ \n");
|
||||
print(" ;:::::; ; OOOOOOOO \n");
|
||||
print(" ,;::::::; ;' / OOOOOOO \n");
|
||||
print(" ;:::::::::`. ,,,;. / / DOOOOOO \n");
|
||||
print(" .';:::::::::::::::::;, / / DOOOO \n");
|
||||
print(" ,::::::;::::::;;;;::::;, / / DOOO \n");
|
||||
print(" ;`::::::`'::::::;;;::::: ,#/ / DOOO \n");
|
||||
print(" :`:::::::`;::::::;;::: ;::# / DOOO \n");
|
||||
print(" ::`:::::::`;:::::::: ;::::# / DOO \n");
|
||||
print(" `:`:::::::`;:::::: ;::::::#/ DOO \n");
|
||||
print(" :::`:::::::`;; ;:::::::::## OO \n");
|
||||
print(" ::::`:::::::`;::::::::;:::# OO \n");
|
||||
print(" `:::::`::::::::::::;'`:;::# O \n");
|
||||
print(" `:::::`::::::::;' / / `:# \n");
|
||||
print(" ::::::`:::::;' / / `# \n");
|
||||
print(" \n");
|
||||
print(" \n");
|
||||
die('Wrong command.');
|
||||
}
|
||||
|
||||
$config = $API_COMMANDS[$cmd];
|
||||
|
||||
|
||||
$secret = isset($_GET['secret']) ? $_GET['secret'] : '';
|
||||
|
||||
if ($config['auth'] === 'webhook_secret' && $secret !== $CONFIG['webhook_secret']) die('Unauthorized.');
|
||||
if ($config['auth'] === 'ajax_secret' && $secret !== $CONFIG['ajax_secret']) die('Unauthorized.');
|
||||
if ($config['auth'] === 'upload_secret' && $secret !== $CONFIG['upload_secret']) die('Unauthorized.');
|
||||
if ($config['auth'] === 'admin' && !isLoggedInByCookie()) die('Unauthorized.');
|
||||
|
||||
|
||||
global $API_OPTIONS;
|
||||
|
||||
$API_OPTIONS = [];
|
||||
foreach ($_GET as $k => $v) $API_OPTIONS[strtolower($k)] = $v;
|
||||
foreach ($OPTIONS['_urlparams'] as $k => $v) $API_OPTIONS[strtolower($k)] = $v;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include $config['src'];
|
||||
}
|
||||
catch (exception $e)
|
||||
{
|
||||
print("API Command failed with exception");
|
||||
print($e);
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
global $OPTIONS;
|
||||
|
||||
require_once (__DIR__ . '/../internals/base.php');
|
||||
require_once (__DIR__ . '/../internals/database.php');
|
||||
|
||||
$folder = $OPTIONS['folder'];
|
||||
$filename = $OPTIONS['filename'];
|
||||
$secret = $OPTIONS['secret'];
|
||||
$uri = $OPTIONS['uri'];
|
||||
|
||||
$reltarget = "Backup/$folder/$filename";
|
||||
|
||||
if ($secret !== $CONFIG['upload_secret']) die('Unauthorized.');
|
||||
|
||||
$putdata = fopen("php://input", "r");
|
||||
$fp = tmpfile();
|
||||
$tmppath = stream_get_meta_data($fp)['uri'];
|
||||
while ($data = fread($putdata, 1024)) fwrite($fp, $data);
|
||||
fclose($putdata);
|
||||
|
||||
$std = shell_exec("ncc_upload " . '"' . $tmppath . '" "' . $reltarget . '" 2>&1');
|
||||
|
||||
fclose($fp);
|
||||
|
||||
$content = "REQUEST: " . $uri . "\r\n\r\n" .
|
||||
"IP: " . get_client_ip() . "\r\n\r\n" .
|
||||
"TARGET: " . $reltarget . "\r\n\r\n" .
|
||||
"OUTPUT: " . $std . "\r\n\r\n";
|
||||
|
||||
sendMail("Fileupload to '$folder' triggered", $content, 'virtualadmin@mikescher.de', 'webserver-info@mikescher.com');
|
||||
|
||||
echo "OK.\n\n";
|
||||
echo $content;
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
$ip = get_client_ip();
|
||||
|
||||
file_put_contents(__DIR__ . '/../dynamic/self_ip_address.auto.cfg', $ip);
|
||||
|
||||
system('add-trusted-ip "' . $ip . '"');
|
||||
|
||||
echo 'Ok.';
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
global $OPTIONS;
|
||||
|
||||
require_once (__DIR__ . '/../internals/base.php');
|
||||
require_once (__DIR__ . '/../internals/database.php');
|
||||
|
||||
$nam = $OPTIONS['name'];
|
||||
$cid = $OPTIONS['clientid'];
|
||||
$ver = $OPTIONS['version'];
|
||||
$prv = $OPTIONS['providerstr'];
|
||||
$pid = $OPTIONS['providerid'];
|
||||
$tnc = $OPTIONS['notecount'];
|
||||
|
||||
if ($nam === 'AlephNote')
|
||||
{
|
||||
Database::connect();
|
||||
|
||||
Database::sql_exec_prep('INSERT INTO an_statslog (ClientID, Version, ProviderStr, ProviderID, NoteCount) VALUES (:cid1, :ver1, :prv1, :pid1, :tnc1) ON DUPLICATE KEY UPDATE Version=:ver2,ProviderStr=:prv2,ProviderID=:pid2,NoteCount=:tnc2',
|
||||
[
|
||||
[':cid1', $cid, PDO::PARAM_STR],
|
||||
[':ver1', $ver, PDO::PARAM_STR],
|
||||
[':prv1', $prv, PDO::PARAM_STR],
|
||||
[':pid1', $pid, PDO::PARAM_STR],
|
||||
[':tnc1', $tnc, PDO::PARAM_INT],
|
||||
|
||||
[':ver2', $ver, PDO::PARAM_STR],
|
||||
[':prv2', $prv, PDO::PARAM_STR],
|
||||
[':pid2', $pid, PDO::PARAM_STR],
|
||||
[':tnc2', $tnc, PDO::PARAM_INT],
|
||||
]);
|
||||
|
||||
print('{"success":true}');
|
||||
}
|
||||
else
|
||||
{
|
||||
print('{"success":false, "message":"Unknown AppName"}');
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
echo "{}";
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
global $OPTIONS;
|
||||
|
||||
require_once (__DIR__ . '/../internals/base.php');
|
||||
require_once (__DIR__ . '/../internals/programs.php');
|
||||
require_once (__DIR__ . '/../internals/updateslog.php');
|
||||
|
||||
$name = $OPTIONS['name'];
|
||||
|
||||
$updatedata = Programs::listUpdateData();
|
||||
|
||||
if (! array_key_exists($name, $updatedata)) httpError(404, 'Invalid Request - [Name] not found');
|
||||
|
||||
$data = $updatedata[$name];
|
||||
|
||||
UpdatesLog::insert($name, $data['version']);
|
||||
|
||||
print($name."<hr>".$data['version']."<hr>".$data['url']);
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
global $OPTIONS;
|
||||
|
||||
require_once (__DIR__ . '/../internals/base.php');
|
||||
require_once (__DIR__ . '/../internals/database.php');
|
||||
|
||||
$hook = $OPTIONS['target'];
|
||||
$secret = $OPTIONS['secret'];
|
||||
$uri = $OPTIONS['uri'];
|
||||
|
||||
if ($secret !== $CONFIG['webhook_secret']) die('Unauthorized.');
|
||||
|
||||
$cmd = "";
|
||||
|
||||
if ($hook == 'website_mikescher') $cmd = 'git pull';
|
||||
else if ($hook == 'griddominance') $cmd = 'update-gdapi';
|
||||
else throw new Exception("Unknown webhook: $hook");
|
||||
|
||||
|
||||
$std = shell_exec($cmd);
|
||||
|
||||
$content = "REQUEST: " . $uri . "\r\n\r\n" .
|
||||
"IP: " . get_client_ip() . "\r\n\r\n" .
|
||||
"TARGET: " . $hook . "\r\n\r\n" .
|
||||
"OUTPUT: " . $std . "\r\n\r\n";
|
||||
|
||||
sendMail("Webhook '$hook' triggered", $content, 'virtualadmin@mikescher.de', 'webserver-info@mikescher.com');
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once (__DIR__ . '/../internals/base.php');
|
||||
|
||||
$cmd = $OPTIONS['cmd'];
|
||||
$secret = $OPTIONS['secret'];
|
||||
|
||||
if (isset($OPTIONS['suffix']) && $OPTIONS['suffix'] !== '') $cmd = $OPTIONS['suffix'] . '::' . $cmd;
|
||||
$cmd = strtolower($cmd);
|
||||
|
||||
if ($secret !== $CONFIG['ajax_secret']) die('Unauthorized.');
|
||||
|
||||
try
|
||||
{
|
||||
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; }
|
||||
if ($cmd === 'updateslog') { include (__DIR__ . '/../ajax/ul_entries.php'); exit; }
|
||||
}
|
||||
catch (exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
die('Wrong command.');
|
||||
Reference in New Issue
Block a user