main: Add /banned command to list banned entries for ops.

This commit is contained in:
Andrey Petrov 2018-12-15 19:04:42 -05:00
parent 86dae2a53e
commit 3572c4674c
2 changed files with 35 additions and 0 deletions

11
auth.go
View File

@ -142,6 +142,17 @@ func (a *Auth) BanFingerprint(authkey string, d time.Duration) {
logger.Debugf("Added to banned: %q (for %s)", authItem.Key(), d)
}
func (a *Auth) Banned() []string {
r := []string{}
iterGet := func(key string, _ set.Item) error {
r = append(r, key)
return nil
}
a.banned.Each(iterGet)
a.bannedAddr.Each(iterGet)
return r
}
// Ban will set an IP address as banned.
func (a *Auth) BanAddr(addr net.Addr, d time.Duration) {
authItem := set.StringItem(newAuthAddr(addr))

24
host.go
View File

@ -1,6 +1,7 @@
package sshchat
import (
"bytes"
"errors"
"fmt"
"io"
@ -454,6 +455,29 @@ func (h *Host) InitCommands(c *chat.Commands) {
},
})
c.Add(chat.Command{
Op: true,
Prefix: "/banned",
Help: "List the current ban conditions.",
Handler: func(room *chat.Room, msg message.CommandMsg) error {
if !room.IsOp(msg.From()) {
return errors.New("must be op")
}
banned := h.auth.Banned()
buf := bytes.Buffer{}
fmt.Fprintf(&buf, "Banned:\n")
for _, key := range banned {
fmt.Fprintf(&buf, " %s\n", key)
}
room.Send(message.NewSystemMsg(buf.String(), msg.From()))
return nil
},
})
c.Add(chat.Command{
Op: true,
Prefix: "/motd",