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