Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
confighttp.cpp File Reference

Definitions for the Web UI Config HTTPS server. More...

#include <filesystem>
#include <format>
#include <fstream>
#include <set>
#include <sstream>
#include <thread>
#include <condition_variable>
#include <mutex>
#include <numeric>
#include <algorithm>
#include <atomic>
#include <deque>
#include <map>
#include <limits>
#include <optional>
#include <iterator>
#include <cctype>
#include <sys/utsname.h>
#include <unistd.h>
#include <cerrno>
#include <cstring>
#include <fcntl.h>
#include <sys/stat.h>
#include <boost/algorithm/string.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/filesystem.hpp>
#include <boost/process/v1/search_path.hpp>
#include <nlohmann/json.hpp>
#include <Simple-Web-Server/crypto.hpp>
#include <Simple-Web-Server/server_https.hpp>
#include "audio.h"
#include "config.h"
#include "confighttp.h"
#include "crypto.h"
#include "display_device.h"
#include "file_handler.h"
#include "globals.h"
#include "httpcommon.h"
#include "logging.h"
#include "network.h"
#include "nvhttp.h"
#include "platform/common.h"
#include "process.h"
#include "rtsp.h"
#include "stream.h"
#include "utility.h"
#include "uuid.h"
#include "video.h"
#include "platform/linux/bounded_command.h"
#include "platform/linux/game_library.h"
#include "platform/linux/misc.h"
#include "platform/linux/prelogin.h"
Include dependency graph for confighttp.cpp:

Go to the source code of this file.

Classes

class  confighttp::HestiaHTTPSServer
struct  confighttp::report_timeline::system_t
 The machine around the stream. A value nobody may read here stays negative. More...
struct  confighttp::report_timeline::sample_t
struct  confighttp::report_timeline::previous_t

Namespaces

namespace  confighttp::report_timeline

Typedefs

using confighttp::https_server_t = HestiaHTTPSServer
using confighttp::args_t = SimpleWeb::CaseInsensitiveMultimap
using confighttp::resp_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTPS>::Response>
using confighttp::req_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTPS>::Request>

Enumerations

enum class  confighttp::op_e { ADD , REMOVE }

Functions

nlohmann::json confighttp::hestia_runtime_status_json ()
bool confighttp::local_api_token_origin_allowed (std::string_view address)
 Whether an address may authenticate with the Game Mode local token.
std::filesystem::path confighttp::local_api_token_path ()
bool confighttp::token_matches (std::string_view presented, std::string_view expected)
void confighttp::write_local_api_token ()
void confighttp::remove_local_api_token ()
bool confighttp::has_local_api_token (req_https_t request)
void confighttp::print_req (const req_https_t &request)
 Log the request details.
void confighttp::send_response (resp_https_t response, const nlohmann::json &output_tree)
 Send a response.
void confighttp::send_unauthorized (resp_https_t response, req_https_t request)
 Send a 401 Unauthorized response.
void confighttp::send_redirect (resp_https_t response, req_https_t request, const char *path)
 Send a redirect response.
std::string confighttp::getCookieValue (const std::string &cookieString, const std::string &key)
 Retrieve the value of a key from a cookie string.
bool confighttp::checkIPOrigin (resp_https_t response, req_https_t request)
 Check if the IP origin is allowed.
bool confighttp::authenticate (resp_https_t response, req_https_t request, bool needsRedirect=false)
 Authenticate the request.
void confighttp::not_found (resp_https_t response, req_https_t request)
 Send a 404 Not Found response.
void confighttp::bad_request (resp_https_t response, req_https_t request, const std::string &error_message="Bad Request")
 Send a 400 Bad Request response.
bool confighttp::validateContentType (resp_https_t response, req_https_t request, const std::string_view &contentType)
 Validate the request content type and send bad request when mismatch.
void confighttp::send_web_page (resp_https_t response, req_https_t request, const std::string &page, const SimpleWeb::CaseInsensitiveMultimap &extra_headers={})
 Serve a page from the packaged web assets.
void confighttp::getIndexPage (resp_https_t response, req_https_t request)
 Get the index page.
void confighttp::getPinPage (resp_https_t response, req_https_t request)
 Get the PIN page.
void confighttp::getAppsPage (resp_https_t response, req_https_t request)
 Get the apps page.
void confighttp::getClientsPage (resp_https_t response, req_https_t request)
 Get the clients page.
void confighttp::getConfigPage (resp_https_t response, req_https_t request)
 Get the configuration page.
void confighttp::getPasswordPage (resp_https_t response, req_https_t request)
 Get the password page.
void confighttp::getLoginPage (resp_https_t response, req_https_t request)
 Get the login page.
void confighttp::getWelcomePage (resp_https_t response, req_https_t request)
 Get the welcome page.
void confighttp::getTroubleshootingPage (resp_https_t response, req_https_t request)
 Get the troubleshooting page.
void confighttp::getFaviconImage (resp_https_t response, req_https_t request)
 Get the favicon image.
void confighttp::getHermesLogoImage (resp_https_t response, req_https_t request)
 Get the Hermes logo image.
bool confighttp::isChildPath (fs::path const &base, fs::path const &query)
 Check if a path is a child of another path.
