1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation 4 #pragma once 5 6 #include "app.hpp" 7 #include "async_resp.hpp" 8 #include "error_messages.hpp" 9 #include "http_request.hpp" 10 #include "query.hpp" 11 #include "registries/privilege_registry.hpp" 12 #include "utils/eventlog_utils.hpp" 13 14 #include <boost/beast/http/field.hpp> 15 #include <boost/beast/http/status.hpp> 16 #include <boost/beast/http/verb.hpp> 17 #include <boost/system/linux_error.hpp> 18 #include <boost/url/format.hpp> 19 #include <boost/url/url.hpp> 20 #include <sdbusplus/message.hpp> 21 #include <sdbusplus/message/native_types.hpp> 22 #include <sdbusplus/unpack_properties.hpp> 23 24 #include <memory> 25 #include <string> 26 27 namespace redfish 28 { 29 30 inline void handleManagersDBusEventLogEntryCollection( 31 crow::App& app, const crow::Request& req, 32 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 33 const std::string& managerId) 34 { 35 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 36 { 37 return; 38 } 39 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 40 { 41 messages::resourceNotFound(asyncResp->res, "Manager", managerId); 42 return; 43 } 44 eventlog_utils::dBusEventLogEntryCollection( 45 asyncResp, eventlog_utils::LogServiceParent::Managers); 46 } 47 48 inline void handleManagersDBusEventLogEntryGet( 49 crow::App& app, const crow::Request& req, 50 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 51 const std::string& managerId, const std::string& entryId) 52 { 53 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 54 { 55 return; 56 } 57 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 58 { 59 messages::resourceNotFound(asyncResp->res, "Manager", managerId); 60 return; 61 } 62 63 eventlog_utils::dBusEventLogEntryGet( 64 asyncResp, eventlog_utils::LogServiceParent::Managers, entryId); 65 } 66 67 inline void handleManagersDBusEventLogEntryPatch( 68 crow::App& app, const crow::Request& req, 69 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 70 const std::string& managerId, const std::string& entryId) 71 { 72 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 73 { 74 return; 75 } 76 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 77 { 78 messages::resourceNotFound(asyncResp->res, "Manager", managerId); 79 return; 80 } 81 82 eventlog_utils::dBusEventLogEntryPatch(req, asyncResp, entryId); 83 } 84 85 inline void handleManagersDBusEventLogEntryDelete( 86 crow::App& app, const crow::Request& req, 87 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 88 const std::string& managerId, const std::string& entryId) 89 { 90 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 91 { 92 return; 93 } 94 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 95 { 96 messages::resourceNotFound(asyncResp->res, "Manager", managerId); 97 return; 98 } 99 100 eventlog_utils::dBusEventLogEntryDelete(asyncResp, entryId); 101 } 102 103 inline void handleManagersDBusLogServiceActionsClear( 104 crow::App& app, const crow::Request& req, 105 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 106 const std::string& managerId) 107 { 108 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 109 { 110 return; 111 } 112 if (!http_helpers::isContentTypeAllowed( 113 req.getHeaderValue("Accept"), 114 http_helpers::ContentType::OctetStream, true)) 115 { 116 asyncResp->res.result(boost::beast::http::status::bad_request); 117 } 118 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 119 { 120 messages::resourceNotFound(asyncResp->res, "Manager", managerId); 121 return; 122 } 123 eventlog_utils::dBusLogServiceActionsClear(asyncResp); 124 } 125 126 inline void handleManagersDBusEventLogEntryDownload( 127 crow::App& app, const crow::Request& req, 128 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 129 const std::string& managerId, const std::string& entryId) 130 { 131 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 132 { 133 return; 134 } 135 if (!http_helpers::isContentTypeAllowed( 136 req.getHeaderValue("Accept"), 137 http_helpers::ContentType::OctetStream, true)) 138 { 139 asyncResp->res.result(boost::beast::http::status::bad_request); 140 } 141 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 142 { 143 messages::resourceNotFound(asyncResp->res, "Manager", managerId); 144 return; 145 } 146 eventlog_utils::downloadEventLogEntry(asyncResp, entryId, "System"); 147 } 148 149 inline void requestRoutesManagersDBusEventLogEntryCollection(App& app) 150 { 151 BMCWEB_ROUTE(app, 152 "/redfish/v1/Managers/<str>/LogServices/EventLog/Entries/") 153 .privileges(redfish::privileges::getLogEntryCollection) 154 .methods(boost::beast::http::verb::get)(std::bind_front( 155 handleManagersDBusEventLogEntryCollection, std::ref(app))); 156 } 157 158 inline void requestRoutesManagersDBusEventLogEntry(App& app) 159 { 160 BMCWEB_ROUTE( 161 app, "/redfish/v1/Managers/<str>/LogServices/EventLog/Entries/<str>/") 162 .privileges(redfish::privileges::getLogEntry) 163 .methods(boost::beast::http::verb::get)( 164 std::bind_front(handleManagersDBusEventLogEntryGet, std::ref(app))); 165 166 BMCWEB_ROUTE( 167 app, "/redfish/v1/Managers/<str>/LogServices/EventLog/Entries/<str>/") 168 .privileges(redfish::privileges::patchLogEntry) 169 .methods(boost::beast::http::verb::patch)(std::bind_front( 170 handleManagersDBusEventLogEntryPatch, std::ref(app))); 171 172 BMCWEB_ROUTE( 173 app, "/redfish/v1/Managers/<str>/LogServices/EventLog/Entries/<str>/") 174 .privileges( 175 redfish::privileges:: 176 deleteLogEntrySubOverComputerSystemLogServiceCollectionLogServiceLogEntryCollection) 177 .methods(boost::beast::http::verb::delete_)(std::bind_front( 178 handleManagersDBusEventLogEntryDelete, std::ref(app))); 179 } 180 181 /** 182 * DBusLogServiceActionsClear class supports POST method for ClearLog action. 183 */ 184 inline void requestRoutesManagersDBusLogServiceActionsClear(App& app) 185 { 186 /** 187 * Function handles POST method request. 188 * The Clear Log actions does not require any parameter.The action deletes 189 * all entries found in the Entries collection for this Log Service. 190 */ 191 192 BMCWEB_ROUTE( 193 app, 194 "/redfish/v1/Managers/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 195 .privileges(redfish::privileges:: 196 postLogServiceSubOverComputerSystemLogServiceCollection) 197 .methods(boost::beast::http::verb::post)(std::bind_front( 198 handleManagersDBusLogServiceActionsClear, std::ref(app))); 199 } 200 201 inline void requestRoutesManagersDBusEventLogEntryDownload(App& app) 202 { 203 BMCWEB_ROUTE( 204 app, 205 "/redfish/v1/Managers/<str>/LogServices/EventLog/Entries/<str>/attachment/") 206 .privileges(redfish::privileges::getLogEntry) 207 .methods(boost::beast::http::verb::get)(std::bind_front( 208 handleManagersDBusEventLogEntryDownload, std::ref(app))); 209 } 210 } // namespace redfish 211