| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 1 | #include "webserver_run.hpp" | 
|  | 2 |  | 
|  | 3 | #include "bmcweb_config.h" | 
|  | 4 |  | 
|  | 5 | #include "app.hpp" | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 6 | #include "dbus_monitor.hpp" | 
|  | 7 | #include "dbus_singleton.hpp" | 
|  | 8 | #include "event_service_manager.hpp" | 
|  | 9 | #include "google/google_service_root.hpp" | 
|  | 10 | #include "hostname_monitor.hpp" | 
|  | 11 | #include "ibm/management_console_rest.hpp" | 
|  | 12 | #include "image_upload.hpp" | 
|  | 13 | #include "kvm_websocket.hpp" | 
| Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 14 | #include "logging.hpp" | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 15 | #include "login_routes.hpp" | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 16 | #include "obmc_console.hpp" | 
|  | 17 | #include "openbmc_dbus_rest.hpp" | 
|  | 18 | #include "redfish.hpp" | 
|  | 19 | #include "redfish_aggregator.hpp" | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 20 | #include "user_monitor.hpp" | 
|  | 21 | #include "vm_websocket.hpp" | 
|  | 22 | #include "webassets.hpp" | 
|  | 23 |  | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 24 | #include <boost/asio/io_context.hpp> | 
|  | 25 | #include <sdbusplus/asio/connection.hpp> | 
| Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 26 | #include <sdbusplus/asio/object_server.hpp> | 
| Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 27 |  | 
|  | 28 | #include <memory> | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 29 |  | 
| Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 30 | static void setLogLevel(const std::string& logLevel) | 
|  | 31 | { | 
|  | 32 | const std::basic_string_view<char>* iter = | 
|  | 33 | std::ranges::find(crow::mapLogLevelFromName, logLevel); | 
|  | 34 | if (iter == crow::mapLogLevelFromName.end()) | 
|  | 35 | { | 
|  | 36 | BMCWEB_LOG_ERROR("log-level {} not found", logLevel); | 
|  | 37 | return; | 
|  | 38 | } | 
|  | 39 | crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel); | 
|  | 40 | BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel); | 
|  | 41 | } | 
|  | 42 |  | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 43 | int run() | 
|  | 44 | { | 
|  | 45 | auto io = std::make_shared<boost::asio::io_context>(); | 
|  | 46 | App app(io); | 
|  | 47 |  | 
| Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 48 | std::shared_ptr<sdbusplus::asio::connection> systemBus = | 
|  | 49 | std::make_shared<sdbusplus::asio::connection>(*io); | 
|  | 50 | crow::connections::systemBus = systemBus.get(); | 
|  | 51 |  | 
|  | 52 | auto server = sdbusplus::asio::object_server(systemBus); | 
|  | 53 |  | 
|  | 54 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface = | 
|  | 55 | server.add_interface("/xyz/openbmc_project/bmcweb", | 
|  | 56 | "xyz.openbmc_project.bmcweb"); | 
|  | 57 |  | 
|  | 58 | iface->register_method("SetLogLevel", setLogLevel); | 
|  | 59 |  | 
|  | 60 | iface->initialize(); | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 61 |  | 
|  | 62 | // Static assets need to be initialized before Authorization, because auth | 
|  | 63 | // needs to build the whitelist from the static routes | 
|  | 64 |  | 
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 65 | if constexpr (BMCWEB_STATIC_HOSTING) | 
|  | 66 | { | 
|  | 67 | crow::webassets::requestRoutes(app); | 
|  | 68 | } | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 69 |  | 
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 70 | if constexpr (BMCWEB_KVM) | 
|  | 71 | { | 
|  | 72 | crow::obmc_kvm::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_REDFISH) | 
|  | 76 | { | 
|  | 77 | redfish::RedfishService redfish(app); | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 78 |  | 
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 79 | // Create EventServiceManager instance and initialize Config | 
|  | 80 | redfish::EventServiceManager::getInstance(&*io); | 
| 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_AGGREGATION) | 
|  | 83 | { | 
|  | 84 | // Create RedfishAggregator instance and initialize Config | 
|  | 85 | redfish::RedfishAggregator::getInstance(&*io); | 
|  | 86 | } | 
|  | 87 | } | 
| 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_REST) | 
|  | 90 | { | 
|  | 91 | crow::dbus_monitor::requestRoutes(app); | 
|  | 92 | crow::image_upload::requestRoutes(app); | 
|  | 93 | crow::openbmc_mapper::requestRoutes(app); | 
|  | 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_HOST_SERIAL_SOCKET) | 
|  | 97 | { | 
|  | 98 | crow::obmc_console::requestRoutes(app); | 
|  | 99 | } | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 100 |  | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 101 | crow::obmc_vm::requestRoutes(app); | 
| 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_IBM_MANAGEMENT_CONSOLE) | 
|  | 104 | { | 
|  | 105 | crow::ibm_mc::requestRoutes(app); | 
|  | 106 | } | 
| 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_GOOGLE_API) | 
|  | 109 | { | 
|  | 110 | crow::google_api::requestRoutes(app); | 
|  | 111 | } | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 112 |  | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 113 | crow::login_routes::requestRoutes(app); | 
|  | 114 |  | 
| Jayaprakash Mutyala | ff0a088 | 2024-06-26 09:08:53 +0000 | [diff] [blame] | 115 | if constexpr (!BMCWEB_REDFISH_DBUS_LOG) | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 116 | { | 
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 117 | int rc = redfish::EventServiceManager::startEventLogMonitor(*io); | 
|  | 118 | if (rc != 0) | 
|  | 119 | { | 
|  | 120 | BMCWEB_LOG_ERROR("Redfish event handler setup failed..."); | 
|  | 121 | return rc; | 
|  | 122 | } | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 123 | } | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 124 |  | 
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 125 | if constexpr (!BMCWEB_INSECURE_DISABLE_SSL) | 
| Ed Tanous | 8db8374 | 2024-04-13 09:11:15 -0700 | [diff] [blame] | 126 | { | 
|  | 127 | BMCWEB_LOG_INFO("Start Hostname Monitor Service..."); | 
|  | 128 | crow::hostname_monitor::registerHostnameSignal(); | 
|  | 129 | } | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 130 |  | 
|  | 131 | bmcweb::registerUserRemovedSignal(); | 
|  | 132 |  | 
|  | 133 | app.run(); | 
| Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 134 |  | 
|  | 135 | systemBus->request_name("xyz.openbmc_project.bmcweb"); | 
|  | 136 |  | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 137 | io->run(); | 
|  | 138 |  | 
|  | 139 | crow::connections::systemBus = nullptr; | 
|  | 140 |  | 
| Ed Tanous | 9ed3f90 | 2024-07-15 17:54:31 -0700 | [diff] [blame] | 141 | // TODO(ed) Make event log monitor an RAII object instead of global vars | 
|  | 142 | redfish::EventServiceManager::stopEventLogMonitor(); | 
|  | 143 |  | 
| Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 144 | return 0; | 
|  | 145 | } |