Esempio n. 1
0
func DelGob(w http.ResponseWriter, r *http.Request) {
	gslog.Debug("HANDLER: DelGob called with header: %+v, host: %s, requestURI: %s, remoteAddr: %s", r.Header, r.Host, r.RequestURI, r.RemoteAddr)
	params := r.URL.Query()
	token := params.Get(":token")
	if !validToken(token) {
		returnHTTPError(w, "DelGob", token+" not found", http.StatusNotFound)
		return
	}
	uid, err := store.TokenToUID(token)
	if err != nil {
		gslog.Error("HANDLER: delete gob failed with error: %s", err.Error())
		returnHTTPError(w, "DelGob", "failed to delete gob", http.StatusInternalServerError)
		return
	}
	if uid == "" {
		returnHTTPError(w, "DelGob", token+" not found", http.StatusNotFound)
		return
	}
	err = store.DelGob(uid)
	if err != nil {
		gslog.Error("HANDLER: delete gob failed with error: %s", err.Error())
		returnHTTPError(w, "DelGob", "failed to delete gob", http.StatusInternalServerError)
		return
	}

	pageType := getPageType(r)
	pageBytes, err := templ.GetMessPage(pageType, "successfully deleted "+uid)
	w.Write(pageBytes)
}
Esempio n. 2
0
func AppendGob(w http.ResponseWriter, r *http.Request) {
	gslog.Debug("HANDLER: AppendGob called with header: %+v, host: %s, requestURI: %s, remoteAddr: %s", r.Header, r.Host, r.RequestURI, r.RemoteAddr)
	params := r.URL.Query()
	token := params.Get(":token")
	if !validToken(token) {
		returnHTTPError(w, "AppendGob", token+" not found", http.StatusNotFound)
		return
	}
	gobData := getGobData(w, r)
	if len(gobData) == 0 {
		returnHTTPError(w, "AppendGob", "gob empty", http.StatusBadRequest)
		return
	}
	ip := getIpAddress(r)
	uid, err := store.TokenToUID(token)
	gslog.Debug("HANDLER: AppendGob uid: %s, ip: %s, token: %s", uid, ip, token)
	if err != nil {
		gslog.Error("HANDLER: append gob failed with error: %s", err.Error())
		returnHTTPError(w, "AppendGob", "failed to append gob", http.StatusInternalServerError)
		return
	}
	if uid == "" {
		returnHTTPError(w, "AppendGob", token+" not found", http.StatusNotFound)
		return
	}
	err = store.AppendGob(uid, gobData)
	if err != nil {
		gslog.Error("HANDLER: append gob failed with error: %s", err.Error())
		returnHTTPError(w, "AppendGob", "failed to append gob", http.StatusInternalServerError)
		return
	}

	pageType := getPageType(r)
	// TODO: Should I tell them what gob they appended? Maybe a security flaw
	pageBytes, err := templ.GetMessPage(pageType, "successfully appended "+uid)
	w.Write(pageBytes)
}