blob: b5bc28cac9cee474807599e8e53cb0797c7dfdda [file] [log] [blame]
Ed Tanous9e6e1b22018-03-16 13:08:50 -07001#include <systemd/sd-daemon.h>
Ed Tanous1abe55e2018-09-05 08:30:59 -07002
Ed Tanous04e438c2020-10-03 08:06:26 -07003#include <app.hpp>
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>
Alan Kuoa8220702020-11-26 11:15:29 +08007#include <hostname_monitor.hpp>
Ed Tanous02379d32020-09-15 21:15:44 -07008#include <ibm/management_console_rest.hpp>
Ed Tanousc3ee5222018-05-01 12:58:27 -07009#include <image_upload.hpp>
Ed Tanous3eb2f352018-12-20 12:30:45 -080010#include <kvm_websocket.hpp>
James Feist3909dc82020-04-03 10:58:55 -070011#include <login_routes.hpp>
Ed Tanous77295132018-10-12 11:11:17 -070012#include <obmc_console.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070013#include <openbmc_dbus_rest.hpp>
Ed Tanous1e439872018-05-18 11:48:52 -070014#include <redfish.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070015#include <redfish_v1.hpp>
Ed Tanousaa2e59c2018-04-12 12:17:20 -070016#include <sdbusplus/asio/connection.hpp>
17#include <sdbusplus/bus.hpp>
18#include <sdbusplus/server.hpp>
Ed Tanous52cc1122020-07-18 13:51:21 -070019#include <security_headers.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070020#include <ssl_key_handler.hpp>
Adriana Kobylak1bfbe0e2019-01-17 12:08:38 -060021#include <vm_websocket.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070022#include <webassets.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070023
Ed Tanous02379d32020-09-15 21:15:44 -070024#include <memory>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050025#include <string>
26
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +020027#ifdef BMCWEB_ENABLE_VM_NBDPROXY
28#include <nbd_proxy.hpp>
29#endif
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,
40 0))
41 {
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 Tanouscb13a392020-07-25 19:02:03 +000061int main(int /*argc*/, char** /*argv*/)
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
Ed Tanous1abe55e2018-09-05 08:30:59 -070068 // Static assets need to be initialized before Authorization, because auth
69 // needs to build the whitelist from the static routes
Ed Tanousf0226cd2017-05-16 12:35:38 -070070
Andrew Geisslerd529ee22018-08-10 13:49:54 -070071#ifdef BMCWEB_ENABLE_STATIC_HOSTING
Ed Tanous1abe55e2018-09-05 08:30:59 -070072 crow::webassets::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070073#endif
74
75#ifdef BMCWEB_ENABLE_KVM
Ed Tanous3eb2f352018-12-20 12:30:45 -080076 crow::obmc_kvm::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070077#endif
78
79#ifdef BMCWEB_ENABLE_REDFISH
Ed Tanous1abe55e2018-09-05 08:30:59 -070080 crow::redfish::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070081#endif
82
83#ifdef BMCWEB_ENABLE_DBUS_REST
Ed Tanous1abe55e2018-09-05 08:30:59 -070084 crow::dbus_monitor::requestRoutes(app);
85 crow::image_upload::requestRoutes(app);
86 crow::openbmc_mapper::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070087#endif
88
Ed Tanous77295132018-10-12 11:11:17 -070089#ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET
90 crow::obmc_console::requestRoutes(app);
91#endif
92
Adriana Kobylak1bfbe0e2019-01-17 12:08:38 -060093#ifdef BMCWEB_ENABLE_VM_WEBSOCKET
94 crow::obmc_vm::requestRoutes(app);
95#endif
96
Ratan Gupta453fed02019-12-14 09:39:47 +053097#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
98 crow::ibm_mc::requestRoutes(app);
Ratan Gupta07386c62019-12-14 14:06:09 +053099 crow::ibm_mc_lock::Lock::getInstance();
Ratan Gupta453fed02019-12-14 09:39:47 +0530100#endif
101
Ed Tanous52cc1122020-07-18 13:51:21 -0700102#ifdef BMCWEB_INSECURE_DISABLE_XSS_PREVENTION
103 cors_preflight::requestRoutes(app);
104#endif
105
James Feist3909dc82020-04-03 10:58:55 -0700106 crow::login_routes::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -0700107
Ed Tanous1abe55e2018-09-05 08:30:59 -0700108 setupSocket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -0700109
Ed Tanous1abe55e2018-09-05 08:30:59 -0700110 crow::connections::systemBus =
111 std::make_shared<sdbusplus::asio::connection>(*io);
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +0200112
113#ifdef BMCWEB_ENABLE_VM_NBDPROXY
114 crow::nbd_proxy::requestRoutes(app);
115#endif
116
Ed Tanous1abe55e2018-09-05 08:30:59 -0700117 redfish::RedfishService redfish(app);
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +0100118
AppaRao Puli7f4eb582020-06-13 19:01:29 +0530119#ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES
120 int rc = redfish::EventServiceManager::startEventLogMonitor(*io);
121 if (rc)
122 {
123 BMCWEB_LOG_ERROR << "Redfish event handler setup failed...";
124 return rc;
125 }
126#endif
127
Alan Kuoa8220702020-11-26 11:15:29 +0800128#ifdef BMCWEB_ENABLE_SSL
129 BMCWEB_LOG_INFO << "Start Hostname Monitor Service...";
130 crow::hostname_monitor::registerHostnameSignal();
131#endif
132
Ed Tanous1abe55e2018-09-05 08:30:59 -0700133 app.run();
134 io->run();
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700135
Ed Tanous1abe55e2018-09-05 08:30:59 -0700136 crow::connections::systemBus.reset();
Ed Tanous0fdddb12017-02-28 11:06:34 -0800137}