aboutsummaryrefslogtreecommitdiffstats
path: root/service
diff options
context:
space:
mode:
Diffstat (limited to 'service')
-rw-r--r--service/Dockerfile18
-rw-r--r--service/docker-compose.yml8
-rwxr-xr-xservice/entrypoint.sh9
-rw-r--r--service/src/.gitignore2
-rw-r--r--service/src/Makefile6
-rw-r--r--service/src/cat5
-rw-r--r--service/src/printdoc.c134
-rw-r--r--service/src/stlfile.c4
-rw-r--r--service/src/stlfile.h10
9 files changed, 196 insertions, 0 deletions
diff --git a/service/Dockerfile b/service/Dockerfile
new file mode 100644
index 0000000..68a3d9f
--- /dev/null
+++ b/service/Dockerfile
@@ -0,0 +1,18 @@
+FROM ubuntu:18.04
+
+RUN apt update && apt install -y --no-install-recommends socat
+
+RUN addgroup --system service
+RUN adduser --system --ingroup service --uid 1000 service
+
+RUN mkdir /data
+
+COPY entrypoint.sh /
+RUN chmod +x /entrypoint.sh
+
+COPY src/ /service/
+
+WORKDIR /service/
+EXPOSE 9000
+
+ENTRYPOINT ["/entrypoint.sh"]
diff --git a/service/docker-compose.yml b/service/docker-compose.yml
new file mode 100644
index 0000000..5a7dcd6
--- /dev/null
+++ b/service/docker-compose.yml
@@ -0,0 +1,8 @@
+version: '1'
+services:
+ printdoc:
+ build: .
+ volumes:
+ - ./data/:/data:rw
+ ports:
+ - "2323:8000"
diff --git a/service/entrypoint.sh b/service/entrypoint.sh
new file mode 100755
index 0000000..5445e3e
--- /dev/null
+++ b/service/entrypoint.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+set -e
+set -x
+
+# Chown the mounted data volume
+chown -R service:service "/data/"
+
+# Launch our service as user 'service'
+exec su -s /bin/sh -c 'PYTHONUNBUFFERED=1 python3 n0t3b00k.py' service \ No newline at end of file
diff --git a/service/src/.gitignore b/service/src/.gitignore
new file mode 100644
index 0000000..4620e7e
--- /dev/null
+++ b/service/src/.gitignore
@@ -0,0 +1,2 @@
+printdoc
+*.o
diff --git a/service/src/Makefile b/service/src/Makefile
new file mode 100644
index 0000000..d3c81bc
--- /dev/null
+++ b/service/src/Makefile
@@ -0,0 +1,6 @@
+
+%.o: %.c %.h
+ $(CC) -c -o $@ $< -I .
+
+printdoc: printdoc.c stlfile.o
+ $(CC) -o $@ $< $(CFLAGS) $(LDLIBS)
diff --git a/service/src/cat b/service/src/cat
new file mode 100644
index 0000000..aab4a8b
--- /dev/null
+++ b/service/src/cat
@@ -0,0 +1,5 @@
+
+ /\_/\ [ENO] _
+ = u u =_______| \\ < GET THE FLAG! ;)
+ _ w __( \__))
+ c_____>__(_____)__,
diff --git a/service/src/printdoc.c b/service/src/printdoc.c
new file mode 100644
index 0000000..93b1f97
--- /dev/null
+++ b/service/src/printdoc.c
@@ -0,0 +1,134 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+#include "stlfile.h"
+
+#define ARRSIZE(x) (sizeof(x)/sizeof((x)[0]))
+
+struct command {
+ const char *name;
+ void (*func)();
+};
+
+void request_info();
+void parse_file();
+void cat_flag();
+void list_commands();
+
+struct command commands[] = {
+ { "request", request_info },
+ { "info", parse_file },
+ { "cat", cat_flag },
+ { "ls", list_commands },
+};
+
+const char*
+ask(const char *fmtstr, ...)
+{
+ static char linebuf[256];
+ va_list ap;
+
+ va_start(ap, fmtstr);
+ vprintf(fmtstr, ap);
+ va_end(ap);
+
+ fgets(linebuf, sizeof(linebuf), stdin);
+
+ return linebuf;
+}
+
+void*
+die(const char *fmtstr, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmtstr);
+ vfprintf(stderr, fmtstr, ap);
+ va_end(ap);
+
+ exit(EXIT_FAILURE);
+}
+
+void
+request_info()
+{
+ const char *bufp;
+ char *end, *contents;
+ int len;
+
+ bufp = ask("How large is your file?\n");
+ len = strtoul(bufp, &end, 10);
+ if (!len || *end || len < 7000)
+ die("Invalid file length!\n");
+
+ printf("Ok! Im listening..\n");
+ contents = malloc(len);
+ read(STDIN_FILENO, contents, len);
+
+ printf("I got: %s\n", contents);
+
+ free(contents);
+}
+
+void
+parse_file()
+{
+ printf("hi\n");
+}
+
+void
+cat_flag()
+{
+ FILE *f;
+ char catbuf[256];
+ int nb;
+
+ f = fopen("cat", "r");
+ nb = fread(catbuf, 1, sizeof(catbuf), f);
+ fclose(f);
+
+ printf("%.*s\n", nb, catbuf);
+}
+
+void
+list_commands()
+{
+ int i;
+
+ printf("Available commands:\n");
+ for (i = 0; i < ARRSIZE(commands); i++)
+ printf("%s%s", i ? " " : "", commands[i].name);
+ printf("\n");
+}
+
+int
+main()
+{
+ char linebuf[256], *cp;
+ int exit, i;
+
+ exit = 0;
+ while (!exit) {
+ memset(linebuf, ' ', sizeof(linebuf));
+
+ printf("$ ");
+ exit = !fgets(linebuf, sizeof(linebuf), stdin);
+ if (exit || !*linebuf) break;
+
+ if (*linebuf == '\n') continue;
+ linebuf[strlen(linebuf) - 1] = '\0';
+
+ cp = strchr(linebuf, ' ');
+ if (cp) *cp = 0;
+ for (i = 0; i < ARRSIZE(commands); i++) {
+ if (!strcmp(commands[i].name, linebuf)) {
+ commands[i].func();
+ break;
+ }
+ }
+ }
+
+ printf("see you later!\n");
+}
diff --git a/service/src/stlfile.c b/service/src/stlfile.c
new file mode 100644
index 0000000..37a3a0a
--- /dev/null
+++ b/service/src/stlfile.c
@@ -0,0 +1,4 @@
+#include "stlfile.h"
+
+
+
diff --git a/service/src/stlfile.h b/service/src/stlfile.h
new file mode 100644
index 0000000..307c7c4
--- /dev/null
+++ b/service/src/stlfile.h
@@ -0,0 +1,10 @@
+#ifndef STLFILE_H
+#define STLFILE_H
+
+#include <stdlib.h>
+#include <string.h>
+
+
+
+
+#endif // STLFILE_H