blob: cd31152906a2d249f034b4b8f7f9b068abd4a89e [file] [log] [blame]
Ed Tanousc94ad492019-10-10 15:39:33 -07001#include <app.h>
Ed Tanous9e6e1b22018-03-16 13:08:50 -07002#include <systemd/sd-daemon.h>
Ed Tanous1abe55e2018-09-05 08:30:59 -07003
Ed Tanous8f626352018-12-19 14:51:54 -08004#include <boost/asio/io_context.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07005#include <dbus_monitor.hpp>
6#include <dbus_singleton.hpp>
Ed Tanous02379d32020-09-15 21:15:44 -07007#include <ibm/management_console_rest.hpp>
Ed Tanousc3ee5222018-05-01 12:58:27 -07008#include <image_upload.hpp>
Ed Tanous3eb2f352018-12-20 12:30:45 -08009#include <kvm_websocket.hpp>
James Feist3909dc82020-04-03 10:58:55 -070010#include <login_routes.hpp>
Ed Tanous77295132018-10-12 11:11:17 -070011#include <obmc_console.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070012#include <openbmc_dbus_rest.hpp>
Ed Tanous1e439872018-05-18 11:48:52 -070013#include <redfish.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070014#include <redfish_v1.hpp>
Ed Tanousaa2e59c2018-04-12 12:17:20 -070015#include <sdbusplus/asio/connection.hpp>
16#include <sdbusplus/bus.hpp>
17#include <sdbusplus/server.hpp>
Ed Tanous52cc1122020-07-18 13:51:21 -070018#include <security_headers.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070019#include <ssl_key_handler.hpp>
Adriana Kobylak1bfbe0e2019-01-17 12:08:38 -060020#include <vm_websocket.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070021#include <webassets.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070022
Ed Tanous02379d32020-09-15 21:15:44 -070023#include <memory>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050024#include <string>
25
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +020026#ifdef BMCWEB_ENABLE_VM_NBDPROXY
27#include <nbd_proxy.hpp>
28#endif
29
Vernon Mauery168792a2018-01-26 13:42:54 -080030constexpr int defaultPort = 18080;
31
Ed Tanous23a21a12020-07-25 04:45:05 +000032inline void setupSocket(crow::App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -070033{
34 int listenFd = sd_listen_fds(0);
35 if (1 == listenFd)
36 {
37 BMCWEB_LOG_INFO << "attempting systemd socket activation";
38 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1,
39 0))
40 {
41 BMCWEB_LOG_INFO << "Starting webserver on socket handle "
42 << SD_LISTEN_FDS_START;
43 app.socket(SD_LISTEN_FDS_START);
44 }
45 else
46 {
47 BMCWEB_LOG_INFO
48 << "bad incoming socket, starting webserver on port "
49 << defaultPort;
50 app.port(defaultPort);
51 }
Vernon Mauery168792a2018-01-26 13:42:54 -080052 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070053 else
54 {
55 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort;
56 app.port(defaultPort);
57 }
Vernon Mauery168792a2018-01-26 13:42:54 -080058}
59
Ed Tanouscb13a392020-07-25 19:02:03 +000060int main(int /*argc*/, char** /*argv*/)
Ed Tanous1abe55e2018-09-05 08:30:59 -070061{
Ed Tanouseb643c22020-10-02 14:51:22 -070062 crow::Logger::setLogLevel(crow::LogLevel::Debug);
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010063
Ed Tanous8f626352018-12-19 14:51:54 -080064 auto io = std::make_shared<boost::asio::io_context>();
Ed Tanous52cc1122020-07-18 13:51:21 -070065 App app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070066
Ed Tanous1abe55e2018-09-05 08:30:59 -070067 // Static assets need to be initialized before Authorization, because auth
68 // needs to build the whitelist from the static routes
Ed Tanousf0226cd2017-05-16 12:35:38 -070069
Andrew Geisslerd529ee22018-08-10 13:49:54 -070070#ifdef BMCWEB_ENABLE_STATIC_HOSTING
Ed Tanous1abe55e2018-09-05 08:30:59 -070071 crow::webassets::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070072#endif
73
74#ifdef BMCWEB_ENABLE_KVM
Ed Tanous3eb2f352018-12-20 12:30:45 -080075 crow::obmc_kvm::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070076#endif
77
78#ifdef BMCWEB_ENABLE_REDFISH
Ed Tanous1abe55e2018-09-05 08:30:59 -070079 crow::redfish::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070080#endif
81
82#ifdef BMCWEB_ENABLE_DBUS_REST
Ed Tanous1abe55e2018-09-05 08:30:59 -070083 crow::dbus_monitor::requestRoutes(app);
84 crow::image_upload::requestRoutes(app);
85 crow::openbmc_mapper::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070086#endif
87
Ed Tanous77295132018-10-12 11:11:17 -070088#ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET
89 crow::obmc_console::requestRoutes(app);
90#endif
91
Adriana Kobylak1bfbe0e2019-01-17 12:08:38 -060092#ifdef BMCWEB_ENABLE_VM_WEBSOCKET
93 crow::obmc_vm::requestRoutes(app);
94#endif
95
Ratan Gupta453fed02019-12-14 09:39:47 +053096#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
97 crow::ibm_mc::requestRoutes(app);
Ratan Gupta07386c62019-12-14 14:06:09 +053098 crow::ibm_mc_lock::Lock::getInstance();
Ratan Gupta453fed02019-12-14 09:39:47 +053099#endif
100
Ed Tanous52cc1122020-07-18 13:51:21 -0700101#ifdef BMCWEB_INSECURE_DISABLE_XSS_PREVENTION
102 cors_preflight::requestRoutes(app);
103#endif
104
James Feist3909dc82020-04-03 10:58:55 -0700105 crow::login_routes::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -0700106
Ed Tanous1abe55e2018-09-05 08:30:59 -0700107 setupSocket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -0700108
Ed Tanous1abe55e2018-09-05 08:30:59 -0700109 crow::connections::systemBus =
110 std::make_shared<sdbusplus::asio::connection>(*io);
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +0200111
112#ifdef BMCWEB_ENABLE_VM_NBDPROXY
113 crow::nbd_proxy::requestRoutes(app);
114#endif
115
Ed Tanous1abe55e2018-09-05 08:30:59 -0700116 redfish::RedfishService redfish(app);
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +0100117
AppaRao Puli7f4eb582020-06-13 19:01:29 +0530118#ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES
119 int rc = redfish::EventServiceManager::startEventLogMonitor(*io);
120 if (rc)
121 {
122 BMCWEB_LOG_ERROR << "Redfish event handler setup failed...";
123 return rc;
124 }
125#endif
126
Ed Tanous1abe55e2018-09-05 08:30:59 -0700127 app.run();
128 io->run();
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700129
Ed Tanous1abe55e2018-09-05 08:30:59 -0700130 crow::connections::systemBus.reset();
Ed Tanous0fdddb12017-02-28 11:06:34 -0800131}