From 7d8e5146b11dcddd2d528566ea4e61380789bfe7 Mon Sep 17 00:00:00 2001 From: Peter Hellberg Date: Mon, 15 Dec 2014 03:42:20 +0100 Subject: [PATCH 1/4] Replace first ~ with user.HomeDir, if possible --- cmd.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd.go b/cmd.go index ab41788..82398b5 100644 --- a/cmd.go +++ b/cmd.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "os/signal" + "os/user" "strings" "net/http" @@ -61,7 +62,15 @@ func main() { logLevel := logLevels[numVerbose] logger = golog.New(os.Stderr, logLevel) - privateKey, err := ioutil.ReadFile(options.Identity) + privateKeyPath := options.Identity + if strings.HasPrefix(privateKeyPath, "~") { + user, err := user.Current() + if err == nil { + privateKeyPath = strings.Replace(privateKeyPath, "~", user.HomeDir, 1) + } + } + + privateKey, err := ioutil.ReadFile(privateKeyPath) if err != nil { logger.Errorf("Failed to load identity: %v", err) return From 120cd8aae81fec39255ef8eef001752138407756 Mon Sep 17 00:00:00 2001 From: empathetic-alligator Date: Sun, 14 Dec 2014 21:44:56 -0500 Subject: [PATCH 2/4] Names are now case insensitive. This should address issue #17. Names are stored in the server dict as lowercase and another user cannot take a different casing of that same name. However, a user may change their name to a different casing of their own name. --- server.go | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/server.go b/server.go index df832b2..8b86917 100644 --- a/server.go +++ b/server.go @@ -120,7 +120,7 @@ func (s *Server) Broadcast(msg string, except *Client) { // Privmsg sends a message to a particular nick, if it exists func (s *Server) Privmsg(nick, message string, sender *Client) error { // Get the recipient - target, ok := s.clients[nick] + target, ok := s.clients[strings.ToLower(nick)] if !ok { return fmt.Errorf("no client with that nick") } @@ -165,7 +165,7 @@ func (s *Server) Add(client *Client) { } client.Rename(newName) - s.clients[client.Name] = client + s.clients[strings.ToLower(client.Name)] = client num := len(s.clients) s.Unlock() @@ -175,7 +175,7 @@ func (s *Server) Add(client *Client) { // Remove removes the given client from the list of clients func (s *Server) Remove(client *Client) { s.Lock() - delete(s.clients, client.Name) + delete(s.clients, strings.ToLower(client.Name)) s.Unlock() s.SysMsg("%s left.", client.ColoredName()) @@ -192,7 +192,7 @@ func (s *Server) proposeName(name string) (string, error) { name = fmt.Sprintf("Guest%d", s.count) } - _, collision := s.clients[name] + _, collision := s.clients[strings.ToLower(name)] if collision { err = fmt.Errorf("%s is not available", name) name = fmt.Sprintf("Guest%d", s.count) @@ -204,21 +204,25 @@ func (s *Server) proposeName(name string) (string, error) { // Rename renames the given client (user) func (s *Server) Rename(client *Client, newName string) { s.Lock() + var oldName string + if strings.ToLower(newName) == strings.ToLower(client.Name) { + oldName = client.Name + client.Rename(newName) + } else { + newName, err := s.proposeName(newName) + if err != nil { + client.SysMsg("%s", err) + s.Unlock() + return + } - newName, err := s.proposeName(newName) - if err != nil { - client.SysMsg("%s", err) + // TODO: Use a channel/goroutine for adding clients, rather than locks? + delete(s.clients, strings.ToLower(client.Name)) + oldName = client.Name + client.Rename(newName) + s.clients[strings.ToLower(client.Name)] = client s.Unlock() - return } - - // TODO: Use a channel/goroutine for adding clients, rather than locks? - delete(s.clients, client.Name) - oldName := client.Name - client.Rename(newName) - s.clients[client.Name] = client - s.Unlock() - s.SysMsg("%s is now known as %s.", ColorString(client.Color, oldName), ColorString(client.Color, newName)) } @@ -238,7 +242,7 @@ func (s *Server) List(prefix *string) []string { // Who returns the client with a given name func (s *Server) Who(name string) *Client { - return s.clients[name] + return s.clients[strings.ToLower(name)] } // Op adds the given fingerprint to the list of admins From e2c5b569a9af575f7eb3c99672fb026628b88288 Mon Sep 17 00:00:00 2001 From: empathetic-alligator Date: Sun, 14 Dec 2014 21:51:51 -0500 Subject: [PATCH 3/4] Added travis build status icon to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5d1923b..5bdb203 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/shazow/ssh-chat.svg?branch=master)](https://travis-ci.org/shazow/ssh-chat) + # ssh-chat Custom SSH server written in Go. Instead of a shell, you get a chat prompt. From dd65f7faf243256aedce22135279ec8c1df120fc Mon Sep 17 00:00:00 2001 From: empathetic-alligator Date: Sun, 14 Dec 2014 22:16:56 -0500 Subject: [PATCH 4/4] Added note about make debug to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5bdb203..cc4b53d 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ See notes in the header of our Dockerfile for details on building your own image If you're developing on this repo, there is a handy Makefile that should set things up with `make run`. +Additionally, `make debug` runs the server with an http `pprof` server. This allows you to open [http://localhost:6060/debug/pprof/]() and view profiling data. See [net/http/pprof](http://golang.org/pkg/net/http/pprof/) for more information about `pprof`. ## License