void confighttp::getNodeModules (resp_https_t response, req_https_t request)
 Get an asset from the node_modules directory.
void confighttp::getMetrics (resp_https_t response, req_https_t request)
 Get the live runtime status: encoder, session, and pipeline counters. The same view the Hestia diagnostics return, behind the normal Web UI session auth so the dashboard can poll it.
void confighttp::getApps (resp_https_t response, req_https_t request)
 Get the list of available applications.
void confighttp::getLibrary (resp_https_t response, req_https_t request)
 List the games installed in Steam and Lutris, to add as apps.
void confighttp::saveApp (resp_https_t response, req_https_t request)
 Save an application. To save a new application the UUID must be empty. To update an existing application, you must provide the current UUID of the application.
void confighttp::closeApp (resp_https_t response, req_https_t request)
 Close the currently running application.
void confighttp::reorderApps (resp_https_t response, req_https_t request)
 Reorder applications.
void confighttp::deleteApp (resp_https_t response, req_https_t request)
 Delete an application.
void confighttp::getClients (resp_https_t response, req_https_t request)
 Get the list of paired clients.
void confighttp::updateClient (resp_https_t response, req_https_t request)
 Update client information.
void confighttp::unpair (resp_https_t response, req_https_t request)
 Unpair a client.
void confighttp::unpairAll (resp_https_t response, req_https_t request)
 Unpair all clients.
nlohmann::json confighttp::computed_config_json ()
 Get the configuration settings.
nlohmann::json & confighttp::overlay_config_file (nlohmann::json &response, const std::unordered_map< std::string, std::string > &file_values)
 Overlay a parsed hermes.conf onto response, in place.
void confighttp::getConfig (resp_https_t response, req_https_t request)
 Get the current configuration: the computed values Hermes is running with, overlaid with what the configuration file sets explicitly.
void confighttp::getHestiaCapabilities (resp_https_t response, req_https_t request)
 Return the static Hestia extension capabilities.
nlohmann::json confighttp::hestia_capabilities_json ()
 The Hestia extension capabilities document.
void confighttp::send_hestia_error (resp_https_t response, SimpleWeb::StatusCode status, const char *code, const char *message)
bool confighttp::authenticate_hestia_client (resp_https_t response, req_https_t request, crypto::PERM permission, const char *operation)
std::shared_ptr< crypto::named_cert_t > confighttp::authenticate_hestia_paired_client (resp_https_t response, req_https_t request)
bool confighttp::hestia_has_exact_keys (const nlohmann::json &object, const std::set< std::string > &keys)
bool confighttp::hestia_is_positive_integer (const nlohmann::json &value)
bool confighttp::hestia_is_one_of (const nlohmann::json &value, const std::set< std::string > &values)
bool confighttp::validate_hestia_session_prepare (const nlohmann::json &request, std::string &error)
void confighttp::prepare_hestia_session (resp_https_t response, req_https_t request)
 Store settings for a paired Hestia client's next stream launch.
void confighttp::stop_hestia_session (resp_https_t response, req_https_t request)
nlohmann::json confighttp::hestia_display_status_json ()
void confighttp::get_hestia_display_status (resp_https_t response, req_https_t request)
void confighttp::recover_hestia_display (resp_https_t response, req_https_t request)
void confighttp::get_hestia_commands (resp_https_t response, req_https_t request)
void confighttp::get_hestia_client_permissions (resp_https_t response, req_https_t request)
void confighttp::get_hestia_clipboard (resp_https_t response, req_https_t request)
nlohmann::json confighttp::hestia_preflight_json ()
 Aggregate "is the host ready to stream?" checks.
void confighttp::get_hestia_diagnostics (resp_https_t response, req_https_t request)
void confighttp::get_hestia_stream_info (resp_https_t response, req_https_t request)
std::optional< long long > confighttp::report_timeline::read_number (const fs::path &path)
std::string confighttp::report_timeline::read_word (const fs::path &path)
std::optional< fs::path > confighttp::report_timeline::hwmon (std::initializer_list< std::string_view > names, const fs::path &root="/sys/class/hwmon")
double confighttp::report_timeline::temperature (const fs::path &dir, std::string_view label)
double confighttp::report_timeline::current_amdgpu_clock (const fs::path &path)
void confighttp::report_timeline::read_nvidia (const std::string &pci_address, system_t &s)
system_t confighttp::report_timeline::read_system (bool gpu)
void confighttp::report_timeline::record ()
std::vector< sample_t > confighttp::report_timeline::snapshot ()
void confighttp::machine_snapshot (std::ostream &out)
std::string confighttp::diagnostic_report ()
void confighttp::send_diagnostic_report (resp_https_t response)
void confighttp::getDiagnosticReport (resp_https_t response, req_https_t request)
 Download a diagnostic report of this host.
void confighttp::get_hestia_diagnostic_report (resp_https_t response, req_https_t request)
void confighttp::set_hestia_clipboard (resp_https_t response, req_https_t request)
void confighttp::run_hestia_command (resp_https_t response, req_https_t request)
void confighttp::getLocale (resp_https_t response, req_https_t request)
 Get the locale setting.
