Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 3 | #include "webserver_run.hpp" |
| 4 | |
| 5 | #include "bmcweb_config.h" |
| 6 | |
| 7 | #include "app.hpp" |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 8 | #include "dbus_monitor.hpp" |
| 9 | #include "dbus_singleton.hpp" |
| 10 | #include "event_service_manager.hpp" |
| 11 | #include "google/google_service_root.hpp" |
| 12 | #include "hostname_monitor.hpp" |
| 13 | #include "ibm/management_console_rest.hpp" |
| 14 | #include "image_upload.hpp" |
Ed Tanous | 9838eb2 | 2025-01-29 16:24:42 -0800 | [diff] [blame] | 15 | #include "io_context_singleton.hpp" |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 16 | #include "kvm_websocket.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 17 | #include "logging.hpp" |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 18 | #include "login_routes.hpp" |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 19 | #include "obmc_console.hpp" |
| 20 | #include "openbmc_dbus_rest.hpp" |
| 21 | #include "redfish.hpp" |
| 22 | #include "redfish_aggregator.hpp" |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 23 | #include "user_monitor.hpp" |
| 24 | #include "vm_websocket.hpp" |
rohitpai | cf9085a | 2025-02-24 12:33:59 +0530 | [diff] [blame] | 25 | #include "watchdog.hpp" |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 26 | #include "webassets.hpp" |
| 27 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 28 | #include <boost/asio/io_context.hpp> |
| 29 | #include <sdbusplus/asio/connection.hpp> |
Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 30 | #include <sdbusplus/asio/object_server.hpp> |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 31 | |
Ed Tanous | 41fe81c | 2024-09-02 15:08:41 -0700 | [diff] [blame] | 32 | #include <algorithm> |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 33 | #include <memory> |
Ed Tanous | 41fe81c | 2024-09-02 15:08:41 -0700 | [diff] [blame] | 34 | #include <string> |
| 35 | #include <string_view> |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 36 | |
Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 37 | static void setLogLevel(const std::string& logLevel) |
| 38 | { |
| 39 | const std::basic_string_view<char>* iter = |
| 40 | std::ranges::find(crow::mapLogLevelFromName, logLevel); |
| 41 | if (iter == crow::mapLogLevelFromName.end()) |
| 42 | { |
| 43 | BMCWEB_LOG_ERROR("log-level {} not found", logLevel); |
| 44 | return; |
| 45 | } |
| 46 | crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel); |
| 47 | BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel); |
| 48 | } |
| 49 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 50 | int run() |
| 51 | { |
Ed Tanous | 9838eb2 | 2025-01-29 16:24:42 -0800 | [diff] [blame] | 52 | boost::asio::io_context& io = getIoContext(); |
| 53 | App app; |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 54 | |
Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 55 | std::shared_ptr<sdbusplus::asio::connection> systemBus = |
Ed Tanous | 9838eb2 | 2025-01-29 16:24:42 -0800 | [diff] [blame] | 56 | std::make_shared<sdbusplus::asio::connection>(io); |
Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 57 | crow::connections::systemBus = systemBus.get(); |
| 58 | |
| 59 | auto server = sdbusplus::asio::object_server(systemBus); |
| 60 | |
| 61 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface = |
| 62 | server.add_interface("/xyz/openbmc_project/bmcweb", |
| 63 | "xyz.openbmc_project.bmcweb"); |
| 64 | |
| 65 | iface->register_method("SetLogLevel", setLogLevel); |
| 66 | |
| 67 | iface->initialize(); |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 68 | |
| 69 | // Static assets need to be initialized before Authorization, because auth |
| 70 | // needs to build the whitelist from the static routes |
| 71 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 72 | if constexpr (BMCWEB_STATIC_HOSTING) |
| 73 | { |
| 74 | crow::webassets::requestRoutes(app); |
| 75 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 76 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 77 | if constexpr (BMCWEB_KVM) |
| 78 | { |
| 79 | crow::obmc_kvm::requestRoutes(app); |
| 80 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 81 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 82 | if constexpr (BMCWEB_REDFISH) |
| 83 | { |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame^] | 84 | redfish::RedfishService::getInstance(app); |
Alexander Hansen | 6c58a03 | 2024-11-21 15:27:04 -0800 | [diff] [blame] | 85 | |
| 86 | // Create EventServiceManager instance and initialize Config |
Ed Tanous | 9838eb2 | 2025-01-29 16:24:42 -0800 | [diff] [blame] | 87 | redfish::EventServiceManager::getInstance(); |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 88 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 89 | if constexpr (BMCWEB_REDFISH_AGGREGATION) |
| 90 | { |
| 91 | // Create RedfishAggregator instance and initialize Config |
Ed Tanous | 9838eb2 | 2025-01-29 16:24:42 -0800 | [diff] [blame] | 92 | redfish::RedfishAggregator::getInstance(); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 93 | } |
| 94 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 95 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 96 | if constexpr (BMCWEB_REST) |
| 97 | { |
| 98 | crow::dbus_monitor::requestRoutes(app); |
| 99 | crow::image_upload::requestRoutes(app); |
| 100 | crow::openbmc_mapper::requestRoutes(app); |
| 101 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 102 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 103 | if constexpr (BMCWEB_HOST_SERIAL_SOCKET) |
| 104 | { |
| 105 | crow::obmc_console::requestRoutes(app); |
| 106 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 107 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 108 | crow::obmc_vm::requestRoutes(app); |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 109 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 110 | if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE) |
| 111 | { |
| 112 | crow::ibm_mc::requestRoutes(app); |
| 113 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 114 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 115 | if constexpr (BMCWEB_GOOGLE_API) |
| 116 | { |
| 117 | crow::google_api::requestRoutes(app); |
| 118 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 119 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 120 | crow::login_routes::requestRoutes(app); |
| 121 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 122 | if constexpr (!BMCWEB_INSECURE_DISABLE_SSL) |
Ed Tanous | 8db8374 | 2024-04-13 09:11:15 -0700 | [diff] [blame] | 123 | { |
| 124 | BMCWEB_LOG_INFO("Start Hostname Monitor Service..."); |
| 125 | crow::hostname_monitor::registerHostnameSignal(); |
| 126 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 127 | |
| 128 | bmcweb::registerUserRemovedSignal(); |
| 129 | |
rohitpai | cf9085a | 2025-02-24 12:33:59 +0530 | [diff] [blame] | 130 | bmcweb::ServiceWatchdog watchdog; |
| 131 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 132 | app.run(); |
Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 133 | |
| 134 | systemBus->request_name("xyz.openbmc_project.bmcweb"); |
| 135 | |
Ed Tanous | 9838eb2 | 2025-01-29 16:24:42 -0800 | [diff] [blame] | 136 | io.run(); |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 137 | |
| 138 | crow::connections::systemBus = nullptr; |
| 139 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 140 | return 0; |
| 141 | } |