blob: 036db5479a7a4922edf6c46400d9d67c360a6c76 [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 Tanousc3ee5222018-05-01 12:58:27 -07007#include <image_upload.hpp>
Ed Tanous3eb2f352018-12-20 12:30:45 -08008#include <kvm_websocket.hpp>
James Feist3909dc82020-04-03 10:58:55 -07009#include <login_routes.hpp>
Ed Tanous77295132018-10-12 11:11:17 -070010#include <obmc_console.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070011#include <openbmc_dbus_rest.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050012
13#include <memory>
Ratan Gupta453fed02019-12-14 09:39:47 +053014#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
15#include <ibm/management_console_rest.hpp>
16#endif
Ed Tanousba9f9a62017-10-11 16:40:35 -070017#include <persistent_data_middleware.hpp>
Ed Tanous1e439872018-05-18 11:48:52 -070018#include <redfish.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070019#include <redfish_v1.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 Tanous911ac312017-08-15 09:37:42 -070023#include <security_headers_middleware.hpp>
24#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 Tanous1e439872018-05-18 11:48:52 -070027#include <webserver_common.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070028
Gunnar Mills1214b7e2020-06-04 10:11:30 -050029#include <string>
30
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +020031#ifdef BMCWEB_ENABLE_VM_NBDPROXY
32#include <nbd_proxy.hpp>
33#endif
34
Vernon Mauery168792a2018-01-26 13:42:54 -080035constexpr int defaultPort = 18080;
36
37template <typename... Middlewares>
Ed Tanous1abe55e2018-09-05 08:30:59 -070038void setupSocket(crow::Crow<Middlewares...>& app)
39{
40 int listenFd = sd_listen_fds(0);
41 if (1 == listenFd)
42 {
43 BMCWEB_LOG_INFO << "attempting systemd socket activation";
44 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1,
45 0))
46 {
47 BMCWEB_LOG_INFO << "Starting webserver on socket handle "
48 << SD_LISTEN_FDS_START;
49 app.socket(SD_LISTEN_FDS_START);
50 }
51 else
52 {
53 BMCWEB_LOG_INFO
54 << "bad incoming socket, starting webserver on port "
55 << defaultPort;
56 app.port(defaultPort);
57 }
Vernon Mauery168792a2018-01-26 13:42:54 -080058 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070059 else
60 {
61 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort;
62 app.port(defaultPort);
63 }
Vernon Mauery168792a2018-01-26 13:42:54 -080064}
65
Ed Tanous1abe55e2018-09-05 08:30:59 -070066int main(int argc, char** argv)
67{
Ed Tanous271584a2019-07-09 16:24:22 -070068 crow::logger::setLogLevel(crow::LogLevel::Debug);
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010069
Ed Tanous8f626352018-12-19 14:51:54 -080070 auto io = std::make_shared<boost::asio::io_context>();
Ed Tanous1abe55e2018-09-05 08:30:59 -070071 CrowApp app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070072
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 Tanous1abe55e2018-09-05 08:30:59 -070085 crow::redfish::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070086#endif
87
88#ifdef BMCWEB_ENABLE_DBUS_REST
Ed Tanous1abe55e2018-09-05 08:30:59 -070089 crow::dbus_monitor::requestRoutes(app);
90 crow::image_upload::requestRoutes(app);
91 crow::openbmc_mapper::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070092#endif
93
Ed Tanous77295132018-10-12 11:11:17 -070094#ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET
95 crow::obmc_console::requestRoutes(app);
96#endif
97
Adriana Kobylak1bfbe0e2019-01-17 12:08:38 -060098#ifdef BMCWEB_ENABLE_VM_WEBSOCKET
99 crow::obmc_vm::requestRoutes(app);
100#endif
101
Ratan Gupta453fed02019-12-14 09:39:47 +0530102#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
103 crow::ibm_mc::requestRoutes(app);
Ratan Gupta07386c62019-12-14 14:06:09 +0530104 crow::ibm_mc_lock::Lock::getInstance();
Ratan Gupta453fed02019-12-14 09:39:47 +0530105#endif
106
James Feist3909dc82020-04-03 10:58:55 -0700107 crow::login_routes::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -0700108
Ed Tanous1abe55e2018-09-05 08:30:59 -0700109 BMCWEB_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')';
110 setupSocket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -0700111
Ed Tanous1abe55e2018-09-05 08:30:59 -0700112 crow::connections::systemBus =
113 std::make_shared<sdbusplus::asio::connection>(*io);
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +0200114
115#ifdef BMCWEB_ENABLE_VM_NBDPROXY
116 crow::nbd_proxy::requestRoutes(app);
117#endif
118
Ed Tanous1abe55e2018-09-05 08:30:59 -0700119 redfish::RedfishService redfish(app);
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +0100120
AppaRao Puli7f4eb582020-06-13 19:01:29 +0530121#ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES
122 int rc = redfish::EventServiceManager::startEventLogMonitor(*io);
123 if (rc)
124 {
125 BMCWEB_LOG_ERROR << "Redfish event handler setup failed...";
126 return rc;
127 }
128#endif
129
Ed Tanous1abe55e2018-09-05 08:30:59 -0700130 app.run();
131 io->run();
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700132
Ed Tanous1abe55e2018-09-05 08:30:59 -0700133 crow::connections::systemBus.reset();
Ed Tanous0fdddb12017-02-28 11:06:34 -0800134}