diff --git a/docs/source/about/advanced_usage.rst b/docs/source/about/advanced_usage.rst index c433a7ca..dfc86454 100644 --- a/docs/source/about/advanced_usage.rst +++ b/docs/source/about/advanced_usage.rst @@ -552,6 +552,9 @@ port **Default** ``47989`` +**Range** + ``1029-65514`` + **Example** .. code-block:: text diff --git a/src/config.cpp b/src/config.cpp index 7c738679..94657a49 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -16,6 +16,8 @@ #include "config.h" #include "main.h" +#include "nvhttp.h" +#include "rtsp.h" #include "utility.h" #include "platform/common.h" @@ -1049,7 +1051,7 @@ namespace config { bool_f(vars, "always_send_scancodes", input.always_send_scancodes); int port = sunshine.port; - int_f(vars, "port"s, port); + int_between_f(vars, "port"s, port, { 1024 + nvhttp::PORT_HTTPS, 65535 - rtsp_stream::RTSP_SETUP_PORT }); sunshine.port = (std::uint16_t) port; string_restricted_f(vars, "address_family", sunshine.address_family, { "ipv4"sv, "both"sv }); diff --git a/src/main.cpp b/src/main.cpp index c04e5dcd..a2aee13f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -836,7 +836,15 @@ write_file(const char *path, const std::string_view &contents) { */ std::uint16_t map_port(int port) { - // TODO: Ensure port is in the range of 21-65535 + // calculate the port from the config port + auto mapped_port = (std::uint16_t)((int) config::sunshine.port + port); + + // Ensure port is in the range of 1024-65535 + if (mapped_port < 1024 || mapped_port > 65535) { + BOOST_LOG(warning) << "Port out of range: "sv << mapped_port; + } + // TODO: Ensure port is not already in use by another application - return (std::uint16_t)((int) config::sunshine.port + port); + + return mapped_port; } diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html index d85004cd..d2a8f4c3 100644 --- a/src_assets/common/assets/web/config.html +++ b/src_assets/common/assets/web/config.html @@ -72,6 +72,7 @@ id="origin_web_ui_allowed" class="form-select" v-model="config.origin_web_ui_allowed" + @change="forceUpdate" > @@ -80,6 +81,10 @@
The origin of the remote endpoint address that is not denied access to Web UI
+ +
+ Exposing the Web UI to the internet is a security risk! Proceed at your own risk! +
@@ -625,14 +630,79 @@
Set the family of ports used by Sunshine
+ +
+ Sunshine cannot use ports below 1024! +
+ +
+ Ports above 65535 are not available! +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ProtocolPortNote
TCP{{+effectivePort - 5}}
TCP{{+effectivePort}} + +
TCP{{+effectivePort + 1}}Web UI
TCP{{+effectivePort + 21}}
UDP{{+effectivePort + 9}} - {{+effectivePort + 11}}
+ +
+ Exposing the Web UI to the internet is a security risk! + Proceed at your own risk! +
@@ -1058,10 +1128,11 @@
- Success! Click 'Apply' to restart Sunshine and apply changes. This will terminate any running sessions. + Click 'Apply' to restart Sunshine and apply changes. + This will terminate any running sessions.
-
- Success! Sunshine is restarting to apply changes. +
+ Sunshine is restarting to apply changes.
@@ -1223,6 +1294,9 @@ }); }, methods: { + forceUpdate() { + this.$forceUpdate() + }, serialize() { let nl = this.config === "windows" ? "\r\n" : "\n"; this.config.resolutions = @@ -1309,6 +1383,16 @@ this.global_prep_cmd.push(template); }, }, + computed: { + effectivePort() { + // Convert config.port to a number. + const port = +this.config?.port + + // Check if port is NaN or a falsy value (like 0, empty string, etc.). + // If so, default to config port. Otherwise, use the value of port. + return port ? port : 47989 + }, + } });