commit ebbe8918990c9625c23c85852ea4a7ed394850c8 Author: cynic Date: Thu Feb 17 11:48:22 2022 -0500 init~ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e16ae3f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +store/* \ No newline at end of file diff --git a/box.py b/box.py new file mode 100644 index 0000000..2667c4a --- /dev/null +++ b/box.py @@ -0,0 +1,35 @@ +import socket +from PIL import Image +from io import BytesIO +from hashlib import sha256 +from threading import Thread + +_PORT = 1337 + +def handle_conn(conn): + conn.sendall("hai~".encode("ascii")) + data = b"" + while True: + part = conn.recv(4096) + if not part: + break + data += part + try: + img = Image.open(BytesIO(data)) + except OSError: + conn.sendall("cannot parse image".encode("ascii")) + return + no_exif = Image.new(img.mode, img.size)# abandon metadata + no_exif.putdata(list(img.getdata())) + filename = f"store/{sha256(no_exif.tobytes()).hexdigest()}.{img.format.lower()}" + no_exif.save(filename) + conn.sendall(f"saved to {filename}".encode("ascii")) + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.bind(("0.0.0.0", _PORT)) + +s.listen() + +while True: + conn, conn_addr = s.accept() + Thread(target=handle_conn, args=(conn,)).start() diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..c195978 --- /dev/null +++ b/readme.txt @@ -0,0 +1,6 @@ +give your pictures to the box and they will be put in storage +you may take them out later through some other means if you ask nicely + +pv $FILENAME -p | nc $REMOTE 1337 -q 0 + +(seriously not great you should probably prefer a real protocol) \ No newline at end of file