diff --git a/src/service/core/smithproxy_objapi.cpp b/src/service/core/smithproxy_objapi.cpp index 528d7146..1b6c85c0 100644 --- a/src/service/core/smithproxy_objapi.cpp +++ b/src/service/core/smithproxy_objapi.cpp @@ -12,6 +12,52 @@ #include #include +void ObjAPI::for_each_proxy(std::function callable) { + auto const& instance = SmithProxy::instance(); + + auto lc_ = std::scoped_lock(socle::sobjectDB::getlock()); + + + auto list_worker = [callable](const char* title, auto& listener) { + for (auto const& acc: listener) { + for(auto const& wrk: acc->tasks()) { + + auto lc_ = std::scoped_lock(wrk.second->proxy_lock()); + + for(auto const& [ p, _ ] : wrk.second->proxies()) { + if(auto* proxy = dynamic_cast(p.get()); p != nullptr) { + callable(proxy); + } + } + } + } + }; + + list_worker("plain acceptor", instance.plain_proxies); + list_worker("tls acceptor", instance.ssl_proxies); + + list_worker("udp receiver", instance.udp_proxies); + list_worker("dtls receiver", instance.dtls_proxies); + + list_worker("socks acceptor", instance.socks_proxies); + + list_worker("plain redirect acceptor", instance.redir_plain_proxies); + list_worker("dns redirect receiver", instance.redir_udp_proxies); + list_worker("tls redirect acceptor", instance.redir_ssl_proxies); +} + +nlohmann::json ObjAPI::proxy_session_connid_list() { + + using nlohmann::json; + json ret; + + for_each_proxy([&ret](MitmProxy const* px){ + if(px) ret.push_back(px->to_connection_ID()); + }); + + return ret; +} + nlohmann::json ObjAPI::proxy_session_list_json(uint64_t oid, bool active_only, bool tls_info, bool verbose) { using nlohmann::json; auto const& instance = SmithProxy::instance(); diff --git a/src/service/core/smithproxy_objapi.hpp b/src/service/core/smithproxy_objapi.hpp index 7fc673e1..6efe7753 100644 --- a/src/service/core/smithproxy_objapi.hpp +++ b/src/service/core/smithproxy_objapi.hpp @@ -3,6 +3,11 @@ #include +class MitmMproxy; struct ObjAPI { + void for_each_proxy(std::function callable); + + nlohmann::json proxy_session_connid_list(); nlohmann::json proxy_session_list_json(uint64_t oid, bool active_only, bool tls_info, bool verbose); -}; \ No newline at end of file +}; + diff --git a/src/service/http/webhooks.cpp b/src/service/http/webhooks.cpp index bf3cae24..1493aed7 100644 --- a/src/service/http/webhooks.cpp +++ b/src/service/http/webhooks.cpp @@ -30,7 +30,8 @@ namespace sx::http::webhooks { nlohmann::json const ping = { { "action", "ping" }, {"source", get_hostid() }, - {"type", "proxy"} + {"type", "proxy"}, + {"proxies", SmithProxy::instance().API.proxy_session_connid_list() } }; sx::http::AsyncRequest::emit( to_string(ping),