I lost 4 hours of sleep over this lmao
Signed-off-by: sneedium <sneed@sneedmc.org>
This commit is contained in:
parent
c5f62b53d7
commit
3bd01a8c29
19
LICENSE
19
LICENSE
@ -686,6 +686,23 @@ an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
18. NIGGER Notice.
|
||||
|
||||
The above copyright notice, this permission notice and the word
|
||||
"NIGGER" shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
19. Farmer Notice.
|
||||
|
||||
This program is farmer software: it is free to be redistributed and/or
|
||||
modified by farmers. Redistribution and/or modification of the Software
|
||||
by city slickers is strictly prohibited.
|
||||
|
||||
20. Dwarf Notice.
|
||||
|
||||
I am a dwarf and I'm digging a hole, diggy diggy hole, I'm digging a hole.
|
||||
If this is not literally you, you cannot use this software.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
@ -713,7 +730,7 @@ the "copyright" line and a pointer to where the full notice is found.
|
||||
Affero Giant Sneed License for more details.
|
||||
|
||||
You should have received a copy of the Affero Giant Sneed License
|
||||
along with this program. If not, see <https://agsl.licenses.sneedmc.org>.
|
||||
along with this program. If not, see <https://agsl-nfd.licenses.sneedmc.org>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
|
6
Makefile
6
Makefile
@ -1,7 +1,6 @@
|
||||
prefix=/usr/local
|
||||
confdir=/etc
|
||||
systemd_dir=${DESTDIR}${confdir}/systemd/system
|
||||
nginx_dir=${DESTDIR}${confdir}/nginx
|
||||
bindir=${DESTDIR}${prefix}/bin
|
||||
|
||||
CC := gcc
|
||||
@ -22,9 +21,6 @@ clean:
|
||||
$(BIN): $(OBJ)
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
install-nginx:
|
||||
@install -Dm644 doc/gsl.nginx ${nginx_dir}/sites-available/gsl
|
||||
|
||||
install-systemd:
|
||||
@install -Dm644 doc/gsl.service ${systemd_dir}/gsl.service
|
||||
@install -Dm644 doc/gsl.conf ${DESTDIR}/${confdir}/gsl.conf
|
||||
@ -32,4 +28,4 @@ install-systemd:
|
||||
install-bin:
|
||||
@install -Dm755 ${BIN} ${bindir}/${BIN}
|
||||
|
||||
install: install-bin install-nginx install-systemd
|
||||
install: install-bin install-systemd
|
||||
|
3
doc/gsl.conf
Normal file
3
doc/gsl.conf
Normal file
@ -0,0 +1,3 @@
|
||||
BIN="/usr/bin/gsl"
|
||||
# replace this with the path to clink (usually /usr/local/bin/clink by default)
|
||||
PORT=33368
|
10
doc/gsl.service
Normal file
10
doc/gsl.service
Normal file
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=serve gsl
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=/etc/gsl.conf
|
||||
ExecStart=/bin/sh -c '${BIN} -p ${PORT}'
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
88
index.h
88
index.h
@ -1,63 +1,31 @@
|
||||
const char *INDEX_HTML = // FIXME: Change this to licenses.sneedmc.org index. Maybe dynamically generate some crap
|
||||
const char *INDEX_HTML =
|
||||
"\r\n"
|
||||
"<!DOCTYPE html>\r\n"
|
||||
"<html lang=en>\r\n"
|
||||
" <head>\r\n"
|
||||
" <title>A Minimal, Filesystem-Backed URL Shortener</title>\r\n"
|
||||
" <meta charset='utf-8'>\r\n"
|
||||
" <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>\r\n"
|
||||
" <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>\r\n"
|
||||
" <meta name='viewport' content='width=device-width, initial-scale=1'>\r\n"
|
||||
" <meta content='A super simple, minimal, and filesystem-backed URL Shortener.' name='description'>\r\n"
|
||||
" </head>\r\n"
|
||||
" <body style='font-family: monospace; max-width: 80ch;'>\r\n"
|
||||
"\r\n"
|
||||
"<header>\r\n"
|
||||
"A Minimal, Filesystem-Backed URL Shortener\r\n"
|
||||
"</header>\r\n"
|
||||
"\r\n"
|
||||
"<style>\r\n"
|
||||
"@media (max-width: 1000px) {\r\n"
|
||||
" pre code {\r\n"
|
||||
" display: block;\r\n"
|
||||
" max-width: 100%%;\r\n"
|
||||
" overflow-x: auto;\r\n"
|
||||
" -webkit-overflow-scrolling: touch;\r\n"
|
||||
" padding: 0 5px 5px 0;\r\n"
|
||||
" }\r\n"
|
||||
"}\r\n"
|
||||
"</style>\r\n"
|
||||
"\r\n"
|
||||
"<pre><code>Examples:\r\n"
|
||||
" 1. Create a short link to https://duckduckgo.com\r\n"
|
||||
" $ curl -d https://duckduckgo.com %s\r\n"
|
||||
" %s/502fb5543c36014f\r\n"
|
||||
"\r\n"
|
||||
" 2. Create a short link with a custom path\r\n"
|
||||
" $ curl -d https://duckduckgo.com %s/ddg\r\n"
|
||||
" %s/ddg\r\n"
|
||||
"\r\n"
|
||||
" 3. Create a short link to https://duckduckgo.com using a query string\r\n"
|
||||
" $ curl %s?https://duckduckgo.com\r\n"
|
||||
" %s/1acd382417199d7e\r\n"
|
||||
"\r\n"
|
||||
" 4. Create a short link with a custom path using a query string\r\n"
|
||||
" $ curl %s/ddg?https://duckduckgo.com\r\n"
|
||||
" %s/ddg\r\n"
|
||||
"\r\n"
|
||||
" 5. Deleting a short link\r\n"
|
||||
" $ TMP=$(mktemp)\r\n"
|
||||
" $ LINK=$(curl -sS %s -d https://duckduckgo.com -D $TMP)\r\n"
|
||||
" $ # Link created, headers stored in temp file\r\n"
|
||||
" $ DEL=$(cat $TMP | grep -i delete-with | awk '{print$2}'| tr -d '\\r')\r\n"
|
||||
" $ # Gets the deletion key, in the 'X-Delete-With' header\r\n"
|
||||
" $ curl $LINK\r\n"
|
||||
" <a href="https://duckduckgo.com">Permanent Redirect</a>.\r\n"
|
||||
" $ curl $LINK -X DELETE -d $DEL\r\n"
|
||||
" $ curl $LINK\r\n"
|
||||
" this short link does not exist\r\n"
|
||||
" $ # Link has been deleted</code></pre>\r\n"
|
||||
"\r\n"
|
||||
"<footer style='white-space: pre;'>Source code: <a href='https://short.swurl.xyz/src'>short.swurl.xyz/src</a></a>\r\n"
|
||||
"</footer>\r\n"
|
||||
"<html>\r\n"
|
||||
" <head>\r\n"
|
||||
" <title>The Giant Sneed Licenses</title>\r\n"
|
||||
" <meta property=\"og:title\" content=\"The Giant Sneed Licenses\">\r\n"
|
||||
" <meta property=\"og:url\" content=\"https://licenses.sneedmc.org\">\r\n"
|
||||
" <meta property=\"og:description\" content=\"The only licenses you'll ever sneed.\">\r\n"
|
||||
" <meta property=\"og:site_name\" content=\"SneedMC\">\r\n"
|
||||
" <meta property=\"og:type\" content=\"website\">\r\n"
|
||||
" <meta property=\"og:image\" content=\"https://licenses.sneedmc.org/favicon.ico\">\r\n"
|
||||
" </head>\r\n"
|
||||
" <body>\r\n"
|
||||
" <h1>Giant Sneed Licenses</h1>\r\n"
|
||||
" <p>The only licenses you'll ever sneed.</p>\r\n"
|
||||
" <p>Sneed. That is all. Also included is a very large penis.</p>\r\n"
|
||||
" <h2>Licenses available</h2>\r\n"
|
||||
" <ul>\r\n"
|
||||
" <li><a href=\"https://gsl.licenses.sneedmc.org\">GSL</a></li>\r\n"
|
||||
" <li><a href=\"https://agsl.licenses.sneedmc.org\">AGSL</a></li>\r\n"
|
||||
" <li><a href=\"https://lgsl.licenses.sneedmc.org\">LGSL</a></li>\r\n"
|
||||
" <li><a href=\"https://gslf.licenses.sneedmc.org\">GSL + Farmer Notice</a></li>\r\n"
|
||||
" <li><a href=\"https://agslf.licenses.sneedmc.org\">AGSL + Farmer Notice</a></li>\r\n"
|
||||
" <li><a href=\"https://lgslf.licenses.sneedmc.org\">LGSL + Farmer Notice</a></li>\r\n"
|
||||
" </ul>\r\n"
|
||||
" <h2>Credits</h2>\r\n"
|
||||
" <p><a href=\"https://sneedmc.org\">sneed</a></p>\r\n"
|
||||
" </body>\r\n"
|
||||
"</html>\r\n";
|
||||
|
||||
|
15
main.c
15
main.c
@ -15,8 +15,6 @@
|
||||
|
||||
char *port = "33368"; // sneed, backwards, in phone number, with the last number changed to 8 cuz sneedmc.org is already on 33367
|
||||
|
||||
static struct mg_http_serve_opts s_http_server_opts;
|
||||
|
||||
void trim(char *str) {
|
||||
char *_str = str;
|
||||
int len = strlen(_str);
|
||||
@ -87,10 +85,6 @@ bool eq(const char *s1, const char *s2, int n) {
|
||||
}
|
||||
|
||||
void handle_url_req(struct mg_connection *nc, char *host, char *link) {
|
||||
if (strncmp(link, "favicon.ico", 12) == 0) {
|
||||
mg_http_reply(nc, 404, "", "Not Found"); // FIXME: sneed cube.
|
||||
return;
|
||||
}
|
||||
char *a_host = strdup(host);
|
||||
char **host_elements = str_split(a_host, '.');
|
||||
|
||||
@ -98,7 +92,7 @@ void handle_url_req(struct mg_connection *nc, char *host, char *link) {
|
||||
|
||||
if (arrlen(host_elements) == 3) {
|
||||
// FIXME: index.html goes here.
|
||||
return mg_http_reply(nc, 200, "Content-Type: text/html\r\n", "Sneed\r\n");
|
||||
return mg_http_reply(nc, 200, "Content-Type: text/html\r\n", "%s\r\n", INDEX_HTML);
|
||||
}
|
||||
|
||||
char *b_host = strdup(host_elements[0]);
|
||||
@ -152,7 +146,7 @@ void handle_url_req(struct mg_connection *nc, char *host, char *link) {
|
||||
}
|
||||
}
|
||||
|
||||
mg_http_reply(nc, 200, "", license, output_clauses[0], output_clauses[1], output_clauses[2], host);
|
||||
mg_http_reply(nc, 200, "Content-Type: text/plain; charset=utf-8\r\n", license, output_clauses[0], output_clauses[1], output_clauses[2], host);
|
||||
|
||||
free(host_elements);
|
||||
free(host_clauses);
|
||||
@ -185,6 +179,11 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p, void *f) {
|
||||
snprintf(host, mhost.len + 1, "%s", mhost.ptr);
|
||||
|
||||
if (strncmp(hm->method.ptr, "GET", hm->method.len) == 0){
|
||||
if (eq(uri, "favicon.ico", 12) || eq(uri, "sneedcube.png", 14)) {
|
||||
struct mg_http_serve_opts opts = {.root_dir = "/srv/gsl"}; // Serve local dir
|
||||
if (ev == MG_EV_HTTP_MSG) mg_http_serve_dir(nc, p, &opts);
|
||||
return;
|
||||
}
|
||||
handle_url_req(nc, host, uri);
|
||||
} else {
|
||||
mg_http_reply(nc, 405, "Allow: GET\r\n", "");
|
||||
|
6933
mongoose.c
6933
mongoose.c
File diff suppressed because it is too large
Load Diff
1110
mongoose.h
1110
mongoose.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user