void confighttp::saveConfig (resp_https_t response, req_https_t request)
 Save the configuration settings.
bool confighttp::running_in_container ()
 Whether Hermes is running inside a container.
void confighttp::installEvdi (resp_https_t response, req_https_t request)
void confighttp::getEvdiInstallStatus (resp_https_t response, req_https_t request)
void confighttp::getEvdiStatus (resp_https_t response, req_https_t request)
void confighttp::getHermesKmsStatus (resp_https_t response, req_https_t request)
void confighttp::getSessions (resp_https_t response, req_https_t request)
 List the isolated sessions this server is holding.
void confighttp::getGameModeStatus (resp_https_t response, req_https_t request)
 Everything the Game Mode console shows on one screen, in one call.
void confighttp::terminateSession (resp_https_t response, req_https_t request)
 End one isolated session.
void confighttp::getClipboardStatus (resp_https_t response, req_https_t request)
void confighttp::installClipboard (resp_https_t response, req_https_t request)
void confighttp::uploadCover (resp_https_t response, req_https_t request)
 Upload a cover image.
void confighttp::getLogs (resp_https_t response, req_https_t request)
 Get the logs from the log file.
void confighttp::savePassword (resp_https_t response, req_https_t request)
 Update existing credentials.
void confighttp::getOTP (resp_https_t response, req_https_t request)
 Get a one-time password (OTP).
void confighttp::savePin (resp_https_t response, req_https_t request)
 Send a PIN code to the host.
void confighttp::resetDisplayDevicePersistence (resp_https_t response, req_https_t request)
 Reset the display device persistence.
void confighttp::restart (resp_https_t response, req_https_t request)
 Restart Hermes.
void confighttp::quit (resp_https_t response, req_https_t request)
 Quit Hermes.
void confighttp::launchApp (resp_https_t response, req_https_t request)
 Launch an application.
void confighttp::disconnect (resp_https_t response, req_https_t request)
 Disconnect a client.
void confighttp::login (resp_https_t response, req_https_t request)
 Login the user.
void confighttp::start ()
 Start the HTTPS server.

Variables

std::string confighttp::sessionCookie
std::string confighttp::localApiToken
 A bearer token any local process of this user may present.
std::filesystem::path confighttp::localApiTokenPath
struct confighttp::report_timeline::previous_t confighttp::report_timeline::previous
std::string confighttp::report_timeline::encode_card
 The encoding GPU's sysfs device directory.
std::mutex confighttp::report_timeline::mutex
std::deque< sample_t > confighttp::report_timeline::samples
constexpr std::size_t confighttp::report_timeline::max_samples = 720

Detailed Description

Definitions for the Web UI Config HTTPS server.

Todo
Authentication, better handling of routes common to nvhttp, cleanup

Definition in file confighttp.cpp.

Macro Definition Documentation

◆ BOOST_BIND_GLOBAL_PLACEHOLDERS

#define BOOST_BIND_GLOBAL_PLACEHOLDERS

Definition at line 7 of file confighttp.cpp.

Typedef Documentation

◆ args_t

using confighttp::args_t = SimpleWeb::CaseInsensitiveMultimap

Definition at line 189 of file confighttp.cpp.

◆ https_server_t

using confighttp::https_server_t = HestiaHTTPSServer

Definition at line 188 of file confighttp.cpp.

◆ req_https_t

using confighttp::req_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTPS>::Request>

Definition at line 191 of file confighttp.cpp.

◆ resp_https_t

using confighttp::resp_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTPS>::Response>

Definition at line 190 of file confighttp.cpp.

Enumeration Type Documentation

◆ op_e

enum class confighttp::op_e
strong
Enumerator
ADD 

Add client.

REMOVE 

Remove client.

Definition at line 194 of file confighttp.cpp.

Function Documentation

◆ authenticate()

bool confighttp::authenticate ( resp_https_t response,
req_https_t request,
bool needsRedirect = false )

Authenticate the request.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
needsRedirectWhether to redirect on failure.
Returns
True if authenticated, false otherwise.

This function uses session cookies (if set) and ensures they have not expired.

Definition at line 720 of file confighttp.cpp.

◆ authenticate_hestia_client()

bool confighttp::authenticate_hestia_client ( resp_https_t response,
req_https_t request,
crypto::PERM permission,
const char * operation )

Definition at line 1762 of file confighttp.cpp.

◆ authenticate_hestia_paired_client()

std::shared_ptr< crypto::named_cert_t > confighttp::authenticate_hestia_paired_client ( resp_https_t response,
req_https_t request )

Definition at line 1778 of file confighttp.cpp.

◆ bad_request()

void confighttp::bad_request ( resp_https_t response,
req_https_t request,
const std::string & error_message = "Bad Request" )

Send a 400 Bad Request response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
error_messageThe error message.

Definition at line 787 of file confighttp.cpp.

◆ checkIPOrigin()

bool confighttp::checkIPOrigin ( resp_https_t response,
req_https_t request )

Check if the IP origin is allowed.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Returns
True if allowed, false otherwise.

Definition at line 700 of file confighttp.cpp.

◆ closeApp()

