示例#1
0
func PushRecurringEnd(w http.ResponseWriter, req *http.Request) *webapp.Error {
	host, err := hostnamesec.GetValidHost(req.RemoteAddr)
	if err != nil {
		http.Error(w, "forbidden", http.StatusForbidden)
		return nil
	}

	vars := mux.Vars(req)
	task, tOk := vars["task"]
	identifier, iOk := vars["identifier"]
	state, sOk := vars["state"]
	if !tOk || !iOk || !sOk {
		return webapp.Write(errors.New("Invalid request"), "invalid request", http.StatusBadRequest)
	}

	buf := new(bytes.Buffer)
	buf.ReadFrom(req.Body)
	defer req.Body.Close()
	body := buf.String()

	err = anaLog.PushRecurringEnd(task, host, identifier, state, body)
	if err != nil {
		return webapp.Write(err, err.Error(), http.StatusInternalServerError)
	}

	w.WriteHeader(http.StatusAccepted)
	return nil
}
示例#2
0
func AnalyzeRecurring(w http.ResponseWriter, req *http.Request) *webapp.Error {
	_, err := hostnamesec.GetValidHost(req.RemoteAddr)
	if err != nil {
		idl.Emerg(err)
	}
	ta, err := anaLog.AnalyzeRecurring()
	fmt.Fprintln(w, ta, err)
	return nil
}
示例#3
0
func PushRecurringBegin(w http.ResponseWriter, req *http.Request) *webapp.Error {
	host, err := hostnamesec.GetValidHost(req.RemoteAddr)
	if err != nil {
		http.Error(w, "forbidden", http.StatusForbidden)
		return nil
	}

	vars := mux.Vars(req)
	task, ok := vars["task"]
	if !ok {
		return webapp.Write(errors.New("Invalid request: no task"), "no task given", http.StatusBadRequest)
	}

	identifier, err := anaLog.PushRecurringBegin(task, host)
	if err != nil {
		return webapp.Write(err, err.Error(), http.StatusInternalServerError)
	}

	w.WriteHeader(http.StatusCreated)
	fmt.Fprint(w, identifier)
	return nil
}