blob: 4bdf880641e6e8032684874091b3846e3f3c08fb [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>
Ed Tanous1abe55e2018-09-05 08:30:59 -07009#include <memory>
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>
Ratan Gupta453fed02019-12-14 09:39:47 +053012#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
13#include <ibm/management_console_rest.hpp>
14#endif
Ed Tanousba9f9a62017-10-11 16:40:35 -070015#include <persistent_data_middleware.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 Tanous911ac312017-08-15 09:37:42 -070021#include <security_headers_middleware.hpp>
22#include <ssl_key_handler.hpp>
Ed Tanous1abe55e2018-09-05 08:30:59 -070023#include <string>
Ed Tanous911ac312017-08-15 09:37:42 -070024#include <token_authorization_middleware.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
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
35template <typename... Middlewares>
Ed Tanous1abe55e2018-09-05 08:30:59 -070036void setupSocket(crow::Crow<Middlewares...>& app)
37{
38 int listenFd = sd_listen_fds(0);
39 if (1 == listenFd)
40 {
41 BMCWEB_LOG_INFO << "attempting systemd socket activation";
42 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1,
43 0))
44 {
45 BMCWEB_LOG_INFO << "Starting webserver on socket handle "
46 << SD_LISTEN_FDS_START;
47 app.socket(SD_LISTEN_FDS_START);
48 }
49 else
50 {
51 BMCWEB_LOG_INFO
52 << "bad incoming socket, starting webserver on port "
53 << defaultPort;
54 app.port(defaultPort);
55 }
Vernon Mauery168792a2018-01-26 13:42:54 -080056 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070057 else
58 {
59 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort;
60 app.port(defaultPort);
61 }
Vernon Mauery168792a2018-01-26 13:42:54 -080062}
63
Ed Tanous1abe55e2018-09-05 08:30:59 -070064int main(int argc, char** argv)
65{
Ed Tanous271584a2019-07-09 16:24:22 -070066 crow::logger::setLogLevel(crow::LogLevel::Debug);
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010067
Ed Tanous8f626352018-12-19 14:51:54 -080068 auto io = std::make_shared<boost::asio::io_context>();
Ed Tanous1abe55e2018-09-05 08:30:59 -070069 CrowApp app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070070
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
Ed Tanous1abe55e2018-09-05 08:30:59 -070083 crow::redfish::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070084#endif
85
86#ifdef BMCWEB_ENABLE_DBUS_REST
Ed Tanous1abe55e2018-09-05 08:30:59 -070087 crow::dbus_monitor::requestRoutes(app);
88 crow::image_upload::requestRoutes(app);
89 crow::openbmc_mapper::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070090#endif
91
Ed Tanous77295132018-10-12 11:11:17 -070092#ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET
93 crow::obmc_console::requestRoutes(app);
94#endif
95
Adriana Kobylak1bfbe0e2019-01-17 12:08:38 -060096#ifdef BMCWEB_ENABLE_VM_WEBSOCKET
97 crow::obmc_vm::requestRoutes(app);
98#endif
99
Ratan Gupta453fed02019-12-14 09:39:47 +0530100#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
101 crow::ibm_mc::requestRoutes(app);
102#endif
103
Ed Tanous1abe55e2018-09-05 08:30:59 -0700104 crow::token_authorization::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -0700105
Ed Tanous1abe55e2018-09-05 08:30:59 -0700106 BMCWEB_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')';
107 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
Ed Tanous1abe55e2018-09-05 08:30:59 -0700118 app.run();
119 io->run();
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700120
Ed Tanous1abe55e2018-09-05 08:30:59 -0700121 crow::connections::systemBus.reset();
Ed Tanous0fdddb12017-02-28 11:06:34 -0800122}