mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:25:11 +00:00
This allows us to have commands apply to admins or MUCs only(which would help with many things I want to implement).
259 lines
7.8 KiB
C
259 lines
7.8 KiB
C
#include <Routes.h>
|
|
|
|
#include <Cytoplasm/Cytoplasm.h>
|
|
#include <Cytoplasm/Memory.h>
|
|
#include <Cytoplasm/Rand.h>
|
|
#include <Cytoplasm/Log.h>
|
|
|
|
#include <AS.h>
|
|
|
|
static bool
|
|
HasAdmin(ParseeData *data)
|
|
{
|
|
DbRef *admins;
|
|
HashMap *json;
|
|
bool ret = false;
|
|
|
|
admins = DbLock(data->db, 1, "admins");
|
|
if (!admins)
|
|
{
|
|
return false;
|
|
}
|
|
json = DbJson(admins);
|
|
ret = ArraySize(JsonValueAsArray(HashMapGet(json, "admins")));
|
|
|
|
DbUnlock(data->db, admins);
|
|
return ret;
|
|
}
|
|
|
|
static const char *
|
|
GetRandomQuote(void)
|
|
{
|
|
const char *quotes[] =
|
|
{
|
|
"Kinda jealous of that, to be fair.",
|
|
"*(noms)*",
|
|
"Why look inward when you can challenge the mainstream "
|
|
"media?",
|
|
"Boo!",
|
|
"[...] I can make up lots of reasons to attack you.",
|
|
"Go Kontribute to C99 projects!",
|
|
"We truly live in a " CODE "...",
|
|
"You truly lack the Desire Drive for this!",
|
|
"Eeh? Bifrost mode? Only bad servers use Bifrost mode!",
|
|
"'Wow parsee can save the world' - said a wise guy",
|
|
"As small as a dwarf, and can run on your pie!",
|
|
"It's all wicked unsafe, memory slow 🚀🚀🚀🚀",
|
|
|
|
"XMPP kinda sucks.",
|
|
"Matrix kinda sucks.",
|
|
|
|
"Throw jabs!",
|
|
"'Won't you hold my <presence/> safe?' - Kanako",
|
|
|
|
NAME ": the federated world's little little kobashi",
|
|
|
|
"Go take a look at your stanzas!",
|
|
"Go take a look at your objects!",
|
|
|
|
"DEC Alpha AXP-Certified!",
|
|
|
|
"this is the moment parsee started parsing or smth idk"
|
|
" - another wise person",
|
|
"Ah, merde, mon TGV est en retard de 53 minutes !"
|
|
};
|
|
const size_t count = sizeof(quotes)/sizeof(*quotes);
|
|
|
|
return quotes[RandInt(count) % count];
|
|
}
|
|
|
|
RouteHead(RouteRoot, arr, argp)
|
|
{
|
|
ParseeHttpArg *args = argp;
|
|
const ParseeConfig *config = args->data->config;
|
|
|
|
HttpResponseHeader(args->ctx, "Content-Type", "text/html");
|
|
HttpSendHeaders(args->ctx);
|
|
#define P(...) StreamPrintf(args->stream, __VA_ARGS__)
|
|
P("<!DOCTYPE html>");
|
|
P("<html lang='en'>");
|
|
{
|
|
P("<head>");
|
|
{
|
|
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 {");
|
|
P("background-color: #222;");
|
|
P("color: #eee;");
|
|
P("font-family: sans-serif;");
|
|
P("}");
|
|
P("#ascii {");
|
|
P("text-align: center;");
|
|
P("color: #be1337;");
|
|
P("}");
|
|
P("#ascii pre {");
|
|
P("display: inline-block;");
|
|
P("text-align: left;");
|
|
P("}");
|
|
P("img {");
|
|
P("image-rendering: pixelated;");
|
|
P("}");
|
|
P("blockquote {");
|
|
P("border-left: 2px solid #ccc;");
|
|
P("margin: 1.5em 10px;");
|
|
P("background: #444;");
|
|
P("padding: 0.5em;");
|
|
P("}");
|
|
P("blockquote p {");
|
|
P("display: inline-block;");
|
|
P("}");
|
|
P("a:visited {");
|
|
P("color: #bedead;");
|
|
P("}");
|
|
P("a:link {");
|
|
P("color: #fad;");
|
|
P("}");
|
|
}
|
|
P("</style>");
|
|
}
|
|
P("</head>");
|
|
|
|
P("<body>");
|
|
{
|
|
size_t i;
|
|
P("<center>");
|
|
P("<h1>Your %s is running, all with that %s!</h1>", NAME, CODE);
|
|
P("</center>");
|
|
P("<hr/>");
|
|
P("<blockquote><i>");
|
|
{
|
|
P("%s", GetRandomQuote());
|
|
}
|
|
P("</i></blockquote>");
|
|
P("<pre id='ascii'><code>");
|
|
for (i = 0; i < PARSEE_ASCII_LINES; i++)
|
|
{
|
|
XMLElement *e = XMLCreateText((char *) parsee_ascii[i]);
|
|
XMLEncode(args->stream, e);
|
|
XMLFreeElement(e);
|
|
P("<br/>");
|
|
}
|
|
P("</code></pre>");
|
|
|
|
P("<p>");
|
|
{
|
|
P("Welcome, sysadmin! ");
|
|
}
|
|
P("</p>");
|
|
|
|
P("<p>");
|
|
{
|
|
P("Your homeserver now can interact with the bridge, with ");
|
|
P("the generated YAML file and Jabber component shared ");
|
|
P("secret.");
|
|
}
|
|
P("</p>");
|
|
|
|
P("<p>");
|
|
{
|
|
char *mxid, *jid;
|
|
char *m_to;
|
|
|
|
mxid = ParseeMXID(args->data);
|
|
m_to = ParseeGenerateMTO(mxid);
|
|
jid = ParseeJID(args->data);
|
|
|
|
P("You may be interested in sending <code>!help</code> to ");
|
|
P("the Matrix <a href='%s'>%s bridge</a>, or pop out ", m_to, NAME);
|
|
P("<code>%s</code>'s command list on XMPP as a starter.", jid);
|
|
|
|
Free(mxid);
|
|
Free(m_to);
|
|
Free(jid);
|
|
}
|
|
P("</p>");
|
|
|
|
P("<p>");
|
|
{
|
|
P("More information available at ");
|
|
P("<a ");
|
|
P("href='https://kappach.at/parsee'");
|
|
P(">the actual page</a>.");
|
|
}
|
|
P("</p>");
|
|
|
|
P("<h2>Permissions?</h2>");
|
|
P("<p>");
|
|
{
|
|
const char *perms = !HasAdmin(args->data) ?
|
|
" <strong style='color: red;'>(which I know you do)</strong>" :
|
|
"";
|
|
|
|
P("If you have problems running commands%s, you may want to ", perms);
|
|
P("look into if you have set yourself as an admin.");
|
|
}
|
|
P("</p>");
|
|
|
|
P("<p>");
|
|
{
|
|
P("With a packaged and installed version of %s, ", NAME);
|
|
P("you may add an admin with ");
|
|
P("<code>parsee-adminify '%s' '[glob]'</code>. ", config->db_path);
|
|
P("Please see its manual page for more information.");
|
|
}
|
|
P("</p>");
|
|
|
|
P("<h2>Extra information</h2>");
|
|
P("<p>");
|
|
{
|
|
P("<h3>Dev documentations!!!!</h3>");
|
|
P("Developers may be interested into looking up the ");
|
|
P("<a href='https://at.kappach.at'>at.kappach.at</a> ");
|
|
P("page for extensions used by Parsee on Matrix and XMPP. ");
|
|
}
|
|
P("</p>");
|
|
|
|
P("<h3>Parsee statistics</h3>");
|
|
P("<p>");
|
|
{
|
|
const char *cyto_ver = CytoplasmGetVersionStr();
|
|
size_t alloc = MemoryAllocated();
|
|
P("<pre><code>");
|
|
P("Software: %s ", NAME);
|
|
P("(v%s [%s]/Cytoplasm %s)\n", VERSION, CODE, cyto_ver);
|
|
P("Cytoplasm heap used: %d B\n", alloc);
|
|
P("</code></pre>");
|
|
}
|
|
P("</p>");
|
|
|
|
P("<p>");
|
|
{
|
|
P("Some clicky links relating to %s:", NAME);
|
|
P("<ul>");
|
|
{
|
|
const char *fedi = "https://tengu.kappach.at/parsee";
|
|
const char *icon = "https://kappach.at/parsee.gif";
|
|
P("<li><a href='%s'>Repository</a></li>", REPOSITORY);
|
|
P("<li><a href='%s'>Fediverse</a></li>", fedi);
|
|
P("<li>CC0 88x31: <img src='%s' /></li>", icon);
|
|
}
|
|
P("</ul>");
|
|
}
|
|
P("</p>");
|
|
|
|
P("<blockquote><i>");
|
|
P("Good luck, and have fun! :D");
|
|
P("</i></blockquote>");
|
|
P("<p>— LDA</p>");
|
|
}
|
|
P("</body>");
|
|
}
|
|
P("</html>");
|
|
#undef P
|
|
|
|
(void) arr;
|
|
return NULL;
|
|
}
|