mirror of
https://github.com/ergochat/ergo.git
synced 2025-02-27 02:50:52 +01:00
commit
9b21ee36b2
@ -12,11 +12,12 @@ import (
|
|||||||
|
|
||||||
// LimiterConfig controls the automated connection limits.
|
// LimiterConfig controls the automated connection limits.
|
||||||
type LimiterConfig struct {
|
type LimiterConfig struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
|
CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
|
||||||
CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
|
CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
|
||||||
IPsPerCidr int `yaml:"ips-per-subnet"`
|
ConnsPerSubnet int `yaml:"connections-per-subnet"`
|
||||||
Exempted []string
|
IPsPerSubnet int `yaml:"ips-per-subnet"` // legacy name for ConnsPerSubnet
|
||||||
|
Exempted []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -145,7 +146,11 @@ func (cl *Limiter) ApplyConfig(config LimiterConfig) error {
|
|||||||
cl.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)
|
cl.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)
|
||||||
// subnetLimit is explicitly NOT capped at a minimum of one.
|
// subnetLimit is explicitly NOT capped at a minimum of one.
|
||||||
// this is so that CL config can be used to allow ONLY clients from exempted IPs/nets
|
// this is so that CL config can be used to allow ONLY clients from exempted IPs/nets
|
||||||
cl.subnetLimit = config.IPsPerCidr
|
cl.subnetLimit = config.ConnsPerSubnet
|
||||||
|
// but: check if the current key was left unset, but the legacy was set:
|
||||||
|
if cl.subnetLimit == 0 && config.IPsPerSubnet != 0 {
|
||||||
|
cl.subnetLimit = config.IPsPerSubnet
|
||||||
|
}
|
||||||
cl.exemptedIPs = exemptedIPs
|
cl.exemptedIPs = exemptedIPs
|
||||||
cl.exemptedNets = exemptedNets
|
cl.exemptedNets = exemptedNets
|
||||||
|
|
||||||
|
@ -1594,16 +1594,14 @@ func motdHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// NAMES [<channel>{,<channel>}]
|
// NAMES [<channel>{,<channel>} [target]]
|
||||||
func namesHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
func namesHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
||||||
var channels []string
|
var channels []string
|
||||||
if len(msg.Params) > 0 {
|
if len(msg.Params) > 0 {
|
||||||
channels = strings.Split(msg.Params[0], ",")
|
channels = strings.Split(msg.Params[0], ",")
|
||||||
}
|
}
|
||||||
//var target string
|
|
||||||
//if len(msg.Params) > 1 {
|
// TODO: in a post-federation world, process `target` (server to forward request to)
|
||||||
// target = msg.Params[1]
|
|
||||||
//}
|
|
||||||
|
|
||||||
if len(channels) == 0 {
|
if len(channels) == 0 {
|
||||||
for _, channel := range server.channels.Channels() {
|
for _, channel := range server.channels.Channels() {
|
||||||
@ -1612,21 +1610,13 @@ func namesHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// limit regular users to only listing one channel
|
|
||||||
if !client.flags[modes.Operator] {
|
|
||||||
channels = channels[:1]
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, chname := range channels {
|
for _, chname := range channels {
|
||||||
casefoldedChname, err := CasefoldChannel(chname)
|
channel := server.channels.Get(chname)
|
||||||
channel := server.channels.Get(casefoldedChname)
|
if channel != nil {
|
||||||
if err != nil || channel == nil {
|
channel.Names(client, rb)
|
||||||
if len(chname) > 0 {
|
} else if chname != "" {
|
||||||
rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, client.t("No such channel"))
|
rb.Add(nil, server.name, RPL_ENDOFNAMES, client.Nick(), chname, client.t("End of NAMES list"))
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
channel.Names(client, rb)
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ server:
|
|||||||
password: JDJhJDA0JG9rTTVERlNRa0hpOEZpNkhjZE95SU9Da1BseFdlcWtOTEQxNEFERVlqbEZNTkdhOVlYUkMu
|
password: JDJhJDA0JG9rTTVERlNRa0hpOEZpNkhjZE95SU9Da1BseFdlcWtOTEQxNEFERVlqbEZNTkdhOVlYUkMu
|
||||||
|
|
||||||
# hosts that can use this webirc command
|
# hosts that can use this webirc command
|
||||||
|
# you should also add these addresses to the connection limits and throttling exemption lists
|
||||||
hosts:
|
hosts:
|
||||||
# - localhost
|
# - localhost
|
||||||
# - "127.0.0.1"
|
# - "127.0.0.1"
|
||||||
@ -100,8 +101,8 @@ server:
|
|||||||
# how wide the cidr should be for IPv6
|
# how wide the cidr should be for IPv6
|
||||||
cidr-len-ipv6: 64
|
cidr-len-ipv6: 64
|
||||||
|
|
||||||
# maximum number of IPs per subnet (defined above by the cird length)
|
# maximum concurrent connections per subnet (defined above by the cidr length)
|
||||||
ips-per-subnet: 16
|
connections-per-subnet: 16
|
||||||
|
|
||||||
# IPs/networks which are exempted from connection limits
|
# IPs/networks which are exempted from connection limits
|
||||||
exempted:
|
exempted:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user