void confighttp::closeApp ( resp_https_t response,
req_https_t request )

Close the currently running application.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
HTTP request
POST /api/apps/close
Request body: null

Definition at line 1298 of file confighttp.cpp.

◆ computed_config_json()

nlohmann::json confighttp::computed_config_json ( )

Get the configuration settings.

The fields the Web UI's config response computes for itself: host status, platform and version. Never configuration.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Every key here must also be in config::server_computed_keys(), which is what keeps a hermes.conf from overwriting one of them; a test asserts it.

Definition at line 1619 of file confighttp.cpp.

◆ deleteApp()

void confighttp::deleteApp ( resp_https_t response,
req_https_t request )

Delete an application.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
HTTP request
POST /api/apps/delete
Request body: { uuid: 'aaaa-bbbb' }

Definition at line 1432 of file confighttp.cpp.

◆ diagnostic_report()

std::string confighttp::diagnostic_report ( )

One plain-text file that explains a host to someone who cannot see it: the machine and its GPUs, the last capture-path check, the warnings and errors in the log, the stream timeline, the runtime state, the settings without secrets, and the recent log. Made to attach to an issue.

Definition at line 2976 of file confighttp.cpp.

◆ disconnect()

void confighttp::disconnect ( resp_https_t response,
req_https_t request )

Disconnect a client.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 4065 of file confighttp.cpp.

◆ get_hestia_client_permissions()

void confighttp::get_hestia_client_permissions ( resp_https_t response,
req_https_t request )

Definition at line 2087 of file confighttp.cpp.

◆ get_hestia_clipboard()

void confighttp::get_hestia_clipboard ( resp_https_t response,
req_https_t request )

Definition at line 2114 of file confighttp.cpp.

◆ get_hestia_commands()

void confighttp::get_hestia_commands ( resp_https_t response,
req_https_t request )

Definition at line 2070 of file confighttp.cpp.

◆ get_hestia_diagnostic_report()

void confighttp::get_hestia_diagnostic_report ( resp_https_t response,
req_https_t request )

Definition at line 3179 of file confighttp.cpp.

◆ get_hestia_diagnostics()

void confighttp::get_hestia_diagnostics ( resp_https_t response,
req_https_t request )

Definition at line 2396 of file confighttp.cpp.

◆ get_hestia_display_status()

void confighttp::get_hestia_display_status ( resp_https_t response,
req_https_t request )

Definition at line 2018 of file confighttp.cpp.

◆ get_hestia_stream_info()

void confighttp::get_hestia_stream_info ( resp_https_t response,
req_https_t request )

What the stream about to start, or running, goes through: the capture, its size and rate, the encoder and its GPU, as the last capture-path check found them. A client shows it so its user knows the stream is served the way they expect. readiness is null before any check, and when the last check was not for this client's launch: with several clients, another's stream says nothing about the one asking.

Definition at line 2412 of file confighttp.cpp.

◆ getApps()

void confighttp::getApps ( resp_https_t response,
req_https_t request )

Get the list of available applications.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
HTTP request
GET /api/apps
Request body: null

Definition at line 1131 of file confighttp.cpp.

◆ getAppsPage()

void confighttp::getAppsPage ( resp_https_t response,
req_https_t request )

Get the apps page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 912 of file confighttp.cpp.

◆ getClients()

void confighttp::getClients ( resp_https_t response,
req_https_t request )

Get the list of paired clients.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
HTTP request
GET /api/clients/list
Request body: null

Definition at line 1488 of file confighttp.cpp.

◆ getClientsPage()

void confighttp::getClientsPage ( resp_https_t response,
req_https_t request )

Get the clients page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 927 of file confighttp.cpp.

◆ getClipboardStatus()

void confighttp::getClipboardStatus ( resp_https_t response,
req_https_t request )

Definition at line 3634 of file confighttp.cpp.

◆ getConfig()

void confighttp::getConfig ( resp_https_t response,
req_https_t request )

Get the current configuration: the computed values Hermes is running with, overlaid with what the configuration file sets explicitly.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
HTTP request
GET /api/config
Request body: null

Definition at line 1659 of file confighttp.cpp.

◆ getConfigPage()

void confighttp::getConfigPage ( resp_https_t response,
req_https_t request )

Get the configuration page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 942 of file confighttp.cpp.

◆ getCookieValue()

std::string confighttp::getCookieValue ( const std::string & cookieString,
const std::string & key )

Retrieve the value of a key from a cookie string.

Parameters
cookieStringThe cookie header string.
keyThe key to search.
Returns
The value if found, empty string otherwise.

Definition at line 682 of file confighttp.cpp.

◆ getDiagnosticReport()

void confighttp::getDiagnosticReport ( resp_https_t response,
req_https_t request )

Download a diagnostic report of this host.

HTTP request
GET /api/diagnostics/report
Request body: null

Definition at line 3171 of file confighttp.cpp.

◆ getEvdiInstallStatus()

void confighttp::getEvdiInstallStatus ( resp_https_t response,
req_https_t request )

Return the state of the EVDI installation started by this Web UI.

Definition at line 3425 of file confighttp.cpp.

◆ getEvdiStatus()

