mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
Fix proxied DLINE/throttle/etc error messages
This commit is contained in:
parent
a9e4ed237e
commit
ffe7375a68
@ -7,8 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goshuirc/irc-go/ircmsg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ThrottleDetails holds the connection-throttling details for a subnet/IP.
|
// ThrottleDetails holds the connection-throttling details for a subnet/IP.
|
||||||
@ -115,12 +113,6 @@ func NewConnectionThrottle(config ConnectionThrottleConfig) (*ConnectionThrottle
|
|||||||
|
|
||||||
ct.BanDuration = config.BanDuration
|
ct.BanDuration = config.BanDuration
|
||||||
ct.BanMessage = config.BanMessage
|
ct.BanMessage = config.BanMessage
|
||||||
ircmsgOutput := ircmsg.MakeMessage(nil, "", "ERROR", ct.BanMessage)
|
|
||||||
msg, err := ircmsgOutput.Line()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Could not make error message: %s", err.Error())
|
|
||||||
}
|
|
||||||
ct.BanMessageBytes = []byte(msg)
|
|
||||||
|
|
||||||
// assemble exempted nets
|
// assemble exempted nets
|
||||||
for _, cidr := range config.Exempted {
|
for _, cidr := range config.Exempted {
|
||||||
|
@ -31,10 +31,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// common error line to sub values into
|
||||||
|
errorMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "%s ")}[0]).Line()
|
||||||
|
|
||||||
// common error responses
|
// common error responses
|
||||||
tooManyClientsMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Too many clients from your network")}[0]).Line()
|
couldNotParseIPMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Unable to parse your IP address")}[0]).Line()
|
||||||
couldNotParseIPMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Unable to parse your IP address")}[0]).Line()
|
|
||||||
bannedFromServerMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "You are banned from this server (%s)")}[0]).Line()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -275,7 +276,8 @@ func (server *Server) Run() {
|
|||||||
|
|
||||||
isBanned, banMsg := server.checkBans(ipaddr)
|
isBanned, banMsg := server.checkBans(ipaddr)
|
||||||
if isBanned {
|
if isBanned {
|
||||||
conn.Conn.Write(banMsg)
|
// this might not show up properly on some clients, but our objective here is just to close the connection out before it has a load impact on us
|
||||||
|
conn.Conn.Write([]byte(fmt.Sprintf(errorMsg, banMsg)))
|
||||||
conn.Conn.Close()
|
conn.Conn.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -289,11 +291,11 @@ func (server *Server) Run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) checkBans(ipaddr net.IP) (banned bool, message []byte) {
|
func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
|
||||||
// check DLINEs
|
// check DLINEs
|
||||||
isBanned, info := server.dlines.CheckIP(ipaddr)
|
isBanned, info := server.dlines.CheckIP(ipaddr)
|
||||||
if isBanned {
|
if isBanned {
|
||||||
return true, []byte(info.BanMessage(bannedFromServerMsg))
|
return true, info.BanMessage("You are banned from this server (%s)")
|
||||||
}
|
}
|
||||||
|
|
||||||
// check connection limits
|
// check connection limits
|
||||||
@ -302,8 +304,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message []byte) {
|
|||||||
server.connectionLimitsMutex.Unlock()
|
server.connectionLimitsMutex.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// too many connections from one client, tell the client and close the connection
|
// too many connections from one client, tell the client and close the connection
|
||||||
// this might not show up properly on some clients, but our objective here is just to close it out before it has a load impact on us
|
return true, "Too many clients from your network"
|
||||||
return true, []byte(tooManyClientsMsg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check connection throttle
|
// check connection throttle
|
||||||
@ -323,10 +324,10 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message []byte) {
|
|||||||
server.connectionThrottle.ResetFor(ipaddr)
|
server.connectionThrottle.ResetFor(ipaddr)
|
||||||
|
|
||||||
// this might not show up properly on some clients, but our objective here is just to close it out before it has a load impact on us
|
// this might not show up properly on some clients, but our objective here is just to close it out before it has a load impact on us
|
||||||
return true, []byte(server.connectionThrottle.BanMessageBytes)
|
return true, server.connectionThrottle.BanMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
return false, nil
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -2196,7 +2197,7 @@ func proxyHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
|
|
||||||
isBanned, banMsg := server.checkBans(parsedProxiedIP)
|
isBanned, banMsg := server.checkBans(parsedProxiedIP)
|
||||||
if isBanned {
|
if isBanned {
|
||||||
client.Quit(string(banMsg))
|
client.Quit(banMsg)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user