3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 21:39:25 +01:00
UBAN ADD and DEL need to produce snomasks and loglines
This commit is contained in:
Shivaram Lingamneni 2021-04-08 05:10:17 -04:00
parent 745fd764dd
commit 6817186224

View File

@ -13,6 +13,7 @@ import (
"github.com/oragono/oragono/irc/custime" "github.com/oragono/oragono/irc/custime"
"github.com/oragono/oragono/irc/flatip" "github.com/oragono/oragono/irc/flatip"
"github.com/oragono/oragono/irc/sno"
"github.com/oragono/oragono/irc/utils" "github.com/oragono/oragono/irc/utils"
) )
@ -160,18 +161,64 @@ func ubanAddHandler(client *Client, target ubanTarget, params []string, rb *Resp
switch target.banType { switch target.banType {
case ubanCIDR: case ubanCIDR:
ubanAddCIDR(client, target, duration, requireSASL, operReason, rb) err = ubanAddCIDR(client, target, duration, requireSASL, operReason, rb)
case ubanNickmask: case ubanNickmask:
ubanAddNickmask(client, target, duration, operReason, rb) err = ubanAddNickmask(client, target, duration, operReason, rb)
case ubanNick: case ubanNick:
ubanAddAccount(client, target, duration, operReason, rb) err = ubanAddAccount(client, target, duration, operReason, rb)
}
if err == nil {
announceUban(client, true, target, duration, requireSASL, operReason)
} }
return false return false
} }
func ubanAddCIDR(client *Client, target ubanTarget, duration time.Duration, requireSASL bool, operReason string, rb *ResponseBuffer) { func announceUban(client *Client, add bool, target ubanTarget, duration time.Duration, requireSASL bool, operReason string) {
err := client.server.dlines.AddNetwork(target.cidr, duration, requireSASL, "", operReason, client.Oper().Name) oper := client.Oper()
if oper == nil {
return
}
operName := oper.Name
var buf strings.Builder
fmt.Fprintf(&buf, "Operator %s", operName)
if add {
buf.WriteString(" added")
} else {
buf.WriteString(" removed")
}
switch target.banType {
case ubanCIDR:
buf.WriteString(" an IP-based")
case ubanNickmask:
buf.WriteString(" a NUH-mask")
case ubanNick:
buf.WriteString(" an account suspension")
}
buf.WriteString(" UBAN against ")
switch target.banType {
case ubanCIDR:
buf.WriteString(target.cidr.String())
case ubanNickmask, ubanNick:
buf.WriteString(target.nickOrMask)
}
if duration != 0 {
fmt.Fprintf(&buf, " [duration: %v]", duration)
}
if requireSASL {
buf.WriteString(" [require-SASL]")
}
if operReason != "" {
fmt.Fprintf(&buf, " [reason: %s]", operReason)
}
line := buf.String()
client.server.snomasks.Send(sno.LocalXline, line)
client.server.logger.Info("opers", line)
}
func ubanAddCIDR(client *Client, target ubanTarget, duration time.Duration, requireSASL bool, operReason string, rb *ResponseBuffer) (err error) {
err = client.server.dlines.AddNetwork(target.cidr, duration, requireSASL, "", operReason, client.Oper().Name)
if err == nil { if err == nil {
rb.Notice(fmt.Sprintf(client.t("Successfully added UBAN for %s"), target.cidr.HumanReadableString())) rb.Notice(fmt.Sprintf(client.t("Successfully added UBAN for %s"), target.cidr.HumanReadableString()))
} else { } else {
@ -192,10 +239,11 @@ func ubanAddCIDR(client *Client, target ubanTarget, duration time.Duration, requ
rb.Notice(line) rb.Notice(line)
} }
} }
return
} }
func ubanAddNickmask(client *Client, target ubanTarget, duration time.Duration, operReason string, rb *ResponseBuffer) { func ubanAddNickmask(client *Client, target ubanTarget, duration time.Duration, operReason string, rb *ResponseBuffer) (err error) {
err := client.server.klines.AddMask(target.nickOrMask, duration, "", operReason, client.Oper().Name) err = client.server.klines.AddMask(target.nickOrMask, duration, "", operReason, client.Oper().Name)
if err == nil { if err == nil {
rb.Notice(fmt.Sprintf(client.t("Successfully added UBAN for %s"), target.nickOrMask)) rb.Notice(fmt.Sprintf(client.t("Successfully added UBAN for %s"), target.nickOrMask))
} else { } else {
@ -229,9 +277,10 @@ func ubanAddNickmask(client *Client, target ubanTarget, duration time.Duration,
} }
rb.Notice(client.t("You can suspend their accounts instead; try /UBAN ADD <nickname>")) rb.Notice(client.t("You can suspend their accounts instead; try /UBAN ADD <nickname>"))
} }
return
} }
func ubanAddAccount(client *Client, target ubanTarget, duration time.Duration, operReason string, rb *ResponseBuffer) { func ubanAddAccount(client *Client, target ubanTarget, duration time.Duration, operReason string, rb *ResponseBuffer) (err error) {
account := target.nickOrMask account := target.nickOrMask
// TODO this doesn't enumerate all sessions if ForceNickEqualsAccount is disabled // TODO this doesn't enumerate all sessions if ForceNickEqualsAccount is disabled
var sessionData []SessionData var sessionData []SessionData
@ -239,7 +288,7 @@ func ubanAddAccount(client *Client, target ubanTarget, duration time.Duration, o
sessionData, _ = mcl.AllSessionData(nil, true) sessionData, _ = mcl.AllSessionData(nil, true)
} }
err := client.server.accounts.Suspend(account, duration, client.Oper().Name, operReason) err = client.server.accounts.Suspend(account, duration, client.Oper().Name, operReason)
switch err { switch err {
case nil: case nil:
rb.Notice(fmt.Sprintf(client.t("Successfully suspended account %s"), account)) rb.Notice(fmt.Sprintf(client.t("Successfully suspended account %s"), account))
@ -254,6 +303,7 @@ func ubanAddAccount(client *Client, target ubanTarget, duration time.Duration, o
default: default:
rb.Notice(client.t("An error occurred")) rb.Notice(client.t("An error occurred"))
} }
return
} }
func ubanDelHandler(client *Client, target ubanTarget, params []string, rb *ResponseBuffer) bool { func ubanDelHandler(client *Client, target ubanTarget, params []string, rb *ResponseBuffer) bool {
@ -276,6 +326,7 @@ func ubanDelHandler(client *Client, target ubanTarget, params []string, rb *Resp
} }
if err == nil { if err == nil {
rb.Notice(fmt.Sprintf(client.t("Successfully removed ban on %s"), targetString)) rb.Notice(fmt.Sprintf(client.t("Successfully removed ban on %s"), targetString))
announceUban(client, false, target, 0, false, "")
} else { } else {
rb.Notice(fmt.Sprintf(client.t("Could not remove ban: %v"), err)) rb.Notice(fmt.Sprintf(client.t("Could not remove ban: %v"), err))
} }