2022-01-13 00:53:10 +03:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/owncast/owncast/activitypub"
|
|
|
|
"github.com/owncast/owncast/activitypub/outbox"
|
|
|
|
"github.com/owncast/owncast/activitypub/persistence"
|
|
|
|
"github.com/owncast/owncast/core/data"
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils "github.com/owncast/owncast/webserver/utils"
|
2022-01-13 00:53:10 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// SendFederatedMessage will send a manual message to the fediverse.
|
|
|
|
func SendFederatedMessage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !requirePOST(w, r) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
configValue, success := getValueFromRequest(w, r)
|
|
|
|
if !success {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
message, ok := configValue.Value.(string)
|
|
|
|
if !ok {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, "unable to send message")
|
2022-04-23 23:19:17 +03:00
|
|
|
return
|
2022-01-13 00:53:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := activitypub.SendPublicFederatedMessage(message); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
2022-01-13 00:53:10 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, true, "sent")
|
2022-01-13 00:53:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetFederationEnabled will set if Federation features are enabled.
|
|
|
|
func SetFederationEnabled(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !requirePOST(w, r) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
configValue, success := getValueFromRequest(w, r)
|
|
|
|
if !success {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := data.SetFederationEnabled(configValue.Value.(bool)); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
2022-01-13 00:53:10 +03:00
|
|
|
return
|
|
|
|
}
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, true, "federation features saved")
|
2022-01-13 00:53:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetFederationActivityPrivate will set if Federation features are private to followers.
|
|
|
|
func SetFederationActivityPrivate(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !requirePOST(w, r) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
configValue, success := getValueFromRequest(w, r)
|
|
|
|
if !success {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := data.SetFederationIsPrivate(configValue.Value.(bool)); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
2022-01-13 00:53:10 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update Fediverse followers about this change.
|
|
|
|
if err := outbox.UpdateFollowersWithAccountUpdates(); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
2022-01-13 00:53:10 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, true, "federation private saved")
|
2022-01-13 00:53:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetFederationShowEngagement will set if Fedivese engagement shows in chat.
|
|
|
|
func SetFederationShowEngagement(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !requirePOST(w, r) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
configValue, success := getValueFromRequest(w, r)
|
|
|
|
if !success {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := data.SetFederationShowEngagement(configValue.Value.(bool)); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
2022-01-13 00:53:10 +03:00
|
|
|
return
|
|
|
|
}
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, true, "federation show engagement saved")
|
2022-01-13 00:53:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetFederationUsername will set the local actor username used for federation activities.
|
|
|
|
func SetFederationUsername(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !requirePOST(w, r) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
configValue, success := getValueFromRequest(w, r)
|
|
|
|
if !success {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := data.SetFederationUsername(configValue.Value.(string)); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
2022-01-13 00:53:10 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, true, "username saved")
|
2022-01-13 00:53:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetFederationGoLiveMessage will set the federated message sent when the streamer goes live.
|
|
|
|
func SetFederationGoLiveMessage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !requirePOST(w, r) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
configValue, success := getValueFromRequest(w, r)
|
|
|
|
if !success {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := data.SetFederationGoLiveMessage(configValue.Value.(string)); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
2022-01-13 00:53:10 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, true, "message saved")
|
2022-01-13 00:53:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetFederationBlockDomains saves a list of domains to block on the Fediverse.
|
|
|
|
func SetFederationBlockDomains(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !requirePOST(w, r) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
configValues, success := getValuesFromRequest(w, r)
|
|
|
|
if !success {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, "unable to handle provided domains")
|
2022-01-13 00:53:10 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
domainStrings := make([]string, 0)
|
|
|
|
for _, domain := range configValues {
|
|
|
|
domainStrings = append(domainStrings, domain.Value.(string))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := data.SetBlockedFederatedDomains(domainStrings); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
2022-01-13 00:53:10 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, true, "saved")
|
2022-01-13 00:53:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetFederatedActions will return the saved list of accepted inbound
|
|
|
|
// federated activities.
|
2022-03-07 04:18:51 +03:00
|
|
|
func GetFederatedActions(page int, pageSize int, w http.ResponseWriter, r *http.Request) {
|
|
|
|
offset := pageSize * page
|
|
|
|
|
|
|
|
activities, total, err := persistence.GetInboundActivities(pageSize, offset)
|
2022-01-13 00:53:10 +03:00
|
|
|
if err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
2022-01-13 00:53:10 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-02 07:44:37 +03:00
|
|
|
response := webutils.PaginatedResponse{
|
2022-03-07 04:18:51 +03:00
|
|
|
Total: total,
|
|
|
|
Results: activities,
|
|
|
|
}
|
|
|
|
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteResponse(w, response)
|
2022-01-13 00:53:10 +03:00
|
|
|
}
|