From b6bf3792d8dbb7b407dbfb6d8acf63ab1f733f15 Mon Sep 17 00:00:00 2001 From: Bartosz Wieczorek Date: Wed, 25 Jun 2025 19:44:13 +0200 Subject: [PATCH] Fix proxy for websockets --- PAM/ssh/include/rublon/websockets.hpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/PAM/ssh/include/rublon/websockets.hpp b/PAM/ssh/include/rublon/websockets.hpp index cd25cae..47ffbf9 100644 --- a/PAM/ssh/include/rublon/websockets.hpp +++ b/PAM/ssh/include/rublon/websockets.hpp @@ -42,13 +42,6 @@ class WebSocket { RublonEventData * currentEvent{nullptr}; std::pmr::string proxyUrl{}; - -// constexpr static const struct lws_protocol_vhost_options pvo = { -// NULL, /* "next" pvo linked-list / -// &pvo_proxy_uri, / "child" pvo linked-list / -// "push_protocol", / protocol name we belong to on this vhost / -// "" / ignored */ -// }; public: WebSocket(const Configuration & config) : _config{config}, urlv{_config.get().apiServer}, proxyUrl{_config.get().apiServer.get_allocator()} { @@ -70,7 +63,11 @@ class WebSocket { log(rlevel, "libwesockets: %s", line); }; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_INFO | LLL_DEBUG | LLL_HEADER, lws_log_emit); + if(_config.get().logging) { + lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_INFO | LLL_DEBUG | LLL_HEADER, lws_log_emit); + } else { + lws_set_log_level(LLL_ERR | LLL_WARN, lws_log_emit); + } memset(&info, 0, sizeof(info)); memset(&ccinfo, 0, sizeof(ccinfo)); @@ -78,15 +75,15 @@ class WebSocket { info.port = CONTEXT_PORT_NO_LISTEN; info.protocols = protocols; info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; - + if(cfg.proxyEnabled && (cfg.proxyType == "http" || cfg.proxyType == "https")) { assert(cfg.proxyType.has_value()); assert(cfg.proxyHost.has_value()); log(LogLevel::Debug, "WebSocket using proxy"); - + // "username:password\@server:port" - proxyUrl.reserve(conservative_estimate(cfg.proxyUsername, cfg.proxyPass, cfg.proxyHost) + 10); if(cfg.proxyAuthRequired) { + proxyUrl.reserve(conservative_estimate(cfg.proxyUsername, cfg.proxyPass, cfg.proxyHost) + 10); proxyUrl += *cfg.proxyUsername; proxyUrl += ":"; proxyUrl += *cfg.proxyPass; @@ -96,9 +93,9 @@ class WebSocket { proxyUrl += *cfg.proxyHost; log(LogLevel::Debug, "WebSocket proxy %s", proxyUrl.c_str()); info.http_proxy_address = proxyUrl.c_str(); - info.http_proxy_port = config.proxyPort.value_or(8080); + info.http_proxy_port = config.proxyPort.value_or(8080); } - + context = lws_create_context(&info); const std::string_view prefix = "https://";