![]() |
Sunshine v2026.319.132152
Self-hosted game stream host for Moonlight.
|
Definitions for the Web UI Config HTTP server. More...
#include <algorithm>#include <filesystem>#include <format>#include <fstream>#include <string_view>#include <boost/algorithm/string.hpp>#include <boost/asio/ssl/context.hpp>#include <boost/filesystem.hpp>#include <nlohmann/json.hpp>#include <Simple-Web-Server/crypto.hpp>#include <Simple-Web-Server/server_https.hpp>#include "platform/windows/misc.h"#include <vector>#include <Windows.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 "utility.h"#include "uuid.h"Classes | |
| struct | confighttp::csrf_token_t |
Enumerations | |
| enum class | confighttp::op_e { ADD , REMOVE } |
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 fs::path &dir_path, const std::string &type_str) |
| Lists, filters, and sorts the entries of a directory for the browse API. | |
| 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. | |
| void | confighttp::closeApp (const resp_https_t &response, const req_https_t &request) |
| Close the currently running application. | |
| void | confighttp::deleteApp (const resp_https_t &response, const req_https_t &request) |
| Delete an application. | |
| 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_windows_drives () |
| Builds a JSON array of available Windows drive letters. | |
| void | confighttp::getApps (const resp_https_t &response, const req_https_t &request) |
| Get the list of available applications. | |
| void | confighttp::getAsset (const resp_https_t &response, const req_https_t &request) |
| Get an asset. | |
| void | confighttp::getClients (const resp_https_t &response, const req_https_t &request) |
| Get the list of paired clients. | |
| void | confighttp::getConfig (const resp_https_t &response, const req_https_t &request) |
| Get the configuration settings. | |
| void | confighttp::getCover (const resp_https_t &response, const req_https_t &request) |
| Get an application's image. | |
| void | confighttp::getCSRFToken (const resp_https_t &response, const req_https_t &request) |
| Get a CSRF token for the authenticated user. | |
| void | confighttp::getFaviconImage (const resp_https_t &response, const req_https_t &request) |
| Get the favicon image. | |
| 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::getLogs (const resp_https_t &response, const req_https_t &request) |
| Get the logs from the log file. | |
| 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::getSunshineLogoImage (const resp_https_t &response, const req_https_t &request) |
| Get the Sunshine logo image. | |
| void | confighttp::getViGEmBusStatus (const resp_https_t &response, const req_https_t &request) |
| Get ViGEmBus driver version and installation status. | |
| void | confighttp::installViGEmBus (const resp_https_t &response, const req_https_t &request) |
| Install ViGEmBus driver with elevated permissions. | |
| bool | confighttp::is_browsable_executable (const fs::directory_entry &entry, const fs::file_status &status) |
| Checks whether a directory entry qualifies as an executable file. | |
| bool | confighttp::isChildPath (fs::path const &base, fs::path const &query) |
| Check if a path is a child of another path. | |
| 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::resetDisplayDevicePersistence (const resp_https_t &response, const req_https_t &request) |
| Reset the display device persistence. | |
| void | confighttp::restart (const resp_https_t &response, const req_https_t &request) |
| Restart Sunshine. | |
| void | confighttp::saveApp (const resp_https_t &response, const req_https_t &request) |
Save an application. To save a new application, the index must be -1. To update an existing application, you must provide the current index of the application. | |
| void | confighttp::saveConfig (const resp_https_t &response, const req_https_t &request) |
| Save the configuration settings. | |
| void | confighttp::savePassword (const resp_https_t &response, const req_https_t &request) |
| Update existing credentials. | |
| void | confighttp::savePin (const resp_https_t &response, const req_https_t &request) |
| Send a pin code to the host. The pin is generated from the Moonlight client during the pairing process. | |
| 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 () |
| void | confighttp::unpair (const resp_https_t &response, const req_https_t &request) |
| Unpair a client. | |
| void | confighttp::unpairAll (const resp_https_t &response, const req_https_t &request) |
| Unpair all clients. | |
| void | confighttp::uploadCover (const resp_https_t &response, const req_https_t &request) |
| Upload a cover image. | |
| bool | confighttp::validate_csrf_token (const resp_https_t &response, const req_https_t &request, const std::string &client_id) |
| bool | confighttp::validate_stored_csrf_token (const resp_https_t &response, const req_https_t &request, const std::string_view client_id, const std::string_view provided_token) |
| Validate a stored CSRF token for a client against a provided token string. | |
Variables | |
| constexpr auto | confighttp::CSRF_TOKEN_LIFETIME = std::chrono::hours(1) |
| constexpr auto | confighttp::CSRF_TOKEN_SIZE = 32 |
| std::map< std::string, csrf_token_t, std::less<> > | confighttp::csrf_tokens |
| std::mutex | confighttp::csrf_tokens_mutex |
Definitions for the Web UI Config HTTP server.
|
strong |
| 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 fs::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". |
| 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.
| response | The HTTP response object. |
| request | The HTTP request object. |
| index | The application index/id. |
| 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.
| response | The HTTP response object. |
| request | The HTTP request object. |
| contentType | The expected content type |
| void confighttp::closeApp | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Close the currently running application.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::deleteApp | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Delete an application.
| response | The HTTP response object. |
| request | The HTTP request object. |
| 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_windows_drives | ( | ) |
Builds a JSON array of available Windows drive letters.
| void confighttp::getApps | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get the list of available applications.
| response | The HTTP response object. |
| request | The HTTP request object. |
| 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::getClients | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get the list of paired clients.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::getConfig | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get the configuration settings.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::getCover | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get an application's image.
| 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::getFaviconImage | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get the favicon image.
| response | The HTTP response object. |
| request | The HTTP request object. |
combine function with getSunshineLogoImage and possibly getNodeModules
use mime_types map
| 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::getLogs | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get the logs from the log file.
| 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::getSunshineLogoImage | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get the Sunshine logo image.
| response | The HTTP response object. |
| request | The HTTP request object. |
combine function with getFaviconImage and possibly getNodeModules
use mime_types map
| void confighttp::getViGEmBusStatus | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Get ViGEmBus driver version and installation status.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::installViGEmBus | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Install ViGEmBus driver with elevated permissions.
| response | The HTTP response object. |
| request | The HTTP request object. |
| bool confighttp::is_browsable_executable | ( | const fs::directory_entry & | entry, |
| const fs::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::isChildPath | ( | fs::path const & | base, |
| fs::path const & | query ) |
Check if a path is a child of another path.
| base | The base path. |
| query | The path to check. |
| 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::resetDisplayDevicePersistence | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Reset the display device persistence.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::restart | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Restart Sunshine.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::saveApp | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Save an application. To save a new application, the index must be -1. To update an existing application, you must provide the current index of the application.
| response | The HTTP response object. |
| request | The 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",
"index": -1,
"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."
}
|
| void confighttp::saveConfig | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Save the configuration settings.
| response | The HTTP response object. |
| request | The HTTP request object. The body for the POST request should be JSON serialized in the following format: {
"key": "value"
}
|
| void confighttp::savePassword | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Update existing credentials.
| response | The HTTP response object. |
| request | The 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"
}
|
| void confighttp::savePin | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Send a pin code to the host. The pin is generated from the Moonlight client during the pairing process.
| response | The HTTP response object. |
| request | The HTTP request object. The body for the post request should be JSON serialized in the following format: {
"pin": "<pin>",
"name": "Friendly Client Name"
}
|
| 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::unpair | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Unpair a client.
| response | The HTTP response object. |
| request | The HTTP request object. The body for the POST request should be JSON serialized in the following format: {
"uuid": "<uuid>"
}
|
| void confighttp::unpairAll | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Unpair all clients.
| response | The HTTP response object. |
| request | The HTTP request object. |
| void confighttp::uploadCover | ( | const resp_https_t & | response, |
| const req_https_t & | request ) |
Upload a cover image.
| response | The HTTP response object. |
| request | The HTTP request object. The body for the post request should be JSON serialized in the following format: {
"key": "igdb_<game_id>",
"url": "https://images.igdb.com/igdb/image/upload/t_cover_big_2x/<slug>.png"
}
|
| bool confighttp::validate_stored_csrf_token | ( | const resp_https_t & | response, |
| const req_https_t & | request, | ||
| const std::string_view | client_id, | ||
| const std::string_view | provided_token ) |
Validate a stored CSRF token for a client against a provided token string.
| response | The HTTP response object. |
| request | The HTTP request object. |
| client_id | A unique identifier for the client. |
| provided_token | The token string to validate. |