blob: 16180ae316ca84fc9267568682275a85f486f7d4 [file] [log] [blame]
Ed Tanous9e6e1b22018-03-16 13:08:50 -07001#include <systemd/sd-daemon.h>
Ed Tanousc9b55212017-06-12 13:25:51 -07002#include <dbus/connection.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07003#include <dbus_monitor.hpp>
4#include <dbus_singleton.hpp>
5#include <intel_oem.hpp>
6#include <openbmc_dbus_rest.hpp>
Ed Tanousba9f9a62017-10-11 16:40:35 -07007#include <persistent_data_middleware.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07008#include <redfish_v1.hpp>
9#include <security_headers_middleware.hpp>
10#include <ssl_key_handler.hpp>
11#include <token_authorization_middleware.hpp>
12#include <web_kvm.hpp>
13#include <webassets.hpp>
Ed Tanousc4771fb2017-03-13 13:39:49 -070014#include <memory>
Ed Tanous0fdddb12017-02-28 11:06:34 -080015#include <string>
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +010016#include "redfish.hpp"
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010017#include "webserver_common.hpp"
Ed Tanous911ac312017-08-15 09:37:42 -070018#include <crow/app.h>
19#include <boost/asio.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070020
Vernon Mauery168792a2018-01-26 13:42:54 -080021constexpr int defaultPort = 18080;
22
23template <typename... Middlewares>
24void setup_socket(crow::Crow<Middlewares...>& app) {
25 int listen_fd = sd_listen_fds(0);
26 if (1 == listen_fd) {
27 CROW_LOG_INFO << "attempting systemd socket activation";
28 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, 0)) {
29 CROW_LOG_INFO << "Starting webserver on socket handle "
30 << SD_LISTEN_FDS_START;
31 app.socket(SD_LISTEN_FDS_START);
32 } else {
33 CROW_LOG_INFO << "bad incoming socket, starting webserver on port "
Ed Tanous9e6e1b22018-03-16 13:08:50 -070034 << defaultPort;
Vernon Mauery168792a2018-01-26 13:42:54 -080035 app.port(defaultPort);
36 }
37 } else {
38 CROW_LOG_INFO << "Starting webserver on port " << defaultPort;
39 app.port(defaultPort);
40 }
41}
42
Ed Tanous99923322017-03-03 14:21:24 -080043int main(int argc, char** argv) {
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010044 crow::logger::setLogLevel(crow::LogLevel::DEBUG);
45
Ed Tanous3dac7492017-08-02 13:46:20 -070046 auto io = std::make_shared<boost::asio::io_service>();
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +010047 crow::PersistentData::session_store =
48 std::make_shared<crow::PersistentData::SessionStore>();
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010049 CrowApp app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070050
Ed Tanous911ac312017-08-15 09:37:42 -070051#ifdef CROW_ENABLE_SSL
52 std::string ssl_pem_file("server.pem");
Ed Tanous4d92cbf2017-06-22 15:41:02 -070053 std::cout << "Building SSL context\n";
Ed Tanous4758d5b2017-06-06 15:28:13 -070054
Ed Tanous911ac312017-08-15 09:37:42 -070055 ensuressl::ensure_openssl_key_present_and_valid(ssl_pem_file);
56 std::cout << "SSL Enabled\n";
57 auto ssl_context = ensuressl::get_ssl_context(ssl_pem_file);
58 app.ssl(std::move(ssl_context));
59#endif
60 // Static assets need to be initialized before Authorization, because auth
61 // needs to build the whitelist from the static routes
62 crow::webassets::request_routes(app);
63 crow::TokenAuthorization::request_routes(app);
Ed Tanousf0226cd2017-05-16 12:35:38 -070064
Ed Tanous911ac312017-08-15 09:37:42 -070065 crow::kvm::request_routes(app);
66 crow::redfish::request_routes(app);
67 crow::dbus_monitor::request_routes(app);
68 crow::intel_oem::request_routes(app);
69 crow::openbmc_mapper::request_routes(app);
70
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010071
Vernon Mauery168792a2018-01-26 13:42:54 -080072
73 CROW_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')';
74 setup_socket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -070075
76 // Start dbus connection
Ed Tanous911ac312017-08-15 09:37:42 -070077 crow::connections::system_bus =
78 std::make_shared<dbus::connection>(*io, dbus::bus::system);
Ed Tanous3dac7492017-08-02 13:46:20 -070079
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010080 redfish::RedfishService redfish(app);
81
Ed Tanous4758d5b2017-06-06 15:28:13 -070082 app.run();
Ed Tanous9e6e1b22018-03-16 13:08:50 -070083 io->run();
Ed Tanous0fdddb12017-02-28 11:06:34 -080084}