Ed Tanous | c94ad49 | 2019-10-10 15:39:33 -0700 | [diff] [blame] | 1 | #include <app.h> |
Ed Tanous | 9e6e1b2 | 2018-03-16 13:08:50 -0700 | [diff] [blame] | 2 | #include <systemd/sd-daemon.h> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 3 | |
Ed Tanous | 8f62635 | 2018-12-19 14:51:54 -0800 | [diff] [blame] | 4 | #include <boost/asio/io_context.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 5 | #include <dbus_monitor.hpp> |
| 6 | #include <dbus_singleton.hpp> |
Ed Tanous | c3ee522 | 2018-05-01 12:58:27 -0700 | [diff] [blame] | 7 | #include <image_upload.hpp> |
Ed Tanous | 3eb2f35 | 2018-12-20 12:30:45 -0800 | [diff] [blame] | 8 | #include <kvm_websocket.hpp> |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame^] | 9 | #include <login_routes.hpp> |
Ed Tanous | 7729513 | 2018-10-12 11:11:17 -0700 | [diff] [blame] | 10 | #include <obmc_console.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 11 | #include <openbmc_dbus_rest.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 12 | |
| 13 | #include <memory> |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 14 | #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE |
| 15 | #include <ibm/management_console_rest.hpp> |
| 16 | #endif |
Ed Tanous | ba9f9a6 | 2017-10-11 16:40:35 -0700 | [diff] [blame] | 17 | #include <persistent_data_middleware.hpp> |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 18 | #include <redfish.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 19 | #include <redfish_v1.hpp> |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 20 | #include <sdbusplus/asio/connection.hpp> |
| 21 | #include <sdbusplus/bus.hpp> |
| 22 | #include <sdbusplus/server.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 23 | #include <security_headers_middleware.hpp> |
| 24 | #include <ssl_key_handler.hpp> |
Adriana Kobylak | 1bfbe0e | 2019-01-17 12:08:38 -0600 | [diff] [blame] | 25 | #include <vm_websocket.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 26 | #include <webassets.hpp> |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 27 | #include <webserver_common.hpp> |
Ed Tanous | cc5a37f | 2017-05-11 10:27:23 -0700 | [diff] [blame] | 28 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 29 | #include <string> |
| 30 | |
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 31 | #ifdef BMCWEB_ENABLE_VM_NBDPROXY |
| 32 | #include <nbd_proxy.hpp> |
| 33 | #endif |
| 34 | |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 35 | constexpr int defaultPort = 18080; |
| 36 | |
| 37 | template <typename... Middlewares> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 38 | void setupSocket(crow::Crow<Middlewares...>& app) |
| 39 | { |
| 40 | int listenFd = sd_listen_fds(0); |
| 41 | if (1 == listenFd) |
| 42 | { |
| 43 | BMCWEB_LOG_INFO << "attempting systemd socket activation"; |
| 44 | if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, |
| 45 | 0)) |
| 46 | { |
| 47 | BMCWEB_LOG_INFO << "Starting webserver on socket handle " |
| 48 | << SD_LISTEN_FDS_START; |
| 49 | app.socket(SD_LISTEN_FDS_START); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | BMCWEB_LOG_INFO |
| 54 | << "bad incoming socket, starting webserver on port " |
| 55 | << defaultPort; |
| 56 | app.port(defaultPort); |
| 57 | } |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 58 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 59 | else |
| 60 | { |
| 61 | BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort; |
| 62 | app.port(defaultPort); |
| 63 | } |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 66 | int main(int argc, char** argv) |
| 67 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 68 | crow::logger::setLogLevel(crow::LogLevel::Debug); |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 69 | |
Ed Tanous | 8f62635 | 2018-12-19 14:51:54 -0800 | [diff] [blame] | 70 | auto io = std::make_shared<boost::asio::io_context>(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 71 | CrowApp app(io); |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 72 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 73 | // Static assets need to be initialized before Authorization, because auth |
| 74 | // needs to build the whitelist from the static routes |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 75 | |
Andrew Geissler | d529ee2 | 2018-08-10 13:49:54 -0700 | [diff] [blame] | 76 | #ifdef BMCWEB_ENABLE_STATIC_HOSTING |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 77 | crow::webassets::requestRoutes(app); |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 78 | #endif |
| 79 | |
| 80 | #ifdef BMCWEB_ENABLE_KVM |
Ed Tanous | 3eb2f35 | 2018-12-20 12:30:45 -0800 | [diff] [blame] | 81 | crow::obmc_kvm::requestRoutes(app); |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 82 | #endif |
| 83 | |
| 84 | #ifdef BMCWEB_ENABLE_REDFISH |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 85 | crow::redfish::requestRoutes(app); |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 86 | #endif |
| 87 | |
| 88 | #ifdef BMCWEB_ENABLE_DBUS_REST |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 89 | crow::dbus_monitor::requestRoutes(app); |
| 90 | crow::image_upload::requestRoutes(app); |
| 91 | crow::openbmc_mapper::requestRoutes(app); |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 92 | #endif |
| 93 | |
Ed Tanous | 7729513 | 2018-10-12 11:11:17 -0700 | [diff] [blame] | 94 | #ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET |
| 95 | crow::obmc_console::requestRoutes(app); |
| 96 | #endif |
| 97 | |
Adriana Kobylak | 1bfbe0e | 2019-01-17 12:08:38 -0600 | [diff] [blame] | 98 | #ifdef BMCWEB_ENABLE_VM_WEBSOCKET |
| 99 | crow::obmc_vm::requestRoutes(app); |
| 100 | #endif |
| 101 | |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 102 | #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE |
| 103 | crow::ibm_mc::requestRoutes(app); |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 104 | crow::ibm_mc_lock::Lock::getInstance(); |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 105 | #endif |
| 106 | |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame^] | 107 | crow::login_routes::requestRoutes(app); |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 108 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 109 | BMCWEB_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')'; |
| 110 | setupSocket(app); |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 111 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 112 | crow::connections::systemBus = |
| 113 | std::make_shared<sdbusplus::asio::connection>(*io); |
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 114 | |
| 115 | #ifdef BMCWEB_ENABLE_VM_NBDPROXY |
| 116 | crow::nbd_proxy::requestRoutes(app); |
| 117 | #endif |
| 118 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 119 | redfish::RedfishService redfish(app); |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 120 | |
AppaRao Puli | 7f4eb58 | 2020-06-13 19:01:29 +0530 | [diff] [blame] | 121 | #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES |
| 122 | int rc = redfish::EventServiceManager::startEventLogMonitor(*io); |
| 123 | if (rc) |
| 124 | { |
| 125 | BMCWEB_LOG_ERROR << "Redfish event handler setup failed..."; |
| 126 | return rc; |
| 127 | } |
| 128 | #endif |
| 129 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 130 | app.run(); |
| 131 | io->run(); |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 132 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 133 | crow::connections::systemBus.reset(); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 134 | } |