blob: ff0bbd74203cfc39aefedffc8ce8e82b4b978b7c [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>
Feras Aldahlawi735ef6d2021-03-19 14:01:46 -07009#include <google/google_service_root.hpp>
Alan Kuoa8220702020-11-26 11:15:29 +080010#include <hostname_monitor.hpp>
Ed Tanous02379d32020-09-15 21:15:44 -070011#include <ibm/management_console_rest.hpp>
Ed Tanousc3ee5222018-05-01 12:58:27 -070012#include <image_upload.hpp>
Ed Tanous3eb2f352018-12-20 12:30:45 -080013#include <kvm_websocket.hpp>
James Feist3909dc82020-04-03 10:58:55 -070014#include <login_routes.hpp>
Ed Tanouse3009e42022-02-16 15:42:37 -080015#include <nbd_proxy.hpp>
Ed Tanous77295132018-10-12 11:11:17 -070016#include <obmc_console.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070017#include <openbmc_dbus_rest.hpp>
Ed Tanous1e439872018-05-18 11:48:52 -070018#include <redfish.hpp>
Carson Labrado7fb33562022-04-18 23:26:56 +000019#include <redfish_aggregator.hpp>
Ed Tanousaa2e59c2018-04-12 12:17:20 -070020#include <sdbusplus/asio/connection.hpp>
21#include <sdbusplus/bus.hpp>
22#include <sdbusplus/server.hpp>
Ed Tanous52cc1122020-07-18 13:51:21 -070023#include <security_headers.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070024#include <ssl_key_handler.hpp>
Adriana Kobylak1bfbe0e2019-01-17 12:08:38 -060025#include <vm_websocket.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070026#include <webassets.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070027
Ed Tanous02379d32020-09-15 21:15:44 -070028#include <memory>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050029#include <string>
30
Vernon Mauery168792a2018-01-26 13:42:54 -080031constexpr int defaultPort = 18080;
32
Ed Tanous23a21a12020-07-25 04:45:05 +000033inline void setupSocket(crow::App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -070034{
35 int listenFd = sd_listen_fds(0);
36 if (1 == listenFd)
37 {
38 BMCWEB_LOG_INFO << "attempting systemd socket activation";
39 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1,
Ed Tanouse662eae2022-01-25 10:39:19 -080040 0) != 0)
Ed Tanous1abe55e2018-09-05 08:30:59 -070041 {
42 BMCWEB_LOG_INFO << "Starting webserver on socket handle "
43 << SD_LISTEN_FDS_START;
44 app.socket(SD_LISTEN_FDS_START);
45 }
46 else
47 {
48 BMCWEB_LOG_INFO
49 << "bad incoming socket, starting webserver on port "
50 << defaultPort;
51 app.port(defaultPort);
52 }
Vernon Mauery168792a2018-01-26 13:42:54 -080053 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070054 else
55 {
56 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort;
57 app.port(defaultPort);
58 }
Vernon Mauery168792a2018-01-26 13:42:54 -080059}
60
Ed Tanous2119e272022-02-17 18:07:14 -080061static int run()
Ed Tanous1abe55e2018-09-05 08:30:59 -070062{
Ed Tanouseb643c22020-10-02 14:51:22 -070063 crow::Logger::setLogLevel(crow::LogLevel::Debug);
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010064
Ed Tanous8f626352018-12-19 14:51:54 -080065 auto io = std::make_shared<boost::asio::io_context>();
Ed Tanous52cc1122020-07-18 13:51:21 -070066 App app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070067
AppaRao Pulif6f97192021-03-23 23:36:40 +000068 crow::connections::systemBus =
69 std::make_shared<sdbusplus::asio::connection>(*io);
70
Ed Tanous1abe55e2018-09-05 08:30:59 -070071 // Static assets need to be initialized before Authorization, because auth
72 // needs to build the whitelist from the static routes
Ed Tanousf0226cd2017-05-16 12:35:38 -070073
Andrew Geisslerd529ee22018-08-10 13:49:54 -070074#ifdef BMCWEB_ENABLE_STATIC_HOSTING
Ed Tanous1abe55e2018-09-05 08:30:59 -070075 crow::webassets::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070076#endif
77
78#ifdef BMCWEB_ENABLE_KVM
Ed Tanous3eb2f352018-12-20 12:30:45 -080079 crow::obmc_kvm::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070080#endif
81
82#ifdef BMCWEB_ENABLE_REDFISH
P Dheeraj Srujan Kumarb614e2b2021-02-05 01:51:15 +053083 redfish::RedfishService redfish(app);
84
Carson Labrado7fb33562022-04-18 23:26:56 +000085 // Create HttpClient instance and initialize Config
86 crow::HttpClient::getInstance();
87
P Dheeraj Srujan Kumarb614e2b2021-02-05 01:51:15 +053088 // Create EventServiceManager instance and initialize Config
89 redfish::EventServiceManager::getInstance();
Carson Labrado7fb33562022-04-18 23:26:56 +000090
91#ifdef BMCWEB_ENABLE_REDFISH_AGGREGATION
92 // Create RedfishAggregator instance and initialize Config
93 redfish::RedfishAggregator::getInstance();
94#endif
Ed Tanous1e439872018-05-18 11:48:52 -070095#endif
96
97#ifdef BMCWEB_ENABLE_DBUS_REST
Ed Tanous1abe55e2018-09-05 08:30:59 -070098 crow::dbus_monitor::requestRoutes(app);
99 crow::image_upload::requestRoutes(app);
100 crow::openbmc_mapper::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -0700101#endif
102
Ed Tanous77295132018-10-12 11:11:17 -0700103#ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET
104 crow::obmc_console::requestRoutes(app);
105#endif
106
Adriana Kobylak1bfbe0e2019-01-17 12:08:38 -0600107#ifdef BMCWEB_ENABLE_VM_WEBSOCKET
108 crow::obmc_vm::requestRoutes(app);
109#endif
110
Ratan Gupta453fed02019-12-14 09:39:47 +0530111#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
112 crow::ibm_mc::requestRoutes(app);
Ratan Gupta07386c62019-12-14 14:06:09 +0530113 crow::ibm_mc_lock::Lock::getInstance();
Ratan Gupta453fed02019-12-14 09:39:47 +0530114#endif
115
Feras Aldahlawi735ef6d2021-03-19 14:01:46 -0700116#ifdef BMCWEB_ENABLE_GOOGLE_API
117 crow::google_api::requestRoutes(app);
118#endif
119
Ed Tanouse662eae2022-01-25 10:39:19 -0800120 if (bmcwebInsecureDisableXssPrevention != 0)
Ed Tanous0260d9d2021-02-07 19:31:07 +0000121 {
122 cors_preflight::requestRoutes(app);
123 }
Ed Tanous52cc1122020-07-18 13:51:21 -0700124
James Feist3909dc82020-04-03 10:58:55 -0700125 crow::login_routes::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -0700126
Ed Tanous1abe55e2018-09-05 08:30:59 -0700127 setupSocket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -0700128
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +0200129#ifdef BMCWEB_ENABLE_VM_NBDPROXY
130 crow::nbd_proxy::requestRoutes(app);
131#endif
132
AppaRao Puli7f4eb582020-06-13 19:01:29 +0530133#ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES
134 int rc = redfish::EventServiceManager::startEventLogMonitor(*io);
Ed Tanouse662eae2022-01-25 10:39:19 -0800135 if (rc != 0)
AppaRao Puli7f4eb582020-06-13 19:01:29 +0530136 {
137 BMCWEB_LOG_ERROR << "Redfish event handler setup failed...";
138 return rc;
139 }
140#endif
141
Alan Kuoa8220702020-11-26 11:15:29 +0800142#ifdef BMCWEB_ENABLE_SSL
143 BMCWEB_LOG_INFO << "Start Hostname Monitor Service...";
144 crow::hostname_monitor::registerHostnameSignal();
145#endif
146
Ed Tanous1abe55e2018-09-05 08:30:59 -0700147 app.run();
148 io->run();
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700149
Ed Tanous1abe55e2018-09-05 08:30:59 -0700150 crow::connections::systemBus.reset();
P Dheeraj Srujan Kumar85bf8902021-07-12 21:07:36 +0530151 return 0;
Ed Tanous0fdddb12017-02-28 11:06:34 -0800152}
Ed Tanous24b2fe82022-01-06 12:45:54 -0800153
154int main(int /*argc*/, char** /*argv*/)
155{
156 try
157 {
158 return run();
159 }
160 catch (...)
161 {
162 return -1;
163 BMCWEB_LOG_CRITICAL << "Threw exception to main";
164 }
165}