UniSet 2.44.3
LauncherHttpRegistry.h
1/*
2 * Copyright (c) 2026 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 */
8// -------------------------------------------------------------------------
9#ifndef LauncherHttpRegistry_H_
10#define LauncherHttpRegistry_H_
11// -------------------------------------------------------------------------
12#ifndef DISABLE_REST_API
13// -------------------------------------------------------------------------
14#include <memory>
15#include "UHttpRequestHandler.h"
16#include "ProcessManager.h"
17// -------------------------------------------------------------------------
18namespace uniset
19{
37 class LauncherHttpRegistry :
39 public std::enable_shared_from_this<LauncherHttpRegistry>
40 {
41 public:
42 explicit LauncherHttpRegistry(ProcessManager& pm);
43 virtual ~LauncherHttpRegistry() = default;
44
45 // Configuration
46 void setReadToken(const std::string& token);
47 void setControlToken(const std::string& token);
48 void setHtmlTemplate(const std::string& path);
49
50 // IHttpRequestRegistry interface
51 Poco::JSON::Object::Ptr httpRequest(const UHttp::HttpRequestContext& ctx) override;
52 Poco::JSON::Array::Ptr httpGetObjectsList(const UHttp::HttpRequestContext& ctx) override;
53 Poco::JSON::Object::Ptr httpHelpRequest(const UHttp::HttpRequestContext& ctx) override;
54
55 // Static file serving (HTML, JS)
57 const std::string& path,
58 Poco::Net::HTTPServerRequest& req,
59 Poco::Net::HTTPServerResponse& resp) override;
60
61 private:
62 Poco::JSON::Object::Ptr handleStatus();
63 Poco::JSON::Object::Ptr handleProcesses();
64 Poco::JSON::Object::Ptr handleProcess(const std::string& name);
65 Poco::JSON::Object::Ptr handleRestart(const std::string& name);
66 Poco::JSON::Object::Ptr handleStop(const std::string& name);
67 Poco::JSON::Object::Ptr handleStart(const std::string& name);
68 Poco::JSON::Object::Ptr handleRestartAll();
69 Poco::JSON::Object::Ptr handleReloadAll();
70 Poco::JSON::Object::Ptr handleHealth();
71 Poco::JSON::Object::Ptr handleGroups();
72 Poco::JSON::Object::Ptr handleHelp();
73
74 Poco::JSON::Object::Ptr processToJSON(const ProcessInfo& proc);
75 Poco::JSON::Object::Ptr groupToJSON(const ProcessGroup& group);
76
77 // Authorization helpers
78 bool checkReadAuth(const Poco::Net::HTTPServerRequest& req);
79 bool checkControlAuth(const Poco::Net::HTTPServerRequest& req);
80 static bool validateBearerToken(const Poco::Net::HTTPServerRequest& req,
81 const std::string& expectedToken);
82
83 // File serving helpers
84 bool sendHtmlFile(const std::string& filename,
85 Poco::Net::HTTPServerRequest& req,
86 Poco::Net::HTTPServerResponse& resp);
87 bool sendJsFile(const std::string& filename,
88 Poco::Net::HTTPServerRequest& req,
89 Poco::Net::HTTPServerResponse& resp);
90 std::string findFile(const std::string& filename);
91 std::string applyTemplateVars(const std::string& content);
92
93 ProcessManager& pm_;
94 std::string readToken_;
95 std::string controlToken_;
96 std::string htmlTemplatePath_;
97 };
98
99} // end of namespace uniset
100// -------------------------------------------------------------------------
101#endif // DISABLE_REST_API
102// -------------------------------------------------------------------------
103#endif // LauncherHttpRegistry_H_
104// -------------------------------------------------------------------------
bool httpStaticRequest(const std::string &path, Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp) override
Определения LauncherHttpRegistry.cc:610
Определения ProcessManager.h:43
Определения UHttpRequestHandler.h:146
Определения Calibration.h:27
Определения ProcessInfo.h:113
Определения ProcessInfo.h:66
Определения UHttpRequestHandler.h:87