blob: bf1168e48ede0043dd965ab8867825ac18286b60 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanous3cd70722024-04-06 09:24:01 -07003#include "webserver_run.hpp"
4
5#include "bmcweb_config.h"
6
7#include "app.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -07008#include "dbus_monitor.hpp"
9#include "dbus_singleton.hpp"
10#include "event_service_manager.hpp"
11#include "google/google_service_root.hpp"
12#include "hostname_monitor.hpp"
13#include "ibm/management_console_rest.hpp"
14#include "image_upload.hpp"
Ed Tanous9838eb22025-01-29 16:24:42 -080015#include "io_context_singleton.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070016#include "kvm_websocket.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070017#include "logging.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070018#include "login_routes.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070019#include "obmc_console.hpp"
20#include "openbmc_dbus_rest.hpp"
21#include "redfish.hpp"
22#include "redfish_aggregator.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070023#include "user_monitor.hpp"
24#include "vm_websocket.hpp"
25#include "webassets.hpp"
26
Ed Tanous3cd70722024-04-06 09:24:01 -070027#include <boost/asio/io_context.hpp>
28#include <sdbusplus/asio/connection.hpp>
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070029#include <sdbusplus/asio/object_server.hpp>
Ed Tanous5b904292024-04-16 11:10:17 -070030
Ed Tanous41fe81c2024-09-02 15:08:41 -070031#include <algorithm>
Ed Tanous5b904292024-04-16 11:10:17 -070032#include <memory>
Ed Tanous41fe81c2024-09-02 15:08:41 -070033#include <string>
34#include <string_view>
Ed Tanous3cd70722024-04-06 09:24:01 -070035
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070036static void setLogLevel(const std::string& logLevel)
37{
38 const std::basic_string_view<char>* iter =
39 std::ranges::find(crow::mapLogLevelFromName, logLevel);
40 if (iter == crow::mapLogLevelFromName.end())
41 {
42 BMCWEB_LOG_ERROR("log-level {} not found", logLevel);
43 return;
44 }
45 crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel);
46 BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel);
47}
48
Ed Tanous3cd70722024-04-06 09:24:01 -070049int run()
50{
Ed Tanous9838eb22025-01-29 16:24:42 -080051 boost::asio::io_context& io = getIoContext();
52 App app;
Ed Tanous3cd70722024-04-06 09:24:01 -070053
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070054 std::shared_ptr<sdbusplus::asio::connection> systemBus =
Ed Tanous9838eb22025-01-29 16:24:42 -080055 std::make_shared<sdbusplus::asio::connection>(io);
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070056 crow::connections::systemBus = systemBus.get();
57
58 auto server = sdbusplus::asio::object_server(systemBus);
59
60 std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
61 server.add_interface("/xyz/openbmc_project/bmcweb",
62 "xyz.openbmc_project.bmcweb");
63
64 iface->register_method("SetLogLevel", setLogLevel);
65
66 iface->initialize();
Ed Tanous3cd70722024-04-06 09:24:01 -070067
68 // Static assets need to be initialized before Authorization, because auth
69 // needs to build the whitelist from the static routes
70
Ed Tanous25b54db2024-04-17 15:40:31 -070071 if constexpr (BMCWEB_STATIC_HOSTING)
72 {
73 crow::webassets::requestRoutes(app);
74 }
Ed Tanous3cd70722024-04-06 09:24:01 -070075
Ed Tanous25b54db2024-04-17 15:40:31 -070076 if constexpr (BMCWEB_KVM)
77 {
78 crow::obmc_kvm::requestRoutes(app);
79 }
Ed Tanous3cd70722024-04-06 09:24:01 -070080
Ed Tanous25b54db2024-04-17 15:40:31 -070081 if constexpr (BMCWEB_REDFISH)
82 {
83 redfish::RedfishService redfish(app);
Alexander Hansen6c58a032024-11-21 15:27:04 -080084
85 // Create EventServiceManager instance and initialize Config
Ed Tanous9838eb22025-01-29 16:24:42 -080086 redfish::EventServiceManager::getInstance();
Ed Tanous3cd70722024-04-06 09:24:01 -070087
Ed Tanous25b54db2024-04-17 15:40:31 -070088 if constexpr (BMCWEB_REDFISH_AGGREGATION)
89 {
90 // Create RedfishAggregator instance and initialize Config
Ed Tanous9838eb22025-01-29 16:24:42 -080091 redfish::RedfishAggregator::getInstance();
Ed Tanous25b54db2024-04-17 15:40:31 -070092 }
93 }
Ed Tanous3cd70722024-04-06 09:24:01 -070094
Ed Tanous25b54db2024-04-17 15:40:31 -070095 if constexpr (BMCWEB_REST)
96 {
97 crow::dbus_monitor::requestRoutes(app);
98 crow::image_upload::requestRoutes(app);
99 crow::openbmc_mapper::requestRoutes(app);
100 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700101
Ed Tanous25b54db2024-04-17 15:40:31 -0700102 if constexpr (BMCWEB_HOST_SERIAL_SOCKET)
103 {
104 crow::obmc_console::requestRoutes(app);
105 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700106
Ed Tanous3cd70722024-04-06 09:24:01 -0700107 crow::obmc_vm::requestRoutes(app);
Ed Tanous3cd70722024-04-06 09:24:01 -0700108
Ed Tanous25b54db2024-04-17 15:40:31 -0700109 if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE)
110 {
111 crow::ibm_mc::requestRoutes(app);
112 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700113
Ed Tanous25b54db2024-04-17 15:40:31 -0700114 if constexpr (BMCWEB_GOOGLE_API)
115 {
116 crow::google_api::requestRoutes(app);
117 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700118
Ed Tanous3cd70722024-04-06 09:24:01 -0700119 crow::login_routes::requestRoutes(app);
120
Ed Tanous25b54db2024-04-17 15:40:31 -0700121 if constexpr (!BMCWEB_INSECURE_DISABLE_SSL)
Ed Tanous8db83742024-04-13 09:11:15 -0700122 {
123 BMCWEB_LOG_INFO("Start Hostname Monitor Service...");
124 crow::hostname_monitor::registerHostnameSignal();
125 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700126
127 bmcweb::registerUserRemovedSignal();
128
129 app.run();
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -0700130
131 systemBus->request_name("xyz.openbmc_project.bmcweb");
132
Ed Tanous9838eb22025-01-29 16:24:42 -0800133 io.run();
Ed Tanous3cd70722024-04-06 09:24:01 -0700134
135 crow::connections::systemBus = nullptr;
136
Ed Tanous3cd70722024-04-06 09:24:01 -0700137 return 0;
138}