|
Sunshine latest
Self-hosted game stream host for Moonlight.
|
Declarations for the Web UI Config HTTP server. More...
#include <filesystem>#include <functional>#include <memory>#include <string>#include <string_view>#include <libvirtualhid/license.hpp>#include <nlohmann/json.hpp>#include <Simple-Web-Server/server_https.hpp>#include "thread_safe.h"Go to the source code of this file.
Macros | |
| #define | WEB_DIR SUNSHINE_ASSETS_DIR "/web/" |
| Macro for WEB DIR. | |
Functions | |
| bool | confighttp::authenticate (const resp_https_t &response, const req_https_t &request) |
| Authenticate the user. | |
| void | confighttp::bad_request (const resp_https_t &response, const req_https_t &request, const std::string &error_message) |
| Send a 400 Bad Request response. | |
| void | confighttp::browseDirectory (const resp_https_t &response, const req_https_t &request) |
| Browse the server filesystem. | |
| nlohmann::json | confighttp::build_browse_entries (const std::filesystem::path &dir_path, const std::string &type_str) |
| Lists, filters, and sorts the entries of a directory for the browse API. | |
| nlohmann::json | confighttp::build_driver_status (bool installed, const std::string &version, std::string_view minimum_version) |
| Build a standard driver status response. | |
| nlohmann::json | confighttp::build_virtualhid_license_status (const lvh::LicenseResult &result) |
| Convert a libvirtualhid license result into a Web UI response. | |
| void | confighttp::cancelPairing (const resp_https_t &response, const req_https_t &request) |
| Cancel a client pairing request that is waiting for PIN approval. The body for the delete request should be JSON serialized in the following format: | |
| bool | confighttp::check_app_index (const resp_https_t &response, const req_https_t &request, int index) |
| Validates the application index and sends an error response if invalid. | |
| bool | confighttp::check_content_type (const resp_https_t &response, const req_https_t &request, const std::string_view &contentType) |
| Validate the request content type and send a bad request when mismatched. | |
| std::string | confighttp::generate_csrf_token (const std::string &client_id) |
| Generate a new CSRF token for a client. | |
| std::string | confighttp::get_client_id (const req_https_t &request) |
| Get a unique client identifier for CSRF token management. | |
| nlohmann::json | confighttp::get_vigembus_driver_status () |
| Build ViGEmBus fallback driver version and installation status. | |
| nlohmann::json | confighttp::get_virtualhid_driver_status () |
| Build libvirtualhid driver version and installation status. | |
| nlohmann::json | confighttp::get_windows_drives () |
| Builds a JSON array of available Windows drive letters. | |
| void | confighttp::getAsset (const resp_https_t &response, const req_https_t &request) |
| Get an asset. | |
| void | confighttp::getCSRFToken (const resp_https_t &response, const req_https_t &request) |
| Get a CSRF token for the authenticated user. | |
| void | confighttp::getLocale (const resp_https_t &response, const req_https_t &request) |
| Get the locale setting. This endpoint does not require authentication. | |
| void | confighttp::getPage (const resp_https_t &response, const req_https_t &request, const char *html_file, const bool require_auth, const bool redirect_if_username) |
| Get an HTML page. | |
| void | confighttp::getPendingPairings (const resp_https_t &response, const req_https_t &request) |
| List client pairing requests that are waiting for PIN approval. | |
| void | confighttp::getVirtualInputLicense (const resp_https_t &response, const req_https_t &request) |
| Get the current libvirtualhid machine license status. | |
| void | confighttp::getVirtualInputStatus (const resp_https_t &response, const req_https_t &request) |
| Get virtual input driver version and installation status. | |
| bool | confighttp::is_browsable_executable (const std::filesystem::directory_entry &entry, const std::filesystem::file_status &status) |
| Checks whether a directory entry qualifies as an executable file. | |
| bool | confighttp::is_driver_version_development (std::string_view version) |
| Check whether a detected driver version identifies a development build. | |
| bool | confighttp::is_driver_version_supported (std::string_view version, std::string_view minimum_version) |
| Check whether a detected driver version satisfies a minimum version. | |
| void | confighttp::not_found (const resp_https_t &response, const req_https_t &request, const std::string &error_message) |
| Send a 404 Not Found response. | |
| void | confighttp::print_req (const req_https_t &request) |
| Log the request details. | |
| void | confighttp::resetPortalToken (const resp_https_t &response, const req_https_t &request) |
| Authenticate a Web UI request and delete the saved XDG Portal restore token. | |
| void | confighttp::savePin (const resp_https_t &response, const req_https_t &request) |
| Submit a PIN and return whether the selected client completes pairing. | |
| void | confighttp::send_redirect (const resp_https_t &response, const req_https_t &request, const char *path) |
| Send a redirect response. | |
| void | confighttp::send_response (const resp_https_t &response, const nlohmann::json &output_tree) |
| Send a response. | |
| void | confighttp::send_unauthorized (const resp_https_t &response, const req_https_t &request) |
| Send a 401 Unauthorized response. | |
| void | confighttp::start () |
| Start the HTTPS configuration server. | |
| void | confighttp::updateVirtualInputLicense (const resp_https_t &response, const req_https_t &request) |
| Activate, validate, or deactivate the libvirtualhid machine license. | |
| bool | confighttp::validate_csrf_token (const resp_https_t &response, const req_https_t &request, const std::string &client_id) |
| Validate CSRF token. | |
Variables | |
| const std::map< std::string, std::string > | mime_types |
| File-extension to MIME-type mapping used when serving the Web UI. | |
| constexpr auto | confighttp::PORT_HTTPS = 1 |
| GameStream port offset for port https. | |
Declarations for the Web UI Config HTTP server.
| bool confighttp::authenticate | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Authenticate the user.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::bad_request | ( | const resp_https_t & | response, |
| const req_https_t & | request, | ||
| const std::string & | error_message ) |
Send a 400 Bad Request response.
| response | The HTTP response object. |
| request | The HTTP request object. |
| error_message | The error message to include in the response. |
| void confighttp::browseDirectory | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Browse the server filesystem.
| response | The HTTP response object. |
| request | The HTTP request object. |
| nlohmann::json confighttp::build_browse_entries | ( | const std::filesystem::path & | dir_path, |
| const std::string & | type_str ) |
Lists, filters, and sorts the entries of a directory for the browse API.
| dir_path | The directory to list. |
| type_str | Filter type: "directory", "executable", "file", or "any". |
| nlohmann::json confighttp::build_driver_status | ( | bool | installed, |
| const std::string & | version, | ||
| std::string_view | minimum_version ) |
Build a standard driver status response.
| installed | Whether the driver was detected. |
| version | Detected driver version. |
| minimum_version | Minimum supported driver version, or empty for any version. |
| nlohmann::json confighttp::build_virtualhid_license_status | ( | const lvh::LicenseResult & | result | ) |
Convert a libvirtualhid license result into a Web UI response.
| result | License operation result. |
| void confighttp::cancelPairing | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Cancel a client pairing request that is waiting for PIN approval. The body for the delete request should be JSON serialized in the following format:
Cancel an explicitly selected pairing request.
| response | HTTP response object to populate. |
| request | HTTP request data from the client. |
| bool confighttp::check_app_index | ( | const resp_https_t & | response, |
| const req_https_t & | request, | ||
| int | index ) |
Validates the application index and sends an error response if invalid.
Check app index.
| response | HTTP response object to populate. |
| request | HTTP request data from the client. |
| index | Zero-based index of the item being addressed. |
| bool confighttp::check_content_type | ( | const resp_https_t & | response, |
| const req_https_t & | request, | ||
| const std::string_view & | contentType ) |
Validate the request content type and send a bad request when mismatched.
Check content type.
| response | HTTP response object to populate. |
| request | HTTP request data from the client. |
| contentType | Expected HTTP content type. |
| std::string confighttp::generate_csrf_token | ( | const std::string & | client_id | ) |
Generate a new CSRF token for a client.
| client_id | A unique identifier for the client (e.g., session ID or username). |
| std::string confighttp::get_client_id | ( | const req_https_t & | request | ) |
Get a unique client identifier for CSRF token management.
| request | The HTTP request object. |
| nlohmann::json confighttp::get_vigembus_driver_status | ( | ) |
Build ViGEmBus fallback driver version and installation status.
| nlohmann::json confighttp::get_virtualhid_driver_status | ( | ) |
Build libvirtualhid driver version and installation status.
| nlohmann::json confighttp::get_windows_drives | ( | ) |
Builds a JSON array of available Windows drive letters.
| void confighttp::getAsset | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get an asset.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::getCSRFToken | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get a CSRF token for the authenticated user.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::getLocale | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get the locale setting. This endpoint does not require authentication.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::getPage | ( | const resp_https_t & | response, |
| const req_https_t & | request, | ||
| const char * | html_file, | ||
| const bool | require_auth, | ||
| const bool | redirect_if_username ) |
Get an HTML page.
| response | The HTTP response object. |
| request | The HTTP request object. |
| html_file | The HTML file to serve (relative to WEB_DIR). |
| require_auth | Whether to require authentication (default: true). |
| redirect_if_username | If true, redirect to "/" when the username is set (for welcome page). |
| void confighttp::getPendingPairings | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
List client pairing requests that are waiting for PIN approval.
List authenticated pairing requests awaiting operator approval.
| response | HTTP response object to populate. |
| request | HTTP request data from the client. |
| void confighttp::getVirtualInputLicense | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get the current libvirtualhid machine license status.
| response | HTTP response object. |
| request | Authenticated HTTP request. |
| void confighttp::getVirtualInputStatus | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get virtual input driver version and installation status.
| response | The HTTP response object. |
| request | The HTTP request object. |
| bool confighttp::is_browsable_executable | ( | const std::filesystem::directory_entry & | entry, |
| const std::filesystem::file_status & | status ) |
Checks whether a directory entry qualifies as an executable file.
| entry | The directory entry to check. |
| status | The cached file status for the entry. |
| bool confighttp::is_driver_version_development | ( | std::string_view | version | ) |
Check whether a detected driver version identifies a development build.
Numeric versions beginning with 0.0 and containing at least three components are development builds.
| version | Detected driver version. |
| bool confighttp::is_driver_version_supported | ( | std::string_view | version, |
| std::string_view | minimum_version ) |
Check whether a detected driver version satisfies a minimum version.
Empty minimum versions accept any detected version. Non-empty minimum versions require a fully numeric dotted version string. Development versions beginning with 0.0 are always accepted.
| version | Detected driver version. |
| minimum_version | Minimum supported driver version, or empty for any version. |
| void confighttp::not_found | ( | const resp_https_t & | response, |
| const req_https_t & | request, | ||
| const std::string & | error_message ) |
Send a 404 Not Found response.
| response | The HTTP response object. |
| request | The HTTP request object. |
| error_message | The error message to include in the response. |
| void confighttp::print_req | ( | const req_https_t & | request | ) |
Log the request details.
| request | The HTTP request object. |
| void confighttp::resetPortalToken | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Authenticate a Web UI request and delete the saved XDG Portal restore token.
On platforms without XDG Portal capture, this operation succeeds without changing the filesystem.
| response | HTTP response used for authentication, CSRF, and status output. |
| request | HTTP request carrying the client identity and CSRF token. |
| void confighttp::savePin | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Submit a PIN and return whether the selected client completes pairing.
Apply a PIN to an explicitly selected pairing request.
The request remains open for up to the configured ping_timeout while Moonlight completes the cryptographic handshake. A wrong PIN, protocol failure, cancellation, or timeout returns {"status":false}. The body for the post request should be JSON serialized in the following format:
| response | HTTP response object to populate. |
| request | HTTP request data from the client. |
| void confighttp::send_redirect | ( | const resp_https_t & | response, |
| const req_https_t & | request, | ||
| const char * | path ) |
Send a redirect response.
| response | The HTTP response object. |
| request | The HTTP request object. |
| path | The path to redirect to. |
| void confighttp::send_response | ( | const resp_https_t & | response, |
| const nlohmann::json & | output_tree ) |
Send a response.
| response | The HTTP response object. |
| output_tree | The JSON tree to send. |
| void confighttp::send_unauthorized | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Send a 401 Unauthorized response.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::updateVirtualInputLicense | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Activate, validate, or deactivate the libvirtualhid machine license.
Submitted license keys are used only for the synchronous broker call. They are never logged or saved in Sunshine's configuration, and extracted mutable copies are overwritten before the handler returns.
| response | HTTP response object. |
| request | Authenticated HTTP request with a JSON action. |
| bool confighttp::validate_csrf_token | ( | const resp_https_t & | response, |
| const req_https_t & | request, | ||
| const std::string & | client_id ) |
Validate CSRF token.
| response | HTTP response object to populate. |
| request | HTTP request data from the client. |
| client_id | Client identifier used to look up the CSRF token. |
| const std::map<std::string, std::string> mime_types |
File-extension to MIME-type mapping used when serving the Web UI.