mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-29 15:40:02 +01:00
Merge pull request #128 from euank/return-bad-ip-err
server: close connection on parse-ip failure
This commit is contained in:
commit
0b75351e56
@ -31,12 +31,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// cached because this may be used lots
|
// common error responses
|
||||||
tooManyClientsMsg = ircmsg.MakeMessage(nil, "", "ERROR", "Too many clients from your network")
|
tooManyClientsMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Too many clients from your network")}[0]).Line()
|
||||||
tooManyClientsBytes, _ = tooManyClientsMsg.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()
|
||||||
bannedFromServerMsg = ircmsg.MakeMessage(nil, "", "ERROR", "You are banned from this server (%s)")
|
|
||||||
bannedFromServerBytes, _ = bannedFromServerMsg.Line()
|
|
||||||
|
|
||||||
errDbOutOfDate = errors.New("Database schema is old")
|
errDbOutOfDate = errors.New("Database schema is old")
|
||||||
)
|
)
|
||||||
@ -430,11 +428,15 @@ func (server *Server) Run() {
|
|||||||
case conn := <-server.newConns:
|
case conn := <-server.newConns:
|
||||||
// check connection limits
|
// check connection limits
|
||||||
ipaddr := net.ParseIP(IPString(conn.Conn.RemoteAddr()))
|
ipaddr := net.ParseIP(IPString(conn.Conn.RemoteAddr()))
|
||||||
if ipaddr != nil {
|
if ipaddr == nil {
|
||||||
|
conn.Conn.Write([]byte(couldNotParseIPMsg))
|
||||||
|
conn.Conn.Close()
|
||||||
|
continue
|
||||||
|
}
|
||||||
// check DLINEs
|
// check DLINEs
|
||||||
isBanned, info := server.dlines.CheckIP(ipaddr)
|
isBanned, info := server.dlines.CheckIP(ipaddr)
|
||||||
if isBanned {
|
if isBanned {
|
||||||
banMessage := fmt.Sprintf(bannedFromServerBytes, info.Reason)
|
banMessage := fmt.Sprintf(bannedFromServerMsg, info.Reason)
|
||||||
if info.Time != nil {
|
if info.Time != nil {
|
||||||
banMessage += fmt.Sprintf(" [%s]", info.Time.Duration.String())
|
banMessage += fmt.Sprintf(" [%s]", info.Time.Duration.String())
|
||||||
}
|
}
|
||||||
@ -450,7 +452,7 @@ func (server *Server) Run() {
|
|||||||
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
|
// 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
|
||||||
conn.Conn.Write([]byte(tooManyClientsBytes))
|
conn.Conn.Write([]byte(tooManyClientsMsg))
|
||||||
conn.Conn.Close()
|
conn.Conn.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -483,7 +485,6 @@ func (server *Server) Run() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user