2018-01-21 11:17:43 +00:00
package routes
import (
"net/http"
2018-10-27 03:21:02 +00:00
"github.com/Azareal/Gosora/common"
2018-01-21 11:17:43 +00:00
)
func IPSearch ( w http . ResponseWriter , r * http . Request , user common . User ) common . RouteError {
2018-04-22 12:33:56 +00:00
header , ferr := common . UserCheck ( w , r , & user )
2018-01-21 11:17:43 +00:00
if ferr != nil {
return ferr
}
2018-06-01 05:02:29 +00:00
header . Title = common . 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 {
return common . NoPermissions ( w , r , user )
}
// TODO: Reject IP Addresses with illegal characters
2018-05-31 06:51:31 +00:00
var ip = common . SanitiseSingleLine ( r . FormValue ( "ip" ) )
2018-01-21 11:17:43 +00:00
uids , err := common . IPSearch . Lookup ( ip )
if err != nil {
return common . InternalError ( err , w , r )
}
// 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
userList , err := common . Users . BulkGetMap ( uids )
if err != nil {
return common . InternalError ( err , w , r )
}
2018-06-01 05:02:29 +00:00
pi := common . IPSearchPage { header , userList , ip }
2018-02-19 04:26:01 +00:00
if common . RunPreRenderHook ( "pre_render_ip_search" , w , r , & user , & pi ) {
2018-03-08 03:59:47 +00:00
return nil
}
2018-04-22 12:33:56 +00:00
err = common . RunThemeTemplate ( header . Theme . Name , "ip_search" , pi , w )
2018-01-21 11:17:43 +00:00
if err != nil {
return common . InternalError ( err , w , r )
}
return nil
}