You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
815 B

package api
import (
"net/http"
"regexp"
)
func (r *Router) handleClearPortLogs(w http.ResponseWriter, req *http.Request) {
ctx, ok := r.authorizeCommand(w, req, commandSpec{Action: "log.port.clear", Target: "logs", Permission: "log.clear"})
if !ok {
return
}
var body struct {
Channel string `json:"channel"`
Password string `json:"password"`
}
if ok, _ := decodeJSONBody(w, req, &body, false); !ok {
return
}
if body.Channel != "ALL" && !regexp.MustCompile(`^CH(?:0[1-9]|[1-3][0-9]|4[0-8])$`).MatchString(body.Channel) {
writeError(w, http.StatusBadRequest, "validation_failed", "select ALL or one port CH01 through CH48 ")
return
}
if !r.verifyCurrentPassword(w, ctx, body.Password) {
return
}
result, err := r.store.ClearPortLogs(ctx, body.Channel)
writeResult(w, result, err)
}