Browse Source
* Create http auth middleware * Add support for ending the inbound stream. Closes #191 * Add a simple success response to API requestspull/207/head
6 changed files with 90 additions and 0 deletions
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
package controllers |
||||
|
||||
import ( |
||||
"net/http" |
||||
|
||||
"github.com/gabek/owncast/core" |
||||
"github.com/gabek/owncast/core/rtmp" |
||||
) |
||||
|
||||
// DisconnectInboundConnection will force-disconnect an inbound stream
|
||||
func DisconnectInboundConnection(w http.ResponseWriter, r *http.Request) { |
||||
if !core.GetStatus().Online { |
||||
writeSimpleResponse(w, false, "no inbound stream connected") |
||||
return |
||||
} |
||||
|
||||
rtmp.Disconnect() |
||||
writeSimpleResponse(w, true, "inbound stream disconnected") |
||||
} |
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
package models |
||||
|
||||
// BaseAPIResponse is a simple response to API requests.
|
||||
type BaseAPIResponse struct { |
||||
Success bool `json:"success"` |
||||
Message string `json:"message"` |
||||
} |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
package middleware |
||||
|
||||
import ( |
||||
"crypto/subtle" |
||||
"net/http" |
||||
|
||||
"github.com/gabek/owncast/config" |
||||
log "github.com/sirupsen/logrus" |
||||
) |
||||
|
||||
// RequireAdminAuth wraps a handler requiring HTTP basic auth for it using the given
|
||||
// the stream key as the password and and a hardcoded "admin" for username.
|
||||
func RequireAdminAuth(handler http.HandlerFunc) http.HandlerFunc { |
||||
username := "admin" |
||||
password := config.Config.VideoSettings.StreamingKey |
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) { |
||||
|
||||
user, pass, ok := r.BasicAuth() |
||||
realm := "Owncast Authenticated Request" |
||||
|
||||
// Failed
|
||||
if !ok || subtle.ConstantTimeCompare([]byte(user), []byte(username)) != 1 || subtle.ConstantTimeCompare([]byte(pass), []byte(password)) != 1 { |
||||
w.Header().Set("WWW-Authenticate", `Basic realm="`+realm+`"`) |
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized) |
||||
log.Warnln("Failed authentication for", r.URL.Path, "from", r.RemoteAddr, r.UserAgent()) |
||||
return |
||||
} |
||||
|
||||
// Success
|
||||
log.Traceln("Authenticated request OK for", r.URL.Path, "from", r.RemoteAddr, r.UserAgent()) |
||||
handler(w, r) |
||||
} |
||||
} |
Loading…
Reference in new issue