void confighttp::getEvdiStatus ( resp_https_t response,
req_https_t request )

Return the current EVDI runtime and DKMS status for the Audio/Video UI.

Definition at line 3442 of file confighttp.cpp.

◆ getFaviconImage()

void confighttp::getFaviconImage ( resp_https_t response,
req_https_t request )

Get the favicon image.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 1023 of file confighttp.cpp.

◆ getGameModeStatus()

void confighttp::getGameModeStatus ( resp_https_t response,
req_https_t request )

Everything the Game Mode console shows on one screen, in one call.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

A console driven with a thumbstick polls; three round trips per poll to assemble one screen is three times the work and three chances to render a half-updated view. What it needs is small and fits in one object: is Hermes up, does anybody need a PIN typed right now, how many devices are paired, and is anything streaming.

pending_pair is the field the console exists for. It is true only while a client's request is parked waiting for four digits, so the console can put the pairing screen in front of the user at the moment it is useful instead of asking them to go looking for it.

Definition at line 3545 of file confighttp.cpp.

◆ getHermesKmsStatus()

void confighttp::getHermesKmsStatus ( resp_https_t response,
req_https_t request )

Return the current Hermes-KMS driver and DKMS status for the Audio/Video UI.

Definition at line 3454 of file confighttp.cpp.

◆ getHermesLogoImage()

void confighttp::getHermesLogoImage ( resp_https_t response,
req_https_t request )

Get the Hermes logo image.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Todo

combine function with getFaviconImage and possibly getNodeModules

use mime_types map

Definition at line 1042 of file confighttp.cpp.

◆ getHestiaCapabilities()

void confighttp::getHestiaCapabilities ( resp_https_t response,
req_https_t request )

Return the static Hestia extension capabilities.

This endpoint is deliberately read-only and unauthenticated so clients can detect Hermes before an extension authentication flow is available. It does not expose host state or permit any host-control operation.

Definition at line 1678 of file confighttp.cpp.

◆ getIndexPage()

void confighttp::getIndexPage ( resp_https_t response,
req_https_t request )

Get the index page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 882 of file confighttp.cpp.

◆ getLibrary()

void confighttp::getLibrary ( resp_https_t response,
req_https_t request )

List the games installed in Steam and Lutris, to add as apps.

Reads native Steam (~/.local/share/Steam, ~/.steam/steam) and Flatpak Steam, and asks Lutris (native or Flatpak) for its installed games. Each game comes with the command that starts it; nothing is added here.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
HTTP request
GET /api/library
Request body: null

Definition at line 1165 of file confighttp.cpp.

◆ getLocale()

void confighttp::getLocale ( resp_https_t response,
req_https_t request )

Get the locale setting.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
HTTP request
GET /api/configLocale
Request body: null

Definition at line 3271 of file confighttp.cpp.

◆ getLoginPage()

void confighttp::getLoginPage ( resp_https_t response,
req_https_t request )

Get the login page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Todo
Combine this function with getWelcomePage if appropriate.

Definition at line 974 of file confighttp.cpp.

◆ getLogs()

void confighttp::getLogs ( resp_https_t response,
req_https_t request )

Get the logs from the log file.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

@api_examples{/api/logs| GET| null}

Definition at line 3749 of file confighttp.cpp.

◆ getMetrics()

void confighttp::getMetrics ( resp_https_t response,
req_https_t request )

Get the live runtime status: encoder, session, and pipeline counters. The same view the Hestia diagnostics return, behind the normal Web UI session auth so the dashboard can poll it.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
HTTP request
GET /api/metrics
Request body: null

Definition at line 1115 of file confighttp.cpp.

◆ getNodeModules()

void confighttp::getNodeModules ( resp_https_t response,
req_https_t request )

Get an asset from the node_modules directory.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 1069 of file confighttp.cpp.

◆ getOTP()

void confighttp::getOTP ( resp_https_t response,
req_https_t request )

Get a one-time password (OTP).

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

@api_examples{/api/otp| GET| null}

Definition at line 3839 of file confighttp.cpp.

◆ getPasswordPage()

void confighttp::getPasswordPage ( resp_https_t response,
req_https_t request )

Get the password page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 957 of file confighttp.cpp.

◆ getPinPage()

void confighttp::getPinPage ( resp_https_t response,
req_https_t request )

Get the PIN page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 897 of file confighttp.cpp.

◆ getSessions()

void confighttp::getSessions ( resp_https_t response,
req_https_t request )

List the isolated sessions this server is holding.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Not the same list as /api/clients/list, which is who may connect, nor the same as who is streaming: an isolated session outlives the stream that started it, so that a client can come back to the desktop it left. That is also how one can be left running with nobody attached, which is the case this list exists to make visible.

Definition at line 3479 of file confighttp.cpp.

◆ getTroubleshootingPage()

void confighttp::getTroubleshootingPage ( resp_https_t response,
req_https_t request )

Get the troubleshooting page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 1008 of file confighttp.cpp.

◆ getWelcomePage()

void confighttp::getWelcomePage ( resp_https_t response,
req_https_t request )

Get the welcome page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 992 of file confighttp.cpp.

◆ has_local_api_token()

