1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #include "webserver_run.hpp" 4 5 #include "bmcweb_config.h" 6 7 #include "app.hpp" 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 "io_context_singleton.hpp" 16 #include "kvm_websocket.hpp" 17 #include "logging.hpp" 18 #include "login_routes.hpp" 19 #include "obmc_console.hpp" 20 #include "openbmc_dbus_rest.hpp" 21 #include "redfish.hpp" 22 #include "redfish_aggregator.hpp" 23 #include "user_monitor.hpp" 24 #include "vm_websocket.hpp" 25 #include "watchdog.hpp" 26 #include "webassets.hpp" 27 28 #include <boost/asio/io_context.hpp> 29 #include <sdbusplus/asio/connection.hpp> 30 #include <sdbusplus/asio/object_server.hpp> 31 32 #include <algorithm> 33 #include <memory> 34 #include <string> 35 #include <string_view> 36 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 50 int run() 51 { 52 boost::asio::io_context& io = getIoContext(); 53 App app; 54 55 std::shared_ptr<sdbusplus::asio::connection> systemBus = 56 std::make_shared<sdbusplus::asio::connection>(io); 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(); 68 69 // Static assets need to be initialized before Authorization, because auth 70 // needs to build the whitelist from the static routes 71 72 if constexpr (BMCWEB_STATIC_HOSTING) 73 { 74 crow::webassets::requestRoutes(app); 75 } 76 77 if constexpr (BMCWEB_KVM) 78 { 79 crow::obmc_kvm::requestRoutes(app); 80 } 81 82 if constexpr (BMCWEB_REDFISH) 83 { 84 redfish::RedfishService redfish(app); 85 86 // Create EventServiceManager instance and initialize Config 87 redfish::EventServiceManager::getInstance(); 88 89 if constexpr (BMCWEB_REDFISH_AGGREGATION) 90 { 91 // Create RedfishAggregator instance and initialize Config 92 redfish::RedfishAggregator::getInstance(); 93 } 94 } 95 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 } 102 103 if constexpr (BMCWEB_HOST_SERIAL_SOCKET) 104 { 105 crow::obmc_console::requestRoutes(app); 106 } 107 108 crow::obmc_vm::requestRoutes(app); 109 110 if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE) 111 { 112 crow::ibm_mc::requestRoutes(app); 113 } 114 115 if constexpr (BMCWEB_GOOGLE_API) 116 { 117 crow::google_api::requestRoutes(app); 118 } 119 120 crow::login_routes::requestRoutes(app); 121 122 if constexpr (!BMCWEB_INSECURE_DISABLE_SSL) 123 { 124 BMCWEB_LOG_INFO("Start Hostname Monitor Service..."); 125 crow::hostname_monitor::registerHostnameSignal(); 126 } 127 128 bmcweb::registerUserRemovedSignal(); 129 130 bmcweb::ServiceWatchdog watchdog; 131 132 app.run(); 133 134 systemBus->request_name("xyz.openbmc_project.bmcweb"); 135 136 io.run(); 137 138 crow::connections::systemBus = nullptr; 139 140 return 0; 141 } 142