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