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 <memory> 10 #include <obmc_console.hpp> 11 #include <openbmc_dbus_rest.hpp> 12 #include <persistent_data_middleware.hpp> 13 #include <redfish.hpp> 14 #include <redfish_v1.hpp> 15 #include <sdbusplus/asio/connection.hpp> 16 #include <sdbusplus/bus.hpp> 17 #include <sdbusplus/server.hpp> 18 #include <security_headers_middleware.hpp> 19 #include <ssl_key_handler.hpp> 20 #include <string> 21 #include <token_authorization_middleware.hpp> 22 #include <vm_websocket.hpp> 23 #include <webassets.hpp> 24 #include <webserver_common.hpp> 25 26 #ifdef BMCWEB_ENABLE_VM_NBDPROXY 27 #include <nbd_proxy.hpp> 28 #endif 29 30 constexpr int defaultPort = 18080; 31 32 template <typename... Middlewares> 33 void setupSocket(crow::Crow<Middlewares...>& app) 34 { 35 int listenFd = sd_listen_fds(0); 36 if (1 == listenFd) 37 { 38 BMCWEB_LOG_INFO << "attempting systemd socket activation"; 39 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, 40 0)) 41 { 42 BMCWEB_LOG_INFO << "Starting webserver on socket handle " 43 << SD_LISTEN_FDS_START; 44 app.socket(SD_LISTEN_FDS_START); 45 } 46 else 47 { 48 BMCWEB_LOG_INFO 49 << "bad incoming socket, starting webserver on port " 50 << defaultPort; 51 app.port(defaultPort); 52 } 53 } 54 else 55 { 56 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort; 57 app.port(defaultPort); 58 } 59 } 60 61 int main(int argc, char** argv) 62 { 63 crow::logger::setLogLevel(crow::LogLevel::Debug); 64 65 auto io = std::make_shared<boost::asio::io_context>(); 66 CrowApp app(io); 67 68 // Static assets need to be initialized before Authorization, because auth 69 // needs to build the whitelist from the static routes 70 71 #ifdef BMCWEB_ENABLE_STATIC_HOSTING 72 crow::webassets::requestRoutes(app); 73 #endif 74 75 #ifdef BMCWEB_ENABLE_KVM 76 crow::obmc_kvm::requestRoutes(app); 77 #endif 78 79 #ifdef BMCWEB_ENABLE_REDFISH 80 crow::redfish::requestRoutes(app); 81 #endif 82 83 #ifdef BMCWEB_ENABLE_DBUS_REST 84 crow::dbus_monitor::requestRoutes(app); 85 crow::image_upload::requestRoutes(app); 86 crow::openbmc_mapper::requestRoutes(app); 87 #endif 88 89 #ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET 90 crow::obmc_console::requestRoutes(app); 91 #endif 92 93 #ifdef BMCWEB_ENABLE_VM_WEBSOCKET 94 crow::obmc_vm::requestRoutes(app); 95 #endif 96 97 crow::token_authorization::requestRoutes(app); 98 99 BMCWEB_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')'; 100 setupSocket(app); 101 102 crow::connections::systemBus = 103 std::make_shared<sdbusplus::asio::connection>(*io); 104 105 #ifdef BMCWEB_ENABLE_VM_NBDPROXY 106 crow::nbd_proxy::requestRoutes(app); 107 #endif 108 109 redfish::RedfishService redfish(app); 110 111 app.run(); 112 io->run(); 113 114 crow::connections::systemBus.reset(); 115 } 116