1 #include <systemd/sd-daemon.h> 2 3 #include <app.hpp> 4 #include <boost/asio/io_context.hpp> 5 #include <cors_preflight.hpp> 6 #include <dbus_monitor.hpp> 7 #include <dbus_singleton.hpp> 8 #include <hostname_monitor.hpp> 9 #include <ibm/management_console_rest.hpp> 10 #include <image_upload.hpp> 11 #include <kvm_websocket.hpp> 12 #include <login_routes.hpp> 13 #include <obmc_console.hpp> 14 #include <openbmc_dbus_rest.hpp> 15 #include <redfish.hpp> 16 #include <redfish_v1.hpp> 17 #include <sdbusplus/asio/connection.hpp> 18 #include <sdbusplus/bus.hpp> 19 #include <sdbusplus/server.hpp> 20 #include <security_headers.hpp> 21 #include <ssl_key_handler.hpp> 22 #include <vm_websocket.hpp> 23 #include <webassets.hpp> 24 25 #include <memory> 26 #include <string> 27 28 #ifdef BMCWEB_ENABLE_VM_NBDPROXY 29 #include <nbd_proxy.hpp> 30 #endif 31 32 constexpr int defaultPort = 18080; 33 34 inline void setupSocket(crow::App& app) 35 { 36 int listenFd = sd_listen_fds(0); 37 if (1 == listenFd) 38 { 39 BMCWEB_LOG_INFO << "attempting systemd socket activation"; 40 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, 41 0)) 42 { 43 BMCWEB_LOG_INFO << "Starting webserver on socket handle " 44 << SD_LISTEN_FDS_START; 45 app.socket(SD_LISTEN_FDS_START); 46 } 47 else 48 { 49 BMCWEB_LOG_INFO 50 << "bad incoming socket, starting webserver on port " 51 << defaultPort; 52 app.port(defaultPort); 53 } 54 } 55 else 56 { 57 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort; 58 app.port(defaultPort); 59 } 60 } 61 62 int main(int /*argc*/, char** /*argv*/) 63 { 64 crow::Logger::setLogLevel(crow::LogLevel::Debug); 65 66 auto io = std::make_shared<boost::asio::io_context>(); 67 App app(io); 68 69 crow::connections::systemBus = 70 std::make_shared<sdbusplus::asio::connection>(*io); 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::requestRoutes(app); 85 redfish::RedfishService redfish(app); 86 87 // Create EventServiceManager instance and initialize Config 88 redfish::EventServiceManager::getInstance(); 89 #endif 90 91 #ifdef BMCWEB_ENABLE_DBUS_REST 92 crow::dbus_monitor::requestRoutes(app); 93 crow::image_upload::requestRoutes(app); 94 crow::openbmc_mapper::requestRoutes(app); 95 #endif 96 97 #ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET 98 crow::obmc_console::requestRoutes(app); 99 #endif 100 101 #ifdef BMCWEB_ENABLE_VM_WEBSOCKET 102 crow::obmc_vm::requestRoutes(app); 103 #endif 104 105 #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE 106 crow::ibm_mc::requestRoutes(app); 107 crow::ibm_mc_lock::Lock::getInstance(); 108 #endif 109 110 if (bmcwebInsecureDisableXssPrevention) 111 { 112 cors_preflight::requestRoutes(app); 113 } 114 115 crow::login_routes::requestRoutes(app); 116 117 setupSocket(app); 118 119 #ifdef BMCWEB_ENABLE_VM_NBDPROXY 120 crow::nbd_proxy::requestRoutes(app); 121 #endif 122 123 #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES 124 int rc = redfish::EventServiceManager::startEventLogMonitor(*io); 125 if (rc) 126 { 127 BMCWEB_LOG_ERROR << "Redfish event handler setup failed..."; 128 return rc; 129 } 130 #endif 131 132 #ifdef BMCWEB_ENABLE_SSL 133 BMCWEB_LOG_INFO << "Start Hostname Monitor Service..."; 134 crow::hostname_monitor::registerHostnameSignal(); 135 #endif 136 137 app.run(); 138 io->run(); 139 140 crow::connections::systemBus.reset(); 141 } 142