Beispiel #1
0
func HandleBalancerCreate(w http.ResponseWriter, r *http.Request) {
	err := r.ParseForm()
	if err != nil {
		http.Error(w, "Bad Request", http.StatusBadRequest)
		return
	}
	body := struct {
		Label string `schema:"label"`
	}{}
	err = schema.NewDecoder().Decode(&body, r.PostForm)
	if err != nil {
		http.Error(w, "Bad Request", http.StatusBadRequest)
		return
	}

	bal := data.Balancer{}
	bal.Label = body.Label
	err = bal.Put()
	if err != nil {
		panic(err)
	}

	err = feline.Commit(&bal)
	if err != nil {
		panic(err)
	}

	http.Redirect(w, r, "/balancers/"+bal.Id.Hex()+"/edit", http.StatusSeeOther)
}
Beispiel #2
0
func HandleServerUpdate(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	if !bson.IsObjectIdHex(vars["id"]) {
		http.Error(w, "Not Found", http.StatusNotFound)
		return
	}
	srv, err := data.GetServer(bson.ObjectIdHex(vars["id"]))
	if err != nil {
		panic(err)
	}

	err = r.ParseForm()
	if err != nil {
		http.Error(w, "Bad Request", http.StatusBadRequest)
		return
	}
	body := struct {
		Label    string `schema:"label"`
		Settings struct {
			Address      string `schema:"address"`
			Weight       int    `schema:"weight"`
			Availability string `schema:"availability"`
		} `schema:"settings"`
	}{}
	err = schema.NewDecoder().Decode(&body, r.PostForm)
	if err != nil {
		http.Error(w, "Bad Request", http.StatusBadRequest)
		return
	}

	srv.Label = body.Label
	srv.Settings.Address = body.Settings.Address
	srv.Settings.Weight = body.Settings.Weight
	srv.Settings.Availability = data.Availability(body.Settings.Availability)
	err = srv.Put()
	if err != nil {
		panic(err)
	}

	bal, err := srv.Balancer()
	if err != nil {
		panic(err)
	}
	err = feline.Commit(bal)
	if err != nil {
		panic(err)
	}

	http.Redirect(w, r, "/balancers/"+srv.BalancerId.Hex(), http.StatusSeeOther)
}
Beispiel #3
0
func HandleBalancerUpdate(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	if !bson.IsObjectIdHex(vars["id"]) {
		http.Error(w, "Not Found", http.StatusNotFound)
		return
	}
	bal, err := data.GetBalancer(bson.ObjectIdHex(vars["id"]))
	if err != nil {
		panic(err)
	}

	err = r.ParseForm()
	if err != nil {
		http.Error(w, "Bad Request", http.StatusBadRequest)
		return
	}
	body := struct {
		Label    string `schema:"label"`
		Settings struct {
			Hostname   string `schema:"hostname"`
			Port       int    `schema:"port"`
			Protocol   string `schema:"protocol"`
			Algorithm  string `schema:"algorithm"`
			SSLOptions struct {
				CipherSuite string  `schema:"cipher_suite"`
				Certificate *string `schema:"certificate"`
				PrivateKey  *string `schema:"private_key"`
			} `schema:"ssl_options"`
		} `schema:"settings"`
	}{}
	err = schema.NewDecoder().Decode(&body, r.PostForm)
	if err != nil {
		http.Error(w, "Bad Request", http.StatusBadRequest)
		return
	}

	bal.Label = body.Label
	bal.Settings.Hostname = body.Settings.Hostname
	bal.Settings.Port = body.Settings.Port
	bal.Settings.Protocol = data.Protocol(body.Settings.Protocol)
	bal.Settings.Algorithm = data.Algorithm(body.Settings.Algorithm)
	if body.Settings.Protocol == "https" {
		bal.Settings.SSLOptions.CipherSuite = "recommended"
		if body.Settings.SSLOptions.Certificate != nil {
			bal.Settings.SSLOptions.Certificate = []byte(*body.Settings.SSLOptions.Certificate)
		}
		if body.Settings.SSLOptions.PrivateKey != nil {
			bal.Settings.SSLOptions.PrivateKey = []byte(*body.Settings.SSLOptions.PrivateKey)
		}
	}
	err = bal.Put()
	if err != nil {
		panic(err)
	}

	err = feline.Commit(bal)
	if err != nil {
		panic(err)
	}

	http.Redirect(w, r, "/balancers/"+bal.Id.Hex(), http.StatusSeeOther)
}