mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-07 19:03:17 +03:00
Resolved merge conflict.
This commit is contained in:
commit
6bf5348b4e
24
client.go
24
client.go
@ -26,11 +26,12 @@ const HELP_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> Available commands:
|
|||||||
` + RESET
|
` + RESET
|
||||||
|
|
||||||
const OP_HELP_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> Available operator commands:
|
const OP_HELP_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> Available operator commands:
|
||||||
/ban $NAME - Banish a user from the chat
|
/ban $NAME - Banish a user from the chat
|
||||||
/kick $NAME - Kick em' out.
|
/kick $NAME - Kick em' out.
|
||||||
/op $NAME - Promote a user to server operator.
|
/op $NAME - Promote a user to server operator.
|
||||||
/silence $NAME - Revoke a user's ability to speak.
|
/silence $NAME - Revoke a user's ability to speak.
|
||||||
/motd $MESSAGE - Sets the Message of the Day
|
/motd $MESSAGE - Sets the Message of the Day
|
||||||
|
/whitelist $FINGERPRINT - Adds pubkey fingerprint to the connection whitelist
|
||||||
` + RESET
|
` + RESET
|
||||||
|
|
||||||
const ABOUT_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> ssh-chat is made by @shazow.
|
const ABOUT_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> ssh-chat is made by @shazow.
|
||||||
@ -351,7 +352,7 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
|||||||
} else {
|
} else {
|
||||||
newmotd = parts[1] + " " + parts[2]
|
newmotd = parts[1] + " " + parts[2]
|
||||||
}
|
}
|
||||||
c.Server.SetMotd(c, newmotd)
|
c.Server.SetMotd(newmotd)
|
||||||
c.Server.MotdBroadcast(c)
|
c.Server.MotdBroadcast(c)
|
||||||
}
|
}
|
||||||
case "/theme":
|
case "/theme":
|
||||||
@ -369,6 +370,17 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
|||||||
c.Rename(c.Name)
|
c.Rename(c.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "/whitelist": /* whitelist a fingerprint */
|
||||||
|
if !c.Server.IsOp(c) {
|
||||||
|
c.SysMsg("You're not an admin.")
|
||||||
|
} else if len(parts) != 2 {
|
||||||
|
c.SysMsg("Missing $FINGERPRINT from: /whitelist $FINGERPRINT")
|
||||||
|
} else {
|
||||||
|
fingerprint := parts[1]
|
||||||
|
c.Server.Whitelist(fingerprint)
|
||||||
|
c.SysMsg("Added %s to the whitelist", fingerprint)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
c.SysMsg("Invalid command: %s", line)
|
c.SysMsg("Invalid command: %s", line)
|
||||||
}
|
}
|
||||||
|
15
cmd.go
15
cmd.go
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ type Options struct {
|
|||||||
Bind string `long:"bind" description:"Host and port to listen on." default:"0.0.0.0:22"`
|
Bind string `long:"bind" description:"Host and port to listen on." default:"0.0.0.0:22"`
|
||||||
Admin []string `long:"admin" description:"Fingerprint of pubkey to mark as admin."`
|
Admin []string `long:"admin" description:"Fingerprint of pubkey to mark as admin."`
|
||||||
Whitelist string `long:"whitelist" description:"Optional file of pubkey fingerprints that are allowed to connect"`
|
Whitelist string `long:"whitelist" description:"Optional file of pubkey fingerprints that are allowed to connect"`
|
||||||
|
Motd string `long:"motd" description:"Message of the Day file (optional)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var logLevels = []log.Level{
|
var logLevels = []log.Level{
|
||||||
@ -80,6 +82,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.Motd != "" {
|
||||||
|
motd, err := ioutil.ReadFile(options.Motd)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("Failed to load MOTD file: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
motdString := string(motd[:])
|
||||||
|
/* hack to normalize line endings into \r\n */
|
||||||
|
motdString = strings.Replace(motdString, "\r\n", "\n", -1)
|
||||||
|
motdString = strings.Replace(motdString, "\n", "\r\n", -1)
|
||||||
|
server.SetMotd(motdString)
|
||||||
|
}
|
||||||
|
|
||||||
// Construct interrupt handler
|
// Construct interrupt handler
|
||||||
sig := make(chan os.Signal, 1)
|
sig := make(chan os.Signal, 1)
|
||||||
signal.Notify(sig, os.Interrupt)
|
signal.Notify(sig, os.Interrupt)
|
||||||
|
@ -123,21 +123,19 @@ func (s *Server) Privmsg(nick, message string, sender *Client) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) SetMotd(client *Client, motd string) {
|
func (s *Server) SetMotd(motd string) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
s.motd = motd
|
s.motd = motd
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) MotdUnicast(client *Client) {
|
func (s *Server) MotdUnicast(client *Client) {
|
||||||
client.SysMsg("/** MOTD")
|
client.SysMsg("MOTD:\r\n" + ColorString("36", s.motd)) /* a nice cyan color */
|
||||||
client.SysMsg(" * " + ColorString("36", s.motd)) /* a nice cyan color */
|
|
||||||
client.SysMsg(" **/")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) MotdBroadcast(client *Client) {
|
func (s *Server) MotdBroadcast(client *Client) {
|
||||||
s.Broadcast(ContinuousFormat(SYSTEM_MESSAGE_FORMAT, fmt.Sprintf(" * New MOTD set by %s.", client.ColoredName())), client)
|
s.Broadcast(ContinuousFormat(SYSTEM_MESSAGE_FORMAT, fmt.Sprintf(" * New MOTD set by %s.", client.ColoredName())), client)
|
||||||
s.Broadcast(" /**\r\n" + " * " + ColorString("36", s.motd) + "\r\n **/", client)
|
s.Broadcast(ColorString("36", s.motd), client)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Add(client *Client) {
|
func (s *Server) Add(client *Client) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user