1 #include "webserver_run.hpp" 2 3 #include "bmcweb_config.h" 4 5 #include "app.hpp" 6 #include "cors_preflight.hpp" 7 #include "dbus_monitor.hpp" 8 #include "dbus_singleton.hpp" 9 #include "event_service_manager.hpp" 10 #include "google/google_service_root.hpp" 11 #include "hostname_monitor.hpp" 12 #include "ibm/management_console_rest.hpp" 13 #include "image_upload.hpp" 14 #include "kvm_websocket.hpp" 15 #include "login_routes.hpp" 16 #include "nbd_proxy.hpp" 17 #include "obmc_console.hpp" 18 #include "openbmc_dbus_rest.hpp" 19 #include "redfish.hpp" 20 #include "redfish_aggregator.hpp" 21 #include "security_headers.hpp" 22 #include "ssl_key_handler.hpp" 23 #include "user_monitor.hpp" 24 #include "vm_websocket.hpp" 25 #include "webassets.hpp" 26 27 #include <systemd/sd-daemon.h> 28 29 #include <boost/asio/io_context.hpp> 30 #include <sdbusplus/asio/connection.hpp> 31 #include <sdbusplus/bus.hpp> 32 #include <sdbusplus/server.hpp> 33 34 constexpr int defaultPort = 18080; 35 36 static void setupSocket(crow::App& app) 37 { 38 int listenFd = sd_listen_fds(0); 39 if (1 == listenFd) 40 { 41 BMCWEB_LOG_INFO("attempting systemd socket activation"); 42 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, 43 0) != 0) 44 { 45 BMCWEB_LOG_INFO("Starting webserver on socket handle {}", 46 SD_LISTEN_FDS_START); 47 app.socket(SD_LISTEN_FDS_START); 48 } 49 else 50 { 51 BMCWEB_LOG_INFO( 52 "bad incoming socket, starting webserver on port {}", 53 defaultPort); 54 app.port(defaultPort); 55 } 56 } 57 else 58 { 59 BMCWEB_LOG_INFO("Starting webserver on port {}", defaultPort); 60 app.port(defaultPort); 61 } 62 } 63 64 int run() 65 { 66 auto io = std::make_shared<boost::asio::io_context>(); 67 App app(io); 68 69 sdbusplus::asio::connection systemBus(*io); 70 crow::connections::systemBus = &systemBus; 71 72 // Static assets need to be initialized before Authorization, because auth 73 // needs to build the whitelist from the static routes 74 75 #ifdef BMCWEB_ENABLE_STATIC_HOSTING 76 crow::webassets::requestRoutes(app); 77 #endif 78 79 #ifdef BMCWEB_ENABLE_KVM 80 crow::obmc_kvm::requestRoutes(app); 81 #endif 82 83 #ifdef BMCWEB_ENABLE_REDFISH 84 redfish::RedfishService redfish(app); 85 86 // Create EventServiceManager instance and initialize Config 87 redfish::EventServiceManager::getInstance(&*io); 88 89 #ifdef BMCWEB_ENABLE_REDFISH_AGGREGATION 90 // Create RedfishAggregator instance and initialize Config 91 redfish::RedfishAggregator::getInstance(&*io); 92 #endif 93 #endif 94 95 #ifdef BMCWEB_ENABLE_DBUS_REST 96 crow::dbus_monitor::requestRoutes(app); 97 crow::image_upload::requestRoutes(app); 98 crow::openbmc_mapper::requestRoutes(app); 99 #endif 100 101 #ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET 102 crow::obmc_console::requestRoutes(app); 103 #endif 104 105 #ifdef BMCWEB_ENABLE_VM_WEBSOCKET 106 crow::obmc_vm::requestRoutes(app); 107 #endif 108 109 #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE 110 crow::ibm_mc::requestRoutes(app); 111 crow::ibm_mc_lock::Lock::getInstance(); 112 #endif 113 114 #ifdef BMCWEB_ENABLE_GOOGLE_API 115 crow::google_api::requestRoutes(app); 116 #endif 117 118 if (bmcwebInsecureDisableXssPrevention != 0) 119 { 120 cors_preflight::requestRoutes(app); 121 } 122 123 crow::login_routes::requestRoutes(app); 124 125 setupSocket(app); 126 127 #ifdef BMCWEB_ENABLE_VM_NBDPROXY 128 crow::nbd_proxy::requestRoutes(app); 129 #endif 130 131 #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES 132 int rc = redfish::EventServiceManager::startEventLogMonitor(*io); 133 if (rc != 0) 134 { 135 BMCWEB_LOG_ERROR("Redfish event handler setup failed..."); 136 return rc; 137 } 138 #endif 139 140 #ifdef BMCWEB_ENABLE_SSL 141 BMCWEB_LOG_INFO("Start Hostname Monitor Service..."); 142 crow::hostname_monitor::registerHostnameSignal(); 143 #endif 144 145 bmcweb::registerUserRemovedSignal(); 146 147 app.run(); 148 io->run(); 149 150 crow::connections::systemBus = nullptr; 151 152 return 0; 153 } 154