1
0
This commit is contained in:
Mike Schwörer 2020-01-16 13:21:14 +01:00
parent 5302868327
commit f5a9552dbd
22 changed files with 237 additions and 169 deletions

View File

@ -1,9 +1,9 @@
<?php <?php
require_once (__DIR__ . '/../internals/base.php'); require_once (__DIR__ . '/../internals/website.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/alephnoteStatistics.php');
Database::connect(); /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
?> ?>
<div class="stripedtable_container"> <div class="stripedtable_container">
@ -20,7 +20,7 @@ Database::connect();
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach (AlephNoteStatistics::getAllActiveEntriesOrdered() as $entry): ?> <?php foreach ($SITE->modules->AlephNoteStatistics()->getAllActiveEntriesOrdered() as $entry): ?>
<tr> <tr>
<td><?php echo $entry['ClientID']; ?></td> <td><?php echo $entry['ClientID']; ?></td>
<td><?php echo $entry['Version']; ?></td> <td><?php echo $entry['Version']; ?></td>

View File

@ -1,16 +1,17 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
global $API_OPTIONS; /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
if (!isset($API_OPTIONS['name'])) httpDie(400, "Wrong parameters."); if (!isset($API_OPTIONS['name'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
if (!isset($API_OPTIONS['clientid'])) httpDie(400, "Wrong parameters."); if (!isset($API_OPTIONS['clientid'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
if (!isset($API_OPTIONS['version'])) httpDie(400, "Wrong parameters."); if (!isset($API_OPTIONS['version'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
if (!isset($API_OPTIONS['providerstr'])) httpDie(400, "Wrong parameters."); if (!isset($API_OPTIONS['providerstr'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
if (!isset($API_OPTIONS['providerid'])) httpDie(400, "Wrong parameters."); if (!isset($API_OPTIONS['providerid'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
if (!isset($API_OPTIONS['notecount'])) httpDie(400, "Wrong parameters."); if (!isset($API_OPTIONS['notecount'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
$nam = $API_OPTIONS['name']; $nam = $API_OPTIONS['name'];
$cid = $API_OPTIONS['clientid']; $cid = $API_OPTIONS['clientid'];
@ -22,9 +23,7 @@ $tnc = $API_OPTIONS['notecount'];
if ($nam !== 'AlephNote') print('{"success":false, "message":"Unknown AppName"}'); if ($nam !== 'AlephNote') print('{"success":false, "message":"Unknown AppName"}');
Database::connect(); $SITE->modules->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',
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], [':cid1', $cid, PDO::PARAM_STR],
[':ver1', $ver, PDO::PARAM_STR], [':ver1', $ver, PDO::PARAM_STR],

View File

@ -1,3 +1,9 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
echo "{}"; /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
echo "{}";

View File

@ -1,11 +1,11 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../extern/egg/ExtendedGitGraph2.php');
require_once (__DIR__ . '/../internals/mikeschergitgraph.php');
set_time_limit(900); // 15min set_time_limit(900); // 15min
$v = MikescherGitGraph::create(); $v = $SITE->modules->ExtendedGitGraph()->updateCache();
$v->updateCache();

View File

@ -1,12 +1,12 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
require_once (__DIR__ . '/../internals/base.php'); /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
require_once (__DIR__ . '/../extern/egg/ExtendedGitGraph2.php'); /** @var URLRoute $ROUTE */ global $ROUTE;
require_once (__DIR__ . '/../internals/mikeschergitgraph.php'); /** @var Website $SITE */ global $SITE;
set_time_limit(900); // 15min set_time_limit(900); // 15min
$v = MikescherGitGraph::create(); $SITE->modules->ExtendedGitGraph()->update();
$v->update(); $SITE->modules->ExtendedGitGraph()->updateCache();
$v->updateCache();

View File

@ -1,10 +1,14 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
global $CONFIG; /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
if ($CONFIG['extendedgitgraph']['output_file'])
if ($SITE->config['extendedgitgraph']['output_file'])
{ {
$lfile = $CONFIG['extendedgitgraph']['output_filepath']; $lfile = $SITE->config['extendedgitgraph']['output_filepath'];
if (file_exists($lfile)) if (file_exists($lfile))
{ {
@ -18,11 +22,11 @@ if ($CONFIG['extendedgitgraph']['output_file'])
echo '[[ FILE NOT FOUND ]]'; echo '[[ FILE NOT FOUND ]]';
} }
} }
else if ($CONFIG['extendedgitgraph']['output_file']) else if ($SITE->config['extendedgitgraph']['output_file'])
{ {
if (session_status() !== PHP_SESSION_ACTIVE) session_start(); if (session_status() !== PHP_SESSION_ACTIVE) session_start();
$svar = $CONFIG['extendedgitgraph']['session_var']; $svar = $SITE->config['extendedgitgraph']['session_var'];
if (isset($_GET['clear'])) if (key_exists($svar, $_SESSION)) $_SESSION[$svar] = ''; if (isset($_GET['clear'])) if (key_exists($svar, $_SESSION)) $_SESSION[$svar] = '';

View File

@ -1,16 +1,21 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
require_once (__DIR__ . '/../internals/base.php'); /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
require_once (__DIR__ . '/../internals/adventofcode.php'); /** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
global $PARAM_AOCCALENDAR;
$PARAM_AOCCALENDAR =
[ if (!isset($API_OPTIONS['year'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
'year' => intval($_GET['year']), if (!isset($API_OPTIONS['nav'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
'nav' => boolval($_GET['nav']), if (!isset($API_OPTIONS['linkheader'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
'linkheader' => boolval($_GET['linkheader']), if (!isset($API_OPTIONS['ajax'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
'ajax' => boolval($_GET['ajax']),
'frame' => false, $year = intval($API_OPTIONS['year']);
'frameid' => strval($_GET['frameid']), $shownav = boolval($API_OPTIONS['nav']);
]; $linkheader = boolval($API_OPTIONS['linkheader']);
require (__DIR__ . '/../fragments/panel_aoc_calendar.php'); $ajax = boolval($API_OPTIONS['ajax']);
$frameid = strval($API_OPTIONS['frameid']);
$SITE->fragments->PanelAdventOfCodeCalendar($year, $shownav, $linkheader, $ajax, false, $frameid);

View File

@ -1,21 +1,21 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
global $API_OPTIONS; /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/programs.php');
require_once (__DIR__ . '/../internals/updateslog.php');
if (!isset($API_OPTIONS['name'])) httpDie(400, "Wrong parameters."); if (!isset($API_OPTIONS['name'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
$name = $API_OPTIONS['name']; $name = $API_OPTIONS['name'];
$updatedata = UpdatesLog::listUpdateData(); $updatedata = $SITE->modules->UpdatesLog()->listUpdateData();
if (!array_key_exists($name, $updatedata)) httpError(404, 'Invalid Request - [Name] not found'); if (!array_key_exists($name, $updatedata)) { $FRAME_OPTIONS->forceResult(404, 'Invalid Request - [Name] not found'); return; }
$data = $updatedata[$name]; $data = $updatedata[$name];
UpdatesLog::insert($name, $data['version']); $SITE->modules->UpdatesLog()->insert($name, $data['version']);
print($name."<hr>".$data['version']."<hr>".$data['url']); print($name."<hr>".$data['version']."<hr>".$data['url']);

View File

@ -1,17 +1,17 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
global $API_OPTIONS; /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
global $OPTIONS; /** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
if (!isset($API_OPTIONS['folder'])) httpDie(400, "Wrong parameters."); if (!isset($API_OPTIONS['folder'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
if (!isset($API_OPTIONS['filename'])) httpDie(400, "Wrong parameters."); if (!isset($API_OPTIONS['filename'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
$folder = $API_OPTIONS['folder']; $folder = $API_OPTIONS['folder'];
$filename = $API_OPTIONS['filename']; $filename = $API_OPTIONS['filename'];
$uri = $OPTIONS['uri']; $uri = $ROUTE->full_url;
$reltarget = "Backup/$folder/$filename"; $reltarget = "Backup/$folder/$filename";

View File

@ -1,21 +1,27 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
global $API_OPTIONS; /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
global $OPTIONS; /** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
if (!isset($API_OPTIONS['target'])) httpDie(400, "Wrong parameters."); if (!isset($API_OPTIONS['target'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
$hook = $API_OPTIONS['target']; $hook = $API_OPTIONS['target'];
$uri = $OPTIONS['uri']; $uri = $ROUTE->full_url;
$cmd = ""; $cmd = "";
if ($hook == 'website_mikescher') $cmd = 'git pull'; if ($hook == 'website_mikescher')
else if ($hook == 'griddominance') $cmd = 'update-gdapi'; $cmd = 'git pull';
else httpDie(400, "Unknown webhook: $hook"); else if ($hook == 'griddominance')
$cmd = 'update-gdapi';
else
{
$FRAME_OPTIONS->forceResult(400, "Unknown webhook: $hook");
return;
}
$std = shell_exec($cmd); $std = shell_exec($cmd);

View File

@ -1,4 +1,9 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
$ip = get_client_ip(); $ip = get_client_ip();

View File

@ -1,10 +1,10 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
global $OPTIONS; /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/books.php');
require_once (__DIR__ . '/../internals/programs.php');
echo '<!DOCTYPE html>'; echo '<!DOCTYPE html>';
echo '<html lang="en">'; echo '<html lang="en">';
@ -17,10 +17,10 @@ echo '<meta http-equiv="refresh" content="3; url=/admin; ?>" />';
echo '</head>'; echo '</head>';
echo '<body>'; echo '<body>';
foreach (Books::listAll() as $book) foreach ($SITE->modules->Books()->listAll() as $book)
{ {
echo 'Create preview for ' . $book['title'] . '<br/>' . "\n"; echo 'Create preview for ' . $book['title'] . '<br/>' . "\n";
Books::createPreview($book); $SITE->modules->Books()->createPreview($book);
} }
echo 'Finished.' . '<br/>' . "\n"; echo 'Finished.' . '<br/>' . "\n";

View File

@ -1,10 +1,10 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
global $OPTIONS; /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/books.php');
require_once (__DIR__ . '/../internals/programs.php');
echo '<!DOCTYPE html>'; echo '<!DOCTYPE html>';
echo '<html lang="en">'; echo '<html lang="en">';
@ -17,10 +17,10 @@ echo '<meta http-equiv="refresh" content="3;url=/admin;"/>';
echo '</head>'; echo '</head>';
echo '<body>'; echo '<body>';
foreach (Programs::listAll() as $prog) foreach ($SITE->modules->Programs()->listAll() as $prog)
{ {
echo 'Create preview for ' . $prog['name'] . '<br/>' . "\n"; echo 'Create preview for ' . $prog['name'] . '<br/>' . "\n";
Programs::createPreview($prog); $SITE->modules->Programs()->createPreview($prog);
} }
echo 'Finished.' . '<br/>' . "\n"; echo 'Finished.' . '<br/>' . "\n";

View File

@ -1,10 +1,9 @@
<?php <?php
require_once (__DIR__ . '/../internals/base.php'); require_once (__DIR__ . '/../internals/website.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/updateslog.php');
Database::connect();
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
?> ?>
<div class="stripedtable_container" style="width: 100%;"> <div class="stripedtable_container" style="width: 100%;">
<table class="stripedtable"> <table class="stripedtable">
@ -16,7 +15,7 @@ Database::connect();
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach (UpdatesLog::getEntries($_GET['ulname'], 512) as $entry): ?> <?php foreach ($SITE->modules->UpdatesLog()->getEntries($_GET['ulname'], 512) as $entry): ?>
<tr> <tr>
<td><?php echo $entry['ip']; ?></td> <td><?php echo $entry['ip']; ?></td>
<td><?php echo $entry['version']; ?></td> <td><?php echo $entry['version']; ?></td>

9
www/frames/api_frame.php Normal file
View File

@ -0,0 +1,9 @@
<?php
require_once (__DIR__ . '/../internals/website.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
print($FRAME_OPTIONS->raw);

View File

@ -33,19 +33,19 @@ $URL_RULES =
[ 'url' => ['books', 'view', '?{id}'], 'target' => 'books_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], [ 'url' => ['books', 'view', '?{id}'], 'target' => 'books_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ],
[ 'url' => ['books', 'view', '?{id}', '*'], 'target' => 'books_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], [ 'url' => ['books', 'view', '?{id}', '*'], 'target' => 'books_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ],
[ 'url' => ['update.php'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], [ 'url' => ['update.php'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ],
[ 'url' => ['update.php', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], [ 'url' => ['update.php', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ],
[ 'url' => ['update'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], [ 'url' => ['update'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ],
[ 'url' => ['update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], [ 'url' => ['update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ],
[ 'url' => ['update2'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], [ 'url' => ['update2'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ],
[ 'url' => ['api', 'update'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], [ 'url' => ['api', 'update'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ],
[ 'url' => ['api', 'update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], [ 'url' => ['api', 'update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ],
[ 'url' => ['api', 'test'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'base::test' ], ], [ 'url' => ['api', 'test'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'base::test' ], ],
[ 'url' => ['api', 'setselfadress'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::setselfaddress' ], ], [ 'url' => ['api', 'setselfadress'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'server::setselfaddress' ], ],
[ 'url' => ['api', 'statsping'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'alephnote::statsping' ], ], [ 'url' => ['api', 'statsping'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'alephnote::statsping' ], ],
[ 'url' => ['api', 'webhook', '?{target}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::gitwebhook' ], ], [ 'url' => ['api', 'webhook', '?{target}'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'server::gitwebhook' ], ],
[ 'url' => ['api', 'backupupload'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::backupupload' ], ], [ 'url' => ['api', 'backupupload'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'server::backupupload' ], ],
[ 'url' => ['api', '?{cmd}'], 'target' => 'api.php', 'options' => [ ], 'parameter' => [ 'cmd' => '%URL%' ], ], [ 'url' => ['api', '?{cmd}'], 'target' => 'api.php', 'options' => [ 'api' ], 'parameter' => [ 'cmd' => '%URL%' ], ],
[ 'url' => ['admin'], 'target' => 'admin.php', 'options' => [ 'password' ], 'parameter' => [ ] ], [ 'url' => ['admin'], 'target' => 'admin.php', 'options' => [ 'password' ], 'parameter' => [ ] ],

View File

@ -18,6 +18,16 @@ class MikescherGitGraph
return __DIR__ . '/../../dynamic/egg/cache_fullrenderer.html'; return __DIR__ . '/../../dynamic/egg/cache_fullrenderer.html';
} }
public function update()
{
return $this->extgitgraph->update();
}
public function updateCache()
{
return $this->extgitgraph->updateCache();
}
/** /**
* @return string|null * @return string|null
*/ */

View File

@ -76,4 +76,11 @@ class PageFrameOptions
$this->force_redirect = true; $this->force_redirect = true;
$this->force_redirect_url = $url; $this->force_redirect_url = $url;
} }
public function forceResult(int $statuscode, string $content)
{
$this->statuscode = $statuscode;
ob_clean();
echo $content;
}
} }

View File

@ -88,6 +88,8 @@ class RuleEngine
} }
if (!$match) return null; if (!$match) return null;
$route->urlParameter = $urlparams;
$ctrlOpt = $rule['options']; $ctrlOpt = $rule['options'];
if (in_array('disabled', $ctrlOpt)) return null; if (in_array('disabled', $ctrlOpt)) return null;

View File

@ -16,12 +16,20 @@ class URLRoute
/** @var int */ /** @var int */
public $needsAdminLogin; public $needsAdminLogin;
/** @var array */
public $urlParameter;
/** @var bool */
public $isAPI;
public function __construct(string $target, string $url) public function __construct(string $target, string $url)
{ {
$this->targetpath = __DIR__ . '/../pages/' . $target; $this->targetpath = (__DIR__ . '/../pages/' . $target);
$this->full_url = $url; $this->full_url = $url;
$this->parameter = []; $this->parameter = [];
$this->needsAdminLogin = false; $this->needsAdminLogin = false;
$this->urlParameter = [];
$this->isAPI = false;
} }
/** /**

View File

@ -17,7 +17,7 @@ class Website
public $config; public $config;
/** @var bool|null */ /** @var bool|null */
public $isLoggedIn = null; private $isLoggedIn = null;
/** @var Modules */ /** @var Modules */
public $modules; public $modules;

View File

@ -1,8 +1,15 @@
<?php <?php
require_once (__DIR__ . '/../internals/website.php');
global $OPTIONS; /** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
$FRAME_OPTIONS->title = null;
$FRAME_OPTIONS->canonical_url = null;
$FRAME_OPTIONS->activeHeader = null;
$FRAME_OPTIONS->frame = 'api_frame.php';
require_once (__DIR__ . '/../internals/base.php');
$API_COMMANDS = $API_COMMANDS =
[ [
@ -29,7 +36,7 @@ $API_COMMANDS =
'html::panel_aoc_calendar' => [ 'src' => __DIR__.'/../commands/html_panel-aoc-calendar.php', 'auth' => 'none' ], 'html::panel_aoc_calendar' => [ 'src' => __DIR__.'/../commands/html_panel-aoc-calendar.php', 'auth' => 'none' ],
]; ];
$cmd = strtolower($OPTIONS['cmd']); $cmd = strtolower($ROUTE->parameter['cmd']);
if (!array_key_exists($cmd, $API_COMMANDS)) if (!array_key_exists($cmd, $API_COMMANDS))
{ {
@ -66,17 +73,17 @@ $config = $API_COMMANDS[$cmd];
$secret = isset($_GET['secret']) ? $_GET['secret'] : ''; $secret = isset($_GET['secret']) ? $_GET['secret'] : '';
if ($config['auth'] === 'webhook_secret' && $secret !== $CONFIG['webhook_secret']) httpDie(401, 'Unauthorized.'); if ($config['auth'] === 'webhook_secret' && $secret !== $CONFIG['webhook_secret']) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; }
if ($config['auth'] === 'ajax_secret' && $secret !== $CONFIG['ajax_secret']) httpDie(401, 'Unauthorized.'); if ($config['auth'] === 'ajax_secret' && $secret !== $CONFIG['ajax_secret']) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; }
if ($config['auth'] === 'upload_secret' && $secret !== $CONFIG['upload_secret']) httpDie(401, 'Unauthorized.'); if ($config['auth'] === 'upload_secret' && $secret !== $CONFIG['upload_secret']) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; }
if ($config['auth'] === 'admin' && !isLoggedInByCookie()) httpDie(401, 'Unauthorized.'); if ($config['auth'] === 'admin' && !$SITE->isLoggedInByCookie()) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; }
global $API_OPTIONS; global $API_OPTIONS;
$API_OPTIONS = []; $API_OPTIONS = [];
foreach ($_GET as $k => $v) $API_OPTIONS[strtolower($k)] = $v; foreach ($_GET as $k => $v) $API_OPTIONS[strtolower($k)] = $v;
foreach ($OPTIONS['_urlparams'] as $k => $v) $API_OPTIONS[strtolower($k)] = $v; foreach ($ROUTE->urlParameter as $k => $v) $API_OPTIONS[strtolower($k)] = $v;
try try
{ {
@ -85,15 +92,16 @@ try
} }
catch (exception $e) catch (exception $e)
{ {
print("API Command failed with exception");
print($e);
$content = $content =
"REQUEST: " . var_export($_REQUEST) . "\r\n\r\n" . "REQUEST: " . var_export($_REQUEST) . "\r\n\r\n" .
"IP: " . get_client_ip() . "\r\n\r\n" . "IP: " . get_client_ip() . "\r\n\r\n" .
"ERROR: " . $e . "\r\n\r\n"; "ERROR: " . $e . "\r\n\r\n";
if (isProd()) sendMail("Website API call failed", $content, 'virtualadmin@mikescher.de', 'webserver-info@mikescher.com'); if ($SITE->isProd()) sendMail("Website API call failed", $content, 'virtualadmin@mikescher.de', 'webserver-info@mikescher.com');
httpDie(500, 'Error.'); $msg = "Error.";
if (!$SITE->isProd()) $msg = "Error.\n" . "API Command failed with exception.\n" . $e;
$FRAME_OPTIONS->forceResult(500, $msg);
return;
} }