From e9a95c2c543b51d362d9122d892f8ecab7891b33 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Wed, 18 Jun 2025 02:00:52 +0200 Subject: [PATCH] Include 'running since' in the footer --- build.c | 8 +++++--- main.c | 3 +++ routes.c | 13 +++++++++++++ timer.c | 24 ++++++++++++++++++++++++ timer.h | 7 +++++++ tmpls/blog.html | 1 + tmpls/home.html | 1 + tmpls/page-missing.html | 1 + tmpls/template-blog.html | 1 + 9 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 timer.c create mode 100644 timer.h diff --git a/build.c b/build.c index 58481c5..b84254e 100644 --- a/build.c +++ b/build.c @@ -20,7 +20,9 @@ int main(int argc, char ** argv) "./baked.c", "./baked.h", "./clonestr.h", - "./commit.h" + "./commit.h", + "./timer.c", + "./timer.h", "./mongoose.o", "./gpp1", @@ -82,13 +84,13 @@ int main(int argc, char ** argv) #if DEBUG 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", - "./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", "-lpthread"); #else CMD("cc", "-fPIC", "-I.", "-D_GNU_SOURCE", "-DGEBS_NO_PREFIX", "-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", "-lpthread"); #endif diff --git a/main.c b/main.c index 82932a9..c36217b 100644 --- a/main.c +++ b/main.c @@ -9,6 +9,7 @@ #include "routes.h" #include "baked.h" +#include "timer.h" Route *route_hashtable = NULL; @@ -109,6 +110,8 @@ void init_route_hashtable(void) int main(int argc, char ** argv) { + start_timer(); + init_baked_resources(); mg_log_set(MG_LL_DEBUG); diff --git a/routes.c b/routes.c index 5175398..f4d474d 100644 --- a/routes.c +++ b/routes.c @@ -7,6 +7,7 @@ #include "baked.h" #include "clonestr.h" #include "commit.h" +#include "timer.h" #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)); + char timer[100]; + get_timer_string(timer, sizeof(timer)); + list_append(&env, fmt("-DRUNNING_SINCE=%s", timer)); #if DEBUG list_append(&env, "-DHOTRELOAD=1"); @@ -197,6 +201,9 @@ ROUTE_HANDLER(home) } 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 list_append(&env, "-DHOTRELOAD=1"); @@ -231,6 +238,9 @@ ROUTE_HANDLER(generic_blog) } 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 list_append(&env, "-DHOTRELOAD=1"); @@ -319,6 +329,9 @@ ROUTE_HANDLER(blog) } 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 list_append(&env, "-DHOTRELOAD=1"); diff --git a/timer.c b/timer.c new file mode 100644 index 0000000..f73a872 --- /dev/null +++ b/timer.c @@ -0,0 +1,24 @@ +#include +#include +#include + +#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); +} + diff --git a/timer.h b/timer.h new file mode 100644 index 0000000..979da7b --- /dev/null +++ b/timer.h @@ -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_ diff --git a/tmpls/blog.html b/tmpls/blog.html index 0e0f44c..8804156 100644 --- a/tmpls/blog.html +++ b/tmpls/blog.html @@ -18,6 +18,7 @@
HOME COMMIT: <#COMMIT> + Running since: <#RUNNING_SINCE>
diff --git a/tmpls/home.html b/tmpls/home.html index 292c54c..37ecead 100644 --- a/tmpls/home.html +++ b/tmpls/home.html @@ -49,6 +49,7 @@
HOME COMMIT: <#COMMIT> + Running since: <#RUNNING_SINCE>
diff --git a/tmpls/page-missing.html b/tmpls/page-missing.html index 402fa00..e662fb3 100644 --- a/tmpls/page-missing.html +++ b/tmpls/page-missing.html @@ -13,6 +13,7 @@
HOME COMMIT: <#COMMIT> + Running since: <#RUNNING_SINCE>
diff --git a/tmpls/template-blog.html b/tmpls/template-blog.html index ff4b235..2d3df88 100644 --- a/tmpls/template-blog.html +++ b/tmpls/template-blog.html @@ -11,6 +11,7 @@
HOME COMMIT: <#COMMIT> + Running since: <#RUNNING_SINCE>