1
0
Fork 0
mirror of https://github.com/owncast/owncast.git synced 2024-10-28 01:59:38 +01:00

Support setting admin password and temp stream key via cli flag

This commit is contained in:
Gabe Kangas 2022-11-28 21:32:11 -08:00
parent 5d51c73cd9
commit 842bdcc808
3 changed files with 20 additions and 5 deletions

View file

@ -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 == "" {

View file

@ -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()

16
main.go
View file

@ -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)