blob: d1418416906a878d9654a8ebd49f51527ae2245a [file] [log] [blame]
Ed Tanous1abe55e2018-09-05 08:30:59 -07001#include <crow/app.h>
Ed Tanous9e6e1b22018-03-16 13:08:50 -07002#include <systemd/sd-daemon.h>
Ed Tanous1abe55e2018-09-05 08:30:59 -07003
Ed Tanous1e439872018-05-18 11:48:52 -07004#include <bmcweb/settings.hpp>
Ed Tanous1abe55e2018-09-05 08:30:59 -07005#include <boost/asio.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07006#include <dbus_monitor.hpp>
7#include <dbus_singleton.hpp>
Ed Tanousc3ee5222018-05-01 12:58:27 -07008#include <image_upload.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>
Ed Tanousba9f9a62017-10-11 16:40:35 -070012#include <persistent_data_middleware.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 Tanous911ac312017-08-15 09:37:42 -070018#include <security_headers_middleware.hpp>
19#include <ssl_key_handler.hpp>
Ed Tanous1abe55e2018-09-05 08:30:59 -070020#include <string>
Ed Tanous911ac312017-08-15 09:37:42 -070021#include <token_authorization_middleware.hpp>
22#include <web_kvm.hpp>
23#include <webassets.hpp>
Ed Tanous1e439872018-05-18 11:48:52 -070024#include <webserver_common.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070025
Vernon Mauery168792a2018-01-26 13:42:54 -080026constexpr int defaultPort = 18080;
27
28template <typename... Middlewares>
Ed Tanous1abe55e2018-09-05 08:30:59 -070029void setupSocket(crow::Crow<Middlewares...>& app)
30{
31 int listenFd = sd_listen_fds(0);
32 if (1 == listenFd)
33 {
34 BMCWEB_LOG_INFO << "attempting systemd socket activation";
35 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1,
36 0))
37 {
38 BMCWEB_LOG_INFO << "Starting webserver on socket handle "
39 << SD_LISTEN_FDS_START;
40 app.socket(SD_LISTEN_FDS_START);
41 }
42 else
43 {
44 BMCWEB_LOG_INFO
45 << "bad incoming socket, starting webserver on port "
46 << defaultPort;
47 app.port(defaultPort);
48 }
Vernon Mauery168792a2018-01-26 13:42:54 -080049 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070050 else
51 {
52 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort;
53 app.port(defaultPort);
54 }
Vernon Mauery168792a2018-01-26 13:42:54 -080055}
56
Ed Tanous1abe55e2018-09-05 08:30:59 -070057int main(int argc, char** argv)
58{
59 crow::logger::setLogLevel(crow::LogLevel::DEBUG);
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010060
Ed Tanous1abe55e2018-09-05 08:30:59 -070061 auto io = std::make_shared<boost::asio::io_service>();
62 CrowApp app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070063
Ed Tanous55c7b7a2018-05-22 15:27:24 -070064#ifdef BMCWEB_ENABLE_SSL
Ed Tanous1abe55e2018-09-05 08:30:59 -070065 std::string sslPemFile("server.pem");
66 std::cout << "Building SSL Context\n";
Ed Tanous4758d5b2017-06-06 15:28:13 -070067
Ed Tanous1abe55e2018-09-05 08:30:59 -070068 ensuressl::ensureOpensslKeyPresentAndValid(sslPemFile);
69 std::cout << "SSL Enabled\n";
70 auto sslContext = ensuressl::getSslContext(sslPemFile);
71 app.ssl(std::move(sslContext));
Ed Tanous911ac312017-08-15 09:37:42 -070072#endif
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 Tanous1abe55e2018-09-05 08:30:59 -070081 crow::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
Ed Tanous1abe55e2018-09-05 08:30:59 -070098 crow::token_authorization::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -070099
Ed Tanous1abe55e2018-09-05 08:30:59 -0700100 BMCWEB_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')';
101 setupSocket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -0700102
Ed Tanous1abe55e2018-09-05 08:30:59 -0700103 crow::connections::systemBus =
104 std::make_shared<sdbusplus::asio::connection>(*io);
105 redfish::RedfishService redfish(app);
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +0100106
Ed Tanous1abe55e2018-09-05 08:30:59 -0700107 app.run();
108 io->run();
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700109
Ed Tanous1abe55e2018-09-05 08:30:59 -0700110 crow::connections::systemBus.reset();
Ed Tanous0fdddb12017-02-28 11:06:34 -0800111}