/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
#include "remote/infohandler.hpp"
#include "remote/httputility.hpp"
#include "base/application.hpp"
using namespace icinga;
REGISTER_URLHANDLER("/", InfoHandler);
bool InfoHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response, const Dictionary::Ptr& params)
{
if (request.RequestUrl->GetPath().size() > 2)
return false;
if (request.RequestMethod != "GET")
return false;
if (request.RequestUrl->GetPath().empty()) {
response.SetStatus(302, "Found");
response.AddHeader("Location", "/v1");
return true;
}
if (request.RequestUrl->GetPath()[0] != "v1" || request.RequestUrl->GetPath().size() != 1)
return false;
response.SetStatus(200, "OK");
std::vector You are authenticated as " + user->GetName() + ". ";
if (!permInfo.empty()) {
body += "Your user has the following permissions:Hello from Icinga 2 (Version: " + Application::GetAppVersion() + ")!
";
body += "";
for (const String& perm : permInfo) {
body += "
";
} else
body += "Your user does not have any permissions.
More information about API requests is available in the documentation.
)"; response.WriteBody(body.CStr(), body.GetLength()); } return true; }