|
@@ -13,6 +13,7 @@ import (
|
13
|
13
|
|
14
|
14
|
"github.com/oragono/oragono/irc/custime"
|
15
|
15
|
"github.com/oragono/oragono/irc/flatip"
|
|
16
|
+ "github.com/oragono/oragono/irc/sno"
|
16
|
17
|
"github.com/oragono/oragono/irc/utils"
|
17
|
18
|
)
|
18
|
19
|
|
|
@@ -160,18 +161,64 @@ func ubanAddHandler(client *Client, target ubanTarget, params []string, rb *Resp
|
160
|
161
|
|
161
|
162
|
switch target.banType {
|
162
|
163
|
case ubanCIDR:
|
163
|
|
- ubanAddCIDR(client, target, duration, requireSASL, operReason, rb)
|
|
164
|
+ err = ubanAddCIDR(client, target, duration, requireSASL, operReason, rb)
|
164
|
165
|
case ubanNickmask:
|
165
|
|
- ubanAddNickmask(client, target, duration, operReason, rb)
|
|
166
|
+ err = ubanAddNickmask(client, target, duration, operReason, rb)
|
166
|
167
|
case ubanNick:
|
167
|
|
- ubanAddAccount(client, target, duration, operReason, rb)
|
168
|
|
-
|
|
168
|
+ err = ubanAddAccount(client, target, duration, operReason, rb)
|
|
169
|
+ }
|
|
170
|
+ if err == nil {
|
|
171
|
+ announceUban(client, true, target, duration, requireSASL, operReason)
|
169
|
172
|
}
|
170
|
173
|
return false
|
171
|
174
|
}
|
172
|
175
|
|
173
|
|
-func ubanAddCIDR(client *Client, target ubanTarget, duration time.Duration, requireSASL bool, operReason string, rb *ResponseBuffer) {
|
174
|
|
- err := client.server.dlines.AddNetwork(target.cidr, duration, requireSASL, "", operReason, client.Oper().Name)
|
|
176
|
+func announceUban(client *Client, add bool, target ubanTarget, duration time.Duration, requireSASL bool, operReason string) {
|
|
177
|
+ oper := client.Oper()
|
|
178
|
+ if oper == nil {
|
|
179
|
+ return
|
|
180
|
+ }
|
|
181
|
+ operName := oper.Name
|
|
182
|
+
|
|
183
|
+ var buf strings.Builder
|
|
184
|
+ fmt.Fprintf(&buf, "Operator %s", operName)
|
|
185
|
+
|
|
186
|
+ if add {
|
|
187
|
+ buf.WriteString(" added")
|
|
188
|
+ } else {
|
|
189
|
+ buf.WriteString(" removed")
|
|
190
|
+ }
|
|
191
|
+ switch target.banType {
|
|
192
|
+ case ubanCIDR:
|
|
193
|
+ buf.WriteString(" an IP-based")
|
|
194
|
+ case ubanNickmask:
|
|
195
|
+ buf.WriteString(" a NUH-mask")
|
|
196
|
+ case ubanNick:
|
|
197
|
+ buf.WriteString(" an account suspension")
|
|
198
|
+ }
|
|
199
|
+ buf.WriteString(" UBAN against ")
|
|
200
|
+ switch target.banType {
|
|
201
|
+ case ubanCIDR:
|
|
202
|
+ buf.WriteString(target.cidr.String())
|
|
203
|
+ case ubanNickmask, ubanNick:
|
|
204
|
+ buf.WriteString(target.nickOrMask)
|
|
205
|
+ }
|
|
206
|
+ if duration != 0 {
|
|
207
|
+ fmt.Fprintf(&buf, " [duration: %v]", duration)
|
|
208
|
+ }
|
|
209
|
+ if requireSASL {
|
|
210
|
+ buf.WriteString(" [require-SASL]")
|
|
211
|
+ }
|
|
212
|
+ if operReason != "" {
|
|
213
|
+ fmt.Fprintf(&buf, " [reason: %s]", operReason)
|
|
214
|
+ }
|
|
215
|
+ line := buf.String()
|
|
216
|
+ client.server.snomasks.Send(sno.LocalXline, line)
|
|
217
|
+ client.server.logger.Info("opers", line)
|
|
218
|
+}
|
|
219
|
+
|
|
220
|
+func ubanAddCIDR(client *Client, target ubanTarget, duration time.Duration, requireSASL bool, operReason string, rb *ResponseBuffer) (err error) {
|
|
221
|
+ err = client.server.dlines.AddNetwork(target.cidr, duration, requireSASL, "", operReason, client.Oper().Name)
|
175
|
222
|
if err == nil {
|
176
|
223
|
rb.Notice(fmt.Sprintf(client.t("Successfully added UBAN for %s"), target.cidr.HumanReadableString()))
|
177
|
224
|
} else {
|
|
@@ -192,10 +239,11 @@ func ubanAddCIDR(client *Client, target ubanTarget, duration time.Duration, requ
|
192
|
239
|
rb.Notice(line)
|
193
|
240
|
}
|
194
|
241
|
}
|
|
242
|
+ return
|
195
|
243
|
}
|
196
|
244
|
|
197
|
|
-func ubanAddNickmask(client *Client, target ubanTarget, duration time.Duration, operReason string, rb *ResponseBuffer) {
|
198
|
|
- err := client.server.klines.AddMask(target.nickOrMask, duration, "", operReason, client.Oper().Name)
|
|
245
|
+func ubanAddNickmask(client *Client, target ubanTarget, duration time.Duration, operReason string, rb *ResponseBuffer) (err error) {
|
|
246
|
+ err = client.server.klines.AddMask(target.nickOrMask, duration, "", operReason, client.Oper().Name)
|
199
|
247
|
if err == nil {
|
200
|
248
|
rb.Notice(fmt.Sprintf(client.t("Successfully added UBAN for %s"), target.nickOrMask))
|
201
|
249
|
} else {
|
|
@@ -229,9 +277,10 @@ func ubanAddNickmask(client *Client, target ubanTarget, duration time.Duration,
|
229
|
277
|
}
|
230
|
278
|
rb.Notice(client.t("You can suspend their accounts instead; try /UBAN ADD <nickname>"))
|
231
|
279
|
}
|
|
280
|
+ return
|
232
|
281
|
}
|
233
|
282
|
|
234
|
|
-func ubanAddAccount(client *Client, target ubanTarget, duration time.Duration, operReason string, rb *ResponseBuffer) {
|
|
283
|
+func ubanAddAccount(client *Client, target ubanTarget, duration time.Duration, operReason string, rb *ResponseBuffer) (err error) {
|
235
|
284
|
account := target.nickOrMask
|
236
|
285
|
// TODO this doesn't enumerate all sessions if ForceNickEqualsAccount is disabled
|
237
|
286
|
var sessionData []SessionData
|
|
@@ -239,7 +288,7 @@ func ubanAddAccount(client *Client, target ubanTarget, duration time.Duration, o
|
239
|
288
|
sessionData, _ = mcl.AllSessionData(nil, true)
|
240
|
289
|
}
|
241
|
290
|
|
242
|
|
- err := client.server.accounts.Suspend(account, duration, client.Oper().Name, operReason)
|
|
291
|
+ err = client.server.accounts.Suspend(account, duration, client.Oper().Name, operReason)
|
243
|
292
|
switch err {
|
244
|
293
|
case nil:
|
245
|
294
|
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
|
254
|
303
|
default:
|
255
|
304
|
rb.Notice(client.t("An error occurred"))
|
256
|
305
|
}
|
|
306
|
+ return
|
257
|
307
|
}
|
258
|
308
|
|
259
|
309
|
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
|
276
|
326
|
}
|
277
|
327
|
if err == nil {
|
278
|
328
|
rb.Notice(fmt.Sprintf(client.t("Successfully removed ban on %s"), targetString))
|
|
329
|
+ announceUban(client, false, target, 0, false, "")
|
279
|
330
|
} else {
|
280
|
331
|
rb.Notice(fmt.Sprintf(client.t("Could not remove ban: %v"), err))
|
281
|
332
|
}
|