From 842bdcc808fa643e15ba8c3dfebd8f8ba8f1194e Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Mon, 28 Nov 2022 21:32:11 -0800 Subject: [PATCH] Support setting admin password and temp stream key via cli flag --- config/config.go | 3 +++ core/rtmp/rtmp.go | 6 ++++++ main.go | 16 +++++++++++----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 152c17a57..d4f590382 100644 --- a/config/config.go +++ b/config/config.go @@ -40,6 +40,9 @@ var BuildPlatform = "dev" // EnableAutoUpdate will explicitly enable in-place auto-updates via the admin. var EnableAutoUpdate = false +// A temporary stream key that can be set via the command line. +var TemporaryStreamKey = "" + // GetCommit will return an identifier used for identifying the point in time this build took place. func GetCommit() string { if GitCommit == "" { diff --git a/core/rtmp/rtmp.go b/core/rtmp/rtmp.go index 01d0fa38c..35214a400 100644 --- a/core/rtmp/rtmp.go +++ b/core/rtmp/rtmp.go @@ -11,6 +11,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/nareix/joy5/format/rtmp" + "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" ) @@ -87,6 +88,11 @@ 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/main.go b/main.go index bf00ed8e0..2e34f5dd8 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,8 @@ var ( enableDebugOptions = flag.Bool("enableDebugFeatures", false, "Enable additional debugging options.") enableVerboseLogging = flag.Bool("enableVerboseLogging", false, "Enable additional logging.") restoreDatabaseFile = flag.String("restoreDatabase", "", "Restore an Owncast database backup") - newStreamKey = flag.String("streamkey", "", "Set your stream key/admin password") + newAdminPassword = flag.String("adminpassword", "", "Set your admin password") + newStreamKey = flag.String("streamkey", "", "Set a temporary stream key for this session") webServerPortOverride = flag.String("webserverport", "", "Force the web server to listen on a specific port") webServerIPOverride = flag.String("webserverip", "", "Force web server to listen on this IP address") rtmpPortOverride = flag.Int("rtmpport", 0, "Set listen port for the RTMP server") @@ -101,15 +102,20 @@ func main() { } func handleCommandLineFlags() { - if *newStreamKey != "" { - if err := data.SetAdminPassword(*newStreamKey); err != nil { - log.Errorln("Error setting your stream key.", err) + if *newAdminPassword != "" { + if err := data.SetAdminPassword(*newAdminPassword); err != nil { + log.Errorln("Error setting your admin password.", err) log.Exit(1) } else { - log.Infoln("Stream key changed") + log.Infoln("Admin password changed") } } + if *newStreamKey != "" { + log.Println("Temporary stream key is set for this session.") + config.TemporaryStreamKey = *newStreamKey + } + // Set the web server port if *webServerPortOverride != "" { portNumber, err := strconv.Atoi(*webServerPortOverride)