From 23a721857f98369a75a41d1c3c2514d5618639e6 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Mon, 27 Feb 2023 17:08:52 -0800 Subject: [PATCH] Do not support stream key UI or any persisted stream keys when overridden via cli flag. Closes #2749 --- controllers/admin/serverConfig.go | 2 ++ core/rtmp/rtmp.go | 10 +++++----- web/components/admin/Offline.tsx | 10 ++++++++-- web/pages/admin/config/server/index.tsx | 10 ++++++++-- web/types/config-section.ts | 1 + web/utils/server-status-context.tsx | 1 + 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/controllers/admin/serverConfig.go b/controllers/admin/serverConfig.go index 7f26a411f..455d66870 100644 --- a/controllers/admin/serverConfig.go +++ b/controllers/admin/serverConfig.go @@ -52,6 +52,7 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) { FFmpegPath: ffmpeg, AdminPassword: data.GetAdminPassword(), StreamKeys: data.GetStreamKeys(), + StreamKeyOverridden: config.TemporaryStreamKey != "", WebServerPort: config.WebServerPort, WebServerIP: config.WebServerIP, RTMPServerPort: data.GetRTMPPortNumber(), @@ -101,6 +102,7 @@ type serverConfigAdminResponse struct { FFmpegPath string `json:"ffmpegPath"` AdminPassword string `json:"adminPassword"` StreamKeys []models.StreamKey `json:"streamKeys"` + StreamKeyOverridden bool `json:"streamKeyOverridden"` WebServerPort int `json:"webServerPort"` WebServerIP string `json:"webServerIP"` RTMPServerPort int `json:"rtmpServerPort"` diff --git a/core/rtmp/rtmp.go b/core/rtmp/rtmp.go index 06164c919..b9a4f96dd 100644 --- a/core/rtmp/rtmp.go +++ b/core/rtmp/rtmp.go @@ -81,6 +81,11 @@ func HandleConn(c *rtmp.Conn, nc net.Conn) { accessGranted := false validStreamingKeys := data.GetStreamKeys() + // If a stream key override was specified then use that instead. + if config.TemporaryStreamKey != "" { + validStreamingKeys = []models.StreamKey{{Key: config.TemporaryStreamKey}} + } + for _, key := range validStreamingKeys { if secretMatch(key.Key, c.URL.Path) { accessGranted = true @@ -88,11 +93,6 @@ func HandleConn(c *rtmp.Conn, nc net.Conn) { } } - // Test against the temporary key if it was set at runtime. - if config.TemporaryStreamKey != "" && secretMatch(config.TemporaryStreamKey, c.URL.Path) { - accessGranted = true - } - if !accessGranted { log.Errorln("invalid streaming key; rejecting incoming stream") _ = nc.Close() diff --git a/web/components/admin/Offline.tsx b/web/components/admin/Offline.tsx index 28d592a93..b79cd895e 100644 --- a/web/components/admin/Offline.tsx +++ b/web/components/admin/Offline.tsx @@ -44,7 +44,7 @@ export const Offline: FC = ({ logs = [], config }) => { const serverStatusData = useContext(ServerStatusContext); const { serverConfig } = serverStatusData || {}; - const { rtmpServerPort } = serverConfig; + const { rtmpServerPort, streamKeyOverridden } = serverConfig; const instanceUrl = global.window?.location.hostname || ''; let rtmpURL; @@ -79,7 +79,13 @@ export const Offline: FC = ({ logs = [], config }) => { Streaming Keys: - View + {!streamKeyOverridden ? ( + View + ) : ( + + Overridden via command line. + + )} diff --git a/web/pages/admin/config/server/index.tsx b/web/pages/admin/config/server/index.tsx index f89a2b0e5..bb45d32d9 100644 --- a/web/pages/admin/config/server/index.tsx +++ b/web/pages/admin/config/server/index.tsx @@ -1,13 +1,19 @@ -import React, { ReactElement } from 'react'; +import React, { ReactElement, useContext } from 'react'; import { Tabs } from 'antd'; import StreamKeys from '../../../../components/admin/config/server/StreamKeys'; import ServerConfig from '../../../../components/admin/config/server/ServerConfig'; import StorageConfig from '../../../../components/admin/config/server/StorageConfig'; +import { ServerStatusContext } from '../../../../utils/server-status-context'; import { AdminLayout } from '../../../../components/layouts/AdminLayout'; export default function PublicFacingDetails() { + const serverStatusData = useContext(ServerStatusContext); + + const { serverConfig } = serverStatusData || {}; + const { streamKeyOverridden } = serverConfig; + return (
, }, - { + !streamKeyOverridden && { label: `Stream Keys`, key: '2', children: , diff --git a/web/types/config-section.ts b/web/types/config-section.ts index 938a233f1..0f0fece19 100644 --- a/web/types/config-section.ts +++ b/web/types/config-section.ts @@ -140,6 +140,7 @@ export interface ConfigDetails { rtmpServerPort: string; s3: S3Field; streamKeys: StreamKey[]; + streamKeyOverridden: boolean; adminPassword: string; videoSettings: VideoSettingsFields; webServerPort: string; diff --git a/web/utils/server-status-context.tsx b/web/utils/server-status-context.tsx index 06b30849a..4993561ad 100644 --- a/web/utils/server-status-context.tsx +++ b/web/utils/server-status-context.tsx @@ -8,6 +8,7 @@ import { DEFAULT_VARIANT_STATE } from './config-constants'; export const initialServerConfigState: ConfigDetails = { streamKeys: [], + streamKeyOverridden: false, adminPassword: '', instanceDetails: { customStyles: '',