bool confighttp::has_local_api_token ( req_https_t request)

Whether the request carries the local token in an Authorization header.

Definition at line 296 of file confighttp.cpp.

◆ hestia_capabilities_json()

nlohmann::json confighttp::hestia_capabilities_json ( )

The Hestia extension capabilities document.

Exposed so the served document can be checked against the capabilities.schema.json this repository ships. The two had drifted - the document advertised a virtual display backend the schema does not allow - and every shipped Hestia rejected the whole document for it.

Definition at line 1684 of file confighttp.cpp.

◆ hestia_display_status_json()

nlohmann::json confighttp::hestia_display_status_json ( )

Definition at line 1987 of file confighttp.cpp.

◆ hestia_has_exact_keys()

bool confighttp::hestia_has_exact_keys ( const nlohmann::json & object,
const std::set< std::string > & keys )

Definition at line 1786 of file confighttp.cpp.

◆ hestia_is_one_of()

bool confighttp::hestia_is_one_of ( const nlohmann::json & value,
const std::set< std::string > & values )

Definition at line 1804 of file confighttp.cpp.

◆ hestia_is_positive_integer()

bool confighttp::hestia_is_positive_integer ( const nlohmann::json & value)

Definition at line 1800 of file confighttp.cpp.

◆ hestia_preflight_json()

nlohmann::json confighttp::hestia_preflight_json ( )

Aggregate "is the host ready to stream?" checks.

Returns
{ready: bool, checks: [{id, status: ok|warn|fail, message}]}. ready is false only when at least one check fails (warnings, such as a software-encoding fallback, do not block).

Definition at line 2283 of file confighttp.cpp.

◆ hestia_runtime_status_json()

nlohmann::json confighttp::hestia_runtime_status_json ( )

Definition at line 2129 of file confighttp.cpp.

◆ installClipboard()

void confighttp::installClipboard ( resp_https_t response,
req_https_t request )

Definition at line 3646 of file confighttp.cpp.

◆ installEvdi()

void confighttp::installEvdi ( resp_https_t response,
req_https_t request )

Start EVDI installation only after the user explicitly confirms it in the UI. pkexec owns the privilege prompt, so Hermes never handles an admin password.

Definition at line 3346 of file confighttp.cpp.

◆ isChildPath()

bool confighttp::isChildPath ( fs::path const & base,
fs::path const & query )

Check if a path is a child of another path.

Parameters
baseThe base path.
queryThe path to check.
Returns
True if the path is a child of the base path, false otherwise.

Definition at line 1059 of file confighttp.cpp.

◆ launchApp()

void confighttp::launchApp ( resp_https_t response,
req_https_t request )

Launch an application.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 4003 of file confighttp.cpp.

◆ local_api_token_origin_allowed()

bool confighttp::local_api_token_origin_allowed ( std::string_view address)

Whether an address may authenticate with the Game Mode local token.

The token is capped at this machine and private/local networks even when normal Web UI logins are configured to accept WAN clients.

Definition at line 78 of file confighttp.cpp.

◆ local_api_token_path()

std::filesystem::path confighttp::local_api_token_path ( )

Definition at line 224 of file confighttp.cpp.

◆ login()

void confighttp::login ( resp_https_t response,
req_https_t request )

Login the user.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

The body for the POST request should be JSON serialized in the following format:

{
"username": "<username>",
"password": "<password>"
}

Definition at line 4099 of file confighttp.cpp.

◆ machine_snapshot()

void confighttp::machine_snapshot ( std::ostream & out)

What is attached to and running on the machine, as an unprivileged user can read it: USB devices, input devices, display outputs with their state, Hermes' own sessions, network links with their speed, sound cards, and the programs using the most memory and CPU time.

Definition at line 2807 of file confighttp.cpp.

◆ not_found()

void confighttp::not_found ( resp_https_t response,
req_https_t request )

Send a 404 Not Found response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 768 of file confighttp.cpp.

◆ overlay_config_file()

nlohmann::json & confighttp::overlay_config_file ( nlohmann::json & response,
const std::unordered_map< std::string, std::string > & file_values )

Overlay a parsed hermes.conf onto response, in place.

A key the response already carries is left alone. The Web UI posts the whole config response back and saveConfig() persists it, so a read-only field really does end up in the file - and a parsed value is always a string, which replaced a JSON array with "[]" and took the home page down with it.

Returns
response, for chaining.

Definition at line 1637 of file confighttp.cpp.

◆ prepare_hestia_session()

void confighttp::prepare_hestia_session ( resp_https_t response,
req_https_t request )

Store settings for a paired Hestia client's next stream launch.

The normal GameStream launch path consumes the short-lived settings and creates a virtual display only when the stream actually begins.

The response's settings says what that launch will apply for the requested app, so the client can show where a host setting overrides its own: for virtual_display and scale_factor, the requested and effective values and the source that decided (client, app_forced for an app that forces its setting, app or host_default when the client's value is not used, headless, or isolated_session for an app that always runs on a display of its own). It is null when no app has the requested id.

Definition at line 1892 of file confighttp.cpp.

◆ print_req()

void confighttp::print_req ( const req_https_t & request)

