mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-18 00:22:34 +01:00
fixes uint, moved code, stole slingnams hsNotifyChannel function
This commit is contained in:
parent
6a9fa35d35
commit
9756ce02ba
@ -101,18 +101,18 @@ type DnsblListEntry struct {
|
|||||||
Types []string
|
Types []string
|
||||||
Reply map[string]DnsblListReply
|
Reply map[string]DnsblListReply
|
||||||
Action string
|
Action string
|
||||||
ActionType uint
|
ActionType DnsblActionType
|
||||||
Reason string
|
Reason string
|
||||||
}
|
}
|
||||||
|
|
||||||
type DnsblListReply struct {
|
type DnsblListReply struct {
|
||||||
Action string
|
Action string
|
||||||
ActionType uint
|
ActionType DnsblActionType
|
||||||
Reason string
|
Reason string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conf *Config) DnsblTypes(action string) (uint, error) {
|
func (conf *Config) DnsblTypes(action string) (DnsblActionType, error) {
|
||||||
actions := map[string]uint{
|
actions := map[string]DnsblActionType{
|
||||||
"require-sasl": DnsblRequireSaslReply,
|
"require-sasl": DnsblRequireSaslReply,
|
||||||
"allow": DnsblAllowReply,
|
"allow": DnsblAllowReply,
|
||||||
"block": DnsblBlockReply,
|
"block": DnsblBlockReply,
|
||||||
|
63
irc/dnsbl.go
63
irc/dnsbl.go
@ -7,41 +7,27 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/oragono/oragono/irc/sno"
|
"github.com/oragono/oragono/irc/sno"
|
||||||
|
"github.com/oragono/oragono/irc/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
|
type DnsblActionType uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DnsblRequireSaslReply uint = iota
|
DnsblRequireSaslReply DnsblActionType = iota
|
||||||
DnsblAllowReply
|
DnsblAllowReply
|
||||||
DnsblBlockReply
|
DnsblBlockReply
|
||||||
DnsblNotifyReply
|
DnsblNotifyReply
|
||||||
DnsblUnknownReply
|
DnsblUnknownReply
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReverseAddress returns IPv4 addresses reversed
|
|
||||||
func ReverseAddress(ip net.IP) string {
|
|
||||||
// This is a IPv4 address
|
|
||||||
if ip.To4() != nil {
|
|
||||||
address := strings.Split(ip.String(), ".")
|
|
||||||
|
|
||||||
for i, j := 0, len(address)-1; i < j; i, j = i+1, j-1 {
|
|
||||||
address[i], address[j] = address[j], address[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Join(address, ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
// fallback to returning the String of IP if it is not an IPv4 address
|
|
||||||
return ip.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// LookupBlacklistEntry performs a lookup on the dnsbl on the client IP
|
// LookupBlacklistEntry performs a lookup on the dnsbl on the client IP
|
||||||
func (server *Server) LookupBlacklistEntry(list *DnsblListEntry, client *Client) []string {
|
func (server *Server) LookupBlacklistEntry(list *DnsblListEntry, client *Client) []string {
|
||||||
res, err := net.LookupHost(fmt.Sprintf("%s.%s", ReverseAddress(client.IP()), list.Host))
|
res, err := net.LookupHost(fmt.Sprintf("%s.%s", utils.ReverseAddress(client.IP()), list.Host))
|
||||||
|
|
||||||
var entries []string
|
var entries []string
|
||||||
if err != nil {
|
if err != nil {
|
||||||
server.logger.Info("dnsbl-lookup", fmt.Sprintf("DNSBL loopup failed: %s", err))
|
// An error may indicate that the A record was not found
|
||||||
return entries
|
return entries
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,12 +51,11 @@ func (server *Server) ProcessBlacklist(client *Client) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := server.DnsblConfig().Channel
|
|
||||||
lists := server.DnsblConfig().Lists
|
lists := server.DnsblConfig().Lists
|
||||||
|
|
||||||
type DnsblTypeResponse struct {
|
type DnsblTypeResponse struct {
|
||||||
Host string
|
Host string
|
||||||
ActionType uint
|
ActionType DnsblActionType
|
||||||
Reason string
|
Reason string
|
||||||
}
|
}
|
||||||
var items = []DnsblTypeResponse{}
|
var items = []DnsblTypeResponse{}
|
||||||
@ -98,54 +83,46 @@ func (server *Server) ProcessBlacklist(client *Client) {
|
|||||||
item := items[0]
|
item := items[0]
|
||||||
switch item.ActionType {
|
switch item.ActionType {
|
||||||
case DnsblRequireSaslReply:
|
case DnsblRequireSaslReply:
|
||||||
client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Connecting client %s matched %s, requiring SASL to proceed", client.IP(), item.Host))
|
dnsblSendServiceMessage(server, fmt.Sprintf("Connecting client %s matched %s, requiring SASL to proceed", client.IP(), item.Host))
|
||||||
client.SetRequireSasl(true, item.Reason)
|
client.SetRequireSasl(true, item.Reason)
|
||||||
|
|
||||||
case DnsblBlockReply:
|
case DnsblBlockReply:
|
||||||
client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Connecting client %s matched %s - killing", client.IP(), item.Host))
|
dnsblSendServiceMessage(server, fmt.Sprintf("Connecting client %s matched %s - killing", client.IP(), item.Host))
|
||||||
client.Quit(strings.Replace(item.Reason, "{ip}", client.IPString(), -1))
|
client.Quit(strings.Replace(item.Reason, "{ip}", client.IPString(), -1))
|
||||||
|
|
||||||
case DnsblNotifyReply:
|
case DnsblNotifyReply:
|
||||||
client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Connecting client %s matched %s", client.IP(), item.Host))
|
dnsblSendServiceMessage(server, fmt.Sprintf("Connecting client %s matched %s", client.IP(), item.Host))
|
||||||
|
|
||||||
case DnsblAllowReply:
|
case DnsblAllowReply:
|
||||||
client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Allowing host %s [%s]", client.IP(), item.Host))
|
dnsblSendServiceMessage(server, fmt.Sprintf("Allowing host %s [%s]", client.IP(), item.Host))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectionRequiresSasl(client *Client) bool {
|
func ConnectionRequiresSasl(client *Client) bool {
|
||||||
sasl, reason := client.RequireSasl()
|
sasl, reason := client.RequireSasl()
|
||||||
|
|
||||||
if !sasl {
|
if !sasl {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := client.server.DnsblConfig().Channel
|
|
||||||
|
|
||||||
if client.Account() == "" {
|
if client.Account() == "" {
|
||||||
//client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Connecting client %s and did not authenticate through SASL - blocking connection", client.IP()))
|
dnsblSendServiceMessage(client.server, fmt.Sprintf("Connecting client %s and did not authenticate through SASL - blocking connection", client.IP()))
|
||||||
client.Quit(strings.Replace(reason, "{ip}", client.IPString(), -1))
|
client.Quit(strings.Replace(reason, "{ip}", client.IPString(), -1))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
client.sendServerMessage("", channel, sno.Dnsbl, fmt.Sprintf("Connecting client %s authenticated through SASL - allowing", client.IP()))
|
dnsblSendServiceMessage(client.server, fmt.Sprintf("Connecting client %s authenticated through SASL - allowing", client.IP()))
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) sendServerMessage(pseudo string, channel string, mask sno.Mask, message string) {
|
func dnsblSendServiceMessage(server *Server, message string) {
|
||||||
/*
|
channel := server.DnsblConfig().Channel
|
||||||
This causes an out of bounds error - possibly in client.Send() - investigate further
|
if channel != "" {
|
||||||
if pseudo == "" {
|
server.serviceNotifyChannel(server.name, channel, message)
|
||||||
pseudo = client.server.name
|
}
|
||||||
}
|
server.snomasks.Send(sno.Dnsbl, message)
|
||||||
|
|
||||||
if channel != "" {
|
|
||||||
client.Send(nil, pseudo, "PRIVMSG", channel, message)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
client.server.snomasks.Send(mask, message)
|
|
||||||
}
|
}
|
||||||
|
@ -463,7 +463,7 @@ func (server *Server) tryRegister(c *Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if connection requires SASL
|
// Check if connection requires SASL
|
||||||
if connectionRequiresSasl(c) {
|
if ConnectionRequiresSasl(c) {
|
||||||
c.destroy(false)
|
c.destroy(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1230,6 +1230,18 @@ func (target *Client) RplList(channel *Channel, rb *ResponseBuffer) {
|
|||||||
rb.Add(nil, target.server.name, RPL_LIST, target.nick, channel.name, strconv.Itoa(memberCount), channel.topic)
|
rb.Add(nil, target.server.name, RPL_LIST, target.nick, channel.name, strconv.Itoa(memberCount), channel.topic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// serviceNotifyChannel sends messages to a channel as a pseudo client
|
||||||
|
func (server *Server) serviceNotifyChannel(pseudoClient string, channelName string, message string) {
|
||||||
|
channel := server.channels.Get(channelName)
|
||||||
|
if channel == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
channelName = channel.Name()
|
||||||
|
for _, client := range channel.Members() {
|
||||||
|
client.Send(nil, pseudoClient, "PRIVMSG", channelName, message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ResumeDetails are the details that we use to resume connections.
|
// ResumeDetails are the details that we use to resume connections.
|
||||||
type ResumeDetails struct {
|
type ResumeDetails struct {
|
||||||
OldNick string
|
OldNick string
|
||||||
|
@ -94,3 +94,20 @@ func IsHostname(name string) bool {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReverseAddress returns IPv4 addresses reversed
|
||||||
|
func ReverseAddress(ip net.IP) string {
|
||||||
|
// This is a IPv4 address
|
||||||
|
if ip.To4() != nil {
|
||||||
|
address := strings.Split(ip.String(), ".")
|
||||||
|
|
||||||
|
for i, j := 0, len(address)-1; i < j; i, j = i+1, j-1 {
|
||||||
|
address[i], address[j] = address[j], address[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(address, ".")
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback to returning the String of IP if it is not an IPv4 address
|
||||||
|
return ip.String()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user