blob: 8060f88ca00fd10107b208859e9e1d1cfc1bd789 [file] [log] [blame]
Ed Tanousc9b55212017-06-12 13:25:51 -07001#include <dbus/connection.hpp>
Ed Tanous911ac312017-08-15 09:37:42 -07002#include <dbus_monitor.hpp>
3#include <dbus_singleton.hpp>
4#include <intel_oem.hpp>
5#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>
8#include <security_headers_middleware.hpp>
9#include <ssl_key_handler.hpp>
10#include <token_authorization_middleware.hpp>
11#include <web_kvm.hpp>
12#include <webassets.hpp>
Ed Tanousc4771fb2017-03-13 13:39:49 -070013#include <memory>
Ed Tanous0fdddb12017-02-28 11:06:34 -080014#include <string>
Ed Tanous911ac312017-08-15 09:37:42 -070015#include <crow/app.h>
16#include <boost/asio.hpp>
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010017#include "redfish.hpp"
Ed Tanouscc5a37f2017-05-11 10:27:23 -070018
Ed Tanous99923322017-03-03 14:21:24 -080019int main(int argc, char** argv) {
Ed Tanous3dac7492017-08-02 13:46:20 -070020 auto io = std::make_shared<boost::asio::io_service>();
Ed Tanousba9f9a62017-10-11 16:40:35 -070021 crow::App<crow::PersistentData::Middleware,
22 crow::TokenAuthorization::Middleware,
Ed Tanous911ac312017-08-15 09:37:42 -070023 crow::SecurityHeadersMiddleware>
Ed Tanous3dac7492017-08-02 13:46:20 -070024 app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070025
Ed Tanous911ac312017-08-15 09:37:42 -070026#ifdef CROW_ENABLE_SSL
27 std::string ssl_pem_file("server.pem");
Ed Tanous4d92cbf2017-06-22 15:41:02 -070028 std::cout << "Building SSL context\n";
Ed Tanous4758d5b2017-06-06 15:28:13 -070029
Ed Tanous911ac312017-08-15 09:37:42 -070030 ensuressl::ensure_openssl_key_present_and_valid(ssl_pem_file);
31 std::cout << "SSL Enabled\n";
32 auto ssl_context = ensuressl::get_ssl_context(ssl_pem_file);
33 app.ssl(std::move(ssl_context));
34#endif
35 // Static assets need to be initialized before Authorization, because auth
36 // needs to build the whitelist from the static routes
37 crow::webassets::request_routes(app);
38 crow::TokenAuthorization::request_routes(app);
Ed Tanousf0226cd2017-05-16 12:35:38 -070039
Ed Tanous911ac312017-08-15 09:37:42 -070040 crow::kvm::request_routes(app);
41 crow::redfish::request_routes(app);
42 crow::dbus_monitor::request_routes(app);
43 crow::intel_oem::request_routes(app);
44 crow::openbmc_mapper::request_routes(app);
45
46 crow::logger::setLogLevel(crow::LogLevel::INFO);
47 int port = 18080;
Ed Tanous4d92cbf2017-06-22 15:41:02 -070048 std::cout << "Starting webserver on port " << port << "\n";
Ed Tanous4758d5b2017-06-06 15:28:13 -070049 app.port(port);
Ed Tanous3dac7492017-08-02 13:46:20 -070050
51 // Start dbus connection
Ed Tanous911ac312017-08-15 09:37:42 -070052 crow::connections::system_bus =
53 std::make_shared<dbus::connection>(*io, dbus::bus::system);
Ed Tanous3dac7492017-08-02 13:46:20 -070054
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010055 redfish::RedfishService redfish(app);
56
Ed Tanous4758d5b2017-06-06 15:28:13 -070057 app.run();
Ed Tanous0fdddb12017-02-28 11:06:34 -080058}