Log the request details.

Parameters
requestThe HTTP request object.

Definition at line 612 of file confighttp.cpp.

◆ quit()

void confighttp::quit ( resp_https_t response,
req_https_t request )

Quit Hermes.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 3964 of file confighttp.cpp.

◆ recover_hestia_display()

void confighttp::recover_hestia_display ( resp_https_t response,
req_https_t request )

Definition at line 2026 of file confighttp.cpp.

◆ remove_local_api_token()

void confighttp::remove_local_api_token ( )

Definition at line 285 of file confighttp.cpp.

◆ reorderApps()

void confighttp::reorderApps ( resp_https_t response,
req_https_t request )

Reorder applications.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
HTTP request
POST /api/apps/reorder
Request body: {"order": ["aaaa-bbbb", "cccc-dddd"]}

Definition at line 1318 of file confighttp.cpp.

◆ resetDisplayDevicePersistence()

void confighttp::resetDisplayDevicePersistence ( resp_https_t response,
req_https_t request )

Reset the display device persistence.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

@api_examples{/api/reset-display-device-persistence| POST| null}

Definition at line 3915 of file confighttp.cpp.

◆ restart()

void confighttp::restart ( resp_https_t response,
req_https_t request )

Restart Hermes.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

@api_examples{/api/restart| POST| null}

Definition at line 3934 of file confighttp.cpp.

◆ run_hestia_command()

void confighttp::run_hestia_command ( resp_https_t response,
req_https_t request )

Definition at line 3218 of file confighttp.cpp.

◆ running_in_container()

bool confighttp::running_in_container ( )

Whether Hermes is running inside a container.

Both runtimes leave a marker in the image and systemd sets $container for anything it starts inside one. This is not a security boundary: it only decides whether offering to install a kernel module can possibly help.

Definition at line 3334 of file confighttp.cpp.

◆ saveApp()

void confighttp::saveApp ( resp_https_t response,
req_https_t request )

Save an application. To save a new application the UUID must be empty. To update an existing application, you must provide the current UUID of the application.

Parameters
responseThe HTTP response object.
requestThe HTTP request object. The body for the post request should be JSON serialized in the following format:
{
"name": "Application Name",
"output": "Log Output Path",
"cmd": "Command to run the application",
"exclude-global-prep-cmd": false,
"elevated": false,
"auto-detach": true,
"wait-all": true,
"exit-timeout": 5,
"prep-cmd": [
{
"do": "Command to prepare",
"undo": "Command to undo preparation",
"elevated": false
}
],
"detached": [
"Detached command"
],
"image-path": "Full path to the application image. Must be a png file.",
"uuid": "aaaa-bbbb"
}
HTTP request
POST /api/apps
Request body: {"name":"Hello, World!","uuid": "aaaa-bbbb"}

Definition at line 1252 of file confighttp.cpp.

◆ saveConfig()

void confighttp::saveConfig ( resp_https_t response,
req_https_t request )

Save the configuration settings.

Parameters
responseThe HTTP response object.
requestThe HTTP request object. The body for the post request should be JSON serialized in the following format:
{
"key": "value"
}
Attention
It is recommended to ONLY save the config settings that differ from the default behavior.
HTTP request
POST /api/config
Request body: {"key":"value"}

Definition at line 3295 of file confighttp.cpp.

◆ savePassword()

void confighttp::savePassword ( resp_https_t response,
req_https_t request )

Update existing credentials.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

The body for the POST request should be JSON serialized in the following format:

{
"currentUsername": "Current Username",
"currentPassword": "Current Password",
"newUsername": "New Username",
"newPassword": "New Password",
"confirmNewPassword": "Confirm New Password"
}

@api_examples{/api/password| POST| {"currentUsername":"admin","currentPassword":"admin","newUsername":"admin","newPassword":"admin","confirmNewPassword":"admin"}}

Definition at line 3782 of file confighttp.cpp.

◆ savePin()

void confighttp::savePin ( resp_https_t response,
req_https_t request )

Send a PIN code to the host.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

The body for the POST request should be JSON serialized in the following format:

{
"pin": "<pin>",
"name": "Friendly Client Name"
}

@api_examples{/api/pin| POST| {"pin":"1234","name":"My PC"}}

Definition at line 3886 of file confighttp.cpp.

◆ send_diagnostic_report()

void confighttp::send_diagnostic_report ( resp_https_t response)

Definition at line 3158 of file confighttp.cpp.

◆ send_hestia_error()

void confighttp::send_hestia_error ( resp_https_t response,
SimpleWeb::StatusCode status,
const char * code,
const char * message )

Definition at line 1746 of file confighttp.cpp.

◆ send_redirect()

void confighttp::send_redirect ( resp_https_t response,
req_https_t request,
const char * path )

Send a redirect response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
pathThe path to redirect to.

Definition at line 665 of file confighttp.cpp.

◆ send_response()

void confighttp::send_response ( resp_https_t response,
const nlohmann::json & output_tree )

Send a response.

Parameters
responseThe HTTP response object.
output_treeThe JSON tree to send.

Definition at line 630 of file confighttp.cpp.

◆ send_unauthorized()

