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