blob: 2ec7e370ffca38a5a08e4aef10314c7c86929997 [file] [log] [blame]
Ed Tanousf9273472017-02-28 16:05:13 -08001#include "crow/app.h"
Ed Tanousc4771fb2017-03-13 13:39:49 -07002#include "crow/ci_map.h"
Ed Tanousf9273472017-02-28 16:05:13 -08003#include "crow/common.h"
4#include "crow/dumb_timer_queue.h"
5#include "crow/http_connection.h"
Ed Tanousc4771fb2017-03-13 13:39:49 -07006#include "crow/http_parser_merged.h"
Ed Tanousf9273472017-02-28 16:05:13 -08007#include "crow/http_request.h"
8#include "crow/http_response.h"
9#include "crow/http_server.h"
10#include "crow/json.h"
11#include "crow/logging.h"
12#include "crow/middleware.h"
13#include "crow/middleware_context.h"
14#include "crow/mustache.h"
15#include "crow/parser.h"
Ed Tanousc4771fb2017-03-13 13:39:49 -070016#include "crow/query_string.h"
Ed Tanousf9273472017-02-28 16:05:13 -080017#include "crow/routing.h"
Ed Tanous0fdddb12017-02-28 11:06:34 -080018#include "crow/settings.h"
19#include "crow/socket_adaptors.h"
Ed Tanous0fdddb12017-02-28 11:06:34 -080020#include "crow/utility.h"
Ed Tanous0fdddb12017-02-28 11:06:34 -080021#include "crow/websocket.h"
Ed Tanous0fdddb12017-02-28 11:06:34 -080022
Ed Tanous5f34a9c2017-02-28 12:35:13 -080023#include "color_cout_g3_sink.hpp"
Ed Tanous7d3dba42017-04-05 13:04:39 -070024#include "security_headers_middleware.hpp"
Ed Tanous9140a672017-04-24 17:01:32 -070025#include "ssl_key_handler.hpp"
Ed Tanous7d3dba42017-04-05 13:04:39 -070026#include "token_authorization_middleware.hpp"
Ed Tanous9140a672017-04-24 17:01:32 -070027#include "web_kvm.hpp"
28#include "webassets.hpp"
29#include "webassets.hpp"
Ed Tanousb4d29f42017-03-24 16:39:25 -070030
31#include <boost/asio.hpp>
32#include <boost/endian/arithmetic.hpp>
33
Ed Tanous0fdddb12017-02-28 11:06:34 -080034#include <iostream>
Ed Tanousc4771fb2017-03-13 13:39:49 -070035#include <memory>
Ed Tanous0fdddb12017-02-28 11:06:34 -080036#include <string>
Ed Tanousc4771fb2017-03-13 13:39:49 -070037#include <unordered_set>
Ed Tanous9b65f1f2017-03-07 15:17:13 -080038
Ed Tanous99923322017-03-03 14:21:24 -080039int main(int argc, char** argv) {
Ed Tanous9b65f1f2017-03-07 15:17:13 -080040 auto worker(g3::LogWorker::createLogWorker());
Ed Tanous1ccd57c2017-03-21 13:15:58 -070041 std::string logger_name("bmcweb");
42 std::string folder("/tmp/");
43 auto handle = worker->addDefaultLogger(logger_name, folder);
Ed Tanous99923322017-03-03 14:21:24 -080044 g3::initializeLogging(worker.get());
Ed Tanous1ccd57c2017-03-21 13:15:58 -070045 auto sink_handle = worker->addSink(std::make_unique<crow::ColorCoutSink>(),
46 &crow::ColorCoutSink::ReceiveLogMessage);
Ed Tanous0fdddb12017-02-28 11:06:34 -080047
Ed Tanous99923322017-03-03 14:21:24 -080048 std::string ssl_pem_file("server.pem");
49 ensuressl::ensure_openssl_key_present_and_valid(ssl_pem_file);
Ed Tanous0fdddb12017-02-28 11:06:34 -080050
Ed Tanous7d3dba42017-04-05 13:04:39 -070051 crow::App<crow::TokenAuthorizationMiddleware, crow::SecurityHeadersMiddleware>
52 app;
Ed Tanousb4d29f42017-03-24 16:39:25 -070053
Ed Tanous99923322017-03-03 14:21:24 -080054 crow::webassets::request_routes(app);
Ed Tanousc81ca422017-03-21 16:18:49 -070055 crow::kvm::request_routes(app);
Ed Tanous0fdddb12017-02-28 11:06:34 -080056
Ed Tanous9b65f1f2017-03-07 15:17:13 -080057 crow::logger::setLogLevel(crow::LogLevel::INFO);
Ed Tanousc4771fb2017-03-13 13:39:49 -070058 CROW_ROUTE(app, "/systeminfo")
59 ([]() {
60
61 crow::json::wvalue j;
62 j["device_id"] = 0x7B;
63 j["device_provides_sdrs"] = true;
64 j["device_revision"] = true;
65 j["device_available"] = true;
66 j["firmware_revision"] = "0.68";
67
68 j["ipmi_revision"] = "2.0";
69 j["supports_chassis_device"] = true;
70 j["supports_bridge"] = true;
71 j["supports_ipmb_event_generator"] = true;
72 j["supports_ipmb_event_receiver"] = true;
73 j["supports_fru_inventory_device"] = true;
74 j["supports_sel_device"] = true;
75 j["supports_sdr_repository_device"] = true;
76 j["supports_sensor_device"] = true;
77
78 j["firmware_aux_revision"] = "0.60.foobar";
79
80 return j;
81 });
82
Ed Tanousc4771fb2017-03-13 13:39:49 -070083 CROW_ROUTE(app, "/ipmiws")
84 .websocket()
85 .onopen([&](crow::websocket::connection& conn) {
86
87 })
Ed Tanous1ccd57c2017-03-21 13:15:58 -070088 .onclose(
89 [&](crow::websocket::connection& conn, const std::string& reason) {
Ed Tanousc4771fb2017-03-13 13:39:49 -070090
Ed Tanous1ccd57c2017-03-21 13:15:58 -070091 })
92 .onmessage([&](crow::websocket::connection& conn, const std::string& data,
93 bool is_binary) {
Ed Tanousc4771fb2017-03-13 13:39:49 -070094 boost::asio::io_service io_service;
Ed Tanous1ccd57c2017-03-21 13:15:58 -070095 using boost::asio::ip::udp;
96 udp::resolver resolver(io_service);
97 udp::resolver::query query(udp::v4(), "10.243.48.31", "623");
98 udp::endpoint receiver_endpoint = *resolver.resolve(query);
99
100 udp::socket socket(io_service);
101 socket.open(udp::v4());
102
103 socket.send_to(boost::asio::buffer(data), receiver_endpoint);
104
105 std::array<char, 255> recv_buf;
106
107 udp::endpoint sender_endpoint;
108 size_t len =
109 socket.receive_from(boost::asio::buffer(recv_buf), sender_endpoint);
110 // TODO(ed) THis is ugly. Find a way to not make a copy (ie, use
Ed Tanous7d3dba42017-04-05 13:04:39 -0700111 // std::string::data() to
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700112 std::string str(std::begin(recv_buf), std::end(recv_buf));
113 LOG(DEBUG) << "Got " << str << "back \n";
114 conn.send_binary(str);
115
Ed Tanousc4771fb2017-03-13 13:39:49 -0700116 });
Ed Tanous01250f22017-04-18 17:49:51 -0700117 auto ssl_context = ensuressl::get_ssl_context(ssl_pem_file);
Ed Tanous9140a672017-04-24 17:01:32 -0700118 app.port(18080)
119 //.ssl(std::move(ssl_context))
120 //.concurrency(4)
121 .run();
Ed Tanous0fdddb12017-02-28 11:06:34 -0800122}