3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-15 00:19:29 +01:00

Merge pull request #1702 from ajaspers/whowas

Show real IP in WHOWAS to opers with ban capability.
This commit is contained in:
Shivaram Lingamneni 2021-06-22 02:28:56 -04:00 committed by GitHub
commit f07524111c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View File

@ -269,6 +269,7 @@ type WhoWas struct {
username string
hostname string
realname string
ip 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
}

View File

@ -436,6 +436,7 @@ func (client *Client) detailsNoMutex() (result ClientDetails) {
result.username = client.username
result.hostname = client.hostname
result.realname = client.realname
result.ip = client.getIPNoMutex()
result.nickMask = client.nickMaskString
result.nickMaskCasefolded = client.nickMaskCasefolded
result.account = client.account

View File

@ -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 {
results := server.whoWas.Find(nickname, count)
if len(results) == 0 {
@ -3428,6 +3425,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.ip.String())))
}
}
}
rb.Add(nil, server.name, RPL_ENDOFWHOWAS, cnick, utils.SafeErrorParam(nickname), client.t("End of WHOWAS"))

View File

@ -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"