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.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

3
main.c
View File

@ -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);

View File

@ -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");

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;">
<a href="/">HOME</a>
<span>COMMIT: <#COMMIT></span>
<span>Running since: <#RUNNING_SINCE></span>
</div>
</footer>

View File

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

View File

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

View File

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