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
)
2019-04-19 06:36:26 +00:00
func IPSearch ( w http . ResponseWriter , r * http . Request , user c . User , header * c . Header ) c . RouteError {
2018-11-01 06:43:56 +00:00
header . 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-04-19 06:36:26 +00:00
var ip = c . SanitiseSingleLine ( r . FormValue ( "ip" ) )
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
}
2019-04-19 09:34:16 +00:00
return renderTemplate ( "ip_search" , w , r , header , c . IPSearchPage { header , userList , ip } )
2018-01-21 11:17:43 +00:00
}