blob: 93b3aa68e3f9788ba03bf1eb489537887a04c9f6 [file] [log] [blame]
Ed Tanous9e6e1b22018-03-16 13:08:50 -07001#include <systemd/sd-daemon.h>
Ed Tanous911ac312017-08-15 09:37:42 -07002#include <dbus_monitor.hpp>
3#include <dbus_singleton.hpp>
Ed Tanousc3ee5222018-05-01 12:58:27 -07004#include <image_upload.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07005#include <openbmc_dbus_rest.hpp>
Ed Tanousba9f9a62017-10-11 16:40:35 -07006#include <persistent_data_middleware.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07007#include <redfish_v1.hpp>
Ed Tanousaa2e59c2018-04-12 12:17:20 -07008#include <sdbusplus/asio/connection.hpp>
9#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -070011#include <security_headers_middleware.hpp>
12#include <ssl_key_handler.hpp>
13#include <token_authorization_middleware.hpp>
14#include <web_kvm.hpp>
15#include <webassets.hpp>
Ed Tanousc4771fb2017-03-13 13:39:49 -070016#include <memory>
Ed Tanous0fdddb12017-02-28 11:06:34 -080017#include <string>
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +010018#include "redfish.hpp"
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010019#include "webserver_common.hpp"
Ed Tanous911ac312017-08-15 09:37:42 -070020#include <crow/app.h>
21#include <boost/asio.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070022
Vernon Mauery168792a2018-01-26 13:42:54 -080023constexpr int defaultPort = 18080;
24
25template <typename... Middlewares>
26void setup_socket(crow::Crow<Middlewares...>& app) {
27 int listen_fd = sd_listen_fds(0);
28 if (1 == listen_fd) {
29 CROW_LOG_INFO << "attempting systemd socket activation";
30 if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, 0)) {
31 CROW_LOG_INFO << "Starting webserver on socket handle "
32 << SD_LISTEN_FDS_START;
33 app.socket(SD_LISTEN_FDS_START);
34 } else {
35 CROW_LOG_INFO << "bad incoming socket, starting webserver on port "
Ed Tanous9e6e1b22018-03-16 13:08:50 -070036 << defaultPort;
Vernon Mauery168792a2018-01-26 13:42:54 -080037 app.port(defaultPort);
38 }
39 } else {
40 CROW_LOG_INFO << "Starting webserver on port " << defaultPort;
41 app.port(defaultPort);
42 }
43}
44
Ed Tanous99923322017-03-03 14:21:24 -080045int main(int argc, char** argv) {
Ed Tanousc3ee5222018-05-01 12:58:27 -070046 crow::logger::setLogLevel(crow::LogLevel::DEBUG);
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010047
Ed Tanous3dac7492017-08-02 13:46:20 -070048 auto io = std::make_shared<boost::asio::io_service>();
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +010049 crow::PersistentData::session_store =
50 std::make_shared<crow::PersistentData::SessionStore>();
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010051 CrowApp app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070052
Ed Tanous911ac312017-08-15 09:37:42 -070053#ifdef CROW_ENABLE_SSL
54 std::string ssl_pem_file("server.pem");
Ed Tanous4d92cbf2017-06-22 15:41:02 -070055 std::cout << "Building SSL context\n";
Ed Tanous4758d5b2017-06-06 15:28:13 -070056
Ed Tanous911ac312017-08-15 09:37:42 -070057 ensuressl::ensure_openssl_key_present_and_valid(ssl_pem_file);
58 std::cout << "SSL Enabled\n";
59 auto ssl_context = ensuressl::get_ssl_context(ssl_pem_file);
60 app.ssl(std::move(ssl_context));
61#endif
62 // Static assets need to be initialized before Authorization, because auth
63 // needs to build the whitelist from the static routes
64 crow::webassets::request_routes(app);
65 crow::TokenAuthorization::request_routes(app);
Ed Tanousf0226cd2017-05-16 12:35:38 -070066
Ed Tanous911ac312017-08-15 09:37:42 -070067 crow::kvm::request_routes(app);
68 crow::redfish::request_routes(app);
69 crow::dbus_monitor::request_routes(app);
Ed Tanousc3ee5222018-05-01 12:58:27 -070070 crow::image_upload::requestRoutes(app);
Ed Tanous911ac312017-08-15 09:37:42 -070071 crow::openbmc_mapper::request_routes(app);
72
Vernon Mauery168792a2018-01-26 13:42:54 -080073 CROW_LOG_INFO << "bmcweb (" << __DATE__ << ": " << __TIME__ << ')';
74 setup_socket(app);
Ed Tanous3dac7492017-08-02 13:46:20 -070075
Ed Tanous911ac312017-08-15 09:37:42 -070076 crow::connections::system_bus =
Ed Tanousaa2e59c2018-04-12 12:17:20 -070077 std::make_shared<sdbusplus::asio::connection>(*io);
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010078 redfish::RedfishService redfish(app);
79
Ed Tanous4758d5b2017-06-06 15:28:13 -070080 app.run();
Ed Tanous9e6e1b22018-03-16 13:08:50 -070081 io->run();
Ed Tanousaa2e59c2018-04-12 12:17:20 -070082
Ed Tanousc3ee5222018-05-01 12:58:27 -070083 crow::connections::system_bus.reset();
Ed Tanous0fdddb12017-02-28 11:06:34 -080084}