bitreich-short

fork of git.z3bra.org/bitreich-short
git clone git://git.pyratebeard.net/bitreich-short.git
Log | Files | Refs | README | LICENSE

commit fcd6c934e0a00098016278527c53ea8305e479b6
parent 1d63bfa9303355b61925256bb06169e17e38f4f5
Author: Christoph Lohmann <20h@r-36.net>
Date:   Fri, 14 Aug 2020 00:27:57 +0200

Add favicon.gif support and cake hater denuciation.

Diffstat:
Mbitreich-httpd.c | 30+++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/bitreich-httpd.c b/bitreich-httpd.c @@ -11,6 +11,8 @@ #include <sys/stat.h> #include <fcntl.h> #include <string.h> +#include <sys/socket.h> +#include <netdb.h> void * xmalloc(size_t size) @@ -95,12 +97,27 @@ servefile(char *path, char *ctype, int sock) int main(int argc, char *argv[]) { - char *wwwbase, *wwwindex, request[512], *ctype, *path; + char *wwwbase, *wwwindex, request[512], *ctype, *path, + clienth[NI_MAXHOST], clientp[NI_MAXSERV]; int rlen; + struct sockaddr_storage clt; + socklen_t cltlen = sizeof(clt); wwwbase = "/bitreich/www"; wwwindex = "index.html"; + if (!getpeername(0, (struct sockaddr *)&clt, &cltlen)) { + if (getnameinfo((struct sockaddr *)&clt, cltlen, clienth, + sizeof(clienth), clientp, sizeof(clientp), + NI_NUMERICHOST|NI_NUMERICSERV)) { + clienth[0] = clientp[0] = '\0'; + } + if (!strncmp(clienth, "::ffff:", 7)) + memmove(clienth, clienth+7, strlen(clienth)-6); + } else { + clienth[0] = clientp[0] = '\0'; + } + rlen = read(0, request, sizeof(request)-1); if (rlen < 0) return 1; @@ -113,6 +130,17 @@ main(int argc, char *argv[]) if (strstr(request, "s/bitreich.sh")) { asprintf(&path, "%s/s/bitreich.sh", wwwbase); ctype = "text/plain"; + } else if (strstr(request, "favicon.gif")) { + asprintf(&path, "%s/s/favicon.gif", wwwbase); + ctype = "image/gif"; + } else if (strstr(request, "dickbutt")) { + asprintf(&path, + "/home/annna/bin/annna-say -c \"#bitreich-tv\" \"%s:%s cake hater appeared.\"", + clienth, clientp); + system(path); + free(path); + asprintf(&path, "%s/s/dickbutt.jpg", wwwbase); + ctype = "image/jpeg"; } else { asprintf(&path, "%s/%s", wwwbase, wwwindex); ctype = "text/html";