Fix motd, invalid fingerprint, no auth whitelist.

This commit is contained in:
Andrey Petrov 2014-12-16 20:15:37 -08:00
parent bb0c8e9e49
commit 8bba2e3917
3 changed files with 22 additions and 14 deletions

View File

@ -14,10 +14,10 @@ const (
MsgBuffer int = 50
// MaxMsgLength is the maximum length of a message
MaxMsgLength int = 512
MaxMsgLength int = 1024
// HelpText is the text returned by /help
HelpText string = systemMessageFormat + `-> Available commands:
HelpText string = `Available commands:
/about - About this chat.
/exit - Exit the chat.
/help - Show this help text.
@ -28,10 +28,10 @@ const (
/whois $NAME - Display information about another connected user.
/msg $NAME $MESSAGE - Sends a private message to a user.
/motd - Prints the Message of the Day.
/theme [color|mono] - Set client theme.` + Reset
/theme [color|mono] - Set client theme.`
// OpHelpText is the additional text returned by /help if the client is an Op
OpHelpText string = systemMessageFormat + `-> Available operator commands:
OpHelpText string = `Available operator commands:
/ban $NAME - Banish a user from the chat
/kick $NAME - Kick em' out.
/op $NAME - Promote a user to server operator.
@ -39,18 +39,17 @@ const (
/shutdown $MESSAGE - Broadcast message and shutdown server.
/motd $MESSAGE - Set message shown whenever somebody joins.
/whitelist $FINGERPRINT - Add fingerprint to whitelist, prevent anyone else from joining.
/whitelist github.com/$USER - Add github user's pubkeys to whitelist.` + Reset
/whitelist github.com/$USER - Add github user's pubkeys to whitelist.`
// AboutText is the text returned by /about
AboutText string = systemMessageFormat + `-> ssh-chat is made by @shazow.
AboutText string = `ssh-chat is made by @shazow.
It is a custom ssh server built in Go to serve a chat experience
instead of a shell.
Source: https://github.com/shazow/ssh-chat
For more, visit shazow.net or follow at twitter.com/shazow
` + Reset
For more, visit shazow.net or follow at twitter.com/shazow`
// RequiredWait is the time a client is required to wait between messages
RequiredWait time.Duration = time.Second / 2
@ -222,14 +221,14 @@ func (c *Client) handleShell(channel ssh.Channel) {
case "/exit":
channel.Close()
case "/help":
c.WriteLines(strings.Split(HelpText, "\n"))
c.SysMsg(strings.Replace(HelpText, "\n", "\r\n", -1))
if c.Server.IsOp(c) {
c.WriteLines(strings.Split(OpHelpText, "\n"))
c.SysMsg(strings.Replace(OpHelpText, "\n", "\r\n", -1))
}
case "/about":
c.WriteLines(strings.Split(AboutText, "\n"))
c.SysMsg(strings.Replace(AboutText, "\n", "\r\n", -1))
case "/uptime":
c.Write(c.Server.Uptime())
c.SysMsg(c.Server.Uptime())
case "/beep":
c.beepMe = !c.beepMe
if c.beepMe {

View File

@ -1 +1 @@
Welcome to chat.shazow.net, enter /help for more. 
Welcome to chat.shazow.net, enter /help for more. 

View File

@ -81,7 +81,13 @@ func NewServer(privateKey []byte) (*Server, error) {
return perm, nil
},
KeyboardInteractiveCallback: func(conn ssh.ConnMetadata, challenge ssh.KeyboardInteractiveChallenge) (*ssh.Permissions, error) {
return nil, fmt.Errorf("Must have an SSH keypair to connect.")
if server.IsBanned("") {
return nil, fmt.Errorf("Interactive login disabled.")
}
if !server.IsWhitelisted("") {
return nil, fmt.Errorf("Not Whitelisted.")
}
return nil, nil
},
}
config.AddHostKey(signer)
@ -267,6 +273,9 @@ func (s *Server) Op(fingerprint string) {
// Whitelist adds the given fingerprint to the whitelist
func (s *Server) Whitelist(fingerprint string) error {
if fingerprint == "" {
return fmt.Errorf("Invalid fingerprint.")
}
if strings.HasPrefix(fingerprint, "github.com/") {
return s.whitelistIdentityURL(fingerprint)
}