package icecast_output import ( "io" "git.icedream.tech/icedream/uplink/app/authentication" "git.icedream.tech/icedream/uplink/app/channels" "git.icedream.tech/icedream/uplink/app/servers/http" "github.com/gin-gonic/gin" ) type pluginInstance struct { server *httpserver.Server authenticator authentication.Authenticator channelManager *channels.ChannelManager } func (instance *pluginInstance) SetAuthenticator(authenticator authentication.Authenticator) { instance.authenticator = authenticator } func (instance *pluginInstance) SetChannelManager(channelManager *channels.ChannelManager) { instance.channelManager = channelManager } func (instance *pluginInstance) SetServer(server *httpserver.Server) { instance.server = server router := instance.server.Router router.PUT("/:channel", func(ctx *gin.Context) { channel := instance.channelManager.Channel(ctx.Param("channel")) if channel == nil { ctx.Status(404) return } if user, password, ok := ctx.Request.BasicAuth(); ok { if !instance.authenticator.VerifyUsernameAndPassword(channel, user, password) { ctx.Status(401) return } } else { ctx.Status(401) return } io.Copy(channel.InputStream, ctx.Request.Body) }) }