2018-01-21 11:17:43 +00:00
package routes
import (
"net/http"
2019-04-19 06:36:26 +00:00
c "github.com/Azareal/Gosora/common"
2018-11-01 06:43:56 +00:00
"github.com/Azareal/Gosora/common/phrases"
2018-01-21 11:17:43 +00:00
)
2020-03-15 11:34:57 +00:00
func IPSearch ( w http . ResponseWriter , r * http . Request , user c . User , h * c . Header ) c . RouteError {
2020-02-09 10:00:08 +00:00
h . Title = phrases . GetTitlePhrase ( "ip_search" )
2018-01-21 11:17:43 +00:00
// TODO: How should we handle the permissions if we extend this into an alt detector of sorts?
if ! user . Perms . ViewIPs {
2019-04-19 06:36:26 +00:00
return c . NoPermissions ( w , r , user )
2018-01-21 11:17:43 +00:00
}
// TODO: Reject IP Addresses with illegal characters
2019-10-01 21:06:22 +00:00
ip := c . SanitiseSingleLine ( r . FormValue ( "ip" ) )
2019-04-19 06:36:26 +00:00
uids , err := c . IPSearch . Lookup ( ip )
2018-01-21 11:17:43 +00:00
if err != nil {
2019-04-19 06:36:26 +00:00
return c . InternalError ( err , w , r )
2018-01-21 11:17:43 +00:00
}
// 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
2019-04-19 06:36:26 +00:00
userList , err := c . Users . BulkGetMap ( uids )
2018-01-21 11:17:43 +00:00
if err != nil {
2019-04-19 06:36:26 +00:00
return c . InternalError ( err , w , r )
2018-01-21 11:17:43 +00:00
}
2020-02-09 10:00:08 +00:00
return renderTemplate ( "ip_search" , w , r , h , c . IPSearchPage { h , userList , ip } )
2018-01-21 11:17:43 +00:00
}