2023-06-09 23:25:04 +03:00
|
|
|
package webserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-07-22 08:25:59 +03:00
|
|
|
"github.com/owncast/owncast/models"
|
2023-06-16 03:11:44 +03:00
|
|
|
"github.com/owncast/owncast/services/config"
|
2023-06-09 23:25:04 +03:00
|
|
|
"github.com/owncast/owncast/utils"
|
2023-07-22 08:25:59 +03:00
|
|
|
"github.com/owncast/owncast/webserver/handlers/federation"
|
2023-06-09 23:25:04 +03:00
|
|
|
"github.com/owncast/owncast/webserver/middleware"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *webServer) setupRoutes() {
|
|
|
|
s.setupWebAssetRoutes()
|
|
|
|
s.setupInternalAPIRoutes()
|
|
|
|
s.setupAdminAPIRoutes()
|
|
|
|
s.setupExternalThirdPartyAPIRoutes()
|
|
|
|
s.setupModerationAPIRoutes()
|
2023-07-22 08:25:59 +03:00
|
|
|
s.setupActivityPubFederationRoutes()
|
2023-06-09 23:25:04 +03:00
|
|
|
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/hls/", s.handlers.HandleHLSRequest)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// websocket
|
|
|
|
s.router.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
|
2023-07-22 08:25:59 +03:00
|
|
|
s.chatService.HandleClientConnection(w, r)
|
2023-06-09 23:25:04 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
s.router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// This is a hack because Prometheus enables this endpoint by default
|
|
|
|
// due to its use of expvar and we do not want this exposed.
|
|
|
|
if r.URL.Path == "/debug/vars" {
|
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
return
|
|
|
|
} else if r.URL.Path == "/embed/chat/" || r.URL.Path == "/embed/chat" {
|
|
|
|
// Redirect /embed/chat
|
|
|
|
http.Redirect(w, r, "/embed/chat/readonly", http.StatusTemporaryRedirect)
|
|
|
|
} else {
|
2023-06-10 03:29:02 +03:00
|
|
|
s.handlers.IndexHandler(w, r)
|
2023-06-09 23:25:04 +03:00
|
|
|
// s.ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *webServer) setupWebAssetRoutes() {
|
2023-07-22 08:25:59 +03:00
|
|
|
c := config.Get()
|
2023-06-16 03:11:44 +03:00
|
|
|
|
2023-06-09 23:25:04 +03:00
|
|
|
// The admin web app.
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/admin/", middleware.RequireAdminAuth(s.handlers.IndexHandler))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Images
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/thumbnail.jpg", s.handlers.GetThumbnail)
|
|
|
|
s.router.HandleFunc("/preview.gif", s.handlers.GetPreview)
|
|
|
|
s.router.HandleFunc("/logo", s.handlers.GetLogo)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Custom Javascript
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/customjavascript", s.handlers.ServeCustomJavascript)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Return a single emoji image.
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc(config.EmojiDir, s.handlers.GetCustomEmojiImage)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// return the logo
|
|
|
|
|
|
|
|
// return a logo that's compatible with external social networks
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/logo/external", s.handlers.GetCompatibleLogo)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// robots.txt
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/robots.txt", s.handlers.GetRobotsDotTxt)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Optional public static files
|
2023-06-16 03:11:44 +03:00
|
|
|
s.router.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir(c.PublicFilesPath))))
|
2023-06-09 23:25:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *webServer) setupInternalAPIRoutes() {
|
|
|
|
// Internal APIs
|
|
|
|
|
|
|
|
// status of the system
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/status", s.handlers.GetStatus)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// custom emoji supported in the chat
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/emoji", s.handlers.GetCustomEmojiList)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// chat history api
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/chat", middleware.RequireUserAccessToken(s.handlers.GetChatMessages))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// web config api
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/config", s.handlers.GetWebConfig)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// return the YP protocol data
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/yp", s.handlers.GetYPResponse)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// list of all social platforms
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/socialplatforms", s.handlers.GetAllSocialPlatforms)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// return the list of video variants available
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/video/variants", s.handlers.GetVideoStreamOutputVariants)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// tell the backend you're an active viewer
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/ping", s.handlers.Ping)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// register a new chat user
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/chat/register", s.handlers.RegisterAnonymousChatUser)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// return remote follow details
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/remotefollow", s.handlers.RemoteFollow)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// return followers
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/followers", middleware.HandlePagination(s.handlers.GetFollowers))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// save client video playback metrics
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/metrics/playback", s.handlers.ReportPlaybackMetrics)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Register for notifications
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/notifications/register", middleware.RequireUserAccessToken(s.handlers.RegisterForLiveNotifications))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Start auth flow
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc("/api/auth/indieauth", middleware.RequireUserAccessToken(s.indieAuthHandlers.StartAuthFlow))
|
|
|
|
s.router.HandleFunc("/api/auth/indieauth/callback", s.indieAuthHandlers.HandleRedirect)
|
|
|
|
s.router.HandleFunc("/api/auth/provider/indieauth", s.indieAuthHandlers.HandleAuthEndpoint)
|
2023-06-09 23:25:04 +03:00
|
|
|
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc("/api/auth/fediverse", middleware.RequireUserAccessToken(s.fediAuthHandlers.RegisterFediverseOTPRequest))
|
|
|
|
s.router.HandleFunc("/api/auth/fediverse/verify", s.fediAuthHandlers.VerifyFediverseOTPRequest)
|
2023-06-09 23:25:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *webServer) setupAdminAPIRoutes() {
|
|
|
|
// Current inbound broadcaster
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/status", middleware.RequireAdminAuth(s.handlers.GetAdminStatus))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Disconnect inbound stream
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/disconnect", middleware.RequireAdminAuth(s.handlers.DisconnectInboundConnection))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Server config
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/serverconfig", middleware.RequireAdminAuth(s.handlers.GetServerConfig))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get viewer count over time
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/viewersOverTime", middleware.RequireAdminAuth(s.handlers.GetViewersOverTime))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get active viewers
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/viewers", middleware.RequireAdminAuth(s.handlers.GetActiveViewers))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get hardware stats
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/hardwarestats", middleware.RequireAdminAuth(s.handlers.GetHardwareStats))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get a a detailed list of currently connected chat clients
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/chat/clients", middleware.RequireAdminAuth(s.handlers.GetConnectedChatClients))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get all logs
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/logs", middleware.RequireAdminAuth(s.handlers.GetLogs))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get warning/error logs
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/logs/warnings", middleware.RequireAdminAuth(s.handlers.GetWarnings))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get all chat messages for the admin, unfiltered.
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/chat/messages", middleware.RequireAdminAuth(s.handlers.GetAdminChatMessages))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Update chat message visibility
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/chat/messagevisibility", middleware.RequireAdminAuth(s.handlers.UpdateMessageVisibility))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Enable/disable a user
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/chat/users/setenabled", middleware.RequireAdminAuth(s.handlers.UpdateUserEnabled))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Ban/unban an IP address
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/chat/users/ipbans/create", middleware.RequireAdminAuth(s.handlers.BanIPAddress))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Remove an IP address ban
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/chat/users/ipbans/remove", middleware.RequireAdminAuth(s.handlers.UnBanIPAddress))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Return all the banned IP addresses
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/chat/users/ipbans", middleware.RequireAdminAuth(s.handlers.GetIPAddressBans))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get a list of disabled users
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/chat/users/disabled", middleware.RequireAdminAuth(s.handlers.GetDisabledUsers))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Set moderator status for a user
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/chat/users/setmoderator", middleware.RequireAdminAuth(s.handlers.UpdateUserModerator))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get a list of moderator users
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/chat/users/moderators", middleware.RequireAdminAuth(s.handlers.GetModerators))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// return followers
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/followers", middleware.RequireAdminAuth(middleware.HandlePagination(s.handlers.GetFollowers)))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get a list of pending follow requests
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/followers/pending", middleware.RequireAdminAuth(s.handlers.GetPendingFollowRequests))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get a list of rejected or blocked follows
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/followers/blocked", middleware.RequireAdminAuth(s.handlers.GetBlockedAndRejectedFollowers))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Set the following state of a follower or follow request.
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/followers/approve", middleware.RequireAdminAuth(s.handlers.ApproveFollower))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Upload custom emoji
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/emoji/upload", middleware.RequireAdminAuth(s.handlers.UploadCustomEmoji))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Delete custom emoji
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/emoji/delete", middleware.RequireAdminAuth(s.handlers.DeleteCustomEmoji))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Update config values
|
|
|
|
|
|
|
|
// Change the current streaming key in memory
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/adminpass", middleware.RequireAdminAuth(s.handlers.SetAdminPassword))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Set an array of valid stream keys
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/streamkeys", middleware.RequireAdminAuth(s.handlers.SetStreamKeys))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Change the extra page content in memory
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/pagecontent", middleware.RequireAdminAuth(s.handlers.SetExtraPageContent))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Stream title
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/streamtitle", middleware.RequireAdminAuth(s.handlers.SetStreamTitle))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Server name
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/name", middleware.RequireAdminAuth(s.handlers.SetServerName))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Server summary
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/serversummary", middleware.RequireAdminAuth(s.handlers.SetServerSummary))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Offline message
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/offlinemessage", middleware.RequireAdminAuth(s.handlers.SetCustomOfflineMessage))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Server welcome message
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/welcomemessage", middleware.RequireAdminAuth(s.handlers.SetServerWelcomeMessage))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Disable chat
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/chat/disable", middleware.RequireAdminAuth(s.handlers.SetChatDisabled))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Disable chat user join messages
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/chat/joinmessagesenabled", middleware.RequireAdminAuth(s.handlers.SetChatJoinMessagesEnabled))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Enable/disable chat established user mode
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/chat/establishedusermode", middleware.RequireAdminAuth(s.handlers.SetEnableEstablishedChatUserMode))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Set chat usernames that are not allowed
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/chat/forbiddenusernames", middleware.RequireAdminAuth(s.handlers.SetForbiddenUsernameList))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Set the suggested chat usernames that will be assigned automatically
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/chat/suggestedusernames", middleware.RequireAdminAuth(s.handlers.SetSuggestedUsernameList))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Set video codec
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/video/codec", middleware.RequireAdminAuth(s.handlers.SetVideoCodec))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Set style/color/css values
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/appearance", middleware.RequireAdminAuth(s.handlers.SetCustomColorVariableValues))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Return all webhooks
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/webhooks", middleware.RequireAdminAuth(s.handlers.GetWebhooks))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Delete a single webhook
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/webhooks/delete", middleware.RequireAdminAuth(s.handlers.DeleteWebhook))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Create a single webhook
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/webhooks/create", middleware.RequireAdminAuth(s.handlers.CreateWebhook))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get all access tokens
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/accesstokens", middleware.RequireAdminAuth(s.handlers.GetExternalAPIUsers))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Delete a single access token
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/accesstokens/delete", middleware.RequireAdminAuth(s.handlers.DeleteExternalAPIUser))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Create a single access token
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/accesstokens/create", middleware.RequireAdminAuth(s.handlers.CreateExternalAPIUser))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Return the auto-update features that are supported for this instance.
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/update/options", middleware.RequireAdminAuth(s.handlers.AutoUpdateOptions))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Begin the auto update
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/update/start", middleware.RequireAdminAuth(s.handlers.AutoUpdateStart))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Force quit the service to restart it
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/update/forcequit", middleware.RequireAdminAuth(s.handlers.AutoUpdateForceQuit))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Logo path
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/logo", middleware.RequireAdminAuth(s.handlers.SetLogo))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Server tags
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/tags", middleware.RequireAdminAuth(s.handlers.SetTags))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// ffmpeg
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/ffmpegpath", middleware.RequireAdminAuth(s.handlers.SetFfmpegPath))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Server http port
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/webserverport", middleware.RequireAdminAuth(s.handlers.SetWebServerPort))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Server http listen address
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/webserverip", middleware.RequireAdminAuth(s.handlers.SetWebServerIP))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Server rtmp port
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/rtmpserverport", middleware.RequireAdminAuth(s.handlers.SetRTMPServerPort))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Websocket host override
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/sockethostoverride", middleware.RequireAdminAuth(s.handlers.SetSocketHostOverride))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Custom video serving endpoint
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/videoservingendpoint", middleware.RequireAdminAuth(s.handlers.SetVideoServingEndpoint))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Is server marked as NSFW
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/nsfw", middleware.RequireAdminAuth(s.handlers.SetNSFW))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// directory enabled
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/directoryenabled", middleware.RequireAdminAuth(s.handlers.SetDirectoryEnabled))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// social handles
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/socialhandles", middleware.RequireAdminAuth(s.handlers.SetSocialHandles))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set the number of video segments and duration per segment in a playlist
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/video/streamlatencylevel", middleware.RequireAdminAuth(s.handlers.SetStreamLatencyLevel))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set an array of video output configurations
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/video/streamoutputvariants", middleware.RequireAdminAuth(s.handlers.SetStreamOutputVariants))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set s3 configuration
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/s3", middleware.RequireAdminAuth(s.handlers.SetS3Configuration))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set server url
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/serverurl", middleware.RequireAdminAuth(s.handlers.SetServerURL))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// reset the YP registration
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/yp/reset", middleware.RequireAdminAuth(s.handlers.ResetYPRegistration))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set external action links
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/externalactions", middleware.RequireAdminAuth(s.handlers.SetExternalActions))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set custom style css
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/customstyles", middleware.RequireAdminAuth(s.handlers.SetCustomStyles))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set custom style javascript
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/customjavascript", middleware.RequireAdminAuth(s.handlers.SetCustomJavascript))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Video playback metrics
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/metrics/video", middleware.RequireAdminAuth(s.handlers.GetVideoPlaybackMetrics))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Is the viewer count hidden from viewers
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/hideviewercount", middleware.RequireAdminAuth(s.handlers.SetHideViewerCount))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set disabling of search indexing
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/disablesearchindexing", middleware.RequireAdminAuth(s.handlers.SetDisableSearchIndexing))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// enable/disable federation features
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/federation/enable", middleware.RequireAdminAuth(s.handlers.SetFederationEnabled))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set if federation activities are private
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/federation/private", middleware.RequireAdminAuth(s.handlers.SetFederationActivityPrivate))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set if fediverse engagement appears in chat
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/federation/showengagement", middleware.RequireAdminAuth(s.handlers.SetFederationShowEngagement))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set local federated username
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/federation/username", middleware.RequireAdminAuth(s.handlers.SetFederationUsername))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// set federated go live message
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/federation/livemessage", middleware.RequireAdminAuth(s.handlers.SetFederationGoLiveMessage))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Federation blocked domains
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/federation/blockdomains", middleware.RequireAdminAuth(s.handlers.SetFederationBlockDomains))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// send a public message to the Fediverse from the server's user
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/federation/send", middleware.RequireAdminAuth(s.handlers.SendFederatedMessage))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Return federated activities
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/federation/actions", middleware.RequireAdminAuth(middleware.HandlePagination(s.handlers.GetFederatedActions)))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Prometheus metrics
|
|
|
|
s.router.Handle("/api/admin/prometheus", middleware.RequireAdminAuth(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
promhttp.Handler().ServeHTTP(rw, r)
|
|
|
|
}))
|
|
|
|
|
|
|
|
// Configure outbound notification channels.
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/admin/config/notifications/discord", middleware.RequireAdminAuth(s.handlers.SetDiscordNotificationConfiguration))
|
|
|
|
s.router.HandleFunc("/api/admin/config/notifications/browser", middleware.RequireAdminAuth(s.handlers.SetBrowserNotificationConfiguration))
|
2023-06-09 23:25:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *webServer) setupExternalThirdPartyAPIRoutes() {
|
|
|
|
// Send a system message to chat
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc("/api/integrations/chat/system", middleware.RequireExternalAPIAccessToken(models.ScopeCanSendSystemMessages, s.handlers.SendSystemMessage))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Send a system message to a single client
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc(utils.RestEndpoint("/api/integrations/chat/system/client/{clientId}", middleware.RequireExternalAPIAccessToken(models.ScopeCanSendSystemMessages, s.handlers.SendSystemMessageToConnectedClient)))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Send a user message to chat *NO LONGER SUPPORTED
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc("/api/integrations/chat/user", middleware.RequireExternalAPIAccessToken(models.ScopeCanSendChatMessages, s.handlers.SendUserMessage))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Send a message to chat as a specific 3rd party bot/integration based on its access token
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc("/api/integrations/chat/send", middleware.RequireExternalAPIAccessToken(models.ScopeCanSendChatMessages, s.handlers.SendIntegrationChatMessage))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Send a user action to chat
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc("/api/integrations/chat/action", middleware.RequireExternalAPIAccessToken(models.ScopeCanSendSystemMessages, s.handlers.SendChatAction))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Hide chat message
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc("/api/integrations/chat/messagevisibility", middleware.RequireExternalAPIAccessToken(models.ScopeHasAdminAccess, s.handlers.ExternalUpdateMessageVisibility))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Stream title
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc("/api/integrations/streamtitle", middleware.RequireExternalAPIAccessToken(models.ScopeHasAdminAccess, s.handlers.ExternalSetStreamTitle))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get chat history
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc("/api/integrations/chat", middleware.RequireExternalAPIAccessToken(models.ScopeHasAdminAccess, s.handlers.ExternalGetChatMessages))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Connected clients
|
2023-07-22 08:25:59 +03:00
|
|
|
s.router.HandleFunc("/api/integrations/clients", middleware.RequireExternalAPIAccessToken(models.ScopeHasAdminAccess, s.handlers.ExternalGetConnectedChatClients))
|
2023-06-09 23:25:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *webServer) setupModerationAPIRoutes() {
|
|
|
|
// Update chat message visibility
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/chat/messagevisibility", middleware.RequireUserModerationScopeAccesstoken(s.handlers.UpdateMessageVisibility))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Enable/disable a user
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/chat/users/setenabled", middleware.RequireUserModerationScopeAccesstoken(s.handlers.UpdateUserEnabled))
|
2023-06-09 23:25:04 +03:00
|
|
|
|
|
|
|
// Get a user's details
|
2023-06-10 03:29:02 +03:00
|
|
|
s.router.HandleFunc("/api/moderation/chat/user/", middleware.RequireUserModerationScopeAccesstoken(s.handlers.GetUserDetails))
|
2023-06-09 23:25:04 +03:00
|
|
|
}
|
2023-07-22 08:25:59 +03:00
|
|
|
|
|
|
|
// StartRouter will start the federation specific http router.
|
|
|
|
func (s *webServer) setupActivityPubFederationRoutes() {
|
|
|
|
// WebFinger
|
|
|
|
s.router.HandleFunc("/.well-known/webfinger", federation.WebfingerHandler)
|
|
|
|
|
|
|
|
// Host Metadata
|
|
|
|
s.router.HandleFunc("/.well-known/host-meta", federation.HostMetaController)
|
|
|
|
|
|
|
|
// Nodeinfo v1
|
|
|
|
s.router.HandleFunc("/.well-known/nodeinfo", federation.NodeInfoController)
|
|
|
|
|
|
|
|
// x-nodeinfo v2
|
|
|
|
s.router.HandleFunc("/.well-known/x-nodeinfo2", federation.XNodeInfo2Controller)
|
|
|
|
|
|
|
|
// Nodeinfo v2
|
|
|
|
s.router.HandleFunc("/nodeinfo/2.0", federation.NodeInfoV2Controller)
|
|
|
|
|
|
|
|
// Instance details
|
|
|
|
s.router.HandleFunc("/api/v1/instance", federation.InstanceV1Controller)
|
|
|
|
|
|
|
|
// Single ActivityPub Actor
|
|
|
|
s.router.HandleFunc("/federation/user/", middleware.RequireActivityPubOrRedirect(federation.ActorHandler))
|
|
|
|
|
|
|
|
// Single AP object
|
|
|
|
s.router.HandleFunc("/federation/", middleware.RequireActivityPubOrRedirect(federation.ObjectHandler))
|
|
|
|
}
|