void confighttp::send_unauthorized ( resp_https_t response,
req_https_t request )

Send a 401 Unauthorized response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Definition at line 643 of file confighttp.cpp.

◆ send_web_page()

void confighttp::send_web_page ( resp_https_t response,
req_https_t request,
const std::string & page,
const SimpleWeb::CaseInsensitiveMultimap & extra_headers = {} )

Serve a page from the packaged web assets.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
pageThe file name under the web asset directory.
extra_headersResponse headers to add on top of the common set.

A missing asset used to be served as an empty 200: read_file() returns an empty string and only says so at debug level, so the browser rendered a blank page and the log held nothing to explain it. That is what a build or package with the wrong HERMES_ASSETS_DIR looks like from the outside, and it is indistinguishable from the UI itself being broken. Fail loudly with the path we actually looked at instead.

Definition at line 850 of file confighttp.cpp.

◆ set_hestia_clipboard()

void confighttp::set_hestia_clipboard ( resp_https_t response,
req_https_t request )

Definition at line 3186 of file confighttp.cpp.

◆ start()

void confighttp::start ( )

Start the HTTPS server.

Definition at line 4137 of file confighttp.cpp.

◆ stop_hestia_session()

void confighttp::stop_hestia_session ( resp_https_t response,
req_https_t request )

Definition at line 1974 of file confighttp.cpp.

◆ terminateSession()

void confighttp::terminateSession ( resp_https_t response,
req_https_t request )

End one isolated session.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

The body for the POST request should be JSON serialized in the following format:

{
"uuid": "<client uuid>"
}

The stream is stopped first where there is one, so the client is told the session ended rather than being left holding a stream into a desktop that is being torn down underneath it. Ending a session does not unpair the client and does not remove its account or its files: it may connect again and get the same session back.

Definition at line 3592 of file confighttp.cpp.

◆ token_matches()

bool confighttp::token_matches ( std::string_view presented,
std::string_view expected )

Compare in constant time, so a wrong token cannot be found byte by byte.

Definition at line 233 of file confighttp.cpp.

◆ unpair()

void confighttp::unpair ( resp_https_t response,
req_https_t request )

Unpair a client.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

The body for the POST request should be JSON serialized in the following format:

{
"uuid": "<uuid>"
}
HTTP request
POST /api/clients/unpair
Request body: {"uuid":"1234"}

Definition at line 1572 of file confighttp.cpp.

◆ unpairAll()

void confighttp::unpairAll ( resp_https_t response,
req_https_t request )

Unpair all clients.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
HTTP request
POST /api/clients/unpair-all
Request body: null

Definition at line 1600 of file confighttp.cpp.

◆ updateClient()

void confighttp::updateClient ( resp_https_t response,
req_https_t request )

Update client information.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

The body for the POST request should be JSON serialized in the following format:

{
"uuid": "<uuid>",
"name": "<Friendly Name>",
"display_mode": "1920x1080x59.94",
"do": [ { "cmd": "<command>", "elevated": false }, ... ],
"undo": [ { "cmd": "<command>", "elevated": false }, ... ],
"perm": <uint32_t>
}

Definition at line 1519 of file confighttp.cpp.

◆ uploadCover()

void confighttp::uploadCover ( resp_https_t response,
req_https_t request )

Upload a cover image.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

@api_examples{/api/covers/upload| POST| {"key":"igdb_1234","url":"https://images.igdb.com/igdb/image/upload/t_cover_big_2x/abc123.png"}}

Definition at line 3699 of file confighttp.cpp.

◆ validate_hestia_session_prepare()

bool confighttp::validate_hestia_session_prepare ( const nlohmann::json & request,
std::string & error )

Definition at line 1808 of file confighttp.cpp.

◆ validateContentType()

bool confighttp::validateContentType ( resp_https_t response,
req_https_t request,
const std::string_view & contentType )

Validate the request content type and send bad request when mismatch.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
contentTypeThe required content type.

Definition at line 808 of file confighttp.cpp.

◆ write_local_api_token()

void confighttp::write_local_api_token ( )

Definition at line 244 of file confighttp.cpp.

Variable Documentation

◆ localApiToken

std::string confighttp::localApiToken

A bearer token any local process of this user may present.

The Game Mode console has no keyboard to log in with, and a controller is the wrong instrument for a password. It does not need one: it runs as the same user as Hermes, on the same machine, and that user can already read Hermes' credentials file, write its config and ptrace the process. A token readable only by that uid therefore grants nothing that was not already available - it is a convenience over a boundary that does not exist, not a hole in one that does.

It lives in the runtime directory, which is tmpfs and mode 0700, so it is gone at reboot and unreadable by other users. It is not a substitute for logging in from a browser: a request carrying it still has to come from this machine or a private/local network, and it is never handed out over HTTP. WAN token authentication stays disabled even when password/cookie login is explicitly enabled from WAN.

Definition at line 221 of file confighttp.cpp.

◆ localApiTokenPath

std::filesystem::path confighttp::localApiTokenPath

Definition at line 222 of file confighttp.cpp.

◆ sessionCookie

std::string confighttp::sessionCookie

Definition at line 200 of file confighttp.cpp.