blob: fc2638a36eec0e6cd8eed5f0280a4e90e4cd75a8 [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 Tanous1abe55e2018-09-05 08:30:59 -07004#include <boost/asio.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 Tanous1abe55e2018-09-05 08:30:59 -07008#include <memory>
Ed Tanous77295132018-10-12 11:11:17 -07009#include <obmc_console.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070010#include <openbmc_dbus_rest.hpp>
Ed Tanousba9f9a62017-10-11 16:40:35 -070011#include <persistent_data_middleware.hpp>
Ed Tanous1e439872018-05-18 11:48:52 -070012#include <redfish.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070013#include <redfish_v1.hpp>
Ed Tanousaa2e59c2018-04-12 12:17:20 -070014#include <sdbusplus/asio/connection.hpp>
15#include <sdbusplus/bus.hpp>
16#include <sdbusplus/server.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070017#include <security_headers_middleware.hpp>
18#include <ssl_key_handler.hpp>
Ed Tanous1abe55e2018-09-05 08:30:59 -070019#include <string>
Ed Tanous911ac312017-08-15 09:37:42 -070020#include <token_authorization_middleware.hpp>
21#include <web_kvm.hpp>
22#include <webassets.hpp>
Ed Tanous1e439872018-05-18 11:48:52 -070023#include <webserver_common.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070024
Vernon Mauery168792a2018-01-26 13:42:54 -080025constexpr int defaultPort = 18080;
26
27template <typename... Middlewares>
Ed Tanous1abe55e2018-09-05 08:30:59 -070028void setupSocket(crow::Crow<Middlewares...>& app)
29{
30 int listenFd = sd_listen_fds(0);
31 if (1 == listenFd)
32 {
33 BMCWEB_LOG_INFO << "attempting systemd socket activation";
34 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1,
35 0))
36 {
37 BMCWEB_LOG_INFO << "Starting webserver on socket handle "
38 << SD_LISTEN_FDS_START;
39 app.socket(SD_LISTEN_FDS_START);
40 }
41 else
42 {
43 BMCWEB_LOG_INFO
44 << "bad incoming socket, starting webserver on port "
45 << defaultPort;
46 app.port(defaultPort);
47 }
Vernon Mauery168792a2018-01-26 13:42:54 -080048 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070049 else
50 {
51 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort;
52 app.port(defaultPort);
53 }
Vernon Mauery168792a2018-01-26 13:42:54 -080054}
55
Ed Tanous1abe55e2018-09-05 08:30:59 -070056int main(int argc, char** argv)
57{
58 crow::logger::setLogLevel(crow::LogLevel::DEBUG);
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010059
Ed Tanous1abe55e2018-09-05 08:30:59 -070060 auto io = std::make_shared<boost::asio::io_service>();
61 CrowApp app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070062
Ed Tanous55c7b7a2018-05-22 15:27:24 -070063#ifdef BMCWEB_ENABLE_SSL
Ed Tanous1abe55e2018-09-05 08:30:59 -070064 std::string sslPemFile("server.pem");
65 std::cout << "Building SSL Context\n";
Ed Tanous4758d5b2017-06-06 15:28:13 -070066
Ed Tanous1abe55e2018-09-05 08:30:59 -070067 ensuressl::ensureOpensslKeyPresentAndValid(sslPemFile);
68 std::cout << "SSL Enabled\n";
69 auto sslContext = ensuressl::getSslContext(sslPemFile);
70 app.ssl(std::move(sslContext));
Ed Tanous911ac312017-08-15 09:37:42 -070071#endif
Ed Tanous1abe55e2018-09-05 08:30:59 -070072 // Static assets need to be initialized before Authorization, because auth
73 // needs to build the whitelist from the static routes
Ed Tanousf0226cd2017-05-16 12:35:38 -070074
Andrew Geisslerd529ee22018-08-10 13:49:54 -070075#ifdef BMCWEB_ENABLE_STATIC_HOSTING
Ed Tanous1abe55e2018-09-05 08:30:59 -070076 crow::webassets::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070077#endif
78
79#ifdef BMCWEB_ENABLE_KVM
Ed Tanous1abe55e2018-09-05 08:30:59 -070080 crow::kvm::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070081#endif
82
83#ifdef BMCWEB_ENABLE_REDFISH
Ed Tanous1abe55e2018-09-05 08:30:59 -070084 crow::redfish::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070085#endif
86
87#ifdef BMCWEB_ENABLE_DBUS_REST
Ed Tanous1abe55e2018-09-05 08:30:59 -070088 crow::dbus_monitor::requestRoutes(app);
89 crow::image_upload::requestRoutes(app);
90 crow::openbmc_mapper::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070091#endif
92
Ed Tanous77295132018-10-12 11:11:17 -070093#ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET
94 crow::obmc_console::requestRoutes(app);
95#endif
96
Ed Tanous1abe55e2018-09-05 08:30:59 -070097 crow::token_authorization::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -070098
Ed Tanous1abe55e2018-09-05 08:30:59 -070099 BMCWEB_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')';
100 setupSocket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -0700101
Ed Tanous1abe55e2018-09-05 08:30:59 -0700102 crow::connections::systemBus =
103 std::make_shared<sdbusplus::asio::connection>(*io);
104 redfish::RedfishService redfish(app);
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +0100105
Ed Tanous1abe55e2018-09-05 08:30:59 -0700106 app.run();
107 io->run();
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700108
Ed Tanous1abe55e2018-09-05 08:30:59 -0700109 crow::connections::systemBus.reset();
Ed Tanous0fdddb12017-02-28 11:06:34 -0800110}