Example #1
0
func ConfigPost(u utils.Utils, w http.ResponseWriter, r *http.Request) {
	specifiedSecret := parseSecret(r)
	configSecret := os.Getenv("CONFIG_SECRET")
	if configSecret == "" || specifiedSecret != configSecret {
		w.WriteHeader(http.StatusForbidden)
		u.Errorf("admin.ConfigGet: wrong secret %s", specifiedSecret)
		return
	}

	r.ParseForm()
	if keys, ok := r.PostForm["key"]; ok {
		for _, key := range keys {
			if len(key) < 1 {
				continue
			}

			if values, ok := r.PostForm[key]; ok {
				for _, value := range values {
					if err := u.ConfigSet(key, value); err != nil {
						w.WriteHeader(http.StatusInternalServerError)
						u.Errorf("admin.ConfigSet: u.ConfigSet(%q, %q) error %v", key, value, err)
						return
					}
				}
			}
		}
	}

	RulesRefresh(u)
	w.WriteHeader(http.StatusAccepted)
}