2020-10-30 18:16:21 +01:00
|
|
|
package room
|
|
|
|
|
|
|
|
import (
|
2021-01-08 23:42:53 +01:00
|
|
|
"net/http"
|
|
|
|
|
2020-10-30 18:16:21 +01:00
|
|
|
"github.com/go-chi/chi"
|
|
|
|
|
2020-11-16 19:37:52 +01:00
|
|
|
"demodesk/neko/internal/http/auth"
|
2021-02-14 14:40:17 +01:00
|
|
|
"demodesk/neko/internal/types"
|
2021-01-08 23:42:53 +01:00
|
|
|
"demodesk/neko/internal/utils"
|
2020-10-30 18:16:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type RoomHandler struct {
|
2020-12-08 14:31:15 +01:00
|
|
|
sessions types.SessionManager
|
|
|
|
desktop types.DesktopManager
|
|
|
|
capture types.CaptureManager
|
2020-10-30 18:16:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func New(
|
|
|
|
sessions types.SessionManager,
|
2020-11-01 16:54:06 +01:00
|
|
|
desktop types.DesktopManager,
|
|
|
|
capture types.CaptureManager,
|
2020-10-30 18:16:21 +01:00
|
|
|
) *RoomHandler {
|
2020-12-08 14:31:15 +01:00
|
|
|
// Init
|
2020-10-30 18:16:21 +01:00
|
|
|
|
|
|
|
return &RoomHandler{
|
2020-12-08 14:31:15 +01:00
|
|
|
sessions: sessions,
|
|
|
|
desktop: desktop,
|
|
|
|
capture: capture,
|
2020-10-30 18:16:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 18:16:25 +01:00
|
|
|
func (h *RoomHandler) Route(r chi.Router) {
|
2020-11-18 21:56:42 +01:00
|
|
|
r.With(auth.AdminsOnly).Route("/broadcast", func(r chi.Router) {
|
2020-11-18 22:35:50 +01:00
|
|
|
r.Get("/", h.broadcastStatus)
|
|
|
|
r.Post("/start", h.boradcastStart)
|
|
|
|
r.Post("/stop", h.boradcastStop)
|
2020-10-31 10:48:24 +01:00
|
|
|
})
|
2020-10-30 18:16:21 +01:00
|
|
|
|
2020-11-16 19:37:52 +01:00
|
|
|
r.With(auth.HostsOnly).Route("/clipboard", func(r chi.Router) {
|
2021-01-29 20:05:13 +01:00
|
|
|
r.Get("/", h.clipboardGetText)
|
|
|
|
r.Post("/", h.clipboardSetText)
|
|
|
|
r.Get("/image.png", h.clipboardGetImage)
|
|
|
|
|
|
|
|
// TODO: Refactor. xclip is failing to set propper target type
|
|
|
|
// and this content is sent back to client as text in another
|
|
|
|
// clipboard update. Therefore endpoint is not usable!
|
2021-01-29 00:03:22 +01:00
|
|
|
//r.Post("/image", h.clipboardSetImage)
|
2021-02-02 18:28:32 +01:00
|
|
|
|
2021-01-29 20:05:13 +01:00
|
|
|
// TODO: Refactor. If there would be implemented custom target
|
|
|
|
// retrieval, this endpoint would be useful.
|
|
|
|
//r.Get("/targets", h.clipboardGetTargets)
|
2020-10-31 12:35:02 +01:00
|
|
|
})
|
2020-11-16 22:48:20 +01:00
|
|
|
|
2021-01-12 23:35:46 +01:00
|
|
|
r.Route("/keyboard", func(r chi.Router) {
|
2021-01-15 16:53:03 +01:00
|
|
|
r.Get("/map", h.keyboardMapGet)
|
|
|
|
r.With(auth.HostsOnly).Post("/map", h.keyboardMapSet)
|
2021-01-12 23:35:46 +01:00
|
|
|
|
|
|
|
r.Get("/modifiers", h.keyboardModifiersGet)
|
|
|
|
r.With(auth.HostsOnly).Post("/modifiers", h.keyboardModifiersSet)
|
2020-11-18 21:56:42 +01:00
|
|
|
})
|
|
|
|
|
2020-11-16 22:48:20 +01:00
|
|
|
r.Route("/control", func(r chi.Router) {
|
2020-11-18 23:14:28 +01:00
|
|
|
r.Get("/", h.controlStatus)
|
2020-11-18 22:35:50 +01:00
|
|
|
r.Post("/request", h.controlRequest)
|
|
|
|
r.Post("/release", h.controlRelease)
|
2020-11-18 21:10:40 +01:00
|
|
|
|
2020-11-18 22:35:50 +01:00
|
|
|
r.With(auth.AdminsOnly).Post("/take", h.controlTake)
|
|
|
|
r.With(auth.AdminsOnly).Post("/give", h.controlGive)
|
2020-11-29 15:58:26 +01:00
|
|
|
r.With(auth.AdminsOnly).Post("/reset", h.controlReset)
|
2020-11-16 22:48:20 +01:00
|
|
|
})
|
2020-11-18 21:34:39 +01:00
|
|
|
|
2020-11-18 21:56:42 +01:00
|
|
|
r.Route("/screen", func(r chi.Router) {
|
2021-01-21 20:44:09 +01:00
|
|
|
r.With(auth.CanWatchOnly).Get("/", h.screenConfiguration)
|
2021-01-23 15:23:10 +01:00
|
|
|
r.With(auth.CanWatchOnly).Get("/shot.jpg", h.screenShotGet)
|
2021-01-23 15:17:52 +01:00
|
|
|
r.With(auth.CanWatchOnly).Get("/cast.jpg", h.screenCastGet)
|
2020-11-18 21:53:06 +01:00
|
|
|
|
2020-11-18 22:35:50 +01:00
|
|
|
r.With(auth.AdminsOnly).Post("/", h.screenConfigurationChange)
|
|
|
|
r.With(auth.AdminsOnly).Get("/configurations", h.screenConfigurationsList)
|
2020-11-18 21:53:06 +01:00
|
|
|
})
|
2021-01-06 18:57:50 +01:00
|
|
|
|
2021-01-08 23:42:53 +01:00
|
|
|
r.With(h.uploadMiddleware).Route("/upload", func(r chi.Router) {
|
2021-01-07 18:28:23 +01:00
|
|
|
r.Post("/drop", h.uploadDrop)
|
2021-01-18 10:34:33 +01:00
|
|
|
r.Post("/dialog", h.uploadDialogPost)
|
|
|
|
r.Delete("/dialog", h.uploadDialogClose)
|
2021-01-06 18:57:50 +01:00
|
|
|
})
|
2020-10-30 18:16:21 +01:00
|
|
|
}
|
2021-01-08 23:42:53 +01:00
|
|
|
|
|
|
|
func (h *RoomHandler) uploadMiddleware(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
session := auth.GetSession(r)
|
2021-01-09 13:42:08 +01:00
|
|
|
if !session.IsHost() && (!session.CanHost() || !h.sessions.ImplicitHosting()) {
|
2021-01-08 23:42:53 +01:00
|
|
|
utils.HttpForbidden(w, "Without implicit hosting, only host can upload files.")
|
|
|
|
} else {
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|