Include 'running since' in the footer

This commit is contained in:
kamkow1
2025-06-18 02:00:52 +02:00
parent a90517c4da
commit e9a95c2c54
9 changed files with 56 additions and 3 deletions

View File

@ -20,7 +20,9 @@ int main(int argc, char ** argv)
"./baked.c", "./baked.c",
"./baked.h", "./baked.h",
"./clonestr.h", "./clonestr.h",
"./commit.h" "./commit.h",
"./timer.c",
"./timer.h",
"./mongoose.o", "./mongoose.o",
"./gpp1", "./gpp1",
@ -82,13 +84,13 @@ int main(int argc, char ** argv)
#if DEBUG #if DEBUG
CMD("cc", "-fPIC", "-ggdb", "-I.", "-DDEBUG=1", "-D_GNU_SOURCE", "-DGEBS_NO_PREFIX", CMD("cc", "-fPIC", "-ggdb", "-I.", "-DDEBUG=1", "-D_GNU_SOURCE", "-DGEBS_NO_PREFIX",
"-DINCBIN_PREFIX=", "-DINCBIN_STYLE=INCBIN_STYLE_SNAKE", "-Wl,-z,execstack", "-o", "./aboba", "-DINCBIN_PREFIX=", "-DINCBIN_STYLE=INCBIN_STYLE_SNAKE", "-Wl,-z,execstack", "-o", "./aboba",
"./main.c", "./routes.c", "./baked.c", "./mongoose.o", "./cJSON/cJSON.c", "./main.c", "./routes.c", "./baked.c", "./timer.c", "./mongoose.o", "./cJSON/cJSON.c",
"./md5-c/md5.c", "./md5-c/md5.c",
"-lpthread"); "-lpthread");
#else #else
CMD("cc", "-fPIC", "-I.", "-D_GNU_SOURCE", "-DGEBS_NO_PREFIX", CMD("cc", "-fPIC", "-I.", "-D_GNU_SOURCE", "-DGEBS_NO_PREFIX",
"-DINCBIN_PREFIX=", "-DINCBIN_STYLE=INCBIN_STYLE_SNAKE", "-Wl,-z,execstack", "-o", "./aboba", "-DINCBIN_PREFIX=", "-DINCBIN_STYLE=INCBIN_STYLE_SNAKE", "-Wl,-z,execstack", "-o", "./aboba",
"./main.c", "./routes.c", "./baked.c", "./mongoose.o", "./cJSON/cJSON.c", "./main.c", "./routes.c", "./baked.c", "./timer.c", "./mongoose.o", "./cJSON/cJSON.c",
"./md5-c/md5.c", "./md5-c/md5.c",
"-lpthread"); "-lpthread");
#endif #endif

3
main.c
View File

@ -9,6 +9,7 @@
#include "routes.h" #include "routes.h"
#include "baked.h" #include "baked.h"
#include "timer.h"
Route *route_hashtable = NULL; Route *route_hashtable = NULL;
@ -109,6 +110,8 @@ void init_route_hashtable(void)
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
start_timer();
init_baked_resources(); init_baked_resources();
mg_log_set(MG_LL_DEBUG); mg_log_set(MG_LL_DEBUG);

View File

