mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-09 20:02:26 +03:00
Host.go: assign registered nicks to users upon connection.
This commit is contained in:
parent
043b45dbbe
commit
fedad0f216
13
auth.go
13
auth.go
@ -67,6 +67,7 @@ type Auth struct {
|
|||||||
|
|
||||||
settingsMu sync.RWMutex
|
settingsMu sync.RWMutex
|
||||||
allowlistMode bool
|
allowlistMode bool
|
||||||
|
keynamesMode bool
|
||||||
opLoader KeyLoader
|
opLoader KeyLoader
|
||||||
allowlistLoader KeyLoader
|
allowlistLoader KeyLoader
|
||||||
}
|
}
|
||||||
@ -96,6 +97,18 @@ func (a *Auth) SetAllowlistMode(value bool) {
|
|||||||
a.allowlistMode = value
|
a.allowlistMode = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Auth) SetKeynamesMode(value bool) {
|
||||||
|
a.settingsMu.Lock()
|
||||||
|
defer a.settingsMu.Unlock()
|
||||||
|
a.keynamesMode = value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Auth) Keyname(key ssh.PublicKey) string {
|
||||||
|
fingerprint := sshd.Fingerprint(key)
|
||||||
|
name := a.keynamesByFingerprint[fingerprint]
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
// SetPassphrase enables passphrase authentication with the given passphrase.
|
// SetPassphrase enables passphrase authentication with the given passphrase.
|
||||||
// If an empty passphrase is given, disable passphrase authentication.
|
// If an empty passphrase is given, disable passphrase authentication.
|
||||||
func (a *Auth) SetPassphrase(passphrase string) {
|
func (a *Auth) SetPassphrase(passphrase string) {
|
||||||
|
9
host.go
9
host.go
@ -101,6 +101,15 @@ func (h *Host) isOp(conn sshd.Connection) bool {
|
|||||||
// Connect a specific Terminal to this host and its room.
|
// Connect a specific Terminal to this host and its room.
|
||||||
func (h *Host) Connect(term *sshd.Terminal) {
|
func (h *Host) Connect(term *sshd.Terminal) {
|
||||||
id := NewIdentity(term.Conn)
|
id := NewIdentity(term.Conn)
|
||||||
|
|
||||||
|
if h.auth.keynamesMode {
|
||||||
|
name := h.auth.Keyname(id.PublicKey())
|
||||||
|
if len(name) >0 {
|
||||||
|
id.SetName(name)
|
||||||
|
id.SetSymbol("✓")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
user := message.NewUserScreen(id, term)
|
user := message.NewUserScreen(id, term)
|
||||||
user.OnChange = func() {
|
user.OnChange = func() {
|
||||||
term.SetPrompt(GetPrompt(user))
|
term.SetPrompt(GetPrompt(user))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user