mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-12 23:27:17 +03:00
/whois: Hide IP if user isn't admin; display client and time joined. (#192)
Resolves #170.
This commit is contained in:
parent
f6de73d420
commit
66adee6f9a
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -14,3 +14,7 @@
|
||||
path = vendor/github.com/shazow/rateio
|
||||
url = https://github.com/shazow/rateio
|
||||
branch = master
|
||||
[submodule "vendor/github.com/dustin/go-humanize"]
|
||||
path = vendor/github.com/dustin/go-humanize
|
||||
url = https://github.com/dustin/go-humanize
|
||||
branch = master
|
||||
|
9
host.go
9
host.go
@ -330,7 +330,14 @@ func (h *Host) InitCommands(c *chat.Commands) {
|
||||
}
|
||||
|
||||
id := target.Identifier.(*Identity)
|
||||
room.Send(message.NewSystemMsg(id.Whois(), msg.From()))
|
||||
var whois string
|
||||
switch room.IsOp(msg.From()) {
|
||||
case true:
|
||||
whois = id.WhoisAdmin()
|
||||
case false:
|
||||
whois = id.Whois()
|
||||
}
|
||||
room.Send(message.NewSystemMsg(whois, msg.From()))
|
||||
|
||||
return nil
|
||||
},
|
||||
|
@ -26,7 +26,7 @@ func stripPrompt(s string) string {
|
||||
func TestHostGetPrompt(t *testing.T) {
|
||||
var expected, actual string
|
||||
|
||||
u := message.NewUser(&Identity{nil, "foo"})
|
||||
u := message.NewUser(&Identity{id: "foo"})
|
||||
u.SetColorIdx(2)
|
||||
|
||||
actual = GetPrompt(u)
|
||||
|
29
identity.go
29
identity.go
@ -1,9 +1,10 @@
|
||||
package sshchat
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/shazow/ssh-chat/chat"
|
||||
"github.com/shazow/ssh-chat/chat/message"
|
||||
"github.com/shazow/ssh-chat/sshd"
|
||||
@ -12,7 +13,8 @@ import (
|
||||
// Identity is a container for everything that identifies a client.
|
||||
type Identity struct {
|
||||
sshd.Connection
|
||||
id string
|
||||
id string
|
||||
created time.Time
|
||||
}
|
||||
|
||||
// NewIdentity returns a new identity object from an sshd.Connection.
|
||||
@ -20,6 +22,7 @@ func NewIdentity(conn sshd.Connection) *Identity {
|
||||
return &Identity{
|
||||
Connection: conn,
|
||||
id: chat.SanitizeName(conn.Name()),
|
||||
created: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,14 +42,28 @@ func (i Identity) Name() string {
|
||||
return i.id
|
||||
}
|
||||
|
||||
// Whois returns a whois description for non-admin users.
|
||||
func (i Identity) Whois() string {
|
||||
fingerprint := "(no public key)"
|
||||
if i.PublicKey() != nil {
|
||||
fingerprint = sshd.Fingerprint(i.PublicKey())
|
||||
}
|
||||
return "name: " + i.Name() + message.Newline +
|
||||
" > fingerprint: " + fingerprint + message.Newline +
|
||||
" > client: " + chat.SanitizeData(string(i.ClientVersion())) + message.Newline +
|
||||
" > joined: " + humanize.Time(i.created)
|
||||
}
|
||||
|
||||
// WhoisAdmin returns a whois description for admin users.
|
||||
func (i Identity) WhoisAdmin() string {
|
||||
ip, _, _ := net.SplitHostPort(i.RemoteAddr().String())
|
||||
fingerprint := "(no public key)"
|
||||
if i.PublicKey() != nil {
|
||||
fingerprint = sshd.Fingerprint(i.PublicKey())
|
||||
}
|
||||
// TODO: Include time joined, client, etc.
|
||||
return fmt.Sprintf("name: %s"+message.Newline+
|
||||
" > ip: %s"+message.Newline+
|
||||
" > fingerprint: %s", i.Name(), ip, fingerprint)
|
||||
return "name: " + i.Name() + message.Newline +
|
||||
" > ip: " + ip + message.Newline +
|
||||
" > fingerprint: " + fingerprint + message.Newline +
|
||||
" > client: " + chat.SanitizeData(string(i.ClientVersion())) + message.Newline +
|
||||
" > joined: " + humanize.Time(i.created)
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ type Connection interface {
|
||||
PublicKey() ssh.PublicKey
|
||||
RemoteAddr() net.Addr
|
||||
Name() string
|
||||
ClientVersion() []byte
|
||||
Close() error
|
||||
}
|
||||
|
||||
|
1
vendor/github.com/dustin/go-humanize
generated
vendored
Submodule
1
vendor/github.com/dustin/go-humanize
generated
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 2fcb5204cdc65b4bec9fd0a87606bb0d0e3c54e8
|
Loading…
x
Reference in New Issue
Block a user