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>;
75 void getPage(
const resp_https_t &response,
const req_https_t &request,
const char *html_file,
bool require_auth =
true,
bool redirect_if_username =
false);
137 nlohmann::json
build_driver_status(
bool installed,
const std::string &version, std::string_view minimum_version);
170 using virtual_input_license_status_provider_t = std::function<lvh::LicenseResult()>;
171 using portal_token_path_provider_t = std::function<std::filesystem::path()>;
178 void set_virtual_input_license_status_provider_for_testing(virtual_input_license_status_provider_t status_provider);
183 void reset_virtual_input_license_status_provider_for_testing();
190 void set_portal_token_path_provider_for_testing(portal_token_path_provider_t path_provider);
195 void reset_portal_token_path_provider_for_testing();
202 void clear_sensitive_string_for_testing(std::string &value);
237 {
"gif",
"image/gif"},
238 {
"htm",
"text/html"},
239 {
"html",
"text/html"},
240 {
"ico",
"image/x-icon"},
241 {
"jpeg",
"image/jpeg"},
242 {
"jpg",
"image/jpeg"},
243 {
"js",
"application/javascript"},
244 {
"json",
"application/json"},
245 {
"png",
"image/png"},
246 {
"svg",
"image/svg+xml"},
248 {
"txt",
"text/plain"},
249 {
"woff2",
"font/woff2"},
std::string generate_csrf_token(const std::string &client_id)
Generate a new CSRF token for a client.
Definition confighttp.cpp:735
void not_found(const resp_https_t &response, const req_https_t &request, const std::string &error_message)
Send a 404 Not Found response.
Definition confighttp.cpp:644
void getCSRFToken(const resp_https_t &response, const req_https_t &request)
Get a CSRF token for the authenticated user.
Definition confighttp.cpp:1003
nlohmann::json get_vigembus_driver_status()
Build ViGEmBus fallback driver version and installation status.
Definition confighttp.cpp:2001
void getVirtualInputLicense(const resp_https_t &response, const req_https_t &request)
Get the current libvirtualhid machine license status.
Definition confighttp.cpp:2053
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:1746
bool 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.
Definition confighttp.cpp:858
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:2129
void bad_request(const resp_https_t &response, const req_https_t &request, const std::string &error_message)
Send a 400 Bad Request response.
Definition confighttp.cpp:665
void send_unauthorized(const resp_https_t &response, const req_https_t &request)
Send a 401 Unauthorized response.
Definition confighttp.cpp:551
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:2171
void print_req(const req_https_t &request)
Log the request details.
Definition confighttp.cpp:516
std::shared_ptr< SimpleWeb::ServerBase< SimpleWeb::HTTPS >::Response > resp_https_t
Shared HTTPS response object passed to configuration handlers.
Definition confighttp.cpp:74
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:796
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:1904
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:1444
std::string get_client_id(const req_https_t &request)
Get a unique client identifier for CSRF token management.
Definition confighttp.cpp:715
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:295
void send_response(const resp_https_t &response, const nlohmann::json &output_tree)
Send a response.
Definition confighttp.cpp:538
nlohmann::json build_virtualhid_license_status(const lvh::LicenseResult &result)
Convert a libvirtualhid license result into a Web UI response.
Definition confighttp.cpp:335
void getVirtualInputStatus(const resp_https_t &response, const req_https_t &request)
Get virtual input driver version and installation status.
Definition confighttp.cpp:2032
void 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.
Definition confighttp.cpp:882
std::shared_ptr< SimpleWeb::ServerBase< SimpleWeb::HTTPS >::Request > req_https_t
Shared HTTPS request object received by configuration handlers.
Definition confighttp.cpp:78
void getAsset(const resp_https_t &response, const req_https_t &request)
Get an asset.
Definition confighttp.cpp:958
nlohmann::json get_virtualhid_driver_status()
Build libvirtualhid driver version and installation status.
Definition confighttp.cpp:1960
nlohmann::json get_windows_drives()
Builds a JSON array of available Windows drive letters.
Definition confighttp.cpp:2147
void updateVirtualInputLicense(const resp_https_t &response, const req_https_t &request)
Activate, validate, or deactivate the libvirtualhid machine license.
Definition confighttp.cpp:2069
bool is_driver_version_development(std::string_view version)
Check whether a detected driver version identifies a development build.
Definition confighttp.cpp:267
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:684
bool authenticate(const resp_https_t &response, const req_https_t &request)
Authenticate the user.
Definition confighttp.cpp:595
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:1827
SimpleWeb::Server< SimpleWeb::HTTPS > https_server_t
HTTPS server type used for Sunshine's configuration UI.
Definition confighttp.cpp:65
void start()
Start the HTTPS configuration server.
Definition confighttp.cpp:2313
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:272
void browseDirectory(const resp_https_t &response, const req_https_t &request)
Browse the server filesystem.
Definition confighttp.cpp:2234
void send_redirect(const resp_https_t &response, const req_https_t &request, const char *path)
Send a redirect response.
Definition confighttp.cpp:578
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:1776
const std::map< std::string, std::string > mime_types
File-extension to MIME-type mapping used when serving the Web UI.
Definition confighttp.h:235
constexpr auto PORT_HTTPS
GameStream port offset for port https.
Definition confighttp.h:29
Declarations for thread-safe data structures.