diff --git a/.gitignore b/.gitignore index 5141d98..c18856a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ cmake-build-debug cmake-build-release build +pkg # JetBrains IDEs .idea/ diff --git a/.vscode/launch.json b/.vscode/launch.json index 7d5acb9..ab59233 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,10 +2,10 @@ "version": "0.2.0", "configurations": [ { - "name": "Debug Crow App", + "name": "Debug Server Admin Panel", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/build/app", + "program": "${workspaceFolder}/build/lf-server-admin-panel", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/PKGBUILD b/PKGBUILD deleted file mode 100644 index f2c6fb1..0000000 --- a/PKGBUILD +++ /dev/null @@ -1,26 +0,0 @@ -# Maintainer: Lukas Forsberg lukas96.forsberg@gmail.com - -pkgname=lf-server-admin-panel -pkgver=0.1.0 -pkgrel=1 -arch=('x86_64') -depends=('crow' 'asio') -pkgdesc="A Linux C++ Crow/HTMX web service to list the status of user specified systemd services" -license=('MIT') -makedepends=('cmake' 'gcc') -source=( - ${pkgname}-${pkgver}.tar.gz -) -md5sums=('SKIP') # SKIP if local files -build() { - cd "$srcdir" - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr - make -} -package() { - install -Dm755 "$srcdir/${pkgname}" "$pkgdir/usr/bin/${pkgname}" - install -Dm644 "$srcdir/templates/index.html" "$pkgdir/usr/share/${pkgname}/templates/index.html" - install -Dm644 "$srcdir/static/htmx.min.js" "$pkgdir/usr/share/${pkgname}/static/htmx.min.js" - install -Dm644 "$srcdir/static/settings.json" "$pkgdir/usr/share/${pkgname}/static/settings.json" - install -Dm644 "$srcdir/lf-server-admin-panel.service" "$pkgdir/usr/lib/systemd/system/lf-server-admin-panel.service" -} \ No newline at end of file diff --git a/README.md b/README.md index 9d1b02c..c2e8ad4 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ run : F5 or Run → Start Debugging 1. tar the source files to make it cleaner ``` -tar czf lf-server-admin-panel-0.1.0.tar.gz src/ static/ templates/ lf-server-admin-panel.service CMakeLists.txt +tar czf pkg/lf-server-admin-panel-0.1.1.tar.gz src/ static/ templates/ lf-server-admin-panel.service CMakeLists.txt ``` 2. create the package ``` -makepkg -fL +makepkg -f ``` \ No newline at end of file diff --git a/src/json_settings.cpp b/src/json_settings.cpp index 0c3e4dd..16f9400 100644 --- a/src/json_settings.cpp +++ b/src/json_settings.cpp @@ -41,6 +41,12 @@ expected AppSettings::loadAppSettings() { return unexpected("'services' array in JSON file is empty"); } + if (j.contains("httpPort")) { + settings.httpPort = j["httpPort"].get(); + } else { + settings.httpPort = {}; + } + return settings; } diff --git a/src/json_settings.h b/src/json_settings.h index e92cd85..77a4a26 100644 --- a/src/json_settings.h +++ b/src/json_settings.h @@ -5,6 +5,7 @@ #include #include #include +#include struct Service { std::string name; @@ -17,6 +18,7 @@ struct AppSettings { std::optional getId(std::string_view name); std::vector services; + std::optional httpPort; }; #endif // JSON_SETTINGS_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index fc645cd..afca86d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "json_settings.h" #include "htmx_helper.h" @@ -68,5 +69,19 @@ int main() { return crow::response{row.htmx()}; }); - app.port(8080).multithreaded().run(); + const uint16_t defaultPort = 3010; + uint16_t httpPort = defaultPort; + + { + auto opt_settings = AppSettings::loadAppSettings(); + if (opt_settings.has_value()){ + auto& settings = opt_settings.value(); + httpPort = settings.httpPort.value_or(defaultPort); + } else { + CROW_LOG_ERROR << "failed to load settings : " << opt_settings.error(); + } + } + + app.loglevel(crow::LogLevel::INFO); + app.port(httpPort).multithreaded().run(); } diff --git a/static/server-settings.json b/static/server-settings.json new file mode 100644 index 0000000..d7a4cb3 --- /dev/null +++ b/static/server-settings.json @@ -0,0 +1,11 @@ +{ + "httpPort" : 3010, + "services": [ + ["Calibre", " calibre-server.service"], + ["File Server", "file-server.service"], + ["Jellyfin", "jellyfin.service"], + ["DuckDNS", "duckdns.service"], + ["Wiki.js", "wiki.service"], + ["qBitTorrent", "qbittorrent-nox@lukas.service"] + ] +} diff --git a/static/settings.json b/static/settings.json index c85f2c1..4a000d2 100644 --- a/static/settings.json +++ b/static/settings.json @@ -1,4 +1,5 @@ { + "httpPort" : 3010, "services": [ ["Cups", "cups.service"], ["Waydriod", "waydroid-container.service"]