Ed Tanous | 9e6e1b2 | 2018-03-16 13:08:50 -0700 | [diff] [blame] | 1 | #include <systemd/sd-daemon.h> |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 2 | #include <bmcweb/settings.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 3 | #include <dbus_monitor.hpp> |
| 4 | #include <dbus_singleton.hpp> |
Ed Tanous | c3ee522 | 2018-05-01 12:58:27 -0700 | [diff] [blame] | 5 | #include <image_upload.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 6 | #include <openbmc_dbus_rest.hpp> |
Ed Tanous | ba9f9a6 | 2017-10-11 16:40:35 -0700 | [diff] [blame] | 7 | #include <persistent_data_middleware.hpp> |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 8 | #include <redfish.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 9 | #include <redfish_v1.hpp> |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 10 | #include <sdbusplus/asio/connection.hpp> |
| 11 | #include <sdbusplus/bus.hpp> |
| 12 | #include <sdbusplus/server.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 13 | #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 Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 18 | #include <webserver_common.hpp> |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame] | 19 | #include <memory> |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 20 | #include <string> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 21 | #include <crow/app.h> |
| 22 | #include <boost/asio.hpp> |
Ed Tanous | cc5a37f | 2017-05-11 10:27:23 -0700 | [diff] [blame] | 23 | |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 24 | constexpr int defaultPort = 18080; |
| 25 | |
| 26 | template <typename... Middlewares> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 27 | void 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 Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 31 | if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, 0)) { |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 32 | BMCWEB_LOG_INFO << "Starting webserver on socket handle " |
| 33 | << SD_LISTEN_FDS_START; |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 34 | app.socket(SD_LISTEN_FDS_START); |
| 35 | } else { |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 36 | BMCWEB_LOG_INFO << "bad incoming socket, starting webserver on port " |
| 37 | << defaultPort; |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 38 | app.port(defaultPort); |
| 39 | } |
| 40 | } else { |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 41 | BMCWEB_LOG_INFO << "Starting webserver on port " << defaultPort; |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 42 | app.port(defaultPort); |
| 43 | } |
| 44 | } |
| 45 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 46 | int main(int argc, char** argv) { |
Ed Tanous | c3ee522 | 2018-05-01 12:58:27 -0700 | [diff] [blame] | 47 | crow::logger::setLogLevel(crow::LogLevel::DEBUG); |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 48 | |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 49 | auto io = std::make_shared<boost::asio::io_service>(); |
Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 50 | CrowApp app(io); |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 51 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 52 | #ifdef BMCWEB_ENABLE_SSL |
| 53 | std::string sslPemFile("server.pem"); |
| 54 | std::cout << "Building SSL Context\n"; |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 55 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 56 | ensuressl::ensureOpensslKeyPresentAndValid(sslPemFile); |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 57 | std::cout << "SSL Enabled\n"; |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 58 | auto sslContext = ensuressl::getSslContext(sslPemFile); |
| 59 | app.ssl(std::move(sslContext)); |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 60 | #endif |
| 61 | // Static assets need to be initialized before Authorization, because auth |
| 62 | // needs to build the whitelist from the static routes |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 63 | |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 64 | #ifdef BMCWEB_ENABLE_PHOSPHOR_WEBUI |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 65 | crow::webassets::requestRoutes(app); |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 66 | #endif |
| 67 | |
| 68 | #ifdef BMCWEB_ENABLE_KVM |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 69 | crow::kvm::requestRoutes(app); |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | #ifdef BMCWEB_ENABLE_REDFISH |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 73 | crow::redfish::requestRoutes(app); |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 74 | #endif |
| 75 | |
| 76 | #ifdef BMCWEB_ENABLE_DBUS_REST |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 77 | crow::dbus_monitor::requestRoutes(app); |
Ed Tanous | c3ee522 | 2018-05-01 12:58:27 -0700 | [diff] [blame] | 78 | crow::image_upload::requestRoutes(app); |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 79 | crow::openbmc_mapper::requestRoutes(app); |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 80 | #endif |
| 81 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 82 | crow::token_authorization::requestRoutes(app); |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 83 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 84 | BMCWEB_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')'; |
| 85 | setupSocket(app); |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 86 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 87 | crow::connections::systemBus = |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 88 | std::make_shared<sdbusplus::asio::connection>(*io); |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 89 | redfish::RedfishService redfish(app); |
| 90 | |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 91 | app.run(); |
Ed Tanous | 9e6e1b2 | 2018-03-16 13:08:50 -0700 | [diff] [blame] | 92 | io->run(); |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 93 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 94 | crow::connections::systemBus.reset(); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 95 | } |