From b41c93d19d99bcb9a3628d3ed10f1151e9cbba4e Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Mon, 15 Apr 2019 11:22:53 -0400 Subject: [PATCH] Add option to generate new pin on start Added "NewPin" to the settings to regenarate and save a new pin to the settings file on server start. --- settings.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/settings.go b/settings.go index 032e5c0..f8f1717 100644 --- a/settings.go +++ b/settings.go @@ -36,7 +36,8 @@ type Settings struct { LogLevel common.LogLevel LogFile string RoomAccess AccessMode - RoomAccessPin string // auto generate this, + RoomAccessPin string // The current pin + NewPin bool // Auto generate a new pin on start. Overwrites RoomAccessPin if set. // Rate limiting stuff, in seconds RateLimitChat time.Duration @@ -132,8 +133,12 @@ func LoadSettings(filename string) (*Settings, error) { s.RoomAccess = AccessOpen } - if s.RoomAccess != AccessOpen && len(s.RoomAccessPin) == 0 { - s.RoomAccessPin = "1234" + if (s.RoomAccess != AccessOpen && len(s.RoomAccessPin) == 0) || s.NewPin { + pin, err := s.generateNewPin() + if err != nil { + common.LogErrorf("Unable to generate new pin: %v", err) + } + common.LogInfof("New pin generated: %s", pin) } // Don't use LogInfof() here. Log isn't setup yet when LoadSettings() is called from init().