1
0

Refactor [su_ajax|admin_cmd|api_webhook] methods into single /api/ interface

This commit is contained in:
2019-12-28 22:42:25 +01:00
parent 75e53f2f52
commit d0aea4e4e7
39 changed files with 306 additions and 234 deletions

1
www/commands/.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>

View File

@@ -0,0 +1,42 @@
<?php
global $API_OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
if (!isset($API_OPTIONS['name'])) die("Wrong parameters.");
if (!isset($API_OPTIONS['clientid'])) die("Wrong parameters.");
if (!isset($API_OPTIONS['version'])) die("Wrong parameters.");
if (!isset($API_OPTIONS['providerstr'])) die("Wrong parameters.");
if (!isset($API_OPTIONS['providerid'])) die("Wrong parameters.");
if (!isset($API_OPTIONS['notecount'])) die("Wrong parameters.");
$nam = $API_OPTIONS['name'];
$cid = $API_OPTIONS['clientid'];
$ver = $API_OPTIONS['version'];
$prv = $API_OPTIONS['providerstr'];
$pid = $API_OPTIONS['providerid'];
$tnc = $API_OPTIONS['notecount'];
if ($nam !== 'AlephNote') print('{"success":false, "message":"Unknown AppName"}');
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}');

View File

@@ -0,0 +1,3 @@
<?php
echo "{}";

View File

@@ -0,0 +1,11 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../extern/egg/ExtendedGitGraph2.php');
require_once (__DIR__ . '/../internals/mikeschergitgraph.php');
set_time_limit(900); // 15min
$v = MikescherGitGraph::create();
$v->updateCache();

View File

@@ -0,0 +1,12 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../extern/egg/ExtendedGitGraph2.php');
require_once (__DIR__ . '/../internals/mikeschergitgraph.php');
set_time_limit(900); // 15min
$v = MikescherGitGraph::create();
$v->update();
$v->updateCache();

View File

@@ -0,0 +1,18 @@
<?php
global $CONFIG;
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
if (isset($_GET['clear']))
{
if (key_exists($CONFIG['extendedgitgraph']['session_var'], $_SESSION)) $_SESSION[$CONFIG['extendedgitgraph']['session_var']] = '';
}
if (key_exists($CONFIG['extendedgitgraph']['session_var'], $_SESSION))
echo $_SESSION[$CONFIG['extendedgitgraph']['session_var']];
else
echo '[[ NO SESSION STARTED ]]';
return;

View File

@@ -0,0 +1,21 @@
<?php
global $API_OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/programs.php');
require_once (__DIR__ . '/../internals/updateslog.php');
if (!isset($API_OPTIONS['name'])) die("Wrong parameters.");
$name = $API_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']);

View File

@@ -0,0 +1,38 @@
<?php
global $API_OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
if (!isset($API_OPTIONS['folder'])) die("Wrong parameters.");
if (!isset($API_OPTIONS['filename'])) die("Wrong parameters.");
if (!isset($API_OPTIONS['secret'])) die("Wrong parameters.");
if (!isset($API_OPTIONS['uri'])) die("Wrong parameters.");
$folder = $API_OPTIONS['folder'];
$filename = $API_OPTIONS['filename'];
$secret = $API_OPTIONS['secret'];
$uri = $API_OPTIONS['uri'];
$reltarget = "Backup/$folder/$filename";
$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;

View File

@@ -0,0 +1,29 @@
<?php
global $API_OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
if (!isset($API_OPTIONS['target'])) die("Wrong parameters.");
if (!isset($API_OPTIONS['secret'])) die("Wrong parameters.");
if (!isset($API_OPTIONS['uri'])) die("Wrong parameters.");
$hook = $API_OPTIONS['target'];
$secret = $API_OPTIONS['secret'];
$uri = $API_OPTIONS['uri'];
$cmd = "";
if ($hook == 'website_mikescher') $cmd = 'git pull';
else if ($hook == 'griddominance') $cmd = 'update-gdapi';
else die("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');

View File

@@ -0,0 +1,9 @@
<?php
$ip = get_client_ip();
file_put_contents(__DIR__ . '/../dynamic/self_ip_address.auto.cfg', $ip);
system('add-trusted-ip "' . $ip . '"');
echo 'Ok.';

View File

@@ -0,0 +1,32 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/books.php');
require_once (__DIR__ . '/../internals/programs.php');
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>';
die('Wrong command.');

View File

@@ -0,0 +1,29 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/books.php');
require_once (__DIR__ . '/../internals/programs.php');
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>';

View File

@@ -0,0 +1,28 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/updateslog.php');
Database::connect();
?>
<div class="stripedtable_container" style="width: 100%;">
<table class="stripedtable">
<thead>
<tr>
<th>IP</th>
<th>Version</th>
<th>Timestamp</th>
</tr>
</thead>
<tbody>
<?php foreach (UpdatesLog::getEntries($_GET['ulname'], 512) as $entry): ?>
<tr>
<td><?php echo $entry['ip']; ?></td>
<td><?php echo $entry['version']; ?></td>
<td><?php echo $entry['date']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>