blob: eaedc1189ecc4a7e3d26785e647005529fe68a58 [file] [log] [blame]
Ed Tanous2205bbf2021-06-17 13:33:47 -07001#include <bmcweb_config.h>
Ed Tanous9e6e1b22018-03-16 13:08:50 -07002#include <systemd/sd-daemon.h>
Ed Tanous1abe55e2018-09-05 08:30:59 -07003
Ed Tanous04e438c2020-10-03 08:06:26 -07004#include <app.hpp>
Ed Tanous8f626352018-12-19 14:51:54 -08005#include <boost/asio/io_context.hpp>
Ed Tanous0260d9d2021-02-07 19:31:07 +00006#include <cors_preflight.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07007#include <dbus_monitor.hpp>
8#include <dbus_singleton.hpp>
Alan Kuoa8220702020-11-26 11:15:29 +08009#include <hostname_monitor.hpp>
Ed Tanous02379d32020-09-15 21:15:44 -070010#include <ibm/management_console_rest.hpp>
Ed Tanousc3ee5222018-05-01 12:58:27 -070011#include <image_upload.hpp>
Ed Tanous3eb2f352018-12-20 12:30:45 -080012#include <kvm_websocket.hpp>
James Feist3909dc82020-04-03 10:58:55 -070013#include <login_routes.hpp>
Ed Tanous77295132018-10-12 11:11:17 -070014#include <obmc_console.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070015#include <openbmc_dbus_rest.hpp>
Ed Tanous1e439872018-05-18 11:48:52 -070016#include <redfish.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070017#include <redfish_v1.hpp>
Ed Tanousaa2e59c2018-04-12 12:17:20 -070018#include <sdbusplus/asio/connection.hpp>
19#include <sdbusplus/bus.hpp>
20#include <sdbusplus/server.hpp>
Ed Tanous52cc1122020-07-18 13:51:21 -070021#include <security_headers.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070022#include <ssl_key_handler.hpp>
Adriana Kobylak1bfbe0e2019-01-17 12:08:38 -060023#include <vm_websocket.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070024#include <webassets.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070025
Ed Tanous02379d32020-09-15 21:15:44 -070026#include <memory>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050027#include <string>
28
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +020029#ifdef BMCWEB_ENABLE_VM_NBDPROXY
30#include <nbd_proxy.hpp>
31#endif
32
Vernon Mauery168792a2018-01-26 13:42:54 -080033constexpr int defaultPort = 18080;
34
Ed Tanous23a21a12020-07-25 04:45:05 +000035inline void setupSocket(crow::App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -070036{
37 int listenFd = sd_listen_fds(0);
38 if (1 == listenFd)
39 {
40 BMCWEB_LOG_INFO << "attempting systemd socket activation";
41 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1,
42 0))
43 {
44 BMCWEB_LOG_INFO << "Starting webserver on socket handle "
45 << SD_LISTEN_FDS_START;
46 app.socket(SD_LISTEN_FDS_START);
47 }
48 else
49 {
50 BMCWEB_LOG_INFO
51 << "bad incoming socket, starting webserver on port "
52 << defaultPort;
53 app.port(defaultPort);
54 }
Vernon Mauery168792a2018-01-26 13:42:54 -080055 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070056 else
57 {
58 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort;
59 app.port(defaultPort);
60 }
Vernon Mauery168792a2018-01-26 13:42:54 -080061}
62
Ed Tanouscb13a392020-07-25 19:02:03 +000063int main(int /*argc*/, char** /*argv*/)
Ed Tanous1abe55e2018-09-05 08:30:59 -070064{
Ed Tanouseb643c22020-10-02 14:51:22 -070065 crow::Logger::setLogLevel(crow::LogLevel::Debug);
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010066
Ed Tanous8f626352018-12-19 14:51:54 -080067 auto io = std::make_shared<boost::asio::io_context>();
Ed Tanous52cc1122020-07-18 13:51:21 -070068 App app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070069
AppaRao Pulif6f97192021-03-23 23:36:40 +000070 crow::connections::systemBus =
71 std::make_shared<sdbusplus::asio::connection>(*io);
72
Ed Tanous1abe55e2018-09-05 08:30:59 -070073 // Static assets need to be initialized before Authorization, because auth
74 // needs to build the whitelist from the static routes
Ed Tanousf0226cd2017-05-16 12:35:38 -070075
Andrew Geisslerd529ee22018-08-10 13:49:54 -070076#ifdef BMCWEB_ENABLE_STATIC_HOSTING
Ed Tanous1abe55e2018-09-05 08:30:59 -070077 crow::webassets::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070078#endif
79
80#ifdef BMCWEB_ENABLE_KVM
Ed Tanous3eb2f352018-12-20 12:30:45 -080081 crow::obmc_kvm::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070082#endif
83
84#ifdef BMCWEB_ENABLE_REDFISH
Ed Tanous55b695f2021-03-24 08:39:26 -070085 redfish::requestRoutes(app);
P Dheeraj Srujan Kumarb614e2b2021-02-05 01:51:15 +053086 redfish::RedfishService redfish(app);
87
88 // Create EventServiceManager instance and initialize Config
89 redfish::EventServiceManager::getInstance();
Ed Tanous1e439872018-05-18 11:48:52 -070090#endif
91
92#ifdef BMCWEB_ENABLE_DBUS_REST
Ed Tanous1abe55e2018-09-05 08:30:59 -070093 crow::dbus_monitor::requestRoutes(app);
94 crow::image_upload::requestRoutes(app);
95 crow::openbmc_mapper::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070096#endif
97
Ed Tanous77295132018-10-12 11:11:17 -070098#ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET
99 crow::obmc_console::requestRoutes(app);
100#endif
101
Adriana Kobylak1bfbe0e2019-01-17 12:08:38 -0600102#ifdef BMCWEB_ENABLE_VM_WEBSOCKET
103 crow::obmc_vm::requestRoutes(app);
104#endif
105
Ratan Gupta453fed02019-12-14 09:39:47 +0530106#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
107 crow::ibm_mc::requestRoutes(app);
Ratan Gupta07386c62019-12-14 14:06:09 +0530108 crow::ibm_mc_lock::Lock::getInstance();
Ratan Gupta453fed02019-12-14 09:39:47 +0530109#endif
110
Ed Tanous0260d9d2021-02-07 19:31:07 +0000111 if (bmcwebInsecureDisableXssPrevention)
112 {
113 cors_preflight::requestRoutes(app);
114 }
Ed Tanous52cc1122020-07-18 13:51:21 -0700115
James Feist3909dc82020-04-03 10:58:55 -0700116 crow::login_routes::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -0700117
Ed Tanous1abe55e2018-09-05 08:30:59 -0700118 setupSocket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -0700119
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +0200120#ifdef BMCWEB_ENABLE_VM_NBDPROXY
121 crow::nbd_proxy::requestRoutes(app);
122#endif
123
AppaRao Puli7f4eb582020-06-13 19:01:29 +0530124#ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES
125 int rc = redfish::EventServiceManager::startEventLogMonitor(*io);
126 if (rc)
127 {
128 BMCWEB_LOG_ERROR << "Redfish event handler setup failed...";
129 return rc;
130 }
131#endif
132
Alan Kuoa8220702020-11-26 11:15:29 +0800133#ifdef BMCWEB_ENABLE_SSL
134 BMCWEB_LOG_INFO << "Start Hostname Monitor Service...";
135 crow::hostname_monitor::registerHostnameSignal();
136#endif
137
Ed Tanous1abe55e2018-09-05 08:30:59 -0700138 app.run();
139 io->run();
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700140
Ed Tanous1abe55e2018-09-05 08:30:59 -0700141 crow::connections::systemBus.reset();
Ed Tanous0fdddb12017-02-28 11:06:34 -0800142}