diff --git a/src/confighttp.cpp b/src/confighttp.cpp index cc571bf2b27..44765d7ab3a 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -701,6 +701,28 @@ namespace confighttp { outputTree.put("status", true); } + void + listClients(resp_https_t response, req_https_t request) { + if (!authenticate(response, request)) return; + + print_req(request); + + pt::ptree named_certs = nvhttp::get_all_clients(); + + pt::ptree outputTree; + + outputTree.put("status", false); + + auto g = util::fail_guard([&]() { + std::ostringstream data; + pt::write_json(data, outputTree); + response->write(data.str()); + }); + + outputTree.add_child("named_certs", named_certs); + outputTree.put("status", true); + } + void closeApp(resp_https_t response, req_https_t request) { if (!authenticate(response, request)) return; @@ -746,6 +768,7 @@ namespace confighttp { server.resource["^/api/password$"]["POST"] = savePassword; server.resource["^/api/apps/([0-9]+)$"]["DELETE"] = deleteApp; server.resource["^/api/clients/unpair$"]["POST"] = unpairAll; + server.resource["^/api/clients/list$"]["GET"] = listClients; server.resource["^/api/apps/close$"]["POST"] = closeApp; server.resource["^/api/covers/upload$"]["POST"] = uploadCover; server.resource["^/images/sunshine.ico$"]["GET"] = getFaviconImage; diff --git a/src/nvhttp.cpp b/src/nvhttp.cpp index 663f59eecd3..382038b8682 100644 --- a/src/nvhttp.cpp +++ b/src/nvhttp.cpp @@ -752,6 +752,21 @@ namespace nvhttp { response->close_connection_after_response = true; } + pt::ptree + get_all_clients() { + pt::ptree named_cert_nodes; + for (auto &[_, client] : map_id_client) { + for (auto &named_cert : client.named_certs) { + pt::ptree named_cert_node; + named_cert_node.put("name"s, named_cert.name); + named_cert_node.put("uniqueID"s, named_cert.uniqueID); + named_cert_nodes.push_back(std::make_pair(""s, named_cert_node)); + } + } + + return named_cert_nodes; + } + void applist(resp_https_t response, req_https_t request) { print_req(request); diff --git a/src/nvhttp.h b/src/nvhttp.h index 0a5862514c4..11df8fc6f56 100644 --- a/src/nvhttp.h +++ b/src/nvhttp.h @@ -9,6 +9,9 @@ // standard includes #include +// lib includes +#include + // local includes #include "thread_safe.h" @@ -44,6 +47,8 @@ namespace nvhttp { start(); bool pin(std::string pin, std::string name); + boost::property_tree::ptree + get_all_clients(); void erase_all_clients(); } // namespace nvhttp