Send the real hash as part of the config (fixes #681)

This commit is contained in:
Audrius Butkevicius 2014-09-13 21:52:20 +01:00
parent bf7a128142
commit 24cbcef620
1 changed files with 11 additions and 21 deletions

View File

@ -45,10 +45,6 @@ var (
eventSub *events.BufferedSubscription eventSub *events.BufferedSubscription
) )
const (
unchangedPassword = "--password-unchanged--"
)
func init() { func init() {
l.AddHandler(logger.LevelWarn, showGuiError) l.AddHandler(logger.LevelWarn, showGuiError)
sub := events.Default.Subscribe(events.AllEvents) sub := events.Default.Subscribe(events.AllEvents)
@ -274,12 +270,8 @@ func restGetNodeStats(m *model.Model, w http.ResponseWriter, r *http.Request) {
} }
func restGetConfig(w http.ResponseWriter, r *http.Request) { func restGetConfig(w http.ResponseWriter, r *http.Request) {
encCfg := cfg
if encCfg.GUI.Password != "" {
encCfg.GUI.Password = unchangedPassword
}
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
json.NewEncoder(w).Encode(encCfg) json.NewEncoder(w).Encode(cfg)
} }
func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) { func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) {
@ -290,18 +282,16 @@ func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
} else { } else {
if newCfg.GUI.Password == "" { if newCfg.GUI.Password != cfg.GUI.Password {
// Leave it empty if newCfg.GUI.Password != "" {
} else if newCfg.GUI.Password == unchangedPassword { hash, err := bcrypt.GenerateFromPassword([]byte(newCfg.GUI.Password), 0)
newCfg.GUI.Password = cfg.GUI.Password if err != nil {
} else { l.Warnln("bcrypting password:", err)
hash, err := bcrypt.GenerateFromPassword([]byte(newCfg.GUI.Password), 0) http.Error(w, err.Error(), 500)
if err != nil { return
l.Warnln("bcrypting password:", err) } else {
http.Error(w, err.Error(), 500) newCfg.GUI.Password = string(hash)
return }
} else {
newCfg.GUI.Password = string(hash)
} }
} }