Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 1 | #include <dbus/connection.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 2 | #include <dbus_monitor.hpp> |
| 3 | #include <dbus_singleton.hpp> |
| 4 | #include <intel_oem.hpp> |
| 5 | #include <openbmc_dbus_rest.hpp> |
Ed Tanous | ba9f9a6 | 2017-10-11 16:40:35 -0700 | [diff] [blame] | 6 | #include <persistent_data_middleware.hpp> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 7 | #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 Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame] | 13 | #include <memory> |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 14 | #include <string> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 15 | #include <crow/app.h> |
| 16 | #include <boost/asio.hpp> |
Ed Tanous | cc5a37f | 2017-05-11 10:27:23 -0700 | [diff] [blame] | 17 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 18 | int main(int argc, char** argv) { |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 19 | auto io = std::make_shared<boost::asio::io_service>(); |
Ed Tanous | ba9f9a6 | 2017-10-11 16:40:35 -0700 | [diff] [blame] | 20 | crow::App<crow::PersistentData::Middleware, |
| 21 | crow::TokenAuthorization::Middleware, |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 22 | crow::SecurityHeadersMiddleware> |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 23 | app(io); |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 24 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 25 | #ifdef CROW_ENABLE_SSL |
| 26 | std::string ssl_pem_file("server.pem"); |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 27 | std::cout << "Building SSL context\n"; |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 28 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 29 | ensuressl::ensure_openssl_key_present_and_valid(ssl_pem_file); |
| 30 | std::cout << "SSL Enabled\n"; |
| 31 | auto ssl_context = ensuressl::get_ssl_context(ssl_pem_file); |
| 32 | app.ssl(std::move(ssl_context)); |
| 33 | #endif |
| 34 | // Static assets need to be initialized before Authorization, because auth |
| 35 | // needs to build the whitelist from the static routes |
| 36 | crow::webassets::request_routes(app); |
| 37 | crow::TokenAuthorization::request_routes(app); |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 38 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 39 | crow::kvm::request_routes(app); |
| 40 | crow::redfish::request_routes(app); |
| 41 | crow::dbus_monitor::request_routes(app); |
| 42 | crow::intel_oem::request_routes(app); |
| 43 | crow::openbmc_mapper::request_routes(app); |
| 44 | |
| 45 | crow::logger::setLogLevel(crow::LogLevel::INFO); |
| 46 | int port = 18080; |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 47 | std::cout << "Starting webserver on port " << port << "\n"; |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 48 | app.port(port); |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 49 | |
| 50 | // Start dbus connection |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 51 | crow::connections::system_bus = |
| 52 | std::make_shared<dbus::connection>(*io, dbus::bus::system); |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 53 | |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 54 | app.run(); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 55 | } |