From 5d648db72eb009ea3960745c527d5c5413dcf29a Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Fri, 17 Oct 2014 10:29:54 +0100 Subject: [PATCH] make the icecast admin password persistent --- node/icecast_config.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/node/icecast_config.go b/node/icecast_config.go index dad85a3a..c6546fe1 100644 --- a/node/icecast_config.go +++ b/node/icecast_config.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/xml" "io" + "io/ioutil" "log" "net" "net/url" @@ -16,8 +17,28 @@ import ( var ( //shoutHttpPort = 8001 maxClients = 10000 + + icecastAdminPwFile = "/etc/icecast/.admin_pw" + icecastAdminPw string ) +// Return the global Icecast admin password. If it does not exist, +// generate a random one and save it for subsequent invocations. +func getIcecastAdminPassword() string { + if icecastAdminPw == "" { + data, err := ioutil.ReadFile(icecastAdminPwFile) + if err != nil { + icecastAdminPw = autoradio.GeneratePassword() + if err := ioutil.WriteFile(icecastAdminPwFile, []byte(icecastAdminPw), 0600); err != nil { + log.Printf("Couldn't save icecast admin password: %v", err) + } + } else { + icecastAdminPw = string(data) + } + } + return icecastAdminPw +} + type iceLimitsConfig struct { Clients int `xml:"clients"` Sources int `xml:"sources"` @@ -115,10 +136,12 @@ type icecastConfig struct { // that it is possible to set them on a per-host basis. // func defaultDebianConfig(publicIp string) *icecastConfig { - // Pick some random passwords on startup. We don't use them, - // but icecast is happier if they're set. + // Set the icecast admin password once, on the first run, and + // save it on the filesystem. We don't use the global source + // password, but icecast is happier if it's set, so we just + // use a random password every time. sourcePw := autoradio.GeneratePassword() - adminPw := autoradio.GeneratePassword() + adminPw := getIcecastAdminPassword() return &icecastConfig{ XMLName: xml.Name{"", "icecast"}, -- GitLab