http
This commit is contained in:
parent
03c3c58811
commit
470b98d69c
12
http.go
12
http.go
@ -33,6 +33,7 @@ func startHTTP(cfg Config) {
|
||||
func handleKick(w http.ResponseWriter, r *http.Request) {
|
||||
user, pass, ok := r.BasicAuth()
|
||||
if !ok || !checkCredentials(user, pass) || !globalOps[user] {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="API"`)
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
@ -88,6 +89,7 @@ func handleKick(w http.ResponseWriter, r *http.Request) {
|
||||
func handleModeAPI(w http.ResponseWriter, r *http.Request) {
|
||||
user, pass, ok := r.BasicAuth()
|
||||
if !ok || !checkCredentials(user, pass) || !globalOps[user] {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="API"`)
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
@ -142,7 +144,9 @@ func handleModeAPI(w http.ResponseWriter, r *http.Request) {
|
||||
Status: "ok",
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
enc := json.NewEncoder(w)
|
||||
enc.SetIndent(" ", " ")
|
||||
enc.Encode(resp)
|
||||
}
|
||||
|
||||
type ChannelInfo struct {
|
||||
@ -154,6 +158,7 @@ type ChannelInfo struct {
|
||||
func handleListAPI(w http.ResponseWriter, r *http.Request) {
|
||||
user, pass, ok := r.BasicAuth()
|
||||
if !ok || !checkCredentials(user, pass) || !globalOps[user] {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="API"`)
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
@ -177,13 +182,16 @@ func handleListAPI(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if err := json.NewEncoder(w).Encode(list); err != nil {
|
||||
enc := json.NewEncoder(w)
|
||||
enc.SetIndent(" ", " ")
|
||||
if err := enc.Encode(list); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
func handleMOTDreload(w http.ResponseWriter, r *http.Request) {
|
||||
user, pass, ok := r.BasicAuth()
|
||||
if !ok || !checkCredentials(user, pass) || !globalOps[user] {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="API"`)
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user