blob: 55152d6033085d984c12ea411d8f9e03a1048cb5 [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>
27void setup_socket(crow::Crow<Middlewares...>& app) {
28 int listen_fd = sd_listen_fds(0);
29 if (1 == listen_fd) {
30 CROW_LOG_INFO << "attempting systemd socket activation";
31 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, 0)) {
32 CROW_LOG_INFO << "Starting webserver on socket handle "
33 << SD_LISTEN_FDS_START;
34 app.socket(SD_LISTEN_FDS_START);
35 } else {
36 CROW_LOG_INFO << "bad incoming socket, starting webserver on port "
Ed Tanous9e6e1b22018-03-16 13:08:50 -070037 << defaultPort;
Vernon Mauery168792a2018-01-26 13:42:54 -080038 app.port(defaultPort);
39 }
40 } else {
41 CROW_LOG_INFO << "Starting webserver on port " << defaultPort;
42 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 Tanous911ac312017-08-15 09:37:42 -070052#ifdef CROW_ENABLE_SSL
53 std::string ssl_pem_file("server.pem");
Ed Tanous4d92cbf2017-06-22 15:41:02 -070054 std::cout << "Building SSL context\n";
Ed Tanous4758d5b2017-06-06 15:28:13 -070055
Ed Tanous911ac312017-08-15 09:37:42 -070056 ensuressl::ensure_openssl_key_present_and_valid(ssl_pem_file);
57 std::cout << "SSL Enabled\n";
58 auto ssl_context = ensuressl::get_ssl_context(ssl_pem_file);
59 app.ssl(std::move(ssl_context));
60#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
65 crow::webassets::request_routes(app);
66#endif
67
68#ifdef BMCWEB_ENABLE_KVM
Ed Tanous911ac312017-08-15 09:37:42 -070069 crow::kvm::request_routes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070070#endif
71
72#ifdef BMCWEB_ENABLE_REDFISH
Ed Tanous911ac312017-08-15 09:37:42 -070073 crow::redfish::request_routes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070074#endif
75
76#ifdef BMCWEB_ENABLE_DBUS_REST
Ed Tanous911ac312017-08-15 09:37:42 -070077 crow::dbus_monitor::request_routes(app);
Ed Tanousc3ee5222018-05-01 12:58:27 -070078 crow::image_upload::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -070079 crow::openbmc_mapper::request_routes(app);
Ed Tanous1e439872018-05-18 11:48:52 -070080#endif
81
82 crow::TokenAuthorization::request_routes(app);
Ed Tanous911ac312017-08-15 09:37:42 -070083
Vernon Mauery168792a2018-01-26 13:42:54 -080084 CROW_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')';
85 setup_socket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -070086
Ed Tanous911ac312017-08-15 09:37:42 -070087 crow::connections::system_bus =
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 Tanousc3ee5222018-05-01 12:58:27 -070094 crow::connections::system_bus.reset();
Ed Tanous0fdddb12017-02-28 11:06:34 -080095}