forked from Telodendria/Telodendria
Build basic framework for creating static pages.
The login fallback, as well as the user-interactive authentication fallbacks, are static HTML pages.
This commit is contained in:
parent
fae9eb4473
commit
36169181dd
9 changed files with 203 additions and 37 deletions
2
TODO.txt
2
TODO.txt
|
@ -22,7 +22,7 @@ Milestone: v0.2.0
|
||||||
[x] Logout
|
[x] Logout
|
||||||
[x] Delete refresh token if present
|
[x] Delete refresh token if present
|
||||||
[ ] Logout all
|
[ ] Logout all
|
||||||
[ ] Login fallback (static HTML page)
|
[~] Login fallback (static HTML page)
|
||||||
[x] User Interactive
|
[x] User Interactive
|
||||||
[x] Passwords
|
[x] Passwords
|
||||||
[x] Caller builds flows
|
[x] Caller builds flows
|
||||||
|
|
|
@ -21,17 +21,21 @@
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <Routes.h>
|
#include <Html.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <Telodendria.h>
|
#include <Telodendria.h>
|
||||||
|
|
||||||
ROUTE_IMPL(RouteMainPage, args)
|
void
|
||||||
|
HtmlBegin(FILE * stream, char *title)
|
||||||
{
|
{
|
||||||
FILE *stream = HttpStream(args->context);
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
HttpResponseHeader(args->context, "Content-Type", "text/html");
|
if (!stream)
|
||||||
HttpSendHeaders(args->context);
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stream,
|
fprintf(stream,
|
||||||
"<!DOCTYPE html>"
|
"<!DOCTYPE html>"
|
||||||
|
@ -39,27 +43,35 @@ ROUTE_IMPL(RouteMainPage, args)
|
||||||
"<head>"
|
"<head>"
|
||||||
"<meta charset=\"utf-8\">"
|
"<meta charset=\"utf-8\">"
|
||||||
"<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">"
|
"<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">"
|
||||||
"<title>It Works! | Telodendria</title>"
|
"<title>%s | Telodendria</title>"
|
||||||
"<style>"
|
"<style>"
|
||||||
|
":root {"
|
||||||
|
" --accent: #7b8333;"
|
||||||
|
"}"
|
||||||
"body {"
|
"body {"
|
||||||
" margin: auto;"
|
" margin: auto;"
|
||||||
" max-width: 6in;"
|
" max-width: 8.5in;"
|
||||||
" padding: 0.25in;"
|
" padding: 0.25in;"
|
||||||
" background-color: #0d1117;"
|
" background-color: #0d1117;"
|
||||||
" color: white;"
|
" color: white;"
|
||||||
"}"
|
"}"
|
||||||
"h1, p, pre {"
|
"a {"
|
||||||
|
" color: var(--accent);"
|
||||||
|
" text-decoration: none;"
|
||||||
|
"}"
|
||||||
|
"h1 {"
|
||||||
" text-align: center;"
|
" text-align: center;"
|
||||||
"}"
|
"}"
|
||||||
"a {"
|
".logo {"
|
||||||
" color: #7b8333;"
|
" color: var(--accent);"
|
||||||
" text-decoration: none;"
|
" text-align: center;"
|
||||||
|
" font-weight: bold;"
|
||||||
"}"
|
"}"
|
||||||
"</style>"
|
"</style>"
|
||||||
"</head>"
|
"</head>"
|
||||||
"<body>"
|
"<body>"
|
||||||
"<pre style=\"color: #7b8333; font-weight: bold;\">"
|
"<pre class=\"logo\">"
|
||||||
);
|
,title);
|
||||||
|
|
||||||
for (i = 0; i < TELODENDRIA_LOGO_HEIGHT; i++)
|
for (i = 0; i < TELODENDRIA_LOGO_HEIGHT; i++)
|
||||||
{
|
{
|
||||||
|
@ -68,24 +80,14 @@ ROUTE_IMPL(RouteMainPage, args)
|
||||||
|
|
||||||
fprintf(stream,
|
fprintf(stream,
|
||||||
"</pre>"
|
"</pre>"
|
||||||
"<h1>It works! Telodendria is running</h1>"
|
"<h1>%s</h1>"
|
||||||
"<p>"
|
,title);
|
||||||
"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>"
|
|
||||||
);
|
|
||||||
|
|
||||||
|
void
|
||||||
|
HtmlEnd(FILE * stream)
|
||||||
|
{
|
||||||
fprintf(stream,
|
fprintf(stream,
|
||||||
"</body>"
|
"</body>"
|
||||||
"</html>"
|
"</html>");
|
||||||
);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
|
@ -100,11 +100,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
||||||
|
|
||||||
pathPart = MATRIX_PATH_POP(pathParts);
|
pathPart = MATRIX_PATH_POP(pathParts);
|
||||||
|
|
||||||
if (!pathPart)
|
if (MATRIX_PATH_EQUALS(pathPart, ".well-known"))
|
||||||
{
|
|
||||||
response = RouteMainPage(&routeArgs);
|
|
||||||
}
|
|
||||||
else if (MATRIX_PATH_EQUALS(pathPart, ".well-known"))
|
|
||||||
{
|
{
|
||||||
response = RouteWellKnown(&routeArgs);
|
response = RouteWellKnown(&routeArgs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,12 @@ ROUTE_IMPL(RouteMatrix, args)
|
||||||
HashMap *response = NULL;
|
HashMap *response = NULL;
|
||||||
char *pathPart = MATRIX_PATH_POP(args->path);
|
char *pathPart = MATRIX_PATH_POP(args->path);
|
||||||
|
|
||||||
|
if (MATRIX_PATH_EQUALS(pathPart, "static"))
|
||||||
|
{
|
||||||
|
Free(pathPart);
|
||||||
|
return RouteStatic(args);
|
||||||
|
}
|
||||||
|
|
||||||
if (!MATRIX_PATH_EQUALS(pathPart, "client") || MATRIX_PATH_PARTS(args->path) < 1)
|
if (!MATRIX_PATH_EQUALS(pathPart, "client") || MATRIX_PATH_PARTS(args->path) < 1)
|
||||||
{
|
{
|
||||||
Free(pathPart);
|
Free(pathPart);
|
||||||
|
|
37
src/Routes/RouteStatic.c
Normal file
37
src/Routes/RouteStatic.c
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* 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 <Static.h>
|
||||||
|
|
||||||
|
ROUTE_IMPL(RouteStatic, args)
|
||||||
|
{
|
||||||
|
FILE *stream = HttpStream(args->context);
|
||||||
|
|
||||||
|
HttpResponseHeader(args->context, "Content-Type", "text/html");
|
||||||
|
HttpSendHeaders(args->context);
|
||||||
|
|
||||||
|
StaticItWorks(stream);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
55
src/Static/StaticItWorks.c
Normal file
55
src/Static/StaticItWorks.c
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* 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 <Static.h>
|
||||||
|
#include <Html.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
StaticItWorks(FILE * stream)
|
||||||
|
{
|
||||||
|
HtmlBegin(stream, "It works! Telodendria is running.");
|
||||||
|
|
||||||
|
fprintf(stream,
|
||||||
|
"<style>"
|
||||||
|
"p {"
|
||||||
|
" text-align: center;"
|
||||||
|
"}"
|
||||||
|
"</style>"
|
||||||
|
);
|
||||||
|
|
||||||
|
fprintf(stream,
|
||||||
|
"<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>"
|
||||||
|
);
|
||||||
|
|
||||||
|
HtmlEnd(stream);
|
||||||
|
}
|
35
src/include/Html.h
Normal file
35
src/include/Html.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* 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_HTML_H
|
||||||
|
#define TELODENDRIA_HTML_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
extern void
|
||||||
|
HtmlBegin(FILE *, char *);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
HtmlEnd(FILE *);
|
||||||
|
|
||||||
|
#endif /* TELODENDRIA_HTML_H */
|
|
@ -57,9 +57,9 @@ 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(RouteStatic); /* /_matrix/static */
|
||||||
|
|
||||||
ROUTE(RouteLogin); /* /_matrix/client/(r0|v3)/login */
|
ROUTE(RouteLogin); /* /_matrix/client/(r0|v3)/login */
|
||||||
ROUTE(RouteLogout); /* /_matrix/client/(r0|v3)/logout */
|
ROUTE(RouteLogout); /* /_matrix/client/(r0|v3)/logout */
|
||||||
|
|
35
src/include/Static.h
Normal file
35
src/include/Static.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* 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_STATIC_H
|
||||||
|
#define TELODENDRIA_STATIC_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
extern void
|
||||||
|
StaticItWorks(FILE *);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
StaticLogin(FILE *);
|
||||||
|
|
||||||
|
#endif /* TELODENDRIA_STATIC_H */
|
Loading…
Reference in a new issue