mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-08-31 19:08:29 +00:00
Merge pull request #1450 from PepperDash/feature/mobile-control-https-wss-support
feat(mobile-control): support https/wss for direct server URLs when Secure is true
This commit is contained in:
commit
aff4c1e897
2 changed files with 23 additions and 18 deletions
|
|
@ -554,15 +554,8 @@ namespace PepperDash.Essentials.Touchpanel
|
||||||
return false;
|
return false;
|
||||||
}) ? csIpAddress.ToString() : processorIp;
|
}) ? csIpAddress.ToString() : processorIp;
|
||||||
|
|
||||||
var match = Regex.Match(url, @"^http://([^:/]+):\d+/mc/app\?token=.+$");
|
// replace the host but preserve whatever scheme (http/https) is already present in the URL
|
||||||
if (match.Success)
|
var updatedUrl = Regex.Replace(url, @"^(https?)://[^:/]+", $"$1://{ip}");
|
||||||
{
|
|
||||||
string ipa = match.Groups[1].Value;
|
|
||||||
// ip will be "192.168.1.100"
|
|
||||||
}
|
|
||||||
|
|
||||||
// replace ipa with ip but leave the rest of the string intact
|
|
||||||
var updatedUrl = Regex.Replace(url, @"^http://[^:/]+", $"http://{ip}");
|
|
||||||
|
|
||||||
this.LogVerbose("Updated URL: {updatedUrl}", updatedUrl);
|
this.LogVerbose("Updated URL: {updatedUrl}", updatedUrl);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,16 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Port { get; private set; }
|
public int Port { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the HTTP scheme to use for generated URLs, based on whether the direct server is configured as secure
|
||||||
|
/// </summary>
|
||||||
|
private string HttpScheme => _parent.Config.DirectServer.Secure ? "https" : "http";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the WebSocket scheme to use for generated URLs, based on whether the direct server is configured as secure
|
||||||
|
/// </summary>
|
||||||
|
private string WsScheme => _parent.Config.DirectServer.Secure ? "wss" : "ws";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user app URL prefix
|
/// Gets the user app URL prefix
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -134,7 +144,8 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return string.Format("http://{0}:{1}{2}?token=",
|
return string.Format("{0}://{1}:{2}{3}?token=",
|
||||||
|
HttpScheme,
|
||||||
CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0),
|
CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0),
|
||||||
Port,
|
Port,
|
||||||
_userAppBaseHref);
|
_userAppBaseHref);
|
||||||
|
|
@ -273,7 +284,7 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
_server = new HttpServer(Port, false);
|
_server = new HttpServer(Port, _parent.Config.DirectServer.Secure);
|
||||||
|
|
||||||
_server.OnGet += Server_OnGet;
|
_server.OnGet += Server_OnGet;
|
||||||
|
|
||||||
|
|
@ -291,7 +302,7 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||||
{
|
{
|
||||||
ClientCertificateRequired = false,
|
ClientCertificateRequired = false,
|
||||||
CheckCertificateRevocation = false,
|
CheckCertificateRevocation = false,
|
||||||
EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11
|
EnabledSslProtocols = SslProtocols.Tls12
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -403,11 +414,11 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||||
ip = csIpAddress.ToString();
|
ip = csIpAddress.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
var appUrl = $"http://{ip}:{_parent.Config.DirectServer.Port}/mc/app?token={touchpanel.Key}";
|
var appUrl = $"{HttpScheme}://{ip}:{Port}/mc/app?token={touchpanel.Key}";
|
||||||
|
|
||||||
this.LogVerbose("Sending URL {appUrl} to touchpanel {touchpanelKey}", appUrl, touchpanel.Touchpanel.Key);
|
this.LogVerbose("Sending URL {appUrl} to touchpanel {touchpanelKey}", appUrl, touchpanel.Touchpanel.Key);
|
||||||
|
|
||||||
touchpanel.Touchpanel.SetAppUrl($"http://{ip}:{_parent.Config.DirectServer.Port}/mc/app?token={touchpanel.Key}");
|
touchpanel.Touchpanel.SetAppUrl(appUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -487,7 +498,7 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||||
{
|
{
|
||||||
var config = new MobileControlApplicationConfig
|
var config = new MobileControlApplicationConfig
|
||||||
{
|
{
|
||||||
ApiPath = string.Format("http://{0}:{1}/mc/api", processorIp, _parent.Config.DirectServer.Port),
|
ApiPath = string.Format("{0}://{1}:{2}/mc/api", HttpScheme, processorIp, Port),
|
||||||
GatewayAppPath = "",
|
GatewayAppPath = "",
|
||||||
LogoPath = _parent.Config.ApplicationConfig?.LogoPath ?? "logo/logo.png",
|
LogoPath = _parent.Config.ApplicationConfig?.LogoPath ?? "logo/logo.png",
|
||||||
EnableDev = _parent.Config.ApplicationConfig?.EnableDev ?? false,
|
EnableDev = _parent.Config.ApplicationConfig?.EnableDev ?? false,
|
||||||
|
|
@ -1098,6 +1109,7 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||||
res.StatusCode = 200;
|
res.StatusCode = 200;
|
||||||
res.Close();
|
res.Close();
|
||||||
|
|
||||||
|
// remote log collector has no dedicated secure flag; keep it on http regardless of DirectServer.Secure
|
||||||
var logRequest = new HttpRequestMessage(HttpMethod.Post, $"http://{_parent.Config.DirectServer.Logging.Host}:{_parent.Config.DirectServer.Logging.Port}/logs")
|
var logRequest = new HttpRequestMessage(HttpMethod.Post, $"http://{_parent.Config.DirectServer.Logging.Host}:{_parent.Config.DirectServer.Logging.Port}/logs")
|
||||||
{
|
{
|
||||||
Content = new StringContent(body, Encoding.UTF8, "application/json"),
|
Content = new StringContent(body, Encoding.UTF8, "application/json"),
|
||||||
|
|
@ -1213,8 +1225,7 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||||
this.LogVerbose("Assigning ClientId: {clientId} for token: {token} at {timestamp}", clientId, token, now);
|
this.LogVerbose("Assigning ClientId: {clientId} for token: {token} at {timestamp}", clientId, token, now);
|
||||||
|
|
||||||
// Construct WebSocket URL with clientId query parameter
|
// Construct WebSocket URL with clientId query parameter
|
||||||
var wsProtocol = "ws";
|
var wsUrl = $"{WsScheme}://{CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0)}:{Port}{_wsPath}{token}?clientId={clientId}";
|
||||||
var wsUrl = $"{wsProtocol}://{CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0)}:{Port}{_wsPath}{token}?clientId={clientId}";
|
|
||||||
|
|
||||||
// Construct the response object
|
// Construct the response object
|
||||||
JoinResponse jRes = new JoinResponse
|
JoinResponse jRes = new JoinResponse
|
||||||
|
|
@ -1226,7 +1237,8 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||||
Config = _parent.GetConfigWithPluginVersion(),
|
Config = _parent.GetConfigWithPluginVersion(),
|
||||||
CodeExpires = new DateTime().AddYears(1),
|
CodeExpires = new DateTime().AddYears(1),
|
||||||
UserCode = bridge.UserCode,
|
UserCode = bridge.UserCode,
|
||||||
UserAppUrl = string.Format("http://{0}:{1}/mc/app",
|
UserAppUrl = string.Format("{0}://{1}:{2}/mc/app",
|
||||||
|
HttpScheme,
|
||||||
CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0),
|
CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0),
|
||||||
Port),
|
Port),
|
||||||
WebSocketUrl = wsUrl,
|
WebSocketUrl = wsUrl,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue