140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 33cd7072bSEd Tanous #include "webserver_run.hpp" 43cd7072bSEd Tanous 53cd7072bSEd Tanous #include "bmcweb_config.h" 63cd7072bSEd Tanous 73cd7072bSEd Tanous #include "app.hpp" 83cd7072bSEd Tanous #include "dbus_monitor.hpp" 93cd7072bSEd Tanous #include "dbus_singleton.hpp" 103cd7072bSEd Tanous #include "event_service_manager.hpp" 113cd7072bSEd Tanous #include "google/google_service_root.hpp" 123cd7072bSEd Tanous #include "hostname_monitor.hpp" 133cd7072bSEd Tanous #include "ibm/management_console_rest.hpp" 143cd7072bSEd Tanous #include "image_upload.hpp" 159838eb20SEd Tanous #include "io_context_singleton.hpp" 163cd7072bSEd Tanous #include "kvm_websocket.hpp" 175b90429aSEd Tanous #include "logging.hpp" 183cd7072bSEd Tanous #include "login_routes.hpp" 193cd7072bSEd Tanous #include "obmc_console.hpp" 203cd7072bSEd Tanous #include "openbmc_dbus_rest.hpp" 213cd7072bSEd Tanous #include "redfish.hpp" 223cd7072bSEd Tanous #include "redfish_aggregator.hpp" 233cd7072bSEd Tanous #include "user_monitor.hpp" 243cd7072bSEd Tanous #include "vm_websocket.hpp" 25*cf9085acSrohitpai #include "watchdog.hpp" 263cd7072bSEd Tanous #include "webassets.hpp" 273cd7072bSEd Tanous 283cd7072bSEd Tanous #include <boost/asio/io_context.hpp> 293cd7072bSEd Tanous #include <sdbusplus/asio/connection.hpp> 30bd1299b7SAushim Nagarkatti #include <sdbusplus/asio/object_server.hpp> 315b90429aSEd Tanous 3241fe81c2SEd Tanous #include <algorithm> 335b90429aSEd Tanous #include <memory> 3441fe81c2SEd Tanous #include <string> 3541fe81c2SEd Tanous #include <string_view> 363cd7072bSEd Tanous setLogLevel(const std::string & logLevel)37bd1299b7SAushim Nagarkattistatic void setLogLevel(const std::string& logLevel) 38bd1299b7SAushim Nagarkatti { 39bd1299b7SAushim Nagarkatti const std::basic_string_view<char>* iter = 40bd1299b7SAushim Nagarkatti std::ranges::find(crow::mapLogLevelFromName, logLevel); 41bd1299b7SAushim Nagarkatti if (iter == crow::mapLogLevelFromName.end()) 42bd1299b7SAushim Nagarkatti { 43bd1299b7SAushim Nagarkatti BMCWEB_LOG_ERROR("log-level {} not found", logLevel); 44bd1299b7SAushim Nagarkatti return; 45bd1299b7SAushim Nagarkatti } 46bd1299b7SAushim Nagarkatti crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel); 47bd1299b7SAushim Nagarkatti BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel); 48bd1299b7SAushim Nagarkatti } 49bd1299b7SAushim Nagarkatti run()503cd7072bSEd Tanousint run() 513cd7072bSEd Tanous { 529838eb20SEd Tanous boost::asio::io_context& io = getIoContext(); 539838eb20SEd Tanous App app; 543cd7072bSEd Tanous 55bd1299b7SAushim Nagarkatti std::shared_ptr<sdbusplus::asio::connection> systemBus = 569838eb20SEd Tanous std::make_shared<sdbusplus::asio::connection>(io); 57bd1299b7SAushim Nagarkatti crow::connections::systemBus = systemBus.get(); 58bd1299b7SAushim Nagarkatti 59bd1299b7SAushim Nagarkatti auto server = sdbusplus::asio::object_server(systemBus); 60bd1299b7SAushim Nagarkatti 61bd1299b7SAushim Nagarkatti std::shared_ptr<sdbusplus::asio::dbus_interface> iface = 62bd1299b7SAushim Nagarkatti server.add_interface("/xyz/openbmc_project/bmcweb", 63bd1299b7SAushim Nagarkatti "xyz.openbmc_project.bmcweb"); 64bd1299b7SAushim Nagarkatti 65bd1299b7SAushim Nagarkatti iface->register_method("SetLogLevel", setLogLevel); 66bd1299b7SAushim Nagarkatti 67bd1299b7SAushim Nagarkatti iface->initialize(); 683cd7072bSEd Tanous 693cd7072bSEd Tanous // Static assets need to be initialized before Authorization, because auth 703cd7072bSEd Tanous // needs to build the whitelist from the static routes 713cd7072bSEd Tanous 7225b54dbaSEd Tanous if constexpr (BMCWEB_STATIC_HOSTING) 7325b54dbaSEd Tanous { 743cd7072bSEd Tanous crow::webassets::requestRoutes(app); 7525b54dbaSEd Tanous } 763cd7072bSEd Tanous 7725b54dbaSEd Tanous if constexpr (BMCWEB_KVM) 7825b54dbaSEd Tanous { 793cd7072bSEd Tanous crow::obmc_kvm::requestRoutes(app); 8025b54dbaSEd Tanous } 813cd7072bSEd Tanous 8225b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH) 8325b54dbaSEd Tanous { 843cd7072bSEd Tanous redfish::RedfishService redfish(app); 856c58a03eSAlexander Hansen 866c58a03eSAlexander Hansen // Create EventServiceManager instance and initialize Config 879838eb20SEd Tanous redfish::EventServiceManager::getInstance(); 883cd7072bSEd Tanous 8925b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_AGGREGATION) 9025b54dbaSEd Tanous { 913cd7072bSEd Tanous // Create RedfishAggregator instance and initialize Config 929838eb20SEd Tanous redfish::RedfishAggregator::getInstance(); 9325b54dbaSEd Tanous } 9425b54dbaSEd Tanous } 953cd7072bSEd Tanous 9625b54dbaSEd Tanous if constexpr (BMCWEB_REST) 9725b54dbaSEd Tanous { 983cd7072bSEd Tanous crow::dbus_monitor::requestRoutes(app); 993cd7072bSEd Tanous crow::image_upload::requestRoutes(app); 1003cd7072bSEd Tanous crow::openbmc_mapper::requestRoutes(app); 10125b54dbaSEd Tanous } 1023cd7072bSEd Tanous 10325b54dbaSEd Tanous if constexpr (BMCWEB_HOST_SERIAL_SOCKET) 10425b54dbaSEd Tanous { 1053cd7072bSEd Tanous crow::obmc_console::requestRoutes(app); 10625b54dbaSEd Tanous } 1073cd7072bSEd Tanous 1083cd7072bSEd Tanous crow::obmc_vm::requestRoutes(app); 1093cd7072bSEd Tanous 11025b54dbaSEd Tanous if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE) 11125b54dbaSEd Tanous { 1123cd7072bSEd Tanous crow::ibm_mc::requestRoutes(app); 11325b54dbaSEd Tanous } 1143cd7072bSEd Tanous 11525b54dbaSEd Tanous if constexpr (BMCWEB_GOOGLE_API) 11625b54dbaSEd Tanous { 1173cd7072bSEd Tanous crow::google_api::requestRoutes(app); 11825b54dbaSEd Tanous } 1193cd7072bSEd Tanous 1203cd7072bSEd Tanous crow::login_routes::requestRoutes(app); 1213cd7072bSEd Tanous 12225b54dbaSEd Tanous if constexpr (!BMCWEB_INSECURE_DISABLE_SSL) 1238db83747SEd Tanous { 1243cd7072bSEd Tanous BMCWEB_LOG_INFO("Start Hostname Monitor Service..."); 1253cd7072bSEd Tanous crow::hostname_monitor::registerHostnameSignal(); 1268db83747SEd Tanous } 1273cd7072bSEd Tanous 1283cd7072bSEd Tanous bmcweb::registerUserRemovedSignal(); 1293cd7072bSEd Tanous 130*cf9085acSrohitpai bmcweb::ServiceWatchdog watchdog; 131*cf9085acSrohitpai 1323cd7072bSEd Tanous app.run(); 133bd1299b7SAushim Nagarkatti 134bd1299b7SAushim Nagarkatti systemBus->request_name("xyz.openbmc_project.bmcweb"); 135bd1299b7SAushim Nagarkatti 1369838eb20SEd Tanous io.run(); 1373cd7072bSEd Tanous 1383cd7072bSEd Tanous crow::connections::systemBus = nullptr; 1393cd7072bSEd Tanous 1403cd7072bSEd Tanous return 0; 1413cd7072bSEd Tanous } 142