Add content policy and add abuse categories
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"fornaxian.tech/pixeldrain_server/api/restapi/apiclient"
|
||||
"fornaxian.tech/pixeldrain_server/util"
|
||||
"github.com/Fornaxian/log"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
@@ -15,11 +14,9 @@ func (wc *WebController) serveAdClick(w http.ResponseWriter, r *http.Request, p
|
||||
w.Header().Set("Referrer-Policy", "origin")
|
||||
http.Redirect(w, r, r.URL.Query().Get("target"), http.StatusTemporaryRedirect)
|
||||
|
||||
api := apiclient.New(wc.apiURLInternal)
|
||||
|
||||
// The Real IP is used in the API server to determine that the view is not
|
||||
// fake
|
||||
api.RealIP = util.RemoteAddress(r)
|
||||
var api = wc.api.RealIP(util.RemoteAddress(r))
|
||||
|
||||
// Log a view on the file
|
||||
if err := api.PostFileView(p.ByName("id"), wc.viewTokenOrBust()); err != nil {
|
||||
|
@@ -110,7 +110,14 @@ func (wc *WebController) adminAbuseForm(td *TemplateData, r *http.Request) (f Fo
|
||||
Label: "Type",
|
||||
DefaultValue: "unknown",
|
||||
Type: FieldTypeRadio,
|
||||
RadioValues: []string{"unknown", "copyright", "terrorism", "child_abuse"},
|
||||
RadioValues: []string{
|
||||
"unknown",
|
||||
"copyright",
|
||||
"child_abuse",
|
||||
"terrorism",
|
||||
"gore",
|
||||
"malware",
|
||||
},
|
||||
}, {
|
||||
Name: "reporter",
|
||||
Label: "Reporter",
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"fornaxian.tech/pixeldrain_server/api/restapi/apiclient"
|
||||
"fornaxian.tech/pixeldrain_server/util"
|
||||
"github.com/Fornaxian/log"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
@@ -21,9 +20,8 @@ func (wc *WebController) serveFilePreview(w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
api := apiclient.New(wc.apiURLInternal)
|
||||
api.APIKey, _ = wc.getAPIKey(r)
|
||||
api.RealIP = util.RemoteAddress(r)
|
||||
apiKey, _ := wc.getAPIKey(r)
|
||||
api := wc.api.Login(apiKey).RealIP(util.RemoteAddress(r))
|
||||
|
||||
file, err := api.GetFileInfo(p.ByName("id")) // TODO: Error handling
|
||||
if err != nil {
|
||||
|
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
func (wc *WebController) viewTokenOrBust() (t string) {
|
||||
var err error
|
||||
if t, err = wc.systemPixelAPI.GetMiscViewToken(); err != nil {
|
||||
if t, err = wc.api.GetMiscViewToken(); err != nil {
|
||||
log.Error("Could not get viewtoken: %s", err)
|
||||
}
|
||||
return t
|
||||
@@ -47,9 +47,7 @@ func adType() int {
|
||||
switch i := rand.Intn(5); i {
|
||||
case 0:
|
||||
return amarulaSolutions
|
||||
case 1:
|
||||
return adMaven
|
||||
case 2, 3, 4:
|
||||
case 1, 2, 3, 4:
|
||||
return propellerAds
|
||||
default:
|
||||
panic(fmt.Errorf(
|
||||
|
@@ -29,7 +29,7 @@ type TemplateData struct {
|
||||
Style pixeldrainStyleSheet
|
||||
UserStyle template.CSS
|
||||
APIEndpoint template.URL
|
||||
PixelAPI *apiclient.PixelAPI
|
||||
PixelAPI apiclient.PixelAPI
|
||||
Hostname template.HTML
|
||||
|
||||
// Only used on file viewer page
|
||||
@@ -50,19 +50,19 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request)
|
||||
Style: userStyle(r),
|
||||
UserStyle: template.CSS(userStyle(r).String()),
|
||||
APIEndpoint: template.URL(wc.apiURLExternal),
|
||||
PixelAPI: apiclient.New(wc.apiURLInternal),
|
||||
Hostname: template.HTML(wc.hostname),
|
||||
URLQuery: r.URL.Query(),
|
||||
}
|
||||
|
||||
// Use the user's IP address for making requests
|
||||
t.PixelAPI.RealIP = util.RemoteAddress(r)
|
||||
// Use the user's IP address for making requests
|
||||
PixelAPI: wc.api.RealIP(util.RemoteAddress(r)),
|
||||
|
||||
Hostname: template.HTML(wc.hostname),
|
||||
URLQuery: r.URL.Query(),
|
||||
}
|
||||
|
||||
// If the user is authenticated we'll indentify him and put the user info
|
||||
// into the templatedata. This is used for putting the username in the menu
|
||||
// and stuff like that
|
||||
if key, err := wc.getAPIKey(r); err == nil {
|
||||
t.PixelAPI.APIKey = key // Use the user's API key for all requests
|
||||
t.PixelAPI = t.PixelAPI.Login(key) // Use the user's API key for all requests
|
||||
t.User, err = t.PixelAPI.UserInfo()
|
||||
if err != nil {
|
||||
// This session key doesn't work, or the backend is down, user
|
||||
@@ -71,7 +71,7 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
if err.Error() == "authentication_required" || err.Error() == "authentication_failed" {
|
||||
// Disable API authentication
|
||||
t.PixelAPI.APIKey = ""
|
||||
t.PixelAPI = wc.api
|
||||
|
||||
// Remove the authentication cookie
|
||||
log.Debug("Deleting invalid API key")
|
||||
|
@@ -5,7 +5,6 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"fornaxian.tech/pixeldrain_server/api/restapi/apiclient"
|
||||
"github.com/Fornaxian/log"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
@@ -16,8 +15,7 @@ func (wc *WebController) serveLogout(
|
||||
p httprouter.Params,
|
||||
) {
|
||||
if key, err := wc.getAPIKey(r); err == nil {
|
||||
var api = apiclient.New(wc.apiURLInternal)
|
||||
api.APIKey = key
|
||||
var api = wc.api.Login(key)
|
||||
if err = api.UserSessionDestroy(key); err != nil {
|
||||
log.Warn("logout failed for session '%s': %s", key, err)
|
||||
}
|
||||
@@ -150,7 +148,7 @@ func (wc *WebController) loginForm(td *TemplateData, r *http.Request) (f Form) {
|
||||
}
|
||||
|
||||
if f.ReadInput(r) {
|
||||
loginResp, err := td.PixelAPI.UserLogin(f.FieldVal("username"), f.FieldVal("password"), false)
|
||||
loginResp, err := td.PixelAPI.UserLogin(f.FieldVal("username"), f.FieldVal("password"))
|
||||
if err != nil {
|
||||
formAPIError(err, &f)
|
||||
} else {
|
||||
|
@@ -170,8 +170,7 @@ func (wc *WebController) serveEmailConfirm(
|
||||
var err error
|
||||
var status string
|
||||
|
||||
api := apiclient.New(wc.apiURLInternal)
|
||||
err = api.UserEmailResetConfirm(r.FormValue("key"))
|
||||
err = wc.api.UserEmailResetConfirm(r.FormValue("key"))
|
||||
if err != nil && err.Error() == "not_found" {
|
||||
status = "not_found"
|
||||
} else if err != nil {
|
||||
|
@@ -36,9 +36,10 @@ type WebController struct {
|
||||
|
||||
httpClient *http.Client
|
||||
|
||||
// This API client should only be used for system functions like getting
|
||||
// view tokens. It has no authentication and no IP forwarding
|
||||
systemPixelAPI *apiclient.PixelAPI
|
||||
// API client to use for all requests. If the user is authenticated you
|
||||
// should call Login() on this object. Calling Login will create a copy and
|
||||
// not alter the original PixelAPI, but it will use the same HTTP Transport
|
||||
api apiclient.PixelAPI
|
||||
}
|
||||
|
||||
// New initializes a new WebController by registering all the request handlers
|
||||
@@ -60,7 +61,7 @@ func New(
|
||||
apiURLExternal: apiURLExternal,
|
||||
sessionCookieDomain: sessionCookieDomain,
|
||||
httpClient: &http.Client{Timeout: time.Minute * 10},
|
||||
systemPixelAPI: apiclient.New(apiURLInternal),
|
||||
api: apiclient.New(apiURLInternal),
|
||||
}
|
||||
wc.templates = NewTemplateManager(resourceDir, apiURLExternal, debugMode)
|
||||
wc.templates.ParseTemplates(false)
|
||||
@@ -218,7 +219,7 @@ func (wc *WebController) serveMarkdown(tpl string, requireAuth bool) httprouter.
|
||||
var inHeader = false
|
||||
blackfriday.New(
|
||||
blackfriday.WithRenderer(renderer),
|
||||
blackfriday.WithExtensions(blackfriday.CommonExtensions),
|
||||
blackfriday.WithExtensions(blackfriday.CommonExtensions|blackfriday.AutoHeadingIDs),
|
||||
).Parse(
|
||||
tplBuf.Bytes(),
|
||||
).Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus {
|
||||
@@ -337,8 +338,7 @@ func (wc *WebController) getAPIKey(r *http.Request) (key string, err error) {
|
||||
func (wc *WebController) captchaKey() string {
|
||||
// This only runs on the first request
|
||||
if wc.captchaSiteKey == "" {
|
||||
var api = apiclient.New(wc.apiURLInternal)
|
||||
capt, err := api.GetRecaptcha()
|
||||
capt, err := wc.api.GetRecaptcha()
|
||||
if err != nil {
|
||||
log.Error("Error getting recaptcha key: %s", err)
|
||||
return ""
|
||||
|
Reference in New Issue
Block a user