From c6653e6113f9ed6211029b51dbdb8220c8cdc845 Mon Sep 17 00:00:00 2001 From: "Arthur K." Date: Fri, 19 Dec 2025 16:48:22 +0300 Subject: [PATCH] =?UTF-8?q?=D1=85=D0=BE=D0=B7=D1=8F=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0:=20=D0=BE=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7?= =?UTF-8?q?=D0=B8=D1=80=D1=83=D0=B9=D1=82=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BA=D0=B5=D1=80=D0=B0,=20=D1=83=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D1=82=D0=B5=20=D1=85=D0=B0=D1=80=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=B5=D1=80=D1=8B=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=B0=D1=80=D0=B5=D1=82=D0=BA=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +--- puppy/Dockerfile | 7 ++++++- puppy/app/main.cpp | 39 +++++++++++++++++++++++++++++--------- puppy/docker-entrypoint.sh | 3 +++ 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index b50f60d..f364d66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -.cache/ -/test build/ -cache/ +.cache/ cmake-build*/ compile_commands.json diff --git a/puppy/Dockerfile b/puppy/Dockerfile index 4e0ac0a..e7809d9 100644 --- a/puppy/Dockerfile +++ b/puppy/Dockerfile @@ -6,12 +6,16 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteracive apt-get install -y \ apt-get clean && rm -rf /var/lib/apt/lists/*; WORKDIR /build + +COPY app/healthcheck.cpp app/healthcheck.cpp +COPY include/httplib.hpp include/httplib.hpp +RUN g++ -o healthcheck -I./include ./app/healthcheck.cpp; + COPY app app COPY include include COPY src src COPY CMakeLists.txt . -RUN g++ -o healthcheck -I./include ./app/healthcheck.cpp; RUN --mount=type=cache,target=cmake-build cmake -B cmake-build \ -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ && cmake --build cmake-build -j$(nproc) && \ @@ -38,6 +42,7 @@ HEALTHCHECK CMD ./healthcheck; EXPOSE 80/tcp VOLUME /cache +STOPSIGNAL SIGINT COPY docker-entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] diff --git a/puppy/app/main.cpp b/puppy/app/main.cpp index 913dd92..b64480d 100644 --- a/puppy/app/main.cpp +++ b/puppy/app/main.cpp @@ -1,8 +1,11 @@ #include "httplib.hpp" +#include #include #include +#include #include +#include #include #include "PromtCtlDocument.hpp" @@ -10,9 +13,9 @@ static inline std::string random_filename(int len = 65) { static const char ASCII_PRINTABLE[] = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - std::random_device random_device; - std::mt19937 generator(random_device()); - std::uniform_int_distribution distribution(0, static_cast(strlen(ASCII_PRINTABLE) - 1)); + static std::random_device random_device; + static std::mt19937 generator(random_device()); + static std::uniform_int_distribution distribution(0, static_cast(strlen(ASCII_PRINTABLE) - 1)); std::string random_string; random_string.reserve(len); for (int i = 0; i < len; ++i) @@ -61,11 +64,20 @@ static inline auto read_file(const std::string &filename) { size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, 0, 0); std::string out; - out.resize(size); - WideCharToMultiByte(CP_UTF8, 0, wstr, -1, out.data(), size, 0, 0); + out.resize(size - 1); + WideCharToMultiByte(CP_UTF8, 0, wstr, -1, out.data(), size - 1, 0, 0); delete[] wstr; - return out; + std::string out_lf; + out_lf.reserve(out.size()); + + for (auto c : out) { + if (c == '\r') + continue; + out_lf.push_back(c); + } + + return out_lf; } class WebServer { @@ -160,7 +172,7 @@ class WebServer { } void listen(const char *host = "0.0.0.0", unsigned short port = 80) { - print("Started!"); + print("started!"); m_svr.listen(host, port); } @@ -171,12 +183,21 @@ class WebServer { } }; -int main() { - print("Starting..."); +static std::function signal_action; +void signal_handler(int signal) { + signal_action(signal); +} + +int main() { CoInitializeEx(NULL, COINIT_MULTITHREADED); CoInitializeSecurity(nullptr, -1, nullptr, nullptr, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IDENTIFY, nullptr, EOAC_NONE, nullptr); WebServer ws; + + signal_action = [&](int x) { ws.stop(); }; + std::signal(SIGTERM, signal_handler); + std::signal(SIGINT, signal_handler); + ws.listen(); } diff --git a/puppy/docker-entrypoint.sh b/puppy/docker-entrypoint.sh index 95049a5..5209beb 100755 --- a/puppy/docker-entrypoint.sh +++ b/puppy/docker-entrypoint.sh @@ -1,5 +1,8 @@ #!/bin/bash +echo 'initializing wine...' wineboot -i +echo 'copying registy values...' wine regedit $WINEPREFIX/drive_c/registry.reg +echo 'starting...' exec wine /app/promt-puppy.exe