X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/ebd170a764ab9660adee464588cda1801c7986b4..37324ea9b8c06d96b9383be993da02a01f103253:/projects/stargazer/plugins/other/radius/radius.cpp?ds=sidebyside diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 3ec0f705..78c80b4d 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -1,4 +1,13 @@ #include "radius.h" +#include "server.h" +#include "radproto/error.h" + +#include "stg/common.h" + +#include +#include +#include +#include //uint8_t, uint32_t using STG::RADIUS; @@ -14,6 +23,57 @@ std::string RADIUS::GetVersion() const } RADIUS::RADIUS() + : m_logger(PluginLogger::get("radius")), + m_running(false) +{ +} + +int RADIUS::Start() +{ + m_thread = std::jthread([this](auto token){ Run(std::move(token)); }); + return 0; +} + +int RADIUS::Stop() +{ + if (!m_thread.joinable()) + return 0; + + m_thread.request_stop(); + + m_thread.join(); + return 0; +} + +void RADIUS::SetRunning(bool val) +{ + const std::lock_guard lock(m_mutex); + m_running = val; +} + +bool RADIUS::IsRunning() { + const std::lock_guard lock(m_mutex); + return m_running; } +int RADIUS::Run(std::stop_token token) +{ + SetRunning(true); + + try + { + boost::asio::io_service ioService; + Server server(ioService, "secret", 1812, "/usr/share/freeradius/dictionary"); + ioService.run(); + } + catch (const std::exception& e) + { + m_errorStr = "Exception in RADIUS::Run(): " + std::string(e.what()); + m_logger("Exception in RADIUS:: Run(): %s", e.what()); + printfd(__FILE__, "Exception in RADIUS:: Run(). Message: '%s'\n", e.what()); + } + + SetRunning(false); + return 0; +}