Sunshine latest
Self-hosted game stream host for Moonlight.
confighttp.cpp File Reference

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

#include <filesystem>
#include <set>
#include <boost/algorithm/string.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/asio/ssl/context_base.hpp>
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <Simple-Web-Server/crypto.hpp>
#include <Simple-Web-Server/server_https.hpp>
#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 "utility.h"
#include "uuid.h"
#include "version.h"
Include dependency graph for confighttp.cpp:

Typedefs

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

Enumerations

enum class  confighttp::op_e { ADD , REMOVE }
 

Functions

bool confighttp::authenticate (resp_https_t response, req_https_t request)
 Authenticate the user.
 
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.
 
void confighttp::closeApp (resp_https_t response, req_https_t request)
 Close the currently running application.
 
void confighttp::deleteApp (resp_https_t response, req_https_t request)
 Delete an application.
 
void confighttp::getApps (resp_https_t response, req_https_t request)
 Get the list of available applications.
 
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::getConfig (resp_https_t response, req_https_t request)
 Get the configuration settings.
 
void confighttp::getConfigPage (resp_https_t response, req_https_t request)
 Get the configuration page.
 
void confighttp::getFaviconImage (resp_https_t response, req_https_t request)
 Get the favicon image.
 
void confighttp::getIndexPage (resp_https_t response, req_https_t request)
 Get the index page.
 
void confighttp::getLocale (resp_https_t response, req_https_t request)
 Get the locale setting. This endpoint does not require authentication.
 
void confighttp::getLogs (resp_https_t response, req_https_t request)
 Get the logs from the log file.
 
void confighttp::getNodeModules (resp_https_t response, req_https_t request)
 Get an asset from the node_modules directory.
 
void confighttp::getPasswordPage (resp_https_t response, req_https_t request)
 Get the password page.
 
void confighttp::getPinPage (resp_https_t response, req_https_t request)
 Get the PIN page.
 
void confighttp::getSunshineLogoImage (resp_https_t response, req_https_t request)
 Get the Sunshine logo image.
 
void confighttp::getTroubleshootingPage (resp_https_t response, req_https_t request)
 Get the troubleshooting page.
 
void confighttp::getWelcomePage (resp_https_t response, req_https_t request)
 Get the welcome page.
 
bool confighttp::isChildPath (fs::path const &base, fs::path const &query)
 Check if a path is a child of another path.
 
void confighttp::listClients (resp_https_t response, req_https_t request)
 Get the list of paired clients.
 
void confighttp::not_found (resp_https_t response, req_https_t request)
 Send a 404 Not Found response.
 
void confighttp::print_req (const req_https_t &request)
 Log the request details.
 
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 Sunshine.
 
void confighttp::saveApp (resp_https_t response, 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 (resp_https_t response, req_https_t request)
 Save the configuration settings.
 
void confighttp::savePassword (resp_https_t response, req_https_t request)
 Update existing credentials.
 
void confighttp::savePin (resp_https_t response, 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 (resp_https_t response, req_https_t request, const char *path)
 Send a redirect response.
 
void confighttp::send_response (resp_https_t response, const pt::ptree &output_tree)
 Send a response.
 
void confighttp::send_unauthorized (resp_https_t response, req_https_t request)
 Send a 401 Unauthorized response.
 
void confighttp::start ()
 
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.
 
void confighttp::uploadCover (resp_https_t response, req_https_t request)
 Upload a cover image.
 

Detailed Description

Definitions for the Web UI Config HTTP server.

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

Enumeration Type Documentation

◆ op_e

enum class confighttp::op_e
strong
Enumerator
ADD 

Add client.

REMOVE 

Remove client.

Function Documentation

◆ authenticate()

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

Authenticate the user.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Returns
True if the user is authenticated, false otherwise.

◆ 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 to include in the response.

◆ 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.

◆ deleteApp()

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

Delete an application.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ 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.

◆ 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.

◆ 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.

◆ getConfig()

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

Get the configuration settings.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ 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.

◆ 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.
Todo

combine function with getSunshineLogoImage and possibly getNodeModules

use mime_types map

◆ 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.
Todo
combine these functions into a single function that accepts the page, i.e "index", "pin", "apps"

◆ getLocale()

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

Get the locale setting. This endpoint does not require authentication.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ getSunshineLogoImage()

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

Get the Sunshine logo image.

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

combine function with getFaviconImage and possibly getNodeModules

use mime_types map

◆ 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.

◆ 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.

◆ 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.

◆ listClients()

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

Get the list of paired clients.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ 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.

◆ print_req()

void confighttp::print_req ( const req_https_t & request)

Log the request details.

Parameters
requestThe HTTP request object.

◆ 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.

◆ restart()

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

Restart Sunshine.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ saveApp()

void confighttp::saveApp ( resp_https_t response,
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.

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",
"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."
}

◆ 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.

◆ 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"
}

◆ savePin()

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

Send a pin code to the host. The pin is generated from the Moonlight client during the pairing process.

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"
}

◆ 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.

◆ send_response()

void confighttp::send_response ( resp_https_t response,
const pt::ptree & output_tree )

Send a response.

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

◆ 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.

◆ 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>"
}

◆ unpairAll()

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

Unpair all clients.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ 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. 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"
}