From 50e6f227a0a56a519311c894a0eb8f051bba78fb Mon Sep 17 00:00:00 2001 From: rasmus Date: Mon, 19 May 2025 22:44:13 +0200 Subject: [PATCH] Added docker support --- Dockerfile | 24 ++++++++++++++++++++++++ Makefile | 10 +++++----- include/Options.h | 1 + src/ServerUtils.cpp | 4 ++-- src/main.cpp | 20 +++++++++++--------- 5 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eb05ccf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM gcc:latest + +RUN apt update && apt install -y cmake + +WORKDIR /app + +#COPY a.png /app/ +#COPY content /app/ +#COPY wordlist /app/ +#COPY include /app/ +#COPY src /app/ +#COPY CMakeLists.txt /app/ + +COPY . /app/ + +RUN ls -lh . + +RUN cmake . +RUN make + +EXPOSE 8888 +EXPOSE 8889 + +CMD ["./tarpit", "wordlist/", "content/style.css", "content/images/", "a.png"] diff --git a/Makefile b/Makefile index 1ab4b0a..3b31db2 100644 --- a/Makefile +++ b/Makefile @@ -48,10 +48,10 @@ cmake_force: SHELL = /bin/sh # The CMake executable. -CMAKE_COMMAND = /usr/bin/cmake +CMAKE_COMMAND = "/home/skingging/Tar Apps/clion-2025.1.1/bin/cmake/linux/x64/bin/cmake" # The command to remove a file. -RM = /usr/bin/cmake -E rm -f +RM = "/home/skingging/Tar Apps/clion-2025.1.1/bin/cmake/linux/x64/bin/cmake" -E rm -f # Escaping for special characters. EQUALS = = @@ -67,8 +67,8 @@ CMAKE_BINARY_DIR = /home/skingging/Documents/Projects/CPP/AI-Tarpit-Reimagined # Special rule for the target edit_cache edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "Running CMake cache editor..." - /usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) + @$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "No interactive CMake dialog available..." + "/home/skingging/Tar Apps/clion-2025.1.1/bin/cmake/linux/x64/bin/cmake" -E echo No\ interactive\ CMake\ dialog\ available. .PHONY : edit_cache # Special rule for the target edit_cache @@ -78,7 +78,7 @@ edit_cache/fast: edit_cache # Special rule for the target rebuild_cache rebuild_cache: @$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "Running CMake to regenerate build system..." - /usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) + "/home/skingging/Tar Apps/clion-2025.1.1/bin/cmake/linux/x64/bin/cmake" --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) .PHONY : rebuild_cache # Special rule for the target rebuild_cache diff --git a/include/Options.h b/include/Options.h index f90ce2d..8d016c8 100644 --- a/include/Options.h +++ b/include/Options.h @@ -8,6 +8,7 @@ class Options { public: string word_lists; string images; + string favicon; string css; }; diff --git a/src/ServerUtils.cpp b/src/ServerUtils.cpp index 8c43040..2cd735c 100644 --- a/src/ServerUtils.cpp +++ b/src/ServerUtils.cpp @@ -94,11 +94,11 @@ void ServerUtils::process_request(const int client_fd) { } else if (url == "/favicon.png") { - send_image(client_fd, "/home/skingging/Documents/Projects/CPP/AI-Tarpit-Reimagined/a.png", PNG); + send_image(client_fd, options_.favicon, PNG); } else if (WordUtils::contains_image(url)) { - string p = "/home/skingging/Documents/Projects/CPP/AI-Tarpit-Reimagined/content/images/"; + string p = options_.images; p += WordUtils::extract_image_name(url); send_image(client_fd, p, AVIF); } diff --git a/src/main.cpp b/src/main.cpp index ca8cd15..afa13b3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,34 +14,36 @@ using namespace std; int main(const int argc, const char* argv[]) { Options options; - if (argc > 4) - { + if (argc > 5) { cout << "Too many arguments"; return 0; } - if (!FileUtils::fileExists(argv[1])) - { + if (!FileUtils::fileExists(argv[1])) { cout << "Filepath: " << argv[1] << " doesn't exist."; return 0; } options.word_lists = argv[1]; - if (!FileUtils::fileExists(argv[2])) - { + if (!FileUtils::fileExists(argv[2])) { cout << "Filepath: " << argv[2] << " doesn't exist."; return 0; } options.css = argv[2]; - if (!FileUtils::fileExists(argv[3])) - { + if (!FileUtils::fileExists(argv[3])) { cout << "Filepath: " << argv[3] << " doesn't exist."; return 0; } options.images = argv[3]; - cout << options.word_lists << " " << options.css << " " << options.images << " " << endl; + if (!FileUtils::fileExists(argv[4])) { + cout << "Filepath: " << argv[4] << " doesn't exist."; + return 0; + } + options.favicon = argv[4]; + + //cout << options.word_lists << " " << options.css << " " << options.images << " " << endl; auto queue = make_shared>(); auto metrics = make_shared>();