blob: e2a776a7e44eb6c13275fb95f2ddaf0004a9b47f [file] [log] [blame]
Ed Tanous9e6e1b22018-03-16 13:08:50 -07001#include <systemd/sd-daemon.h>
Ed Tanous1e439872018-05-18 11:48:52 -07002#include <bmcweb/settings.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07003#include <dbus_monitor.hpp>
4#include <dbus_singleton.hpp>
Ed Tanousc3ee5222018-05-01 12:58:27 -07005#include <image_upload.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07006#include <openbmc_dbus_rest.hpp>
Ed Tanousba9f9a62017-10-11 16:40:35 -07007#include <persistent_data_middleware.hpp>
Ed Tanous1e439872018-05-18 11:48:52 -07008#include <redfish.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07009#include <redfish_v1.hpp>
Ed Tanousaa2e59c2018-04-12 12:17:20 -070010#include <sdbusplus/asio/connection.hpp>
11#include <sdbusplus/bus.hpp>
12#include <sdbusplus/server.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070013#include <security_headers_middleware.hpp>
14#include <ssl_key_handler.hpp>
15#include <token_authorization_middleware.hpp>
16#include <web_kvm.hpp>
17#include <webassets.hpp>
Ed Tanous1e439872018-05-18 11:48:52 -070018#include <webserver_common.hpp>
Ed Tanousc4771fb2017-03-13 13:39:49 -070019#include <memory>
Ed Tanous0fdddb12017-02-28 11:06:34 -080020#include <string>
Ed Tanous911ac312017-08-15 09:37:42 -070021#include <crow/app.h>
22#include <boost/asio.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070023
Vernon Mauery168792a2018-01-26 13:42:54 -080024constexpr int defaultPort = 18080;
25
26template <typename... Middlewares>
Ed Tanous55c7b7a2018-05-22 15:27:24 -070027void setupSocket(crow::Crow<Middlewares...>& app) {
28 int listenFd = sd_listen_fds(0);
29 if (1 == listenFd) {
30 BMCWEB_LOG_INFO << "attempting systemd socket activation";
Vernon Mauery168792a2018-01-26 13:42:54 -080031 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, 0)) {
Ed Tanous55c7b7a2018-05-22 15:27:24 -070032 BMCWEB_LOG_INFO << "Starting webserver on socket handle "
33 << SD_LISTEN_FDS_START;
Vernon Mauery168792a2018-01-26 13:42:54 -080034 app.socket(SD_LISTEN_FDS_START);
35 } else {
Ed Tanous55c7b7a2018-05-22 15:27:24 -070036 BMCWEB_LOG_INFO << "bad incoming socket, starting webserver on port "
37 << defaultPort;
Vernon Mauery168792a2018-01-26 13:42:54 -080038 app.port(defaultPort);
39 }
40 } else {
Ed Tanous55c7b7a2018-05-22 15:27:24 -070041 BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort;
Vernon Mauery168792a2018-01-26 13:42:54 -080042 app.port(defaultPort);
43 }
44}
45
Ed Tanous99923322017-03-03 14:21:24 -080046int main(int argc, char** argv) {
Ed Tanousc3ee5222018-05-01 12:58:27 -070047 crow::logger::setLogLevel(crow::LogLevel::DEBUG);
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010048
Ed Tanous3dac7492017-08-02 13:46:20 -070049 auto io = std::make_shared<boost::asio::io_service>();
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010050 CrowApp app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070051
Ed Tanous55c7b7a2018-05-22 15:27:24 -070052#ifdef BMCWEB_ENABLE_SSL
53 std::string sslPemFile("server.pem");
54 std::cout << "Building SSL Context\n";
Ed Tanous4758d5b2017-06-06 15:28:13 -070055
Ed Tanous55c7b7a2018-05-22 15:27:24 -070056 ensuressl::ensureOpensslKeyPresentAndValid(sslPemFile);
Ed Tanous911ac312017-08-15 09:37:42 -070057 std::cout << "SSL Enabled\n";
Ed Tanous55c7b7a2018-05-22 15:27:24 -070058 auto sslContext = ensuressl::getSslContext(sslPemFile);
59 app.ssl(std::move(sslContext));
Ed Tanous911ac312017-08-15 09:37:42 -070060#endif
61 // Static assets need to be initialized before Authorization, because auth
62 // needs to build the whitelist from the static routes
Ed Tanousf0226cd2017-05-16 12:35:38 -070063
Ed Tanous1e439872018-05-18 11:48:52 -070064#ifdef BMCWEB_ENABLE_PHOSPHOR_WEBUI
Ed Tanous55c7b7a2018-05-22 15:27:24 -070065 crow::webassets::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070066#endif
67
68#ifdef BMCWEB_ENABLE_KVM
Ed Tanous55c7b7a2018-05-22 15:27:24 -070069 crow::kvm::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070070#endif
71
72#ifdef BMCWEB_ENABLE_REDFISH
Ed Tanous55c7b7a2018-05-22 15:27:24 -070073 crow::redfish::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070074#endif
75
76#ifdef BMCWEB_ENABLE_DBUS_REST
Ed Tanous55c7b7a2018-05-22 15:27:24 -070077 crow::dbus_monitor::requestRoutes(app);
Ed Tanousc3ee5222018-05-01 12:58:27 -070078 crow::image_upload::requestRoutes(app);
Ed Tanous55c7b7a2018-05-22 15:27:24 -070079 crow::openbmc_mapper::requestRoutes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070080#endif
81
Ed Tanous55c7b7a2018-05-22 15:27:24 -070082 crow::token_authorization::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -070083
Ed Tanous55c7b7a2018-05-22 15:27:24 -070084 BMCWEB_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')';
85 setupSocket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -070086
Ed Tanous55c7b7a2018-05-22 15:27:24 -070087 crow::connections::systemBus =
Ed Tanousaa2e59c2018-04-12 12:17:20 -070088 std::make_shared<sdbusplus::asio::connection>(*io);
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010089 redfish::RedfishService redfish(app);
90
Ed Tanous4758d5b2017-06-06 15:28:13 -070091 app.run();
Ed Tanous9e6e1b22018-03-16 13:08:50 -070092 io->run();
Ed Tanousaa2e59c2018-04-12 12:17:20 -070093
Ed Tanous55c7b7a2018-05-22 15:27:24 -070094 crow::connections::systemBus.reset();
Ed Tanous0fdddb12017-02-28 11:06:34 -080095}