From f5a9552dbd91cf94c1475123fa6a91d580b7a98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer=20=28Macbook=29?= Date: Thu, 16 Jan 2020 13:21:14 +0100 Subject: [PATCH] API --- www/commands/alephnote_show.php | 10 +- www/commands/alephnote_statsping.php | 23 ++-- www/commands/base_test.php | 8 +- www/commands/extendedgitgraph_redraw.php | 12 +- www/commands/extendedgitgraph_refresh.php | 12 +- www/commands/extendedgitgraph_status.php | 14 +- www/commands/html_panel-aoc-calendar.php | 31 +++-- www/commands/progs_updatecheck.php | 16 +-- www/commands/server_backupupload.php | 14 +- www/commands/server_gitwebhook.php | 24 ++-- www/commands/server_setselfaddress.php | 5 + www/commands/site_createBookThumbnails.php | 12 +- www/commands/site_createProgramThumbnails.php | 12 +- www/commands/updates_show.php | 11 +- www/frames/api_frame.php | 9 ++ www/index.php | 128 +++++++++--------- www/internals/modules/mikeschergitgraph.php | 10 ++ www/internals/pageframeoptions.php | 7 + www/internals/ruleengine.php | 2 + www/internals/urlroute.php | 10 +- www/internals/website.php | 2 +- www/pages/api.php | 34 +++-- 22 files changed, 237 insertions(+), 169 deletions(-) create mode 100644 www/frames/api_frame.php diff --git a/www/commands/alephnote_show.php b/www/commands/alephnote_show.php index ee98d25..aa2c36d 100644 --- a/www/commands/alephnote_show.php +++ b/www/commands/alephnote_show.php @@ -1,9 +1,9 @@
@@ -20,7 +20,7 @@ Database::connect(); - + modules->AlephNoteStatistics()->getAllActiveEntriesOrdered() as $entry): ?> diff --git a/www/commands/alephnote_statsping.php b/www/commands/alephnote_statsping.php index dcbf878..98e3f99 100644 --- a/www/commands/alephnote_statsping.php +++ b/www/commands/alephnote_statsping.php @@ -1,16 +1,17 @@ forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['clientid'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['version'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['providerstr'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['providerid'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['notecount'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } $nam = $API_OPTIONS['name']; $cid = $API_OPTIONS['clientid']; @@ -22,9 +23,7 @@ $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', +$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', [ [':cid1', $cid, PDO::PARAM_STR], [':ver1', $ver, PDO::PARAM_STR], diff --git a/www/commands/base_test.php b/www/commands/base_test.php index 1c467f6..4a1b139 100644 --- a/www/commands/base_test.php +++ b/www/commands/base_test.php @@ -1,3 +1,9 @@ updateCache(); - +$v = $SITE->modules->ExtendedGitGraph()->updateCache(); diff --git a/www/commands/extendedgitgraph_refresh.php b/www/commands/extendedgitgraph_refresh.php index f2f3bf1..a65c9fe 100644 --- a/www/commands/extendedgitgraph_refresh.php +++ b/www/commands/extendedgitgraph_refresh.php @@ -1,12 +1,12 @@ update(); -$v->updateCache(); +$SITE->modules->ExtendedGitGraph()->update(); +$SITE->modules->ExtendedGitGraph()->updateCache(); diff --git a/www/commands/extendedgitgraph_status.php b/www/commands/extendedgitgraph_status.php index e39ee5e..9a56ba6 100644 --- a/www/commands/extendedgitgraph_status.php +++ b/www/commands/extendedgitgraph_status.php @@ -1,10 +1,14 @@ config['extendedgitgraph']['output_file']) { - $lfile = $CONFIG['extendedgitgraph']['output_filepath']; + $lfile = $SITE->config['extendedgitgraph']['output_filepath']; if (file_exists($lfile)) { @@ -18,11 +22,11 @@ if ($CONFIG['extendedgitgraph']['output_file']) 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(); - $svar = $CONFIG['extendedgitgraph']['session_var']; + $svar = $SITE->config['extendedgitgraph']['session_var']; if (isset($_GET['clear'])) if (key_exists($svar, $_SESSION)) $_SESSION[$svar] = ''; diff --git a/www/commands/html_panel-aoc-calendar.php b/www/commands/html_panel-aoc-calendar.php index fd42fcc..6db0baa 100644 --- a/www/commands/html_panel-aoc-calendar.php +++ b/www/commands/html_panel-aoc-calendar.php @@ -1,16 +1,21 @@ intval($_GET['year']), - 'nav' => boolval($_GET['nav']), - 'linkheader' => boolval($_GET['linkheader']), - 'ajax' => boolval($_GET['ajax']), - 'frame' => false, - 'frameid' => strval($_GET['frameid']), -]; -require (__DIR__ . '/../fragments/panel_aoc_calendar.php'); + + +if (!isset($API_OPTIONS['year'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['nav'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['linkheader'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['ajax'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } + +$year = intval($API_OPTIONS['year']); +$shownav = boolval($API_OPTIONS['nav']); +$linkheader = boolval($API_OPTIONS['linkheader']); +$ajax = boolval($API_OPTIONS['ajax']); +$frameid = strval($API_OPTIONS['frameid']); + +$SITE->fragments->PanelAdventOfCodeCalendar($year, $shownav, $linkheader, $ajax, false, $frameid); diff --git a/www/commands/progs_updatecheck.php b/www/commands/progs_updatecheck.php index 245f42a..602549e 100644 --- a/www/commands/progs_updatecheck.php +++ b/www/commands/progs_updatecheck.php @@ -1,21 +1,21 @@ forceResult(400, "Wrong parameters."); return; } $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]; -UpdatesLog::insert($name, $data['version']); +$SITE->modules->UpdatesLog()->insert($name, $data['version']); print($name."
".$data['version']."
".$data['url']); diff --git a/www/commands/server_backupupload.php b/www/commands/server_backupupload.php index 02740ef..cf26e3e 100644 --- a/www/commands/server_backupupload.php +++ b/www/commands/server_backupupload.php @@ -1,17 +1,17 @@ forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['filename'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } $folder = $API_OPTIONS['folder']; $filename = $API_OPTIONS['filename']; -$uri = $OPTIONS['uri']; +$uri = $ROUTE->full_url; $reltarget = "Backup/$folder/$filename"; diff --git a/www/commands/server_gitwebhook.php b/www/commands/server_gitwebhook.php index 1876fd8..c7f7b6e 100644 --- a/www/commands/server_gitwebhook.php +++ b/www/commands/server_gitwebhook.php @@ -1,21 +1,27 @@ forceResult(400, "Wrong parameters."); return; } $hook = $API_OPTIONS['target']; -$uri = $OPTIONS['uri']; +$uri = $ROUTE->full_url; $cmd = ""; -if ($hook == 'website_mikescher') $cmd = 'git pull'; -else if ($hook == 'griddominance') $cmd = 'update-gdapi'; -else httpDie(400, "Unknown webhook: $hook"); +if ($hook == 'website_mikescher') + $cmd = 'git pull'; +else if ($hook == 'griddominance') + $cmd = 'update-gdapi'; +else +{ + $FRAME_OPTIONS->forceResult(400, "Unknown webhook: $hook"); + return; +} $std = shell_exec($cmd); diff --git a/www/commands/server_setselfaddress.php b/www/commands/server_setselfaddress.php index 0b2db70..f9e0f3e 100644 --- a/www/commands/server_setselfaddress.php +++ b/www/commands/server_setselfaddress.php @@ -1,4 +1,9 @@ '; echo ''; @@ -17,10 +17,10 @@ echo ''; echo ''; echo ''; -foreach (Books::listAll() as $book) +foreach ($SITE->modules->Books()->listAll() as $book) { echo 'Create preview for ' . $book['title'] . '
' . "\n"; - Books::createPreview($book); + $SITE->modules->Books()->createPreview($book); } echo 'Finished.' . '
' . "\n"; diff --git a/www/commands/site_createProgramThumbnails.php b/www/commands/site_createProgramThumbnails.php index 8b5cd6a..7c5b00d 100644 --- a/www/commands/site_createProgramThumbnails.php +++ b/www/commands/site_createProgramThumbnails.php @@ -1,10 +1,10 @@ '; echo ''; @@ -17,10 +17,10 @@ echo ''; echo ''; echo ''; -foreach (Programs::listAll() as $prog) +foreach ($SITE->modules->Programs()->listAll() as $prog) { echo 'Create preview for ' . $prog['name'] . '
' . "\n"; - Programs::createPreview($prog); + $SITE->modules->Programs()->createPreview($prog); } echo 'Finished.' . '
' . "\n"; diff --git a/www/commands/updates_show.php b/www/commands/updates_show.php index 7f35a4b..021f7b3 100644 --- a/www/commands/updates_show.php +++ b/www/commands/updates_show.php @@ -1,10 +1,9 @@
@@ -16,7 +15,7 @@ Database::connect(); - + modules->UpdatesLog()->getEntries($_GET['ulname'], 512) as $entry): ?> diff --git a/www/frames/api_frame.php b/www/frames/api_frame.php new file mode 100644 index 0000000..cff59c6 --- /dev/null +++ b/www/frames/api_frame.php @@ -0,0 +1,9 @@ +raw); \ No newline at end of file diff --git a/www/index.php b/www/index.php index 82677f3..ecf2691 100644 --- a/www/index.php +++ b/www/index.php @@ -7,77 +7,77 @@ $site->init(); $URL_RULES = [ - [ 'url' => [], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['index'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['index.php'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['msmain', 'index'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['about'], 'target' => 'about.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['msmain', 'about'], 'target' => 'about.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['login'], 'target' => 'login.php', 'options' => [ 'http' ], 'parameter' => [ 'login_target' => '/' ], ], - [ 'url' => ['logout'], 'target' => 'logout.php', 'options' => [ 'http' ], 'parameter' => [ 'logout_target' => '/' ], ], + [ 'url' => [], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['index'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['index.php'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['msmain', 'index'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['about'], 'target' => 'about.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['msmain', 'about'], 'target' => 'about.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['login'], 'target' => 'login.php', 'options' => [ 'http' ], 'parameter' => [ 'login_target' => '/' ], ], + [ 'url' => ['logout'], 'target' => 'logout.php', 'options' => [ 'http' ], 'parameter' => [ 'logout_target' => '/' ], ], - [ 'url' => ['programs'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['programs', 'index'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '%GET%' ], ], - [ 'url' => ['programs', 'index'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['programs', 'cat', '?{categoryfilter}'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '%URL%' ], ], - [ 'url' => ['downloads', 'details.php'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['downloads', 'downloads.php'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['programs', 'view', '?{id}'], 'target' => 'programs_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], - [ 'url' => ['programs', 'view'], 'target' => 'programs_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], - [ 'url' => ['downloads', '?{id}'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], - [ 'url' => ['programs', 'download', '?{id}'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], - [ 'url' => ['programs', 'download'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], + [ 'url' => ['programs'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['programs', 'index'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '%GET%' ], ], + [ 'url' => ['programs', 'index'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['programs', 'cat', '?{categoryfilter}'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '%URL%' ], ], + [ 'url' => ['downloads', 'details.php'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['downloads', 'downloads.php'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['programs', 'view', '?{id}'], 'target' => 'programs_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], + [ 'url' => ['programs', 'view'], 'target' => 'programs_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], + [ 'url' => ['downloads', '?{id}'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], + [ 'url' => ['programs', 'download', '?{id}'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], + [ 'url' => ['programs', 'download'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], - [ 'url' => ['books'], 'target' => 'books_list.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['books', 'list'], 'target' => 'books_list.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ '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'], 'target' => 'books_list.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['books', 'list'], 'target' => 'books_list.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ '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' => ['update.php'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update.php', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update2'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['api', 'update'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['api', 'update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['api', 'test'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'base::test' ], ], - [ 'url' => ['api', 'setselfadress'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::setselfaddress' ], ], - [ 'url' => ['api', 'statsping'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'alephnote::statsping' ], ], - [ 'url' => ['api', 'webhook', '?{target}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::gitwebhook' ], ], - [ 'url' => ['api', 'backupupload'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::backupupload' ], ], - [ 'url' => ['api', '?{cmd}'], 'target' => 'api.php', 'options' => [ ], 'parameter' => [ 'cmd' => '%URL%' ], ], + [ 'url' => ['update.php'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], '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', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['update2'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], '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', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['api', 'test'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'base::test' ], ], + [ 'url' => ['api', 'setselfadress'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'server::setselfaddress' ], ], + [ 'url' => ['api', 'statsping'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'alephnote::statsping' ], ], + [ 'url' => ['api', 'webhook', '?{target}'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'server::gitwebhook' ], ], + [ 'url' => ['api', 'backupupload'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'server::backupupload' ], ], + [ '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' => [ ] ], - [ 'url' => ['blog'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], - [ 'url' => ['log'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], - [ 'url' => ['blogpost', 'index'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], - [ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['blog', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['blog', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], - [ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['log', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['log', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], - [ 'url' => ['blogpost', 'view'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%GET%', 'subview' => '' ], ], + [ 'url' => ['blog'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['log'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['blogpost', 'index'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['blog', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['blog', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], + [ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['log', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['log', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], + [ 'url' => ['blogpost', 'view'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%GET%', 'subview' => '' ], ], - [ 'url' => ['webapps'], 'target' => 'webapps_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['webapps'], 'target' => 'webapps_list.php', 'options' => [ ], 'parameter' => [ ], ], - [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'listentries'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['highscores', 'list'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['highscores', 'listgames'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['highscores', 'insert.php'], 'target' => 'highscores_insert.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], - [ 'url' => ['highscores', 'insert'], 'target' => 'highscores_insert.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], - [ 'url' => ['highscores', 'update.php'], 'target' => 'highscores_update.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'update'], 'target' => 'highscores_update.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list_top50.php'], 'target' => 'highscores_top50.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list_top50'], 'target' => 'highscores_top50.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'getNewID.php'], 'target' => 'highscores_newid.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'newid'], 'target' => 'highscores_newid.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'listentries'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['highscores', 'list'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['highscores', 'listgames'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['highscores', 'insert.php'], 'target' => 'highscores_insert.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], + [ 'url' => ['highscores', 'insert'], 'target' => 'highscores_insert.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], + [ 'url' => ['highscores', 'update.php'], 'target' => 'highscores_update.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'update'], 'target' => 'highscores_update.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list_top50.php'], 'target' => 'highscores_top50.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list_top50'], 'target' => 'highscores_top50.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'getNewID.php'], 'target' => 'highscores_newid.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'newid'], 'target' => 'highscores_newid.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], ]; $site->serve($URL_RULES); diff --git a/www/internals/modules/mikeschergitgraph.php b/www/internals/modules/mikeschergitgraph.php index 059eab8..b3fac93 100644 --- a/www/internals/modules/mikeschergitgraph.php +++ b/www/internals/modules/mikeschergitgraph.php @@ -18,6 +18,16 @@ class MikescherGitGraph return __DIR__ . '/../../dynamic/egg/cache_fullrenderer.html'; } + public function update() + { + return $this->extgitgraph->update(); + } + + public function updateCache() + { + return $this->extgitgraph->updateCache(); + } + /** * @return string|null */ diff --git a/www/internals/pageframeoptions.php b/www/internals/pageframeoptions.php index 478b9e2..c9cc72b 100644 --- a/www/internals/pageframeoptions.php +++ b/www/internals/pageframeoptions.php @@ -76,4 +76,11 @@ class PageFrameOptions $this->force_redirect = true; $this->force_redirect_url = $url; } + + public function forceResult(int $statuscode, string $content) + { + $this->statuscode = $statuscode; + ob_clean(); + echo $content; + } } \ No newline at end of file diff --git a/www/internals/ruleengine.php b/www/internals/ruleengine.php index 35e27ad..a7fa119 100644 --- a/www/internals/ruleengine.php +++ b/www/internals/ruleengine.php @@ -88,6 +88,8 @@ class RuleEngine } if (!$match) return null; + $route->urlParameter = $urlparams; + $ctrlOpt = $rule['options']; if (in_array('disabled', $ctrlOpt)) return null; diff --git a/www/internals/urlroute.php b/www/internals/urlroute.php index d8f1583..96bbaa9 100644 --- a/www/internals/urlroute.php +++ b/www/internals/urlroute.php @@ -16,12 +16,20 @@ class URLRoute /** @var int */ public $needsAdminLogin; + /** @var array */ + public $urlParameter; + + /** @var bool */ + public $isAPI; + public function __construct(string $target, string $url) { - $this->targetpath = __DIR__ . '/../pages/' . $target; + $this->targetpath = (__DIR__ . '/../pages/' . $target); $this->full_url = $url; $this->parameter = []; $this->needsAdminLogin = false; + $this->urlParameter = []; + $this->isAPI = false; } /** diff --git a/www/internals/website.php b/www/internals/website.php index c8900a4..bd3175d 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -17,7 +17,7 @@ class Website public $config; /** @var bool|null */ - public $isLoggedIn = null; + private $isLoggedIn = null; /** @var Modules */ public $modules; diff --git a/www/pages/api.php b/www/pages/api.php index 883245b..f953822 100644 --- a/www/pages/api.php +++ b/www/pages/api.php @@ -1,8 +1,15 @@ 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 = [ @@ -29,7 +36,7 @@ $API_COMMANDS = '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)) { @@ -66,17 +73,17 @@ $config = $API_COMMANDS[$cmd]; $secret = isset($_GET['secret']) ? $_GET['secret'] : ''; -if ($config['auth'] === 'webhook_secret' && $secret !== $CONFIG['webhook_secret']) httpDie(401, 'Unauthorized.'); -if ($config['auth'] === 'ajax_secret' && $secret !== $CONFIG['ajax_secret']) httpDie(401, 'Unauthorized.'); -if ($config['auth'] === 'upload_secret' && $secret !== $CONFIG['upload_secret']) httpDie(401, 'Unauthorized.'); -if ($config['auth'] === 'admin' && !isLoggedInByCookie()) 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']) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; } +if ($config['auth'] === 'upload_secret' && $secret !== $CONFIG['upload_secret']) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; } +if ($config['auth'] === 'admin' && !$SITE->isLoggedInByCookie()) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; } 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; +foreach ($ROUTE->urlParameter as $k => $v) $API_OPTIONS[strtolower($k)] = $v; try { @@ -85,15 +92,16 @@ try } catch (exception $e) { - print("API Command failed with exception"); - print($e); - $content = "REQUEST: " . var_export($_REQUEST) . "\r\n\r\n" . "IP: " . get_client_ip() . "\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; }