15#include <libvirtualhid/license.hpp>
16#include <nlohmann/json.hpp>
17#include <Simple-Web-Server/server_https.hpp>
26#define WEB_DIR SUNSHINE_ASSETS_DIR "/web/"
33 using resp_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTPS>::Response>;
34 using req_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTPS>::Request>;
151 nlohmann::json
build_driver_status(
bool installed,
const std::string &version, std::string_view minimum_version);
205 void set_permission_statuses_for_testing(nlohmann::json permissions);
210 void reset_permission_statuses_for_testing();
212 using virtual_input_license_status_provider_t = std::function<lvh::LicenseResult()>;
213 using portal_token_path_provider_t = std::function<std::filesystem::path()>;
220 void set_virtual_input_license_status_provider_for_testing(virtual_input_license_status_provider_t status_provider);
225 void reset_virtual_input_license_status_provider_for_testing();
232 void set_portal_token_path_provider_for_testing(portal_token_path_provider_t path_provider);
237 void reset_portal_token_path_provider_for_testing();
244 void clear_sensitive_string_for_testing(std::string &value);
277const std::map<std::string, std::string, std::less<>>
mime_types = {
279 {
"gif",
"image/gif"},
280 {
"htm",
"text/html"},
281 {
"html",
"text/html"},
282 {
"ico",
"image/x-icon"},
283 {
"jpeg",
"image/jpeg"},
284 {
"jpg",
"image/jpeg"},
285 {
"js",
"application/javascript"},
286 {
"json",
"application/json"},
287 {
"png",
"image/png"},
288 {
"svg",
"image/svg+xml"},
290 {
"txt",
"text/plain"},
291 {
"woff2",
"font/woff2"},
std::string generate_csrf_token(const std::string &client_id)
Generate a new CSRF token for a client.
Definition confighttp.cpp:789
void requestPermission(const resp_https_t &response, const req_https_t &request)
Start a native permission request or open its settings pane.
Definition confighttp.cpp:2061
void getCSRFToken(const resp_https_t &response, const req_https_t &request)
Get a CSRF token for the authenticated user.
Definition confighttp.cpp:1063
bool check_app_index(const resp_https_t &response, int index)
Validates the application index and sends an error response if invalid.
Definition confighttp.cpp:912
nlohmann::json get_vigembus_driver_status()
Build ViGEmBus fallback driver version and installation status.
Definition confighttp.cpp:2143
void getPage(const resp_https_t &response, const req_https_t &request, const bool require_auth, const bool redirect_if_username)
Serve the Web UI single-page application entry document.
Definition confighttp.cpp:928
void getVirtualInputLicense(const resp_https_t &response, const req_https_t &request)
Get the current libvirtualhid machine license status.
Definition confighttp.cpp:2195
void getPendingPairings(const resp_https_t &response, const req_https_t &request)
List client pairing requests that are waiting for PIN approval.
Definition confighttp.cpp:1806
bool is_browsable_executable(const fs::directory_entry &entry, const fs::file_status &status)
Checks whether a directory entry qualifies as an executable file.
Definition confighttp.cpp:2271
void send_unauthorized(const resp_https_t &response, const req_https_t &request)
Send a 401 Unauthorized response.
Definition confighttp.cpp:605
nlohmann::json 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.
Definition confighttp.cpp:2313
void print_req(const req_https_t &request)
Log the request details.
Definition confighttp.cpp:570
std::shared_ptr< SimpleWeb::ServerBase< SimpleWeb::HTTPS >::Response > resp_https_t
Shared HTTPS response object passed to configuration handlers.
Definition confighttp.cpp:84
bool validate_csrf_token(const resp_https_t &response, const req_https_t &request, const std::string &client_id)
Validate CSRF token.
Definition confighttp.cpp:850
void resetPortalToken(const resp_https_t &response, const req_https_t &request)
Authenticate a Web UI request and delete the saved XDG Portal restore token.
Definition confighttp.cpp:1964
void getLocale(const resp_https_t &response, const req_https_t &request)
Get the locale setting. This endpoint does not require authentication.
Definition confighttp.cpp:1504
std::string get_client_id(const req_https_t &request)
Get a unique client identifier for CSRF token management.
Definition confighttp.cpp:769
nlohmann::json build_driver_status(bool installed, const std::string &version, std::string_view minimum_version)
Build a standard driver status response.
Definition confighttp.cpp:313
void send_response(const resp_https_t &response, const nlohmann::json &output_tree)
Send a response.
Definition confighttp.cpp:592
nlohmann::json build_virtualhid_license_status(const lvh::LicenseResult &result)
Convert a libvirtualhid license result into a Web UI response.
Definition confighttp.cpp:353
void not_found(const resp_https_t &response, const std::string &error_message)
Send a 404 Not Found response.
Definition confighttp.cpp:698
void getVirtualInputStatus(const resp_https_t &response, const req_https_t &request)
Get virtual input driver version and installation status.
Definition confighttp.cpp:2174
std::shared_ptr< SimpleWeb::ServerBase< SimpleWeb::HTTPS >::Request > req_https_t
Shared HTTPS request object received by configuration handlers.
Definition confighttp.cpp:88
void getAsset(const resp_https_t &response, const req_https_t &request)
Get an asset.
Definition confighttp.cpp:1018
nlohmann::json get_virtualhid_driver_status()
Build Virtual HID Broker version and installation status.
Definition confighttp.cpp:2096
nlohmann::json get_windows_drives()
Builds a JSON array of available Windows drive letters.
Definition confighttp.cpp:2289
void updateVirtualInputLicense(const resp_https_t &response, const req_https_t &request)
Activate, validate, or deactivate the libvirtualhid machine license.
Definition confighttp.cpp:2211
bool is_driver_version_development(std::string_view version)
Check whether a detected driver version identifies a development build.
Definition confighttp.cpp:285
bool 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.
Definition confighttp.cpp:738
void bad_request(const resp_https_t &response, const std::string &error_message)
Send a 400 Bad Request response.
Definition confighttp.cpp:719
bool authenticate(const resp_https_t &response, const req_https_t &request)
Authenticate the user.
Definition confighttp.cpp:649
void savePin(const resp_https_t &response, const req_https_t &request)
Submit a PIN and return whether the selected client completes pairing.
Definition confighttp.cpp:1887
void getFallbackPage(const resp_https_t &response, const req_https_t &request)
Serve the SPA entry for browser routes and preserve 404 responses for server-owned route prefixes.
Definition confighttp.cpp:952
SimpleWeb::Server< SimpleWeb::HTTPS > https_server_t
HTTPS server type used for Sunshine's configuration UI.
Definition confighttp.cpp:75
void start()
Start the HTTPS configuration server.
Definition confighttp.cpp:2455
bool is_driver_version_supported(std::string_view version, std::string_view minimum_version)
Check whether a detected driver version satisfies a minimum version.
Definition confighttp.cpp:290
void getPermissions(const resp_https_t &response, const req_https_t &request)
Return permission status for the current host platform.
Definition confighttp.cpp:2020
void browseDirectory(const resp_https_t &response, const req_https_t &request)
Browse the server filesystem.
Definition confighttp.cpp:2376
void send_redirect(const resp_https_t &response, const req_https_t &request, const char *path)
Send a redirect response.
Definition confighttp.cpp:632
void 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 sho...
Definition confighttp.cpp:1836
const std::map< std::string, std::string, std::less<> > mime_types
File-extension to MIME-type mapping used when serving the Web UI.
Definition confighttp.h:277
constexpr auto PORT_HTTPS
GameStream port offset for port https.
Definition confighttp.h:29
Declarations for thread-safe data structures.