From 94daf8ad98b19afbd4320078b9d1ee25c9fb82f1 Mon Sep 17 00:00:00 2001 From: c+1 Date: Sun, 1 Sep 2024 21:48:56 -0400 Subject: Initial commit. Allows for the uploading of files. --- .gitignore | 2 ++ Makefile | 15 +++++++++++++++ config/config.php | 9 +++++++++ public/.htaccess | 10 ++++++++++ public/admin.php | 0 public/index.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ public/view.php | 0 util/src/id.c | 40 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 123 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 config/config.php create mode 100644 public/.htaccess create mode 100644 public/admin.php create mode 100644 public/index.php create mode 100644 public/view.php create mode 100644 util/src/id.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..27ae3b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.out +uploads/* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2294f74 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +serve: + cd public && php -S 0.0.0.0:8000 + +CC = gcc +CFLAGS = -Wall -fsanitize=leak + +all: util/id.out + +util/id.out: util/src/id.c + $(CC) $(CFLAGS) $< -o $@ -lssl -lcrypto + +clean: + rm -f util/*.out + +.PHONY: all clean serve diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..d6fcba7 --- /dev/null +++ b/config/config.php @@ -0,0 +1,9 @@ + diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..e46b2d9 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,10 @@ +RewriteEngine On + +RewriteCond %{REQUEST_URI} ^/$ [OR] +RewriteCond %{REQUEST_URI} ^/index\.php$ +RewriteRule ^(.*)$ /index.php [L] + +RewriteCond %{QUERY_STRING} ^v=([a-zA-Z0-9\_\-\~\!\*]{8})$ +RewriteRule ^$ /view.php?v=%1 [L,QSA] + +RewriteRule ^admin\.php$ /admin.php [L] diff --git a/public/admin.php b/public/admin.php new file mode 100644 index 0000000..e69de29 diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..f656154 --- /dev/null +++ b/public/index.php @@ -0,0 +1,47 @@ + $UPLOAD_MAX_SZ]) { + echo "File too large."; + } else { + if (move_uploaded_file($f['tmp_name'], $targetf)) { + $cmd = escapeshellcmd( + "$FILE_PROCESSING_CMD " . + escapeshellarg($targetf) + ); + + shell_exec($cmd); + echo "Uploaded."; + } else { + echo "Error uploading."; + } + } +} + +?> + + + + + + + i2 + + +

Upload File

+
+ + + +
+ + diff --git a/public/view.php b/public/view.php new file mode 100644 index 0000000..e69de29 diff --git a/util/src/id.c b/util/src/id.c new file mode 100644 index 0000000..48bed23 --- /dev/null +++ b/util/src/id.c @@ -0,0 +1,40 @@ +#include +#include +#include + +#define IDLN 8 +#define CHARSET \ + "abcdefghijklmnopqrstuvwxyz" \ + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ + "0123456789" \ + "-_!~" +#define CHARSETLN (sizeof(CHARSET) - 1) + +char* gen() { + char* id = malloc(IDLN + 1); + if (id == NULL) { + perror("malloc"); + exit(1); + } + + unsigned char buf[IDLN]; + if (RAND_bytes(buf, IDLN) != 1) { + perror("RAND_bytes"); + free(id); + exit(1); + } + + for ( + int i = 0; + i < IDLN || (id[IDLN] = '\0'); + id[i++] = CHARSET[buf[i] % CHARSETLN] + ); + + return id; +} + +int main(void) { + char* id = gen(); + printf("%s", id); + free(id); +} -- cgit v1.2.3