Skip to content
Snippets Groups Projects
Commit 5d648db7 authored by ale's avatar ale
Browse files

make the icecast admin password persistent

parent d8922ce2
No related branches found
No related tags found
No related merge requests found
......@@ -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"},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment