diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index 9633526..e9bb19e 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -22,12 +22,11 @@ jobs: - uses: actions/checkout@v3 - name: Install various apt dependencies - run: sudo apt-get install libsqlite3-dev python3-pip libnghttp2-dev pkg-config libssl-dev liblua5.3-dev + run: sudo apt-get install libsqlite3-dev python3-pip libnghttp2-dev pkg-config libssl-dev liblua5.3-dev xxd - name: Install meson run: sudo pip3 install meson ninja - - name: Configure Meson # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type diff --git a/Dockerfile.full-build b/Dockerfile.full-build index 4505b93..c74b5b4 100644 --- a/Dockerfile.full-build +++ b/Dockerfile.full-build @@ -11,6 +11,7 @@ RUN apt-get update -yqq && apt-get install -yqq \ openssl \ libssl-dev \ zlib1g-dev \ + xxd \ libsqlite3-dev COPY . /src WORKDIR /src diff --git a/README.md b/README.md index 692e037..82eafa3 100644 --- a/README.md +++ b/README.md @@ -270,7 +270,7 @@ check the log with `journalctl -u simplomon.service` On Debian derived systems the following works: ``` -apt install python3-pip pkg-config libnghttp2-dev libssl-dev liblua5.3-dev +apt install python3-pip pkg-config libnghttp2-dev libssl-dev liblua5.3-dev xxd ``` In addition, the project requires a recent version of meson, which you can get with 'pip3 install meson ninja' or perhaps 'pip install diff --git a/meson.build b/meson.build index 16bf636..cb94712 100644 --- a/meson.build +++ b/meson.build @@ -70,7 +70,38 @@ doctest_dep=dependency('doctest') simplesockets_dep = dependency('simplesockets', static: true) # argparse_dep = dependency('argparse', version: '>=3') +prog_xxd = find_program('xxd') + +index_html_h = custom_target( + 'index_html.h', output : 'index_html.h', input : 'html/index.html', + command : [prog_xxd, '-i', '@INPUT@', '@OUTPUT@'], +) + +style_css_h = custom_target( + 'style_css.h', output : 'style_css.h', input : 'html/style.css', + command : [prog_xxd, '-i', '@INPUT@', '@OUTPUT@'], +) + +simplomon_ico_h = custom_target( + 'simplomon_ico.h', output : 'simplomon_ico.h', input : 'html/simplomon.ico', + command : [prog_xxd, '-i', '@INPUT@', '@OUTPUT@'], +) + +alpine_min_js_h = custom_target( + 'alpine_min_js.h', output : 'alpine_min_js.h', input : 'html/alpine.min.js', + command : [prog_xxd, '-i', '@INPUT@', '@OUTPUT@'], +) + +logic_js_h = custom_target( + 'logic_js.h', output : 'logic_js.h', input : 'html/logic.js', + command : [prog_xxd, '-i', '@INPUT@', '@OUTPUT@'], +) + + +webpages = [logic_js_h, alpine_min_js_h, simplomon_ico_h, style_css_h, index_html_h] + executable('simplomon', 'simplomon.cc', 'notifiers.cc', 'minicurl.cc', 'dnsmon.cc', 'record-types.cc', 'dnsmessages.cc', 'dns-storage.cc', 'netmon.cc', 'luabridge.cc', 'webservice.cc', 'support.cc', 'promon.cc', 'mailmon.cc', 'nonblocker.cc', +webpages, dependencies: [json_dep, fmt_dep, cpphttplib, simplesockets_dep, lua_dep, curl_dep, sqlite_dep, sqlitewriter_dep]) diff --git a/webservice.cc b/webservice.cc index d3da83f..32cf6d3 100644 --- a/webservice.cc +++ b/webservice.cc @@ -5,6 +5,11 @@ #include #include +#include "index_html.h" +#include "style_css.h" +#include "logic_js.h" +#include "alpine_min_js.h" +#include "simplomon_ico.h" using namespace std; static std::mutex s_lock; @@ -78,9 +83,8 @@ void updateWebService() } } -static void webserverThread(std::unique_ptr svr, string addr) +static void webserverThread(std::unique_ptr svr, ComboAddress ca) { - ComboAddress ca(addr, 8080); if(svr->listen(ca.toString(), ntohs(ca.sin4.sin_port))) { cout<<"Error launching server: "<empty()) goto fail; - if(B64Decode(auth.substr(6), dec)) goto fail; @@ -204,10 +207,26 @@ void startWebService(sol::table data) res.set_content(s_checkerstates.dump(), "application/json"); }); - svr->set_mount_point("/", "./html"); + svr->Get("/simplomon.ico", [](const auto& req, auto& res) { + res.set_content(string((const char*)___html_simplomon_ico, ___html_simplomon_ico_len), "image/x-icon"); + }); + svr->Get("/alpine.min.js", [](const auto& req, auto& res) { + res.set_content(string((const char*)___html_alpine_min_js, ___html_alpine_min_js_len), "application/javascript"); + }); + svr->Get("/logic.js", [](const auto& req, auto& res) { + res.set_content(string((const char*)___html_logic_js, ___html_logic_js_len), "application/javascript"); + }); + svr->Get("/style.css", [](const auto& req, auto& res) { + res.set_content(string((const char*)___html_style_css, ___html_style_css_len), "text/css"); + }); + svr->Get("/", [](const auto& req, auto& res) { + res.set_content(string((const char*)___html_index_html, ___html_index_html_len), "text/html"); + }); - - std::thread t(webserverThread, std::move(svr), data.get_or("address", string("0.0.0.0:8080"))); + string addr = data.get_or("address", string("0.0.0.0:8080")); + ComboAddress ca(addr, 8080); + fmt::print("Going to launch webserver on {}\n", ca.toStringWithPort()); + std::thread t(webserverThread, std::move(svr), ca); t.detach(); }