From e5c2588eab7a02b17606bcc5433cc53ddbe2bc5f Mon Sep 17 00:00:00 2001 From: Alex Jaspersen Date: Sun, 20 Jun 2021 10:26:30 -0700 Subject: [PATCH] Show real IP in WHOWAS to opers with ban capability. --- irc/client.go | 5 +++++ irc/getters.go | 1 + irc/handlers.go | 8 ++++---- irc/numerics.go | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/irc/client.go b/irc/client.go index d8f566d7..793b4419 100644 --- a/irc/client.go +++ b/irc/client.go @@ -269,6 +269,7 @@ type WhoWas struct { username string hostname string realname string + realIP net.IP // technically not required for WHOWAS: account string accountName string @@ -598,6 +599,10 @@ func (client *Client) IP() net.IP { client.stateMutex.RLock() defer client.stateMutex.RUnlock() + return client.getIPNoMutex() +} + +func (client *Client) getIPNoMutex() net.IP { if client.proxiedIP != nil { return client.proxiedIP } diff --git a/irc/getters.go b/irc/getters.go index 3000c1e4..9aff0155 100644 --- a/irc/getters.go +++ b/irc/getters.go @@ -436,6 +436,7 @@ func (client *Client) detailsNoMutex() (result ClientDetails) { result.username = client.username result.hostname = client.hostname result.realname = client.realname + result.realIP = client.getIPNoMutex() result.nickMask = client.nickMaskString result.nickMaskCasefolded = client.nickMaskCasefolded result.account = client.account diff --git a/irc/handlers.go b/irc/handlers.go index e3fb2fe1..fede414e 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -3416,11 +3416,8 @@ func whowasHandler(server *Server, client *Client, msg ircmsg.Message, rb *Respo count = 0 } } - //var target string - //if len(msg.Params) > 2 { - // target = msg.Params[2] - //} cnick := client.Nick() + canSeeIP := client.Oper().HasRoleCapab("ban") for _, nickname := range nicknames { if len(nickname) == 0 { continue @@ -3431,6 +3428,9 @@ func whowasHandler(server *Server, client *Client, msg ircmsg.Message, rb *Respo } else { for _, whoWas := range results { rb.Add(nil, server.name, RPL_WHOWASUSER, cnick, whoWas.nick, whoWas.username, whoWas.hostname, "*", whoWas.realname) + if canSeeIP { + rb.Add(nil, server.name, RPL_WHOWASIP, cnick, whoWas.nick, fmt.Sprintf(client.t("was connecting from %s"), utils.IPStringToHostname(whoWas.realIP.String()))) + } } } rb.Add(nil, server.name, RPL_ENDOFWHOWAS, cnick, utils.SafeErrorParam(nickname), client.t("End of WHOWAS")) diff --git a/irc/numerics.go b/irc/numerics.go index 6e4cffd3..79afff9f 100644 --- a/irc/numerics.go +++ b/irc/numerics.go @@ -168,6 +168,7 @@ const ( ERR_USERSDONTMATCH = "502" ERR_HELPNOTFOUND = "524" ERR_CANNOTSENDRP = "573" + RPL_WHOWASIP = "652" RPL_WHOISSECURE = "671" RPL_YOURLANGUAGESARE = "687" ERR_INVALIDMODEPARAM = "696"