MCPcopy Create free account
hub / github.com/Icinga/icinga2 / HandleRequest

Method HandleRequest

lib/remote/consolehandler.cpp:72–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72bool ConsoleHandler::HandleRequest(
73 const WaitGroup::Ptr&,
74 const HttpApiRequest& request,
75 HttpApiResponse& response,
76 boost::asio::yield_context&
77)
78{
79 namespace http = boost::beast::http;
80
81 auto url = request.Url();
82 auto user = request.User();
83 auto params = request.Params();
84
85 if (url->GetPath().size() != 3)
86 return false;
87
88 if (request.method() != http::verb::post)
89 return false;
90
91 QueryDescription qd;
92
93 String methodName = url->GetPath()[2];
94
95 FilterUtility::CheckPermission(user, "console");
96
97 String session = HttpUtility::GetLastParameter(params, "session");
98
99 if (session.IsEmpty())
100 session = Utility::NewUniqueID();
101
102 String command = HttpUtility::GetLastParameter(params, "command");
103
104 bool sandboxed = HttpUtility::GetLastParameter(params, "sandboxed");
105
106 ConfigObjectsSharedLock lock (std::try_to_lock);
107
108 if (!lock) {
109 HttpUtility::SendJsonError(response, params, 503, "Icinga is reloading.");
110 return true;
111 }
112
113 if (methodName == "execute-script")
114 return ExecuteScriptHelper(request, response, command, session, sandboxed);
115 else if (methodName == "auto-complete-script")
116 return AutocompleteScriptHelper(request, response, command, session, sandboxed);
117
118 HttpUtility::SendJsonError(response, params, 400, "Invalid method specified: " + methodName);
119 return true;
120}
121
122bool ConsoleHandler::ExecuteScriptHelper(const HttpApiRequest& request, HttpApiResponse& response,
123 const String& command, const String& session, bool sandboxed)

Callers

nothing calls this directly

Calls 6

ParamsMethod · 0.80
UrlMethod · 0.45
UserMethod · 0.45
sizeMethod · 0.45
GetPathMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected