1 #include <web_kvm.hpp> 2 #include <webassets.hpp> 3 #include "ssl_key_handler.hpp" 4 5 #include "crow/app.h" 6 #include "crow/ci_map.h" 7 #include "crow/common.h" 8 #include "crow/dumb_timer_queue.h" 9 #include "crow/http_connection.h" 10 #include "crow/http_parser_merged.h" 11 #include "crow/http_request.h" 12 #include "crow/http_response.h" 13 #include "crow/http_server.h" 14 #include "crow/json.h" 15 #include "crow/logging.h" 16 #include "crow/middleware.h" 17 #include "crow/middleware_context.h" 18 #include "crow/mustache.h" 19 #include "crow/parser.h" 20 #include "crow/query_string.h" 21 #include "crow/routing.h" 22 #include "crow/settings.h" 23 #include "crow/socket_adaptors.h" 24 #include "crow/utility.h" 25 #include "crow/websocket.h" 26 27 #include "color_cout_g3_sink.hpp" 28 #include "webassets.hpp" 29 30 #include "security_headers_middleware.hpp" 31 #include "token_authorization_middleware.hpp" 32 33 #include <boost/asio.hpp> 34 #include <boost/endian/arithmetic.hpp> 35 36 #include <iostream> 37 #include <memory> 38 #include <string> 39 #include <unordered_set> 40 41 int main(int argc, char** argv) { 42 auto worker(g3::LogWorker::createLogWorker()); 43 std::string logger_name("bmcweb"); 44 std::string folder("/tmp/"); 45 auto handle = worker->addDefaultLogger(logger_name, folder); 46 g3::initializeLogging(worker.get()); 47 auto sink_handle = worker->addSink(std::make_unique<crow::ColorCoutSink>(), 48 &crow::ColorCoutSink::ReceiveLogMessage); 49 50 std::string ssl_pem_file("server.pem"); 51 ensuressl::ensure_openssl_key_present_and_valid(ssl_pem_file); 52 53 crow::App<crow::TokenAuthorizationMiddleware, crow::SecurityHeadersMiddleware> 54 app; 55 56 crow::webassets::request_routes(app); 57 crow::kvm::request_routes(app); 58 59 crow::logger::setLogLevel(crow::LogLevel::INFO); 60 CROW_ROUTE(app, "/systeminfo") 61 ([]() { 62 63 crow::json::wvalue j; 64 j["device_id"] = 0x7B; 65 j["device_provides_sdrs"] = true; 66 j["device_revision"] = true; 67 j["device_available"] = true; 68 j["firmware_revision"] = "0.68"; 69 70 j["ipmi_revision"] = "2.0"; 71 j["supports_chassis_device"] = true; 72 j["supports_bridge"] = true; 73 j["supports_ipmb_event_generator"] = true; 74 j["supports_ipmb_event_receiver"] = true; 75 j["supports_fru_inventory_device"] = true; 76 j["supports_sel_device"] = true; 77 j["supports_sdr_repository_device"] = true; 78 j["supports_sensor_device"] = true; 79 80 j["firmware_aux_revision"] = "0.60.foobar"; 81 82 return j; 83 }); 84 85 CROW_ROUTE(app, "/ipmiws") 86 .websocket() 87 .onopen([&](crow::websocket::connection& conn) { 88 89 }) 90 .onclose( 91 [&](crow::websocket::connection& conn, const std::string& reason) { 92 93 }) 94 .onmessage([&](crow::websocket::connection& conn, const std::string& data, 95 bool is_binary) { 96 boost::asio::io_service io_service; 97 using boost::asio::ip::udp; 98 udp::resolver resolver(io_service); 99 udp::resolver::query query(udp::v4(), "10.243.48.31", "623"); 100 udp::endpoint receiver_endpoint = *resolver.resolve(query); 101 102 udp::socket socket(io_service); 103 socket.open(udp::v4()); 104 105 socket.send_to(boost::asio::buffer(data), receiver_endpoint); 106 107 std::array<char, 255> recv_buf; 108 109 udp::endpoint sender_endpoint; 110 size_t len = 111 socket.receive_from(boost::asio::buffer(recv_buf), sender_endpoint); 112 // TODO(ed) THis is ugly. Find a way to not make a copy (ie, use 113 // std::string::data() to 114 std::string str(std::begin(recv_buf), std::end(recv_buf)); 115 LOG(DEBUG) << "Got " << str << "back \n"; 116 conn.send_binary(str); 117 118 }); 119 120 app.port(18080) 121 //.ssl(std::move(ensuressl::get_ssl_context(ssl_pem_file))) 122 .run(); 123 } 124