mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-12 15:17:16 +03:00
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package sshchat
|
|
|
|
import (
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/shazow/ssh-chat/chat"
|
|
"github.com/shazow/ssh-chat/chat/message"
|
|
"github.com/shazow/ssh-chat/sshd"
|
|
)
|
|
|
|
// Helpers for printing whois messages
|
|
|
|
func whoisPublic(u User) string {
|
|
fingerprint := "(no public key)"
|
|
// FIXME: Use all connections?
|
|
conn := u.Connections()[0]
|
|
if conn.PublicKey() != nil {
|
|
fingerprint = sshd.Fingerprint(conn.PublicKey())
|
|
}
|
|
|
|
return "name: " + u.Name() + message.Newline +
|
|
" > fingerprint: " + fingerprint + message.Newline +
|
|
" > client: " + chat.SanitizeData(string(conn.ClientVersion())) + message.Newline +
|
|
" > joined: " + humanSince(time.Since(u.Joined())) + " ago"
|
|
}
|
|
|
|
func whoisAdmin(u User) string {
|
|
// FIXME: Use all connections?
|
|
conn := u.Connections()[0]
|
|
ip, _, _ := net.SplitHostPort(conn.RemoteAddr().String())
|
|
fingerprint := "(no public key)"
|
|
if conn.PublicKey() != nil {
|
|
fingerprint = sshd.Fingerprint(conn.PublicKey())
|
|
}
|
|
return "name: " + u.Name() + message.Newline +
|
|
" > ip: " + ip + message.Newline +
|
|
" > fingerprint: " + fingerprint + message.Newline +
|
|
" > client: " + chat.SanitizeData(string(conn.ClientVersion())) + message.Newline +
|
|
" > joined: " + humanSince(time.Since(u.Joined()))
|
|
}
|