| Ed Tanous | 2205bbf | 2021-06-17 13:33:47 -0700 | [diff] [blame] | 1 | #include <bmcweb_config.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 | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 4 | #include <app.hpp> | 
| Ed Tanous | 8f62635 | 2018-12-19 14:51:54 -0800 | [diff] [blame] | 5 | #include <boost/asio/io_context.hpp> | 
| Ed Tanous | 0260d9d | 2021-02-07 19:31:07 +0000 | [diff] [blame] | 6 | #include <cors_preflight.hpp> | 
| Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 7 | #include <dbus_monitor.hpp> | 
|  | 8 | #include <dbus_singleton.hpp> | 
| Feras Aldahlawi | 735ef6d | 2021-03-19 14:01:46 -0700 | [diff] [blame] | 9 | #include <google/google_service_root.hpp> | 
| Alan Kuo | a822070 | 2020-11-26 11:15:29 +0800 | [diff] [blame] | 10 | #include <hostname_monitor.hpp> | 
| Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 11 | #include <ibm/management_console_rest.hpp> | 
| Ed Tanous | c3ee522 | 2018-05-01 12:58:27 -0700 | [diff] [blame] | 12 | #include <image_upload.hpp> | 
| Ed Tanous | 3eb2f35 | 2018-12-20 12:30:45 -0800 | [diff] [blame] | 13 | #include <kvm_websocket.hpp> | 
| James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 14 | #include <login_routes.hpp> | 
| Ed Tanous | 7729513 | 2018-10-12 11:11:17 -0700 | [diff] [blame] | 15 | #include <obmc_console.hpp> | 
| Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 16 | #include <openbmc_dbus_rest.hpp> | 
| Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 17 | #include <redfish.hpp> | 
| Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 18 | #include <redfish_v1.hpp> | 
| Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 19 | #include <sdbusplus/asio/connection.hpp> | 
|  | 20 | #include <sdbusplus/bus.hpp> | 
|  | 21 | #include <sdbusplus/server.hpp> | 
| Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 22 | #include <security_headers.hpp> | 
| Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 23 | #include <ssl_key_handler.hpp> | 
| Adriana Kobylak | 1bfbe0e | 2019-01-17 12:08:38 -0600 | [diff] [blame] | 24 | #include <vm_websocket.hpp> | 
| Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 25 | #include <webassets.hpp> | 
| Ed Tanous | cc5a37f | 2017-05-11 10:27:23 -0700 | [diff] [blame] | 26 |  | 
| Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 27 | #include <memory> | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 28 | #include <string> | 
|  | 29 |  | 
| Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 30 | #ifdef BMCWEB_ENABLE_VM_NBDPROXY | 
|  | 31 | #include <nbd_proxy.hpp> | 
|  | 32 | #endif | 
|  | 33 |  | 
| Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 34 | constexpr int defaultPort = 18080; | 
|  | 35 |  | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 36 | inline void setupSocket(crow::App& app) | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 37 | { | 
|  | 38 | int listenFd = sd_listen_fds(0); | 
|  | 39 | if (1 == listenFd) | 
|  | 40 | { | 
|  | 41 | BMCWEB_LOG_INFO << "attempting systemd socket activation"; | 
|  | 42 | 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] | 43 | 0) != 0) | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 44 | { | 
|  | 45 | BMCWEB_LOG_INFO << "Starting webserver on socket handle " | 
|  | 46 | << SD_LISTEN_FDS_START; | 
|  | 47 | app.socket(SD_LISTEN_FDS_START); | 
|  | 48 | } | 
|  | 49 | else | 
|  | 50 | { | 
|  | 51 | BMCWEB_LOG_INFO | 
|  | 52 | << "bad incoming socket, starting webserver on port " | 
|  | 53 | << defaultPort; | 
|  | 54 | app.port(defaultPort); | 
|  | 55 | } | 
| Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 56 | } | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 57 | else | 
|  | 58 | { | 
|  | 59 | BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort; | 
|  | 60 | app.port(defaultPort); | 
|  | 61 | } | 
| Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 62 | } | 
|  | 63 |  | 
| Ed Tanous | 2119e27 | 2022-02-17 18:07:14 -0800 | [diff] [blame] | 64 | static int run() | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 65 | { | 
| Ed Tanous | eb643c2 | 2020-10-02 14:51:22 -0700 | [diff] [blame] | 66 | crow::Logger::setLogLevel(crow::LogLevel::Debug); | 
| Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 67 |  | 
| Ed Tanous | 8f62635 | 2018-12-19 14:51:54 -0800 | [diff] [blame] | 68 | auto io = std::make_shared<boost::asio::io_context>(); | 
| Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 69 | App app(io); | 
| Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 70 |  | 
| AppaRao Puli | f6f9719 | 2021-03-23 23:36:40 +0000 | [diff] [blame] | 71 | crow::connections::systemBus = | 
|  | 72 | std::make_shared<sdbusplus::asio::connection>(*io); | 
|  | 73 |  | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 74 | // Static assets need to be initialized before Authorization, because auth | 
|  | 75 | // needs to build the whitelist from the static routes | 
| Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 76 |  | 
| Andrew Geissler | d529ee2 | 2018-08-10 13:49:54 -0700 | [diff] [blame] | 77 | #ifdef BMCWEB_ENABLE_STATIC_HOSTING | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 78 | crow::webassets::requestRoutes(app); | 
| Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 79 | #endif | 
|  | 80 |  | 
|  | 81 | #ifdef BMCWEB_ENABLE_KVM | 
| Ed Tanous | 3eb2f35 | 2018-12-20 12:30:45 -0800 | [diff] [blame] | 82 | crow::obmc_kvm::requestRoutes(app); | 
| Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 83 | #endif | 
|  | 84 |  | 
|  | 85 | #ifdef BMCWEB_ENABLE_REDFISH | 
| Ed Tanous | 55b695f | 2021-03-24 08:39:26 -0700 | [diff] [blame] | 86 | redfish::requestRoutes(app); | 
| P Dheeraj Srujan Kumar | b614e2b | 2021-02-05 01:51:15 +0530 | [diff] [blame] | 87 | redfish::RedfishService redfish(app); | 
|  | 88 |  | 
|  | 89 | // Create EventServiceManager instance and initialize Config | 
|  | 90 | redfish::EventServiceManager::getInstance(); | 
| Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 91 | #endif | 
|  | 92 |  | 
|  | 93 | #ifdef BMCWEB_ENABLE_DBUS_REST | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 94 | crow::dbus_monitor::requestRoutes(app); | 
|  | 95 | crow::image_upload::requestRoutes(app); | 
|  | 96 | crow::openbmc_mapper::requestRoutes(app); | 
| Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 97 | #endif | 
|  | 98 |  | 
| Ed Tanous | 7729513 | 2018-10-12 11:11:17 -0700 | [diff] [blame] | 99 | #ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET | 
|  | 100 | crow::obmc_console::requestRoutes(app); | 
|  | 101 | #endif | 
|  | 102 |  | 
| Adriana Kobylak | 1bfbe0e | 2019-01-17 12:08:38 -0600 | [diff] [blame] | 103 | #ifdef BMCWEB_ENABLE_VM_WEBSOCKET | 
|  | 104 | crow::obmc_vm::requestRoutes(app); | 
|  | 105 | #endif | 
|  | 106 |  | 
| Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 107 | #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE | 
|  | 108 | crow::ibm_mc::requestRoutes(app); | 
| Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 109 | crow::ibm_mc_lock::Lock::getInstance(); | 
| Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 110 | #endif | 
|  | 111 |  | 
| Feras Aldahlawi | 735ef6d | 2021-03-19 14:01:46 -0700 | [diff] [blame] | 112 | #ifdef BMCWEB_ENABLE_GOOGLE_API | 
|  | 113 | crow::google_api::requestRoutes(app); | 
|  | 114 | #endif | 
|  | 115 |  | 
| Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 116 | if (bmcwebInsecureDisableXssPrevention != 0) | 
| Ed Tanous | 0260d9d | 2021-02-07 19:31:07 +0000 | [diff] [blame] | 117 | { | 
|  | 118 | cors_preflight::requestRoutes(app); | 
|  | 119 | } | 
| Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 120 |  | 
| James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 121 | crow::login_routes::requestRoutes(app); | 
| Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 122 |  | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 123 | setupSocket(app); | 
| Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 124 |  | 
| Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 125 | #ifdef BMCWEB_ENABLE_VM_NBDPROXY | 
|  | 126 | crow::nbd_proxy::requestRoutes(app); | 
|  | 127 | #endif | 
|  | 128 |  | 
| AppaRao Puli | 7f4eb58 | 2020-06-13 19:01:29 +0530 | [diff] [blame] | 129 | #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES | 
|  | 130 | int rc = redfish::EventServiceManager::startEventLogMonitor(*io); | 
| Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 131 | if (rc != 0) | 
| AppaRao Puli | 7f4eb58 | 2020-06-13 19:01:29 +0530 | [diff] [blame] | 132 | { | 
|  | 133 | BMCWEB_LOG_ERROR << "Redfish event handler setup failed..."; | 
|  | 134 | return rc; | 
|  | 135 | } | 
|  | 136 | #endif | 
|  | 137 |  | 
| Alan Kuo | a822070 | 2020-11-26 11:15:29 +0800 | [diff] [blame] | 138 | #ifdef BMCWEB_ENABLE_SSL | 
|  | 139 | BMCWEB_LOG_INFO << "Start Hostname Monitor Service..."; | 
|  | 140 | crow::hostname_monitor::registerHostnameSignal(); | 
|  | 141 | #endif | 
|  | 142 |  | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 143 | app.run(); | 
|  | 144 | io->run(); | 
| Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 145 |  | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 146 | crow::connections::systemBus.reset(); | 
| P Dheeraj Srujan Kumar | 85bf890 | 2021-07-12 21:07:36 +0530 | [diff] [blame] | 147 | return 0; | 
| Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 148 | } | 
| Ed Tanous | 24b2fe8 | 2022-01-06 12:45:54 -0800 | [diff] [blame] | 149 |  | 
|  | 150 | int main(int /*argc*/, char** /*argv*/) | 
|  | 151 | { | 
|  | 152 | try | 
|  | 153 | { | 
|  | 154 | return run(); | 
|  | 155 | } | 
|  | 156 | catch (...) | 
|  | 157 | { | 
|  | 158 | return -1; | 
|  | 159 | BMCWEB_LOG_CRITICAL << "Threw exception to main"; | 
|  | 160 | } | 
|  | 161 | } |