From a8f375bede6c397ae99558df3265a0f603f3dfd5 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Fri, 25 Jun 2021 17:13:56 +0200 Subject: large refactor of checker, added more havocs to test listing and search, added motd to service welcome banner --- service/src/main.c | 60 +++++++++++++++++++++++++++++++++++++----------- service/src/msgs/banner | 4 ++++ service/src/msgs/motd | 15 ++++++++++++ service/src/msgs/welcome | 6 ----- service/src/stlfile.c | 14 ++++------- service/src/stlfile.h | 4 ++-- 6 files changed, 71 insertions(+), 32 deletions(-) create mode 100644 service/src/msgs/banner create mode 100644 service/src/msgs/motd delete mode 100644 service/src/msgs/welcome (limited to 'service') diff --git a/service/src/main.c b/service/src/main.c index 4b28637..5d99fc1 100644 --- a/service/src/main.c +++ b/service/src/main.c @@ -128,7 +128,7 @@ handle_download(const char *scandir) fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); - if (size > MAXFILESIZE) { + if (size >= MAXFILESIZE) { ERR("File is too large!\n"); goto fail; } @@ -149,6 +149,31 @@ fail: goto exit; } +void +motd() +{ + char linebuf[80]; + int msgc, msgi, i; + FILE *f; + + if (!(f = fopen("msgs/motd", "r"))) return; + + if (!fgets(linebuf, sizeof(linebuf), f)) + goto exit; + + srand(time(NULL)); + if ((msgc = atoi(linebuf))) { + msgi = rand() % msgc; + for (i = 0; i < msgi + 1; i++) + if (!fgets(linebuf, sizeof(linebuf), f)) + return; + printf("%s\n", linebuf); + } + +exit: + fclose(f); +} + void cat_cmd(const char *arg) { @@ -193,34 +218,41 @@ echo_cmd(const char *arg) void upload_cmd(const char *arg) { + char *end, *contents, *modelname; const char *resp; - char *end, *contents; size_t len; + modelname = checkp(strdup(ask("Enter a model name: "))); + if (!strlen(modelname)) { + ERR("Empty model names are not allowed"); + goto exit; + } + resp = ask("How large is your file? "); len = strtoul(resp, &end, 10); if (len <= 0 || len >= MAXFILESIZE || *end) { ERR("Invalid file length!\n"); - return; + goto exit; } printf("Ok! Im listening..\n"); contents = checkp(malloc(len + 1)); if (fread(contents, 1, len, stdin) != len) { ERR("Not enough data received!\n"); - goto cleanup; + goto exit; } contents[len] = '\0'; - if ((cached.valid = parse_file(&cached, contents, len))) { + if ((cached.valid = parse_file(&cached, contents, len, &modelname))) { if (save_submission(&cached, contents, len) != OK) ERR("Failed to save your submission!\n"); else printf("Your file was saved with ID %s!\n", cached.hash); } -cleanup: +exit: free(contents); + free(modelname); } void @@ -264,7 +296,7 @@ search_cmd(const char *arg) if (pathc == 0) { ERR("Couldn't find a matching scan result!\n"); - goto cleanup; + goto exit; } while (1) { @@ -273,15 +305,15 @@ search_cmd(const char *arg) which = strtoul(resp, &end, 10); if (which >= pathc || which < 0 || *end) { ERR("Invalid index!\n"); - goto cleanup; + goto exit; } scandir = aprintf("%s/%s", resultdir, paths[which]); - if (handle_download(scandir) != OK) goto cleanup; + if (handle_download(scandir) != OK) goto exit; FREE(scandir); } -cleanup: +exit: FREE(scandir); for (i = 0; i < pathc; i++) free(paths[i]); @@ -355,7 +387,6 @@ auth_cmd(const char *arg) void cleanexit() { - printf("see you later!\n"); free_info(&cached); free(resultdir); } @@ -364,8 +395,8 @@ int main() { const char *cmd, *envstr; - char *cp, *arg; int exit, i, cmdlen; + char *cp, *arg; if (!(envstr = getenv("RESULTDIR"))) die("RESULTDIR not defined\n"); @@ -378,12 +409,13 @@ main() atexit(cleanexit); - dump("msgs/welcome"); + dump("msgs/banner"); + motd(); exit = 0; while (!exit) { errno = 0; - cmd = ask("$ "); + cmd = ask("\r$ "); if (!*cmd && errno == EBADMSG) break; if (!*cmd) continue; diff --git a/service/src/msgs/banner b/service/src/msgs/banner new file mode 100644 index 0000000..bf73b22 --- /dev/null +++ b/service/src/msgs/banner @@ -0,0 +1,4 @@ + ┌─┐┌┬┐┬ ┌┬┐┌─┐┌─┐┌┬┐┌─┐┬─┐ ┬ + └─┐ │ │ │││ ││ │ │ │├┬┘ ▓ + └─┘ ┴ ┴─┘─┴┘└─┘└─┘ ┴ └─┘┴└─ │ + diff --git a/service/src/msgs/motd b/service/src/msgs/motd new file mode 100644 index 0000000..796f569 --- /dev/null +++ b/service/src/msgs/motd @@ -0,0 +1,15 @@ +13 + We analyze your STL files! + STL: Standard Triangle Language + STL: Standard Template Library + STL: Solid Tesselation Language + STL: Standard Telegraph Level + A file upload service (now in 3D!) + Keep your files small, size matters! + Use 'search' to find models by name! + ENO.. is a popular solid name! + STeaLing flags since 2006! + C4n y0u r34d th1s? 🏁 ➡️ 📁 + ( *ಥ ⌂ * ) dont pwn pls + *finds file* UwU whats this? + diff --git a/service/src/msgs/welcome b/service/src/msgs/welcome deleted file mode 100644 index ac75bb4..0000000 --- a/service/src/msgs/welcome +++ /dev/null @@ -1,6 +0,0 @@ - ┌─┐┌┬┐┬ ┌┬┐┌─┐┌─┐┌┬┐┌─┐┬─┐ ┬ - └─┐ │ │ │││ ││ │ │ │├┬┘ ▓ - └─┘ ┴ ┴─┘─┴┘└─┘└─┘ ┴ └─┘┴└─ │ - - We analyze your STL files! - diff --git a/service/src/stlfile.c b/service/src/stlfile.c index 8a4ba9a..bddb24f 100644 --- a/service/src/stlfile.c +++ b/service/src/stlfile.c @@ -310,7 +310,7 @@ fail: } int -parse_file(struct parseinfo *info, char *buf, size_t len) +parse_file(struct parseinfo *info, char *buf, size_t len, char **modelname) { int status; const char *resp; @@ -332,17 +332,11 @@ parse_file(struct parseinfo *info, char *buf, size_t len) : parse_file_bin(info, buf, len); if (status == FAIL) return FAIL; - if (!info->modelname) { - resp = ask("Please enter your model name: "); - if (strlen(resp) < 4) { - ERR("Model name is too short!\n"); - return FAIL; - } - info->modelname = checkp(strdup(resp)); - } - if (!info->solidname) info->solidname = checkp(strdup("")); + info->modelname = *modelname; + *modelname = NULL; + info->hash = checkp(strdup(mhash(info->modelname, -1))); return OK; diff --git a/service/src/stlfile.h b/service/src/stlfile.h index 76e138c..ed3a433 100644 --- a/service/src/stlfile.h +++ b/service/src/stlfile.h @@ -9,7 +9,7 @@ #include "util.h" -#define FMT_ERR(...) ERR("FORMAT " __VA_ARGS__) +#define FMT_ERR(...) printf("FORMAT ERR: " __VA_ARGS__) enum { KW_INVALID = -1, @@ -47,7 +47,7 @@ struct parseinfo { int type, valid; }; -int parse_file(struct parseinfo *info, char *buf, size_t len); +int parse_file(struct parseinfo *info, char *buf, size_t len, char **modelname); int save_info(struct parseinfo *info, FILE *f); int load_info(struct parseinfo *info, FILE *f); void print_info(struct parseinfo *info); -- cgit v1.2.3-71-gd317