Outsource default documents to actual files
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
*
|
||||
!src
|
||||
!src/**
|
||||
!res
|
||||
!res/**
|
||||
!doc
|
||||
!doc/**
|
||||
!test
|
||||
|
15
Makefile
15
Makefile
@ -7,7 +7,7 @@ DEBIAN_OPTS=-D CACHE_MAGIC_FILE="\"/usr/share/file/magic.mgc\"" -D PHP_FPM_SOCKE
|
||||
|
||||
.PHONY: all prod debug default debian permit clean test
|
||||
all: prod
|
||||
default: bin bin/lib bin/worker bin/sesimos
|
||||
default: bin bin/lib bin/worker bin/res bin/sesimos
|
||||
|
||||
prod: CFLAGS += -O3
|
||||
prod: default
|
||||
@ -32,6 +32,9 @@ bin/lib:
|
||||
bin/worker:
|
||||
mkdir -p bin/worker
|
||||
|
||||
bin/res:
|
||||
mkdir -p bin/res
|
||||
|
||||
bin/test: test/mock_*.c test/test_*.c src/lib/utils.c src/lib/sock.c
|
||||
$(CC) -o $@ $(CFLAGS) $^ -lcriterion
|
||||
|
||||
@ -45,11 +48,19 @@ bin/lib/%.o: src/lib/%.c
|
||||
bin/worker/%.o: src/worker/%.c
|
||||
$(CC) -c -o $@ $(CFLAGS) $<
|
||||
|
||||
bin/res/%.o: bin/res/%.txt
|
||||
objcopy -I binary --rename-section .data=.rodata -O elf64-x86-64 $^ $@
|
||||
|
||||
bin/res/%.txt: res/%.*
|
||||
cp $^ $@
|
||||
echo -ne "\x00" >> $@
|
||||
|
||||
bin/sesimos: bin/server.o bin/logger.o bin/cache_handler.o bin/async.o bin/workers.o \
|
||||
bin/worker/request_handler.o bin/worker/tcp_acceptor.o \
|
||||
bin/worker/fastcgi_handler.o bin/worker/local_handler.o bin/worker/proxy_handler.o \
|
||||
bin/lib/http_static.o bin/res/default.o bin/res/proxy.o bin/res/style.o \
|
||||
bin/lib/compress.o bin/lib/config.o bin/lib/fastcgi.o bin/lib/geoip.o \
|
||||
bin/lib/http.o bin/lib/http_static.o bin/lib/proxy.o bin/lib/sock.o bin/lib/uri.o \
|
||||
bin/lib/http.o bin/lib/proxy.o bin/lib/sock.o bin/lib/uri.o \
|
||||
bin/lib/utils.o bin/lib/websocket.o bin/lib/mpmc.o
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||
|
||||
|
21
res/default.html
Normal file
21
res/default.html
Normal file
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>%1$i %2$s - %7$s</title>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="theme-color" content="%6$s"/>
|
||||
<meta name="color-scheme" content="light dark"/>
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
|
||||
<link rel="stylesheet" type="text/css" href="/.sesimos/style.css"/>
|
||||
%5$s <style>html{--color:var(--%4$s);}</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<section>
|
||||
%3$s%9$s <div class="footer"><a href="https://%7$s/">%7$s</a> - %10$s</div>
|
||||
</section>
|
||||
%8$s </main>
|
||||
</body>
|
||||
</html>
|
31
res/proxy.html
Normal file
31
res/proxy.html
Normal file
@ -0,0 +1,31 @@
|
||||
<section class="error-ctx">
|
||||
<div class="box%1$s">
|
||||
<div class="content">
|
||||
<span>Client</span>
|
||||
<img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTIsMzIgYTMwLDMwLDAsMSwwLDYwLDAgYTMwLDMwLDAsMSwwLC02MCwwIEw2MiwzMiBNNiwxNiBMNTgsMTYgTTYsNDggTDU4LDQ4IE0zMiwyIEwzMiw2MiBhMTUsMzAsMCwxLDAsMCwtNjAgYTE1LDMwLDAsMSwwLDAsNjAgWiIgc3Ryb2tlPSIjMDA4MDAwIiBzdHJva2Utd2lkdGg9IjIiIGZpbGw9IiMwMDAwMDAwMCIvPjwvc3ZnPgo="/>
|
||||
<span>Your Browser</span>
|
||||
</div>
|
||||
<div class="arrow request%2$s"></div>
|
||||
</div>
|
||||
<div class="border%8$s"></div>
|
||||
<div class="box%3$s">
|
||||
<div class="content">
|
||||
<span>Reverse Proxy</span>
|
||||
<h3>%10$03i</h3>
|
||||
<h4>%11$s</h4>
|
||||
<span>%15$s</span>
|
||||
</div>
|
||||
<div class="arrow request%4$s"></div>
|
||||
<div class="arrow response%5$s"></div>
|
||||
</div>
|
||||
<div class="border%9$s"></div>
|
||||
<div class="box%6$s">
|
||||
<div class="content">
|
||||
<span>Server</span>
|
||||
<h3>%12$s</h3>
|
||||
<h4>%13$s</h4>
|
||||
<span>%14$s</span>
|
||||
</div>
|
||||
<div class="arrow response%7$s"></div>
|
||||
</div>
|
||||
</section>
|
66
res/style.css
Normal file
66
res/style.css
Normal file
@ -0,0 +1,66 @@
|
||||
html{
|
||||
font-family:"Arial",sans-serif;
|
||||
--error:#C00000;
|
||||
--warning:#E0C000;
|
||||
--success:#008000;
|
||||
--info:#606060;
|
||||
--soft:#808080;
|
||||
}
|
||||
|
||||
body{background-color:#F0F0F0;margin:0;}
|
||||
main{max-width:650px;margin:2em auto;}
|
||||
section{margin:2em 1em;background-color:#FFFFFF;border: 1px solid var(--color);border-radius:4px;padding:1em;}
|
||||
h1,h2,h3,h4,h5,h6{text-align:center;color:var(--color);font-weight:normal;}
|
||||
h1{font-size:3em;margin:0.125em 0;}
|
||||
h2{font-size:1.5em;margin:0.25em 0 1em 0;}
|
||||
p{text-align:center;font-size:0.875em;}
|
||||
div.footer{color:var(--soft);font-size:0.75em;text-align:center;margin:2em 0 0.5em 0;}
|
||||
div.footer a{color:var(--soft);}
|
||||
ul,ol{width:fit-content;margin:auto;}
|
||||
pre{width:fit-content;margin:2em auto 0 auto;}
|
||||
|
||||
section.error-ctx{display:flex;padding:0;border:none;}
|
||||
div.box{flex:100% 1 1;border:1px solid var(--info);color:var(--info);position:relative;padding:1em;box-sizing:border-box;text-align:center;}
|
||||
div.box.error{border-color:var(--error);color:var(--error);}
|
||||
div.box.success{border-color:var(--success);color:var(--success);}
|
||||
div.arrow{position:absolute;height:20px;width:30px;z-index:10;background-repeat:no-repeat;background-size:contain;}
|
||||
div.arrow.response{left:-17.5px;bottom:calc(33.3333% - 10px);}
|
||||
div.arrow.request{right:-17.5px;top:calc(33.3333% - 10px);}
|
||||
div.border{flex:1px 0 0;background-color:var(--info);}
|
||||
div.border.error{background-color:var(--error);}
|
||||
div.border.success{background-color:var(--success);}
|
||||
div.content>span{display:block;color:var(--soft);font-size:0.75em;}
|
||||
div.content>img{height:3.75rem;margin:0.75rem auto;display:block;}
|
||||
h3{font-size:2.25em;margin:0.75rem 0 0 0;color:unset;height:2.5rem;}
|
||||
h4{font-size:1em;margin:0 0 0.75rem 0;color:unset;height:1.25rem;}
|
||||
|
||||
div.arrow.request.success{background-image:url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEsMSBMMjUsMSBMMjksMTAgTDI1LDE5IEwxLDE5IiBmaWxsPSIjRkZGRkZGIiBzdHJva2U9IiMwMDgwMDAiIHN0cm9rZS13aWR0aD0iMiIvPjwvc3ZnPgo=');}
|
||||
div.arrow.request.error{background-image:url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEsMSBMMjUsMSBMMjksMTAgTDI1LDE5IEwxLDE5IiBmaWxsPSIjRkZGRkZGIiBzdHJva2U9IiNDMDAwMDAiIHN0cm9rZS13aWR0aD0iMiIvPjwvc3ZnPgo=');}
|
||||
div.arrow.response.success{background-image:url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTI5LDE5IEw1LDE5IEwxLDEwIEw1LDEgTDI5LDEiIGZpbGw9IiNGRkZGRkYiIHN0cm9rZT0iIzAwODAwMCIgc3Ryb2tlLXdpZHRoPSIyIi8+PC9zdmc+Cg==');}
|
||||
div.arrow.response.error{background-image:url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTI5LDE5IEw1LDE5IEwxLDEwIEw1LDEgTDI5LDEiIGZpbGw9IiNGRkZGRkYiIHN0cm9rZT0iI0MwMDAwMCIgc3Ryb2tlLXdpZHRoPSIyIi8+PC9zdmc+Cg==');}
|
||||
|
||||
@media(prefers-color-scheme:dark){
|
||||
html{color:#FFFFFF;--soft:#404040;}
|
||||
body{background-color:#101010;}
|
||||
section{background-color:#181818;}
|
||||
|
||||
div.arrow.request.success{background-image:url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEsMSBMMjUsMSBMMjksMTAgTDI1LDE5IEwxLDE5IiBmaWxsPSIjMTgxODE4IiBzdHJva2U9IiMwMDgwMDAiIHN0cm9rZS13aWR0aD0iMiIvPjwvc3ZnPgo=');}
|
||||
div.arrow.request.error{background-image:url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEsMSBMMjUsMSBMMjksMTAgTDI1LDE5IEwxLDE5IiBmaWxsPSIjMTgxODE4IiBzdHJva2U9IiNDMDAwMDAiIHN0cm9rZS13aWR0aD0iMiIvPjwvc3ZnPgo=');}
|
||||
div.arrow.response.success{background-image:url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTI5LDE5IEw1LDE5IEwxLDEwIEw1LDEgTDI5LDEiIGZpbGw9IiMxODE4MTgiIHN0cm9rZT0iIzAwODAwMCIgc3Ryb2tlLXdpZHRoPSIyIi8+PC9zdmc+Cg==');}
|
||||
div.arrow.response.error{background-image:url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTI5LDE5IEw1LDE5IEwxLDEwIEw1LDEgTDI5LDEiIGZpbGw9IiMxODE4MTgiIHN0cm9rZT0iI0MwMDAwMCIgc3Ryb2tlLXdpZHRoPSIyIi8+PC9zdmc+Cg==');}
|
||||
}
|
||||
|
||||
@media(min-width:650px){
|
||||
div.box:first-child{border-top-left-radius:4px;border-bottom-left-radius:4px;border-right:none;}
|
||||
div.box:last-child{border-top-right-radius:4px;border-bottom-right-radius:4px;border-left:none;}
|
||||
div.box:not(:last-child):not(:first-child){border-left:none;border-right:none;}
|
||||
}
|
||||
|
||||
@media(max-width:650px){
|
||||
section.error-ctx{flex-direction:column;height:unset;}
|
||||
div.box:first-child{border-top-left-radius:4px;border-top-right-radius:4px;border-bottom:none;padding-top:1em;}
|
||||
div.box:last-child{border-bottom-right-radius:4px;border-bottom-left-radius:4px;border-top:none;padding-bottom:1em;}
|
||||
div.box:not(:last-child):not(:first-child){border-top:none;border-bottom:none;}
|
||||
div.arrow.response{transform:rotate(90deg);top:-10px;left:calc(33.3333% - 22.5px);right:unset;}
|
||||
div.arrow.request{transform:rotate(90deg);bottom:-10px;right:calc(33.3333% - 22.5px);top:unset;}
|
||||
}
|
@ -370,7 +370,7 @@ int http_send_request(sock *server, http_req *req) {
|
||||
}
|
||||
|
||||
const http_status *http_get_status(unsigned short status_code) {
|
||||
for (int i = 0; i < http_statuses_size / sizeof(http_status); i++) {
|
||||
for (int i = 0; i < http_statuses_size; i++) {
|
||||
if (http_statuses[i].code == status_code) {
|
||||
return &http_statuses[i];
|
||||
}
|
||||
@ -380,7 +380,7 @@ const http_status *http_get_status(unsigned short status_code) {
|
||||
|
||||
const http_status_msg *http_get_error_msg(const http_status *status) {
|
||||
unsigned short code = status->code;
|
||||
for (int i = 0; i < http_status_messages_size / sizeof(http_status_msg); i++) {
|
||||
for (int i = 0; i < http_status_messages_size; i++) {
|
||||
if (http_status_messages[i].code == code) {
|
||||
return &http_status_messages[i];
|
||||
}
|
||||
@ -419,10 +419,10 @@ char *http_get_date(char *buf, size_t size) {
|
||||
const http_doc_info *http_get_status_info(const http_status *status) {
|
||||
unsigned short code = status->code;
|
||||
static http_doc_info info[] = {
|
||||
{"info", HTTP_COLOR_INFO, http_info_icon, http_info_document},
|
||||
{"success", HTTP_COLOR_SUCCESS, http_success_icon, http_success_document},
|
||||
{"warning", HTTP_COLOR_WARNING, http_warning_icon, http_warning_document},
|
||||
{"error", HTTP_COLOR_ERROR, http_error_icon, http_error_document}
|
||||
{"info", HTTP_COLOR_INFO, http_info_icon, http_info_doc},
|
||||
{"success", HTTP_COLOR_SUCCESS, http_success_icon, http_success_doc},
|
||||
{"warning", HTTP_COLOR_WARNING, http_warning_icon, http_warning_doc},
|
||||
{"error", HTTP_COLOR_ERROR, http_error_icon, http_error_doc}
|
||||
};
|
||||
if (code >= 100 && code < 200) {
|
||||
return &info[0];
|
||||
|
@ -32,9 +32,9 @@
|
||||
#define HTTP_5XX_STR "\x1B[1;31m"
|
||||
|
||||
#define HTTP_COLOR_SUCCESS "#008000"
|
||||
#define HTTP_COLOR_INFO "#606060"
|
||||
#define HTTP_COLOR_INFO "#606060"
|
||||
#define HTTP_COLOR_WARNING "#E0C000"
|
||||
#define HTTP_COLOR_ERROR "#C00000"
|
||||
#define HTTP_COLOR_ERROR "#C00000"
|
||||
|
||||
#define CLIENT_MAX_HEADER_SIZE 8192
|
||||
#define HTTP_MAX_HEADER_FIELD_NUM 64
|
||||
@ -117,16 +117,10 @@ extern const http_status_msg http_status_messages[];
|
||||
extern const int http_statuses_size;
|
||||
extern const int http_status_messages_size;
|
||||
|
||||
extern const char http_default_document[];
|
||||
extern const char http_proxy_document[];
|
||||
extern const char http_error_document[];
|
||||
extern const char http_error_icon[];
|
||||
extern const char http_warning_document[];
|
||||
extern const char http_warning_icon[];
|
||||
extern const char http_success_document[];
|
||||
extern const char http_success_icon[];
|
||||
extern const char http_info_document[];
|
||||
extern const char http_info_icon[];
|
||||
extern const char http_error_doc[], http_error_icon[];
|
||||
extern const char http_warning_doc[], http_warning_icon[];
|
||||
extern const char http_success_doc[], http_success_icon[];
|
||||
extern const char http_info_doc[], http_info_icon[];
|
||||
|
||||
void http_to_camel_case(char *str, int mode);
|
||||
|
||||
|
@ -6,10 +6,8 @@
|
||||
* @date 2021-05-03
|
||||
*/
|
||||
|
||||
#include "../defs.h"
|
||||
#include "http.h"
|
||||
|
||||
|
||||
const http_status http_statuses[] = {
|
||||
{100, "Informational", "Continue"},
|
||||
{101, "Informational", "Switching Protocols"},
|
||||
@ -105,201 +103,56 @@ const http_status_msg http_status_messages[] = {
|
||||
{505, "The server does not support, or refuses to support, the HTTP protocol version that was used in the request message."}
|
||||
};
|
||||
|
||||
const char http_default_document[] =
|
||||
"<!DOCTYPE html>\n"
|
||||
"<html lang=\"en\">\n"
|
||||
"<head>\n"
|
||||
"\t<title>%1$i %2$s - %7$s</title>\n"
|
||||
"\t<meta charset=\"UTF-8\"/>\n"
|
||||
"\t<meta name=\"theme-color\" content=\"%6$s\"/>\n"
|
||||
"\t<meta name=\"color-scheme\" content=\"light dark\"/>\n"
|
||||
"\t<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black-translucent\"/>\n"
|
||||
"\t<meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\"/>\n"
|
||||
"\t<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/favicon.ico\"/>\n"
|
||||
"%5$s"
|
||||
"\t<style>\n"
|
||||
"\t\thtml{font-family:\"Arial\",sans-serif;--error:" HTTP_COLOR_ERROR ";--warning:" HTTP_COLOR_WARNING ";--success:" HTTP_COLOR_SUCCESS ";--info:" HTTP_COLOR_INFO ";--soft:#808080;--color:var(--%4$s);}\n"
|
||||
"\t\tbody{background-color:#F0F0F0;margin:0;}\n"
|
||||
"\t\tmain{max-width:650px;margin:2em auto;}\n"
|
||||
"\t\tsection{margin:2em 1em;background-color:#FFFFFF;border: 1px solid var(--color);border-radius:4px;padding:1em;}\n"
|
||||
"\t\th1,h2,h3,h4,h5,h6{text-align:center;color:var(--color);font-weight:normal;}\n"
|
||||
"\t\th1{font-size:3em;margin:0.125em 0;}\n"
|
||||
"\t\th2{font-size:1.5em;margin:0.25em 0 1em 0;}\n"
|
||||
"\t\tp{text-align:center;font-size:0.875em;}\n"
|
||||
"\t\tdiv.footer{color:var(--soft);font-size:0.75em;text-align:center;margin:2em 0 0.5em 0;}\n"
|
||||
"\t\tdiv.footer a{color:var(--soft);}\n"
|
||||
"\t\tul,ol{width:fit-content;margin:auto;}\n"
|
||||
"\t\tpre{width:fit-content;margin:2em auto 0 auto;}\n"
|
||||
"\n"
|
||||
"\t\tsection.error-ctx{display:flex;padding:0;border:none;}\n"
|
||||
"\t\tdiv.box{flex:100%% 1 1;border:1px solid var(--info);color:var(--info);position:relative;padding:1em;box-sizing:border-box;text-align:center;}\n"
|
||||
"\t\tdiv.box.error{border-color:var(--error);color:var(--error);}\n"
|
||||
"\t\tdiv.box.success{border-color:var(--success);color:var(--success);}\n"
|
||||
"\t\tdiv.arrow{position:absolute;height:20px;width:30px;z-index:10;background-repeat:no-repeat;background-size:contain;}\n"
|
||||
"\t\tdiv.arrow.response{left:-17.5px;bottom:calc(33.3333%% - 10px);}\n"
|
||||
"\t\tdiv.arrow.request{right:-17.5px;top:calc(33.3333%% - 10px);}\n"
|
||||
"\t\tdiv.border{flex:1px 0 0;background-color:var(--info);}\n"
|
||||
"\t\tdiv.border.error{background-color:var(--error);}\n"
|
||||
"\t\tdiv.border.success{background-color:var(--success);}\n"
|
||||
"\t\tdiv.content>span{display:block;color:var(--soft);font-size:0.75em;}\n"
|
||||
"\t\tdiv.content>img{height:3.75rem;margin:0.75rem auto;display:block;}\n"
|
||||
"\t\th3{font-size:2.25em;margin:0.75rem 0 0 0;color:unset;height:2.5rem;}\n"
|
||||
"\t\th4{font-size:1em;margin:0 0 0.75rem 0;color:unset;height:1.25rem;}\n"
|
||||
"\n"
|
||||
"\t\tdiv.arrow.request.success{background-image:url('data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHBhdGggZD0iTTEsMSBMMjUsMSBMMjksMTAgTDI1LDE5IEwxLDE5IiBmaWxsPSIjRkZG"
|
||||
"RkZGIiBzdHJva2U9IiMwMDgwMDAiIHN0cm9rZS13aWR0aD0iMiIvPjwvc3ZnPgo=');}\n"
|
||||
"\t\tdiv.arrow.request.error{background-image:url('data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHBhdGggZD0iTTEsMSBMMjUsMSBMMjksMTAgTDI1LDE5IEwxLDE5IiBmaWxsPSIjRkZG"
|
||||
"RkZGIiBzdHJva2U9IiNDMDAwMDAiIHN0cm9rZS13aWR0aD0iMiIvPjwvc3ZnPgo=');}\n"
|
||||
"\t\tdiv.arrow.response.success{background-image:url('data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHBhdGggZD0iTTI5LDE5IEw1LDE5IEwxLDEwIEw1LDEgTDI5LDEiIGZpbGw9IiNGRkZG"
|
||||
"RkYiIHN0cm9rZT0iIzAwODAwMCIgc3Ryb2tlLXdpZHRoPSIyIi8+PC9zdmc+Cg==');}\n"
|
||||
"\t\tdiv.arrow.response.error{background-image:url('data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHBhdGggZD0iTTI5LDE5IEw1LDE5IEwxLDEwIEw1LDEgTDI5LDEiIGZpbGw9IiNGRkZG"
|
||||
"RkYiIHN0cm9rZT0iI0MwMDAwMCIgc3Ryb2tlLXdpZHRoPSIyIi8+PC9zdmc+Cg==');}\n"
|
||||
"\n"
|
||||
"\t\t@media(prefers-color-scheme:dark){\n"
|
||||
"\t\t\thtml{color:#FFFFFF;--soft:#404040;}\n"
|
||||
"\t\t\tbody{background-color:#101010;}\n"
|
||||
"\t\t\tsection{background-color:#181818;}\n"
|
||||
"\n"
|
||||
"\t\t\tdiv.arrow.request.success{background-image:url('data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHBhdGggZD0iTTEsMSBMMjUsMSBMMjksMTAgTDI1LDE5IEwxLDE5IiBmaWxsPSIjMTgx"
|
||||
"ODE4IiBzdHJva2U9IiMwMDgwMDAiIHN0cm9rZS13aWR0aD0iMiIvPjwvc3ZnPgo=');}\n"
|
||||
"\t\t\tdiv.arrow.request.error{background-image:url('data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHBhdGggZD0iTTEsMSBMMjUsMSBMMjksMTAgTDI1LDE5IEwxLDE5IiBmaWxsPSIjMTgx"
|
||||
"ODE4IiBzdHJva2U9IiNDMDAwMDAiIHN0cm9rZS13aWR0aD0iMiIvPjwvc3ZnPgo=');}\n"
|
||||
"\t\t\tdiv.arrow.response.success{background-image:url('data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHBhdGggZD0iTTI5LDE5IEw1LDE5IEwxLDEwIEw1LDEgTDI5LDEiIGZpbGw9IiMxODE4"
|
||||
"MTgiIHN0cm9rZT0iIzAwODAwMCIgc3Ryb2tlLXdpZHRoPSIyIi8+PC9zdmc+Cg==');}\n"
|
||||
"\t\t\tdiv.arrow.response.error{background-image:url('data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMzAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHBhdGggZD0iTTI5LDE5IEw1LDE5IEwxLDEwIEw1LDEgTDI5LDEiIGZpbGw9IiMxODE4"
|
||||
"MTgiIHN0cm9rZT0iI0MwMDAwMCIgc3Ryb2tlLXdpZHRoPSIyIi8+PC9zdmc+Cg==');}\n"
|
||||
"\t\t}\n"
|
||||
"\t\t@media(min-width:650px){\n"
|
||||
"\t\t\tdiv.box:first-child{border-top-left-radius:4px;border-bottom-left-radius:4px;border-right:none;}\n"
|
||||
"\t\t\tdiv.box:last-child{border-top-right-radius:4px;border-bottom-right-radius:4px;border-left:none;}\n"
|
||||
"\t\t\tdiv.box:not(:last-child):not(:first-child){border-left:none;border-right:none;}\n"
|
||||
"\t\t}\n"
|
||||
"\t\t@media(max-width:650px){\n"
|
||||
"\t\t\tsection.error-ctx{flex-direction:column;height:unset;}\n"
|
||||
"\t\t\tdiv.box:first-child{border-top-left-radius:4px;border-top-right-radius:4px;border-bottom:none;padding-top:1em;}\n"
|
||||
"\t\t\tdiv.box:last-child{border-bottom-right-radius:4px;border-bottom-left-radius:4px;border-top:none;padding-bottom:1em;}\n"
|
||||
"\t\t\tdiv.box:not(:last-child):not(:first-child){border-top:none;border-bottom:none;}\n"
|
||||
"\t\t\tdiv.arrow.response{transform:rotate(90deg);top:-10px;left:calc(33.3333%% - 22.5px);right:unset;}\n"
|
||||
"\t\t\tdiv.arrow.request{transform:rotate(90deg);bottom:-10px;right:calc(33.3333%% - 22.5px);top:unset;}\n"
|
||||
"\t\t}\n"
|
||||
"\t</style>\n"
|
||||
"</head>\n"
|
||||
"<body>\n"
|
||||
"\t<main>\n"
|
||||
"\t\t<section>\n"
|
||||
"%3$s"
|
||||
"%9$s"
|
||||
"\t\t\t<div class=\"footer\"><a href=\"https://%7$s/\">%7$s</a> - " SERVER_STR_HTML "</div>\n"
|
||||
"\t\t</section>\n"
|
||||
"%8$s"
|
||||
"\t</main>\n"
|
||||
"</body>\n"
|
||||
"</html>\n";
|
||||
const int http_statuses_size = sizeof(http_statuses) / sizeof(http_status);
|
||||
const int http_status_messages_size = sizeof(http_status_messages) / sizeof(http_status_msg);
|
||||
|
||||
const char http_proxy_document[] =
|
||||
"\t\t<section class=\"error-ctx\">\n"
|
||||
"\t\t\t<div class=\"box%1$s\">\n"
|
||||
"\t\t\t\t<div class=\"content\">\n"
|
||||
"\t\t\t\t\t<span>Client</span>\n"
|
||||
"\t\t\t\t\t<img src=\"data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHBhdGggZD0iTTIsMzIgYTMwLDMwLDAsMSwwLDYwLDAgYTMwLDMwLDAsMSwwLC02MCww"
|
||||
"IEw2MiwzMiBNNiwxNiBMNTgsMTYgTTYsNDggTDU4LDQ4IE0zMiwyIEwzMiw2MiBhMTUsMzAsMCwx"
|
||||
"LDAsMCwtNjAgYTE1LDMwLDAsMSwwLDAsNjAgWiIgc3Ryb2tlPSIjMDA4MDAwIiBzdHJva2Utd2lk"
|
||||
"dGg9IjIiIGZpbGw9IiMwMDAwMDAwMCIvPjwvc3ZnPgo=\"/>\n"
|
||||
"\t\t\t\t\t<span>Your Browser</span>\n"
|
||||
"\t\t\t\t</div>\n"
|
||||
"\t\t\t\t<div class=\"arrow request%2$s\"></div>\n"
|
||||
"\t\t\t</div>\n"
|
||||
"\t\t\t<div class=\"border%8$s\"></div>\n"
|
||||
"\t\t\t<div class=\"box%3$s\">\n"
|
||||
"\t\t\t\t<div class=\"content\">\n"
|
||||
"\t\t\t\t\t<span>Reverse Proxy</span>\n"
|
||||
"\t\t\t\t\t<h3>%10$03i</h3>\n"
|
||||
"\t\t\t\t\t<h4>%11$s</h4>\n"
|
||||
"\t\t\t\t\t<span>" SERVER_NAME "</span>\n"
|
||||
"\t\t\t\t</div>\n"
|
||||
"\t\t\t\t<div class=\"arrow request%4$s\"></div>\n"
|
||||
"\t\t\t\t<div class=\"arrow response%5$s\"></div>\n"
|
||||
"\t\t\t</div>\n"
|
||||
"\t\t\t<div class=\"border%9$s\"></div>\n"
|
||||
"\t\t\t<div class=\"box%6$s\">\n"
|
||||
"\t\t\t\t<div class=\"content\">\n"
|
||||
"\t\t\t\t\t<span>Server</span>\n"
|
||||
"\t\t\t\t\t<h3>%12$s</h3>\n"
|
||||
"\t\t\t\t\t<h4>%13$s</h4>\n"
|
||||
"\t\t\t\t\t<span>%14$s</span>\n"
|
||||
"\t\t\t\t</div>\n"
|
||||
"\t\t\t\t<div class=\"arrow response%7$s\"></div>\n"
|
||||
"\t\t\t</div>\n"
|
||||
"\t\t</section>\n";
|
||||
|
||||
const char http_error_document[] =
|
||||
"\t\t\t<h1>%1$i</h1>\n"
|
||||
"\t\t\t<h2>%2$s :(</h2>\n"
|
||||
"\t\t\t<p>%3$s</p>\n"
|
||||
"\t\t\t<p>%4$s</p>\n";
|
||||
const char http_error_doc[] =
|
||||
" <h1>%1$i</h1>\n"
|
||||
" <h2>%2$s :(</h2>\n"
|
||||
" <p>%3$s</p>\n"
|
||||
" <p>%4$s</p>\n";
|
||||
|
||||
const char http_error_icon[] =
|
||||
"\t<link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
" <link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHRleHQgeD0iNCIgeT0iMTIiIGZpbGw9IiNDMDAwMDAiIHN0eWxlPSJmb250LWZhbWls"
|
||||
"eTonQXJpYWwnLHNhbnMtc2VyaWYiPjooPC90ZXh0Pjwvc3ZnPgo=\"/>\n";
|
||||
|
||||
|
||||
const char http_warning_document[] =
|
||||
"\t\t\t<h1>%1$i</h1>\n"
|
||||
"\t\t\t<h2>%2$s :)</h2>\n"
|
||||
"\t\t\t<p>%3$s</p>\n"
|
||||
"\t\t\t<p>%4$s</p>\n";
|
||||
const char http_warning_doc[] =
|
||||
" <h1>%1$i</h1>\n"
|
||||
" <h2>%2$s :)</h2>\n"
|
||||
" <p>%3$s</p>\n"
|
||||
" <p>%4$s</p>\n";
|
||||
|
||||
const char http_warning_icon[] =
|
||||
"\t<link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
" <link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHRleHQgeD0iNCIgeT0iMTIiIGZpbGw9IiNFMEMwMDAiIHN0eWxlPSJmb250LWZhbWls"
|
||||
"eTonQXJpYWwnLHNhbnMtc2VyaWYiPjopPC90ZXh0Pjwvc3ZnPgo=\"/>\n";
|
||||
|
||||
|
||||
const char http_success_document[] =
|
||||
"\t\t\t<h1>%1$i</h1>\n"
|
||||
"\t\t\t<h2>%2$s :)</h2>\n"
|
||||
"\t\t\t<p>%3$s</p>\n"
|
||||
"\t\t\t<p>%4$s</p>\n";
|
||||
const char http_success_doc[] =
|
||||
" <h1>%1$i</h1>\n"
|
||||
" <h2>%2$s :)</h2>\n"
|
||||
" <p>%3$s</p>\n"
|
||||
" <p>%4$s</p>\n";
|
||||
|
||||
const char http_success_icon[] =
|
||||
"\t<link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
" <link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHRleHQgeD0iNCIgeT0iMTIiIGZpbGw9IiMwMDgwMDAiIHN0eWxlPSJmb250LWZhbWls"
|
||||
"eTonQXJpYWwnLHNhbnMtc2VyaWYiPjopPC90ZXh0Pjwvc3ZnPgo=\"/>\n";
|
||||
|
||||
|
||||
const char http_info_document[] =
|
||||
"\t\t\t<h1>%1$i</h1>\n"
|
||||
"\t\t\t<h2>%2$s :)</h2>\n"
|
||||
"\t\t\t<p>%3$s</p>\n"
|
||||
"\t\t\t<p>%4$s</p>\n";
|
||||
const char http_info_doc[] =
|
||||
" <h1>%1$i</h1>\n"
|
||||
" <h2>%2$s :)</h2>\n"
|
||||
" <p>%3$s</p>\n"
|
||||
" <p>%4$s</p>\n";
|
||||
|
||||
const char http_info_icon[] =
|
||||
"\t<link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
" <link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHRleHQgeD0iNCIgeT0iMTIiIGZpbGw9IiM2MDYwNjAiIHN0eWxlPSJmb250LWZhbWls"
|
||||
"eTonQXJpYWwnLHNhbnMtc2VyaWYiPjopPC90ZXh0Pjwvc3ZnPgo=\"/>\n";
|
||||
|
||||
const int http_statuses_size = sizeof(http_statuses);
|
||||
const int http_status_messages_size = sizeof(http_status_messages);
|
||||
|
28
src/lib/res.h
Normal file
28
src/lib/res.h
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* sesimos - secure, simple, modern web server
|
||||
* @brief HTTP resources (header file)
|
||||
* @file src/lib/res.h
|
||||
* @author Lorenz Stechauner
|
||||
* @date 2022-12-31
|
||||
*/
|
||||
|
||||
#ifndef SESIMOS_RES_H
|
||||
#define SESIMOS_RES_H
|
||||
|
||||
#define http_default_doc _binary_bin_res_default_txt_start
|
||||
#define http_default_doc_size ((unsigned int) (_binary_bin_res_default_txt_end - _binary_bin_res_default_txt_start) - 1)
|
||||
#define http_proxy_doc _binary_bin_res_proxy_txt_start
|
||||
#define http_proxy_doc_size ((unsigned int) (_binary_bin_res_proxy_txt_end - _binary_bin_res_proxy_txt_start) - 1)
|
||||
#define http_style_doc _binary_bin_res_style_txt_start
|
||||
#define http_style_doc_size ((unsigned int) (_binary_bin_res_style_txt_end - _binary_bin_res_style_txt_start) - 1)
|
||||
|
||||
extern const char _binary_bin_res_default_txt_start[];
|
||||
extern const char _binary_bin_res_default_txt_end[];
|
||||
|
||||
extern const char _binary_bin_res_proxy_txt_start[];
|
||||
extern const char _binary_bin_res_proxy_txt_end[];
|
||||
|
||||
extern const char _binary_bin_res_style_txt_start[];
|
||||
extern const char _binary_bin_res_style_txt_end[];
|
||||
|
||||
#endif //SESIMOS_RES_H
|
@ -14,6 +14,7 @@
|
||||
#include "../lib/utils.h"
|
||||
#include "../lib/websocket.h"
|
||||
#include "../server.h"
|
||||
#include "../lib/res.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
@ -128,6 +129,15 @@ static int request_handler(client_ctx_t *ctx) {
|
||||
logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
||||
info(BLD_STR "%s %s", req->method, req->uri);
|
||||
|
||||
if (strcmp(req->uri, "/.sesimos/style.css") == 0 && (strcmp(req->method, "GET") == 0 || strcmp(req->method, "HEAD") == 0)) {
|
||||
memcpy(ctx->msg_buf, http_style_doc, http_style_doc_size);
|
||||
ctx->content_length = http_style_doc_size;
|
||||
res->status= http_get_status(200);
|
||||
http_add_header_field(&res->hdr, "Content-Type", "text/css; charset=UTF-8");
|
||||
http_add_header_field(&res->hdr, "Cache-Control", "public, max-age=3600");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx->conf = get_host_config(ctx->req_host);
|
||||
if (ctx->conf == NULL) {
|
||||
info("Unknown host, redirecting to default");
|
||||
@ -228,14 +238,14 @@ int respond(client_ctx_t *ctx) {
|
||||
http_add_header_field(&res->hdr, "Content-Type", "text/html; charset=UTF-8");
|
||||
|
||||
// TODO list Locations on 3xx Redirects
|
||||
const http_doc_info *info = http_get_status_info(res->status);
|
||||
const http_doc_info *http_info = http_get_status_info(res->status);
|
||||
const http_status_msg *http_msg = http_get_error_msg(res->status);
|
||||
|
||||
if (ctx->msg_content[0] == 0) {
|
||||
if (res->status->code >= 300 && res->status->code < 400) {
|
||||
const char *location = http_get_header_field(&res->hdr, "Location");
|
||||
if (location != NULL) {
|
||||
snprintf(ctx->msg_content, sizeof(ctx->msg_content), "<ul>\n\t<li><a href=\"%s\">%s</a></li>\n</ul>\n", location, location);
|
||||
snprintf(ctx->msg_content, sizeof(ctx->msg_content), " <ul>\n <li><a href=\"%s\">%s</a></li>\n </ul>\n", location, location);
|
||||
}
|
||||
}
|
||||
} else if (strncmp(ctx->msg_content, "<!DOCTYPE html>", 15) == 0 || strncmp(ctx->msg_content, "<html", 5) == 0) {
|
||||
@ -248,28 +258,29 @@ int respond(client_ctx_t *ctx) {
|
||||
const http_status *status_hdr = http_get_status(status->status);
|
||||
char stat_str[8];
|
||||
sprintf(stat_str, "%03i", status->status);
|
||||
sprintf(msg_pre_buf_2, http_proxy_document,
|
||||
snprintf(msg_pre_buf_2, sizeof(msg_pre_buf_2), http_proxy_doc,
|
||||
" success",
|
||||
(status->origin == CLIENT_REQ) ? " error" : " success",
|
||||
(status->origin == INTERNAL) ? " error" : " success",
|
||||
(status->origin == INTERNAL) ? " error" : " success",
|
||||
(status->origin == SERVER_REQ) ? " error" : (status->status == 0 ? "" : " success"),
|
||||
(status->origin == CLIENT_RES) ? " error" : " success",
|
||||
(status->origin == SERVER) ? " error" : (status->status == 0 ? "" : " success"),
|
||||
(status->origin == SERVER) ? " error" : (status->status == 0 ? "" : " success"),
|
||||
(status->origin == SERVER_RES) ? " error" : (status->status == 0 ? "" : " success"),
|
||||
(status->origin == INTERNAL) ? " error" : " success",
|
||||
(status->origin == INTERNAL) ? " error" : " success",
|
||||
(status->origin == INTERNAL || status->origin == SERVER) ? " error" : " success",
|
||||
res->status->code,
|
||||
res->status->msg,
|
||||
(status->status == 0) ? "???" : stat_str,
|
||||
(status_hdr != NULL) ? status_hdr->msg : "",
|
||||
ctx->req_host);
|
||||
ctx->req_host, SERVER_NAME);
|
||||
proxy_doc = msg_pre_buf_2;
|
||||
}
|
||||
|
||||
sprintf(msg_pre_buf_1, info->doc, res->status->code, res->status->msg, http_msg != NULL ? http_msg->msg : "", err_msg[0] != 0 ? err_msg : "");
|
||||
ctx->content_length = snprintf(ctx->msg_buf, sizeof(ctx->msg_buf), http_default_document, res->status->code,
|
||||
res->status->msg, msg_pre_buf_1, info->mode, info->icon, info->color, ctx->req_host,
|
||||
proxy_doc, ctx->msg_content[0] != 0 ? ctx->msg_content : "");
|
||||
snprintf(msg_pre_buf_1, sizeof(msg_pre_buf_1), http_info->doc,
|
||||
res->status->code, res->status->msg, http_msg != NULL ? http_msg->msg : "", err_msg[0] != 0 ? err_msg : "");
|
||||
ctx->content_length = snprintf(ctx->msg_buf, sizeof(ctx->msg_buf), http_default_doc, res->status->code,
|
||||
res->status->msg, msg_pre_buf_1, http_info->mode, http_info->icon, http_info->color, ctx->req_host,
|
||||
proxy_doc, ctx->msg_content[0] != 0 ? ctx->msg_content : "", SERVER_STR_HTML);
|
||||
}
|
||||
if (ctx->content_length >= 0) {
|
||||
sprintf(buf0, "%li", ctx->content_length);
|
||||
|
Reference in New Issue
Block a user