mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-12 23:27:17 +03:00
Closes #155, merges #157 Squashed commit of the following: commit bcb0810637c99223753629a2e55169b07ee9fe51 Author: Andrey Petrov <andrey.petrov@shazow.net> Date: Wed Aug 3 17:58:37 2016 -0400 motd: Refactor inner conditions commit ac28c8cb4e8dc2a0d23abe3dcf52b69175cde51b Author: Aaron <aaron.ounn@gmail.com> Date: Tue Aug 2 09:38:36 2016 +0300 Fix small issues with the help message commit a80ae77e1d691a4ec7125be5441d4f6eea767a75 Author: Aaron <aaron.ounn@gmail.com> Date: Tue Aug 2 09:30:21 2016 +0300 Print the motd if no parameters are passed commit 2db1b3c123661cdbd622d5ba2ff81ede8cb8a951 Author: Aaron <aaron.ounn@gmail.com> Date: Tue Aug 2 09:29:41 2016 +0300 Update the motd command's description
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package sshchat
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
|
|
"github.com/shazow/ssh-chat/chat"
|
|
"github.com/shazow/ssh-chat/chat/message"
|
|
"github.com/shazow/ssh-chat/sshd"
|
|
)
|
|
|
|
// Identity is a container for everything that identifies a client.
|
|
type Identity struct {
|
|
sshd.Connection
|
|
id string
|
|
}
|
|
|
|
// NewIdentity returns a new identity object from an sshd.Connection.
|
|
func NewIdentity(conn sshd.Connection) *Identity {
|
|
return &Identity{
|
|
Connection: conn,
|
|
id: chat.SanitizeName(conn.Name()),
|
|
}
|
|
}
|
|
|
|
func (i Identity) Id() string {
|
|
return i.id
|
|
}
|
|
|
|
func (i *Identity) SetId(id string) {
|
|
i.id = id
|
|
}
|
|
|
|
func (i *Identity) SetName(name string) {
|
|
i.SetId(name)
|
|
}
|
|
|
|
func (i Identity) Name() string {
|
|
return i.id
|
|
}
|
|
|
|
func (i Identity) Whois() 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)
|
|
}
|