Browse Source

DLINE: Save name of the banning oper

tags/v0.10.3
Daniel Oaks 6 years ago
parent
commit
dedb029272
2 changed files with 25 additions and 11 deletions
  1. 24
    10
      irc/dline.go
  2. 1
    1
      irc/server.go

+ 24
- 10
irc/dline.go View File

@@ -49,6 +49,8 @@ type IPBanInfo struct {
49 49
 	Reason string `json:"reason"`
50 50
 	// OperReason is an oper ban reason.
51 51
 	OperReason string `json:"oper_reason"`
52
+	// OperName is the oper who set the ban.
53
+	OperName string `json:"oper_name"`
52 54
 	// Time holds details about the duration, if it exists.
53 55
 	Time *IPRestrictTime `json:"time"`
54 56
 }
@@ -113,7 +115,7 @@ func (dm *DLineManager) AllBans() map[string]IPBanInfo {
113 115
 }
114 116
 
115 117
 // AddNetwork adds a network to the blocked list.
116
-func (dm *DLineManager) AddNetwork(network net.IPNet, length *IPRestrictTime, reason string, operReason string) {
118
+func (dm *DLineManager) AddNetwork(network net.IPNet, length *IPRestrictTime, reason, operReason, operName string) {
117 119
 	netString := network.String()
118 120
 	dln := dLineNet{
119 121
 		Network: network,
@@ -121,6 +123,7 @@ func (dm *DLineManager) AddNetwork(network net.IPNet, length *IPRestrictTime, re
121 123
 			Time:       length,
122 124
 			Reason:     reason,
123 125
 			OperReason: operReason,
126
+			OperName:   operName,
124 127
 		},
125 128
 	}
126 129
 	dm.Lock()
@@ -137,7 +140,7 @@ func (dm *DLineManager) RemoveNetwork(network net.IPNet) {
137 140
 }
138 141
 
139 142
 // AddIP adds an IP address to the blocked list.
140
-func (dm *DLineManager) AddIP(addr net.IP, length *IPRestrictTime, reason string, operReason string) {
143
+func (dm *DLineManager) AddIP(addr net.IP, length *IPRestrictTime, reason, operReason, operName string) {
141 144
 	addrString := addr.String()
142 145
 	dla := dLineAddr{
143 146
 		Address: addr,
@@ -145,6 +148,7 @@ func (dm *DLineManager) AddIP(addr net.IP, length *IPRestrictTime, reason string
145 148
 			Time:       length,
146 149
 			Reason:     reason,
147 150
 			OperReason: operReason,
151
+			OperName:   operName,
148 152
 		},
149 153
 	}
150 154
 	dm.Lock()
@@ -232,7 +236,7 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
232 236
 		}
233 237
 
234 238
 		for key, info := range bans {
235
-			client.Notice(fmt.Sprintf("Ban - %s - %s", key, info.BanMessage("%s")))
239
+			client.Notice(fmt.Sprintf("Ban - %s - added by %s - %s", key, info.OperName, info.BanMessage("%s")))
236 240
 		}
237 241
 
238 242
 		return false
@@ -319,6 +323,10 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
319 323
 			}
320 324
 		}
321 325
 	}
326
+	operName := client.operName
327
+	if operName == "" {
328
+		operName = server.name
329
+	}
322 330
 
323 331
 	// assemble ban info
324 332
 	var banTime *IPRestrictTime
@@ -332,6 +340,7 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
332 340
 	info := IPBanInfo{
333 341
 		Reason:     reason,
334 342
 		OperReason: operReason,
343
+		OperName:   operName,
335 344
 		Time:       banTime,
336 345
 	}
337 346
 
@@ -356,18 +365,18 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
356 365
 	}
357 366
 
358 367
 	if hostNet == nil {
359
-		server.dlines.AddIP(hostAddr, banTime, reason, operReason)
368
+		server.dlines.AddIP(hostAddr, banTime, reason, operReason, operName)
360 369
 	} else {
361
-		server.dlines.AddNetwork(*hostNet, banTime, reason, operReason)
370
+		server.dlines.AddNetwork(*hostNet, banTime, reason, operReason, operName)
362 371
 	}
363 372
 
364 373
 	var snoDescription string
365 374
 	if durationIsUsed {
366 375
 		client.Notice(fmt.Sprintf("Added temporary (%s) D-Line for %s", duration.String(), hostString))
367
-		snoDescription = fmt.Sprintf(ircfmt.Unescape("%s$r added temporary (%s) D-Line for %s"), client.nick, duration.String(), hostString)
376
+		snoDescription = fmt.Sprintf(ircfmt.Unescape("%s [%s]$r added temporary (%s) D-Line for %s"), client.nick, operName, duration.String(), hostString)
368 377
 	} else {
369 378
 		client.Notice(fmt.Sprintf("Added D-Line for %s", hostString))
370
-		snoDescription = fmt.Sprintf(ircfmt.Unescape("%s$r added D-Line for %s"), client.nick, hostString)
379
+		snoDescription = fmt.Sprintf(ircfmt.Unescape("%s [%s]$r added D-Line for %s"), client.nick, operName, hostString)
371 380
 	}
372 381
 	server.snomasks.Send(sno.LocalXline, snoDescription)
373 382
 
@@ -405,7 +414,7 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
405 414
 
406 415
 		// send snomask
407 416
 		sort.Strings(killedClientNicks)
408
-		server.snomasks.Send(sno.LocalKills, fmt.Sprintf(ircfmt.Unescape("%s killed %d clients with a DLINE $c[grey][$r%s$c[grey]]"), client.nick, len(killedClientNicks), strings.Join(killedClientNicks, ", ")))
417
+		server.snomasks.Send(sno.LocalKills, fmt.Sprintf(ircfmt.Unescape("%s [%s] killed %d clients with a DLINE $c[grey][$r%s$c[grey]]"), client.nick, operName, len(killedClientNicks), strings.Join(killedClientNicks, ", ")))
409 418
 	}
410 419
 
411 420
 	return killClient
@@ -495,11 +504,16 @@ func (s *Server) loadDLines() {
495 504
 			var info IPBanInfo
496 505
 			json.Unmarshal([]byte(value), &info)
497 506
 
507
+			// set opername if it isn't already set
508
+			if info.OperName == "" {
509
+				info.OperName = s.name
510
+			}
511
+
498 512
 			// add to the server
499 513
 			if hostNet == nil {
500
-				s.dlines.AddIP(hostAddr, info.Time, info.Reason, info.OperReason)
514
+				s.dlines.AddIP(hostAddr, info.Time, info.Reason, info.OperReason, info.OperName)
501 515
 			} else {
502
-				s.dlines.AddNetwork(*hostNet, info.Time, info.Reason, info.OperReason)
516
+				s.dlines.AddNetwork(*hostNet, info.Time, info.Reason, info.OperReason, info.OperName)
503 517
 			}
504 518
 
505 519
 			return true // true to continue I guess?

+ 1
- 1
irc/server.go View File

@@ -321,7 +321,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
321 321
 			Duration: duration,
322 322
 			Expires:  time.Now().Add(duration),
323 323
 		}
324
-		server.dlines.AddIP(ipaddr, length, server.connectionThrottler.BanMessage(), "Exceeded automated connection throttle")
324
+		server.dlines.AddIP(ipaddr, length, server.connectionThrottler.BanMessage(), "Exceeded automated connection throttle", "auto.connection.throttler")
325 325
 
326 326
 		// they're DLINE'd for 15 minutes or whatever, so we can reset the connection throttle now,
327 327
 		// and once their temporary DLINE is finished they can fill up the throttler again

Loading…
Cancel
Save