1 #include <crow/app.h> 2 #include <systemd/sd-daemon.h> 3 4 #include <bmcweb/settings.hpp> 5 #include <boost/asio.hpp> 6 #include <dbus_monitor.hpp> 7 #include <dbus_singleton.hpp> 8 #include <image_upload.hpp> 9 #include <memory> 10 #include <openbmc_dbus_rest.hpp> 11 #include <persistent_data_middleware.hpp> 12 #include <redfish.hpp> 13 #include <redfish_v1.hpp> 14 #include <sdbusplus/asio/connection.hpp> 15 #include <sdbusplus/bus.hpp> 16 #include <sdbusplus/server.hpp> 17 #include <security_headers_middleware.hpp> 18 #include <ssl_key_handler.hpp> 19 #include <string> 20 #include <token_authorization_middleware.hpp> 21 #include <web_kvm.hpp> 22 #include <webassets.hpp> 23 #include <webserver_common.hpp> 24 25 constexpr int defaultPort = 18080; 26 27 template <typename... Middlewares> 28 void setupSocket(crow::Crow<Middlewares...>& app) 29 { 30 int listenFd = sd_listen_fds(0); 31 if (1 == listenFd) 32 { 33 BMCWEB_LOG_INFO << "attempting systemd socket activation"; 34 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, 35 0)) 36 { 37 BMCWEB_LOG_INFO << "Starting webserver on socket handle " 38 << SD_LISTEN_FDS_START; 39 app.socket(SD_LISTEN_FDS_START); 40 } 41 else 42 { 43 BMCWEB_LOG_INFO 44 << "bad incoming socket, starting webserver on port " 45 << defaultPort; 46 app.port(defaultPort); 47 } 48 } 49 else 50 { 51 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort; 52 app.port(defaultPort); 53 } 54 } 55 56 int main(int argc, char** argv) 57 { 58 crow::logger::setLogLevel(crow::LogLevel::DEBUG); 59 60 auto io = std::make_shared<boost::asio::io_service>(); 61 CrowApp app(io); 62 63 #ifdef BMCWEB_ENABLE_SSL 64 std::string sslPemFile("server.pem"); 65 std::cout << "Building SSL Context\n"; 66 67 ensuressl::ensureOpensslKeyPresentAndValid(sslPemFile); 68 std::cout << "SSL Enabled\n"; 69 auto sslContext = ensuressl::getSslContext(sslPemFile); 70 app.ssl(std::move(sslContext)); 71 #endif 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::kvm::requestRoutes(app); 81 #endif 82 83 #ifdef BMCWEB_ENABLE_REDFISH 84 crow::redfish::requestRoutes(app); 85 #endif 86 87 #ifdef BMCWEB_ENABLE_DBUS_REST 88 crow::dbus_monitor::requestRoutes(app); 89 crow::image_upload::requestRoutes(app); 90 crow::openbmc_mapper::requestRoutes(app); 91 #endif 92 93 crow::token_authorization::requestRoutes(app); 94 95 BMCWEB_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')'; 96 setupSocket(app); 97 98 crow::connections::systemBus = 99 std::make_shared<sdbusplus::asio::connection>(*io); 100 redfish::RedfishService redfish(app); 101 102 app.run(); 103 io->run(); 104 105 crow::connections::systemBus.reset(); 106 } 107