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