blob: 7ae22b535d4ec6f8e7b1d00b3a8315b836056f3a [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>
6#include <redfish_v1.hpp>
7#include <security_headers_middleware.hpp>
8#include <ssl_key_handler.hpp>
9#include <token_authorization_middleware.hpp>
10#include <web_kvm.hpp>
11#include <webassets.hpp>
Ed Tanousc4771fb2017-03-13 13:39:49 -070012#include <memory>
Ed Tanous0fdddb12017-02-28 11:06:34 -080013#include <string>
Ed Tanous911ac312017-08-15 09:37:42 -070014#include <crow/app.h>
15#include <boost/asio.hpp>
Ed Tanouscc5a37f2017-05-11 10:27:23 -070016
Ed Tanous99923322017-03-03 14:21:24 -080017int main(int argc, char** argv) {
Ed Tanous3dac7492017-08-02 13:46:20 -070018 auto io = std::make_shared<boost::asio::io_service>();
Ed Tanous911ac312017-08-15 09:37:42 -070019 crow::App<crow::TokenAuthorization::Middleware,
20 crow::SecurityHeadersMiddleware>
Ed Tanous3dac7492017-08-02 13:46:20 -070021 app(io);
Ed Tanousb4d29f42017-03-24 16:39:25 -070022
Ed Tanous911ac312017-08-15 09:37:42 -070023#ifdef CROW_ENABLE_SSL
24 std::string ssl_pem_file("server.pem");
Ed Tanous4d92cbf2017-06-22 15:41:02 -070025 std::cout << "Building SSL context\n";
Ed Tanous4758d5b2017-06-06 15:28:13 -070026
Ed Tanous911ac312017-08-15 09:37:42 -070027 ensuressl::ensure_openssl_key_present_and_valid(ssl_pem_file);
28 std::cout << "SSL Enabled\n";
29 auto ssl_context = ensuressl::get_ssl_context(ssl_pem_file);
30 app.ssl(std::move(ssl_context));
31#endif
32 // Static assets need to be initialized before Authorization, because auth
33 // needs to build the whitelist from the static routes
34 crow::webassets::request_routes(app);
35 crow::TokenAuthorization::request_routes(app);
Ed Tanousf0226cd2017-05-16 12:35:38 -070036
Ed Tanous911ac312017-08-15 09:37:42 -070037 crow::kvm::request_routes(app);
38 crow::redfish::request_routes(app);
39 crow::dbus_monitor::request_routes(app);
40 crow::intel_oem::request_routes(app);
41 crow::openbmc_mapper::request_routes(app);
42
43 crow::logger::setLogLevel(crow::LogLevel::INFO);
44 int port = 18080;
Ed Tanous4d92cbf2017-06-22 15:41:02 -070045 std::cout << "Starting webserver on port " << port << "\n";
Ed Tanous4758d5b2017-06-06 15:28:13 -070046 app.port(port);
Ed Tanous3dac7492017-08-02 13:46:20 -070047
48 // Start dbus connection
Ed Tanous911ac312017-08-15 09:37:42 -070049 crow::connections::system_bus =
50 std::make_shared<dbus::connection>(*io, dbus::bus::system);
Ed Tanous3dac7492017-08-02 13:46:20 -070051
Ed Tanous4758d5b2017-06-06 15:28:13 -070052 app.run();
Ed Tanous0fdddb12017-02-28 11:06:34 -080053}