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
This commit is contained in:
parent
d08eff1bdb
commit
ce2150f719
7
main.go
7
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()
|
||||
|
||||
|
@ -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,10 +91,12 @@ func LoadSettings(filename string) (*Settings, error) {
|
||||
return s, fmt.Errorf("value for MaxMessageCount must be greater than 0, given %d", s.MaxMessageCount)
|
||||
}
|
||||
|
||||
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 {
|
||||
s.RateLimitChat = 0
|
||||
|
@ -2,6 +2,7 @@
|
||||
"MaxMessageCount": 300,
|
||||
"TitleLength": 50,
|
||||
"AdminPassword": "",
|
||||
"RegenAdminPass": true,
|
||||
"Bans": [],
|
||||
"StreamKey": "ALongStreamKey",
|
||||
"ListenAddress": ":8089",
|
||||
|
Loading…
Reference in New Issue
Block a user