[MOD] Import PNG media.

This commit is contained in:
LDA 2024-08-31 13:16:58 +02:00
commit 1f3d738bb4
12 changed files with 87 additions and 42 deletions

View file

@ -19,7 +19,6 @@ ASUpload(const ParseeConfig *c, Stream *from, unsigned int size, char *mime)
HashMap *reply;
if (!c || !from)
{
Log(LOG_ERR, "No ASUpload input (c=%p from=%p)", c, from);
return NULL;
}

View file

@ -224,8 +224,9 @@ Main(Array *args, HashMap *env)
}
Log(LOG_NOTICE, "Starting up local cronjobs...");
cron = CronCreate( 10 SECONDS );
CronEvery(cron, 5 MINUTES, ParseeCleanup, conf.handlerArgs);
cron = CronCreate( 30 MINUTES );
CronEvery(cron, 1 HOURS, ParseeCleanup, conf.handlerArgs);
ParseeCleanup(conf.handlerArgs);
CronStart(cron);

View file

@ -13,6 +13,7 @@ ComputeKPad(char *key, uint8_t pad, uint8_t *kopad)
{
size_t klen;
uint8_t *kp;
uint8_t kpi[64] = { 0 };
size_t i;
if ((klen = strlen(key)) <= 64)
{
@ -25,14 +26,16 @@ ComputeKPad(char *key, uint8_t pad, uint8_t *kopad)
klen = 32;
}
memset(kpi, 0x00, 64);
memcpy(kpi, kp, klen);
Free(kp);
/* Now that we have K', lets compute it XORd with opad */
for (i = 0; i < 64; i++)
{
uint8_t byte = i < klen ? kp[i] : 0x00;
uint8_t byte = kpi[i];
kopad[i] = byte ^ pad;
}
Free(kp);
}
char *

View file

@ -23,8 +23,8 @@ RouteHead(RouteMedia, arr, argp)
params = HttpRequestParams(args->ctx);
hmac = HashMapGet(params, "hmac");
/* TODO: Make it check the DB for its validicity. "Purging" would be useful.
*/
/* TODO: Make it check the DB for its validicity. "Purging" would be
* useful, alongside checking if someone isn't just a little idiotic. */
{
char *concat = StrConcat(3, server, "/", identi);
chkmak = ParseeHMACS(args->data->id, concat);
@ -32,12 +32,18 @@ RouteHead(RouteMedia, arr, argp)
}
if (!server || !identi || !hmac || !StrEquals(hmac, chkmak))
{
char *err =
hmac && StrEquals(hmac, chkmak) ?
"No server/identifier/HMAC code" :
"Hah! You _dirty_ little liar! Try a little harder!";
Free(chkmak);
HttpResponseStatus(args->ctx, HTTP_BAD_REQUEST);
return MatrixCreateError("M_NOT_YET_UPLOADED", "No server/identifier");
return MatrixCreateError("M_NOT_YET_UPLOADED", err);
}
Free(chkmak);
/* Proxy the media through an authenticated endpoint if the HMAC
* is valid. */
server = HttpUrlEncode(server);
identi = HttpUrlEncode(identi);
path = StrConcat(4, "/_matrix/media/v3/download/", server, "/", identi);

View file

@ -76,6 +76,7 @@ RouteHead(RouteRoot, arr, argp)
{
P("<title>%s Lander</title>", NAME);
P("<meta charset='UTF-8'/>");
P("<link rel='icon' href='data:image/png;base64,%s'/>", media_parsee_logo);
P("<style>");
{
P("html {");
@ -83,6 +84,15 @@ RouteHead(RouteRoot, arr, argp)
P("color: #eee;");
P("font-family: sans-serif;");
P("}");
P("#cols {");
P("column-count: 3;");
P("min-width: 100%;");
P("max-width: 100%;");
P("width: 100%;");
P("}");
P("img {");
P("image-rendering: pixelated;");
P("}");
P("blockquote {");
P("border-left: 2px solid #ccc;");
P("margin: 1.5em 10px;");
@ -105,9 +115,9 @@ RouteHead(RouteRoot, arr, argp)
P("<body>");
{
P("<center><h1>");
P("Your %s is running, all with that %s!", NAME, CODE);
P("</h1></center>");
P("<center>");
P("<h1>Your %s is running, all with that %s!</h1>", NAME, CODE);
P("</center>");
P("<hr/>");
P("<blockquote><i>");
{

View file

@ -97,6 +97,9 @@ typedef struct Argument {
#define MB * 1024 KB
#define GB * 1024 MB
/* A base64-encoded Parsee logo */
extern const char media_parsee_logo[];
/** Generates a valid, getopt-style argument list from a end-terminated
* argument list.
* ------------