mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-07 10:53:07 +03:00
main: Add /banned command to list banned entries for ops.
This commit is contained in:
parent
86dae2a53e
commit
3572c4674c
11
auth.go
11
auth.go
@ -142,6 +142,17 @@ func (a *Auth) BanFingerprint(authkey string, d time.Duration) {
|
|||||||
logger.Debugf("Added to banned: %q (for %s)", authItem.Key(), d)
|
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.
|
// Ban will set an IP address as banned.
|
||||||
func (a *Auth) BanAddr(addr net.Addr, d time.Duration) {
|
func (a *Auth) BanAddr(addr net.Addr, d time.Duration) {
|
||||||
authItem := set.StringItem(newAuthAddr(addr))
|
authItem := set.StringItem(newAuthAddr(addr))
|
||||||
|
24
host.go
24
host.go
@ -1,6 +1,7 @@
|
|||||||
package sshchat
|
package sshchat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"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{
|
c.Add(chat.Command{
|
||||||
Op: true,
|
Op: true,
|
||||||
Prefix: "/motd",
|
Prefix: "/motd",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user