@ -7,6 +7,7 @@
#include "baked.h" #include "baked.h"
#include "clonestr.h" #include "clonestr.h"
#include "commit.h" #include "commit.h"
#include "timer.h"
#define INTERNAL_SERVER_ERROR_MSG "Internal server error ;(. Try again later..." #define INTERNAL_SERVER_ERROR_MSG "Internal server error ;(. Try again later..."
@ -108,6 +109,9 @@ ROUTE_HANDLER(page_not_found)
} }
list_append(&env, fmt("-DCOMMIT=%s", COMMIT_STRING)); list_append(&env, fmt("-DCOMMIT=%s", COMMIT_STRING));
char timer[100];
get_timer_string(timer, sizeof(timer));
list_append(&env, fmt("-DRUNNING_SINCE=%s", timer));
#if DEBUG #if DEBUG
list_append(&env, "-DHOTRELOAD=1"); list_append(&env, "-DHOTRELOAD=1");
@ -197,6 +201,9 @@ ROUTE_HANDLER(home)
} }
list_append(&env, fmt("-DCOMMIT=%s", COMMIT_STRING)); list_append(&env, fmt("-DCOMMIT=%s", COMMIT_STRING));
char timer[100];
get_timer_string(timer, sizeof(timer));
list_append(&env, fmt("-DRUNNING_SINCE=%s", timer));
#if DEBUG #if DEBUG
list_append(&env, "-DHOTRELOAD=1"); list_append(&env, "-DHOTRELOAD=1");
@ -231,6 +238,9 @@ ROUTE_HANDLER(generic_blog)
} }
list_append(&env, fmt("-DCOMMIT=%s", COMMIT_STRING)); list_append(&env, fmt("-DCOMMIT=%s", COMMIT_STRING));
char timer[100];
get_timer_string(timer, sizeof(timer));
list_append(&env, fmt("-DRUNNING_SINCE=%s", timer));
#if DEBUG #if DEBUG
list_append(&env, "-DHOTRELOAD=1"); list_append(&env, "-DHOTRELOAD=1");
@ -319,6 +329,9 @@ ROUTE_HANDLER(blog)
} }
list_append(&env, fmt("-DCOMMIT=%s", COMMIT_STRING)); list_append(&env, fmt("-DCOMMIT=%s", COMMIT_STRING));
char timer[100];
get_timer_string(timer, sizeof(timer));
list_append(&env, fmt("-DRUNNING_SINCE=%s", timer));
#if DEBUG #if DEBUG
list_append(&env, "-DHOTRELOAD=1"); list_append(&env, "-DHOTRELOAD=1");

24
timer.c Normal file
View File

@ -0,0 +1,24 @@
#include <time.h>
#include <stddef.h>
#include <stdio.h>
#include "timer.h"
time_t rawtime;
void start_timer(void)
{
time(&rawtime);
}
void get_timer_string(char *output, size_t size)
{
struct tm * timeinfo;
timeinfo = localtime(&rawtime);
snprintf(output, size, "[%02d %02d %d %02d:%02d:%02d]", timeinfo->tm_mday,
timeinfo->tm_mon + 1, timeinfo->tm_year + 1900,
timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
}

7
timer.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef TIMER_H_
#define TIMER_H_
void start_timer(void);
void get_timer_string(char *output, size_t size);
#endif // TIMER_H_

View File

@ -18,6 +18,7 @@
<div style="float: left;"> <div style="float: left;">
<a href="/">HOME</a> <a href="/">HOME</a>
<span>COMMIT: <#COMMIT></span> <span>COMMIT: <#COMMIT></span>
<span>Running since: <#RUNNING_SINCE></span>
</div> </div>
</footer> </footer>

View File

@ -49,6 +49,7 @@
<div style="float: left;"> <div style="float: left;">
<a href="/">HOME</a> <a href="/">HOME</a>
<span>COMMIT: <#COMMIT></span> <span>COMMIT: <#COMMIT></span>
<span>Running since: <#RUNNING_SINCE></span>
</div> </div>
</footer> </footer>

View File

@ -13,6 +13,7 @@
<div style="float: left;"> <div style="float: left;">
<a href="/">HOME</a> <a href="/">HOME</a>
<span>COMMIT: <#COMMIT></span> <span>COMMIT: <#COMMIT></span>
<span>Running since: <#RUNNING_SINCE></span>
</div> </div>
</footer> </footer>

View File

@ -11,6 +11,7 @@
<div style="float: left;"> <div style="float: left;">
<a href="/">HOME</a> <a href="/">HOME</a>
<span>COMMIT: <#COMMIT></span> <span>COMMIT: <#COMMIT></span>
<span>Running since: <#RUNNING_SINCE></span>
</div> </div>
</footer> </footer>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>