ssh-chat/identity.go
Andrey Petrov c8661e6883 motd: Allow for reading the current motd when no additional args given.
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
2016-08-03 17:58:49 -04:00

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)
}