Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 1 | #include "bmcweb_config.h" |
| 2 | |
| 3 | #include "app.hpp" |
| 4 | #include "cors_preflight.hpp" |
| 5 | #include "dbus_monitor.hpp" |
| 6 | #include "dbus_singleton.hpp" |
Ed Tanous | faf100f | 2023-05-25 10:03:14 -0700 | [diff] [blame] | 7 | #include "google/google_service_root.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 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 "nbd_proxy.hpp" |
| 14 | #include "obmc_console.hpp" |
| 15 | #include "openbmc_dbus_rest.hpp" |
| 16 | #include "redfish.hpp" |
| 17 | #include "redfish_aggregator.hpp" |
| 18 | #include "security_headers.hpp" |
| 19 | #include "ssl_key_handler.hpp" |
Xie Ning | 9fa06f1 | 2022-06-29 18:27:47 +0800 | [diff] [blame] | 20 | #include "user_monitor.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 21 | #include "vm_websocket.hpp" |
| 22 | #include "webassets.hpp" |
| 23 | |
Ed Tanous | 9e6e1b2 | 2018-03-16 13:08:50 -0700 | [diff] [blame] | 24 | #include <systemd/sd-daemon.h> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 25 | |
Ed Tanous | 8f62635 | 2018-12-19 14:51:54 -0800 | [diff] [blame] | 26 | #include <boost/asio/io_context.hpp> |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 27 | #include <sdbusplus/asio/connection.hpp> |
| 28 | #include <sdbusplus/bus.hpp> |
| 29 | #include <sdbusplus/server.hpp> |
Ed Tanous | cc5a37f | 2017-05-11 10:27:23 -0700 | [diff] [blame] | 30 | |
Josh Lehan | 45248ba | 2022-07-14 14:03:29 -0700 | [diff] [blame] | 31 | #include <exception> |
Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 32 | #include <memory> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 33 | #include <string> |
| 34 | |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 35 | constexpr int defaultPort = 18080; |
| 36 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 37 | inline void setupSocket(crow::App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 38 | { |
| 39 | int listenFd = sd_listen_fds(0); |
| 40 | if (1 == listenFd) |
| 41 | { |
| 42 | BMCWEB_LOG_INFO << "attempting systemd socket activation"; |
| 43 | if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 44 | 0) != 0) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 45 | { |
| 46 | BMCWEB_LOG_INFO << "Starting webserver on socket handle " |
| 47 | << SD_LISTEN_FDS_START; |
| 48 | app.socket(SD_LISTEN_FDS_START); |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | BMCWEB_LOG_INFO |
| 53 | << "bad incoming socket, starting webserver on port " |
| 54 | << defaultPort; |
| 55 | app.port(defaultPort); |
| 56 | } |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 57 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 58 | else |
| 59 | { |
| 60 | BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort; |
| 61 | app.port(defaultPort); |
| 62 | } |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Ed Tanous | 2119e27 | 2022-02-17 18:07:14 -0800 | [diff] [blame] | 65 | static int run() |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 66 | { |
Ed Tanous | 8f62635 | 2018-12-19 14:51:54 -0800 | [diff] [blame] | 67 | auto io = std::make_shared<boost::asio::io_context>(); |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 68 | App app(io); |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 69 | |
Nan Zhou | 6384e32 | 2022-06-23 22:28:25 +0000 | [diff] [blame] | 70 | sdbusplus::asio::connection systemBus(*io); |
| 71 | crow::connections::systemBus = &systemBus; |
AppaRao Puli | f6f9719 | 2021-03-23 23:36:40 +0000 | [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 |
P Dheeraj Srujan Kumar | b614e2b | 2021-02-05 01:51:15 +0530 | [diff] [blame] | 85 | redfish::RedfishService redfish(app); |
| 86 | |
| 87 | // Create EventServiceManager instance and initialize Config |
Ed Tanous | f8ca6d7 | 2022-06-28 12:12:03 -0700 | [diff] [blame] | 88 | redfish::EventServiceManager::getInstance(&*io); |
Carson Labrado | 7fb3356 | 2022-04-18 23:26:56 +0000 | [diff] [blame] | 89 | |
| 90 | #ifdef BMCWEB_ENABLE_REDFISH_AGGREGATION |
| 91 | // Create RedfishAggregator instance and initialize Config |
Ed Tanous | f8ca6d7 | 2022-06-28 12:12:03 -0700 | [diff] [blame] | 92 | redfish::RedfishAggregator::getInstance(&*io); |
Carson Labrado | 7fb3356 | 2022-04-18 23:26:56 +0000 | [diff] [blame] | 93 | #endif |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 94 | #endif |
| 95 | |
| 96 | #ifdef BMCWEB_ENABLE_DBUS_REST |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 97 | crow::dbus_monitor::requestRoutes(app); |
| 98 | crow::image_upload::requestRoutes(app); |
| 99 | crow::openbmc_mapper::requestRoutes(app); |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 100 | #endif |
| 101 | |
Ed Tanous | 7729513 | 2018-10-12 11:11:17 -0700 | [diff] [blame] | 102 | #ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET |
| 103 | crow::obmc_console::requestRoutes(app); |
| 104 | #endif |
| 105 | |
Adriana Kobylak | 1bfbe0e | 2019-01-17 12:08:38 -0600 | [diff] [blame] | 106 | #ifdef BMCWEB_ENABLE_VM_WEBSOCKET |
| 107 | crow::obmc_vm::requestRoutes(app); |
| 108 | #endif |
| 109 | |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 110 | #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE |
| 111 | crow::ibm_mc::requestRoutes(app); |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 112 | crow::ibm_mc_lock::Lock::getInstance(); |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 113 | #endif |
| 114 | |
Feras Aldahlawi | 735ef6d | 2021-03-19 14:01:46 -0700 | [diff] [blame] | 115 | #ifdef BMCWEB_ENABLE_GOOGLE_API |
| 116 | crow::google_api::requestRoutes(app); |
| 117 | #endif |
| 118 | |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 119 | if (bmcwebInsecureDisableXssPrevention != 0) |
Ed Tanous | 0260d9d | 2021-02-07 19:31:07 +0000 | [diff] [blame] | 120 | { |
| 121 | cors_preflight::requestRoutes(app); |
| 122 | } |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 123 | |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 124 | crow::login_routes::requestRoutes(app); |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 125 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 126 | setupSocket(app); |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 127 | |
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 128 | #ifdef BMCWEB_ENABLE_VM_NBDPROXY |
| 129 | crow::nbd_proxy::requestRoutes(app); |
| 130 | #endif |
| 131 | |
AppaRao Puli | 7f4eb58 | 2020-06-13 19:01:29 +0530 | [diff] [blame] | 132 | #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES |
| 133 | int rc = redfish::EventServiceManager::startEventLogMonitor(*io); |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 134 | if (rc != 0) |
AppaRao Puli | 7f4eb58 | 2020-06-13 19:01:29 +0530 | [diff] [blame] | 135 | { |
| 136 | BMCWEB_LOG_ERROR << "Redfish event handler setup failed..."; |
| 137 | return rc; |
| 138 | } |
| 139 | #endif |
| 140 | |
Alan Kuo | a822070 | 2020-11-26 11:15:29 +0800 | [diff] [blame] | 141 | #ifdef BMCWEB_ENABLE_SSL |
| 142 | BMCWEB_LOG_INFO << "Start Hostname Monitor Service..."; |
| 143 | crow::hostname_monitor::registerHostnameSignal(); |
| 144 | #endif |
| 145 | |
Xie Ning | 9fa06f1 | 2022-06-29 18:27:47 +0800 | [diff] [blame] | 146 | bmcweb::registerUserRemovedSignal(); |
| 147 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 148 | app.run(); |
| 149 | io->run(); |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 150 | |
Nan Zhou | 6384e32 | 2022-06-23 22:28:25 +0000 | [diff] [blame] | 151 | crow::connections::systemBus = nullptr; |
| 152 | |
P Dheeraj Srujan Kumar | 85bf890 | 2021-07-12 21:07:36 +0530 | [diff] [blame] | 153 | return 0; |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 154 | } |
Ed Tanous | 24b2fe8 | 2022-01-06 12:45:54 -0800 | [diff] [blame] | 155 | |
| 156 | int main(int /*argc*/, char** /*argv*/) |
| 157 | { |
| 158 | try |
| 159 | { |
| 160 | return run(); |
| 161 | } |
Josh Lehan | 45248ba | 2022-07-14 14:03:29 -0700 | [diff] [blame] | 162 | catch (const std::exception& e) |
| 163 | { |
| 164 | BMCWEB_LOG_CRITICAL << "Threw exception to main: " << e.what(); |
| 165 | return -1; |
| 166 | } |
Ed Tanous | 24b2fe8 | 2022-01-06 12:45:54 -0800 | [diff] [blame] | 167 | catch (...) |
| 168 | { |
Ed Tanous | 24b2fe8 | 2022-01-06 12:45:54 -0800 | [diff] [blame] | 169 | BMCWEB_LOG_CRITICAL << "Threw exception to main"; |
Ed Tanous | 6f2cd97 | 2022-06-30 18:09:06 -0700 | [diff] [blame] | 170 | return -1; |
Ed Tanous | 24b2fe8 | 2022-01-06 12:45:54 -0800 | [diff] [blame] | 171 | } |
| 172 | } |