From 4f164ddc67a8757ec7e6b8e4026383091993e241 Mon Sep 17 00:00:00 2001 From: swirl Date: Sat, 25 Sep 2021 17:54:58 -0400 Subject: [PATCH] add -k option --- .gitignore | 2 ++ main.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a54ecf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +pacebin diff --git a/main.c b/main.c index d3c0b1f..0f16285 100644 --- a/main.c +++ b/main.c @@ -13,6 +13,7 @@ char *port = "8081"; char *data_dir = "/srv/pacebin"; char *seed = "secret"; +char *proto = "http://"; static struct mg_http_serve_opts s_http_server_opts; @@ -129,7 +130,7 @@ void handle_post(struct mg_connection *nc, char *content, char *host, char *link char *del_header = malloc(256); sprintf(del_header, "X-Delete-With: %s\r\n", del_key); - mg_http_reply(nc, 201, del_header, "http://%s/%s", host, short_link); + mg_http_reply(nc, 201, del_header, "%s%s/%s", proto, host, short_link); } void handle_delete(struct mg_connection *nc, char *link, char *del_key) { @@ -187,7 +188,7 @@ int main(int argc, char *argv[]) { opterr = 0; setvbuf(stdout, NULL, _IONBF, 0); - while ((c = getopt (argc, argv, "p:d:s:h")) != -1) { + while ((c = getopt (argc, argv, "p:d:s:kh")) != -1) { switch (c) { case 'p': port = optarg; @@ -198,13 +199,17 @@ int main(int argc, char *argv[]) { case 's': seed = optarg; break; + case 'k': + proto = "https://"; + break; case 'h': printf("pacebin: a minimal pastebin\n"); - printf("usage: %s [-p port] [-d data_dir] [-s seed]\n\n", argv[0]); + printf("usage: %s [-p port] [-d data_dir] [-s seed] [-k]\n\n", argv[0]); printf("options:\n"); printf("-p \t\tport to use (default 8081)\n"); printf("-d \tdirectory to store data (default /srv/pacebin)\n"); - printf("-s \t\tsecret seed to use (DO NOT SHARE THIS; default 'secret')\n\n"); + printf("-s \t\tsecret seed to use (DO NOT SHARE THIS; default 'secret')\n"); + printf("-k\t\t\treturns HTTPS URLs when uploading files, use with an HTTPS-enabled reverse proxy\n\n"); printf("source: https://short.swurl.xyz/pacebin (submit bug reports, suggestions, etc. here)\n"); return 0; case '?':