forked from lda/telodendria
Add a non-JSON landing page. This is the basis for other HTML pages.
This commit is contained in:
parent
4e742d5179
commit
e0f7c133d1
6 changed files with 203 additions and 70 deletions
4
TODO.txt
4
TODO.txt
|
@ -18,8 +18,8 @@ Milestone: v0.2.0
|
||||||
[ ] Logout
|
[ ] Logout
|
||||||
[ ] Logout all
|
[ ] Logout all
|
||||||
[ ] Login fallback (static HTML page)
|
[ ] Login fallback (static HTML page)
|
||||||
[ ] Non-JSON endpoints
|
[x] Non-JSON endpoints
|
||||||
[ ] Home page (like Synapse's "it works!")
|
[x] Home page (like Synapse's "it works!")
|
||||||
[ ] Content repository
|
[ ] Content repository
|
||||||
|
|
||||||
[x] Document MemoryHexDump()
|
[x] Document MemoryHexDump()
|
||||||
|
|
37
src/Matrix.c
37
src/Matrix.c
|
@ -40,7 +40,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
||||||
MatrixHttpHandlerArgs *args = (MatrixHttpHandlerArgs *) argp;
|
MatrixHttpHandlerArgs *args = (MatrixHttpHandlerArgs *) argp;
|
||||||
LogConfig *lc = args->lc;
|
LogConfig *lc = args->lc;
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
HashMap *response;
|
HashMap *response = NULL;
|
||||||
|
|
||||||
char *key;
|
char *key;
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
||||||
|
|
||||||
HttpResponseStatus(context, HTTP_OK);
|
HttpResponseStatus(context, HTTP_OK);
|
||||||
HttpResponseHeader(context, "Server", "Telodendria/" TELODENDRIA_VERSION);
|
HttpResponseHeader(context, "Server", "Telodendria/" TELODENDRIA_VERSION);
|
||||||
HttpResponseHeader(context, "Content-Type", "application/json");
|
|
||||||
|
|
||||||
/* CORS */
|
/* CORS */
|
||||||
HttpResponseHeader(context, "Access-Control-Allow-Origin", "*");
|
HttpResponseHeader(context, "Access-Control-Allow-Origin", "*");
|
||||||
|
@ -101,7 +100,11 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
||||||
|
|
||||||
pathPart = MATRIX_PATH_POP(pathParts);
|
pathPart = MATRIX_PATH_POP(pathParts);
|
||||||
|
|
||||||
if (MATRIX_PATH_EQUALS(pathPart, ".well-known"))
|
if (!pathPart)
|
||||||
|
{
|
||||||
|
response = RouteMainPage(&routeArgs);
|
||||||
|
}
|
||||||
|
else if (MATRIX_PATH_EQUALS(pathPart, ".well-known"))
|
||||||
{
|
{
|
||||||
response = RouteWellKnown(&routeArgs);
|
response = RouteWellKnown(&routeArgs);
|
||||||
}
|
}
|
||||||
|
@ -117,19 +120,26 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
||||||
|
|
||||||
Free(pathPart);
|
Free(pathPart);
|
||||||
|
|
||||||
if (!response)
|
/*
|
||||||
|
* If the route handler returned a JSON object, take care
|
||||||
|
* of sending it here.
|
||||||
|
*
|
||||||
|
* Otherwise, if the route handler returned NULL, so assume
|
||||||
|
* that it sent its own headers and and body.
|
||||||
|
*/
|
||||||
|
if (response)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERR, "The route handler returned NULL: %s", requestPath);
|
HttpResponseHeader(context, "Content-Type", "application/json");
|
||||||
HttpResponseStatus(context, HTTP_INTERNAL_SERVER_ERROR);
|
HttpSendHeaders(context);
|
||||||
response = MatrixErrorCreate(M_UNKNOWN);
|
|
||||||
|
stream = HttpStream(context);
|
||||||
|
|
||||||
|
JsonEncode(response, stream);
|
||||||
|
JsonFree(response);
|
||||||
|
|
||||||
|
fprintf(stream, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpSendHeaders(context);
|
|
||||||
|
|
||||||
stream = HttpStream(context);
|
|
||||||
JsonEncode(response, stream);
|
|
||||||
fprintf(stream, "\n");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* By this point, there should be no path parts remaining, but if
|
* By this point, there should be no path parts remaining, but if
|
||||||
* there are, free them up now.
|
* there are, free them up now.
|
||||||
|
@ -140,7 +150,6 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
||||||
}
|
}
|
||||||
|
|
||||||
MATRIX_PATH_FREE(pathParts);
|
MATRIX_PATH_FREE(pathParts);
|
||||||
JsonFree(response);
|
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
LogConfigUnindent(lc);
|
LogConfigUnindent(lc);
|
||||||
|
|
91
src/Routes/RouteMainPage.c
Normal file
91
src/Routes/RouteMainPage.c
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation files
|
||||||
|
* (the "Software"), to deal in the Software without restriction,
|
||||||
|
* including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include <Routes.h>
|
||||||
|
|
||||||
|
#include <Telodendria.h>
|
||||||
|
|
||||||
|
ROUTE_IMPL(RouteMainPage, args)
|
||||||
|
{
|
||||||
|
FILE *stream = HttpStream(args->context);
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
HttpResponseHeader(args->context, "Content-Type", "text/html");
|
||||||
|
HttpSendHeaders(args->context);
|
||||||
|
|
||||||
|
fprintf(stream,
|
||||||
|
"<!DOCTYPE html>"
|
||||||
|
"<html>"
|
||||||
|
"<head>"
|
||||||
|
"<meta charset=\"utf-8\">"
|
||||||
|
"<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">"
|
||||||
|
"<title>It Works! | Telodendria</title>"
|
||||||
|
"<style>"
|
||||||
|
"body {"
|
||||||
|
" margin: auto;"
|
||||||
|
" max-width: 6in;"
|
||||||
|
" padding: 0.25in;"
|
||||||
|
" background-color: #0d1117;"
|
||||||
|
" color: white;"
|
||||||
|
"}"
|
||||||
|
"h1, p, pre {"
|
||||||
|
" text-align: center;"
|
||||||
|
"}"
|
||||||
|
"a {"
|
||||||
|
" color: #7b8333;"
|
||||||
|
" text-decoration: none;"
|
||||||
|
"}"
|
||||||
|
"</style>"
|
||||||
|
"</head>"
|
||||||
|
"<body>"
|
||||||
|
"<pre style=\"color: #7b8333; font-weight: bold;\">"
|
||||||
|
);
|
||||||
|
|
||||||
|
for (i = 0; i < TELODENDRIA_LOGO_HEIGHT; i++)
|
||||||
|
{
|
||||||
|
fprintf(stream, "%s\n", TelodendriaLogo[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stream,
|
||||||
|
"</pre>"
|
||||||
|
"<h1>It works! Telodendria is running</h1>"
|
||||||
|
"<p>"
|
||||||
|
"Your Telodendria server is listening on this port and is ready "
|
||||||
|
"for messages."
|
||||||
|
"</p>"
|
||||||
|
"<p>"
|
||||||
|
"To use this server, you'll need <a href=\"https://matrix.org/clients\">"
|
||||||
|
"a Matrix client</a>."
|
||||||
|
"</p>"
|
||||||
|
"<p>"
|
||||||
|
"Welcome to the Matrix universe :)"
|
||||||
|
"</p>"
|
||||||
|
);
|
||||||
|
|
||||||
|
fprintf(stream,
|
||||||
|
"</body>"
|
||||||
|
"</html>"
|
||||||
|
);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
|
@ -32,6 +32,7 @@
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
|
#include <Telodendria.h>
|
||||||
#include <Memory.h>
|
#include <Memory.h>
|
||||||
#include <TelodendriaConfig.h>
|
#include <TelodendriaConfig.h>
|
||||||
#include <Log.h>
|
#include <Log.h>
|
||||||
|
@ -43,6 +44,42 @@
|
||||||
#include <Cron.h>
|
#include <Cron.h>
|
||||||
#include <UserInteractiveAuth.h>
|
#include <UserInteractiveAuth.h>
|
||||||
|
|
||||||
|
const char
|
||||||
|
TelodendriaLogo[TELODENDRIA_LOGO_HEIGHT][TELODENDRIA_LOGO_WIDTH] = {
|
||||||
|
" .= -=- ",
|
||||||
|
" :.:+ .=:. ",
|
||||||
|
" .=+-==. :. ",
|
||||||
|
" .+- =. ",
|
||||||
|
" .+ :+. ",
|
||||||
|
" ==. -+: ",
|
||||||
|
" =++==--:: =+. ",
|
||||||
|
" .:::--=+=: :+= ",
|
||||||
|
" :==. -=: ",
|
||||||
|
" ===----=-. ... :+. ",
|
||||||
|
" :==+=======: .-+-::-+-=+=",
|
||||||
|
" .==*%#======= :+- .. ",
|
||||||
|
" .:--=-===+=========-. :+: ",
|
||||||
|
" .=++=::..:============-+=-=- ",
|
||||||
|
":+=: :=+-: .-=========-. . ",
|
||||||
|
" =+++: .:=+-: .:--. .--:==: ",
|
||||||
|
" ::---:.. :=+: == ",
|
||||||
|
" ++. .+- ",
|
||||||
|
" =+ .+- ...: ",
|
||||||
|
" +- -+-:-+=::+: ",
|
||||||
|
" :=-....:-=: .--: =- ",
|
||||||
|
" -++=:.:::.. "
|
||||||
|
};
|
||||||
|
|
||||||
|
const char
|
||||||
|
TelodendriaHeader[TELODENDRIA_HEADER_HEIGHT][TELODENDRIA_HEADER_WIDTH] = {
|
||||||
|
"=======================================================",
|
||||||
|
"|_ _|__| | ___ __| | ___ _ __ __| |_ __(_) __ _ ",
|
||||||
|
" | |/ _ \\ |/ _ \\ / _` |/ _ \\ '_ \\ / _` | '__| |/ _` | ",
|
||||||
|
" | | __/ | (_) | (_| | __/ | | | (_| | | | | (_| | ",
|
||||||
|
" |_|\\___|_|\\___/ \\__,_|\\___|_| |_|\\__,_|_| |_|\\__,_| ",
|
||||||
|
"======================================================="
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args)
|
TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args)
|
||||||
{
|
{
|
||||||
|
@ -125,62 +162,18 @@ typedef enum ArgFlag
|
||||||
static void
|
static void
|
||||||
TelodendriaPrintHeader(LogConfig * lc)
|
TelodendriaPrintHeader(LogConfig * lc)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_INFO,
|
size_t i;
|
||||||
" .= -=-");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" :.:+ .=:.");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" .=+-==. :.");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" .+- =.");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" .+ :+.");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" ==. -+:");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" =++==--:: =+.");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" .:::--=+=: :+=");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" :==. -=:");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" ===----=-. ... :+.");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" :==+=======: .-+-::-+-=+=");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" .==*%#======= :+- ..");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" .:--=-===+=========-. :+:");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" .=++=::..:============-+=-=-");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
":+=: :=+-: .-=========-. .");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" =+++: .:=+-: .:--. .--:==:");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" ::---:.. :=+: ==");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" ++. .+-");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" =+ .+- ...:");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" +- -+-:-+=::+:");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" :=-....:-=: .--: =-");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" -++=:.:::..");
|
|
||||||
|
|
||||||
|
for (i = 0; i < TELODENDRIA_LOGO_HEIGHT; i++)
|
||||||
|
{
|
||||||
|
Log(lc, LOG_INFO, "%s", TelodendriaLogo[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < TELODENDRIA_HEADER_HEIGHT; i++)
|
||||||
|
{
|
||||||
|
Log(lc, LOG_INFO, "%s", TelodendriaHeader[i]);
|
||||||
|
}
|
||||||
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" _____ _ _ _ _");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
"|_ _|__| | ___ __| | ___ _ __ __| |_ __(_) __ _");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" | |/ _ \\ |/ _ \\ / _` |/ _ \\ '_ \\ / _` | '__| |/ _` |");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" | | __/ | (_) | (_| | __/ | | | (_| | | | | (_| |");
|
|
||||||
Log(lc, LOG_INFO,
|
|
||||||
" |_|\\___|_|\\___/ \\__,_|\\___|_| |_|\\__,_|_| |_|\\__,_|");
|
|
||||||
Log(lc, LOG_INFO, "Telodendria v" TELODENDRIA_VERSION);
|
Log(lc, LOG_INFO, "Telodendria v" TELODENDRIA_VERSION);
|
||||||
Log(lc, LOG_INFO, "");
|
Log(lc, LOG_INFO, "");
|
||||||
Log(lc, LOG_INFO,
|
Log(lc, LOG_INFO,
|
||||||
|
|
|
@ -57,6 +57,7 @@ typedef struct RouteArgs
|
||||||
HashMap * \
|
HashMap * \
|
||||||
name(RouteArgs * argsName)
|
name(RouteArgs * argsName)
|
||||||
|
|
||||||
|
ROUTE(RouteMainPage); /* / */
|
||||||
ROUTE(RouteWellKnown); /* /.well-known */
|
ROUTE(RouteWellKnown); /* /.well-known */
|
||||||
ROUTE(RouteMatrix); /* /_matrix */
|
ROUTE(RouteMatrix); /* /_matrix */
|
||||||
ROUTE(RouteLogin); /* /_matrix/client/(r0|v3)/login */
|
ROUTE(RouteLogin); /* /_matrix/client/(r0|v3)/login */
|
||||||
|
|
39
src/include/Telodendria.h
Normal file
39
src/include/Telodendria.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation files
|
||||||
|
* (the "Software"), to deal in the Software without restriction,
|
||||||
|
* including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
#ifndef TELODENDRIA_H
|
||||||
|
#define TELODENDRIA_H
|
||||||
|
|
||||||
|
#define TELODENDRIA_LOGO_WIDTH 56
|
||||||
|
#define TELODENDRIA_LOGO_HEIGHT 22
|
||||||
|
|
||||||
|
extern const char
|
||||||
|
TelodendriaLogo[TELODENDRIA_LOGO_HEIGHT][TELODENDRIA_LOGO_WIDTH];
|
||||||
|
|
||||||
|
#define TELODENDRIA_HEADER_WIDTH 56
|
||||||
|
#define TELODENDRIA_HEADER_HEIGHT 6
|
||||||
|
|
||||||
|
extern const char
|
||||||
|
TelodendriaHeader[TELODENDRIA_HEADER_HEIGHT][TELODENDRIA_HEADER_WIDTH];
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue