From ce2150f7192807fc731b0c2766313ae9836920cb Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Sat, 18 Apr 2020 16:02:41 -0400 Subject: [PATCH] Add ability to set admin password at startup The -a flag has been added to allow specifying a new admin password on the command line. This password will only be used for the current session and will not be written to the configuration file. If the password contains spaces, wrap it in quotes on the command line. The quotes should be omitted with the /auth command. Eg, starting the server with: ./MovieNight -a "the admin password" the auth command in chat would be: /auth the admin password --- main.go | 7 +++++++ settings.go | 9 ++++++--- settings_example.json | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 1db444a..6322464 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ var ( addr string sKey string stats = newStreamStats() + sAdminPass string ) func setupSettings() error { @@ -30,6 +31,11 @@ func setupSettings() error { return fmt.Errorf("Missing stream key is settings.json") } + if sAdminPass != "" { + fmt.Println("Password provided at runtime; ignoring password in set in settings.") + settings.AdminPassword = sAdminPass + } + sstore = sessions.NewCookieStore([]byte(settings.SessionKey)) sstore.Options = &sessions.Options{ Path: "/", @@ -43,6 +49,7 @@ func setupSettings() error { func main() { flag.StringVar(&addr, "l", "", "host:port of the MovieNight") flag.StringVar(&sKey, "k", "", "Stream key, to protect your stream") + flag.StringVar(&sAdminPass, "a", "", "Set admin password. Overrides configuration in settings.json. This will not write the password to settings.json.") flag.BoolVar(&pullEmotes, "e", false, "Pull emotes") flag.Parse() diff --git a/settings.go b/settings.go index 76c2741..18f0512 100644 --- a/settings.go +++ b/settings.go @@ -27,6 +27,7 @@ type Settings struct { MaxMessageCount int TitleLength int // maximum length of the title that can be set with the /playing AdminPassword string + RegenAdminPass bool // regenerate admin password on start? StreamKey string ListenAddress string ApprovedEmotes []string // list of channels that have been approved for emote use. Global emotes are always "approved". @@ -90,9 +91,11 @@ func LoadSettings(filename string) (*Settings, error) { return s, fmt.Errorf("value for MaxMessageCount must be greater than 0, given %d", s.MaxMessageCount) } - s.AdminPassword, err = generatePass(time.Now().Unix()) - if err != nil { - return nil, fmt.Errorf("unable to generate admin password: %s", err) + if s.RegenAdminPass == true || s.AdminPassword == "" { + s.AdminPassword, err = generatePass(time.Now().Unix()) + if err != nil { + return nil, fmt.Errorf("unable to generate admin password: %s", err) + } } if s.RateLimitChat == -1 { diff --git a/settings_example.json b/settings_example.json index bf3b028..cd9583c 100644 --- a/settings_example.json +++ b/settings_example.json @@ -2,6 +2,7 @@ "MaxMessageCount": 300, "TitleLength": 50, "AdminPassword": "", + "RegenAdminPass": true, "Bans": [], "StreamKey": "ALongStreamKey", "ListenAddress": ":8089",