github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/routes/moderate.go (about)

     1  package routes
     2  
     3  import (
     4  	"net/http"
     5  
     6  	c "github.com/Azareal/Gosora/common"
     7  	"github.com/Azareal/Gosora/common/phrases"
     8  )
     9  
    10  func IPSearch(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c.RouteError {
    11  	h.Title = phrases.GetTitlePhrase("ip_search")
    12  	// TODO: How should we handle the permissions if we extend this into an alt detector of sorts?
    13  	if !u.Perms.ViewIPs {
    14  		return c.NoPermissions(w, r, u)
    15  	}
    16  
    17  	// TODO: Reject IP Addresses with illegal characters
    18  	ip := c.SanitiseSingleLine(r.FormValue("ip"))
    19  	uids, err := c.IPSearch.Lookup(ip)
    20  	if err != nil {
    21  		return c.InternalError(err, w, r)
    22  	}
    23  
    24  	// TODO: What if a user is deleted via the Control Panel? We'll cross that bridge when we come to it, although we might lean towards blanking the account and removing the related data rather than purging it
    25  	userList, err := c.Users.BulkGetMap(uids)
    26  	if err != nil {
    27  		return c.InternalError(err, w, r)
    28  	}
    29  	return renderTemplate("ip_search", w, r, h, c.IPSearchPage{h, userList, ip})
    30  }